×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Genetic Algorithms in Ansys

Genetic Algorithms in Ansys

Genetic Algorithms in Ansys

(OP)
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.

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

(OP)
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.

RE: Genetic Algorithms in Ansys


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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

RE: Genetic Algorithms in Ansys

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources