129 assert(SPACE_DIM == 3);
131 assert(this->mNumElements == mpMesh->GetNumElements());
137 elem_data.
NodeIndices.resize((*(mpIters->pElemIter))->GetNumNodes());
138 for (
unsigned j=0; j<elem_data.
NodeIndices.size(); j++)
140 unsigned old_index = (*(mpIters->pElemIter))->GetNodeGlobalIndex(j);
141 elem_data.
NodeIndices[j] = mpMesh->IsMeshChanging() ? mpNodeMap->GetNewIndex(old_index) : old_index;
145 elem_data.
Faces.resize((*(mpIters->pElemIter))->GetNumFaces());
146 for (
unsigned i=0; i<elem_data.
Faces.size(); i++)
158 face_data.
NodeIndices.resize(p_face->GetNumNodes());
159 for (
unsigned j=0; j<face_data.
NodeIndices.size(); j++)
161 unsigned old_index = p_face->GetNodeGlobalIndex(j);
162 face_data.
NodeIndices[j] = mpMesh->IsMeshChanging() ? mpNodeMap->GetNewIndex(old_index) : old_index;
166 elem_data.
Faces[i] = face_data;
173 ++(*(mpIters->pElemIter));
211 assert(SPACE_DIM==3 || SPACE_DIM == 2);
217 assert(mpVtkUnstructedMesh->CheckAttributes() == 0);
218 vtkXMLUnstructuredGridWriter* p_writer = vtkXMLUnstructuredGridWriter::New();
219#if VTK_MAJOR_VERSION >= 6
220 p_writer->SetInputData(mpVtkUnstructedMesh);
222 p_writer->SetInput(mpVtkUnstructedMesh);
226 p_writer->SetCompressor(
nullptr);
229 std::string vtk_file_name = this->mpOutputFileHandler->GetOutputDirectoryFullPath() + this->mBaseName;
232 vtk_file_name +=
"_" + stamp;
234 vtk_file_name +=
".vtu";
236 p_writer->SetFileName(vtk_file_name.c_str());
255 MakeVtkMesh(*p_mesh_for_vtk);
258 assert(mpVtkUnstructedMesh->CheckAttributes() == 0);
259 vtkXMLUnstructuredGridWriter* p_writer = vtkXMLUnstructuredGridWriter::New();
260#if VTK_MAJOR_VERSION >= 6
261 p_writer->SetInputData(mpVtkUnstructedMesh);
263 p_writer->SetInput(mpVtkUnstructedMesh);
267 p_writer->SetCompressor(
nullptr);
270 std::string vtk_file_name = this->mpOutputFileHandler->GetOutputDirectoryFullPath() + this->mBaseName;
273 vtk_file_name +=
"_" + stamp;
275 vtk_file_name +=
".vtu";
277 p_writer->SetFileName(vtk_file_name.c_str());
289 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
290 p_pts->GetData()->SetName(
"Vertex positions");
291 for (
unsigned node_num = 0; node_num < rMesh.
GetNumNodes(); node_num++)
293 c_vector<double, SPACE_DIM> position;
294 position = rMesh.
GetNode(node_num)->rGetLocation();
295 if constexpr (SPACE_DIM == 2)
297 p_pts->InsertPoint(node_num, position[0], position[1], 0.0);
299 else if constexpr (SPACE_DIM == 3)
301 p_pts->InsertPoint(node_num, position[0], position[1], position[2]);
309 mpVtkUnstructedMesh->SetPoints(p_pts);
318 p_cell = vtkPolygon::New();
322 p_cell = vtkConvexPointSet::New();
324 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
325 p_cell_id_list->SetNumberOfIds(iter->GetNumNodes());
326 for (
unsigned j=0; j<iter->GetNumNodes(); ++j)
328 p_cell_id_list->SetId(j, iter->GetNodeGlobalIndex(j));
330 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
340 vtkDoubleArray* p_scalars = vtkDoubleArray::New();
341 p_scalars->SetName(dataName.c_str());
342 for (
unsigned i=0; i<dataPayload.size(); i++)
344 p_scalars->InsertNextValue(dataPayload[i]);
347 vtkCellData* p_cell_data = mpVtkUnstructedMesh->GetCellData();
348 p_cell_data->AddArray(p_scalars);
357 vtkDoubleArray* p_scalars = vtkDoubleArray::New();
358 p_scalars->SetName(dataName.c_str());
359 for (
unsigned i=0; i<dataPayload.size(); i++)
361 p_scalars->InsertNextValue(dataPayload[i]);
364 vtkPointData* p_point_data = mpVtkUnstructedMesh->GetPointData();
365 p_point_data->AddArray(p_scalars);
374 this->mpMeshReader =
nullptr;
378 this->mNumElements = mpMesh->GetNumElements();
381 mpIters->pNodeIter =
new NodeIterType(mpMesh->GetNodeIteratorBegin());
384 mpIters->pElemIter =
new ElemIterType(mpMesh->GetElementIteratorBegin());
387 mNodeMapCurrentIndex = 0;
388 if (mpMesh->IsMeshChanging())
390 mpNodeMap =
new NodeMap(mpMesh->GetNumAllNodes());
391 for (NodeIterType it = mpMesh->GetNodeIteratorBegin(); it != mpMesh->GetNodeIteratorEnd(); ++it)
393 mpNodeMap->SetNewIndex(it->GetIndex(), mNodeMapCurrentIndex++);
405 std::string node_file_name = this->mBaseName +
".node";
406 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
409 unsigned num_attr = 0;
410 unsigned max_bdy_marker = 1;
411 unsigned num_nodes = this->GetNumNodes();
413 *p_node_file << num_nodes <<
"\t";
414 *p_node_file << SPACE_DIM <<
"\t";
415 *p_node_file << num_attr <<
"\t";
416 *p_node_file << max_bdy_marker <<
"\n";
417 *p_node_file << std::setprecision(6);
420 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
422 std::vector<double> current_item = this->GetNextNode();
423 *p_node_file << item_num;
424 for (
unsigned i=0; i<SPACE_DIM+1; i++)
426 *p_node_file <<
"\t" << current_item[i];
428 *p_node_file <<
"\n";
430 *p_node_file << comment <<
"\n";
431 p_node_file->close();
434 std::string element_file_name = this->mBaseName +
".cell";
435 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
439 unsigned num_elements = this->GetNumElements();
440 *p_element_file << num_elements <<
"\t" << num_attr <<
"\n";
443 for (
unsigned item_num=0; item_num<num_elements; item_num++)
451 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
454 *p_element_file << item_num <<
"\t" << node_indices.size();
457 for (
unsigned i=0; i<node_indices.size(); i++)
459 *p_element_file <<
"\t" << node_indices[i];
465 *p_element_file <<
"\n";
469 assert(SPACE_DIM == 3);
475 std::vector<unsigned> node_indices = elem_data_with_faces.
NodeIndices;
478 *p_element_file << item_num <<
"\t" << node_indices.size();
481 for (
unsigned i=0; i<node_indices.size(); i++)
483 *p_element_file <<
"\t" << node_indices[i];
487 std::vector<ElementData> faces = elem_data_with_faces.
Faces;
490 *p_element_file <<
"\t" << faces.size();
492 for (
unsigned j=0; j<faces.size(); j++)
495 std::vector<unsigned> face_node_indices = faces[j].NodeIndices;
498 *p_element_file <<
"\t" << faces[j].AttributeValue <<
"\t" << face_node_indices.size();
501 for (
unsigned i=0; i<face_node_indices.size(); i++)
503 *p_element_file <<
"\t" << face_node_indices[i];
512 *p_element_file <<
"\n";
516 *p_element_file << comment <<
"\n";
517 p_element_file->close();