Jump to content
Ruud

Controlling Flux2D from Matlab

Recommended Posts

Hi,

 

I am trying to set up communication between Matlab (version 2019a) and Flux2D (as a server, using version 2019.1). I have been able to do this succesfully in the past with older versions of Flux2D (12.3). However, for the new version, I found that a library needs to be loaded for this in Matlab using the following command:

[notfound,warnings]=loadlibrary(strcat(installFlux,'\Bin\dll\win64\',fluxmp,'.dll'), strcat(installFlux,'\Api\win64\include\flux_mp_matlab.h'));

I have made sure that the variable 'installFlux' is set correctly (manually checked the result of strcat). Also, I am using MinGW as a C/C++ compiler in Matlab (recommended by Matlab). However, when I try to run the command above, I get some errors:

Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through in regex; marked by <-- HERE in m/struct([^;,{(]*){ <-- HERE (.*?)\}([^;])*;/ at C:\Program Files\MATLAB\R2019a\toolbox\matlab\general\private\prototypes.pl line 912.

Failed to parse type '( __cdecl__ )) FMP_stopServer_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_stopServer_Matlab ( int serverUid '
Found on line 12 of input from line 8 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_killServer_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_killServer_Matlab ( int serverUid '
Found on line 13 of input from line 9 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_closeProject_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_closeProject_Matlab ( int serverUid '
Found on line 17 of input from line 13 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_saveProject_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_saveProject_Matlab ( int serverUid '
Found on line 18 of input from line 14 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_solveCurrentStep_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_solveCurrentStep_Matlab ( int serverUid '
Found on line 34 of input from line 30 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_solveActiveNextStep_Matlab ( int serverUid' original input '( __cdecl__ )) FMP_solveActiveNextStep_Matlab ( int serverUid '
Found on line 36 of input from line 32 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_getErrorMessage_Matlab ( int errorId' original input '( __cdecl__ )) FMP_getErrorMessage_Matlab ( int errorId '
Found on line 43 of input from line 39 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.

Failed to parse type '( __cdecl__ )) FMP_freeError_Matlab ( int errorId' original input '( __cdecl__ )) FMP_freeError_Matlab ( int errorId '
Found on line 44 of input from line 40 of file C:\\Altair\\2019\\flux\\Flux\\Api\\win64\\include\\flux_mp_matlab.h
Error parsing argument for function __attribute__ function may be invalid.
*********
Error using loadlibrary
Building flux_mp_thunk_pcwin64 failed.  Compiler output is:
C:\ProgramData\MATLAB\SupportPackages\R2019a\3P.instrset\mingw_w64.instrset\bin\gcc -I"C:\Program
Files\MATLAB\R2019a\extern\include" -fexceptions -fno-omit-frame-pointer -I"C:\SIM_TOOLS\TOOLS\HSM_geometry_optimization"
-I"C:\Altair\2019\flux\Flux\Api\win64\include" "flux_mp_thunk_pcwin64.c" -o "flux_mp_thunk_pcwin64.dll" -shared
flux_mp_thunk_pcwin64.c:33:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_stopServer_Matlab(intserverUidThunk(void fcn(),const char *callstack,int stacksize)
                                     ^
flux_mp_thunk_pcwin64.c:42:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_killServer_Matlab(intserverUidThunk(void fcn(),const char *callstack,int stacksize)
                                     ^
flux_mp_thunk_pcwin64.c:51:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_closeProject_Matlab(intserverUidThunk(void fcn(),const char *callstack,int stacksize)
                                     ^
flux_mp_thunk_pcwin64.c:60:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_saveProject_Matlab(intserverUidThunk(void fcn(),const char *callstack,int stacksize)
                                     ^
flux_mp_thunk_pcwin64.c:69:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_solveCurrentStep_Matlab(intserverUidThunk(void fcn(),const char *callstack,int stacksize)
                                     ^
flux_mp_thunk_pcwin64.c:78:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
 EXPORT_EXTERN_C long long(__cdecl__))FMP_solveActiveNextStep_Matlab(intserverUidThunk(void fcn(),const char *callstack,int
 stacksize)
                                     ^
flux_mp_thunk_pcwin64.c: In function 'cstring':
flux_mp_thunk_pcwin64.c:87:42: error: expected declaration specifiers before ')' token
 EXPORT_EXTERN_C char * cstring(__cdecl__))FMP_getErrorMessage_Matlab(interrorIdThunk(void fcn(),const char *callstack,int
 stacksize)
                                          ^
flux_mp_thunk_pcwin64.c:5:26: error: expected declaration specifiers before '__attribute__'
   #define DLL_EXPORT_SYM __declspec(dllexport)
                          ^
flux_mp_thunk_pcwin64.c:19:25: note: in expansion of macro 'DLL_EXPORT_SYM'
 #define EXPORT_EXTERN_C DLL_EXPORT_SYM
                         ^~~~~~~~~~~~~~
flux_mp_thunk_pcwin64.c:96:1: note: in expansion of macro 'EXPORT_EXTERN_C'
 EXPORT_EXTERN_C long long(__cdecl__))FMP_freeError_Matlab(interrorIdThunk(void fcn(),const char *callstack,int stacksize)
 ^~~~~~~~~~~~~~~
flux_mp_thunk_pcwin64.c:87:24: warning: type of '__cdecl__' defaults to 'int' [-Wimplicit-int]
 EXPORT_EXTERN_C char * cstring(__cdecl__))FMP_getErrorMessage_Matlab(interrorIdThunk(void fcn(),const char *callstack,int
 stacksize)
                        ^~~~~~~
flux_mp_thunk_pcwin64.c:102:1: error: expected '{' at end of input
 }
 ^


Error in flux_link (line 9)
[notfound,warnings]=loadlibrary(strcat(installFlux,'\Bin\dll\win64\',fluxmp,'.dll'),
strcat(installFlux,'\Api\win64\include\flux_mp_matlab.h'));

Do you have any idea what is causing this problem? Is MinGW the right compiler for loading this library, or do I need a different one?

 

Thanks in advance for the reply.

 

Best regards,

Ruud

 

Share this post


Link to post
Share on other sites

Hello Ruud,

Actually the problem is that the compiler you are using (MinGW) is not compatible, that is why you are having this issue.

This coupling have been tested using Visual Studio 2005 as C compiler. Newer versions of Visual Studio should work fine, also. Please, try again using Visual Studio as compiler.

Best regards.

Share this post


Link to post
Share on other sites

Thanks Alejandro!

 

I managed to get the 'loadlibrary' command to work after installing Visual Studio 2019. However, I am still experiencing problems with the API. I am trying to run the following code:

% Init Flux installation path
installFlux = 'C:\Altair\2019\flux\Flux';

% Init Flux dll
fluxmp = 'flux_mp';
if(~libisloaded(fluxmp))
    [notfound,warnings] = loadlibrary(strcat(installFlux,'\Bin\dll\win64\flux_mp.dll'), strcat(installFlux,'\Api\win64\include\flux_mp_matlab.h'))
end
f = libfunctions(fluxmp);

% Server type
FLUX2D_64    ='FLUX2D_2019.1_64';
FLUX3D_64    ='FLUX3D_2019.1_64';
FLUXSKEWED_64='FLUXSKEWED_2019.1_64';
FLUXPEEC_64  ='FLUXPEEC_2019.1_64';

% Server arguments
NUMERICAL_MEMORY_LABEL='MEMSIZN3=';
CHARACTER_MEMORY_LABEL='MEMSIZC3=';
GUI_MEMORY_LABEL      ='JVM_MEMORY=';
LANGUAGE_LABEL        ='CAO_DEFLAN=';
CONSOLE_LABEL         ='CONSOLE_SERVER=';

% Debug Mode
RELEASEMODE=0;
DEBUGMODE  =1;

% Error
maxSizeErrorMessage = 2048;
ME = MException(strcat(fluxmp,':dll'),strcat('Error connection to ',fluxmp));

% Error Code
herror=0;

% Server Uid
serverUid = 0;

% Functions to manage Server
FMP_getServerVersion  = 'FMP_getServerVersion_Matlab';
FMP_init              = 'FMP_init_Matlab';
FMP_startLocaleServer = 'FMP_startLocaleServer_Matlab';
FMP_startRemoteServer = 'FMP_startRemoteServer_Matlab';
FMP_stopServer        = 'FMP_stopServer_Matlab';
FMP_killServer        = 'FMP_killServer_Matlab';

% Functions to manage Project
FMP_loadProject   = 'FMP_loadProject_Matlab';
FMP_closeProject  = 'FMP_closeProject_Matlab';
FMP_saveProject   = 'FMP_saveProject_Matlab';
FMP_saveProjectAs = 'FMP_saveProjectAs_Matlab';

% Functions to manage Jython command
FMP_executeJythonCommand      = 'FMP_executeJythonCommand_Matlab';
FMP_getJythonDoubleArrayValue = 'FMP_getJythonDoubleArrayValue_Matlab';
FMP_getJythonIntArrayValue    = 'FMP_getJythonIntArrayValue_Matlab';
FMP_getJythonStringArrayValue = 'FMP_getJythonStringArrayValue_Matlab';
FMP_setJythonDoubleArrayValue = 'FMP_setJythonDoubleArrayValue_Matlab';
FMP_setJythonIntArrayValue    = 'FMP_setJythonIntArrayValue_Matlab';
FMP_setJythonStringArrayValue = 'FMP_setJythonStringArrayValue_Matlab';

% Functions to manage Solver
FMP_openMultiPhysicsSession  = 'FMP_openMultiPhysicsSession_Matlab';
FMP_closeMultiPhysicsSession = 'FMP_closeMultiPhysicsSession_Matlab';
FMP_solve                    = 'FMP_solve_Matlab';
FMP_solveCurrentStep         = 'FMP_solveCurrentStep_Matlab';
FMP_solveDefineNextStep      = 'FMP_solveDefineNextStep_Matlab';
FMP_solveActiveNextStep      = 'FMP_solveActiveNextStep_Matlab';

% Functions to manage Error
FMP_getErrorMessage = 'FMP_getErrorMessage_Matlab';
FMP_freeError       = 'FMP_freeError_Matlab';

% Init Flux API
herror = calllib(fluxmp,FMP_init,[installFlux '\Bin\prg\win64\multiphys.wfg'],RELEASEMODE);
if (herror ~= 0)
	throw(ME);
end

At the end, when I perform the calllib command, it returns with an error. Is there anyway to get more information about the error (currently it only return a numerical value in 'herror')?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...