Write an Input Reader

The first step in the process of writing an input translator is to define an input format that needs translation. In this example, the definition of the input deck consists of a finite element model that comprises nodes, tria and quad elements, constraints, and forces. In addition, the elements have a property and a material associated with them, and the property and material information is also in the input deck. Given this information, a sample input deck may look something like this:
node, 1,   0.0,   0.0,   0.0
node, 2, 100.0,   0.0,   0.0
node, 3, 100.0, 100.0,   0.0
node, 4,   0.0, 100.0,   0.0
node, 5,   0.0,   0.0, 100.0
node, 6, 100.0,   0.0, 100.0
node, 7, 100.0, 100.0, 100.0
node, 8,   0.0, 100.0, 100.0
quad, 1, 1, 1, 2, 3, 4
tria, 2, 2, 5, 6, 7
tria, 3, 2, 5, 7, 8
property, 1, 1, 0.75
property, 2, 1, 1.00
material, 1, 20000.0, 0.3
hmcolor, component, 1, 9
hmcolor, component, 2, 10
hmname, component, 1, comp1
hmname, component, 2, comp2
hmname, material, 1, material
const, 1, 123456
const, 2, 123456
const, 5, 123456
const, 6, 123456
force, 3, 0.0, 0.0, 10.0
force, 7, 0.0, 0.0, 10.0

The task of writing an input translator is now defined. The entities that exist in the input deck must be transferred to HyperMesh; more specifically, the nodes, elements, constraints, forces, property, and material information must be translated into a format understood by HyperMesh. Given this objective, and with the use of the hminlib functions, it is now possible to write an input translator.

The source code for the example is listed at the end of the section. As the example progresses, it is recommended that you open your manual and flip to the end of the section in order to follow the source code while reading.

As described above, the structure of an input translator written with the program follows a specific format. The first step that an input translator must perform is to initialize hminlib. This is performed by calling the function HMIN_init(). Note that in the example source code below, the function main() calls HMIN_init(), which takes four parameters. The four parameters are the name of the translator, the version of the translator, and then the argc and argv parameters, which are passed into main(). Also note that HMIN_init() returns a pointer to the input file to be read. HMIN_setsolver() is then called to associate attributes with a given template (see *codename () in the template section).

In the next line of the program, control is passed to hminlib. This is accomplished with the function HMIN_readmodel(), which takes a pointer to a function as its only parameter. The function pointer points to a function from which hminlib can retrieve the user-defined functions used to read in an input file. For this example, refer to this function as the inquire function. Note that the inquire function, passed in HMIN_readmodel(), takes two arguments. The first argument, function, is the type of function hminlib is requesting. As described above, one of the user-definable functions is the open function, and the function returns fetestopen() when the value HMIN_OPENFUNCTION is requested. Prepare the inquire function to deal with the following values for function:

HMIN_OPENFUNCTION

HMIN_ENTITYOPENFUNCTION

HMIN_ENTITYGETFUNCTION

HMIN_ENTITYDICTIONARYFUNCTION

HMIN_ENTITYCLOSEFUNCTION

HMIN_COLORFUNCTION

HMIN_NAMEFUNCTION

HMIN_MOVEFUNCTION

HMIN_CLOSEFUNCTION

The second parameter only applies to the entity functions, HMIN_ENTITYOPENFUNCTION, HMIN_ENTITYGETFUNCTION, HMIN_ENTITYDICTIONARYFUNCTION, and HMIN_ENTITYCLOSEFUNCTION. The second parameter is the entity type hminlib is requesting. Any of the entity types listed above are valid for this parameter, but always set the parameter to zero if the function being requested does not relate to an entity.
Note: The inquire function must return NULL if the function being requested is not defined.
The last step in the program is to close hminlib; this is accomplished by calling the function HMIN_close(). HMIN_close() frees memory and closes files and other resources used during the translation process.
Note: main() returns an integer value, and in order for HyperMesh to work properly with the input translator, the function main() must return zero.