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!

Genetic Algorithms in Ansys 1

Status
Not open for further replies.

jpblasques

Marine/Ocean
Nov 24, 2006
20
0
0
DK
Hi all

I need to optimize laminates in regards to thickness and orientation and I thought about applying genetic algorithms. I am modelling a marine composite propeller blade in ANSYS and using APDL.
I thought about building the genetic algorithm in APDL but not really sure if it is possible, has anyone tried?
I considered Topology Optimization but that is very limited in ANSYS, anyone has used any other methods to solve a similar problem?
What about linking to MATLAB's genetic algorithm tool, has anyone tried?

Thanks very much in advance.
 
Replies continue below

Recommended for you

Hi,

I have programmed in APDL a topology optimisation algorithm, so I am shore, one could also implement a genetic algorithm.

Coupling Ansys an Matlab should work too, but I've never done it.

Regards,
Alex
 
Thanks, that's very nice to know. Now I just have to work it out in APDL. I have read that it is truly time consuming this method, do you suggest any alternative?

Thanks once again.
 

The alternative is like you said, coupling Ansys and Matlab. But can't help you with this. If still want to do it with APDL, take a look at the very powerfull commands *V.... and *M....

Alex
 
I used Matlab yo optimized a simulation in Ansys, you need the next: a started, a macro in Ansys and a batch. To optimize I used nsga-II an algorithm created by Deb. I did the next:

In the file in Matlab call the batch:
function vo=fv(x)
%Generate the file for ANSYS
%Open the file batch.mac to write
fid=fopen('batch.mac','w');
%Write the initial part of the file
fprintf(fid,'MACRO_NAME, ');
%Write the first variable
fprintf(fid,num2str(x(1)));
% Write the separation betwend variables
fprintf(fid,', ');
% Write the second variable
fprintf(fid,num2str(x(2)));
% Write the separation betwend variables
fprintf(fid,', ');
% Write the third variable
fprintf(fid,num2str(x(3)));
% Write the separation betwend variables
fprintf(fid,', ');
% Write the forth variable
fprintf(fid,num2str(x(4)));
%Close the file batch.mac
fclose(fid);
%Launcher ANSYS with a file
dos('LAUNCH.BAT');

In LAUNCH.BAT write:
"C:\Program Files\Ansys Inc\V100\ANSYS\bin\intel\ansys100" -b -i BATCH.MAC -o OUT.out

In batch.mac in only one line:
Macro_name, ARG1, ARG2, ARG3, ARG4 (I used 4 variables to optimize in Ansys)

Then:
%Read the solution file of Ansys ANSYS
%Open Solution.txt to read
fid=fopen('Solution.txt');
%Do what you need: initialize, read…
………
%Close file Solution.txt
fclose(fid);
%Make the out vector
vo=[solution(1),solution(2)];

Then write nsga-II in Matlab and the algorithm minimize vo. I hope that this help you.
Regards,
Playu
 
Hello Playu,

how do the optimization program knows, when the result file from ansys is ready? I mean, Matlab must wait until Ansys computes the solution. How it knows, when the solution is ready?

Regards,
Alex
 
Hello mihaiupb,
the algorithm is a multi-objective optimization function where the input arguments are:
pop - Population size, p.e.100
gen - Total number of generations,p.e.50
then matlab run ansys in this case 50*100 times, you will get pareto front with the optimals solutions, and not run more cases, the problem is that with more pop and gen the optimals are better but you take more time...
Regards,
Playu
 
So the parameters for Ansys are known before Optimization starts. So it is a one way coupling form matlab to ansys.

I asked this question, because in some other cases one need to exchange information between ansys and matlab and vice versa. In this case matlab must wait until ansys solves and writes the results and then compute the new set of parameters for ansys and start a new batch run.

I wanted to know, if there is a way to put matlab on "waiting", other then an empty for loop.

Regards,
Alex
 
The parameters for Ansys are known before Optimization starts but only to initialize Ansys, and then there is exchange information between ansys and matlab and vice versa.
I’m not sure about your question, perhaps matlab can “waiting” if you make a parallel computation but I've never done it.
Regards,
Playu
 
Hi,
it seems to me that Playu implicitly replies to a question that arose some time ago, always on the theme about linking Ansys to Matlab or Mathematica.
So, as I understand it, if you write a Matlab routine which contains a system call to an external application, this application will run synchronously (i.e. the parent application will wait for the called application to finish before continueing execution). I believe this depends upon how Matlab external calls work. For example, it seems not to be the same in Mathematica (Mathlink), unless probably you set some flags.
For the moment, I have no clear idea on what happens if you call an external application from an APDL in Ansys: will it run synchronously also, or asynchronously so that the APDL continues "on its own" without waiting for external task's completion?

However, thanks to Playu for enlightning this aspect which, I believe, may interest a lot of users.

Regards
 
Thanks cbrn,
that is exactly how it works, with this method you can call another programs like ADAMS which run or solver anything and when Matlab finish, read the solution and calculate or optimize. I don't know how Ansys can call an external application to do something... sorry. But I hope that the other method will be useful for anybody.
Regards,
Playu
 
Status
Not open for further replies.
Back
Top