-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh2tikz_demo.cxx
166 lines (148 loc) · 6.53 KB
/
mesh2tikz_demo.cxx
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <t8.h> /* General t8code header, always include this. */
#include <t8_cmesh.hxx> /* cmesh definition and basic interface. */
#include <t8_cmesh/t8_cmesh_examples.h> /* A collection of exemplary cmeshes */
#include <t8_forest/t8_forest.h> /* forest definition and basic interface. */
#include <forest_2_tikz/forest_to_tikz.hxx>
#include <t8_schemes/t8_default/t8_default_cxx.hxx>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear.hxx>
#include <sc_options.h>
/*
* This file is demonstration on how to use mesh2tikz.
* We construct a forest with a uniform refinement, set the camera, the view-volume
* and the screen. We also want to write the SFC of the forest. The result is written
* into the file "t8_tikz.tikz". If you want to compare the result you can have a
* look at the vtu-files "tikz_compare" in Paraview.
*/
static t8_cmesh_t
construct_cmesh (sc_MPI_Comm comm)
{
t8_cmesh_t cmesh;
/* clang-format off */
double quad_vertices[12] = {0, 0, 1,
1, 0, 1,
0, 1, 1,
1, 1, 1};
double tri_one_vertices[9] = {1, 1, 1,
1, 0, 1,
1, 1, 0};
double tri_two_vertices[9] = {1, 1, 1,
0, 1, 1,
1, 1, 0};
double tri_three_vertices[9] = {0, 1, 1,
0, 1, 0,
1, 1, 0};
/* clang-format on */
t8_cmesh_init (&cmesh);
t8_cmesh_set_tree_class (cmesh, 0, T8_ECLASS_QUAD);
t8_cmesh_set_tree_class (cmesh, 1, T8_ECLASS_TRIANGLE);
t8_cmesh_set_tree_class (cmesh, 2, T8_ECLASS_TRIANGLE);
t8_cmesh_set_tree_class (cmesh, 3, T8_ECLASS_TRIANGLE);
t8_cmesh_register_geometry<t8_geometry_linear> (cmesh, 3);
t8_cmesh_set_tree_vertices (cmesh, 0, quad_vertices, 4);
t8_cmesh_set_tree_vertices (cmesh, 1, tri_one_vertices, 3);
t8_cmesh_set_tree_vertices (cmesh, 2, tri_two_vertices, 3);
t8_cmesh_set_tree_vertices (cmesh, 3, tri_three_vertices, 3);
t8_cmesh_commit (cmesh, comm);
return cmesh;
}
int
main (int argc, char **argv)
{
int mpiret;
sc_MPI_Comm comm = sc_MPI_COMM_WORLD;
t8_cmesh_t cmesh;
t8_forest_t forest;
const int level = 1;
const char *tikz_name = "t8_tikz";
mpiret = sc_MPI_Init (&argc, &argv);
/* Error check the MPI return value. */
SC_CHECK_MPI (mpiret);
const double screen_width = 30.0;
const double screen_height = 30.0;
double cam[3];
double focus[3];
double up[3];
const double view_width = 3.0;
const double view_height = 3.0;
const double far = 50.0;
const int write_sfc = 1;
const int color_mpi = 1;
int **mpi_colors = (int **)malloc(3*sizeof(int *));
char usage[BUFSIZ];
char help[BUFSIZ];
sc_options_t *opt;
int sreturn;
int helpme;
int parsed;
snprintf (usage, BUFSIZ, "Usage:\t%s <OPTIONS> <ARGUMENTS>",
basename (argv[0]));
sreturn = snprintf (help, BUFSIZ,
"This program reads a .msh file "
"created by the GMSH program and constructs a "
"t8code coarse mesh from them.\n\n%s\n\nExample: %s -f A1\nTo open the file A1.msh."
"\n\nThe default dimension of the mesh to read is 2. Since the "
".msh format stores elements of all (lower) dimensions "
"the user must provide the argument for a different dimension by hand, if "
"desired.\n", usage, basename (argv[0]));
if (sreturn >= BUFSIZ) {
/* The help message was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
t8_debugf ("Warning: Truncated help message to '%s'\n", help);
}
T8_ASSERT(mpi_colors != NULL);
/* Initialize the sc library, has to happen before we initialize t8code. */
sc_init (comm, 1, 1, NULL, SC_LP_ESSENTIAL);
/* Initialize t8code with log level SC_LP_PRODUCTION. See sc.h for more info on the log levels. */
t8_init (SC_LP_PRODUCTION);
opt = sc_options_new(argv[0]);
sc_options_add_switch (opt, 'h', "help", &helpme,
"Display a short help message.");
sc_options_add_double(opt, 'X', "cam_x", &cam[0], 1.0, "The x-coordinate of the camera");
sc_options_add_double(opt, 'Y', "cam_y", &cam[1], 1.0, "The y-coordinate of the camera");
sc_options_add_double(opt, 'Z', "cam_z", &cam[2], 1.0, "The z-coordinate of the camera");
sc_options_add_double(opt, 'U', "up_x", &up[0], 0.0, "The x-coordinate of the up-direction of the camera");
sc_options_add_double(opt, 'V', "up_y", &up[1], 0.0, "The y-coordinate of the up-direction of the camera");
sc_options_add_double(opt, 'W', "up_z", &up[2], 1.0, "The z-coordinate of the up-direction of the camera");
sc_options_add_double(opt, 'F', "focus_x", &focus[0], 0.0, "The x-coordinate of the focus");
sc_options_add_double(opt, 'G', "focus_y", &focus[1], 0.0, "The x-coordinate of the focus");
sc_options_add_double(opt, 'H', "focus_z", &focus[2], 0.0, "The x-coordinate of the focus");
parsed =
sc_options_parse (t8_get_package_id (), SC_LP_ERROR, opt, argc, argv);
if (helpme) {
/* display help message and usage */
t8_global_productionf ("%s\n", help);
sc_options_print_usage (t8_get_package_id (), SC_LP_ERROR, opt, NULL);
}
else if (parsed <= 0) {
/* wrong usage */
t8_global_productionf ("\n\t ERROR: Wrong usage.\n\n");
sc_options_print_usage (t8_get_package_id (), SC_LP_ERROR, opt, NULL);
return 1;
}
else{
for(int i = 0; i < 3; i++){
mpi_colors[i] = (int *)malloc(3*sizeof(int));
for(int j = 0; j < 3; j++){
mpi_colors[i][j] = (i == j) ? 255: 0;
}
}
cmesh = t8_cmesh_new_from_class(T8_ECLASS_TET, comm);
forest =
t8_forest_new_uniform (cmesh, t8_scheme_new_default_cxx (), level, 0,
comm);
mesh2tikz (forest, tikz_name, screen_width, screen_height, cam,
focus, up, view_width, view_height, far, write_sfc, !color_mpi, mpi_colors);
t8_forest_write_vtk (forest, "tikz_compare");
for (int i = 2; i >= 0; i--) {
free (mpi_colors[i]);
}
free(mpi_colors);
t8_forest_unref (&forest);
}
sc_options_destroy(opt);
sc_finalize ();
mpiret = sc_MPI_Finalize ();
SC_CHECK_MPI (mpiret);
return 0;
}