
Introduction:

Automatic code generation is a way to create safe, clean and consistent code. Class specifications are a common thing we wish to specify in a code and are often very repetitive to program. Thus, we use autogenerated C code to define them.

In patin, we use auto generated code to define
- material constants
- quadrature point fields
- material point fields

All these data types are ultimately represented as an array of structs.
The autocode generator
  python/swarm_class_generator.py
can be use to generate the definition of the struct for these fields and also the necessary getter/setter functions to access and set values within the struct.
Support is provided for VTK visualization (which is probably only relevant for marker fields).


Steps Required:

To create a class one must write a small python function which
1/ defines the contents of the struct
2/ defines the names of the members in the struct (as they will appear in the header)
3/ defines the data type of each member (and size if they are an array) in the struct
4/ defines textual names which will be used in the getter/setter functions
5/ Pass this information to the function
  PARTICLE_CLASS_GENERATOR()
which writes out the C code.

6/ Call your new function at the bottom of the python script

7/ Execute the python script
  python swarm_class_generator.py

8/ Edit the autogenerated file and remove the line
  #error(<<REMOVED AUTOGENERATED TAG>> ================== FILE
This is added to cause compilation to crash. It is recommended to leave the comment
/*
  Auto generated by version 0.0 of swarm_class_generator.py
  on otsu.local, at 2013-01-28 10:29:08.937957 by dmay
*/

which serves as a means to track bugs/changes which may arise as the class_generator.py file is modified.

9/ Register your new type.

a) For material constants, open
  material_constants.c
and edit the function
  MaterialConstantsInitialize()

b) For material point properties, open
  ptatin3d.c
and edit the function
  pTatin3dCreateMaterialPoints()

c) For quadrature point properties, open
  quadrature.c
and edit the function
  VolumeQuadratureCreate_GaussLegendreStokes()



Example:

An example is shown below for specifying a struct

def Generate_pTatin_MaterialConst_MaterialType():
	ClassName      = 'MaterialConst_MaterialType'
	ClassNameShort = 'MaterialType'
	variable_names =          [ 'visc_type', 'plastic_type','softening_type' , 'density_type' ]
	variable_types =          [ 'int'      , 'int'         , 'int'           , 'int'          ]
	variable_extents        = [ 1          , 1             , 1               , 1              ]
	variable_textural_names = [ 'visc_type', 'plastic_type', 'softening_type', 'density_type' ]

The files generated will have the name
  MaterialConst_MaterialType_def.c
  MaterialConst_MaterialType_def.h

ClassName : Defines the name associated with typedef'd struct
ClassNameShort : Short name for the class (not currently used)
variable_names : List of variable names which will appear in the struct
variable_types : C type of each variable {char, int, long int, float, double
variable_extents : Indicates array size of variable. If one is selected, variable is treated as A, not A[1]
variable_textural_names : Human readable names for variables. These are used in creating the getter/setter functions for each variable.

From this struct definition above, the autogenerator creates these types

typedef struct {
  int visc_type ;
  int plastic_type ;
  int softening_type ;
  int density_type ;
} MaterialConst_MaterialType ;


typedef enum {
  MaterialType_visc_type = 0,
  MaterialType_plastic_type,
  MaterialType_softening_type,
  MaterialType_density_type
} MaterialConst_MaterialTypeTypeName ;


and these getter/setters

void MaterialConst_MaterialTypeGetField_visc_type(MaterialConst_MaterialType *point,int *data);
void MaterialConst_MaterialTypeGetField_plastic_type(MaterialConst_MaterialType *point,int *data);
void MaterialConst_MaterialTypeGetField_softening_type(MaterialConst_MaterialType *point,int *data);
void MaterialConst_MaterialTypeGetField_density_type(MaterialConst_MaterialType *point,int *data);
void MaterialConst_MaterialTypeSetField_visc_type(MaterialConst_MaterialType *point,int data);
void MaterialConst_MaterialTypeSetField_plastic_type(MaterialConst_MaterialType *point,int data);
void MaterialConst_MaterialTypeSetField_softening_type(MaterialConst_MaterialType *point,int data);
void MaterialConst_MaterialTypeSetField_density_type(MaterialConst_MaterialType *point,int data);
void MaterialConst_MaterialTypeView(MaterialConst_MaterialType *point);





DAM ~Jan 28, 2013
