52 Loki::NoDestroy > Type;
53 return Type::Instance();
79 string fname =
m_config[
"infile"].as<
string>();
83 cerr <<
"Error opening file: " << fname << endl;
93 string fname =
m_config[
"outfile"].as<
string>();
97 cerr <<
"Error opening file: " << fname << endl;
112 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[
m_mesh->m_expDim];
114 m_mesh->m_vertexSet.clear();
116 for (
int i = 0, vid = 0; i < elmt.size(); ++i)
118 for (
int j = 0; j < elmt[i]->GetVertexCount(); ++j)
120 pair<NodeSet::iterator,bool> testIns =
121 m_mesh->m_vertexSet.insert(elmt[i]->GetVertex(j));
125 (*(testIns.first))->m_id = vid++;
129 elmt[i]->SetVertex(j,*testIns.first);
152 if (
m_mesh->m_expDim < 2)
return;
156 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[
m_mesh->m_expDim];
158 m_mesh->m_edgeSet.clear();
161 for (
int i = 0, eid = 0; i < elmt.size(); ++i)
163 for (
int j = 0; j < elmt[i]->GetEdgeCount(); ++j)
165 pair<EdgeSet::iterator,bool> testIns;
167 testIns =
m_mesh->m_edgeSet.insert(ed);
171 (*(testIns.first))->m_id = eid++;
176 elmt[i]->SetEdge(j, e2);
177 if (e2->m_edgeNodes.size() == 0 &&
178 ed->m_edgeNodes.size() > 0)
180 e2->m_curveType = ed->m_curveType;
181 e2->m_edgeNodes = ed->m_edgeNodes;
184 if (e2->m_n1->m_id != ed->m_n1->m_id)
186 reverse(e2->m_edgeNodes.begin(),
187 e2->m_edgeNodes.end());
192 (*(testIns.first))->m_elLink.push_back(
193 pair<ElementSharedPtr,int>(elmt[i],j));
200 for (
int i = 0; i <
m_mesh->m_element[1].size(); ++i)
204 vector<NodeSharedPtr> edgeNodes;
206 new Edge(v0, v1, edgeNodes,
207 m_mesh->m_element[1][i]->GetConf().m_edgeCurveType));
209 if (it ==
m_mesh->m_edgeSet.end())
211 cerr <<
"Cannot find corresponding element edge for "
212 <<
"1D element " << i << endl;
215 m_mesh->m_element[1][i]->SetEdgeLink(*it);
218 ASSERTL0((*it)->m_elLink.size() != 0,
219 "Empty boundary map!");
220 ASSERTL0((*it)->m_elLink.size() == 1,
221 "Too many elements in boundary map!");
222 pair<ElementSharedPtr, int> eMap = (*it)->m_elLink.at(0);
223 eMap.first->SetBoundaryLink(eMap.second, i);
245 if (
m_mesh->m_expDim < 3)
return;
249 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[
m_mesh->m_expDim];
251 m_mesh->m_faceSet.clear();
254 for (
int i = 0, fid = 0; i < elmt.size(); ++i)
256 for (
int j = 0; j < elmt[i]->GetFaceCount(); ++j)
258 pair<FaceSet::iterator,bool> testIns;
259 testIns =
m_mesh->m_faceSet.insert(elmt[i]->GetFace(j));
263 (*(testIns.first))->m_id = fid++;
267 elmt[i]->SetFace(j,*testIns.first);
269 (*(testIns.first))->m_elLink.push_back(
270 pair<ElementSharedPtr,int>(elmt[i],j));
277 for (
int i = 0; i <
m_mesh->m_element[2].size(); ++i)
279 vector<NodeSharedPtr> vertices =
m_mesh->m_element[2][i]->GetVertexList();
280 vector<NodeSharedPtr> faceNodes;
281 vector<EdgeSharedPtr> edgeList =
m_mesh->m_element[2][i]->GetEdgeList();
283 new Face(vertices, faceNodes, edgeList,
284 m_mesh->m_element[2][i]->GetConf().m_faceCurveType));
286 if (it ==
m_mesh->m_faceSet.end())
288 cout <<
"Cannot find corresponding element face for 2D "
289 <<
"element " << i << endl;
292 m_mesh->m_element[2][i]->SetFaceLink(*it);
295 ASSERTL0((*it)->m_elLink.size() != 0,
296 "Empty element link map!");
297 ASSERTL0((*it)->m_elLink.size() == 1,
298 "Too many elements in element link map!");
299 pair<ElementSharedPtr, int> eMap = (*it)->m_elLink.at(0);
300 eMap.first->SetBoundaryLink(eMap.second, i);
315 for (
int i = 0; i <
m_mesh->m_element[
m_mesh->m_expDim].size(); ++i)
332 m_mesh->m_composite.clear();
337 for (
int d = 0; d <=
m_mesh->m_expDim; ++d)
339 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[d];
341 for (
int i = 0; i < elmt.size(); ++i)
344 unsigned int tagid = elmt[i]->GetTagList()[0];
346 it =
m_mesh->m_composite.find(tagid);
348 if (it ==
m_mesh->m_composite.end())
352 pair<CompositeMap::iterator, bool> testIns;
354 tmp->m_tag = elmt[i]->GetTag();
355 testIns =
m_mesh->m_composite.insert(
356 pair<unsigned int, CompositeSharedPtr>(tagid,tmp));
360 if (elmt[i]->GetTag() != it->second->m_tag)
362 cout <<
"Different types of elements in same composite!" << endl;
363 cout <<
" -> Composite uses " << it->second->m_tag << endl;
364 cout <<
" -> Element uses " << elmt[i]->GetTag() << endl;
365 cout <<
"Have you specified physical volumes and surfaces?" << endl;
367 it->second->m_items.push_back(elmt[i]);
408 set<int> prismsDone, tetsDone;
412 for (i = 0; i <
m_mesh->m_element[3].size(); ++i)
418 prismsDone.insert(i);
428 for (it =
m_mesh->m_vertexSet.begin(); it !=
m_mesh->m_vertexSet.end(); ++it)
435 int prismTris[2][3] = {{0,1,4}, {3,2,5}};
439 boost::unordered_set<int> facesDone;
443 while (prismsDone.size() > 0)
445 vector<ElementSharedPtr> line;
449 PrismLines(*prismsDone.begin(), perFaces, prismsDone, line);
453 for (i = 0; i < line.size(); ++i)
456 vector<int> tags = line[i]->GetTagList();
457 vector<NodeSharedPtr> nodes = line[i]->GetVertexList();
462 line[i]->GetFace(1), line[i]->GetFace(3)
465 fIt[0] = facesDone.find(f[0]->m_id);
466 fIt[1] = facesDone.find(f[1]->m_id);
470 for (j = 0; j < 2; ++j)
472 pIt = perFaces.find(f[j]->m_id);
474 if (pIt == perFaces.end())
479 fIt2 = facesDone.find(pIt->second.first->m_id);
481 if (fIt[j] == facesDone.end() &&
482 fIt2 != facesDone.end())
488 if (fIt[0] != facesDone.end() &&
489 fIt[1] != facesDone.end())
493 ASSERTL0(
false,
"Renumbering error!");
495 else if (fIt[0] == facesDone.end() &&
496 fIt[1] == facesDone.end())
499 for (j = 0; j < 2; ++j)
501 for (k = 0; k < 3; ++k)
511 facesDone.insert(f[0]->m_id);
512 facesDone.insert(f[1]->m_id);
518 int t = fIt[0] == facesDone.end() ? 0 : 1;
520 ASSERTL1(fIt[o] != facesDone.end(),
"Renumbering error");
526 nodes[prismTris[o][0]]->m_id,
527 nodes[prismTris[o][1]]->m_id,
528 nodes[prismTris[o][2]]->m_id
530 int tmp2[3] = {0,1,2};
532 if (tmp1[0] > tmp1[1])
534 swap(tmp1[0], tmp1[1]);
535 swap(tmp2[0], tmp2[1]);
538 if (tmp1[1] > tmp1[2])
540 swap(tmp1[1], tmp1[2]);
541 swap(tmp2[1], tmp2[2]);
544 if (tmp1[0] > tmp1[2])
546 swap(tmp1[0], tmp1[2]);
547 swap(tmp2[0], tmp2[2]);
551 for (j = 0; j < 3; ++j)
560 facesDone.insert(f[t]->m_id);
563 for (j = 0; j < 6; ++j)
565 ASSERTL1(nodes[j]->m_id != -1,
"Renumbering error");
574 m_mesh->m_element[3][line[i]->GetId()] = el;
579 for (pIt = perFaces.begin(); pIt != perFaces.end(); ++pIt)
583 vector<int> perVerts = pIt->second.second;
584 int nVerts = perVerts.size();
587 for (j = 0; j < nVerts; ++j)
592 if (n1->m_id == -1 && n2->m_id == -1)
597 else if (n1->m_id != -1 && n2->m_id != -1)
603 ASSERTL0(
false,
"Periodic face renumbering error");
610 for (it2 = tetsDone.begin(); it2 != tetsDone.end(); ++it2)
613 vector<NodeSharedPtr> nodes = el->GetVertexList();
614 vector<int> tags = el->GetTagList();
616 for (i = 0; i < 4; ++i)
618 if (nodes[i]->m_id == -1)
620 nodes[i]->m_id = nodeId++;
631 for (it =
m_mesh->m_vertexSet.begin(); it !=
m_mesh->m_vertexSet.end(); ++it)
633 if ((*it)->m_id == -1)
635 (*it)->m_id = nodeId++;
646 set<int> &prismsDone,
647 vector<ElementSharedPtr> &line)
653 if (it == prismsDone.end())
659 prismsDone.erase(it);
660 line.push_back(
m_mesh->m_element[3][prism]);
663 for (i = 1; i <= 3; i += 2)
669 it2 = perFaces.find(f->m_id);
671 if (it2 != perFaces.end())
673 int id2 = it2->second.first->m_id;
674 nextId = it2->second.first->m_elLink[0].first->GetId();
677 PrismLines(nextId, perFaces, prismsDone, line);
681 if (f->m_elLink.size() == 1)
686 nextId = f->m_elLink[0].first->GetId();
687 if (nextId ==
m_mesh->m_element[3][prism]->GetId())
689 nextId = f->m_elLink[1].first->GetId();
692 PrismLines(nextId, perFaces, prismsDone, line);
704 cerr <<
"WARNING: Unrecognised config option " << key
705 <<
", proceeding anyway." << endl;
708 it->second.beenSet =
true;
710 if (it->second.isBool)
712 it->second.value =
"1";
716 it->second.value = val;
729 cerr <<
"No configuration options for this module." << endl;
735 cerr << setw(10) << it->first <<
": " << it->second.desc
750 if (!it->second.beenSet)
752 it->second.value = it->second.defValue;
764 cerr <<
"Expansion dimension is " <<
m_mesh->m_expDim << endl;
765 cerr <<
"Space dimension is " <<
m_mesh->m_spaceDim << endl;
766 cerr <<
"Read " <<
m_mesh->m_node.size() <<
" nodes" << endl;
767 cerr <<
"Read " <<
m_mesh->GetNumElements() <<
" "
768 <<
m_mesh->m_expDim <<
"-D elements" << endl;
769 cerr <<
"Read " <<
m_mesh->GetNumBndryElements()
770 <<
" boundary elements" << endl;