36 #include "VertexMeshWriter.hpp" 37 #include "Version.hpp" 38 #include "Cylindrical2dVertexMesh.hpp" 39 #include "Toroidal2dVertexMesh.hpp" 44 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
57 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
59 const std::string& rBaseName,
60 const bool clearOutputDir)
65 mNodeMapCurrentIndex(0)
76 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
98 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
106 std::vector<double> coordinates(SPACE_DIM+1);
109 for (
unsigned j=0; j<SPACE_DIM; j++)
111 coordinates[j] = (*(
mpIters->pNodeIter))->GetPoint()[j];
113 coordinates[SPACE_DIM] = (*(
mpIters->pNodeIter))->IsBoundaryNode();
125 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
129 assert(SPACE_DIM == 3);
138 for (
unsigned j=0; j<elem_data.NodeIndices.size(); j++)
140 unsigned old_index = (*(
mpIters->pElemIter))->GetNodeGlobalIndex(j);
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);
166 elem_data.Faces[i] = face_data;
178 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
189 for (
unsigned j=0; j<elem_data.NodeIndices.size(); j++)
191 unsigned old_index = (*(
mpIters->pElemIter))->GetNodeGlobalIndex(j);
196 elem_data.AttributeValue = (*(
mpIters->pElemIter))->GetAttribute();
207 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
211 assert(SPACE_DIM==3 || SPACE_DIM == 2);
218 vtkXMLUnstructuredGridWriter* p_writer = vtkXMLUnstructuredGridWriter::New();
219 #if VTK_MAJOR_VERSION >= 6 226 p_writer->SetCompressor(
nullptr);
232 vtk_file_name +=
"_" + stamp;
234 vtk_file_name +=
".vtu";
236 p_writer->SetFileName(vtk_file_name.c_str());
254 if (dynamic_cast<Toroidal2dVertexMesh*>(&rMesh))
260 delete p_mesh_for_vtk;
262 else if (dynamic_cast<Cylindrical2dVertexMesh*>(&rMesh))
268 delete p_mesh_for_vtk;
277 vtkXMLUnstructuredGridWriter* p_writer = vtkXMLUnstructuredGridWriter::New();
278 #if VTK_MAJOR_VERSION >= 6 285 p_writer->SetCompressor(
nullptr);
291 vtk_file_name +=
"_" + stamp;
293 vtk_file_name +=
".vtu";
295 p_writer->SetFileName(vtk_file_name.c_str());
302 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
307 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
308 p_pts->GetData()->SetName(
"Vertex positions");
309 for (
unsigned node_num=0; node_num<rMesh.
GetNumNodes(); node_num++)
311 c_vector<double, SPACE_DIM> position = rMesh.
GetNode(node_num)->rGetLocation();
314 p_pts->InsertPoint(node_num, position[0], position[1], 0.0);
318 p_pts->InsertPoint(node_num, position[0], position[1], position[2]);
331 p_cell = vtkPolygon::New();
335 p_cell = vtkConvexPointSet::New();
337 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
338 p_cell_id_list->SetNumberOfIds(iter->GetNumNodes());
339 for (
unsigned j=0; j<iter->GetNumNodes(); ++j)
341 p_cell_id_list->SetId(j, iter->GetNodeGlobalIndex(j));
349 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
353 vtkDoubleArray* p_scalars = vtkDoubleArray::New();
354 p_scalars->SetName(dataName.c_str());
355 for (
unsigned i=0; i<dataPayload.size(); i++)
357 p_scalars->InsertNextValue(dataPayload[i]);
361 p_cell_data->AddArray(p_scalars);
366 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
370 vtkDoubleArray* p_scalars = vtkDoubleArray::New();
371 p_scalars->SetName(dataName.c_str());
372 for (
unsigned i=0; i<dataPayload.size(); i++)
374 p_scalars->InsertNextValue(dataPayload[i]);
378 p_point_data->AddArray(p_scalars);
384 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
394 mpIters->pNodeIter =
new NodeIterType(
mpMesh->GetNodeIteratorBegin());
397 mpIters->pElemIter =
new ElemIterType(
mpMesh->GetElementIteratorBegin());
401 if (
mpMesh->IsMeshChanging())
404 for (NodeIterType it =
mpMesh->GetNodeIteratorBegin(); it !=
mpMesh->GetNodeIteratorEnd(); ++it)
412 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
418 std::string node_file_name = this->
mBaseName +
".node";
422 unsigned num_attr = 0;
423 unsigned max_bdy_marker = 1;
426 *p_node_file << num_nodes <<
"\t";
427 *p_node_file << SPACE_DIM <<
"\t";
428 *p_node_file << num_attr <<
"\t";
429 *p_node_file << max_bdy_marker <<
"\n";
430 *p_node_file << std::setprecision(6);
433 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
435 std::vector<double> current_item = this->
GetNextNode();
436 *p_node_file << item_num;
437 for (
unsigned i=0; i<SPACE_DIM+1; i++)
439 *p_node_file <<
"\t" << current_item[i];
441 *p_node_file <<
"\n";
443 *p_node_file << comment <<
"\n";
444 p_node_file->close();
447 std::string element_file_name = this->
mBaseName +
".cell";
453 *p_element_file << num_elements <<
"\t" << num_attr <<
"\n";
456 for (
unsigned item_num=0; item_num<num_elements; item_num++)
464 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
467 *p_element_file << item_num <<
"\t" << node_indices.size();
470 for (
unsigned i=0; i<node_indices.size(); i++)
472 *p_element_file <<
"\t" << node_indices[i];
478 *p_element_file <<
"\n";
482 assert(SPACE_DIM == 3);
488 std::vector<unsigned> node_indices = elem_data_with_faces.
NodeIndices;
491 *p_element_file << item_num <<
"\t" << node_indices.size();
494 for (
unsigned i=0; i<node_indices.size(); i++)
496 *p_element_file <<
"\t" << node_indices[i];
500 std::vector<ElementData> faces = elem_data_with_faces.
Faces;
503 *p_element_file <<
"\t" << faces.size();
505 for (
unsigned j=0; j<faces.size(); j++)
508 std::vector<unsigned> face_node_indices = faces[j].NodeIndices;
511 *p_element_file <<
"\t" << faces[j].AttributeValue <<
"\t" << face_node_indices.size();
514 for (
unsigned i=0; i<face_node_indices.size(); i++)
516 *p_element_file <<
"\t" << face_node_indices[i];
525 *p_element_file <<
"\n";
529 *p_element_file << comment <<
"\n";
530 p_element_file->close();
void AddCellData(std::string dataName, std::vector< double > dataPayload)
unsigned mNodeMapCurrentIndex
MeshWriterIterators< ELEMENT_DIM, SPACE_DIM > * mpIters
void WriteFilesUsingMesh(VertexMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
Node< SPACE_DIM > * GetNode(unsigned index) const
virtual unsigned GetNumNodes() const
virtual unsigned GetNumNodes()
OutputFileHandler * mpOutputFileHandler
AbstractMesh< ELEMENT_DIM, SPACE_DIM >::NodeIterator * pNodeIter
std::string GetOutputDirectoryFullPath() const
virtual std::vector< double > GetNextNode()
vtkUnstructuredGrid * mpVtkUnstructedMesh
std::vector< ElementData > Faces
std::vector< unsigned > NodeIndices
VertexMeshWriter(const std::string &rDirectory, const std::string &rBaseName, const bool clearOutputDir=true)
void SetNewIndex(unsigned oldIndex, unsigned newIndex)
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
VertexElement< ELEMENT_DIM-1, SPACE_DIM > * GetFace(unsigned index) const
VertexElementData GetNextElementWithFaces()
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
void WriteVtkUsingMesh(VertexMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, std::string stamp="")
VertexMesh< ELEMENT_DIM, SPACE_DIM >::VertexElementIterator * pElemIter
unsigned GetNumElements()
unsigned GetNewIndex(unsigned oldIndex) const
void MakeVtkMesh(VertexMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
std::vector< double > GetNextNode()
ElementData GetNextElement()
static std::string GetProvenanceString()
virtual ElementData GetNextElement()
VertexElementIterator GetElementIteratorEnd()
std::vector< unsigned > NodeIndices
void AddPointData(std::string dataName, std::vector< double > dataPayload)
VertexMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > * mpMeshReader