36 #include "TrianglesMeshWriter.hpp" 38 #include "AbstractTetrahedralMesh.hpp" 39 #include "Version.hpp" 46 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
48 const std::string& rDirectory,
49 const std::string& rBaseName,
50 const bool clearOutputDir)
55 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
60 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
66 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
73 std::string node_file_name = this->
mBaseName +
".node";
77 unsigned num_attr = 0;
82 num_attr = this->
mpMesh->GetNumNodeAttributes();
85 unsigned max_bdy_marker = 0;
88 *p_node_file << num_nodes <<
"\t";
89 *p_node_file << SPACE_DIM <<
"\t";
90 *p_node_file << num_attr <<
"\t";
91 *p_node_file << max_bdy_marker;
94 *p_node_file <<
"\tBIN\n";
101 *p_node_file << std::setprecision(20);
104 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
117 *p_node_file << comment <<
"\n";
118 p_node_file->close();
122 if (ELEMENT_DIM < SPACE_DIM)
130 std::string element_file_name = this->
mBaseName +
".ele";
138 if (num_elements == 0)
140 *p_element_file << 0 <<
"\t";
141 *p_element_file << 0 <<
"\t";
142 *p_element_file << 0;
145 *p_element_file <<
"\tBIN\n";
149 *p_element_file <<
"\n";
151 p_element_file->close();
157 unsigned nodes_per_element = element_data.
NodeIndices.size();
158 if (nodes_per_element != ELEMENT_DIM+1)
161 assert(ELEMENT_DIM == SPACE_DIM);
162 assert(nodes_per_element == (ELEMENT_DIM+1)*(ELEMENT_DIM+2)/2);
165 *p_element_file << num_elements <<
"\t";
166 *p_element_file << nodes_per_element <<
"\t";
167 *p_element_file << num_attr;
170 *p_element_file <<
"\tBIN\n";
174 *p_element_file <<
"\n";
178 std::vector<double> attribute_values(1);
179 for (
unsigned item_num=0; item_num<num_elements; item_num++)
192 *p_element_file << comment <<
"\n";
193 p_element_file->close();
199 std::string face_file_name = this->
mBaseName;
201 if (ELEMENT_DIM == 1)
206 else if (ELEMENT_DIM == 2)
208 face_file_name = face_file_name +
".edge";
212 face_file_name = face_file_name +
".face";
217 if (num_elements != 0)
221 *p_face_file << num_faces <<
"\t";
223 *p_face_file << max_bdy_marker;
226 *p_face_file <<
"\tBIN\n";
230 *p_face_file <<
"\n";
234 std::vector<double> default_marker(0);
235 for (
unsigned item_num=0; item_num<num_faces; item_num++)
240 *p_face_file << comment <<
"\n";
241 p_face_file->close();
246 std::string cable_element_file_name = this->
mBaseName +
".cable";
254 *p_cable_element_file << num_cable_elements <<
"\t";
255 *p_cable_element_file << 2 <<
"\t";
256 *p_cable_element_file << num_attr;
259 *p_cable_element_file <<
"\tBIN\n";
263 *p_cable_element_file <<
"\n";
267 std::vector<double> attribute_values(1);
268 for (
unsigned item_num=0; item_num<num_cable_elements; item_num++)
274 *p_cable_element_file << comment;
275 p_cable_element_file->close();
282 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
287 std::string element_file_name = this->
mBaseName;
288 if (ELEMENT_DIM == 1 && (SPACE_DIM == 2 || SPACE_DIM == 3))
290 element_file_name = element_file_name +
".edge";
292 else if (ELEMENT_DIM == 2 && SPACE_DIM == 3)
294 element_file_name = element_file_name +
".face";
301 assert(SPACE_DIM != ELEMENT_DIM);
302 unsigned num_attr = 1;
304 *p_element_file << num_elements <<
"\t";
306 *p_element_file << num_attr;
309 *p_element_file <<
"\tBIN\n";
313 *p_element_file <<
"\n";
317 std::vector<double> attribute_values(1);
318 for (
unsigned item_num=0; item_num<num_elements; item_num++)
325 *p_element_file << comment <<
"\n";
326 p_element_file->close();
329 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
334 if (ELEMENT_DIM == 1 && (SPACE_DIM == 2 || SPACE_DIM == 3))
339 assert(SPACE_DIM == 3 && ELEMENT_DIM == 2);
341 std::string face_file_name = this->
mBaseName;
342 face_file_name = face_file_name +
".edge";
349 unsigned max_bdy_marker = 0;
350 std::vector<double> default_marker(0);
352 *p_face_file << num_faces <<
"\t";
353 *p_face_file << max_bdy_marker;
356 *p_face_file <<
"\tBIN\n";
360 *p_face_file <<
"\n";
364 for (
unsigned item_num=0; item_num<num_faces; item_num++)
369 *p_face_file << comment <<
"\n";
370 p_face_file->close();
373 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
374 template<
class T_DATA>
376 const std::vector<T_DATA> &dataPacket)
380 WriteItem(pFile, itemNumber, dataPacket, std::vector<double>());
383 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
384 template<
class T_DATA>
386 const std::vector<T_DATA> &dataPacket,
387 const std::vector<double> &rAttributes)
393 pFile->write((
char*)&dataPacket[0], dataPacket.size()*
sizeof(T_DATA));
398 if (!rAttributes.empty())
400 pFile->write((
char*)&rAttributes[0], rAttributes.size()*
sizeof(
double));
405 *pFile << itemNumber;
406 for (
unsigned i=0; i<dataPacket.size(); i++)
408 *pFile <<
"\t" << dataPacket[i];
410 for (
unsigned i=0; i<rAttributes.size(); i++)
412 *pFile <<
"\t" << rAttributes[i];
ElementData GetNextCableElement()
virtual ~TrianglesMeshWriter()
unsigned GetNumCableElements()
ElementData GetNextBoundaryElement()
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
static void BeginEvent(unsigned event)
void WriteItem(out_stream &pFile, unsigned itemNumber, const std::vector< T_DATA > &dataPacket, const std::vector< double > &rAttributes)
virtual unsigned GetNumNodes()
TrianglesMeshWriter(const std::string &rDirectory, const std::string &rBaseName, const bool clearOutputDir=true)
OutputFileHandler * mpOutputFileHandler
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()
ElementData GetNextElement()
unsigned GetNumElements()
static std::string GetProvenanceString()
void SetWriteFilesAsBinary()
static void EndEvent(unsigned event)
unsigned GetNumBoundaryFaces()
void WriteElementsAsFaces()