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>
195 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
198 if (this->mWriteMetaFile)
200 std::string meta_file_name = this->mBaseName +
".cg_in";
201 out_stream p_meta_file = this->mpOutputFileHandler->OpenOutputFile(meta_file_name);
203 *p_meta_file <<
"1\n" <<
"0\n";
204 std::string face_file_name = this->mBaseName +
".tri";
205 *p_meta_file << face_file_name <<
"\n";
207 *p_meta_file << comment;
208 p_meta_file->close();
212 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
215 std::ios_base::openmode mode = std::ios::out;
218 mode |= std::ios::app;
222 mode |= std::ios::trunc;
227 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
230 std::string node_file_name = this->mBaseName +
".pts";
231 return this->mpOutputFileHandler->OpenOutputFile(node_file_name, GetOpenMode(append));
234 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
237 std::string element_file_name;
239 if (ELEMENT_DIM == 3)
241 element_file_name = this->mBaseName +
".tetras";
243 else if (ELEMENT_DIM == 2)
245 element_file_name = this->mBaseName +
".tri";
249 element_file_name = this->mBaseName +
".cnnx";
252 return this->mpOutputFileHandler->OpenOutputFile(element_file_name, GetOpenMode(append));
255 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
258 std::string face_file_name = this->mBaseName +
".tri";
259 return this->mpOutputFileHandler->OpenOutputFile(face_file_name, GetOpenMode(append));
262 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
268 out_stream p_node_file = OpenNodeFile();
271 unsigned num_nodes = this->GetNumNodes();
272 *p_node_file << num_nodes <<
"\n";
274 p_node_file->close();
280 out_stream p_element_file = OpenElementFile();
283 unsigned num_elements = this->GetNumElements();
284 *p_element_file << num_elements <<
"\n";
286 p_element_file->close();
294 out_stream p_face_file = OpenFaceFile();
297 unsigned num_faces = this->GetNumBoundaryFaces();
298 *p_face_file << num_faces <<
"\n";
300 p_face_file->close();
307 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
310 out_stream p_node_file = OpenNodeFile(
true);
314 for (NodeIterType iter = this->mpDistributedMesh->GetNodeIteratorBegin();
315 iter != this->mpDistributedMesh->GetNodeIteratorEnd();
318 const c_vector<double, SPACE_DIM>& r_current_item = iter->rGetLocation();
319 for (
unsigned i=0; i<SPACE_DIM; i++)
321 *p_node_file << r_current_item[i] <<
"\t";
325 *p_node_file << 0 <<
"\t";
329 *p_node_file << 0 <<
"\t" << 0 <<
"\t";
331 *p_node_file <<
"\n";
333 p_node_file->close();
335 out_stream p_element_file = OpenElementFile(
true);
339 for (ElemIterType iter = this->mpDistributedMesh->GetElementIteratorBegin();
340 iter != this->mpDistributedMesh->GetElementIteratorEnd();
343 if ( this->mpDistributedMesh->CalculateDesignatedOwnershipOfElement(iter->GetIndex()))
345 for (
unsigned i=0; i<this->mNodesPerElement; i++)
347 if (this->mIndexFromZero)
349 *p_element_file << iter->GetNodeGlobalIndex(i) <<
"\t";
353 *p_element_file << iter->GetNodeGlobalIndex(i)+1 <<
"\t";
357 *p_element_file << iter->GetAttribute() <<
"\n";
360 p_element_file->close();
363 if (ELEMENT_DIM == 3)
365 out_stream p_face_file = OpenFaceFile(
true);
369 for (BoundaryElemIterType iter = this->mpDistributedMesh->GetBoundaryElementIteratorBegin();
370 iter != this->mpDistributedMesh->GetBoundaryElementIteratorEnd();
373 if ( this->mpDistributedMesh->CalculateDesignatedOwnershipOfBoundaryElement((*iter)->GetIndex()))
375 for (
unsigned i=0; i<ELEMENT_DIM; i++)
377 if (this->mIndexFromZero)
379 *p_face_file << (*iter)->GetNodeGlobalIndex(i) <<
"\t";
383 *p_face_file << (*iter)->GetNodeGlobalIndex(i)+1 <<
"\t";
387 *p_face_file << (*iter)->GetAttribute() <<
"\n";
390 p_face_file->close();
394 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
399 out_stream p_node_file = OpenNodeFile(
true);
400 *p_node_file << comment;
401 p_node_file->close();
403 out_stream p_element_file = OpenElementFile(
true);
404 *p_element_file << comment;
405 p_element_file->close();
407 if (ELEMENT_DIM == 3)
409 out_stream p_face_file = OpenFaceFile(
true);
410 *p_face_file << comment;
411 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()