253 cell2nodeSerial = make_ssp<decltype(cell2nodeSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::cell2nodeSerial"},
mesh->getMPI());
254 bnd2nodeSerial = make_ssp<decltype(bnd2nodeSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2nodeSerial"},
mesh->getMPI());
255 coordSerial = make_ssp<decltype(coordSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::coordSerial"},
mesh->getMPI());
258 bnd2cellSerial = make_ssp<decltype(bnd2cellSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2cellSerial"},
mesh->getMPI());
261 bnd2bndOrigSerial = make_ssp<decltype(bnd2bndOrigSerial)::element_type>(
ObjName{
"ReadFromCGNSSerial::bnd2bndOrigSerial"},
mesh->getMPI());
267 if (cg_open(fName.c_str(), CG_MODE_READ, &cgns_file))
269 std::cerr << fmt::format(
"cgns file cannot open: [{}]", fName) << std::endl;
273 if (cg_nbases(cgns_file, &n_bases))
275 DNDS::log() <<
"CGNS === N bases: " << n_bases << std::endl;
278 std::vector<std::pair<int, int>> Base_Zone;
279 std::vector<std::string> BaseNames;
280 std::vector<std::string> ZoneNames;
282 std::vector<std::array<cgsize_t, 9>> ZoneSizes;
283 std::vector<tCoord> ZoneCoords;
284 std::vector<tAdj> ZoneElems;
285 std::vector<tElemInfoArray> ZoneElemInfos;
286 std::vector<std::vector<std::vector<cgsize_t>>> ZoneConnect;
287 std::vector<std::vector<std::vector<cgsize_t>>> ZoneConnectDonor;
288 std::vector<std::vector<int>> ZoneConnectTargetIZone;
291 for (
int iBase = 1; iBase <= n_bases; iBase++)
295 char basename[48]{0};
300 if (cg_base_read(cgns_file, iBase, basename, &celldim, &physdim))
303 if (cg_nzones(cgns_file, iBase, &nzones))
305 for (
int iZone = 1; iZone <= nzones; iZone++)
307 char zonename[48]{0};
308 std::array<cgsize_t, 9> size{0, 0, 0, 0, 0, 0, 0, 0, 0};
309 if (cg_zone_read(cgns_file, iBase, iZone, zonename, size.data()))
312 if (cg_zone_type(cgns_file, iBase, iZone, &zoneType))
315 Base_Zone.emplace_back(std::make_pair(iBase, iZone));
316 BaseNames.emplace_back(basename);
317 ZoneNames.emplace_back(zonename);
338 ZoneCoords.emplace_back(std::make_shared<
decltype(ZoneCoords)::value_type::element_type>());
339 ZoneCoords.back()->Resize(nNodes);
340 std::vector<double> coordsRead(nNodes);
341 cgsize_t RMin[3]{1, 0, 0};
342 cgsize_t RMax[3]{nNodes, 0, 0};
344 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateX", RealDouble, RMin, RMax, coordsRead.data()));
346 ZoneCoords.back()->operator[](i)[0] = coordsRead.at(i);
348 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateY", RealDouble, RMin, RMax, coordsRead.data()));
350 ZoneCoords.back()->operator[](i)[1] = coordsRead.at(i);
354 DNDS_CGNS_CALL_EXIT(cg_coord_read(cgns_file, iBase, iZone,
"CoordinateZ", RealDouble, RMin, RMax, coordsRead.data()));
357 for (
auto &i : coordsRead)
360 ZoneCoords.back()->operator[](i)[2] = coordsRead.at(i);
362 DNDS::log() <<
"CGNS === Zone " << iZone <<
" Coords Reading Done" << std::endl;
376 [[maybe_unused]] cgsize_t cstart = 0;
377 [[maybe_unused]] cgsize_t cend = 0;
380 for (
int iSection = 1; iSection <= nSections; iSection++)
382 char sectionName[48];
386 int nBnd{0}, parentFlag{0};
387 DNDS_CGNS_CALL_EXIT(cg_section_read(cgns_file, iBase, iZone, iSection, sectionName, &etype, &start, &end, &nBnd, &parentFlag));
393 maxend = std::max(end, maxend);
395 ZoneElems.emplace_back(std::make_shared<
decltype(ZoneElems)::value_type::element_type>());
396 ZoneElems.back()->Resize(maxend);
397 ZoneElemInfos.emplace_back(std::make_shared<
decltype(ZoneElemInfos)::value_type::element_type>());
398 ZoneElemInfos.back()->Resize(maxend);
400 for (
int iSection = 1; iSection <= nSections; iSection++)
402 char sectionName[48];
406 int nBnd{0}, parentFlag{0};
407 DNDS_CGNS_CALL_EXIT(cg_section_read(cgns_file, iBase, iZone, iSection, sectionName, &etype, &start, &end, &nBnd, &parentFlag));
408 cgsize_t elemDataSize{0};
410 std::vector<cgsize_t> elemsRead(elemDataSize);
412 int nElemSec = end - start + 1;
415 std::vector<cgsize_t> elemStarts(nElemSec + 1);
416 DNDS_CGNS_CALL_EXIT(cg_poly_elements_read(cgns_file, iBase, iZone, iSection, elemsRead.data(), elemStarts.data(), NULL));
417 for (cgsize_t i = 0; i < nElemSec; i++)
419 auto c_etype =
static_cast<ElementType_t
>(elemsRead.at(elemStarts[i]));
422 DNDS::log() <<
"Error ETYPE " << std::to_string(c_etype) << std::endl;
427 "Element Node Number Mismatch!");
430 ZoneElems.back()->operator()(start - 1 + i, iNode) =
431 elemsRead.at(elemStarts[i] + 1 + iNode) - 1;
432 ZoneElemInfos.back()->operator()(start - 1 + i, 0).setElemType(ct);
433 ZoneElemInfos.back()->operator()(start - 1 + i, 0).zone = Geom::BC_ID_INTERNAL;
440 DNDS_CGNS_CALL_EXIT(cg_elements_read(cgns_file, iBase, iZone, iSection, elemsRead.data(), NULL));
442 for (cgsize_t i = 0; i < nElemSec; i++)
447 ZoneElems.back()->operator()(start - 1 + i, iNode) =
449 ZoneElemInfos.back()->operator()(start - 1 + i, 0).setElemType(ct);
450 ZoneElemInfos.back()->operator()(start - 1 + i, 0).zone = Geom::BC_ID_INTERNAL;
455 DNDS::log() <<
"Error ETYPE " << std::to_string(etype) << std::endl;
459 DNDS::log() <<
"CGNS === Zone " << iZone <<
" Elems Reading Done" << std::endl;
466 for (
int iBC = 1; iBC <= nBC; iBC++)
469 PointSetType_t pType;
470 cgsize_t nPts, normalListSize;
473 DataType_t normalDataType;
476 DNDS_CGNS_CALL_EXIT(cg_boco_info(cgns_file, iBase, iZone, iBC, boconame, &bcType, &pType, &nPts, NormalIndex, &normalListSize, &normalDataType, &nDataset));
478 DNDS_assert_info(pType == PointRange || pType == PointList,
"Only PointRange / PointList supported in BC!");
483 std::vector<cgsize_t> pts(nPts);
484 std::vector<double> normalBuf(normalListSize);
485 DNDS_CGNS_CALL_EXIT(cg_boco_read(cgns_file, iBase, iZone, iBC, pts.data(), normalBuf.data()));
486 DNDS_assert(pts[0] >= 1 && pts[1] <= ZoneElems.back()->Size());
488 t_index BCCode = FBCName_2_ID(std::string(boconame));
489 if (BCCode == BC_ID_NULL)
491 DNDS_assert_info(
false, fmt::format(
"BC NAME [{}] NOT FOUND IN DATABASE", boconame));
493 if (pType == PointRange)
496 ZoneElemInfos.back()->operator()(i, 0).zone = BCCode;
498 else if (pType == PointList)
501 ZoneElemInfos.back()->operator()(i - 1, 0).zone = BCCode;
507 DNDS::log() <<
"CGNS === Zone " << iZone <<
" BCs Reading Done" << std::endl;
515 for (
int iBase = 1; iBase <= n_bases; iBase++)
519 char basename[48]{0};
524 if (cg_base_read(cgns_file, iBase, basename, &celldim, &physdim))
527 if (cg_nzones(cgns_file, iBase, &nzones))
529 for (
int iZone = 1; iZone <= nzones; iZone++)
531 char zonename[48]{0};
532 std::array<cgsize_t, 9> size{0, 0, 0, 0, 0, 0, 0, 0, 0};
533 if (cg_zone_read(cgns_file, iBase, iZone, zonename, size.data()))
536 if (cg_zone_type(cgns_file, iBase, iZone, &zoneType))
546 ZoneConnect.emplace_back();
547 ZoneConnectDonor.emplace_back();
548 ZoneConnectTargetIZone.emplace_back();
551 for (
int iConn = 1; iConn <= nConns; iConn++)
553 char connName[48], donorName[48];
555 GridConnectivityType_t connType;
556 PointSetType_t ptType, ptType_donor;
557 cgsize_t npts, npts_donor;
561 DNDS_CGNS_CALL_EXIT(cg_conn_info(cgns_file, iBase, iZone, iConn, connName, &gLoc, &connType, &ptType, &npts,
562 donorName, &donorZT, &ptType_donor, &donorDT, &npts_donor));
564 DNDS_assert_info(connType == Abutting1to1,
"Only support Abutting1to1 in connection!");
565 DNDS_assert_info(ptType == PointList,
"Only Supports PointList in connection!");
566 DNDS_assert_info(ptType_donor == PointListDonor,
"Only Supports PointListDonor in connection!");
567 DNDS_assert_info(donorZT == Unstructured,
"Only Supports Unstructured in connection!");
569 DNDS_assert_info(npts_donor == npts,
"Only Supports npts_donor == npts in connection!");
572 ZoneConnectDonor.back().emplace_back(npts);
573 ZoneConnect.back().emplace_back(npts);
574 DNDS_CGNS_CALL_EXIT(cg_conn_read(cgns_file, iBase, iZone, iConn, ZoneConnect.back().back().data(), donorDT, ZoneConnectDonor.back().back().data()));
576 for (
size_t iGZ = 0; iGZ < ZoneNames.size(); iGZ++)
578 if (Base_Zone.at(iGZ).first == iBase)
580 if (ZoneNames.at(iGZ) == donorName)
587 ZoneConnectTargetIZone.back().push_back(iGZFound);
588 DNDS::log() <<
"CGNS === Connection at Zone-Zone: " << iZone <<
" - " << iGZFound + 1 << std::endl;
598 auto [NodeOld2New, ZoneNodeStarts] = AssembleZoneNodes(
599 ZoneCoords, ZoneConnect, ZoneConnectDonor, ZoneConnectTargetIZone,
600 coordSerial, mesh->dim);
603 SeparateVolumeAndBoundaryElements(
604 ZoneElems, ZoneElemInfos, NodeOld2New, ZoneNodeStarts,
605 cell2nodeSerial, cellElemInfoSerial, cell2cellOrigSerial,
606 bnd2nodeSerial, bndElemInfoSerial, bnd2bndOrigSerial,
607 node2nodeOrigSerial, coordSerial, mesh->dim);
613 bnd2cellSerial, bnd2nodeSerial, cell2nodeSerial,
614 cellElemInfoSerial, bndElemInfoSerial, coordSerial);
617 for (
DNDS::index iCell = 0; iCell < cell2cellOrigSerial->Size(); iCell++)
618 cell2cellOrigSerial->operator()(iCell, 0) = iCell;
619 for (
DNDS::index iNode = 0; iNode < node2nodeOrigSerial->Size(); iNode++)
620 node2nodeOrigSerial->operator()(iNode, 0) = iNode;
621 for (
DNDS::index iBnd = 0; iBnd < bnd2bndOrigSerial->Size(); iBnd++)
622 bnd2bndOrigSerial->operator()(iBnd, 0) = iBnd;
626 log() <<
"CGNS === Serial Read Done" << std::endl;
630 void UnstructuredMeshSerialRW::
631 ReadFromOpenFOAMAndConvertSerial(
const std::string &fName,
const std::map<std::string, std::string> &nameMapping,
const t_FBCName_2_ID &FBCName_2_ID)
634 this->dataIsSerialIn =
true;
636 cell2nodeSerial = make_ssp<decltype(cell2nodeSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::cell2nodeSerial"}, mesh->getMPI());
637 bnd2nodeSerial = make_ssp<decltype(bnd2nodeSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bnd2nodeSerial"}, mesh->getMPI());
638 coordSerial = make_ssp<decltype(coordSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::coordSerial"}, mesh->getMPI());
639 cellElemInfoSerial = make_ssp<decltype(cellElemInfoSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::cellElemInfoSerial"}, ElemInfo::CommType(), ElemInfo::CommMult(), mesh->getMPI());
640 bndElemInfoSerial = make_ssp<decltype(bndElemInfoSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bndElemInfoSerial"}, ElemInfo::CommType(), ElemInfo::CommMult(), mesh->getMPI());
641 bnd2cellSerial = make_ssp<decltype(bnd2cellSerial)::element_type>(
ObjName{
"ReadFromOpenFOAMAndConvertSerial::bnd2cellSerial"}, mesh->getMPI());
643 if (mRank != mesh->getMPI().rank)
646 std::filesystem::path ofFilePath(fName);
647 std::ifstream pointsIFS(ofFilePath /
"points");
648 std::ifstream facesIFS(ofFilePath /
"faces");
649 std::ifstream ownerIFS(ofFilePath /
"owner");
650 std::ifstream neighbourIFS(ofFilePath /
"neighbour");
651 std::ifstream boundaryIFS(ofFilePath /
"boundary");
671 coordSerial->Resize(ofReader.
points.size());
672 for (
index iN = 0; iN < coordSerial->Size(); iN++)
673 (*coordSerial)[iN] = ofReader.
points.at(iN);
674 log() <<
"OpenFOAM === got num node: " << coordSerial->Size() << std::endl;
676 cell2nodeSerial->Resize(ofConverter.
cell2node.size());
677 cellElemInfoSerial->Resize(ofConverter.
cell2node.size());
678 for (
index iC = 0; iC < cell2nodeSerial->Size(); iC++)
680 cell2nodeSerial->ResizeRow(iC, ofConverter.
cell2node[iC].size());
681 for (
size_t iN = 0; iN < ofConverter.
cell2node[iC].size(); iN++)
682 (*cell2nodeSerial)[iC][iN] = ofConverter.
cell2node[iC][iN];
683 cellElemInfoSerial->operator()(iC, 0) = ofConverter.
cellElemInfo.at(iC);
686 log() <<
"OpenFOAM === got num cell: " << cell2nodeSerial->Size() << std::endl;
689 bnd2nodeSerial->Resize(nBnd);
690 bndElemInfoSerial->Resize(nBnd);
691 bnd2cellSerial->Resize(nBnd);
692 for (
index iBnd = 0; iBnd < nBnd; iBnd++)
695 bnd2nodeSerial->ResizeRow(iBnd, ofReader.
faces[iFaceOF].size());
696 for (
size_t ib2c = 0; ib2c < ofReader.
faces[iFaceOF].size(); ib2c++)
697 (*bnd2nodeSerial)[iBnd][ib2c] = ofReader.
faces[iFaceOF][ib2c];
698 bnd2cellSerial->operator()(iBnd, 0) = ofReader.
owner.at(iFaceOF);
700 bndElemInfoSerial->operator()(iBnd, 0) = ofConverter.
faceElemInfo.at(iFaceOF);
703 log() <<
"nameMapping size: " << nameMapping.size() << std::endl;
707 auto boconame = bc.first;
708 if (nameMapping.count(boconame))
709 boconame = nameMapping.at(boconame);
710 t_index BCCode = FBCName_2_ID(std::string(boconame));
711 if (BCCode == BC_ID_NULL)
713 DNDS_assert_info(
false, fmt::format(
"BC NAME [{}] NOT FOUND IN DATABASE", boconame));
715 for (
index iBndC = 0; iBndC < bc.second.nFaces; iBndC++)
716 bndElemInfoSerial->operator()(iBndC + bc.second.startFace - ofReader.
neighbour.size(), 0).zone = BCCode;
718 for (
index iBnd = 0; iBnd < nBnd; iBnd++)
720 DNDS_assert(bndElemInfoSerial->operator()(iBnd, 0).zone != BC_ID_NULL);
723 log() <<
"OpenFOAM === got num bnd: " << nBnd << std::endl;
725 log() <<
"OpenFOAM === Serial Read Done" << std::endl;