39 std::getline(in, line);
56 catch (
const std::exception &e)
58 std::cerr <<
"seems in a comment but failed to parse it: ";
59 std::cerr << e.what() <<
'\n';
69 inline bool getUntil(std::istream &in,
char v, std::string &buf)
90 inline void readOpenFOAMList(std::istream &in,
const std::function<
void(std::istream &)> &readOneItem)
111 inline void readOpenFOAMObj(std::istream &in,
const std::function<
void(
const std::string &)> &readOneItemLine)
113 bool gotLeft =
false;
131 readOneItemLine(lineBuf);
141 std::stringstream bufSS(buf);
145 std::vector<std::string> ret;
147 { ret.push_back(lineBuf); });
154 std::vector<std::vector<index>>
faces;
173 std::vector<real> readReals;
174 readReals.reserve(4);
179 readReals.push_back(
v);
182 points.at(iPoint).x() = readReals.at(0);
183 points.at(iPoint).y() = readReals.at(1);
184 points.at(iPoint).z() = readReals.at(2);
206 faces.at(iFace).reserve(faceSiz);
211 faces.at(iFace).push_back(inode);
238 owner.at(iFace) = iCell;
281 [&](std::istream &in)
286 std::stringstream bufSS(buf);
291 [&](
const std::string &lineBuf)
293 std::stringstream lineBufSS(lineBuf);
308 if (key ==
"startFace")
311 lineBufSS >> startFace;
319 std::cout << bc.first <<
" " << bc.second.type <<
" " << bc.second.nFaces <<
" " << bc.second.startFace << std::endl;
324 inline std::tuple<Elem::ElemType, std::vector<index>>
326 const std::vector<int> &ownIn)
328 std::vector<std::vector<index>> faces = facesIn;
329 std::vector<int> own = ownIn;
334 std::vector<index> nodes;
336 if (faces.size() == 6)
338 for (
auto &
v : faces)
341 return std::make_tuple(etype, nodes);
344 for (
auto v : faces[0])
347 for (
int i = faces[0].size() - 1; i >= 0; i--)
348 nodes.push_back(faces[0][i]);
349 for (
int iFoot = 0; iFoot < 4; iFoot++)
351 index foot = nodes.at(iFoot);
353 for (
int iFace = 1; iFace < faces.size(); iFace++)
358 for (
int iF2N = 0; iF2N < faces[iFace].size(); iF2N++)
359 if (faces[iFace][iF2N] == foot)
363 headL = faces[iFace][(iFootC - 1) % faces[iFace].size()];
364 headR = faces[iFace][(iFootC + 1) % faces[iFace].size()];
365 auto itFoundL = std::find(nodes.begin(), nodes.begin() + 4, headL);
366 if (itFoundL == nodes.begin() + 4)
373 return std::make_tuple(etype, nodes);
374 nodes.push_back(head);
377 return std::make_tuple(etype, nodes);
381 DNDS_assert_info(
false, fmt::format(
"faces size {} not supported", faces.size()));
382 return std::make_tuple(etype, nodes);
384 return std::make_tuple(etype, nodes);
398 for (
index iF = 0; iF < reader.
faces.size(); iF++)
401 if (reader.
faces.at(iF).size() == 4)
403 else if (reader.
faces.at(iF).size() == 3)
406 DNDS_assert_info(
false, fmt::format(
"face {} has {} nodes, not supported", iF, reader.
faces.at(iF).size()));
414 nCell = std::max(nCell,
v);
415 for (
auto v : reader.
owner)
416 nCell = std::max(nCell,
v);
420 std::vector<int>
nFaces(nCell, 0);
423 for (
auto v : reader.
owner)
425 for (
index iCell = 0; iCell < nCell; iCell++)
430 for (
index iFace = 0; iFace < reader.
owner.size(); iFace++)
442 std::cout <<
"OF Converter has nCell " << nCell << std::endl;
451 std::vector<std::vector<index>> facesIn;
452 for (
auto iFace : this->cell2face[iCell])
454 facesIn.push_back(reader.
faces.at(iFace));
458 fmt::format(
"elem reconstruction failed, iCell {}, nFaces {}", iCell, facesIn.size()));
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
std::vector< std::string > readOpenFOAMHeader(std::istream &in)
void readOpenFOAMList(std::istream &in, const std::function< void(std::istream &)> &readOneItem)
std::tuple< Elem::ElemType, std::vector< index > > ExtractTopologicalElementFromPolyMeshCell(const std::vector< std::vector< index > > &facesIn, const std::vector< int > &ownIn)
int passOpenFOAMSpaces(std::istream &in)
bool getUntil(std::istream &in, char v, std::string &buf)
void readOpenFOAMObj(std::istream &in, const std::function< void(const std::string &)> &readOneItemLine)
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
std::vector< std::vector< index > > cell2face
std::vector< std::vector< index > > cell2node
void BuildCell2Face(OpenFOAMReader &reader)
void BuildFaceElemInfo(OpenFOAMReader &reader)
std::vector< ElemInfo > faceElemInfo
std::vector< ElemInfo > cellElemInfo
std::vector< std::vector< int > > cell2faceOwn
void BuildCell2Node(OpenFOAMReader &reader)
std::map< std::string, OpenFOAMBoundaryCondition > boundaryConditions
std::vector< tPoint > points
std::vector< index > owner
void ReadBoundary(std::istream &IFS)
void ReadPoints(std::istream &IFS)
void ReadOwner(std::istream &IFS)
void ReadNeighbour(std::istream &IFS)
std::vector< index > neighbour
void ReadFaces(std::istream &IFS)
std::vector< std::vector< index > > faces
Eigen::Matrix< real, 5, 1 > v