254 cell2nodeSerial = make_ssp<decltype(cell2nodeSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::cell2nodeSerial"},
mesh->getMPI());
255 bnd2nodeSerial = make_ssp<decltype(bnd2nodeSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2nodeSerial"},
mesh->getMPI());
256 coordSerial = make_ssp<decltype(coordSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::coordSerial"},
mesh->getMPI());
259 bnd2cellSerial = make_ssp<decltype(bnd2cellSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2cellSerial"},
mesh->getMPI());
262 bnd2bndOrigSerial = make_ssp<decltype(bnd2bndOrigSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2bndOrigSerial"},
mesh->getMPI());
268 if (cg_open(fName.c_str(), CG_MODE_READ, &cgns_file))
270 std::cerr << fmt::format(
"cgns file cannot open: [{}]", fName) << std::endl;
274 if (cg_nbases(cgns_file, &n_bases))
276 DNDS::log() <<
"CGNS === N bases: " << n_bases << std::endl;
279 std::vector<std::pair<int, int>> Base_Zone;
280 std::vector<std::string> BaseNames;
281 std::vector<std::string> ZoneNames;
283 std::vector<std::array<cgsize_t, 9>> ZoneSizes;
284 std::vector<tCoord> ZoneCoords;
285 std::vector<tAdj> ZoneElems;
286 std::vector<tElemInfoArray> ZoneElemInfos;
287 std::vector<std::vector<std::vector<cgsize_t>>> ZoneConnect;
288 std::vector<std::vector<std::vector<cgsize_t>>> ZoneConnectDonor;
289 std::vector<std::vector<int>> ZoneConnectTargetIZone;
292 for (
int iBase = 1; iBase <= n_bases; iBase++)
296 std::array<char, 48> basename{};
301 if (cg_base_read(cgns_file, iBase, basename.data(), &celldim, &physdim))
304 if (cg_nzones(cgns_file, iBase, &nzones))
306 for (
int iZone = 1; iZone <= nzones; iZone++)
308 std::array<char, 48> zonename{};
309 std::array<cgsize_t, 9> size{0, 0, 0, 0, 0, 0, 0, 0, 0};
310 if (cg_zone_read(cgns_file, iBase, iZone, zonename.data(), size.data()))
313 if (cg_zone_type(cgns_file, iBase, iZone, &zoneType))
316 Base_Zone.emplace_back(iBase, iZone);
317 BaseNames.emplace_back(basename.data());
318 ZoneNames.emplace_back(zonename.data());
339 ZoneCoords.emplace_back(std::make_shared<
decltype(ZoneCoords)::value_type::element_type>());
340 ZoneCoords.back()->Resize(nNodes);
341 std::vector<double> coordsRead(nNodes);
342 std::array<cgsize_t, 3> RMin{1, 0, 0};
343 std::array<cgsize_t, 3> RMax{nNodes, 0, 0};
345 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateX", RealDouble, RMin.data(), RMax.data(), coordsRead.data()));
347 ZoneCoords.back()->operator[](
i)[0] = coordsRead.at(
i);
349 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateY", RealDouble, RMin.data(), RMax.data(), coordsRead.data()));
351 ZoneCoords.back()->operator[](
i)[1] = coordsRead.at(
i);
355 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateZ", RealDouble, RMin.data(), RMax.data(), coordsRead.data()));
358 for (
auto &
i : coordsRead)
361 ZoneCoords.back()->operator[](
i)[2] = coordsRead.at(
i);
363 DNDS::log() <<
"CGNS === Zone " << iZone <<
" Coords Reading Done" << std::endl;
377 [[maybe_unused]] cgsize_t cstart = 0;
378 [[maybe_unused]] cgsize_t cend = 0;
381 for (
int iSection = 1; iSection <= nSections; iSection++)
383 std::array<char, 48> sectionName{};
387 int nBnd{0}, parentFlag{0};
388 DNDS_CGNS_CALL_EXIT(cg_section_read(cgns_file, iBase, iZone, iSection, sectionName.data(), &etype, &start, &end, &
nBnd, &parentFlag));
394 maxend = std::max(end, maxend);
396 ZoneElems.emplace_back(std::make_shared<
decltype(ZoneElems)::value_type::element_type>());
397 ZoneElems.back()->Resize(maxend);
398 ZoneElemInfos.emplace_back(std::make_shared<
decltype(ZoneElemInfos)::value_type::element_type>());
399 ZoneElemInfos.back()->Resize(maxend);
401 for (
int iSection = 1; iSection <= nSections; iSection++)
403 std::array<char, 48> sectionName{};
407 int nBnd{0}, parentFlag{0};
408 DNDS_CGNS_CALL_EXIT(cg_section_read(cgns_file, iBase, iZone, iSection, sectionName.data(), &etype, &start, &end, &
nBnd, &parentFlag));
409 cgsize_t elemDataSize{0};
411 std::vector<cgsize_t> elemsRead(elemDataSize);
413 int nElemSec = end - start + 1;
416 std::vector<cgsize_t> elemStarts(nElemSec + 1);
417 DNDS_CGNS_CALL_EXIT(cg_poly_elements_read(cgns_file, iBase, iZone, iSection, elemsRead.data(), elemStarts.data(),
nullptr));
418 for (cgsize_t
i = 0;
i < nElemSec;
i++)
420 auto c_etype =
static_cast<ElementType_t
>(elemsRead.at(elemStarts[
i]));
423 DNDS::log() <<
"Error ETYPE " << std::to_string(c_etype) << std::endl;
428 "Element Node Number Mismatch!");
431 ZoneElems.back()->operator()(start - 1 +
i, iNode) =
432 elemsRead.at(elemStarts[
i] + 1 + iNode) - 1;
433 ZoneElemInfos.back()->operator()(start - 1 +
i, 0).setElemType(ct);
434 ZoneElemInfos.back()->operator()(start - 1 +
i, 0).zone = Geom::BC_ID_INTERNAL;
441 DNDS_CGNS_CALL_EXIT(cg_elements_read(cgns_file, iBase, iZone, iSection, elemsRead.data(),
nullptr));
443 for (cgsize_t
i = 0;
i < nElemSec;
i++)
448 ZoneElems.back()->operator()(start - 1 +
i, iNode) =
450 ZoneElemInfos.back()->operator()(start - 1 +
i, 0).setElemType(ct);
451 ZoneElemInfos.back()->operator()(start - 1 +
i, 0).zone = Geom::BC_ID_INTERNAL;
456 DNDS::log() <<
"Error ETYPE " << std::to_string(etype) << std::endl;
460 DNDS::log() <<
"CGNS === Zone " << iZone <<
" Elems Reading Done" << std::endl;
467 for (
int iBC = 1; iBC <= nBC; iBC++)
469 std::array<char, 48> boconame{};
470 PointSetType_t pType;
471 cgsize_t nPts, normalListSize;
473 std::array<int, 3> NormalIndex{};
474 DataType_t normalDataType;
477 DNDS_CGNS_CALL_EXIT(cg_boco_info(cgns_file, iBase, iZone, iBC, boconame.data(), &bcType, &pType, &nPts, NormalIndex.data(), &normalListSize, &normalDataType, &nDataset));
479 DNDS_assert_info(pType == PointRange || pType == PointList,
"Only PointRange / PointList supported in BC!");
484 std::vector<cgsize_t> pts(nPts);
485 std::vector<double> normalBuf(normalListSize);
486 DNDS_CGNS_CALL_EXIT(cg_boco_read(cgns_file, iBase, iZone, iBC, pts.data(), normalBuf.data()));
487 DNDS_assert(pts[0] >= 1 && pts[1] <= ZoneElems.back()->Size());
489 t_index BCCode = FBCName_2_ID(std::string(boconame.data()));
490 if (BCCode == BC_ID_NULL)
492 DNDS_assert_info(
false, fmt::format(
"BC NAME [{}] NOT FOUND IN DATABASE", boconame.data()));
494 if (pType == PointRange)
497 ZoneElemInfos.back()->operator()(
i, 0).zone = BCCode;
499 else if (pType == PointList)
502 ZoneElemInfos.back()->operator()(
i - 1, 0).zone = BCCode;
508 DNDS::log() <<
"CGNS === Zone " << iZone <<
" BCs Reading Done" << std::endl;
516 for (
int iBase = 1; iBase <= n_bases; iBase++)
520 std::array<char, 48> basename{};
525 if (cg_base_read(cgns_file, iBase, basename.data(), &celldim, &physdim))
528 if (cg_nzones(cgns_file, iBase, &nzones))
530 for (
int iZone = 1; iZone <= nzones; iZone++)
532 std::array<char, 48> zonename{};
533 std::array<cgsize_t, 9> size{0, 0, 0, 0, 0, 0, 0, 0, 0};
534 if (cg_zone_read(cgns_file, iBase, iZone, zonename.data(), size.data()))
537 if (cg_zone_type(cgns_file, iBase, iZone, &zoneType))
547 ZoneConnect.emplace_back();
548 ZoneConnectDonor.emplace_back();
549 ZoneConnectTargetIZone.emplace_back();
552 for (
int iConn = 1; iConn <= nConns; iConn++)
554 std::array<char, 48> connName{}, donorName{};
556 GridConnectivityType_t connType;
557 PointSetType_t ptType, ptType_donor;
558 cgsize_t npts, npts_donor;
562 DNDS_CGNS_CALL_EXIT(cg_conn_info(cgns_file, iBase, iZone, iConn, connName.data(), &gLoc, &connType, &ptType, &npts,
563 donorName.data(), &donorZT, &ptType_donor, &donorDT, &npts_donor));
565 DNDS_assert_info(connType == Abutting1to1,
"Only support Abutting1to1 in connection!");
566 DNDS_assert_info(ptType == PointList,
"Only Supports PointList in connection!");
567 DNDS_assert_info(ptType_donor == PointListDonor,
"Only Supports PointListDonor in connection!");
568 DNDS_assert_info(donorZT == Unstructured,
"Only Supports Unstructured in connection!");
570 DNDS_assert_info(npts_donor == npts,
"Only Supports npts_donor == npts in connection!");
573 ZoneConnectDonor.back().emplace_back(npts);
574 ZoneConnect.back().emplace_back(npts);
575 DNDS_CGNS_CALL_EXIT(cg_conn_read(cgns_file, iBase, iZone, iConn, ZoneConnect.back().back().data(), donorDT, ZoneConnectDonor.back().back().data()));
577 for (
size_t iGZ = 0; iGZ < ZoneNames.size(); iGZ++)
579 if (Base_Zone.at(iGZ).first == iBase)
581 if (ZoneNames.at(iGZ) == donorName.data())
588 ZoneConnectTargetIZone.back().push_back(iGZFound);
589 DNDS::log() <<
"CGNS === Connection at Zone-Zone: " << iZone <<
" - " << iGZFound + 1 << std::endl;
599 auto [NodeOld2New, ZoneNodeStarts] = AssembleZoneNodes(
600 ZoneCoords, ZoneConnect, ZoneConnectDonor, ZoneConnectTargetIZone,
601 coordSerial,
mesh->dim);
604 SeparateVolumeAndBoundaryElements(
605 ZoneElems, ZoneElemInfos, NodeOld2New, ZoneNodeStarts,
606 cell2nodeSerial, cellElemInfoSerial, cell2cellOrigSerial,
607 bnd2nodeSerial, bndElemInfoSerial, bnd2bndOrigSerial,
608 node2nodeOrigSerial, coordSerial,
mesh->dim);
614 bnd2cellSerial, bnd2nodeSerial, cell2nodeSerial,
615 cellElemInfoSerial, bndElemInfoSerial, coordSerial);
618 for (
DNDS::index iCell = 0; iCell < cell2cellOrigSerial->Size(); iCell++)
619 cell2cellOrigSerial->operator()(iCell, 0) = iCell;
620 for (
DNDS::index iNode = 0; iNode < node2nodeOrigSerial->Size(); iNode++)
621 node2nodeOrigSerial->operator()(iNode, 0) = iNode;
622 for (
DNDS::index iBnd = 0; iBnd < bnd2bndOrigSerial->Size(); iBnd++)
623 bnd2bndOrigSerial->operator()(iBnd, 0) = iBnd;
627 log() <<
"CGNS === Serial Read Done" << std::endl;
631 void UnstructuredMeshSerialRW::
632 ReadFromOpenFOAMAndConvertSerial(
const std::string &fName,
const std::map<std::string, std::string> &nameMapping,
const t_FBCName_2_ID &FBCName_2_ID)
635 this->dataIsSerialIn =
true;
637 cell2nodeSerial = make_ssp<decltype(cell2nodeSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::cell2nodeSerial"},
mesh->getMPI());
638 bnd2nodeSerial = make_ssp<decltype(bnd2nodeSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bnd2nodeSerial"},
mesh->getMPI());
639 coordSerial = make_ssp<decltype(coordSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::coordSerial"},
mesh->getMPI());
640 cellElemInfoSerial = make_ssp<decltype(cellElemInfoSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::cellElemInfoSerial"}, ElemInfo::CommType(), ElemInfo::CommMult(),
mesh->getMPI());
641 bndElemInfoSerial = make_ssp<decltype(bndElemInfoSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bndElemInfoSerial"}, ElemInfo::CommType(), ElemInfo::CommMult(),
mesh->getMPI());
642 bnd2cellSerial = make_ssp<decltype(bnd2cellSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bnd2cellSerial"},
mesh->getMPI());
644 if (mRank !=
mesh->getMPI().rank)
647 std::filesystem::path ofFilePath(fName);
648 std::ifstream pointsIFS(ofFilePath /
"points");
649 std::ifstream facesIFS(ofFilePath /
"faces");
650 std::ifstream ownerIFS(ofFilePath /
"owner");
651 std::ifstream neighbourIFS(ofFilePath /
"neighbour");
652 std::ifstream boundaryIFS(ofFilePath /
"boundary");
672 coordSerial->Resize(ofReader.
points.size());
673 for (
index iN = 0; iN < coordSerial->Size(); iN++)
674 (*coordSerial)[iN] = ofReader.
points.at(iN);
675 log() <<
"OpenFOAM === got num node: " << coordSerial->Size() << std::endl;
677 cell2nodeSerial->Resize(ofConverter.
cell2node.size());
678 cellElemInfoSerial->Resize(ofConverter.
cell2node.size());
679 for (
index iC = 0; iC < cell2nodeSerial->Size(); iC++)
681 cell2nodeSerial->ResizeRow(iC, ofConverter.
cell2node[iC].size());
682 for (
size_t iN = 0; iN < ofConverter.
cell2node[iC].size(); iN++)
683 (*cell2nodeSerial)[iC][iN] = ofConverter.
cell2node[iC][iN];
684 cellElemInfoSerial->operator()(iC, 0) = ofConverter.
cellElemInfo.at(iC);
687 log() <<
"OpenFOAM === got num cell: " << cell2nodeSerial->Size() << std::endl;
690 bnd2nodeSerial->Resize(
nBnd);
691 bndElemInfoSerial->Resize(
nBnd);
692 bnd2cellSerial->Resize(
nBnd);
693 for (
index iBnd = 0; iBnd <
nBnd; iBnd++)
696 bnd2nodeSerial->ResizeRow(iBnd, ofReader.
faces[iFaceOF].size());
697 for (
size_t ib2c = 0; ib2c < ofReader.
faces[iFaceOF].size(); ib2c++)
698 (*bnd2nodeSerial)[iBnd][ib2c] = ofReader.
faces[iFaceOF][ib2c];
699 bnd2cellSerial->operator()(iBnd, 0) = ofReader.
owner.at(iFaceOF);
701 bndElemInfoSerial->operator()(iBnd, 0) = ofConverter.
faceElemInfo.at(iFaceOF);
704 log() <<
"nameMapping size: " << nameMapping.size() << std::endl;
708 auto boconame = bc.first;
709 if (nameMapping.count(boconame))
710 boconame = nameMapping.at(boconame);
711 t_index BCCode = FBCName_2_ID(std::string(boconame));
712 if (BCCode == BC_ID_NULL)
714 DNDS_assert_info(
false, fmt::format(
"BC NAME [{}] NOT FOUND IN DATABASE", boconame));
716 for (
index iBndC = 0; iBndC < bc.second.nFaces; iBndC++)
717 bndElemInfoSerial->operator()(iBndC + bc.second.startFace - ofReader.
neighbour.size(), 0).zone = BCCode;
719 for (
index iBnd = 0; iBnd <
nBnd; iBnd++)
721 DNDS_assert(bndElemInfoSerial->operator()(iBnd, 0).zone != BC_ID_NULL);
724 log() <<
"OpenFOAM === got num bnd: " <<
nBnd << std::endl;
726 log() <<
"OpenFOAM === Serial Read Done" << std::endl;