Jump to content

Recommended Posts

Hi all,


I'd like to use Matlab to control OptiStruct -- change design variables and run the analysis. My intent is to use numerical methods scripts I've written in Matlab and loop back and forth between Matlab and OptiStruct. The process would run as follows:


 


1. Matlab -- numerical methods algorithm takes in FEA results, outputs design variables


2. Optistruct -- takes in design variables, runs FEA and outputs results (.out file)


3. Repeat


 


Can anyone help me run OptiStruct from Matlab? More generally, does anyone have experience running OptiStruct externally?


 


Thank you in advance for any help!


 


Best,


Alex


RodrigoFST likes this

Share this post


Link to post
Share on other sites

Hi Alex,

 

Were you able to solve this? I want to run a code that changes the .fem file, calls optistruct to run the linear analysis and checks the compliance. After that it will repeat the process till it reaches convergence. How do you get matlab to run optistruct?

 

Thanks,

Rodrigo

Share this post


Link to post
Share on other sites

Hi,

 

This is very complicated but can be done:

 

%uploading a .fem to optistruct and reading punch file using matlab

%step 0 add punch card request(s) at the top of the file
% DISPLACEMENT(SORT1,PUNCH,REAL,NORMAL) = ALL                      
% ESE(PUNCH,PEAK) = ALL %element strain energies (for compliance optimization)
% GPFORCE(PUNCH,REAL) = ALL
% GPSTRAIN(PUNCH,GLOBAL,ALL) = ALL
% STRAIN(SORT1,PUNCH,REAL,ALL) = ALL
% STRESS(SORT1,PUNCH,REAL,ALL,CENTER) = ALL

%step 1 get path to fem
path_new_fem = "INSERT FILEPATH TO FEM FILE HERE";
%step 2 get path to optistruct
loc_opti = 'C:\Program Files\Altair\2017\hwsolvers\scripts\optistruct.bat';
%step 3 send to solver using system() or dos()
command_string1 = char(strcat('"',loc_opti,'" "',path_new_fem,'" -monitor'));
answer = system(command_string1);
%step 4 get path of the punch file
punch_path = 'INSERT FILEPATH TO PUNCH FILE';
%step 5 read the punch file
PCH = reading_punch(punch_path);

 

Using this code, matlab will run optistruct. One thing I have not included is the reading_punch code, which reads a punch file output from NASTRAN/OS. If you need this let me know, however I am certain punch file readers exist for matlab online already.

 

If you are going to do it this way, you will need many other scripts, including one which will take your input variables calculated by matlab and write them to an FEM file. The punch reader can be used to read outputs from OS to matlab such as stress etc. What you will need is heavily dependent on what you are trying to do.

RodrigoFST likes this

Share this post


Link to post
Share on other sites
On 1/21/2020 at 6:44 PM, Crashphys said:

Hi,

 

This is very complicated but can be done:

 

%uploading a .fem to optistruct and reading punch file using matlab

%step 0 add punch card request(s) at the top of the file
% DISPLACEMENT(SORT1,PUNCH,REAL,NORMAL) = ALL                      
% ESE(PUNCH,PEAK) = ALL %element strain energies (for compliance optimization)
% GPFORCE(PUNCH,REAL) = ALL
% GPSTRAIN(PUNCH,GLOBAL,ALL) = ALL
% STRAIN(SORT1,PUNCH,REAL,ALL) = ALL
% STRESS(SORT1,PUNCH,REAL,ALL,CENTER) = ALL

%step 1 get path to fem
path_new_fem = "INSERT FILEPATH TO FEM FILE HERE";
%step 2 get path to optistruct
loc_opti = 'C:\Program Files\Altair\2017\hwsolvers\scripts\optistruct.bat';
%step 3 send to solver using system() or dos()
command_string1 = char(strcat('"',loc_opti,'" "',path_new_fem,'" -monitor'));
answer = system(command_string1);
%step 4 get path of the punch file
punch_path = 'INSERT FILEPATH TO PUNCH FILE';
%step 5 read the punch file
PCH = reading_punch(punch_path);

 

Using this code, matlab will run optistruct. One thing I have not included is the reading_punch code, which reads a punch file output from NASTRAN/OS. If you need this let me know, however I am certain punch file readers exist for matlab online already.

 

If you are going to do it this way, you will need many other scripts, including one which will take your input variables calculated by matlab and write them to an FEM file. The punch reader can be used to read outputs from OS to matlab such as stress etc. What you will need is heavily dependent on what you are trying to do.

 

Thanks a lot for your help. I managed to do it the way you suggested.

Share this post


Link to post
Share on other sites

An example :

               cmd_str = ['"C:\Program Files\Altair\2020\hwsolvers\scripts\optistruct.bat"',' ','"Job.fem"'];
               system(cmd_str);

 

Good luck

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...