4 #include <deal.II/numerics/data_out.h> 5 #include <deal.II/grid/tria.h> 7 #include <deal.II/base/tensor.h> 8 #include <deal.II/base/symmetric_tensor.h> 14 namespace GridRefinement {
39 template <
int dim,
typename real>
41 const dealii::Triangulation<dim, dim> &tria,
42 dealii::Vector<real> data,
49 const unsigned int n_vertices = tria.n_used_vertices();
51 typename dealii::Triangulation<dim, dim>::active_cell_iterator cell =
53 const typename dealii::Triangulation<dim, dim>::active_cell_iterator endc =
57 out <<
"/*********************************** " <<
'\n' 58 <<
" * BACKGROUND MESH FIELD GENERATED * " <<
'\n' 59 <<
" * AUTOMATICALLY BY PHiLiP LIBRARY * " <<
'\n' 60 <<
" ***********************************/" <<
'\n';
63 out <<
"// File contains n_vertices = " << n_vertices <<
'\n' <<
'\n';
66 out <<
"View \"background mesh\" {" <<
'\n';
70 for(cell = tria.begin_active(); cell!=endc; ++cell){
71 if(!cell->is_locally_owned())
continue;
80 for(
unsigned int vertex = 0; vertex < dealii::GeometryInfo<dim>::vertices_per_cell; ++vertex){
84 dealii::Point<dim> pos;
85 if((vertex+2)%4 == 0){
86 pos = cell->vertex(vertex+1);
87 }
else if((vertex+1)%4 == 0){
88 pos = cell->vertex(vertex-1);
90 pos = cell->vertex(vertex);
93 if(vertex != 0){out <<
",";}
96 if(dim >= 1){out << pos[0] <<
",";}
97 else {out << 0 <<
",";}
99 if(dim >= 2){out << pos[1] <<
",";}
100 else {out << 0 <<
",";}
102 if(dim >= 3){out << pos[2];}
134 real v = data[cell->active_cell_index()];
136 for(
unsigned int vertex = 0; vertex < dealii::GeometryInfo<dim>::vertices_per_cell; ++vertex){
137 if(vertex != 0){out <<
",";}
145 out <<
"}; //View \"background mesh\" " <<
'\n';
151 template <
int dim,
typename real>
153 const dealii::Triangulation<dim,dim>& tria,
154 const std::vector<dealii::SymmetricTensor<2,dim,real>>& data,
158 const unsigned int n_vertices = tria.n_used_vertices();
160 typename dealii::Triangulation<dim, dim>::active_cell_iterator cell =
162 const typename dealii::Triangulation<dim, dim>::active_cell_iterator endc =
166 out <<
"/*********************************** " <<
'\n' 167 <<
" * BACKGROUND MESH FIELD GENERATED * " <<
'\n' 168 <<
" * AUTOMATICALLY BY PHiLiP LIBRARY * " <<
'\n' 169 <<
" ***********************************/" <<
'\n';
172 out <<
"// File contains n_vertices = " << n_vertices <<
'\n' <<
'\n';
175 out <<
"View \"background mesh\" {" <<
'\n';
180 for(cell = tria.begin_active(); cell!=endc; ++cell){
181 if(!cell->is_locally_owned())
continue;
184 const dealii::Tensor<2,dim,real> val = data[cell->active_cell_index()];
190 std::vector<dealii::Point<dim>> vertices;
191 vertices.reserve(dealii::GeometryInfo<dim>::vertices_per_cell);
192 for(
unsigned int vertex = 0; vertex < dealii::GeometryInfo<dim>::vertices_per_cell; ++vertex){
196 dealii::Point<dim> pos;
197 if((vertex+2)%4 == 0){
198 pos = cell->vertex(vertex+1);
199 }
else if((vertex+1)%4 == 0){
200 pos = cell->vertex(vertex-1);
202 pos = cell->vertex(vertex);
205 vertices.push_back(pos);
211 std::array<std::array<int,3>,2>{{
216 for(
unsigned int i = 0; i < tri.size(); ++i){
217 if(i != 0){out <<
",";}
220 dealii::Point<dim> pos = vertices[tri[i]];
221 if(dim >= 1){out << pos[0] <<
",";}
222 else {out << 0 <<
",";}
224 if(dim >= 2){out << pos[1] <<
",";}
225 else {out << 0 <<
",";}
227 if(dim >= 3){out << pos[2];}
234 for(
unsigned int vertex = 0; vertex < tri.size(); ++vertex){
237 const unsigned int N = 3;
242 scale = 0.25*0.5/sqrt(2.0);
243 }
else if(p_scale == 2){
244 scale = 0.25/sqrt(3.0);
245 }
else if(p_scale == 3){
246 scale = 0.25/sqrt(2.0);
249 for(
unsigned int i = 0; i < N; ++i){
250 for(
unsigned int j = 0; j < N; ++j){
260 if( (i < dim) && (j < dim) ){
261 out << scale*val[i][j];
283 out <<
"}; //View \"background mesh\" " <<
'\n';
290 template <
int dim,
typename real>
292 std::vector<std::string> &posFile_vec,
296 out <<
"/*********************************** " <<
'\n' 297 <<
" * MESH GEOMETRY FILE GENERATED * " <<
'\n' 298 <<
" * AUTOMATICALLY BY PHiLiP LIBRARY * " <<
'\n' 299 <<
" ***********************************/" <<
'\n' <<
'\n';
302 out <<
"Mesh.CharacteristicLengthFromPoints = 1;" <<
'\n' 303 <<
"Mesh.CharacteristicLengthFromCurvature = 0;" <<
'\n' 304 <<
"Mesh.CharacteristicLengthExtendFromBoundary = 0;" <<
'\n' <<
'\n';
308 out <<
"Mesh.Algorithm = 8;" <<
'\n' 309 <<
"Mesh.RecombinationAlgorithm = 3;" <<
'\n' 310 <<
"Mesh.RecombineAll = 1;" <<
'\n' <<
'\n';
314 write_geo_hyper_cube(0.0, 1.0, out);
318 out <<
"// Merging the background mesh and recombine" <<
'\n';
319 for(
unsigned int ifile = 0; ifile < posFile_vec.size(); ++ifile)
320 out <<
"Merge \"" << posFile_vec[ifile] <<
"\";" <<
'\n';
323 out <<
"Combine Views;" <<
'\n';
326 out <<
"Background Mesh View[0];" <<
'\n';
332 template <
int dim,
typename real>
334 std::vector<std::string> &posFile_vec,
338 out <<
"/*********************************** " <<
'\n' 339 <<
" * MESH GEOMETRY FILE GENERATED * " <<
'\n' 340 <<
" * AUTOMATICALLY BY PHiLiP LIBRARY * " <<
'\n' 341 <<
" ***********************************/" <<
'\n' <<
'\n';
344 out <<
"Mesh.CharacteristicLengthFromPoints = 1;" <<
'\n' 345 <<
"Mesh.CharacteristicLengthFromCurvature = 0;" <<
'\n' 346 <<
"Mesh.CharacteristicLengthExtendFromBoundary = 0;" <<
'\n' <<
'\n';
349 out <<
"Mesh.Algorithm = 7;" <<
'\n' 351 <<
"Mesh.RecombinationAlgorithm = 2;" <<
'\n' 352 <<
"Mesh.RecombineAll = 1;" <<
'\n' <<
'\n';
356 write_geo_hyper_cube(0.0, 1.0, out);
360 out <<
"// Merging the background mesh and recombine" <<
'\n';
361 for(
unsigned int ifile = 0; ifile < posFile_vec.size(); ++ifile)
362 out <<
"Merge \"" << posFile_vec[ifile] <<
"\";" <<
'\n';
365 out <<
"Combine Views;" <<
'\n';
368 out <<
"Background Mesh View[0];" <<
'\n';
374 template <
int dim,
typename real>
385 out <<
"// Points" <<
'\n';
386 out <<
"Point(1)={" << left <<
"," << left <<
"," << 0 <<
"};" <<
'\n';
387 out <<
"Point(2)={" << right <<
"," << left <<
"," << 0 <<
"};" <<
'\n';
388 out <<
"Point(3)={" << right <<
"," << right <<
"," << 0 <<
"};" <<
'\n';
389 out <<
"Point(4)={" << left <<
"," << right <<
"," << 0 <<
"};" <<
'\n';
392 out <<
"// Lines" <<
'\n';
393 out <<
"Line(1)={1,2};" <<
'\n';
394 out <<
"Line(2)={2,3};" <<
'\n';
395 out <<
"Line(3)={3,4};" <<
'\n';
396 out <<
"Line(4)={4,1};" <<
'\n';
399 out <<
"// Loop" <<
'\n';
400 out <<
"Line Loop(1)={1,2,3,4};" <<
'\n';
403 out <<
"// Surface" <<
'\n';
404 out <<
"Plane Surface(1) = {1};" <<
'\n';
409 out <<
"// Colorize" <<
'\n';
410 out <<
"Physical Curve (2) = {1};" <<
'\n';
411 out <<
"Physical Curve (1) = {2};" <<
'\n';
412 out <<
"Physical Curve (3) = {3};" <<
'\n';
413 out <<
"Physical Curve (0) = {4};" <<
'\n';
417 out<<
"Physical Surface(\"surf1\", 5) = {1};"<<
'\n';
422 template <
int dim,
typename real>
424 std::string geo_name,
425 std::string output_name)
427 #if ENABLE_GMSH && defined GMSH_PATH 429 std::string args =
" " + geo_name +
" -" + std::to_string(dim) +
" -save_all -o " + output_name;
430 std::string cmd = GMSH_PATH + args;
431 std::cout <<
"Command is: " << cmd <<
'\n';
432 int ret = std::system(cmd.c_str());
439 std::cerr <<
"Error: Call to gmsh without gmsh enabled." << std::endl;
440 std::cerr <<
" Please set ENABLE_GMSH and GMSH_PATH and try again." << std::endl;
static int call_gmsh(std::string geo_name, std::string output_name)
Performs command line call to GMSH for grid generation (if availible)
Files for the baseline physics.
static void write_geo_hyper_cube(const double left, const double right, std::ostream &out, const bool colorize=true)
Writes the part of the .geo file associated wit the hyperdube geometry.
static void write_geo(std::vector< std::string > &posFile_vec, std::ostream &out)
Writes the central .geo file for call to GMSH on main process with isotropic quad meshing...
static void write_pos_anisotropic(const dealii::Triangulation< dim, dim > &tria, const std::vector< dealii::SymmetricTensor< 2, dim, real >> &data, std::ostream &out, const int p_scale=1)
Write anisotropic tensor .pos file for use with GMSH.
static void write_geo_anisotropic(std::vector< std::string > &posFile_vec, std::ostream &out)
Writes the central .geo file for call to GMSH on main process with anisotropic quad meshing...
static void write_pos(const dealii::Triangulation< dim, dim > &tria, dealii::Vector< real > data, std::ostream &out)
Write scalar .pos file for use with GMSH.