Wednesday, March 11, 2015

Optimizing by ANSYS - Objective Function Defined by Other Software

Key Points:

  1. You have an objective function to be optimized (to find a minimum/maximum point)
  2. But the function is defined by a software other than ANSYS
  3. The function doesn't have a mathematical formula


Suppose you have an objective function which is defined by a complex software, say an FEM or CFD software. The function has one or several variables, and the function generates different values regarding different variable values input.

Basic idea of the solution is by using /sys command in ANSYS APDL code which let ANSYS to invoke your software, and evaluate the function. ANSYS will invoke your software repeatedly until it finds a minimum/maximum point.

Key points for data transfering from ANSYS to your software and vice versa:
1, Your software that defining the objective function should parameterizing the model (the function), so that it can accept one or more parameters and generates the function value.
2, Your software should have a way of passing value to parameter(s), such as command line or an input file.
3, Your software should have a way of passing back the function value, such as program exit code or an output file.

Here is an example of the solution with the way of passing value that passes data by input/output file.

TASCA is the software which defines the objective function. "tascain.txt" is the input file, and tascout.txt is the output file.

vwrite puts the value of X to the input file. Then the code invokes TASCA. TASCA will read the data from "tascain.txt", and evaluate the function, and then writes the function value to "tascaout.txt". The function value will be read from the file and stores in A1 and V.

FILE: volu.inp
*DIM, A1, array, 2,1

X=1.4

*cfopen, tascain,txt
*vwrite, X
(F10.2)
*cfclose

/sys, TASCA evaluate

*vread, A1(1,1), tascaout,txt, c:\working, JIK, 1,1
(F6.2)

V=A1(1,1)


The following shows the optimization control file. V defined as the objective function. The makes ANSYS to find the minimum value of the objective function. To start optimization, type these command in the command input box of the ANSYS: /input, optovlu,inp .

FILE: optvolu.inp
/clear,nostart
/input,volu,inp
/opt
opanl,volu,inp
opvar,X,dv,1.3,1.9,1e-2
opvar,V,obj,,,1e-2
opkeep,on
optype,subp
opsave,optvolu,opt0
opexec