40 #include "../MeshElements.h"
50 "Reads Semtex session files.");
85 cout <<
"InputSem: Start reading file..." << endl;
114 if (word ==
"<"+it->first || word ==
"<"+it->first+
">")
126 if (
sectionMap[
"NODES"] == std::streampos(-1))
128 cerr <<
"Unable to locate NODES section in session file."
133 if (
sectionMap[
"ELEMENTS"] == std::streampos(-1))
135 cerr <<
"Unable to locate ELEMENTS section in session file."
140 if (
sectionMap[
"SURFACES"] != std::streampos(-1))
144 cerr <<
"SURFACES section defined but BCS section not "
149 if (
sectionMap[
"GROUPS"] == std::streampos(-1))
151 cerr <<
"SURFACES section defined but GROUPS section not "
156 if (
sectionMap[
"FIELDS"] == std::streampos(-1))
158 cerr <<
"SURFACES section defined but FIELDS section not "
166 int start, end, nVertices, nEntities, nCurves, nSurf, nGroups, nBCs;
168 vector<double> hoXData, hoYData;
176 ss.clear(); ss.str(line);
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)
continue;
189 ss.clear(); ss.str(line);
190 double x = 0, y = 0, z = 0;
191 ss >>
id >> x >> y >> z;
193 if ((y * y) > 0.000001 &&
m_mesh->m_spaceDim != 3)
197 if ((z * z) > 0.000001)
202 m_mesh->m_node.push_back(boost::shared_ptr<Node>(
new Node(
id, x, y, z)));
209 ss.clear(); ss.str(line);
213 start = tag.find_first_of(
'=');
214 end = tag.find_first_of(
'>');
215 nEntities = atoi(tag.substr(start+1,end).c_str());
218 while (i < nEntities)
221 if (line.length() < 18)
231 ss.clear(); ss.str(line);
233 vector<NodeSharedPtr> nodeList;
234 for (j = 0; j < 4; ++j)
238 nodeList.push_back(
m_mesh->m_node[node-1]);
244 CreateInstance(elType,conf,nodeList,tags);
247 if (E->GetDim() >
m_mesh->m_expDim) {
248 m_mesh->m_expDim = E->GetDim();
250 m_mesh->m_element[E->GetDim()].push_back(E);
255 if (
sectionMap[
"CURVES"] != std::streampos(-1))
257 int np, nel, nodeId =
m_mesh->m_node.size();
261 ss.clear(); ss.str(line);
265 start = tag.find_first_of(
'=');
266 end = tag.find_first_of(
'>');
267 nCurves = atoi(tag.substr(start+1,end).c_str());
273 string fname =
m_config[
"infile"].as<
string>();
274 int ext = fname.find_last_of(
'.');
275 string meshfile = fname.substr(0,ext) +
".msh";
277 homeshFile.open(meshfile.c_str());
278 if (!homeshFile.is_open())
280 cerr <<
"Cannot open or find mesh file: "
282 <<
"Make sure to run meshpr on your session "
283 <<
"file first." << endl;
288 getline(homeshFile, line);
289 ss.clear(); ss.str(line);
290 ss >> np >> nel >> nel >> nel;
294 cerr <<
"Number of elements mismatch in mesh file." << endl;
301 hoXData.resize(nel*np*np);
302 hoYData.resize(nel*np*np);
304 for (j = 0; j < nel*np*np; ++j)
306 getline(homeshFile, line);
307 ss.clear(); ss.str(line);
308 ss >> hoXData[j] >> hoYData[j];
318 if (line.length() < 18)
322 int elmt = 0, side = 0;
323 ss.clear(); ss.str(line);
324 ss >>
id >> elmt >> side >> word;
328 vector<NodeSharedPtr> edgeNodes;
330 if (word !=
"<SPLINE>" && word !=
"<ARC>")
332 cerr <<
"Unknown curve tag: " << word << endl;
339 if (
m_mesh->m_element[2][elmt]->GetConf().m_order > 1)
346 for (
int side = 0; side < 4; ++side)
348 int offset = elmt*np*np;
370 cerr <<
"Unknown side for curve id " <<
id << endl;
374 for (j = 1; j < np-1; ++j, ++nodeId)
376 double x = hoXData[offset+j*stride];
377 double y = hoYData[offset+j*stride];
379 new Node(nodeId, x, y, 0.0));
380 edgeNodes.push_back(n);
385 for (j = 1; j < np-1; ++j)
388 for (k = 1; k < np-1; ++k, ++nodeId)
390 double x = hoXData[offset+k];
391 double y = hoYData[offset+k];
393 new Node(nodeId, x, y, 0.0));
394 edgeNodes.push_back(n);
401 vector<NodeSharedPtr> elvert = e->GetVertexList();
402 vector<int> tags = e->GetTagList();
403 edgeNodes.insert(edgeNodes.begin(), elvert.begin(), elvert.end());
410 CreateInstance(elType,conf,edgeNodes,tags);
417 if (
sectionMap[
"FIELDS"] != std::streampos(-1))
422 ss.clear(); ss.str(line);
426 m_mesh->m_fields.push_back(tag);
432 if (
sectionMap[
"SURFACES"] != std::streampos(-1))
434 map<string,int> conditionMap;
440 ss.clear(); ss.str(line);
444 start = tag.find_first_of(
'=');
445 end = tag.find_first_of(
'>');
446 nGroups = atoi(tag.substr(start+1,end).c_str());
452 ss.clear(); ss.str(line);
454 conditionMap[tag] = i++;
463 ss.clear(); ss.str(line);
467 start = tag.find_first_of(
'=');
468 end = tag.find_first_of(
'>');
469 nBCs = atoi(tag.substr(start+1,end).c_str());
478 ss.clear(); ss.str(line);
479 ss >>
id >> tag >> nF;
482 m_mesh->m_condition[conditionMap[tag]] = p;
489 ss.clear(); ss.str(line);
497 else if (tmp ==
"<N>")
501 else if (tmp ==
"<H>")
504 p->value.push_back(
"0");
505 p->field.push_back(
"p");
511 cerr <<
"Unsupported boundary condition type " << tmp << endl;
517 p->field.push_back(tmp);
523 cerr <<
"Couldn't read boundary condition type " << tag << endl;
530 p->value.push_back(tmp);
538 p->m_composite.push_back(conditionMap[tag]+1);
546 ss.clear(); ss.str(line);
550 start = tag.find_first_of(
'=');
551 end = tag.find_first_of(
'>');
552 nSurf = atoi(tag.substr(start+1,end).c_str());
556 int periodicTagId = -1;
558 set<pair<int, int> > visitedPeriodic;
563 ss.clear(); ss.str(line);
564 ss >>
id >> elmt >> side >> word;
573 if (periodicTagId == -1)
575 periodicTagId = maxTag;
580 for (j = 0; j <
m_mesh->m_fields.size(); ++j)
584 in-> field.push_back(
m_mesh->m_fields[j]);
585 out->field.push_back(
m_mesh->m_fields[j]);
586 in-> value.push_back(
"["+boost::lexical_cast<
587 string>(periodicTagId+1)+
"]");
588 out->value.push_back(
"["+boost::lexical_cast<
589 string>(periodicTagId)+
"]");
591 in-> m_composite.push_back(periodicTagId+1);
592 out->m_composite.push_back(periodicTagId+2);
593 m_mesh->m_condition[periodicTagId] = in;
594 m_mesh->m_condition[periodicTagId+1] = out;
599 ss >> elmtB >> sideB;
603 pair<int, int> c1(elmt, side );
604 pair<int, int> c2(elmtB, sideB);
606 if (visitedPeriodic.count(c1) == 0 &&
607 visitedPeriodic.count(c2) == 0)
609 visitedPeriodic.insert(make_pair(elmtB, sideB));
610 visitedPeriodic.insert(make_pair(elmt, side ));
615 else if (word ==
"<B>")
622 cerr <<
"Unrecognised or unsupported tag " << word << endl;
643 vector<NodeSharedPtr> edgeNodes = edge->m_edgeNodes;
644 edgeNodes.insert(edgeNodes.begin(),edge->m_n2);
645 edgeNodes.insert(edgeNodes.begin(),edge->m_n1);
646 int order = edgeNodes.size()-1;
649 tags.push_back(tagId);
655 m_mesh->m_element[1].push_back(E);
pair< ModuleType, string > ModuleKey
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
map< string, ConfigOption > m_config
List of configuration values.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Node > NodeSharedPtr
Shared pointer to a Node.
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::shared_ptr< Condition > ConditionSharedPtr
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer to an element.
virtual void ProcessVertices()
Extract element vertices.
virtual void ProcessElements()
Generate element IDs.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Basic information about an element.
virtual void ProcessComposites()
Generate composites.
Represents a point in the domain.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
Defines a boundary condition.
ElementFactory & GetElementFactory()
1D Gauss-Lobatto-Legendre quadrature points
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.