Matlab-Ansys Maxwell interface for optimization error: Error using Interface.4824CFB6_4885_4ECF_B6C8_314CC7C0C148/OpenProject - Error: The remote procedure call failed.
Mostrar comentarios más antiguos
Hello,
I design an electric motor with Ansys Maxwell and in order to optimize it I have the optimization code writen in Matlab which I have coupled with Ansys Maxwell.
In every iteration of the optimization Matlab puts different values to the variables (according to the optimization method) I use for the design and sends them to Maxwell. Then Maxwell computes the FEA analysis and sends back the results to Matlab.
For my optimization I want to have 30 particles (code PSO) and 40 iterations, which means that there will be a bit more of 1200 FEA from Maxwell to be computed. Every time Matlab has the new variables ready it calls Maxwell to open the project I want to run the FEA on and after the computation is completed the results are sent to back Matlab and the Maxwell project cloeses. The project is called to open again for the next FEA and the same procedure continues until the end of the optimization.
The problem which comes up is this. After a number of iterations are completed, suddenly Matlab cannot call the Maxwell project to open and I get the fallowing error:
Error using Interface.4824CFB6_4885_4ECF_B6C8_314CC7C0C148/OpenProject
Error: The remote procedure call failed.
Error in ObjectiveFunction (line 13)
oProject = invoke(oDesktop,'OpenProject',[project_path project_name '.aedt']);
Error in PSO_myTry_withParameters (line 100)
Run_objF = fobj(currentX);
Error in main (line 27)
[ GBEST , cgcurve , objective_total ] = PSO_myTry_withParameters( noP , maxIter, problem , visFlag) ;
This depending on the optimization code used each time happens at a different iteration. For example, when I use PSO (30 particles - 40 iterations) happens during the 20th iteration, although it has started computing FEA normally in that iteration. Also, in 3 different computers it occured in the same iteration, during the 20th. In that iteration about 570 FEA have been computed by Maxwell and 570 times the project has been opened and closed.
Acoording to the above error it is Matlab that cannot continue working properly. At first I thought that I may keep a lot of information in arrays and probably after a number of info stored Matlab crashes, so I put the code to keep as less info as possible but still the same problem occured.
I also changed the path of the Maxwell problem and put it in the same folder with the Matlab scripts but again the problem occured.
Has anyone come up with a similar problem? Can anyone help me with this inconvenience?
Thank you beforehand.
15 comentarios
Walter Roberson
el 26 de Feb. de 2022
Could you confirm that you are using activexserver calls? And not for example, a .NET assembly?
Georgios Krassakopoulos
el 26 de Feb. de 2022
Walter Roberson
el 26 de Feb. de 2022
I find evidence that ANSYS uses .NET internally, so it is plausible that it might be possible to invoke it through an assembly. Or perhaps you could use System.Diagnostics.Process and send commands standard input?
Walter Roberson
el 26 de Feb. de 2022
Do you need to "close" the geometry or project?
Could you open it just once and leave it open until the end?
Georgios Krassakopoulos
el 26 de Feb. de 2022
Editada: Walter Roberson
el 1 de Mzo. de 2022
Walter Roberson
el 26 de Feb. de 2022
As an experiment, try creating the ActiveX at the beginning of your program and delete after, leaving it open every time, but still opening and closing the project each cycle.
You might want to onCleanup to be sure of killing the ActiveX session on error.
Georgios Krassakopoulos
el 26 de Feb. de 2022
Walter Roberson
el 26 de Feb. de 2022
in main assign to iMaxwell and right after you do so
cleanme = onCleanup(@()delete(iMaxwell));
Then use https://www.mathworks.com/help/matlab/math/parameterizing-functions.html to define an anonymous function @(x) ObjectiveFunction(x,iMaxwell) and arrange to have that invoked by your pso instead of ObjectiveFunction directly. Now add iMaxwell as a second parameter to ObjectiveFunction
inside ObjectiveFunction you are now getting iMaxwell passed in, so remove the activex call there. Just go ahead and do the invoke() calls.
At the end of ObjectiveFunction do not delete or clear iMaxwell
You do not need to explicitly delete iMaxwell in main() when you are done with it, as long as main() is a function rather than a script. When main terminates due to normal return or due to error somewhere, the local variable cleanme will get automatically deleted. But the onCleanup action in it will get triggered along the way, and that anonymous function will delete(iMaxwell)
It is slightly convoluted but really not bad if you are familiar with paramaterizing functions which is a significant technique in MATLAB that you should get accustomed to.
Georgios Krassakopoulos
el 1 de Mzo. de 2022
Georgios Krassakopoulos
el 1 de Mzo. de 2022
Walter Roberson
el 1 de Mzo. de 2022
Editada: Walter Roberson
el 1 de Mzo. de 2022
I did say,
"You do not need to explicitly delete iMaxwell in main() when you are done with it, as long as main() is a function rather than a script."
but you used a script insted of a function. You really should put that inside a function for automatic cleanup to work.
This does not explain why the RPC server is failing, but does affect whether the iMaxwell connection is automatically cleaned up when a problem occurs.
I do not have ANSYS.. I also do not use Windows much (except for the occasional game)
Georgios Krassakopoulos
el 17 de Mzo. de 2022
supriya Naik
el 3 de Mayo de 2022
Hello sir,
I need some help regarding PSO optimization in ANSYS Maxwell. Can you help me in coding how to add PSO in optimization process through ansys maxwell? Can you please share your basic step of this coding?
supriya Naik
el 19 de Mayo de 2022
@Georgios Krassakopoulos, Hello sir, Can you explain what is "Data Filter" in objective function matlab coding?
hou wa wong
el 29 de Jul. de 2022
hi, i also used the PSO to optimize by using maxwell and matlab. The reason why the RAM become large every time iteration increasing, is that there is a ansys lincense problem. you can just restart the maxwell. For me, i used below command
Desktop.QuitApplication;
clear iMaxwell
clear Desktop
here, you must clear the iMaxwell and Desktop, otherwise, you cannot use command to open maxwell again.
Respuestas (1)
Serhat Duman
el 4 de Mzo. de 2022
0 votos
I taken error as follow:
Error using Interface.2F9C9B95_5169_4291_A70B_5F095D3FEFA6/invoke
Check for incorrect argument data type or missing argument in call to function 'SetVariableValue'.
How can I define the variable from matlab to ansys?.
9 comentarios
Walter Roberson
el 4 de Mzo. de 2022
invoke(oProject,'SetVariableValue','$Do_new', Do_mat);
Serhat Duman
el 4 de Mzo. de 2022
How can I write this code in ANSYS maxwell 2016.
Serhat Duman
el 4 de Mzo. de 2022
This code didn’t work in ANSYS maxwell 2016.
Walter Roberson
el 4 de Mzo. de 2022
Sorry, I do not have any experience with ANSYS
Georgios Krassakopoulos
el 17 de Mzo. de 2022
supriya Naik
el 10 de Mayo de 2022
Error using Interface.4E4ADE7E_0FB6_430F_9D1B_1A66C6A69953/GetPropertyValue
Error: Object returned error code: 0x80070202
Can you explain what is the meaning of this error during interfacing of matlab and ansys.
Walter Roberson
el 10 de Mayo de 2022
error code: 0x80070202 seems to be a custom error code, not a standardized code.
I find it used in a small number of different products; software seems to use it to mean that something was not supported (such as a request to interface an unsupported laser scanner.) I do not know if that is relevent.
supriya Naik
el 13 de Mayo de 2022
Is it possible to avoid it?
Walter Roberson
el 13 de Mayo de 2022
I do not know.
In http://www.edatop.com/hfss/32309.html it appears that for that software the cause is a resource being used by a different program.
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!