100 if constexpr (SPACE_DIM == 2)
104 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
105 p_pts->GetData()->SetName(
"Vertex positions");
109 const unsigned n_vertices = rMesh.GetNumNodes();
110 for (
unsigned node_num = 0; node_num < rMesh.GetNumNodes(); node_num++)
112 c_vector<double, SPACE_DIM> position = rMesh.GetNode(node_num)->rGetLocation();
113 p_pts->InsertPoint(node_num, position[0], position[1], 0.0);
124 const unsigned num_elements = rMesh.GetNumElements();
125 std::vector<unsigned> cell_offset_dist(rMesh.GetNumElements());
126 cell_offset_dist[0] = n_vertices;
127 for (
unsigned i = 1; i < num_elements; ++i)
128 cell_offset_dist[i] = cell_offset_dist[i - 1] + rMesh.GetElement(i - 1)->GetNumNodes();
130 const double alpha = 0.8;
132 for (
auto elem = rMesh.GetElementIteratorBegin(); elem != elem_end; ++elem)
134 const unsigned num_elem_nodes = elem->GetNumNodes();
135 const c_vector<double, SPACE_DIM> elem_centroid = rMesh.GetCentroidOfElement(elem->GetIndex());
136 for (
unsigned elem_node_num = 0; elem_node_num < num_elem_nodes; elem_node_num++)
138 c_vector<double, SPACE_DIM> node_position = elem->GetNode(elem_node_num)->rGetLocation();
139 const double new_x = (node_position[0] - elem_centroid[0]) * alpha + elem_centroid[0];
140 const double new_y = (node_position[1] - elem_centroid[1]) * alpha + elem_centroid[1];
141 p_pts->InsertPoint(cell_offset_dist[elem->GetIndex()] + elem_node_num,
145 mpVtkUnstructedMesh->SetPoints(p_pts);
149 [[maybe_unused]]
unsigned total_num_edges = 0;
150 for (
auto elem = rMesh.GetElementIteratorBegin(); elem != elem_end; ++elem)
153 for (
unsigned edge_index = 0; edge_index < elem->GetNumEdges(); ++edge_index)
156 p_cell = vtkQuad::New();
157 const unsigned num_trap_nodes = p_cell->GetNumberOfEdges();
158 assert(num_trap_nodes == 4);
159 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
160 p_cell_id_list->SetNumberOfIds(num_trap_nodes);
161 auto p_edge = elem->GetEdge(edge_index);
162 assert(p_edge->GetNumNodes() == 2);
165 std::array<unsigned, 2> base_ids = { { p_edge->GetNode(0)->GetIndex(), p_edge->GetNode(1)->GetIndex() } };
166 std::array<unsigned, 2> top_ids = { { elem->GetNodeLocalIndex(base_ids[0])
167 + cell_offset_dist[elem->GetIndex()],
168 elem->GetNodeLocalIndex(base_ids[1]) + cell_offset_dist[elem->GetIndex()] } };
171 p_cell_id_list->SetId(0, base_ids[0]);
172 p_cell_id_list->SetId(1, base_ids[1]);
173 p_cell_id_list->SetId(2, top_ids[1]);
174 p_cell_id_list->SetId(3, top_ids[0]);
175 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
182 p_cell = vtkPolygon::New();
183 const unsigned num_elem_nodes = elem->GetNumNodes();
184 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
185 p_cell_id_list->SetNumberOfIds(num_elem_nodes);
186 for (
unsigned j = 0; j < num_elem_nodes; ++j)
188 p_cell_id_list->SetId(j, cell_offset_dist[elem->GetIndex()] + j);
191 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
197 assert(total_num_edges + num_elements == mpVtkUnstructedMesh->GetNumberOfCells());