File: test_libmeshb_sol.c

package info (click to toggle)
libmeshb 7.80-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,848 kB
  • sloc: ansic: 12,810; f90: 1,146; fortran: 406; makefile: 218
file content (80 lines) | stat: -rw-r--r-- 2,661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

// libMeshb 7.66 basic example: read a general purpose solution file

#include <stdio.h>
#include <stdlib.h>
#include <libmeshb7.h>


int main()
{
   int      i, j, NmbSolLin, ver, dim, TotSolSiz, NmbSolTyp, SolTypTab[ GmfMaxTyp ];
   int      DatTypTab[10], DatSizTab[10];
   int64_t  MshIdx;
   double   *SolTab;
   char     *DatBegTab[10], *DatEndTab[10];
   char     *TypStr[5] = {"", "GmfSca", "GmfVec", "GmfSymMat", "GmfMat"};


   // Open the "out.sol" mesh file
   if(!(MshIdx = GmfOpenMesh("../sample_meshes/out.sol", GmfRead, &ver, &dim)))
      return(1);

   printf("MshIdx: idx = %lld, version = %d, dimension = %d\n", MshIdx, ver, dim);

   if(ver < 2)
      return(1);

   // Read the number vertices and associated solution size for memory allocation
   NmbSolLin = GmfStatKwd(MshIdx, GmfSolAtVertices, &NmbSolTyp, &TotSolSiz, SolTypTab);
   printf("NmbSol = %d, NmbTyp = %d, SolSiz = %d\n", NmbSolLin, NmbSolTyp, TotSolSiz);
   for(i=0;i<NmbSolTyp;i++)
      printf("type %d = %s\n", i, TypStr[ SolTypTab[i] ]);

   SolTab = malloc( (NmbSolLin+1) * TotSolSiz * sizeof(double));

   // Solution field block reading via arguments tables
   DatTypTab[0] = GmfDoubleVec;
   DatSizTab[0] = 5;
   DatBegTab[0] = (char *)&SolTab[         1 * TotSolSiz ];
   DatEndTab[0] = (char *)&SolTab[ NmbSolLin * TotSolSiz ];

   GmfGetBlock(MshIdx, GmfSolAtVertices, 1, NmbSolLin, 0, NULL, NULL,
               GmfArgTab, DatTypTab, DatSizTab, DatBegTab, DatEndTab);

   // Print each solutions of each vertices
   for(i=1;i<=NmbSolLin;i++)
      for(j=0;j<TotSolSiz;j++)
         printf("%d, %d = %g\n", i, j, SolTab[ i * TotSolSiz + j ]);

   // Close the mesh file
   GmfCloseMesh(MshIdx);


   // Open a new mesh file for creation
   if(!(MshIdx = GmfOpenMesh("../sample_meshes/out2.sol", GmfWrite, ver, dim)))
      return(1);

   // Create a new solution field from the previsous one made of two scalars followed by a 3D vector
   SolTypTab[0] = GmfSca;
   SolTypTab[1] = GmfSca;
   SolTypTab[2] = GmfVec;

   // Write the number vertices and associated solution size for memory allocation
   GmfSetKwd(MshIdx, GmfSolAtVertices, NmbSolLin, 3, SolTypTab);

   // Solution field block reading
   GmfSetBlock(MshIdx, GmfSolAtVertices, 1, NmbSolLin, 0, NULL, NULL,
               GmfSca, &SolTab[ 1 * TotSolSiz     ], &SolTab[ NmbSolLin * TotSolSiz     ],
               GmfVec, &SolTab[ 1 * TotSolSiz + 1 ], &SolTab[ NmbSolLin * TotSolSiz + 1 ],
               GmfSca, &SolTab[ 1 * TotSolSiz + 4 ], &SolTab[ NmbSolLin * TotSolSiz + 4 ]);

   // Close the mesh file
   GmfCloseMesh(MshIdx);


   // Free the solutions table
   free(SolTab);

   return(0);
}