Hi Simon,
maybe you can solve your problem with Matlab's C++ interface (
https://de.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html
).
The interface allows you to access Matlab's command line via C++ code, and,
thus, you can use the full capabilities of Matlab within your C++ code.

You could do the following:

call function res = fun(p,y) in C++
transfer vector p from matlab to C++
run deal.ii calculation in C++
res = s - y;
end

BR Andreas


<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virenfrei.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Am Mo., 15. Aug. 2022 um 02:22 Uhr schrieb Simon <simon.wieshe...@gmail.com
>:

> Dear all,
>
> my question is specific and regards the data transfer between Matlab and a
> dealii program. In a nutshell, I have to call my dealii program from Matlab
> with a Matlab vector as argument (my dealii program needs the values in the
> vector). I figured out that Mex files are one way to transfer data to a c++
> program.
>
>
> Here is a snippet of my Matlab script:
>
> function res = fun(p,y)
> s = call_my_dealii_program_passing_the_vector_p
> res = s - y;
> end
>
> My issue is *how to pass the vector 'p' to the dealii program*.
>
> There are MEX files which provide an interface between Matlab and C++
> programs. A standard MEX file looks like this:
>
> //file mymex.cpp
> #include "mex.h"
> //include some more header files from c++ or dealii
> //write here the whole class definition and implemenation
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
> *prhs[])
> {
> //this is the interface function to Matlab where also 'p' is passed
> //in here, I will also create the instance of my dealii program to run the
> typical member //functions ike make_grid(), system_setup(),...
> }
>
> The above mex file is compiled within the Matlab gui using a c++ compiler
> (mex mymex.cpp).
>
> If I do not include any dealii headers in  mymex.cpp , the compilation
> works.
> However, including dealii headers results in a bunch of error messages
> when I compile the program in Matlab (mex mymex.cpp), because environment
> variables are not known to Matlab,...
> Usually, I just call 'spack load dealii' followed by 'make run' to run my
> dealii programs, but I do not know how to 'forward' all this information to
> the Matlab compilation process.
>
> All that said, has someone already worked with Mex files together with
> dealii?
>
> I also appreciate other approaches to manage the data transfer between
> Matlab and dealii.
>
>
> Best
> Simon
>
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see
> https://groups.google.com/d/forum/dealii?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dealii+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/b047d35d-b3e3-465b-88d8-c708343086bfn%40googlegroups.com
> <https://groups.google.com/d/msgid/dealii/b047d35d-b3e3-465b-88d8-c708343086bfn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/CAF_nQ7DepQDY1AjpP81K1Dza73-fTmNnpCyum6SqhvJPMR3CKw%40mail.gmail.com.

Reply via email to