Dear Bruno,

I also thought about transferring the data by reading from/writing to a
file.
But I was looking for a more general approach without having to create
files.

I was also pondering if it is possible to compile the mex file like a
normal dealii program (by adding a few Matlab macros to the files generated
by cmake).
But I can not say how much is involved to do this due to my modest
knowledge about cmake.
If it were possible and someone wanted to guide me through that process, I
would be willed to try that out; otherwise I go with the easier approach
and work with files.


Best
Simon

Bruno Turcksin <[email protected]> schrieb am Mo., 15. Aug. 2022,
14:24:

> Simon,
>
> You could just write/read files to transfer the data and you can launch
> your deal.II code from Matlab using
> https://www.mathworks.com/help/matlab/ref/system.html This way Matlab
> does not need to know anything about deal.II. You just write and read
> files, and you execute a bash command.
>
> Best,
>
> Bruno
>
> On Sunday, August 14, 2022 at 8:22:30 PM UTC-4 Simon wrote:
>
>> 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 a topic in the
> Google Groups "deal.II User Group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/dealii/beTOBvu5ko4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/f7904da5-4e91-408a-a8c3-c512db95cb8dn%40googlegroups.com
> <https://groups.google.com/d/msgid/dealii/f7904da5-4e91-408a-a8c3-c512db95cb8dn%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/CAM50jEvsU1i7aa_9M%2B9Mqtp3z9Ztdx%3D7%3DeL3twodN8-mdZL_EA%40mail.gmail.com.

Reply via email to