4.3.0.2 Definition/initialisation of MMG_Mesh structure:

to define the MMG_Mesh structure, you need to allocate and initialize all the elements described on the previous paragraph. The next steps explains how to do that and dive the C-code corresponding:
  1. Define a pointer on a MMG_Mesh structure:

    MMG_pMesh mymmgmesh

  2. Allocate this pointer:

    mymmgmesh = (MMG_pMesh)calloc(1,sizeof(MMG_Mesh));

  3. Give the nodes, triangles and tetrahedra numbers of your mesh:

    mymmgmesh->np = nbpoint;
    mymmgmesh->nt = nbtri;
    mymmgmesh->ne = nbtetra;

  4. Give the nodes, triangles, tetrahedra maximum numbers:

    mymmgmesh->npmax = nbpointmax;
    mymmgmesh->ntmax = nbtrimax;
    mymmgmesh->nemax = nbtetramax;

  5. Allocate the structure Point, Tetra, Tria, Disp et adja

    mymmgmesh->point = (MMG_pPoint)calloc(mymmgmesh->npmax+1,sizeof(MMG_Point));
    mymmgmesh->tetra = (MMG_pTetra)calloc(mymmgmesh->nemax+1,sizeof(MMG_Tetra));
    mymmgmesh->tria = (MMG_pTria) calloc(mymmgmesh->ntmax+1,sizeof(MMG_Tria));
    mymmgmesh->adja = (int*)calloc(4*mymmgmesh->nemax+5,sizeof(int));
    mymmgmesh->disp = (MMG_pDispl)calloc(mymmgmesh->npmax+1,sizeof(MMG_Displ));
    mymmgmesh->disp->mv = (double*)calloc(3*(mymmgmesh->npmax+1),sizeof(double));
    mymmgmesh->disp->alpha = (short*)calloc(mymmgmesh->npmax+1,sizeof(short));

  6. Initialize the Point structure, that means for all the nodes, give the coordinates and the reference:

    MMG_pMesh mymmgmesh;
    MMG_pPoint ppt;
     
    for (k=1; k<=mymmgmesh->np; k++) {
    ppt = &mymmgmesh->point[k];
    ppt->c[0] = coorx;
    ppt->c[1] = coory;
    ppt->c[2] = coorz;
    ppt->ref = logic;
    }

    NB :The node are numbered from $1$ to mymmgmesh->np in a contiguous way.

  7. Initialize the Tetra structure, that means for all tetrahedra, give the number nodes of the four vertex and the reference:

    MMG_pMesh mymmgmesh;
    MMG_pTetra ptetra;
     
    for (k=1; k<=mymmgmesh->ne; k++) {
    ptetra = &mymmgmesh->tetra[k];
    ptetra->v[0] = num1;
    ptetra->v[1] = num2;
    ptetra->v[2] = num3;
    ptetra->v[3] = num4;
    ptetra->ref = logic;
    }

    NB :The tetrahedra are numbered from $1$ to mymmgmesh->ne in a contiguous way.

  8. (optional) Initialize the Tria structure, that means for all surface triangles, dive the node number of the three vertex and the reference.

    MMG_pMesh mymmgmesh;
    MMG_pTria ptriangle;
     
    for (k=1; k<=mymmgmesh->nt; k++) {
    ptriangle = &mymmgmesh->tria[k];
    ptriangle->v[0] = num1;
    ptriangle->v[1] = num2;
    ptriangle->v[2] = num3;
    ptriangle->ref = logic;
    }

    NB :The node are numbered from $1$ to mymmgmesh->nt in a contiguous way

  9. (optional) If you treat bodies movements, initialize the Disp structure:

    MMG_pMesh mymmgmesh;
    MMG_pDispl pd;
     
    for (k=1; k<mymmgmesh->np; k++) {
    pd = &mesh->mymmgdisp[k];
    pd->mv[0] = depx;
    pd->mv[1] = depy;
    pd->mv[2] = depz;
    }

back to the content


Dobrzynski 2012-03-23