A First Vfe Program

As an example of a simple VfeTools application the following program computes the stiffness matrix for a 2D plane stress 3 node triangular element. The material model is assumed isotropic, linear elastic, with Young’s modulus and Poisson’s ratio of 1.0 and 0.3, respectively. The resulting stiffness matrix is printed to standard output.

A First Program - C Version

#include <stdio.h>
#include "sam/base/base.h"
#include "sam/vfe/vfe.h"

static Vdouble x[3][3] = {{0., 0., 0.}, {1., 0., 0.}, {0., 1., 0.}};

/*----------------------------------------------------------------------
                      Generate Stiffness Matrix for 3 Node Triangle
----------------------------------------------------------------------*/
int
main()
{
    Vint i, j;
    Vdouble prop[2];
    Vdouble kl[21];
    vfe_Solid2D* solid2d;
    vfe_MatlFun* matlfun;
    vfe_LinMat* linmat;

    /* Create material object and set properties */
    linmat = vfe_LinMatBegin();
    vfe_LinMatDef(linmat, SYS_MAT_ISOTROPIC);
    prop[0] = 1.0;
    prop[1] = .3;
    vfe_LinMatSetElasProp(linmat, prop);

    /* Create MatlFun object and load material functions */
    matlfun = vfe_MatlFunBegin();
    vfe_LinMatMatlFun(linmat, matlfun);

    /* Create 2D solid element formulation */
    solid2d = vfe_Solid2DBegin();
    vfe_Solid2DSetTopology(solid2d, SYS_SHAPETRI, 2, 0);

    /* Register material functions */
    vfe_Solid2DSetObject(solid2d, VFE_MATLFUN, matlfun);

    /* Form and print stiffness matrix */
    vfe_Solid2DStiff(solid2d, x, kl);
    printf("Lower triangle of stiffness matrix\n");
    for (i = 0; i < 6; i++) {
        for (j = 0; j <= i; j++) {
            printf("%12.4e ", kl[i * (i + 1) / 2 + j]);
        }
        printf("\n");
    }
    /* Delete objects */
    vfe_Solid2DEnd(solid2d);
    vfe_MatlFunEnd(matlfun);
    vfe_LinMatEnd(linmat);
    return 0;
}

The output of this example program appears below. Only the lower half of the matrix is printed.

Lower triangle of stiffness matrix
7.4176e-01
3.5714e-01   7.4176e-01
-5.4945e-01  -1.6484e-01   5.4945e-01
-1.9231e-01  -1.9231e-01   0.0000e+00   1.9231e-01
-1.9231e-01  -1.9231e-01   0.0000e+00   1.9231e-01   1.9231e-01
-1.6484e-01  -5.4945e-01   1.6484e-01   0.0000e+00   0.0000e+00   5.4945e-01