Ruud 0 Report post Posted October 30, 2019 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 Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted November 5, 2019 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. Quote Share this post Link to post Share on other sites

Ruud 0 Report post Posted November 8, 2019 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')? Quote Share this post Link to post Share on other sites

Aravind Venugopal 1 Report post Posted February 28 On 11/8/2019 at 4:27 PM, Ruud said: 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')? Hi Ruud, I'm a beginner with MATLAB coding as well as Altair Flux. I'm using MATLAB R2019a and Flux 2019 versions. I would like to know how I can interface Flux and MATLAB so that I can model a circuit in MATLAB and export it to flux for using laminated busbar instead of wires in the same. In my MATLAB installation, I don't know which product(s) to install so that I can do this interfacing. In YouTube, I have found some tutorials regarding this issue, but the Flux and MATLAB versions were like 2012, 2013. In those versions, there was this "Flux link" module in the Simulink library browser which had a "Coupling with Flux" option with it. But, I'm not seeing it in my version. It would be great if you could give me step by step instructions on what to do or provide a link that has this details. Thanks and Regards Aravind Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted February 28 Hi Aravind, Please, find attached a tutorial about how to do the coupling between Simulink and Flux. You will also find a Flux project which serves as the starting point of the example. Just some important remarks before you try to run this coupling: · You will find the compatibility of Flux/ Matlab version in the table below. As you can notice, coupling with MATLAB R2019a is not qualified by any Flux version. This does not mean that the coupling is going to fail, but if you want to be sure that you are not going to have any problem with it, it is better to change Matlab version. · Before run Flux – Simulink coupling you should launch a file to activate the API. The default path to this file is: C:\Program Files\Altair\2019\flux\Flux\Bin\prg\win64\Active_Distributed_Computation_and_API Hope this helps. Best regards, Alejandro Rodríguez Flux_simulink_coupling.pdf CABLES.FLU.zip Aravind Venugopal likes this Quote Share this post Link to post Share on other sites

Aravind Venugopal 1 Report post Posted February 29 21 hours ago, Alejandro Rodríguez said: Hi Aravind, Please, find attached a tutorial about how to do the coupling between Simulink and Flux. You will also find a Flux project which serves as the starting point of the example. Just some important remarks before you try to run this coupling: · You will find the compatibility of Flux/ Matlab version in the table below. As you can notice, coupling with MATLAB R2019a is not qualified by any Flux version. This does not mean that the coupling is going to fail, but if you want to be sure that you are not going to have any problem with it, it is better to change Matlab version. · Before run Flux – Simulink coupling you should launch a file to activate the API. The default path to this file is: C:\Program Files\Altair\2019\flux\Flux\Bin\prg\win64\Active_Distributed_Computation_and_API Hope this helps. Best regards, Alejandro Rodríguez Flux_simulink_coupling.pdf 1.16 MB · 0 downloads CABLES.FLU.zip 444.78 kB · 0 downloads Thanks a lot, Mr. Rodríguez. I really appreciate it. I hope that you will help me out with other queries too, which might pop up eventually while I'm working on this project. Warm regards Aravind Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted March 2 You are very welcome. If you have any other questions, please do not hesitate to ask them. We are here to help. Have a nice day. Alejandro Quote Share this post Link to post Share on other sites

pfetzingm 0 Report post Posted March 3 Hello Alejandro, after succesfully setting up the FLUX MATLAB API, I can control FLUX via MATLAB. So far, so good, but I don't get any graphical feedback except from a console window. I would like to see the simulation model or the simulations, but it seems like, the simulations are performed in the background and I get only insight in the simulation results. For example, if I excute FMP_executeJythonCommand(serverUid, 'newProject()') within a MATLAB script, I expected, that the FLUX user interface would appear, but instead, a new project is silently created in the background. I tried differend arguments for the FLUX server, but all I can see is the console via args={strcat(NUMERICAL_MEMORY_LABEL,'600000000'),strcat(CHARACTER_MEMORY_LABEL,'600000000'),strcat(GUI_MEMORY_LABEL,'600'),strcat(LANGUAGE_LABEL,'2'),strcat(CONSOLE_LABEL,'1')}; serverUid = FMP_startLocaleServer(FLUX2D_64,LOCALEWRKDIR,args); Is there any possibility in the arguments for the server to make the user interface visible? I couldn't find any information in the API handbook, except from the attached table. Best regards, Michael Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted March 3 Hello Michael, Unfortunately, Flux is always launched in batch mode. You cannot access to user interface and you must wait to the end of the simulation to have your outputs available. Best regards, Quote Share this post Link to post Share on other sites

Aravind Venugopal 1 Report post Posted March 4 On 3/2/2020 at 1:40 PM, Alejandro Rodríguez said: You are very welcome. If you have any other questions, please do not hesitate to ask them. We are here to help. Have a nice day. Alejandro Hi Alejandro, I tried with the steps mentioned in the flux user guide that you gave me. In Flux, I have setup my model, defined the materials, physics and added the mesh. I have assigned faces of terminals of my laminated busbar with positive and negative voltage. I have also added a couple of I/O parameters (V and I) of multiphysical application with reference values as zero. Now, when I looked for the option, "Generate component for Matlab Simulink coupling" in 'Solving' tab, I'm unable to find it. The only option I see regarding coupling, is "Generate component for GOT-It coupling". Please let me know what I should do to get that option in the 'Solving' tab and proceed further with my project. Thanks and regards Aravind Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted March 4 Hello Aravind. I think problem there is that you are not in the right application. The options that appear in the solving tag depends on the application you have previously defined. Matlab coupling is working for transient magnetic and transient thermal applications, if you have defined your application as steady state AC or static, Matlab coupling will not be available. Best regards, Aravind Venugopal likes this Quote Share this post Link to post Share on other sites

Aravind Venugopal 1 Report post Posted March 4 30 minutes ago, Alejandro Rodríguez said: Hello Aravind. I think problem there is that you are not in the right application. The options that appear in the solving tag depends on the application you have previously defined. Matlab coupling is working for transient magnetic and transient thermal applications, if you have defined your application as steady state AC or static, Matlab coupling will not be available. Best regards, Dear Alejandro, Thanks. That issue is sorted now. Also, I found 'Electrical components' as well as 'Circuit' options in the Physics menu when I defined the application as transient magnetic. But to my surprise, these options aren't available in any application that comes under 'Electric', be it steady state or transient! Is it likewise by default in the software or is it because of some setting change in my version? Regards Aravind Quote Share this post Link to post Share on other sites

Alejandro Rodríguez 19 Report post Posted March 4 Dear Aravind, Your settings are right, electric applications have less option than magnetic ones. Best regards, Quote Share this post Link to post Share on other sites

Ruud 0 Report post Posted May 15 Dear Alejandro, Do you know what argument options I have for the 'CONSOLE_LABEL' argument? It seems that it does not matter whether I set this argument to YES or NO, the console is displayed in both cases. For clarity, I would ultimately like to reduce the amount of information fed back to the user via the console window to either a bare minimum, or nothing at all. Is this possible? Thanks in advance and best regards, Ruud Quote Share this post Link to post Share on other sites