A First Vfe Program
As an example of a simple VfxTools application the following program reads a NASTRAN bulk data file and populates a Model object. The Model object encapsulates the finite element model, solution procedures and output requests in the NASTRAN input file. A ProSolve object is instanced and a finite element solution is performed as specified in the Model object. Various log files and output files are created with summaries of the solution phases and the solution results.
#include <stdlib.h>
#include "sam/base/base.h"
#include "sam/vdm/vdm.h"
#include "sam/vfx/vfx.h"
/*----------------------------------------------------------------------
Solving a NASTRAN or ABAQUS model
----------------------------------------------------------------------*/
int
main(int argc, char* argv[])
{
Vint filetype;
Vchar inputfile[256];
vdm_LMan* lman;
vdm_NASFil* nasfil;
vdm_ABAFil* abafil;
vdm_DataFun* datafun;
vis_Model* model;
vfx_ProSolve* prosolve;
vsy_TextFun* textfun;
vsy_PlainText* plaintext;
if (argc < 2) {
fprintf(stderr, "Usage: %s inputfile\n", argv[0]);
fprintf(stderr, " chexa.dat is assumed\n");
strcpy(inputfile, "chexa.dat");
}
else {
strcpy(inputfile, argv[1]);
}
/* Access input file */
datafun = vdm_DataFunBegin();
/* determine input file type from file extension */
if (strstr(inputfile, ".bdf") != NULL || strstr(inputfile, ".dat") != NULL) {
filetype = VDM_NASTRAN_BULKDATA;
nasfil = vdm_NASFilBegin();
vdm_NASFilDataFun(nasfil, datafun);
}
else if (strstr(inputfile, ".inp") != NULL) {
filetype = VDM_ABAQUS_INPUT;
abafil = vdm_ABAFilBegin();
vdm_ABAFilDataFun(abafil, datafun);
}
else {
fprintf(stderr, "Error: unsupported input file type\n");
return 1;
}
vdm_DataFunSetConvention(datafun, VDM_CONVENTION_DOUBLE);
vdm_DataFunOpen(datafun, 0, inputfile, filetype);
if (vdm_DataFunError(datafun)) {
fprintf(stderr, "Error: opening file %s\n", inputfile);
return 1;
}
/* create lman as helper object */
lman = vdm_LManBegin();
vdm_LManSetObject(lman, VDM_DATAFUN, datafun);
/* load model */
model = vis_ModelBegin();
vdm_LManLoadModel(lman, model);
if (vdm_LManError(lman)) {
fprintf(stderr, "Error: unable to load model information\n");
return 1;
}
/* close input file */
vdm_LManEnd(lman);
vdm_DataFunClose(datafun);
vdm_DataFunEnd(datafun);
if (filetype == VDM_NASTRAN_BULKDATA) {
vdm_NASFilEnd(nasfil);
}
else if (filetype == VDM_ABAQUS_INPUT) {
vdm_ABAFilEnd(abafil);
}
/* instance and initialize ProSolve */
prosolve = vfx_ProSolveBegin();
/* set parameters, no printout file */
vfx_ProSolveSetParami(prosolve, PROSOLVE_PRINTLEVEL, 0);
/* ask for results file in native .vdm format */
vfx_ProSolveSetParami(prosolve, PROSOLVE_RESTYPE, VDM_NATIVE);
vfx_ProSolveSetParamc(prosolve, PROSOLVE_RESFILE, "intro1.vdm");
/* request model information on results file */
vfx_ProSolveSetParami(prosolve, PROSOLVE_SAVEMODEL, SYS_ON);
/* set Model object */
vfx_ProSolveSetObject(prosolve, VIS_MODEL, model);
/* set solution progress output to console */
plaintext = vsy_PlainTextBegin();
textfun = vsy_TextFunBegin();
vsy_PlainTextTextFun(plaintext, textfun);
vsy_TextFunConnectFile(textfun, stdout);
vfx_ProSolveSetObject(prosolve, VSY_TEXTFUN, textfun);
/* execute */
vfx_ProSolveExec(prosolve);
if (vfx_ProSolveError(prosolve)) {
fprintf(stderr, "Error: unable to solve model information\n");
return 1;
}
/* delete output objects */
vsy_PlainTextEnd(plaintext);
vsy_TextFunEnd(textfun);
/* delete Model object contents and object */
vis_ModelDelete(model);
vis_ModelEnd(model);
/* delete ProSolve object */
vfx_ProSolveEnd(prosolve);
return 0;
}