36 #include "../MeshElements.h"
38 #include "../InputModules/InputGmsh.h"
52 "Writes Gmsh msh file.");
62 elmMap[it->second] = it->first;
85 cout <<
"OutputGmsh: Writing file..." << endl;
94 <<
"$EndMeshFormat" << endl;
96 int id =
m_mesh->m_vertexSet.size();
97 vector<ElementSharedPtr> toComplete;
103 for (
int i = 0; i <
m_mesh->m_element[
m_mesh->m_expDim].size(); ++i)
106 if (e->GetMaxOrder() > maxOrder)
108 maxOrder = e->GetMaxOrder();
113 for (
int d = 1; d <= 3; ++d)
115 for (
int i = 0; i <
m_mesh->m_element[d].size(); ++i)
118 if ((e->GetConf().m_order <= 1 && maxOrder > 1) ||
119 (e->GetConf().m_order == maxOrder && e->GetConf().m_faceNodes ==
false))
121 toComplete.push_back(e);
131 for (
int i = 0; i < toComplete.size(); ++i)
133 toComplete[i]->Complete(maxOrder);
137 for (
int d = 1; d <= 3; ++d)
139 for (
int i = 0; i <
m_mesh->m_element[d].size(); ++i)
143 boost::unordered_set<int> edgesDone;
144 boost::unordered_set<int> facesDone;
147 if (e->GetConf().m_order > 1)
149 vector<NodeSharedPtr> tmp;
150 vector<EdgeSharedPtr> edgeList = e->GetEdgeList();
151 vector<FaceSharedPtr> faceList = e->GetFaceList();
152 vector<NodeSharedPtr> volList = e->GetVolumeNodes();
154 for (
int j = 0; j < edgeList.size(); ++j)
157 edgesDone.find(edgeList[j]->m_id);
158 if (it == edgesDone.end() || d != 3)
160 tmp.insert(tmp.end(),
161 edgeList[j]->m_edgeNodes.begin(),
162 edgeList[j]->m_edgeNodes.end());
163 edgesDone.insert(edgeList[j]->m_id);
167 for (
int j = 0; j < faceList.size(); ++j)
170 facesDone.find(faceList[j]->m_id);
171 if (it == facesDone.end() || d != 3)
173 tmp.insert(tmp.end(),
174 faceList[j]->m_faceNodes.begin(),
175 faceList[j]->m_faceNodes.end());
176 facesDone.insert(faceList[j]->m_id);
180 tmp.insert(tmp.end(), volList.begin(), volList.end());
187 for (
int j = 0; j < tmp.size(); ++j)
189 pair<NodeSet::iterator, bool> testIns =
190 m_mesh->m_vertexSet.insert(tmp[j]);
194 (*(testIns.first))->m_id =
id++;
198 tmp[j]->m_id = (*(testIns.first))->m_id;
207 std::set<NodeSharedPtr> tmp(
m_mesh->m_vertexSet.begin(),
208 m_mesh->m_vertexSet.end());
212 <<
m_mesh->m_vertexSet.size() << endl;
214 for (it = tmp.begin(); it != tmp.end(); ++it)
216 m_mshFile << (*it)->m_id <<
" " << scientific << setprecision(10)
218 << (*it)->m_y <<
" " << (*it)->m_z
231 for (
int d = 1; d <= 3; ++d)
233 for (
int i = 0; i <
m_mesh->m_element[d].size(); ++i, ++id)
239 <<
elmMap[e->GetConf()] <<
" ";
243 vector<int> tags = e->GetTagList();
245 if (tags.size() == 1)
247 tags.push_back(tags[0]);
253 for (
int j = 0; j < tags.size(); ++j)
260 vector<NodeSharedPtr> nodeList = e->GetVertexList ();
261 vector<EdgeSharedPtr> edgeList = e->GetEdgeList ();
262 vector<FaceSharedPtr> faceList = e->GetFaceList ();
263 vector<NodeSharedPtr> volList = e->GetVolumeNodes();
267 for (
int j = 0; j < nodeList.size(); ++j)
269 tags.push_back(nodeList[j]->m_id);
272 if (e->GetConf().m_order > 1)
274 for (
int j = 0; j < edgeList.size(); ++j)
276 nodeList = edgeList[j]->m_edgeNodes;
277 for (
int k = 0; k < nodeList.size(); ++k)
279 tags.push_back(nodeList[k]->m_id);
284 for (
int j = 0; j < faceList.size(); ++j)
286 nodeList = faceList[j]->m_faceNodes;
287 for (
int k = 0; k < nodeList.size(); ++k)
290 tags.push_back(nodeList[k]->m_id);
294 for (
int j = 0; j < volList.size(); ++j)
297 tags.push_back(volList[j]->m_id);
304 int order = e->GetConf().m_order;
307 cerr <<
"Temporary error: Gmsh tets only supported "
308 <<
"up to 4th order - will fix soon!" << endl;
313 pos = 4 + 4*(order-1);
314 for (
int j = 0; j < order-1; ++j)
316 swap(tags[j+pos], tags[j+pos+order-1]);
320 reverse(tags.begin()+4+3*(order-1), tags.begin()+4+4*(order-1));
321 reverse(tags.begin()+4+4*(order-1), tags.begin()+4+5*(order-1));
322 reverse(tags.begin()+4+5*(order-1), tags.begin()+4+6*(order-1));
325 pos = 4 + 6*(order-1) + 2*(order-2)*(order-1)/2;
326 for (
int j = 0; j < (order-2)*(order-1)/2; ++j)
328 swap(tags[j+pos], tags[j+pos+(order-2)*(order-1)/2]);
342 vector<int> tmp((order-2)*(order-1)/2);
344 pos = 4 + 6*(order-1);
345 for (
int j = 0; j < order-2; ++j)
347 for (
int k = 0; k < order-2-j; ++k, ++a)
349 tmp[a] = tags[pos+j+k*(2*(order-2)+1-k)/2];
352 for (
int j = 0; j < (order-1)*(order-2)/2; ++j)
354 tags[pos+j] = tmp[j];
358 pos = 4 + 6*(order-1) + 2*(order-2)*(order-1)/2;
360 for (
int j = 0; j < order-2; ++j)
362 for (
int k = 0; k < order-2-j; ++k, ++a)
364 tmp[a] = tags[pos+j+k*(2*(order-2)+1-k)/2];
367 for (
int j = 0; j < (order-1)*(order-2)/2; ++j)
369 tags[pos+j] = tmp[j];
373 pos = 4 + 6*(order-1)+3*(order-2)*(order-1)/2;
375 for (
int j = 0; j < order-2; ++j)
377 for (
int k = order-3-j; k >= 0; --k, ++a)
379 tmp[a] = tags[pos+j+k*(2*(order-2)+1-k)/2];
383 for (
int j = 0; j < (order-1)*(order-2)/2; ++j)
385 tags[pos+j] = tmp[j];
391 int order = e->GetConf().m_order;
394 cerr <<
"Temporary error: Gmsh prisms only "
395 <<
"supported up to 2nd order!" << endl;
400 vector<int> temp (18);
419 for (
int k = 0; k < 18; ++k)
426 for (
int j = 0; j < tags.size(); ++j)
pair< ModuleType, string > ModuleKey
Abstract base class for output modules.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer to an element.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
virtual void Process()
Write mesh to output file.
std::ofstream m_mshFile
Output stream.
void OpenStream()
Open a file for output.
boost::shared_ptr< Geometry > GeometrySharedPtr
boost::unordered_map< ElmtConfig, unsigned int, ElmtConfigHash > elmMap
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.