36 #include "PottsMeshWriter.hpp"
37 #include "Version.hpp"
42 template<
unsigned SPACE_DIM>
55 template<
unsigned SPACE_DIM>
57 const std::string& rBaseName,
58 const bool clearOutputDir)
63 mNodeMapCurrentIndex(0)
69 template<
unsigned SPACE_DIM>
72 if (mpIters->pNodeIter)
74 delete mpIters->pNodeIter;
75 delete mpIters->pElemIter;
86 template<
unsigned SPACE_DIM>
92 assert(this->mNumNodes == mpMesh->GetNumNodes());
94 std::vector<double> coordinates(SPACE_DIM+1);
97 for (
unsigned j=0; j<SPACE_DIM; j++)
99 coordinates[j] = (*(mpIters->pNodeIter))->GetPoint()[j];
101 coordinates[SPACE_DIM] = (*(mpIters->pNodeIter))->IsBoundaryNode();
103 ++(*(mpIters->pNodeIter));
113 template<
unsigned SPACE_DIM>
118 assert(this->mNumElements == mpMesh->GetNumElements());
121 elem_data.
NodeIndices.resize((*(mpIters->pElemIter))->GetNumNodes());
122 for (
unsigned j=0; j<elem_data.NodeIndices.size(); j++)
124 unsigned old_index = (*(mpIters->pElemIter))->GetNodeGlobalIndex(j);
125 elem_data.NodeIndices[j] = mpMesh->IsMeshChanging() ? mpNodeMap->GetNewIndex(old_index) : old_index;
129 elem_data.AttributeValue = (*(mpIters->pElemIter))->GetAttribute();
130 ++(*(mpIters->pElemIter));
141 template<
unsigned SPACE_DIM>
144 this->mpMeshReader =
nullptr;
148 this->mNumElements = mpMesh->GetNumElements();
151 mpIters->pNodeIter =
new NodeIterType(mpMesh->GetNodeIteratorBegin());
154 mpIters->pElemIter =
new ElemIterType(mpMesh->GetElementIteratorBegin());
157 mNodeMapCurrentIndex = 0;
158 if (mpMesh->IsMeshChanging())
160 mpNodeMap =
new NodeMap(mpMesh->GetNumAllNodes());
161 for (NodeIterType it = mpMesh->GetNodeIteratorBegin(); it != mpMesh->GetNodeIteratorEnd(); ++it)
163 mpNodeMap->
SetNewIndex(it->GetIndex(), mNodeMapCurrentIndex++);
170 template<
unsigned SPACE_DIM>
176 std::string node_file_name = this->mBaseName +
".node";
177 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
180 unsigned num_attr = 0;
181 unsigned max_bdy_marker = 1;
182 unsigned num_nodes = this->GetNumNodes();
184 *p_node_file << num_nodes <<
"\t";
185 *p_node_file << SPACE_DIM <<
"\t";
186 *p_node_file << num_attr <<
"\t";
187 *p_node_file << max_bdy_marker <<
"\n";
188 *p_node_file << std::setprecision(6);
191 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
193 std::vector<double> current_item = this->GetNextNode();
194 *p_node_file << item_num;
195 for (
unsigned i=0; i<SPACE_DIM+1; i++)
197 *p_node_file <<
"\t" << current_item[i];
199 *p_node_file <<
"\n";
201 *p_node_file << comment <<
"\n";
202 p_node_file->close();
205 std::string element_file_name = this->mBaseName +
".cell";
206 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
209 unsigned num_elements = this->GetNumElements();
210 *p_element_file << num_elements <<
"\t";
217 if (num_elements != 0)
219 *p_element_file << num_attr <<
"\n";
223 *p_element_file << 0 <<
"\n";
227 for (
unsigned item_num=0; item_num<num_elements; item_num++)
233 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
236 *p_element_file << item_num <<
"\t" << node_indices.size();
239 for (
unsigned i=0; i<node_indices.size(); i++)
241 *p_element_file <<
"\t" << node_indices[i];
248 *p_element_file <<
"\n";
251 *p_element_file << comment <<
"\n";
252 p_element_file->close();
void WriteFilesUsingMesh(PottsMesh< SPACE_DIM > &rMesh)
virtual std::vector< double > GetNextNode()
MeshPottsWriterIterators< SPACE_DIM > * mpIters
std::vector< unsigned > NodeIndices
void SetNewIndex(unsigned oldIndex, unsigned newIndex)
AbstractMesh< SPACE_DIM, SPACE_DIM >::NodeIterator * pNodeIter
PottsMesh< SPACE_DIM >::PottsElementIterator * pElemIter
std::vector< double > GetNextNode()
PottsMeshWriter(const std::string &rDirectory, const std::string &rBaseName, const bool clearOutputDir=true)
virtual unsigned GetNumNodes() const
ElementData GetNextElement()
static std::string GetProvenanceString()
virtual ElementData GetNextElement()