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>
78 out_stream p_node_file = OpenNodeFile();
81 unsigned num_nodes = this->GetNumNodes();
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";
122 out_stream p_element_file = OpenElementFile();
125 unsigned num_elements = this->GetNumElements();
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++)
138 if (this->mIndexFromZero)
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();
156 out_stream p_face_file = OpenFaceFile();
159 unsigned num_faces = this->GetNumBoundaryFaces();
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++)
167 ElementData current_item = this->GetNextBoundaryElement();
168 for (
unsigned i=0; i<ELEMENT_DIM; i++)
170 if (this->mIndexFromZero)
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>
196 if (this->mWriteMetaFile)
198 std::string meta_file_name = this->mBaseName +
".cg_in";
199 out_stream p_meta_file = this->mpOutputFileHandler->OpenOutputFile(meta_file_name);
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";
229 return this->mpOutputFileHandler->OpenOutputFile(node_file_name, GetOpenMode(append));
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";
250 return this->mpOutputFileHandler->OpenOutputFile(element_file_name, GetOpenMode(append));
253 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
256 std::string face_file_name = this->mBaseName +
".tri";
257 return this->mpOutputFileHandler->OpenOutputFile(face_file_name, GetOpenMode(append));
260 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
266 out_stream p_node_file = OpenNodeFile();
269 unsigned num_nodes = this->GetNumNodes();
270 *p_node_file << num_nodes <<
"\n";
272 p_node_file->close();
278 out_stream p_element_file = OpenElementFile();
281 unsigned num_elements = this->GetNumElements();
282 *p_element_file << num_elements <<
"\n";
284 p_element_file->close();
292 out_stream p_face_file = OpenFaceFile();
295 unsigned num_faces = this->GetNumBoundaryFaces();
296 *p_face_file << num_faces <<
"\n";
298 p_face_file->close();
305 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
308 out_stream p_node_file = OpenNodeFile(
true);
312 for (NodeIterType iter = this->mpDistributedMesh->GetNodeIteratorBegin();
313 iter != this->mpDistributedMesh->GetNodeIteratorEnd();
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();
333 out_stream p_element_file = OpenElementFile(
true);
337 for (ElemIterType iter = this->mpDistributedMesh->GetElementIteratorBegin();
338 iter != this->mpDistributedMesh->GetElementIteratorEnd();
341 if (this->mpDistributedMesh->CalculateDesignatedOwnershipOfElement(iter->GetIndex()))
343 for (
unsigned i=0; i<this->mNodesPerElement; i++)
345 if (this->mIndexFromZero)
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)
363 out_stream p_face_file = OpenFaceFile(
true);
367 for (BoundaryElemIterType iter = this->mpDistributedMesh->GetBoundaryElementIteratorBegin();
368 iter != this->mpDistributedMesh->GetBoundaryElementIteratorEnd();
371 if (this->mpDistributedMesh->CalculateDesignatedOwnershipOfBoundaryElement((*iter)->GetIndex()))
373 for (
unsigned i=0; i<ELEMENT_DIM; i++)
375 if (this->mIndexFromZero)
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>
397 out_stream p_node_file = OpenNodeFile(
true);
398 *p_node_file << comment;
399 p_node_file->close();
401 out_stream p_element_file = OpenElementFile(
true);
402 *p_element_file << comment;
403 p_element_file->close();
405 if (ELEMENT_DIM == 3)
407 out_stream p_face_file = OpenFaceFile(
true);
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)
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
static std::string GetProvenanceString()
std::vector< BoundaryElement< ELEMENT_DIM-1, SPACE_DIM > * >::const_iterator BoundaryElementIterator
void AppendLocalDataToFiles()