3#include <mmg/mmg2d/libmmg2d.h>
17 double v[8] = {0, -M_PI/2, 2 * M_PI, -M_PI/2, 2 * M_PI, M_PI/2, 0, M_PI/2};
25 fprintf(stderr,
"error %i during meshing.\n",
ier);
39 int np, nt, nquad, na;
41 double* verts = malloc(2 * np *
sizeof(
double));
44 for (
int i = 0; i < np; i++) {
47 double y = verts[2 * i + 1];
50 double E = cos(y) * cos(y);
61 double factor = 100.0;
64 const double eps = 1.e-1;
85 fprintf(stderr,
"error %i during remeshing.\n",
ier);
98 verts = realloc(verts, 2 * np *
sizeof(
double));
99 int* tris = malloc(3 * nt *
sizeof(
int));
103 printf(
"\n\n -- Save the final mesh 'sphere-end.mesh' at Medit file format.\n");
105 FILE *fp = fopen(
"sphere-end.mesh",
"w+");
107 fprintf(fp,
"MeshVersionFormatted 2\n\n Dimension 3\n\n Vertices %d\n\n", np);
108 for (
int i = 0; i < np; i++) {
109 double x = verts[2 * i];
110 double y = verts[2 * i + 1];
113 double newx = cos(x) * cos(y);
114 double newy = sin(x) * cos(y);
115 double newz = sin(y);
116 fprintf(fp,
"%f %f %f 0\n", newx, newy, newz);
118 fprintf(fp,
"Triangles %d\n", nt);
120 for (
int i = 0; i < nt; i++)
121 fprintf(fp,
"%i %i %i 0\n", tris[3 * i], tris[3 * i +1], tris[3 * i + 2]);
123 fprintf(fp,
"End\n");
int MMG2D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG2D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
Set integer parameter iparam to value val.
int MMG2D_Set_meshSize(MMG5_pMesh mesh, MMG5_int np, MMG5_int nt, MMG5_int nquad, MMG5_int na)
Set the numbers of entities in the mesh.
int MMG2D_Set_tensorSol(MMG5_pSol met, double m11, double m12, double m22, MMG5_int pos)
Set a single element of a tensor sol structure.
int MMG2D_Get_vertices(MMG5_pMesh mesh, double *vertices, MMG5_int *refs, int *areCorners, int *areRequired)
Get the coordinates and references of all vertices in the mesh.
int MMG2D_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
Set the size and type of a solution field.
int MMG2D_Get_meshSize(MMG5_pMesh mesh, MMG5_int *np, MMG5_int *nt, MMG5_int *nquad, MMG5_int *na)
Get the number of vertices, triangles and edges of the mesh.
int MMG2D_Set_vertices(MMG5_pMesh mesh, double *vertices, MMG5_int *refs)
Set the coordinates and references of all vertices in the mesh.
int MMG2D_Set_dparameter(MMG5_pMesh mesh, MMG5_pSol sol, int dparam, double val)
Set double parameter dparam to value val.
int MMG2D_Free_all(const int starter,...)
Deallocations before return.
int MMG2D_Get_triangles(MMG5_pMesh mesh, MMG5_int *tria, MMG5_int *refs, int *areRequired)
Get the vertices and references of all triangles in the mesh.
program main
Example for using mmglib (basic use)
int MMG2D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
int MMG2D_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save a mesh and optionally one data field in MSH format, ascii or binary depending on the filename ex...
int MMG2D_saveSol(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save metric field in medit solution file format.
int MMG2D_mmg2dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
int MMG2D_mmg2dmesh(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh generation library.
LIBMMG2D_EXPORT void MMG2D_Free_solutions(MMG5_pMesh mesh, MMG5_pSol sol)
Free the solution.