36 #include "CmguiMeshWriter.hpp"
37 #include "Version.hpp"
38 #include <boost/shared_ptr.hpp>
40 #include "AbstractTetrahedralMesh.hpp"
41 #include "DistributedTetrahedralMesh.hpp"
47 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
49 const std::string& rBaseName,
94 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
100 out_stream p_node_file = OpenNodeFile();
101 WriteNodeFileHeader(p_node_file);
104 for (
unsigned item_num=0; item_num<this->GetNumNodes(); item_num++)
106 std::vector<double> current_item = this->GetNextNode();
108 *p_node_file <<
"Node:\t" << item_num+1 <<
"\t";
109 for (
unsigned i=0; i<SPACE_DIM; i++)
111 *p_node_file << current_item[i] <<
"\t";
114 *p_node_file <<
"\n";
116 p_node_file->close();
122 std::vector<boost::shared_ptr<std::ofstream> > elem_files = OpenElementFiles();
123 WriteElementsFileHeader(elem_files);
126 for (
unsigned item_num=0; item_num<this->GetNumElements(); item_num++)
129 std::vector<unsigned> current_element = elem.
NodeIndices;
134 *elem_files[elem.
AttributeValue] <<
"Element:\t" << item_num+1 <<
" 0 0 Nodes:\t";
135 for (
unsigned i=0; i<mNumNodesPerElement; i++)
137 *elem_files[elem.
AttributeValue] << current_element[mReordering[i]]+1 <<
"\t";
144 for (
unsigned region_index=0; region_index<mRegionNames.size(); region_index++)
146 elem_files[region_index]->close();
150 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
153 mAdditionalFieldNames = rFieldNames;
156 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
159 mRegionNames = rRegionNames;
162 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
165 std::string node_file_name = this->mBaseName +
".exnode";
166 return this->mpOutputFileHandler->OpenOutputFile(node_file_name, GetOpenMode(append));
169 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
173 std::vector<boost::shared_ptr<std::ofstream> > elem_files;
175 if (mRegionNames.size() == 0)
177 mRegionNames.push_back(this->mBaseName);
179 elem_files.resize(mRegionNames.size());
181 std::string directory = this->mpOutputFileHandler->GetOutputDirectoryFullPath();
182 for (
unsigned region_index=0; region_index<mRegionNames.size(); region_index++)
184 std::string elem_file_name = mRegionNames[region_index] +
".exelem";
186 boost::shared_ptr<std::ofstream> p_output_file(
new std::ofstream((directory+elem_file_name).c_str(), GetOpenMode(append)));
188 if (!p_output_file->is_open())
190 EXCEPTION(
"Could not open file \"" + elem_file_name +
"\" in " + directory);
200 elem_files[region_index] = p_output_file;
205 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
210 *rpNodeFile << comment;
213 *rpNodeFile <<
"Group name: " << this->mGroupName <<
"\n";
218 *rpNodeFile << CmguiNodeFileHeader1D;
223 *rpNodeFile << CmguiNodeFileHeader2D;
228 *rpNodeFile << CmguiNodeFileHeader3D;
238 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
242 for (
unsigned region_index=0; region_index<mRegionNames.size(); region_index++)
248 *rElemFiles[region_index] << comment;
250 *rElemFiles[region_index] <<
"Group name: " << mGroupName <<
"\n";
251 *rElemFiles[region_index] << mElementFileHeader;
254 unsigned number_of_fields = mAdditionalFieldNames.size();
255 std::stringstream string_of_number_of_fields;
258 string_of_number_of_fields << number_of_fields+1;
261 *rElemFiles[region_index] <<
" #Fields="<<string_of_number_of_fields.str()<<
"\n";
264 *rElemFiles[region_index] << mCoordinatesFileHeader;
267 for (
unsigned i = 0; i < number_of_fields; i++)
270 std::stringstream i_string;
272 *rElemFiles[region_index]<<i_string.str()<<
") "<<mAdditionalFieldNames[i]<<
" ,";
273 *rElemFiles[region_index] << mAdditionalFieldHeader;
278 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
284 out_stream p_node_file = OpenNodeFile();
285 WriteNodeFileHeader(p_node_file);
286 p_node_file->close();
292 std::vector<boost::shared_ptr<std::ofstream> > elem_files = OpenElementFiles();
293 WriteElementsFileHeader(elem_files);
294 for (
unsigned i = 0; i < elem_files.size(); i++)
296 elem_files[i]->close();
300 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
304 out_stream p_node_file = OpenNodeFile(
true);
308 for (NodeIterType iter = this->mpDistributedMesh->GetNodeIteratorBegin();
309 iter != this->mpDistributedMesh->GetNodeIteratorEnd();
312 const c_vector<double, SPACE_DIM>& r_current_item = iter->rGetLocation();
313 *p_node_file <<
"Node:\t" << iter->GetIndex()+1 <<
"\t";
315 for (
unsigned i=0; i<SPACE_DIM; i++)
317 *p_node_file << r_current_item[i] <<
"\t";
320 *p_node_file <<
"\n";
322 p_node_file->close();
326 std::vector<boost::shared_ptr<std::ofstream> > elem_files = OpenElementFiles(
true);
329 for (ElemIterType iter = this->mpDistributedMesh->GetElementIteratorBegin();
330 iter != this->mpDistributedMesh->GetElementIteratorEnd();
333 if (this->mpDistributedMesh->CalculateDesignatedOwnershipOfElement(iter->GetIndex()))
335 assert(iter->GetUnsignedAttribute() < mRegionNames.size());
337 *elem_files[iter->GetUnsignedAttribute()] <<
"Element:\t" << iter->GetIndex()+1 <<
" 0 0 Nodes:\t";
338 for (
unsigned i=0; i<this->mNodesPerElement; i++)
340 *elem_files[iter->GetUnsignedAttribute()] << iter->GetNodeGlobalIndex(i)+1 <<
"\t";
343 *elem_files[iter->GetUnsignedAttribute()] <<
"\n";
347 for (
unsigned region_index=0; region_index<mRegionNames.size(); region_index++)
349 elem_files[region_index]->close();
354 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
360 template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
363 std::ios_base::openmode mode = std::ios::out;
366 mode |= std::ios::app;
370 mode |= std::ios::trunc;
std::string mAdditionalFieldHeader
out_stream OpenNodeFile(bool append=false)
#define EXCEPTION(message)
void SetRegionNames(std::vector< std::string > &rRegionNames)
std::string mCoordinatesFileHeader
std::vector< boost::shared_ptr< std::ofstream > > OpenElementFiles(bool append=false)
void WriteElementsFileHeader(std::vector< boost::shared_ptr< std::ofstream > > &rElemFiles)
std::vector< unsigned > NodeIndices
std::ios_base::openmode GetOpenMode(bool append)
std::string mElementFileHeader
unsigned mNumNodesPerElement
std::vector< unsigned > mReordering
void SetAdditionalFieldNames(std::vector< std::string > &rFieldNames)
void AppendLocalDataToFiles()
static std::string GetProvenanceString()
CmguiMeshWriter(const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true)
void WriteNodeFileHeader(out_stream &rpNodeFile)
void CreateFilesWithHeaders()