How to use a Zlanguage script in optimizer ?#

One can use zLanguage base package inside an optimization loop. Let us consider the following differential system :**

\[\frac{\partial\chi}{\partial x}=B+A\sin(x)\chi(x)\]

The optimization problem to be solved is to find parametres \(A\) and \(B\) so that curve \(\chi=f(x)\) fits a predefined “experimental” result.

First write a script solving this differential system for any parameter \(A\) and \(B\) (these parameters are loaded from a file names ’solve.dat’) ,:

void main()
{
  VECTOR vx,vy;
  double ti,tf;
  global double A,B;

  data_file.load_globals("solve.dat");
  runge.eps_r=.001;
  runge.ymax_r=.001;
  vy.resize(50);
  vx.resize(vy.size());
  ti=0.; tf=2.;
  vy[0]=0.;
  runge.integrate(derivative,ti,tf,vx,vy,vx.size());
  data_file.output_vectors("solve.test",vx,vy);
}

void derivative(double time, VECTOR chi, VECTOR dchi)
{
  dchi.resize(1);
  dchi[0]=B+A*sin(time)*chi[0];
}

In file ’solve.dat.tmpl’, just put (as usual with zOptimizer) the unknowns :

A ?A
B ?B

And use the following input file (with ’Zrun -o’ command) to find \(A\) and \(B\) :

****optimize sqp
  ***files solve.dat
  ***shell Zrun -zpt opti.z7p 2>&1 > /dev/null
  ***values
    A 5. min .5 max 50.
    B 10. min 1. max 100.
  ***compare
    g_file_file solve.test 1 2 solve.ref 1 2 weight 50.
****return

An example using zLanguage/zMaster and zOptimiser#

The goal of this problem is to optimize geometrical parameters of a turbine disk to lower both mises equivalent stress and mises equivalent strain. The axisymmetric geometry, with two unknown parameters A and B is the following :

../../_images/disk.svg

The mesh script file (named ’mesh.z7p’) is the following :

void main()
{
  global double A,B;
  double dl;
  POINT a,b,c,d,ee,f;
  LINE l1,l2,l3,l4,l5,l6;
  LISET li;
  DELAUNAY domain;
  RENUMBERING renum;

  data_file.load_globals("AB.dat");
//
  dl=3.;
//
  a.x=30.; a.y=0.;
  b.x=a.x+120.; b.y=0.;
  c.x=b.x; c.y=30.;
  d.x=B+15.; d.y=A;
  ee.x=B-15.; ee.y=A;
  f.x=a.x; f.y=30.;
//
  l1.bind(b,a); l2.bind(c,b);
  l3.bind(d,c); l4.bind(ee,d);
  l5.bind(f,ee); l6.bind(a,f);
//
  l1.set_nodes(int(l1.length()/dl)+1,1.);
  l2.set_nodes(int(l2.length()/dl)+1,1.);
  l3.set_nodes(int(l3.length()/dl)+1,1.);
  l4.set_nodes(int(l4.length()/dl)+1,1.);
  l5.set_nodes(int(l5.length()/dl)+1,1.);
  l6.set_nodes(int(l6.length()/dl)+1,1.);
//
  domain.add(l1); domain.add(l2);
  domain.add(l3); domain.add(l4);
  domain.add(l5); domain.add(l6);
  li.add(l1); li.name="bottom";
//
  domain.link(); li.link();
  domain.mesh.name="disk.geof";
  domain.element_type="cax6";
  domain.name="disk";
  domain.remesh();
  renum.renumbering(domain.mesh);
  domain.mesh.save();
}

The file ’AB.dat.tmpl’ only contains :

A ?A
B ?B

The finite element input file (’mesh.inp’) is :

****calcul
  ***mesh
    **file disk.geof
  ***resolution newton
    **sequence
      *time 100.
      *algorithm eeeeee
      *increment 1
      *iteration 10
  ***bc
    **impose_nodal_dof
      bottom U2 0.0
    **centrifugal ALL_ELEMENT (0. 0.) d2 1.e5 time
  ***material
      *file mesh.inp
****return

***behavior linear_elastic
 **elasticity
     young 200000.0
     poisson 0.3
 ***coefficient
   masvol 1.e-6
***return

****post_processing
  ***local_post_processing
    **elset ALL_ELEMENT
    **output_number 1
    **file integ
    **process mises sig
    **process mises eto
  ***global_post_processing
    **output_number 1
    **elset ALL_ELEMENT
    **file integ
    **process max sigmises
    **process max etomises
****return

And the optimizer input file (’opti.inp’) is :

****optimize sqp
  ***files AB.dat
  ***shell
    Zrun -B mesh.z7p
    Zrun mesh
    Zrun -pp mesh
    ./traite.csh
  ***values
    A 30. min 16. max 49.
    B 90. min 46. max 134.
  ***compare i_file_file mesh.post 1 mesh.ref 1 weight 50.
****return

The file ’mesh.ref’ is supposed to contain the following lines (it represents the ’objective’, ie the best mises value which is zero in this case) :

0.
0.

The shell script named ’traite.csh’ slightly transforms post processing result file to make comparison easier :

#!/bin/csh
awk '(NR==3)||(NR==6) { if(NR==6) fact=1.e5;
  else fact=1.; printf("%f\n",$2*fact); }' mesh.post > mesh.res

This optimization problem leads to the solution \((A=49.,B=46.)\).