tetmesh_write1.c 1.43 KB
Newer Older
1 2 3 4 5 6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "H5hut.h"

7
#ifndef H5_HAVE_PARALLEL
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
#ifndef MPI_COMM_WORLD
#define MPI_COMM_WORLD 0
#endif
#endif

const char* FNAME = "simple_tet1.h5";

typedef struct vertex {
	h5_float64_t P[3];
} vertex_t;

typedef struct elem {
	h5_loc_idx_t vids[4];
} elem_t;

vertex_t Vertices[] = {
	{{-1.0,  0.0,  0.0}},
	{{ 0.0,  0.0,  1.0}},
	{{ 0.0,  1.0,  0.0}},
	{{ 1.0,  0.0,  0.0}},
};

elem_t Elems[] = {
	{{ 0, 1, 2, 3 }},
};

const int num_vertices = sizeof (Vertices) / sizeof (Vertices[0]);
const int num_elems = sizeof (Elems) / sizeof (Elems[0]);

int
main (
	int argc,
	char* argv[]
	) {
	/* abort program on errors in library */
	H5SetErrorHandler (H5AbortErrorhandler);
	H5SetVerbosityLevel (H5_DEBUG_ALL);

	/* open file and add mesh */
	h5_file_t const f = H5OpenFile (FNAME, H5_O_WRONLY, 0);
	h5t_mesh_t* mesh;
	H5FedAddTetrahedralMesh (f, "0", &mesh);

	/* store vertices */
	H5FedBeginStoreVertices (mesh, num_vertices);
	int i;
	for (i = 0; i < num_vertices; i++) {
		H5FedStoreVertex (mesh, -1, Vertices[i].P);
	}
	H5FedEndStoreVertices (mesh);

	/* store elements */
	H5FedBeginStoreElements (mesh, num_elems);
	for (i = 0; i < num_elems; i++) {
		H5FedStoreElement (mesh, Elems[i].vids);
	}
	H5FedEndStoreElements (mesh);

	/* add 1. Level */
	H5FedBeginRefineElements (mesh);
	H5FedRefineElement (mesh, 0);
	H5FedEndRefineElements (mesh);

	H5FedCloseMesh (mesh);
	H5CloseFile (f);
	return 0;
}