41 #include <boost/algorithm/string.hpp>
57 InputNek5000::create,
"Reads Nektar rea file.");
82 int nParam, nElements, nCurves;
83 int i, j, k, nodeCounter = 0;
93 cout <<
"InputNek5000: Start reading file..." << endl;
99 for (i = 0; i < 4; ++i)
104 stringstream s(line);
107 for (i = 0; i < nParam; ++i)
120 for (i = 0; i < j; ++i)
130 for (i = 0; i < j; ++i)
138 bool foundMesh =
false;
142 if (line.find(
"MESH") != string::npos)
151 cerr <<
"Couldn't find MESH tag inside file." << endl;
159 s >> nElements >>
m_mesh->m_expDim;
163 m_mesh->m_fields.push_back(
"u");
164 m_mesh->m_fields.push_back(
"v");
165 if (
m_mesh->m_spaceDim > 2)
167 m_mesh->m_fields.push_back(
"w");
169 m_mesh->m_fields.push_back(
"p");
172 for (i = 0; i < nElements; ++i)
177 if (
m_mesh->m_expDim == 2)
182 for (j = 0; j < 2; ++j)
187 for (k = 0; k < 4; ++k)
199 for (j = 0; j < 6; ++j)
204 int offset = j > 2 ? 4 : 0;
205 for (k = 0; k < 4; ++k)
207 s >> vertex[offset + k][j % 3];
215 vector<NodeSharedPtr> nodeList(nNodes);
216 for (k = 0; k < nNodes; ++k)
218 nodeList[k] = boost::shared_ptr<Node>(
220 0, vertex[k][0], vertex[k][1], vertex[k][2]));
221 pair<NodeSet::iterator, bool> testIns =
222 m_mesh->m_vertexSet.insert(nodeList[k]);
226 nodeList[k] = *(testIns.first);
230 nodeList[k]->m_id = nodeCounter++;
234 vector<int> tags(1, 0);
237 elType, conf, nodeList, tags);
238 m_mesh->m_element[E->GetDim()].push_back(E);
243 if (line.find(
"CURVE") == string::npos)
245 cerr <<
"Cannot find curved side data." << endl;
263 int nek2nekedge[12] = {
264 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7
270 int nek2nekface[6] = {
276 for (i = 0; i < nCurves; ++i)
284 if (nElements < 1000)
287 s.str(line.substr(0, 3));
290 s.str(line.substr(3, 3));
292 line = line.substr(6);
294 else if (nElements < 1000000)
297 s.str(line.substr(0, 2));
300 s.str(line.substr(2, 6));
302 line = line.substr(8);
307 s.str(line.substr(0, 2));
310 s.str(line.substr(2, 12));
312 line = line.substr(14);
318 for (j = 0; j < 5; ++j)
326 side = nek2nekedge[side];
337 int convexity = radius < 0 ? -1 : 1;
338 radius = fabs(radius);
346 Node P1(*(edge->m_n1)), P2(*(edge->m_n2));
348 if (fabs(P1.m_z - P2.
m_z) > 1e-8)
350 cout <<
"warning: detected non x-y edge." << endl;
352 P1.m_z = P2.
m_z = 0.0;
354 Node unitNormal, link, centroid, centre;
355 Node midpoint = (P1 + P2)*0.5, dx = P2 - P1;
358 unitNormal.
m_x = -dx.m_y / l;
359 unitNormal.
m_y = dx.m_x / l;
361 if (2.0 * radius < l)
363 cerr <<
"failure" << endl;
367 semiangle = asin (0.5 * l / radius);
371 vector<NodeSharedPtr> elNodes = el->GetVertexList();
372 int nNodes = elNodes.size();
374 for (
int i = 0; i < nNodes; ++i)
377 Node tmp(*elNodes[i]);
383 link = centroid - midpoint;
386 centre = midpoint + unitNormal * (
sign * cos(semiangle) *
390 theta1 = atan2 (P1.m_y - centre.
m_y, P1.m_x - centre.
m_x);
391 theta2 = atan2 (P2.
m_y - centre.
m_y, P2.
m_x - centre.
m_x);
392 dtheta = theta2 - theta1;
394 if (fabs(dtheta) > 2.0*semiangle + 1e-15)
396 dtheta += (dtheta < 0.0) ? 2.0*M_PI : -2.0*M_PI;
399 edge->m_edgeNodes.clear();
401 for (j = 1; j < nq-1; ++j) {
402 phi = theta1 + dtheta * 0.5 * (rp[j] + 1.0);
405 centre.
m_x + radius * cos(phi),
406 centre.
m_y + radius * sin(phi),
408 edge->m_edgeNodes.push_back(asd);
416 cerr <<
"Curve type '" << curveType <<
"' on side " << side
417 <<
" of element " << elmt <<
" is unsupported;"
418 <<
"will ignore." << endl;
421 cerr <<
"Unknown curve type '" << curveType <<
"' on side "
422 << side <<
" of element " << elmt <<
"; will ignore."
432 if (line.find(
"BOUNDARY") == string::npos)
434 cerr <<
"Cannot find boundary conditions." << endl;
439 boost::unordered_set<pair<int, int> > periodicIn;
440 int periodicInId = -1, periodicOutId = -1;
445 int perIn = 0, perOut = 0;
453 if (line.find(
"*") != string::npos)
465 s.str(line.substr(0, 4));
468 if (nElements < 1000)
472 s.str(line.substr(4, 3));
475 s.str(line.substr(7, 3));
477 line = line.substr(10);
479 else if (nElements < 100000)
483 s.str(line.substr(4, 5));
486 s.str(line.substr(9, 1));
488 line = line.substr(10);
490 else if (nElements < 1000000)
494 s.str(line.substr(4, 6));
496 side = lineCnt % (2 *
m_mesh->m_expDim);
497 line = line.substr(9);
503 s.str(line.substr(4, 12));
505 side = lineCnt % (2 *
m_mesh->m_expDim);
506 line = line.substr(15);
512 for (i = 0; i < 5; ++i)
526 std::string fields[] = {
"u",
"v",
"w",
"p" };
537 for (i = 0; i <
m_mesh->m_fields.size() - 1; ++i)
539 c->field.push_back(fields[i]);
540 c->value.push_back(
"0");
545 c->field.push_back(fields[3]);
546 c->value.push_back(
"0");
554 int perElmt = (int)(data[0] + 0.5) - 1;
555 int perFace = (int)(data[1] + 0.5) - 1;
558 if (periodicInId == -1)
560 periodicInId =
m_mesh->m_condition.size();
561 periodicOutId =
m_mesh->m_condition.size()+1;
565 bool hasIn = periodicIn.find(make_pair(perElmt, perFace)) !=
570 swap(periodicInId, periodicOutId);
575 periodicIn.insert(make_pair(elmt, side));
579 std::string periodicInStr =
"[" +
580 boost::lexical_cast<
string>(periodicInId) +
"]";
581 std::string periodicOutStr =
"[" +
582 boost::lexical_cast<
string>(periodicOutId) +
"]";
584 for (i = 0; i <
m_mesh->m_fields.size() - 1; ++i)
586 c->field.push_back(fields[i]);
587 c->value.push_back(periodicOutStr);
591 c->field.push_back(fields[3]);
592 c->value.push_back(periodicOutStr);
600 c->m_composite.push_back(nComposite++);
601 c2->m_composite.push_back(nComposite++);
603 c2->field = c->field;
605 for (i = 0; i < c->type.size(); ++i)
607 c2->value.push_back(periodicInStr);
610 m_mesh->m_condition[periodicInId] = c;
611 m_mesh->m_condition[periodicOutId] = c2;
616 swap(periodicInId, periodicOutId);
626 int compTag, conditionId;
630 if (el->GetDim() == 3)
633 vector<NodeSharedPtr> nodeList;
634 nodeList.insert(nodeList.begin(),
635 f->m_vertexList.begin(),
636 f->m_vertexList.end());
644 conf, nodeList, tags);
647 for (
int i = 0; i < f->m_vertexList.size(); ++i)
649 surfEl->GetEdge(i)->m_edgeNodes = f->m_edgeList[i]->m_edgeNodes;
650 surfEl->GetEdge(i)->m_curveType = f->m_edgeList[i]->m_curveType;
657 vector<NodeSharedPtr> nodeList;
658 nodeList.push_back(f->m_n1);
659 nodeList.push_back(f->m_n2);
675 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end();
688 conditionId =
m_mesh->m_condition.size();
689 compTag = nComposite;
690 c->m_composite.push_back(compTag);
691 m_mesh->m_condition[conditionId] = c;
695 compTag = c->m_composite[0];
700 vector<int> existingTags = surfEl->GetTagList();
702 existingTags.insert(existingTags.begin(), compTag);
703 surfEl->SetTagList(existingTags);
704 surfEl->SetId(nSurfaces);
706 m_mesh->m_element[surfEl->GetDim()].push_back(surfEl);
710 if (lineCnt != nElements * (
m_mesh->m_expDim * 2))
712 cerr <<
"Warning: boundary conditions may not have been correctly read "
713 <<
"from Nek5000 input file." << endl;
718 cerr <<
"Warning: number of periodic faces does not match." << endl;
730 if (periodicInId != -1)
733 ->m_composite[0]]->m_reorder =
false;
735 ->m_composite[0]]->m_reorder =
false;
NEKMESHUTILS_EXPORT NekDouble dot(const Node &pSrc) const
Basic information about an element.
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
#define sign(a, b)
return the sign(b)*a
pair< ModuleType, string > ModuleKey
NekDouble m_y
Y-coordinate.
MeshSharedPtr m_mesh
Mesh object.
ElementFactory & GetElementFactory()
Represents a point in the domain.
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
boost::shared_ptr< Node > NodeSharedPtr
PointsManagerT & PointsManager(void)
Defines a specification for a set of points.
boost::shared_ptr< Condition > ConditionSharedPtr
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
NekDouble m_x
X-coordinate.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::shared_ptr< Element > ElementSharedPtr
boost::shared_ptr< Face > FaceSharedPtr
NekDouble m_z
Z-coordinate.
std::pair< ModuleType, std::string > ModuleKey
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
1D Gauss-Lobatto-Legendre quadrature points
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.