Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Matlab from Ansys input file? 1

Status
Not open for further replies.

plvachon

Mechanical
Jun 16, 2005
38
0
0
CA
Hi,

I need to solve an equation (numerically) in Ansys... May I call a Matlab session from an Ansys input file, and then use the solution from Matlab to continue the process in Ansys? In other words, I must find the value(s) of x for which f(x)=y, with y known. I mention that f(x) is a complicated equation and it is not possible to isolate x "symbolically".

Thanks in advance...
 
Replies continue below

Recommended for you

Hi,
as far as I know, you may be able to call an "exit" towards the Operating System, but the new process will be seen as "son" of the main Ansys session. In other words, I doubt that you would be able to open the Matlab executable in such a way, at least not the one you usually launch from Windows GUI.
BUT usually these math programs offer you a way to access the kernel without launching the whole program. With Mathematica, for example, you can do it with Mathlink. This is the kind of executables which can be launched from a "parent" application, receive input parameters and restitute output parameters as well.
This is a very interesting topic; if I have time, I'll have a look on Ansys' side... If you come through the problem, please let us know!

Regards
 
This may prove difficult to do but if it could be done I think the /SYS and/or /SYP commands are the only way for Ansys to communicate with the operating system. Is it not possible to solve this complex equation with APDL?
 
Hi,
Plvachon, Stringmaker's suggestion is valuable in the sense that you can write any equation solver with APDL as you would do with Visual Basic for example: you can write, for example, your own Newton-Raphson algorithm for iterative solution search. Of course, you won't have built-in functions as you would have with math kernels.

Regards
 
Thanks Cbrn and Stringmaker. I will write a Newton-Raphson algorithm. But it would have been interesting to solve with an existing solver!

Regards.
 
Plvachon, see the APDL section and list of commands in the Ansys documentation. There is a vast collection of both logical and vector/matrix operational commands which when coupled together can most likely do exactly what you're interested in. Most of these commands begin with an asterisk (e.g. *DO, *ELSE, *IF, *VFUN, *VOPER).

Good luck!
 
Hi,
I tried to find more info about how Ansys could link to a math program, but there is very little about it in the Help.
As Stringmaker said, the way you can call the math kernel is /SYS or /SYP depending on the need to pass arguments or not. As I understand it, these arguments could be the parameters for your equation, depending on how the math-kernel link works; comand-line "options" like those which begin with a "-", for example "pkzip -a -d", should be included in the "string" part of the /SYP command. I have serious doubts about if the arguments would be re-read back in Ansys after the /SYP command execution or not: I strongly don't think so... Another doubt is if Ansys will wait for the end of the sub-session execution or not (i.e. if the /SYP call is synchronous or not), before continueing the macro execution. If the sub-session is asynchronous, you have no chance to accomplish what you need (well, there would be the trick to insert a "pause" with the /WAIT command, once you know approximately the time needed by Matlab to open, process and close). If instead it is synchronous, then you could try to have Matlab read the params from file (written by Ansys' APDL just prior to issue the /SYS or /SYP command) and write the results to another file (which would be read by Ansys' APDL right after the sub-session execution, thus controlling the attribution of the values to the correct parameters). For example, with Mathematica (Mathlink), you write an "executable macro" similar to an Ansys command file, which includes all the Mathlink commands needed for your specific task: in this example, the /SYP command would call this macro, which in its turn would perform some Mathlink-compatible operations (open a file, read data, format data, process data, write output to file). Probably something similar is possible with Matlab. I fear this will be more difficult than writing the Newton-Raphson solver...

Regards
 
Hi all,

I am glad that this topic is discussed, because I had the same problem. System of general equations ideal for symbolic Newton-Raphson solution in Matlab, but I needed it in Ansys during solution time-steps.

My system of equatin was dependent on 3 input parameters provided by Ansys /POST and it should return many results which were to be used for updating Ansys BCs.

After all I used Matlab for generation of 3D matrices (each dimension for one input) to calculate all possible combinations sufficiently fine. One 3D matrix for one result parameter. These matrices were saved in *.txt and read by Ansys as tabular input. Then they can be used for interpolation .....

It is not so clear solution like you are looking for but it works.

Good luck to you all, with regards H-up.




 
Status
Not open for further replies.
Back
Top