4 #include <deal.II/base/exceptions.h> 5 #include <deal.II/base/utilities.h> 7 #include <deal.II/grid/grid_in.h> 8 #include <deal.II/grid/tria.h> 10 #include <deal.II/grid/grid_reordering.h> 11 #include <deal.II/grid/grid_tools.h> 13 #include <deal.II/grid/grid_out.h> 15 #include <deal.II/fe/fe_tools.h> 17 #include <deal.II/dofs/dof_renumbering.h> 19 #include "high_order_grid.h" 20 #include "gmsh_reader.hpp" 33 template <
int spacedim>
36 dealii::Triangulation<1, spacedim> &triangulation)
38 if (boundary_ids.size() > 0) {
39 for (
const auto &cell : triangulation.active_cell_iterators()) {
40 for (
unsigned int f : dealii::GeometryInfo<1>::face_indices()) {
41 if (boundary_ids.find(cell->vertex_index(f)) != boundary_ids.end()) {
43 AssertThrow( cell->at_boundary(f),
45 "You are trying to prescribe boundary ids on the face " 46 "of a 1d cell (i.e., on a vertex), but this face is not actually at " 47 "the boundary of the mesh. This is not allowed."));
49 cell->face(f)->set_boundary_id(boundary_ids.find(cell->vertex_index(f))->second);
57 void rotate_indices(std::vector<unsigned int> &numbers,
const unsigned int n_indices_per_direction,
const char direction,
const bool mesh_reader_verbose_output)
60 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
61 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
63 const unsigned int n = n_indices_per_direction;
65 for (
unsigned int i = 1; i < dim; ++i)
74 for (
unsigned int i = n; i > 0;)
87 for (
unsigned int iz = 0; iz < ((dim > 2) ? n : 1); ++iz)
88 for (
unsigned int j = 0; j < n; ++j)
89 for (
unsigned int i = 0; i < n; ++i)
91 unsigned int k = n * i - j + n - 1 + n * n * iz;
101 for (
unsigned int iz = 0; iz < ((dim > 2) ? n : 1); ++iz)
102 for (
unsigned int iy = 0; iy < n; ++iy)
103 for (
unsigned int ix = 0; ix < n; ++ix)
105 unsigned int k = n * ix - iy + n - 1 + n * n * iz;
115 for (
unsigned int iz = 0; iz < ((dim > 2) ? n : 1); ++iz)
116 for (
unsigned int iy = 0; iy < n; ++iy)
117 for (
unsigned int ix = 0; ix < n; ++ix)
119 unsigned int k = iy + n * ix + n * n * iz;
126 Assert(dim > 2, dealii::ExcDimensionMismatch(dim, 3));
127 for (
unsigned int iz = 0; iz < n; ++iz)
128 for (
unsigned int iy = 0; iy < n; ++iy)
129 for (
unsigned int ix = 0; ix < n; ++ix)
131 unsigned int k = n * (n * iy - iz + n - 1) + ix;
138 Assert(dim > 2, dealii::ExcDimensionMismatch(dim, 3));
139 for (
unsigned int iz = 0; iz < n; ++iz)
140 for (
unsigned int iy = 0; iy < n; ++iy)
141 for (
unsigned int ix = 0; ix < n; ++ix)
143 unsigned int k = n * (n * iy - iz + n - 1) + ix;
148 Assert(
false, dealii::ExcNotImplemented());
232 for (
unsigned int iz = 0; iz < n; ++iz)
233 for (
unsigned int iy = 0; iy < n; ++iy)
234 for (
unsigned int ix = 0; ix < n; ++ix)
236 unsigned int k = (ix) * n + n - (iy + 1) + (n * n * iz);
238 if(mesh_reader_verbose_output) pcout <<
"3D rotation matrix, physical node mapping, Z-axis : " << k << std::endl;
243 for (
unsigned int iz = 0; iz < n; ++iz)
244 for (
unsigned int iy = 0; iy < n; ++iy)
245 for (
unsigned int ix = 0; ix < n; ++ix)
247 unsigned int k = (ix) + (n * (n-1)) + (n * n * iy) - (n * iz);
249 if(mesh_reader_verbose_output) pcout <<
"3D rotation matrix, physical node mapping, X-axis : " << k << std::endl;
254 for (
unsigned int iz = 0; iz < n; ++iz)
255 for (
unsigned int iy = 0; iy < n; ++iy)
256 for (
unsigned int ix = 0; ix < n; ++ix)
258 unsigned int k = (ix * n * n) + (n - 1) + (iy * n) - (iz);
260 if(mesh_reader_verbose_output) pcout <<
"3D rotation matrix, physical node mapping, Y-axis : " << k << std::endl;
265 for (
unsigned int iz = 0; iz < n; ++iz)
266 for (
unsigned int iy = 0; iy < n; ++iy)
267 for (
unsigned int ix = 0; ix < n; ++ix)
269 unsigned int k = (n * (n - 1)) + ix - (iy * n) + (n * n * iz);
271 if(mesh_reader_verbose_output) pcout <<
"3D rotation matrix, physical node mapping, Flip-axis : " << k << std::endl;
278 template <
int dim,
int spacedim>
281 dealii::Triangulation<dim, spacedim> &)
285 Assert(dim != 1, dealii::ExcInternalError());
289 void open_file_toRead(
const std::string filepath, std::ifstream& file_in)
291 file_in.open(filepath);
293 std::cout <<
"Could not open file "<< filepath << std::endl;
299 void read_gmsh_entities(std::ifstream &infile, std::array<std::map<int, int>, 4> &tag_maps)
303 unsigned long n_points, n_curves, n_surfaces, n_volumes;
305 infile >> n_points >> n_curves >> n_surfaces >> n_volumes;
307 unsigned int n_physicals;
308 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y, box_max_z;
309 (void) box_min_x; (void) box_min_y; (void) box_min_z;
310 (void) box_max_x; (void) box_max_y; (void) box_max_z;
311 for (
unsigned int i = 0; i < n_points; ++i) {
315 infile >> entity_tag >> box_min_x >> box_min_y >> box_min_z >> n_physicals;
318 AssertThrow(n_physicals < 2, dealii::ExcMessage(
"More than one tag is not supported!"));
320 int physical_tag = 0;
321 for (
unsigned int j = 0; j < n_physicals; ++j) {
322 infile >> physical_tag;
325 tag_maps[0][entity_tag] = physical_tag;
327 for (
unsigned int i = 0; i < n_curves; ++i) {
331 infile >> entity_tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >> box_max_y >> box_max_z >> n_physicals;
333 AssertThrow(n_physicals < 2, dealii::ExcMessage(
"More than one tag is not supported!"));
335 int physical_tag = 0;
336 for (
unsigned int j = 0; j < n_physicals; ++j) {
337 infile >> physical_tag;
339 tag_maps[1][entity_tag] = physical_tag;
344 for (
unsigned int j = 0; j < n_points; ++j) {
345 infile >> entity_tag;
348 for (
unsigned int i = 0; i < n_surfaces; ++i) {
352 infile >> entity_tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >> box_max_y >> box_max_z >> n_physicals;
354 AssertThrow(n_physicals < 2, dealii::ExcMessage(
"More than one tag is not supported!"));
356 int physical_tag = 0;
357 for (
unsigned int j = 0; j < n_physicals; ++j) {
358 infile >> physical_tag;
361 tag_maps[2][entity_tag] = physical_tag;
365 for (
unsigned int j = 0; j < n_curves; ++j) {
366 infile >> entity_tag;
369 for (
unsigned int i = 0; i < n_volumes; ++i) {
373 infile >> entity_tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >> box_max_y >> box_max_z >> n_physicals;
375 AssertThrow(n_physicals < 2,
376 dealii::ExcMessage(
"More than one tag is not supported!"));
378 int physical_tag = 0;
379 for (
unsigned int j = 0; j < n_physicals; ++j) {
380 infile >> physical_tag;
383 tag_maps[3][entity_tag] = physical_tag;
386 infile >> n_surfaces;
387 for (
unsigned int j = 0; j < n_surfaces; ++j) {
388 infile >> entity_tag;
395 template<
int spacedim>
396 void read_gmsh_nodes( std::ifstream &infile, std::vector<dealii::Point<spacedim>> &vertices, std::map<int, int> &vertex_indices,
const bool mesh_reader_verbose_output )
399 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
400 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
404 unsigned int n_entity_blocks, n_vertices;
407 infile >> n_entity_blocks >> n_vertices >> min_node_tag >> max_node_tag;
408 if(mesh_reader_verbose_output) pcout <<
"Reading nodes..." << std::endl;
410 vertices.resize(n_vertices);
412 unsigned int global_vertex = 0;
413 for (
unsigned int entity_block = 0; entity_block < n_entity_blocks; ++entity_block) {
415 unsigned long numNodes;
419 int tagEntity, dimEntity;
420 infile >> tagEntity >> dimEntity >> parametric >> numNodes;
422 std::vector<int> vertex_numbers;
424 for (
unsigned long vertex_per_entity = 0; vertex_per_entity < numNodes; ++vertex_per_entity) {
426 infile >> vertex_number;
427 vertex_numbers.push_back(vertex_number);
430 for (
unsigned long vertex_per_entity = 0; vertex_per_entity < numNodes; ++vertex_per_entity, ++global_vertex) {
433 infile >> x[0] >> x[1] >> x[2];
435 for (
unsigned int d = 0; d < spacedim; ++d) {
436 vertices[global_vertex](d) = x[d];
440 vertex_number = vertex_numbers[vertex_per_entity];
442 vertex_indices[vertex_number] = global_vertex;
446 if (parametric != 0) {
447 int n_parametric = dimEntity;
448 if (dimEntity == 0) n_parametric = 1;
450 for (
int d=0; d<n_parametric; ++d) {
457 AssertDimension(global_vertex, n_vertices);
458 if(mesh_reader_verbose_output) pcout <<
"Finished reading nodes." << std::endl;
461 unsigned int gmsh_cell_type_to_order(
unsigned int cell_type)
463 unsigned int cell_order = 0;
464 if ( (cell_type == MSH_LIN_2) || (cell_type == MSH_QUA_4) || (cell_type == MSH_HEX_8) ) {
466 }
else if ( (cell_type == MSH_LIN_3) || (cell_type == MSH_QUA_9) || (cell_type == MSH_HEX_27) ) {
468 }
else if ( (cell_type == MSH_LIN_4) || (cell_type == MSH_QUA_16) || (cell_type == MSH_HEX_64) ) {
470 }
else if ( (cell_type == MSH_LIN_5) || (cell_type == MSH_QUA_25) || (cell_type == MSH_HEX_125) ) {
472 }
else if ( (cell_type == MSH_LIN_6) || (cell_type == MSH_QUA_36) || (cell_type == MSH_HEX_216) ) {
474 }
else if ( (cell_type == MSH_LIN_7) || (cell_type == MSH_QUA_49) || (cell_type == MSH_HEX_343) ) {
476 }
else if ( (cell_type == MSH_LIN_8) || (cell_type == MSH_QUA_64) || (cell_type == MSH_HEX_512) ) {
478 }
else if ( (cell_type == MSH_LIN_9) || (cell_type == MSH_QUA_81) || (cell_type == MSH_HEX_729) ) {
480 }
else if ( (cell_type == MSH_PNT) ) {
483 std::cout <<
"Invalid element type read from GMSH " << cell_type <<
". " 484 <<
"\n Valid element types are:" 486 <<
"\n " << MSH_LIN_2 <<
" " << MSH_LIN_3 <<
" " << MSH_LIN_4 <<
" " << MSH_LIN_5 <<
" " << MSH_LIN_6 <<
" " << MSH_LIN_7 <<
" " << MSH_LIN_8 <<
" " << MSH_LIN_9
487 <<
"\n " << MSH_QUA_4 <<
" " << MSH_QUA_9 <<
" " << MSH_QUA_16 <<
" " << MSH_QUA_25 <<
" " << MSH_QUA_36 <<
" " << MSH_QUA_49 <<
" " << MSH_QUA_64 <<
" " << MSH_QUA_81
488 <<
"\n " << MSH_HEX_8 <<
" " << MSH_HEX_27 <<
" " << MSH_HEX_64 <<
" " << MSH_HEX_125 <<
" " << MSH_HEX_216 <<
" " << MSH_HEX_343 <<
" " << MSH_HEX_512 <<
" " << MSH_HEX_729
502 unsigned int find_grid_order(std::ifstream &infile,
const bool mesh_reader_verbose_output)
505 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
506 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
508 auto entity_file_position = infile.tellg();
510 unsigned int grid_order = 0;
512 unsigned int n_entity_blocks, n_cells;
513 int min_ele_tag, max_ele_tag;
514 infile >> n_entity_blocks >> n_cells >> min_ele_tag >> max_ele_tag;
516 if(mesh_reader_verbose_output) pcout <<
"Finding grid order..." << std::endl;
517 if(mesh_reader_verbose_output) pcout << n_entity_blocks <<
" entity blocks with a total of " << n_cells <<
" cells. " << std::endl;
519 std::vector<unsigned int> vertices_id;
521 unsigned int global_cell = 0;
522 for (
unsigned int entity_block = 0; entity_block < n_entity_blocks; ++entity_block) {
523 unsigned long numElements;
526 int tagEntity, dimEntity;
527 infile >> dimEntity >> tagEntity >> cell_type >> numElements;
529 const unsigned int cell_order = gmsh_cell_type_to_order(cell_type);
530 const unsigned int nodes_per_element = std::pow(cell_order + 1, dimEntity);
532 grid_order = std::max(cell_order, grid_order);
534 vertices_id.resize(nodes_per_element);
536 for (
unsigned int cell_per_entity = 0; cell_per_entity < numElements; ++cell_per_entity, ++global_cell) {
539 AssertThrow(infile, dealii::ExcIO());
544 for (
unsigned int i = 0; i < nodes_per_element; ++i) {
545 infile >> vertices_id[i];
550 infile.seekg(entity_file_position);
552 AssertDimension(global_cell, n_cells);
553 if(mesh_reader_verbose_output) pcout <<
"Found grid order = " << grid_order << std::endl;
557 unsigned int ijk_to_num(
const unsigned int i,
558 const unsigned int j,
559 const unsigned int k,
560 const unsigned int n_per_line)
562 return i + j*n_per_line + k*n_per_line*n_per_line;
564 unsigned int ij_to_num(
const unsigned int i,
565 const unsigned int j,
566 const unsigned int n_per_line)
568 return i + j*n_per_line;
581 std::vector<unsigned int>
588 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
589 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
592 const unsigned int n = degree + 1;
594 const unsigned int dofs_per_face = dealii::Utilities::fixed_power<2>(n);
596 std::vector<unsigned int> h2l_2D(dofs_per_face);
602 if(mesh_reader_verbose_output) pcout <<
"DOF_PER_FACE = " << dofs_per_face << std::endl;
604 unsigned int next_index = 0;
605 int subdegree = degree;
606 int square_reduction = 0;
607 while (subdegree > 0) {
609 const unsigned int start = 0 + square_reduction;
610 const unsigned int end = n - square_reduction;
616 i = start; j = start;
617 h2l_2D[next_index++] = ij_to_num(i,j,n);
619 i = end-1; j = start;
620 h2l_2D[next_index++] = ij_to_num(i,j,n);
622 i = end-1; j = end-1;
623 h2l_2D[next_index++] = ij_to_num(i,j,n);
625 i = start; j = end-1;
626 h2l_2D[next_index++] = ij_to_num(i,j,n);
631 unsigned int j = start;
632 for (
unsigned int i = start+1; i < end-1; ++i)
633 h2l_2D[next_index++] = ij_to_num(i,j,n);
637 unsigned int i = end-1;
638 for (
unsigned int j = start+1; j < end-1; ++j)
639 h2l_2D[next_index++] = ij_to_num(i,j,n);
643 unsigned int j = end-1;
646 for (
int i = end-2; i > (int)start; --i)
647 h2l_2D[next_index++] = ij_to_num(i,j,n);
651 unsigned int i = start;
654 for (
int j = end-2; j > (int)start; --j)
655 h2l_2D[next_index++] = ij_to_num(i,j,n);
659 square_reduction += 1;
663 if (subdegree == 0) {
664 const unsigned int middle = (n-1)/2;
665 h2l_2D[next_index++] = ij_to_num(middle, middle, n);
668 Assert(next_index == dofs_per_face, dealii::ExcInternalError());
674 std::vector<unsigned int>
681 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
682 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
685 const unsigned int n = degree + 1;
687 const unsigned int dofs_per_cell = dealii::Utilities::fixed_power<dim>(n);
689 std::vector<unsigned int> h2l(dofs_per_cell);
696 const unsigned int inner_points_per_line = degree - 1;
710 h2l[1] = dofs_per_cell - 1;
711 for (
unsigned int i = 2; i < dofs_per_cell; ++i)
715 unsigned int next_index = 0;
717 int subdegree = degree;
718 int square_reduction = 0;
719 while (subdegree > 0) {
721 const unsigned int start = 0 + square_reduction;
722 const unsigned int end = n - square_reduction;
728 i = start; j = start;
729 h2l[next_index++] = ij_to_num(i,j,n);
731 i = end-1; j = start;
732 h2l[next_index++] = ij_to_num(i,j,n);
734 i = end-1; j = end-1;
735 h2l[next_index++] = ij_to_num(i,j,n);
737 i = start; j = end-1;
738 h2l[next_index++] = ij_to_num(i,j,n);
743 unsigned int j = start;
744 for (
unsigned int i = start+1; i < end-1; ++i)
745 h2l[next_index++] = ij_to_num(i,j,n);
749 unsigned int i = end-1;
750 for (
unsigned int j = start+1; j < end-1; ++j)
751 h2l[next_index++] = ij_to_num(i,j,n);
755 unsigned int j = end-1;
758 for (
int i = end-2; i > (int)start; --i)
759 h2l[next_index++] = ij_to_num(i,j,n);
763 unsigned int i = start;
766 for (
int j = end-2; j > (int)start; --j)
767 h2l[next_index++] = ij_to_num(i,j,n);
771 square_reduction += 1;
774 if (subdegree == 0) {
775 const unsigned int middle = (n-1)/2;
776 h2l[next_index++] = ij_to_num(middle, middle, n);
779 Assert(next_index == dofs_per_cell, dealii::ExcInternalError());
785 unsigned int next_index = 0;
786 std::vector<unsigned int> face_position;
787 std::vector<unsigned int> recursive_3D_position;
788 std::vector<unsigned int> recursive_3D_nodes;
789 std::vector<unsigned int> face_nodes;
792 h2l[next_index++] = 0;
793 h2l[next_index++] = (1) * degree;
794 h2l[next_index++] = (n + 1)*degree;
795 h2l[next_index++] = (n) * degree;
796 h2l[next_index++] = (n * n) * degree;
797 h2l[next_index++] = (n * n + 1) * degree;
798 h2l[next_index++] = (n * n + n + 1) * degree;
799 h2l[next_index++] = (n * n + n) * degree;
808 if(mesh_reader_verbose_output) pcout <<
"DEGREE " << degree << std::endl;
810 unsigned int n = degree - 1;
811 if(mesh_reader_verbose_output) pcout <<
"GMSH H2L " << std::endl;
812 for (
int j = n - 1; j >= 0; --j) {
813 for (
unsigned int i = 0; i < n; ++i) {
814 const unsigned int ij = ij_to_num(i, j, n);
815 if(mesh_reader_verbose_output) pcout << face_nodes[ij] <<
" ";
817 if(mesh_reader_verbose_output) pcout << std::endl;
821 if(mesh_reader_verbose_output) pcout <<
"" << std::endl;
825 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
826 h2l[next_index++] = i + 1;
827 if(mesh_reader_verbose_output) pcout <<
"line 0 - " << i + 1 << std::endl;
831 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
832 h2l[next_index++] = (i + 1) * n;
833 if(mesh_reader_verbose_output) pcout <<
"line 1 - " << (i + 1) * n << std::endl;
837 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
838 h2l[next_index++] = (i + 1) * n * n;
839 if(mesh_reader_verbose_output) pcout <<
"line 2 - " << (i + 1) * n * n << std::endl;
843 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
844 h2l[next_index++] = (2 + i) * n - 1;
845 if(mesh_reader_verbose_output) pcout <<
"line 3 - " << (2 + i) * n - 1 << std::endl;
849 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
850 h2l[next_index++] = (n * n * (i + 1)) + degree;
851 if(mesh_reader_verbose_output) pcout <<
"line 4 - " << (n * n * (i + 1)) + degree << std::endl;
855 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
856 h2l[next_index++] = n * n - (i + 1) - 1;
857 if(mesh_reader_verbose_output) pcout <<
"line 5 - " << n * n - (i + 1) - 1 << std::endl;
861 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
862 h2l[next_index++] = (degree * n + (n * n * (i+1))) + degree;
863 if(mesh_reader_verbose_output) pcout <<
"line 6 - " << (degree * n + (n * n * (i+1))) + degree << std::endl;
867 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
868 h2l[next_index++] = (degree * n + (n * n * (i+1)));
869 if(mesh_reader_verbose_output) pcout <<
"line 7 - " << (degree * n + (n * n * (i+1))) << std::endl;
873 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
874 h2l[next_index++] = (n * n) * degree + (i + 1);
875 if(mesh_reader_verbose_output) pcout <<
"line 8 - " << (n * n) * degree + (i + 1) << std::endl;
879 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
880 h2l[next_index++] = (i + 1) * n + (n * n) * degree;
881 if(mesh_reader_verbose_output) pcout <<
"line 9 - " << (i + 1) * n + (n * n) * degree << std::endl;
884 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
885 h2l[next_index++] = (2 + i) * n - 1 + (n * n) * degree;
886 if(mesh_reader_verbose_output) pcout <<
"line 10 - " << (2 + i) * n - 1 + (n * n) * degree << std::endl;
889 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
890 h2l[next_index++] = n * n * n - 1 - (i + 1);
891 if(mesh_reader_verbose_output) pcout <<
"line 11 - " << n * n * n - 1 - (i + 1) << std::endl;
896 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
897 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
898 if(mesh_reader_verbose_output) pcout <<
"Face 0 : " << n + 1 + (n * j) + (i) << std::endl;
899 face_position.push_back(n + 1 + (n * j) + (i));
903 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
904 h2l[next_index++] = face_position.at(face_nodes[i]);
907 face_position.clear();
910 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
911 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
912 if(mesh_reader_verbose_output) pcout <<
"Face 1 : " << (n * n * (i + 1)) + (j + 1) << std::endl;
913 face_position.push_back((n * n * (i + 1)) + (j + 1));
917 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
918 h2l[next_index++] = face_position.at(face_nodes[i]);
921 face_position.clear();
925 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
926 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
928 if(mesh_reader_verbose_output) pcout <<
"Face 2 : " << (n * n * (j + 1)) + n + i * n << std::endl;
929 face_position.push_back((n * n * (j + 1)) + n + i * n);
933 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
934 h2l[next_index++] = face_position.at(face_nodes[i]);
937 face_position.clear();
941 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
942 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
943 if(mesh_reader_verbose_output) pcout <<
"Face 3 : " << n * (j + 2) - 1 + i * (n * n) + n * n << std::endl;
944 face_position.push_back(n * (j + 2) - 1 + i * (n * n) + n * n);
948 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
949 h2l[next_index++] = face_position.at(face_nodes[i]);
952 face_position.clear();
956 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
957 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
958 if(mesh_reader_verbose_output) pcout <<
"Face 4 : " << (n * n * i) + (n * n * 2) - (j + 1) - 1 << std::endl;
959 face_position.push_back((n * n * i) + (n * n * 2) - (j + 1) - 1);
963 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
964 h2l[next_index++] = face_position.at(face_nodes[i]);
967 face_position.clear();
971 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
972 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
973 if(mesh_reader_verbose_output) pcout <<
"Face 5 : " << (n * n * degree + n + (j + 1)) + i * n << std::endl;
974 face_position.push_back((n * n * degree + n + (j + 1)) + i * n);
978 for (
unsigned int i = 0; i < (degree - 1) * (degree - 1); ++i) {
979 h2l[next_index++] = face_position.at(face_nodes[i]);
983 for (
unsigned int i = 0; i < inner_points_per_line; ++i) {
984 for (
unsigned int j = 0; j < inner_points_per_line; ++j) {
985 for (
unsigned int k = 0; k < inner_points_per_line; ++k) {
987 recursive_3D_position.push_back(n * n + ((j+1) * n) + (k + 1) + (n * n * i));
992 if(mesh_reader_verbose_output) pcout <<
"3D Inner Cube" << std::endl;
993 for (
unsigned int aInt: recursive_3D_position) {
994 if(mesh_reader_verbose_output) pcout << aInt << std::endl;
1002 h2l[next_index++] = recursive_3D_position.at(0);
1011 if(mesh_reader_verbose_output) pcout <<
"Begin recursive call to inner cube" << std::endl;
1012 recursive_3D_nodes = gmsh_hierarchic_to_lexicographic<dim>(degree - 2, mesh_reader_verbose_output);
1014 if(mesh_reader_verbose_output) pcout <<
"Printing recursive_3D_nodes" << std::endl;
1015 for (
unsigned int aInt : recursive_3D_nodes) {
1016 if(mesh_reader_verbose_output) pcout << aInt << std::endl;
1019 if(mesh_reader_verbose_output) pcout <<
"Degree = " << degree << std::endl;
1020 if(mesh_reader_verbose_output) pcout <<
"Dim = " << dim << std::endl;
1023 for (
unsigned int i = 0; i < pow((degree - 1),3); ++i) {
1024 h2l[next_index++] = recursive_3D_position.at(recursive_3D_nodes[i]);
1034 Assert(
false, dealii::ExcNotImplemented());
1042 unsigned int dealii_node_number(
const unsigned int i,
1043 const unsigned int j,
1044 const unsigned int k)
1049 void fe_q_node_number(
const unsigned int index,
1062 template <
int dim,
int spacedim>
1064 const std::vector<dealii::Point<spacedim>>& all_vertices,
1065 const std::vector<unsigned int>& deal_h2l,
1066 const std::vector<unsigned int>& rotate_z90degree,
1067 std::vector<unsigned int>& high_order_vertices_id)
1070 const unsigned int n_vertices = cell.n_vertices();
1071 for (
int zr = 0; zr < 4; ++zr) {
1073 std::vector<char> matching(n_vertices);
1075 for (
unsigned int i_vertex=0; i_vertex < n_vertices; ++i_vertex) {
1077 const unsigned int base_index = i_vertex;
1078 const unsigned int lexicographic_index = deal_h2l[base_index];
1080 const unsigned int vertex_id = high_order_vertices_id[lexicographic_index];
1081 const dealii::Point<dim,double> high_order_vertex = all_vertices[vertex_id];
1084 for (
unsigned int i=0; i < n_vertices; ++i) {
1085 if (cell.vertex(i) == high_order_vertex) {
1090 std::cout <<
"Wrong cell... High-order nodes do not match the cell's vertices." << std::endl;
1094 matching[i_vertex] = (high_order_vertex == cell.vertex(i_vertex)) ?
'T' :
'F';
1097 bool all_matching =
true;
1098 for (
unsigned int i=0; i < n_vertices; ++i) {
1099 if (matching[i] ==
'F') all_matching =
false;
1101 if (all_matching)
return true;
1103 const auto high_order_vertices_id_temp = high_order_vertices_id;
1104 for (
unsigned int i=0; i<high_order_vertices_id.size(); ++i) {
1105 high_order_vertices_id[i] = high_order_vertices_id_temp[rotate_z90degree[i]];
1114 template <
int dim,
int spacedim>
1116 const std::vector<dealii::Point<spacedim>>& all_vertices,
1117 const std::vector<unsigned int>& deal_h2l,
1118 const std::vector<unsigned int>& rotate_x90degree_3D,
1119 const std::vector<unsigned int>& rotate_y90degree_3D,
1120 const std::vector<unsigned int>& rotate_z90degree_3D,
1121 std::vector<unsigned int>& high_order_vertices_id_rotated,
1125 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
1126 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
1129 auto high_order_flip_id_rotated = high_order_vertices_id_rotated;
1130 auto high_order_x_id_rotated = high_order_vertices_id_rotated;
1131 auto high_order_y_id_rotated = high_order_vertices_id_rotated;
1132 auto high_order_vertices_id = high_order_vertices_id_rotated;
1134 const unsigned int n_vertices = cell.n_vertices();
1138 for (
int xr = 0; xr < 4; ++xr) {
1139 for (
int zr = 0; zr < 4; ++zr) {
1140 for (
int zr3d = 0; zr3d < 4; ++zr3d) {
1142 std::vector<char> matching(n_vertices);
1145 for (
unsigned int i_vertex = 0; i_vertex < n_vertices; ++i_vertex) {
1147 const unsigned int base_index = i_vertex;
1150 const unsigned int lexicographic_index = deal_h2l[base_index];
1152 const unsigned int vertex_id = high_order_vertices_id_rotated[lexicographic_index];
1155 const dealii::Point<dim, double> high_order_vertex = all_vertices[vertex_id];
1162 for (
unsigned int i = 0; i < n_vertices; ++i) {
1163 if (cell.vertex(i) == high_order_vertex) {
1170 <<
"Wrong cell... High order nodes do not match the cell's vertices | " 1171 <<
"mpi_rank = " << mpi_rank << std::endl;
1176 matching[i_vertex] = (high_order_vertex == cell.vertex(i_vertex)) ? 0 : 1;
1185 bool all_matching =
true;
1186 for (
unsigned int i = 0; i < n_vertices; ++i) {
1187 if (matching[i] == 1) all_matching =
false;
1191 good_rotation = all_matching;
1194 if (good_rotation) {
1200 high_order_vertices_id = high_order_vertices_id_rotated;
1201 for (
unsigned int i = 0; i < high_order_vertices_id.size(); ++i) {
1202 high_order_vertices_id_rotated[i] = high_order_vertices_id[rotate_z90degree_3D[i]];
1207 if (good_rotation) {
1213 high_order_y_id_rotated = high_order_vertices_id_rotated;
1214 for (
unsigned int i = 0; i < high_order_vertices_id.size(); ++i) {
1215 high_order_vertices_id_rotated[i] = high_order_y_id_rotated[rotate_y90degree_3D[i]];
1220 if (good_rotation) {
1226 high_order_x_id_rotated = high_order_vertices_id_rotated;
1227 for (
unsigned int i = 0; i < high_order_vertices_id.size(); ++i) {
1228 high_order_vertices_id_rotated[i] = high_order_x_id_rotated[rotate_x90degree_3D[i]];
1233 if (good_rotation) {
1245 template <
int dim,
int spacedim>
1246 std::shared_ptr< HighOrderGrid<dim, double> >
1248 const bool periodic_x,
const bool periodic_y,
const bool periodic_z,
1249 const int x_periodic_1,
const int x_periodic_2,
1250 const int y_periodic_1,
const int y_periodic_2,
1251 const int z_periodic_1,
const int z_periodic_2,
1252 const bool mesh_reader_verbose_output,
1253 const bool do_renumber_dofs,
1254 int requested_grid_order,
1255 const bool use_mesh_smoothing)
1258 const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
1259 dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
1262 std::ifstream infile;
1264 open_file_toRead(filename, infile);
1271 std::array<std::map<int, int>, 4> tag_maps;
1279 unsigned int gmsh_file_format = 0;
1280 if (line ==
"$MeshFormat") {
1281 gmsh_file_format = 20;
1288 if (gmsh_file_format == 20) {
1290 unsigned int file_type, data_size;
1292 infile >> version >> file_type >> data_size;
1294 Assert((version == 4.1), dealii::ExcNotImplemented());
1295 gmsh_file_format =
static_cast<unsigned int>(version * 10);
1298 Assert(file_type == 0, dealii::ExcNotImplemented());
1299 Assert(data_size ==
sizeof(
double), dealii::ExcNotImplemented());
1309 if (line ==
"$PhysicalNames") {
1312 }
while (line !=
"$EndPhysicalNames");
1318 if (line ==
"$Entities") read_gmsh_entities(infile, tag_maps);
1322 if (line ==
"$PartitionedEntities") {
1325 }
while (line !=
"$EndPartitionedEntities");
1335 std::vector<dealii::Point<spacedim>> vertices;
1341 std::map<int, int> vertex_indices;
1342 read_gmsh_nodes( infile, vertices, vertex_indices, mesh_reader_verbose_output );
1346 static const std::string end_nodes_marker =
"$EndNodes";
1351 static const std::string begin_elements_marker =
"$Elements";
1354 const unsigned int grid_order = find_grid_order<dim>(infile,mesh_reader_verbose_output);
1356 using Triangulation = dealii::parallel::distributed::Triangulation<dim>;
1357 std::shared_ptr<Triangulation> triangulation;
1359 if(use_mesh_smoothing) {
1360 triangulation = std::make_shared<Triangulation>(
1362 typename dealii::Triangulation<dim>::MeshSmoothing(
1363 dealii::Triangulation<dim>::smoothing_on_refinement |
1364 dealii::Triangulation<dim>::smoothing_on_coarsening));
1368 triangulation = std::make_shared<Triangulation>(MPI_COMM_WORLD);
1371 auto high_order_grid = std::make_shared<HighOrderGrid<dim, double>>(grid_order, triangulation);
1373 unsigned int n_entity_blocks, n_cells;
1374 int min_ele_tag, max_ele_tag;
1375 infile >> n_entity_blocks >> n_cells >> min_ele_tag >> max_ele_tag;
1381 std::vector<dealii::CellData<dim>> p1_cells;
1382 std::vector<dealii::CellData<dim>> high_order_cells;
1383 dealii::CellData<dim> temp_high_order_cells;
1385 dealii::SubCellData subcelldata;
1386 std::map<unsigned int, dealii::types::boundary_id> boundary_ids_1d;
1388 unsigned int global_cell = 0;
1389 for (
unsigned int entity_block = 0; entity_block < n_entity_blocks; ++entity_block) {
1390 unsigned int material_id;
1391 unsigned long numElements;
1395 int tagEntity, dimEntity;
1396 infile >> dimEntity >> tagEntity >> cell_type >> numElements;
1397 material_id = tag_maps[dimEntity][tagEntity];
1399 const unsigned int cell_order = gmsh_cell_type_to_order(cell_type);
1401 unsigned int vertices_per_element = std::pow(2, dimEntity);
1402 unsigned int nodes_per_element = std::pow(cell_order + 1, dimEntity);
1405 for (
unsigned int cell_per_entity = 0; cell_per_entity < numElements; ++cell_per_entity, ++global_cell) {
1411 if (dimEntity == dim) {
1418 p1_cells.emplace_back(vertices_per_element);
1419 high_order_cells.emplace_back(vertices_per_element);
1421 auto &p1_vertices_id = p1_cells.back().vertices;
1422 auto &high_order_vertices_id = high_order_cells.back().vertices;
1424 p1_vertices_id.resize(vertices_per_element);
1425 high_order_vertices_id.resize(nodes_per_element);
1427 for (
unsigned int i = 0; i < nodes_per_element; ++i) {
1428 infile >> high_order_vertices_id[i];
1430 for (
unsigned int i = 0; i < vertices_per_element; ++i) {
1431 p1_vertices_id[i] = high_order_vertices_id[i];
1435 Assert(material_id <= std::numeric_limits<dealii::types::material_id>::max(),
1436 dealii::ExcIndexRange( material_id, 0, std::numeric_limits<dealii::types::material_id>::max()));
1438 AssertIndexRange(material_id, dealii::numbers::invalid_material_id);
1440 p1_cells.back().material_id = material_id;
1443 for (
unsigned int i = 0; i < vertices_per_element; ++i) {
1448 p1_vertices_id[i] = vertex_indices[p1_cells.back().vertices[i]];
1450 for (
unsigned int i = 0; i < nodes_per_element; ++i) {
1451 high_order_vertices_id[i] = vertex_indices[high_order_cells.back().vertices[i]];
1453 }
else if (dimEntity == 1 && dimEntity < dim) {
1456 subcelldata.boundary_lines.emplace_back(vertices_per_element);
1457 auto &p1_vertices_id = subcelldata.boundary_lines.back().vertices;
1458 p1_vertices_id.resize(vertices_per_element);
1460 temp_high_order_cells.vertices.resize(nodes_per_element);
1462 for (
unsigned int i = 0; i < nodes_per_element; ++i) {
1463 infile >> temp_high_order_cells.vertices[i];
1465 for (
unsigned int i = 0; i < vertices_per_element; ++i) {
1466 p1_vertices_id[i] = temp_high_order_cells.vertices[i];
1470 Assert(material_id <= std::numeric_limits<dealii::types::boundary_id>::max(),
1471 dealii::ExcIndexRange( material_id, 0, std::numeric_limits<dealii::types::boundary_id>::max()));
1473 AssertIndexRange(material_id, dealii::numbers::internal_face_boundary_id);
1475 subcelldata.boundary_lines.back().boundary_id =
static_cast<dealii::types::boundary_id
>(material_id);
1478 for (
unsigned int &vertex : subcelldata.boundary_lines.back().vertices) {
1479 if (vertex_indices.find(vertex) != vertex_indices.end()) {
1480 vertex = vertex_indices[vertex];
1484 vertex = dealii::numbers::invalid_unsigned_int;
1488 }
else if (dimEntity == 2 && dimEntity < dim) {
1491 subcelldata.boundary_quads.emplace_back(vertices_per_element);
1492 auto &p1_vertices_id = subcelldata.boundary_quads.back().vertices;
1493 p1_vertices_id.resize(vertices_per_element);
1495 temp_high_order_cells.vertices.resize(nodes_per_element);
1497 for (
unsigned int i = 0; i < nodes_per_element; ++i) {
1498 infile >> temp_high_order_cells.vertices[i];
1500 for (
unsigned int i = 0; i < vertices_per_element; ++i) {
1501 p1_vertices_id[i] = temp_high_order_cells.vertices[i];
1505 Assert(material_id <= std::numeric_limits<dealii::types::boundary_id>::max(),
1506 dealii::ExcIndexRange( material_id, 0, std::numeric_limits<dealii::types::boundary_id>::max()));
1508 AssertIndexRange(material_id, dealii::numbers::internal_face_boundary_id);
1510 subcelldata.boundary_quads.back().boundary_id =
static_cast<dealii::types::boundary_id
>(material_id);
1513 for (
unsigned int &vertex : subcelldata.boundary_quads.back().vertices) {
1514 if (vertex_indices.find(vertex) != vertex_indices.end()) {
1515 vertex = vertex_indices[vertex];
1519 vertex = dealii::numbers::invalid_unsigned_int;
1522 }
else if (cell_type == MSH_PNT) {
1524 unsigned int node_index = 0;
1525 infile >> node_index;
1530 boundary_ids_1d[vertex_indices[node_index]] = material_id;
1538 AssertDimension(global_cell, n_cells);
1542 static const std::string end_elements_marker[] = {
"$ENDELM",
"$EndElements"};
1547 Assert(subcelldata.check_consistency(dim), dealii::ExcInternalError());
1549 AssertThrow(infile, dealii::ExcIO());
1555 const std::vector<dealii::Point<spacedim>> all_vertices = vertices;
1556 dealii::GridTools::delete_unused_vertices(vertices, p1_cells, subcelldata);
1559 if (dim == spacedim) {
1560 dealii::GridReordering<dim, spacedim>::invert_all_cells_of_negative_grid(vertices, p1_cells);
1562 dealii::GridReordering<dim, spacedim>::reorder_cells(p1_cells);
1563 triangulation->create_triangulation_compatibility(vertices, p1_cells, subcelldata);
1565 triangulation->repartition();
1567 dealii::GridOut gridout;
1568 gridout.write_mesh_per_processor_as_vtu(*(high_order_grid->triangulation),
"tria");
1576 high_order_grid->initialize_with_triangulation_manifold();
1578 std::vector<unsigned int> deal_h2l = dealii::FETools::hierarchic_to_lexicographic_numbering<dim>(grid_order);
1579 std::vector<unsigned int> deal_l2h = dealii::Utilities::invert_permutation(deal_h2l);
1581 std::vector<unsigned int> gmsh_h2l = gmsh_hierarchic_to_lexicographic<dim>(grid_order,mesh_reader_verbose_output);
1582 std::vector<unsigned int> gmsh_l2h = dealii::Utilities::invert_permutation(gmsh_h2l);
1585 std::vector<dealii::types::global_dof_index> dof_indices(high_order_grid->fe_system.dofs_per_cell);
1587 std::vector<unsigned int> rotate_z90degree;
1592 std::vector<unsigned int> rotate_z90degree_3D;
1593 std::vector<unsigned int> rotate_y90degree_3D;
1594 std::vector<unsigned int> rotate_x90degree_3D;
1595 std::vector<unsigned int> rotate_flip_z90degree_3D;
1598 if constexpr(dim == 2) {
1599 if(mesh_reader_verbose_output) pcout <<
"Allocating 2D Rotate Z matrix..." << std::endl;
1600 rotate_indices<dim>(rotate_z90degree, grid_order+1,
'Z', mesh_reader_verbose_output);
1603 if(mesh_reader_verbose_output) pcout <<
"Allocating 3D Rotate Z matrix..." << std::endl;
1604 rotate_indices<dim>(rotate_z90degree_3D, grid_order + 1,
'Z', mesh_reader_verbose_output);
1605 if(mesh_reader_verbose_output) pcout <<
"Allocating 3D Rotate Y matrix..." << std::endl;
1606 rotate_indices<dim>(rotate_y90degree_3D, grid_order + 1,
'Y', mesh_reader_verbose_output);
1607 if(mesh_reader_verbose_output) pcout <<
"Allocating 3D Rotate X matrix..." << std::endl;
1608 rotate_indices<dim>(rotate_x90degree_3D, grid_order + 1,
'X', mesh_reader_verbose_output);
1609 if(mesh_reader_verbose_output) pcout <<
"Allocating 3D Rotate FLIP matrix..." << std::endl;
1610 rotate_indices<dim>(rotate_flip_z90degree_3D, grid_order + 1,
'F', mesh_reader_verbose_output);
1613 if(mesh_reader_verbose_output) pcout <<
" " << std::endl;
1614 if(mesh_reader_verbose_output) pcout <<
"*********************************************************************\n";
1615 if(mesh_reader_verbose_output) pcout <<
"//********************** BEGIN ROTATING CELLS *********************//\n";
1616 if(mesh_reader_verbose_output) pcout <<
"*********************************************************************\n";
1617 if(mesh_reader_verbose_output) pcout <<
" " << std::endl;
1622 for (
const auto &cell : high_order_grid->dof_handler_grid.active_cell_iterators()) {
1623 if (cell->is_locally_owned()) {
1624 auto &high_order_vertices_id = high_order_cells[icell].vertices;
1626 auto high_order_vertices_id_lexico = high_order_vertices_id;
1627 for (
unsigned int ihierachic=0; ihierachic<high_order_vertices_id.size(); ++ihierachic) {
1628 const unsigned int lexico_id = gmsh_h2l[ihierachic];
1629 high_order_vertices_id_lexico[lexico_id] = high_order_vertices_id[ihierachic];
1633 auto high_order_vertices_id_rotated = high_order_vertices_id_lexico;
1635 if constexpr(dim == 2) {
1637 bool good_rotation =
get_new_rotated_indices(*cell, all_vertices, deal_h2l, rotate_z90degree, high_order_vertices_id_rotated);
1638 if (!good_rotation) {
1642 std::vector<unsigned int> flipZ;
1643 rotate_indices<dim>(flipZ, grid_order+1,
'3', mesh_reader_verbose_output);
1644 auto high_order_vertices_id_copy = high_order_vertices_id_rotated;
1645 for (
unsigned int i=0; i<high_order_vertices_id_rotated.size(); ++i) {
1646 high_order_vertices_id_rotated[i] = high_order_vertices_id_copy[flipZ[i]];
1648 good_rotation =
get_new_rotated_indices(*cell, all_vertices, deal_h2l, rotate_z90degree, high_order_vertices_id_rotated);
1651 if (!good_rotation) {
1652 std::cout <<
"Couldn't find rotation after flipping either... Aborting..." << std::endl;
1658 bool good_rotation =
get_new_rotated_indices_3D(*cell, all_vertices, deal_h2l, rotate_x90degree_3D, rotate_y90degree_3D, rotate_z90degree_3D, high_order_vertices_id_rotated, mesh_reader_verbose_output);
1659 if (!good_rotation) {
1660 if(mesh_reader_verbose_output) pcout <<
"3D -- Couldn't find rotation... Flipping Z axis and doing it again" << std::endl;
1663 auto high_order_vertices_id_copy = high_order_vertices_id_rotated;
1664 for (
unsigned int i=0; i<high_order_vertices_id_rotated.size(); ++i) {
1665 high_order_vertices_id_rotated[i] = high_order_vertices_id_copy[rotate_flip_z90degree_3D[i]];
1669 good_rotation =
get_new_rotated_indices_3D(*cell, all_vertices, deal_h2l, rotate_x90degree_3D, rotate_y90degree_3D, rotate_z90degree_3D, high_order_vertices_id_rotated, mesh_reader_verbose_output);
1672 if (!good_rotation) {
1673 if(mesh_reader_verbose_output) pcout <<
"3D -- Couldn't find rotation after flipping 3D either... Aborting..." << std::endl;
1678 cell->get_dof_indices(dof_indices);
1679 for (
unsigned int i_vertex = 0; i_vertex < high_order_vertices_id.size(); ++i_vertex) {
1681 const unsigned int base_index = i_vertex;
1682 const unsigned int lexicographic_index = deal_h2l[base_index];
1684 const unsigned int vertex_id = high_order_vertices_id_rotated[lexicographic_index];
1685 const dealii::Point<dim,double> vertex = all_vertices[vertex_id];
1688 for (
int d = 0; d < dim; ++d) {
1689 const unsigned int comp = d;
1690 const unsigned int shape_index = high_order_grid->dof_handler_grid.get_fe().component_to_system_index(comp, base_index);
1691 const unsigned int idof_global = dof_indices[shape_index];
1692 high_order_grid->volume_nodes[idof_global] = vertex[d];
1699 if(mesh_reader_verbose_output) pcout <<
" " << std::endl;
1700 if(mesh_reader_verbose_output) pcout <<
"*********************************************************************\n";
1701 if(mesh_reader_verbose_output) pcout <<
"//********************** DONE ROTATING CELLS **********************//\n";
1702 if(mesh_reader_verbose_output) pcout <<
"*********************************************************************\n";
1703 if(mesh_reader_verbose_output) pcout <<
" " << std::endl;
1705 high_order_grid->volume_nodes.update_ghost_values();
1706 high_order_grid->ensure_conforming_mesh();
1710 std::vector<dealii::Point<1>> equidistant_points(grid_order+1);
1711 const double dx = 1.0 / grid_order;
1712 for (
unsigned int i=0; i<grid_order+1; ++i) {
1713 equidistant_points[i](0) = i*dx;
1715 dealii::Quadrature<1> quad_equidistant(equidistant_points);
1716 dealii::FE_Q<dim> fe_q_equidistant(quad_equidistant);
1717 dealii::FESystem<dim> fe_system_equidistant(fe_q_equidistant, dim);
1718 dealii::DoFHandler<dim> dof_handler_equidistant(*triangulation);
1720 dof_handler_equidistant.initialize(*triangulation, fe_system_equidistant);
1721 dof_handler_equidistant.distribute_dofs(fe_system_equidistant);
1723 if(do_renumber_dofs) dealii::DoFRenumbering::Cuthill_McKee(dof_handler_equidistant);
1725 auto equidistant_nodes = high_order_grid->volume_nodes;
1726 equidistant_nodes.update_ghost_values();
1727 high_order_grid->volume_nodes.update_ghost_values();
1728 dealii::FETools::interpolate(dof_handler_equidistant, equidistant_nodes, high_order_grid->dof_handler_grid, high_order_grid->volume_nodes);
1729 high_order_grid->volume_nodes.update_ghost_values();
1730 high_order_grid->ensure_conforming_mesh();
1733 high_order_grid->update_surface_nodes();
1734 high_order_grid->update_mapping_fe_field();
1735 high_order_grid->reset_initial_nodes();
1738 std::vector<dealii::GridTools::PeriodicFacePair<typename dealii::Triangulation<dim>::cell_iterator> > matched_pairs;
1741 dealii::GridTools::collect_periodic_faces(*high_order_grid->triangulation, x_periodic_1, x_periodic_2, 0, matched_pairs);
1745 dealii::GridTools::collect_periodic_faces(*high_order_grid->triangulation, y_periodic_1, y_periodic_2, 1, matched_pairs);
1749 dealii::GridTools::collect_periodic_faces(*high_order_grid->triangulation, z_periodic_1, z_periodic_2, 2, matched_pairs);
1752 if (periodic_x || periodic_y || periodic_z) {
1753 high_order_grid->triangulation->add_periodicity(matched_pairs);
1757 if (requested_grid_order > 0) {
1758 auto grid = std::make_shared<HighOrderGrid<dim, double>>(requested_grid_order, triangulation);
1759 grid->initialize_with_triangulation_manifold();
1763 std::vector<dealii::Point<1>> equidistant_points(grid_order+1);
1764 const double dx = 1.0 / grid_order;
1765 for (
unsigned int i=0; i<grid_order+1; ++i) {
1766 equidistant_points[i](0) = i*dx;
1768 dealii::Quadrature<1> quad_equidistant(equidistant_points);
1769 dealii::FE_Q<dim> fe_q_equidistant(quad_equidistant);
1770 dealii::FESystem<dim> fe_system_equidistant(fe_q_equidistant, dim);
1771 dealii::DoFHandler<dim> dof_handler_equidistant(*triangulation);
1773 dof_handler_equidistant.initialize(*triangulation, fe_system_equidistant);
1774 dof_handler_equidistant.distribute_dofs(fe_system_equidistant);
1776 if(do_renumber_dofs) dealii::DoFRenumbering::Cuthill_McKee(dof_handler_equidistant);
1778 auto equidistant_nodes = high_order_grid->volume_nodes;
1779 equidistant_nodes.update_ghost_values();
1780 grid->volume_nodes.update_ghost_values();
1781 dealii::FETools::interpolate(dof_handler_equidistant, equidistant_nodes, grid->dof_handler_grid, grid->volume_nodes);
1782 grid->volume_nodes.update_ghost_values();
1783 grid->ensure_conforming_mesh();
1785 grid->update_surface_nodes();
1786 grid->update_mapping_fe_field();
1787 grid->reset_initial_nodes();
1790 std::vector<dealii::GridTools::PeriodicFacePair<typename dealii::Triangulation<dim>::cell_iterator> > matched_pairs;
1793 dealii::GridTools::collect_periodic_faces(*grid->triangulation, x_periodic_1, x_periodic_2, 0, matched_pairs);
1797 dealii::GridTools::collect_periodic_faces(*grid->triangulation, y_periodic_1, y_periodic_2, 1, matched_pairs);
1801 dealii::GridTools::collect_periodic_faces(*grid->triangulation, z_periodic_1, z_periodic_2, 2, matched_pairs);
1804 if (periodic_x || periodic_y || periodic_z) {
1805 grid->triangulation->add_periodicity(matched_pairs);
1811 return high_order_grid;
1815 template <
int dim,
int spacedim>
1816 std::shared_ptr< HighOrderGrid<dim, double> >
1817 read_gmsh(std::string filename,
const bool do_renumber_dofs,
int requested_grid_order,
const bool use_mesh_smoothing)
1820 const bool periodic_x =
false;
1821 const bool periodic_y =
false;
1822 const bool periodic_z =
false;
1823 const int x_periodic_1 = 0;
1824 const int x_periodic_2 = 0;
1825 const int y_periodic_1 = 0;
1826 const int y_periodic_2 = 0;
1827 const int z_periodic_1 = 0;
1828 const int z_periodic_2 = 0;
1829 const bool mesh_reader_verbose_output =
true;
1831 return read_gmsh<dim,spacedim>(filename,
1832 periodic_x, periodic_y, periodic_z,
1833 x_periodic_1, x_periodic_2,
1834 y_periodic_1, y_periodic_2,
1835 z_periodic_1, z_periodic_2,
1836 mesh_reader_verbose_output,
1838 requested_grid_order,
1839 use_mesh_smoothing);
1843 template std::shared_ptr< HighOrderGrid<PHILIP_DIM, double> > read_gmsh<PHILIP_DIM,PHILIP_DIM>(std::string filename,
const bool periodic_x,
const bool periodic_y,
const bool periodic_z,
const int x_periodic_1,
const int x_periodic_2,
const int y_periodic_1,
const int y_periodic_2,
const int z_periodic_1,
const int z_periodic_2,
const bool mesh_reader_verbose_output,
const bool do_renumber_dofs,
int requested_grid_order,
const bool use_mesh_smoothing);
1844 template std::shared_ptr< HighOrderGrid<PHILIP_DIM, double> > read_gmsh<PHILIP_DIM,PHILIP_DIM>(std::string filename,
const bool do_renumber_dofs,
int requested_grid_order,
const bool use_mesh_smoothing);
std::vector< unsigned int > gmsh_hierarchic_to_lexicographic(const unsigned int degree, const bool mesh_reader_verbose_output)
void assign_1d_boundary_ids(const std::map< unsigned int, dealii::types::boundary_id > &boundary_ids, dealii::Triangulation< 1, spacedim > &triangulation)
std::shared_ptr< HighOrderGrid< dim, double > > read_gmsh(std::string filename, const bool periodic_x, const bool periodic_y, const bool periodic_z, const int x_periodic_1, const int x_periodic_2, const int y_periodic_1, const int y_periodic_2, const int z_periodic_1, const int z_periodic_2, const bool mesh_reader_verbose_output, const bool do_renumber_dofs, int requested_grid_order, const bool use_mesh_smoothing)
void rotate_indices(std::vector< unsigned int > &numbers, const unsigned int n_indices_per_direction, const char direction, const bool mesh_reader_verbose_output)
Files for the baseline physics.
std::vector< unsigned int > face_node_finder(const unsigned int degree, const bool mesh_reader_verbose_output)
bool get_new_rotated_indices(const dealii::CellAccessor< dim, spacedim > &cell, const std::vector< dealii::Point< spacedim >> &all_vertices, const std::vector< unsigned int > &deal_h2l, const std::vector< unsigned int > &rotate_z90degree, std::vector< unsigned int > &high_order_vertices_id)
bool get_new_rotated_indices_3D(const dealii::CellAccessor< dim, spacedim > &cell, const std::vector< dealii::Point< spacedim >> &all_vertices, const std::vector< unsigned int > &deal_h2l, const std::vector< unsigned int > &rotate_x90degree_3D, const std::vector< unsigned int > &rotate_y90degree_3D, const std::vector< unsigned int > &rotate_z90degree_3D, std::vector< unsigned int > &high_order_vertices_id_rotated, const bool)
unsigned int find_grid_order(std::ifstream &infile, const bool mesh_reader_verbose_output)