Matlab optimization with Ansys APDL

13 visualizaciones (últimos 30 días)
cristian Massaua
cristian Massaua el 19 de Nov. de 2019
Comentada: ARJUN el 24 de Feb. de 2023
Hi, I need to do a bearings arrangement optimization on a shaft. For this master thesis work i use Matlab to write a FEMin.txt file containing all the Ansys APDL commands, after the writing of this input file MATLAB should launch the Ansys solver, read the macro, write the results.txt file, read the file and perform an multiobj optimization. The main problem of my script is when I call the Ansys solver, no results file was written. If I launch Ansys apdl from my desktop icon and select: file->read input from-> FEMin.txt the program do what I want, perform the analysis and write the results.txt file in the right folder, so i think that the macro file is correct.
I tried this commands to run ansys by matlab:
1)first command i tried
system('SET KMP_STACKSIZE=10240k & "C:\Program Files\ANSYS Inc\ANSYS Student\v195\ANSYS\bin\winx64\ANSYS195.exe" -b -i "FEMin.txt" -o "FEMout.txt"');
set KMP_STACKSIZE to 10240k to avoid memory to run out, than i run the Ansys solver in bach mode (-b) and specified the input file (-i) and the output file (-o)
when i run this command only input and output files were written, reading the FEMout.txt file the simulation seems to be done but ansys can't output the results.txt file...
2)second command i tried
This time i use the ansys launcher to set the user preference like ammount of memory, directory ecc. and going to option->display the command line i copy the command :
system('"C:\Program Files\ANSYS Inc\ANSYS Student\v195\ansys\bin\winx64\MAPDL.exe" -g -p aa_t_i -smp -np 2 -lch -dir "C:\Users\ALIENWARE\Desktop\simulation_fem" -j "file" -s read -m 10240 -db 10240 -l en-us -t -d win32 -b -i FEMin.txt -o FEMout.txt')
this command works like the command above, perform simulation but no results.txt file is write.
I read in other threads that STACKSIZE could be the problem but i have allready set the STACKSIZE over the default 512K when launching the ansys solver.
Another problem is that calling the ansys solver every time that i write a macro slow down my otimization. In ansys environment if i read the input file form FEMin.txt the simulation takes only 0,7s to be done including writting the results file! Maybe there is another way to run my optimization faster?
I hope someone can give me some advise to solve my problem.
ps, I'm using Ansys 19r3 and Matlab R2019b,
i have performed CFD optimization in the same way with Fluent (system(['"C:\Program Files\ANSYS Inc\ANSYS Student\v195\fluent\ntbin\win64\fluent.exe" 2ddp -t4 -g -i Journal_Fluent.jou'])) and i haven' t this input reading problem..
  2 comentarios
Pedro Pesante Castro
Pedro Pesante Castro el 14 de Jun. de 2021
Hi Cristian, how has resulted your job?
I'm trying to optimize some material properties into a APDL script using MATLAB, in order to adjust (minimize error) with the experimental results.
Can you share some information about your project with me? What type of optimization algorithm has you used?
Regards
cristian Massaua
cristian Massaua el 17 de Jun. de 2021
Hi Pedro, i've performed the APDL simulations directly from Ansys, launching in sequence the first macro n_file.txt that ends with ( *USE ,'next macro n+1_file.txt directory'), in this way you need to write first all the macro you need, then start manually Ansys APDL and open the first macro, than the program run automatically all the macro (416 in my case), perform the simulation and write the result files.
For the optimization i wrote another script in Matlab that read all the result.txt files and assign the fitness function at each simulation. I turned my optimization in to a min-min problem, i was looking for minimization of two objective defined by my fitness function; with a min-min problem is possible to define a pareto front like this:
In this picture you can see the pareto front (black line) and the base configuration (red dot), there is a region delimited beetwen the pareto front and the dotted lines containing all the configuration that are better at least in one of the two objective function (value minor copared to base config. ) I put this configuration in a normalized graph with the base configuration on the origin and put new improovement function (i turn the graph in to a max-max problem simply using the opposite of the fitness function improovement function(max)=1/fitness function(min))
In this picture you can see the normalized graph and the pareto front with the 3 configuration choosed as the results of this optimization analisys (1° choice= best in the second improovemnt function but worst in the first improovement function, 3°choice=best on the first improovement function but worst on the second improovement function,2° compromized configuration beetween 1° and 2° choice)
I hope this can be useful to you.

Iniciar sesión para comentar.

Respuestas (2)

cristian Massaua
cristian Massaua el 17 de Jun. de 2021
Hi Pedro, i've performed the APDL simulations directly from Ansys, launching in sequence the first macro n_file.txt that ends with ( *USE ,'next macro n+1_file.txt directory'), in this way you need to write first all the macro you need, then start manually Ansys APDL and open the first macro, than the program run automatically all the macro (416 in my case), perform the simulation and write the result files.
For the optimization i wrote another script in Matlab that read all the result.txt files and assign the fitness function at each simulation. I turned my optimization in to a min-min problem, i was looking for minimization of two objective defined by my fitness function; with a min-min problem is possible to define a pareto front like this:
Pareto front
In this picture you can see the pareto front (black line) and the base configuration (red dot), there is a region delimited beetwen the pareto front and the dotted lines containing all the configuration that are better at least in one of the two objective function (value minor copared to base config. ) I put this configuration in a normalized graph with the base configuration on the origin and put new improovement function (i turn the graph in to a max-max problem simply using the opposite of the fitness function improovement function(max)=1/fitness function(min))
Normalized graph
In this picture you can see the normalized graph and the pareto front with the 3 configuration choosed as the results of this optimization analisys (1° choice= best in the second improovemnt function but worst in the first improovement function, 3°choice=best on the first improovement function but worst on the second improovement function,2° compromized configuration beetween 1° and 2° choice)
I hope this can be useful to you.
  1 comentario
ARJUN
ARJUN el 24 de Feb. de 2023
Hi, for connecting the apdl and matlab, is there any procedures

Iniciar sesión para comentar.


yu tian
yu tian el 30 de En. de 2020
Hey boy, I am very interesting in your problem, and there are some advice I will give to you, maybe it will be useful to you.
Problem one: no results.txt file is write.
Advice one: you must write down the APDL command in your "FEMin.txt", you can get some information about the command "*vwrite" , then your data or parameters which are produced in the process of ANSYS can be write in the results.txt , after that you can read the results.txt to your matlab. And the two command you tried are both OK.
Problem two: slow down optimization
Advice two: To be honest, I find it too and I dont know how to run it faster, an alternative method is to use the ";" to avoid the command window output of matlab, the optimization process may be faster than it not apply. Meanwhile, I am finding some approaches to solve this drawback, if you have some novel advice or method, welcome to share it with me.
I hope these words can be useful to you, good luck.
  1 comentario
ferdaous TRIBAK
ferdaous TRIBAK el 24 de Nov. de 2022
Hi Yu Tian, can you help me to solve my problem? I made a simulation in ansys workbench; then I transferred it to APDL. Now I need to link it to matlab so I can work on the optimization, can you give me a hand?

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by