36 #include "MeshalyzerMeshWriter.hpp" 37 #include "Version.hpp" 40 #include "AbstractTetrahedralMesh.hpp" 41 #include "DistributedTetrahedralMesh.hpp" 48 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
50 const std::string& rBaseName,
51 const bool &rCleanDirectory,
52 const bool &rSetCoolGraphics)
72 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
82 *p_node_file << num_nodes <<
"\n";
85 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
87 std::vector<double> current_item = this->
GetNextNode();
88 for (
unsigned i=0; i<SPACE_DIM; i++)
90 *p_node_file << current_item[i] <<
"\t";
94 *p_node_file << 0 <<
"\t";
98 *p_node_file << 0 <<
"\t" << 0 <<
"\t";
100 *p_node_file <<
"\n";
103 *p_node_file << comment;
104 p_node_file->close();
107 std::string element_file_name;
109 if (ELEMENT_DIM == 3)
111 element_file_name = this->
mBaseName +
".tetras";
113 else if (ELEMENT_DIM == 2)
115 element_file_name = this->
mBaseName +
".tri";
119 element_file_name = this->
mBaseName +
".cnnx";
127 *p_element_file << num_elements <<
"\n";
130 unsigned nodes_per_element = ELEMENT_DIM+1;
131 for (
unsigned item_num=0; item_num<num_elements; item_num++)
135 std::vector<unsigned> current_item = element_data.
NodeIndices;
136 for (
unsigned i=0; i<nodes_per_element; i++)
140 *p_element_file << current_item[i] <<
"\t";
144 *p_element_file << current_item[i]+1 <<
"\t";
150 *p_element_file << comment;
151 p_element_file->close();
161 *p_face_file << num_faces <<
"\n";
164 double material_property = 0.0;
165 for (
unsigned item_num=0; item_num<num_faces; item_num++)
168 for (
unsigned i=0; i<ELEMENT_DIM; i++)
172 *p_face_file << current_item.
NodeIndices[i] <<
"\t";
176 *p_face_file << current_item.
NodeIndices[i]+1 <<
"\t";
179 *p_face_file << material_property <<
"\n";
181 *p_face_file << comment;
182 p_face_file->close();
188 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
193 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
198 std::string meta_file_name = this->
mBaseName +
".cg_in";
201 *p_meta_file <<
"1\n" <<
"0\n";
202 std::string face_file_name = this->
mBaseName +
".tri";
203 *p_meta_file << face_file_name <<
"\n";
205 *p_meta_file << comment;
206 p_meta_file->close();
210 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
213 std::ios_base::openmode mode = std::ios::out;
216 mode |= std::ios::app;
220 mode |= std::ios::trunc;
225 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
228 std::string node_file_name = this->
mBaseName +
".pts";
232 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
235 std::string element_file_name;
237 if (ELEMENT_DIM == 3)
239 element_file_name = this->
mBaseName +
".tetras";
241 else if (ELEMENT_DIM == 2)
243 element_file_name = this->
mBaseName +
".tri";
247 element_file_name = this->
mBaseName +
".cnnx";
253 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
256 std::string face_file_name = this->
mBaseName +
".tri";
260 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
270 *p_node_file << num_nodes <<
"\n";
272 p_node_file->close();
282 *p_element_file << num_elements <<
"\n";
284 p_element_file->close();
296 *p_face_file << num_faces <<
"\n";
298 p_face_file->close();
305 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
316 const c_vector<double, SPACE_DIM>& r_current_item = iter->rGetLocation();
317 for (
unsigned i=0; i<SPACE_DIM; i++)
319 *p_node_file << r_current_item[i] <<
"\t";
323 *p_node_file << 0 <<
"\t";
327 *p_node_file << 0 <<
"\t" << 0 <<
"\t";
329 *p_node_file <<
"\n";
331 p_node_file->close();
341 if (this->
mpDistributedMesh->CalculateDesignatedOwnershipOfElement(iter->GetIndex()))
347 *p_element_file << iter->GetNodeGlobalIndex(i) <<
"\t";
351 *p_element_file << iter->GetNodeGlobalIndex(i)+1 <<
"\t";
355 *p_element_file << iter->GetAttribute() <<
"\n";
358 p_element_file->close();
361 if (ELEMENT_DIM == 3)
367 for (BoundaryElemIterType iter = this->
mpDistributedMesh->GetBoundaryElementIteratorBegin();
371 if (this->
mpDistributedMesh->CalculateDesignatedOwnershipOfBoundaryElement((*iter)->GetIndex()))
373 for (
unsigned i=0; i<ELEMENT_DIM; i++)
377 *p_face_file << (*iter)->GetNodeGlobalIndex(i) <<
"\t";
381 *p_face_file << (*iter)->GetNodeGlobalIndex(i)+1 <<
"\t";
385 *p_face_file << (*iter)->GetAttribute() <<
"\n";
388 p_face_file->close();
392 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
398 *p_node_file << comment;
399 p_node_file->close();
402 *p_element_file << comment;
403 p_element_file->close();
405 if (ELEMENT_DIM == 3)
408 *p_face_file << comment;
409 p_face_file->close();
MeshalyzerMeshWriter(const std::string &rDirectory, const std::string &rBaseName, const bool &rCleanDirectory=true, const bool &rSetCoolGraphics=false)
void CreateFilesWithHeaders()
out_stream OpenNodeFile(bool append=false)
ElementData GetNextBoundaryElement()
virtual unsigned GetNumNodes()
OutputFileHandler * mpOutputFileHandler
virtual ~MeshalyzerMeshWriter()
out_stream OpenFaceFile(bool append=false)
std::ios_base::openmode GetOpenMode(bool append)
out_stream OpenElementFile(bool append=false)
std::vector< unsigned > NodeIndices
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
std::vector< double > GetNextNode()
DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpDistributedMesh
ElementData GetNextElement()
unsigned GetNumElements()
unsigned mNodesPerElement
static std::string GetProvenanceString()
std::vector< BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > * >::const_iterator BoundaryElementIterator
void AppendLocalDataToFiles()
unsigned GetNumBoundaryFaces()