50 "Reads Semtex session files.");
83 cout <<
"InputSem: Start reading file..." << endl;
87 string fileContents, line, word;
88 stringstream ss, ssFile;
115 if (word ==
"<" + it.first || word ==
"<" + it.first +
">")
117 sectionMap[it.first] = linePos;
127 if (
sectionMap[
"NODES"] == std::streampos(-1))
129 cerr <<
"Unable to locate NODES section in session file." << endl;
133 if (
sectionMap[
"ELEMENTS"] == std::streampos(-1))
135 cerr <<
"Unable to locate ELEMENTS section in session file." << endl;
139 if (
sectionMap[
"SURFACES"] != std::streampos(-1))
143 cerr <<
"SURFACES section defined but BCS section not " 148 if (
sectionMap[
"GROUPS"] == std::streampos(-1))
150 cerr <<
"SURFACES section defined but GROUPS section not " 155 if (
sectionMap[
"FIELDS"] == std::streampos(-1))
157 cerr <<
"SURFACES section defined but FIELDS section not " 165 int start, end, nVertices, nEntities, nCurves, nSurf, nGroups, nBCs;
167 vector<double> hoXData, hoYData;
180 start = tag.find_first_of(
'=');
181 end = tag.find_first_of(
'>');
182 nVertices = atoi(tag.substr(start + 1, end).c_str());
185 while (i < nVertices)
188 if (line.length() < 7)
192 double x = 0, y = 0, z = 0;
193 ss >>
id >> x >> y >> z;
195 if ((y * y) > 0.000001 &&
m_mesh->m_spaceDim != 3)
199 if ((z * z) > 0.000001)
205 std::shared_ptr<Node>(
new Node(
id, x, y, z)));
217 start = tag.find_first_of(
'=');
218 end = tag.find_first_of(
'>');
219 nEntities = atoi(tag.substr(start + 1, end).c_str());
222 while (i < nEntities)
225 if (line.length() < 18)
238 vector<NodeSharedPtr> nodeList;
239 for (j = 0; j < 4; ++j)
243 nodeList.push_back(
m_mesh->m_node[node - 1]);
252 if (E->GetDim() >
m_mesh->m_expDim)
254 m_mesh->m_expDim = E->GetDim();
256 m_mesh->m_element[E->GetDim()].push_back(E);
261 if (
sectionMap[
"CURVES"] != std::streampos(-1))
263 int np, nel, nodeId =
m_mesh->m_node.size();
272 start = tag.find_first_of(
'=');
273 end = tag.find_first_of(
'>');
274 nCurves = atoi(tag.substr(start + 1, end).c_str());
280 string fname =
m_config[
"infile"].as<
string>();
281 int ext = fname.find_last_of(
'.');
282 string meshfile = fname.substr(0, ext) +
".msh";
284 homeshFile.open(meshfile.c_str());
285 if (!homeshFile.is_open())
287 cerr <<
"Cannot open or find mesh file: " << meshfile << endl
288 <<
"Make sure to run meshpr on your session " 289 <<
"file first." << endl;
294 getline(homeshFile, line);
297 ss >> np >> nel >> nel >> nel;
301 cerr <<
"Number of elements mismatch in mesh file." << endl;
308 hoXData.resize(nel * np * np);
309 hoYData.resize(nel * np * np);
311 for (j = 0; j < nel * np * np; ++j)
313 getline(homeshFile, line);
316 ss >> hoXData[j] >> hoYData[j];
326 if (line.length() < 18)
330 int elmt = 0, side = 0;
333 ss >>
id >> elmt >> side >> word;
337 vector<NodeSharedPtr> edgeNodes;
339 if (word !=
"<SPLINE>" && word !=
"<ARC>")
341 cerr <<
"Unknown curve tag: " << word << endl;
348 if (
m_mesh->m_element[2][elmt]->GetConf().m_order > 1)
355 for (
int side = 0; side < 4; ++side)
357 int offset = elmt * np * np;
371 offset += np * np - 1;
375 offset += np * (np - 1);
379 cerr <<
"Unknown side for curve id " <<
id << endl;
383 for (j = 1; j < np - 1; ++j, ++nodeId)
385 double x = hoXData[offset + j * stride];
386 double y = hoYData[offset + j * stride];
388 std::shared_ptr<Node>(
new Node(nodeId, x, y, 0.0));
389 edgeNodes.push_back(n);
394 for (j = 1; j < np - 1; ++j)
396 int offset = j * np + 1;
397 for (k = 1; k < np - 1; ++k, ++nodeId)
399 double x = hoXData[offset + k];
400 double y = hoYData[offset + k];
402 std::shared_ptr<Node>(
new Node(nodeId, x, y, 0.0));
403 edgeNodes.push_back(n);
410 vector<NodeSharedPtr> elvert = e->GetVertexList();
411 vector<int> tags = e->GetTagList();
412 edgeNodes.insert(edgeNodes.begin(), elvert.begin(), elvert.end());
423 elType, conf, edgeNodes, tags);
430 if (
sectionMap[
"FIELDS"] != std::streampos(-1))
440 m_mesh->m_fields.push_back(tag);
446 if (
sectionMap[
"SURFACES"] != std::streampos(-1))
448 map<string, int> conditionMap;
459 start = tag.find_first_of(
'=');
460 end = tag.find_first_of(
'>');
461 nGroups = atoi(tag.substr(start + 1, end).c_str());
470 conditionMap[tag] = i++;
484 start = tag.find_first_of(
'=');
485 end = tag.find_first_of(
'>');
486 nBCs = atoi(tag.substr(start + 1, end).c_str());
497 ss >>
id >> tag >> nF;
500 m_mesh->m_condition[conditionMap[tag]] =
p;
516 else if (tmp ==
"<N>")
520 else if (tmp ==
"<H>")
523 p->value.push_back(
"0");
524 p->field.push_back(
"p");
530 cerr <<
"Unsupported boundary condition type " << tmp
537 p->field.push_back(tmp);
543 cerr <<
"Couldn't read boundary condition type " << tag
551 p->value.push_back(tmp);
559 p->m_composite.push_back(conditionMap[tag] + 1);
572 start = tag.find_first_of(
'=');
573 end = tag.find_first_of(
'>');
574 nSurf = atoi(tag.substr(start + 1, end).c_str());
578 int periodicTagId = -1;
580 set<pair<int, int> > visitedPeriodic;
587 ss >>
id >> elmt >> side >> word;
596 if (periodicTagId == -1)
598 periodicTagId = maxTag;
602 for (j = 0; j <
m_mesh->m_fields.size(); ++j)
606 in->field.push_back(
m_mesh->m_fields[j]);
607 out->field.push_back(
m_mesh->m_fields[j]);
608 in->value.push_back(
"[" + boost::lexical_cast<string>(
611 out->value.push_back(
612 "[" + boost::lexical_cast<string>(periodicTagId) +
615 in->m_composite.push_back(periodicTagId + 1);
616 out->m_composite.push_back(periodicTagId + 2);
617 m_mesh->m_condition[periodicTagId] = in;
618 m_mesh->m_condition[periodicTagId + 1] = out;
623 ss >> elmtB >> sideB;
627 pair<int, int> c1(elmt, side);
628 pair<int, int> c2(elmtB, sideB);
630 if (visitedPeriodic.count(c1) == 0 &&
631 visitedPeriodic.count(c2) == 0)
633 visitedPeriodic.insert(make_pair(elmtB, sideB));
634 visitedPeriodic.insert(make_pair(elmt, side));
639 else if (word ==
"<B>")
642 insertEdge(elmt, side, conditionMap[tag] + 1);
646 cerr <<
"Unrecognised or unsupported tag " << word << endl;
666 vector<NodeSharedPtr> edgeNodes = edge->m_edgeNodes;
667 edgeNodes.insert(edgeNodes.begin(), edge->m_n2);
668 edgeNodes.insert(edgeNodes.begin(), edge->m_n1);
669 int order = edgeNodes.size() - 1;
672 tags.push_back(tagId);
682 m_mesh->m_element[1].push_back(E);
Defines a boundary condition.
Basic information about an element.
MeshSharedPtr m_mesh
Mesh object.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
ElementFactory & GetElementFactory()
std::shared_ptr< Node > NodeSharedPtr
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::pair< ModuleType, std::string > ModuleKey
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
std::shared_ptr< Element > ElementSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< Condition > ConditionSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
1D Gauss-Lobatto-Legendre quadrature points
ModuleFactory & GetModuleFactory()