How to use a Zlanguage script in post_processing ?#

The main drawback in using zLanguage scripts is that l is an interpreted language. It provides high functionality to dynamically detect runtime errors such as : type checking, generic pointers, array bounds errors …But these checks require time to execute : an interpreted script will never be as fast as the corresponding binary executable.

zLanguage syntax is very close to C++ syntax which is the language used to write ZSet. All l objects are in fact only tiny wrappers to handle the underlying existing C++ classes. It is then pretty easy to write a C++ class, having a script. ZSet incorporates a module which does this work automatically.

Let us suppose the the user has a working local post-processing script which computes the Mises equivalent stress. It is possible to build a C++ file and then a dynamic loadable library which will be automatically loaded by ZSet.

The starting script is :

ARRAY<string> input()
{
  ARRAY<string> i;

  i.resize(4); i[0]="sig11"; i[1]="sig22"; i[2]="sig33"; i[3]="sig12";
  return(i);
}

ARRAY<string> output()
{
  ARRAY<string> o;

  o.resize(1); o[0]="ffmises";
  return(o);
}

void initialize()
{
  global double max_mises,min_mises;

  max_mises=-MAX_DOUBLE; min_mises=MAX_DOUBLE;
  cout<<"Initialization : \n";
  cout<<"Max mises ="<<max_mises<<"\n";
  cout<<"Min mises ="<<min_mises<<"\n";
}

void destroy()
{
  global double max_mises,min_mises;

  cout<<"Max mises ="<<max_mises<<"\n";
  cout<<"Min mises ="<<min_mises<<"\n";
}

void compute()
{
  TENSOR2 sigma;
  global double max_mises,min_mises;
  double mises;

  sigma.reassign(4,in,0);
  sigma.add_sqrt2();
  mises=sigma.mises();
  if(mises<min_mises) min_mises=mises;
  if(mises>max_mises) max_mises=mises;
  out[0]=mises;
}

This script requires 7.8 seconds to execute on a medium sized 2D mesh (the real characteristics of the mesh and of the computer doe not matter). This script is stored in a file named post.z7p. The following lines go in a file named convert.inp :

****zpconv
  ***source_file post.z7p
  ***output_file A_post.c
  ***type local_post
  ***class_name APOST
  ***keyword z7plocalpost
****return

When the user launchs Zrun -zpconv convert, ZSet will analyze the script post.z7p and will generate a C++ class in A_post.c. This file can then be automatically compiled and inserted into a dynalic library (exactly the same way that a user will generate a dynalic library starting from some ZebFront source files).

The previous three stars commands are :

  • **source_file : gives the name of the script to be converted

  • **output_file : the C++ output file

  • **type : the kind of module to be produced.

  • **class_name : the C++ class name. User can choose about all names.

  • **keyword : the keyword associated with the C++ class.

After the dynamic library is built, the user may use the local post processing named z7plocalpost as every other post-processing criterions.

Note

this converter is in a beta version ! Use it at your own risks, and do not hesitate to contact Z-set developers for more informations.

The same post-processing execution (ie same problem, same computer) using the dynamic library (insted of the interpreted script) requires only 0.79 seconds (speed-up of a factor 10).