30 #include <vtkAppendFilter.h> 32 #include <vtkCell3D.h> 33 #include <vtkDataSetTriangleFilter.h> 34 #include <vtkGeometryFilter.h> 35 #include <vtkPolyDataNormals.h> 36 #include <vtkUnstructuredGrid.h> 38 #include <boost/filesystem.hpp> 42 #include <unordered_map> 48 #include <vtkProperty.h> 49 #include <vtkRenderWindowInteractor.h> 50 #include <vtkRenderer.h> 51 #include <vtkSmartPointer.h> 56 #include <foamVtkVtuAdaptor.H> 58 #include <surfaceLambdaMuSmooth.H> 59 #include <splitMeshRegions.H> 60 #include <mergeMeshes.H> 61 #include <createPatch.H> 62 #include <surfaceSplitByTopology.H> 63 #include <foamToSurface.H> 88 const Foam::fileName surfFileName = (surfLMSmoothParams.slmssurfaceFile);
89 const Foam::fileName outFileName = (surfLMSmoothParams.slmsoutputFile);
90 const Foam::scalar lambda = (surfLMSmoothParams.lambda_);
91 const Foam::scalar mu = (surfLMSmoothParams.mu);
92 const Foam::label iters = (surfLMSmoothParams.slmsIterations);
93 const bool addFtrFl = (surfLMSmoothParams.addFeatureFile);
94 auto slmsObj = surfaceLambdaMuSmooth();
95 slmsObj.execute(surfFileName, outFileName, lambda, mu, iters, addFtrFl);
108 std::pair<std::vector<int>, std::vector<std::string>>
111 const bool useCellZones = (spltMshRegions.cellZones);
112 auto smrObj = splitMeshRegions();
113 return smrObj.execute(useCellZones);
121 auto mmObj = mergeMeshes();
124 std::vector<std::string> addCases;
131 addCases.push_back(mergeMeshesParams.addCase);
133 for (
int i = 2; i < (nDomains + 1); i++) {
134 if (i == dirStat) i++;
135 addCases.push_back(
"domain" + (std::to_string(i)));
137 addCases.push_back(mergeMeshesParams.addCase);
139 mmObj.execute(mergeMeshesParams.masterCasePath, mergeMeshesParams.addCasePath,
140 addCases, nDomains, dirStat);
151 auto cpObj = createPatch();
153 cpObj.execute(dirStat, createPatchParams.pathSurrounding,
cpDict_);
162 auto ftsObj = foamToSurface();
163 ftsObj.execute(foamToSurfaceParams.outSurfName);
174 Foam::fileName surfFileName(surfSplitParams.surfFile);
175 Foam::Info <<
"Reading surface from " << surfFileName << Foam::endl;
176 Foam::fileName outFileName(surfSplitParams.outSurfFile);
177 auto ssbtObj = surfaceSplitByTopology();
178 return ssbtObj.execute(surfFileName, outFileName);
192 std::string dir_path =
"./system/" + createPatchParams.
pathSurrounding;
195 boost::filesystem::path dir(dir_path);
197 boost::filesystem::create_directory(dir);
198 }
catch (boost::filesystem::filesystem_error &e) {
199 std::cerr <<
"Problem in creating system directory for the snappyHexMesh" 201 std::cerr << e.what() << std::endl;
207 std::string contText =
209 /*--------------------------------*- C++ -*----------------------------------*\n\ 211 | \\\\ / F ield | NEMoSys: snappyHexMesh interface |\n\ 212 | \\\\ / O peration | |\n\ 214 | \\\\/ M anipulation | |\n\ 215 \\*---------------------------------------------------------------------------*/\n\ 222 location \"system\";\n\ 223 object createPatchDict;\n\ 228 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
230 contText = contText +
"\n\npointSync true;\n";
231 contText = contText +
"\n\npatches\n";
232 contText = contText +
"(\n";
233 contText = contText +
"\t{\n";
235 contText +
"\t\tname " + (createPatchParams.surroundingName) +
";\n";
236 contText = contText +
"\n\t\tpatchInfo\n";
237 contText = contText +
"\t\t{\n";
239 contText +
"\t\t\ttype " + (createPatchParams.srrndngPatchType) +
";\n";
240 contText = contText +
"\t\t}\n";
241 contText = contText +
"\n\t\tconstructFrom patches;\n";
242 contText = contText +
"\n\t\tpatches (\"domain0_to_domain.*\");";
243 contText = contText +
"\n\t}\n";
244 contText = contText +
");\n";
246 contText = contText +
247 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " 251 std::ofstream contDict;
253 contDict.open(std::string(dir_path) +
"/createPatchDict");
254 contDict << contText;
259 Foam::dictionary tmptmpDuc =
260 new Foam::dictionary(Foam::IStringStream(contText)(),
true);
261 cpDict_ = std::unique_ptr<Foam::dictionary>(
262 new Foam::dictionary(
"createPatchDict"));
266 const char dir_path2[] =
"./system/domain2";
269 boost::filesystem::path dir2(dir_path2);
271 boost::filesystem::create_directory(dir2);
272 }
catch (boost::filesystem::filesystem_error &e) {
273 std::cerr <<
"Problem in creating system directory for createPatch" 275 std::cerr << e.what() << std::endl;
281 std::string contText2 =
283 /*--------------------------------*- C++ -*----------------------------------*\n\ 285 | \\\\ / F ield | NEMoSys: snappyHexMesh interface |\n\ 286 | \\\\ / O peration | |\n\ 288 | \\\\/ M anipulation | |\n\ 289 \\*---------------------------------------------------------------------------*/\n\ 296 location \"system\";\n\ 297 object createPatchDict;\n\ 300 contText2 = contText2 +
301 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " 304 contText2 = contText2 +
"\n\npointSync true;\n";
305 contText2 = contText2 +
"\n\npatches\n";
306 contText2 = contText2 +
"(\n";
307 contText2 = contText2 +
"\t{\n";
308 contText2 = contText2 +
"\t\tname " + (createPatchParams.packsName) +
";\n";
309 contText2 = contText2 +
"\n\t\tpatchInfo\n";
310 contText2 = contText2 +
"\t\t{\n";
312 contText2 +
"\t\t\ttype " + (createPatchParams.packsPatchType) +
";\n";
313 contText2 = contText2 +
"\t\t}\n";
314 contText2 = contText2 +
"\n\t\tconstructFrom patches;\n";
315 contText2 = contText2 +
"\n\t\tpatches (\"domain.*_to_domain0\");";
316 contText2 = contText2 +
"\n\t}\n";
317 contText2 = contText2 +
");\n";
319 contText2 = contText2 +
320 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " 324 std::ofstream contDict2;
326 contDict2.open(std::string(dir_path2) +
"/createPatchDict");
327 contDict2 << contText2;
333 Foam::dictionary tmptmpDuc2 =
334 new Foam::dictionary(Foam::IStringStream(contText2)(),
true);
335 cpDict_ = std::unique_ptr<Foam::dictionary>(
336 new Foam::dictionary(
"createPatchDict"));
339 const char dir_path2[] =
"./system/domain1";
341 boost::filesystem::path dir2(dir_path2);
343 boost::filesystem::create_directory(dir2);
344 }
catch (boost::filesystem::filesystem_error &e) {
345 std::cerr <<
"Problem in creating system directory for createPatch" 347 std::cerr << e.what() << std::endl;
353 std::string contText2 =
355 /*--------------------------------*- C++ -*----------------------------------*\n\ 357 | \\\\ / F ield | NEMoSys: snappyHexMesh interface |\n\ 358 | \\\\ / O peration | |\n\ 360 | \\\\/ M anipulation | |\n\ 361 \\*---------------------------------------------------------------------------*/\n\ 368 location \"system\";\n\ 369 object createPatchDict;\n\ 372 contText2 = contText2 +
373 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " 376 contText2 = contText2 +
"\n\npointSync true;\n";
377 contText2 = contText2 +
"\n\npatches\n";
378 contText2 = contText2 +
"(\n";
379 contText2 = contText2 +
"\t{\n";
380 contText2 = contText2 +
"\t\tname " + (createPatchParams.packsName) +
";\n";
381 contText2 = contText2 +
"\n\t\tpatchInfo\n";
382 contText2 = contText2 +
"\t\t{\n";
384 contText2 +
"\t\t\ttype " + (createPatchParams.packsPatchType) +
";\n";
385 contText2 = contText2 +
"\t\t}\n";
386 contText2 = contText2 +
"\n\t\tconstructFrom patches;\n";
387 contText2 = contText2 +
"\n\t\tpatches (\"domain.*_to_domain0\");";
388 contText2 = contText2 +
"\n\t}\n";
389 contText2 = contText2 +
");\n";
391 contText2 = contText2 +
392 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " 396 std::ofstream contDict2;
398 contDict2.open(std::string(dir_path2) +
"/createPatchDict");
399 contDict2 << contText2;
404 Foam::dictionary tmptmpDuc2 =
405 new Foam::dictionary(Foam::IStringStream(contText2)(),
true);
407 cpDict_ = std::unique_ptr<Foam::dictionary>(
408 new Foam::dictionary(
"createPatchDict"));
415 const std::string &outName) {
416 bool writeDicts =
true;
417 std::unique_ptr<getDicts> initFoam;
418 initFoam = std::unique_ptr<getDicts>(
new getDicts());
419 auto controlDict_ = initFoam->createControlDict(writeDicts);
421 Foam::Time runTime(controlDict_.get(),
".",
".");
423 auto _fmeshSurr = std::unique_ptr<NEM::MSH::foamGeoMesh>(
426 auto _fmeshPacks = std::unique_ptr<NEM::MSH::foamGeoMesh>(
430 vtkSmartPointer<vtkUnstructuredGrid> dataSetSurr =
433 vtkSmartPointer<vtkUnstructuredGrid> surrTmp =
435 auto objVfoamSurr = Foam::vtk::vtuAdaptor();
436 surrTmp = objVfoamSurr.internal(_fmeshSurr->getFoamMesh());
438 int impPts = (int)(surrTmp->GetNumberOfPoints());
440 vtkSmartPointer<vtkUnstructuredGrid> pckTmp =
442 auto objVfoamPck = Foam::vtk::vtuAdaptor();
443 pckTmp = objVfoamPck.internal(_fmeshPacks->
getFoamMesh());
446 vtkSmartPointer<vtkAppendFilter> appendFilter =
448 appendFilter->AddInputData(surrTmp);
449 appendFilter->AddInputData(pckTmp);
450 appendFilter->MergePointsOn();
451 appendFilter->Update();
452 dataSetSurr = appendFilter->GetOutput();
454 int numPoints = (int)(dataSetSurr->GetNumberOfPoints());
457 ANNpointArray pntCrd;
458 pntCrd = annAllocPts(numPoints, nDim);
459 for (
int iPnt = 0; iPnt < numPoints; iPnt++) {
460 std::vector<double> getPt = std::vector<double>(3);
461 dataSetSurr->GetPoint(iPnt, &getPt[0]);
462 pntCrd[iPnt][0] = getPt[0];
463 pntCrd[iPnt][1] = getPt[1];
464 pntCrd[iPnt][2] = getPt[2];
467 ANNkd_tree *kdTree =
new ANNkd_tree(pntCrd, numPoints, nDim);
471 std::map<int, int> dupNdeMap;
474 ANNidxArray nnIdx =
new ANNidx[nNib];
475 ANNdistArray dists =
new ANNdist[nNib];
476 qryPnt = annAllocPt(nDim);
478 for (
int iNde = 0; iNde < impPts; iNde++) {
479 std::vector<double> getPt = std::vector<double>(3);
480 dataSetSurr->GetPoint(iNde, &getPt[0]);
481 qryPnt[0] = getPt[0];
482 qryPnt[1] = getPt[1];
483 qryPnt[2] = getPt[2];
484 kdTree->annkFRSearch(qryPnt, rad, nNib, nnIdx, dists, 0);
485 if (dists[1] <= tol) {
486 if ((nnIdx[1]) >= impPts)
487 dupNdeMap[nnIdx[0]] = nnIdx[1];
489 dupNdeMap[nnIdx[1]] = nnIdx[0];
493 int numDupPnts = (int)dupNdeMap.size();
494 std::cout <<
"Found " << numDupPnts <<
" duplicate nodes.\n";
497 std::map<int, int>::iterator it = dupNdeMap.begin();
498 std::vector<int> cellID;
499 for (
int i = 0; i < (int)(dupNdeMap.size()); i++) {
504 dataSetSurr->GetPointCells(it->second, cells);
505 nCells = (int)cells->GetNumberOfIds();
507 for (cellNum = 0; cellNum < nCells; cellNum++) {
508 cellID.push_back((
int)(cells->GetId(cellNum)));
513 sort(cellID.begin(), cellID.end());
514 cellID.erase(unique(cellID.begin(), cellID.end()), cellID.end());
516 int know = (int)cellID.size();
521 std::vector<int> newCellIds;
522 std::vector<int> debugCellIds;
524 for (
int i = 0; i < know; i++) {
526 std::vector<int> ptIdzz(8);
529 cell = dataSetSurr->GetCell(cellID[i]);
531 vtkIdList *pts = cell->GetPointIds();
533 for (
int j = 0; j < 8; j++) { ptIdzz[j] = (int)(pts->GetId(j)); }
536 std::map<int, int>::iterator it2 = dupNdeMap.begin();
537 while (it2 != dupNdeMap.end()) {
538 for (
int k = 0; k < 8; k++) {
539 if ((it2->second) == ptIdzz[k]) {
549 newCellIds.push_back(cellID[i]);
551 debugCellIds.push_back(cellID[i]);
555 int size2 = (int)newCellIds.size();
558 std::vector<int> globalPtIds;
559 std::vector<int> surroundingArray;
560 std::vector<int> packArray;
561 for (
int i = 0; i < size2; i++) {
563 cell = dataSetSurr->GetCell(newCellIds[i]);
564 vtkIdList *pts = cell->GetPointIds();
566 for (
int j = 0; j < 6; j++) {
568 int *ptFaces =
nullptr;
569 vtkCell3D *cell3d =
static_cast<vtkCell3D *
>(cell);
570 cell3d->GetFacePoints(j, ptFaces);
571 std::vector<int> keysDupMap = std::vector<int>(4);
572 std::map<int, int>::iterator it3 = dupNdeMap.begin();
573 while (it3 != dupNdeMap.end()) {
574 for (
int h = 0; h < 4; h++) {
575 if ((it3->second) == (pts->GetId(ptFaces[h]))) {
577 keysDupMap[h] = it3->first;
587 for (
int k = 0; k < 4; k++) { globalPtIds.push_back(keysDupMap[k]); }
592 std::map<int, int>::iterator it5;
595 std::unordered_multimap<int, int> cohesiveMap;
597 for (
int i = 0; i < (int)globalPtIds.size(); i++) {
598 it5 = dupNdeMap.find(globalPtIds[i]);
600 if (it5 == dupNdeMap.end()) {
603 surroundingArray.push_back(it5->first);
604 packArray.push_back(it5->second);
609 int newCells = (int)(packArray.size() / 4);
610 int startNum = (int)(dataSetSurr->GetNumberOfCells());
614 std::vector<int> pntCohesiveIds;
615 int nCelCohesivePnts;
616 for (
int icl = 0; icl < newCells; icl++) {
617 nCelCohesivePnts = 4;
618 pntCohesiveIds.resize((nCelCohesivePnts * 2), -1);
619 for (
int ip = 0; ip < nCelCohesivePnts; ip++) {
620 pntCohesiveIds[ip] = packArray[it7];
621 pntCohesiveIds[ip + 4] = surroundingArray[it7];
625 vtkCellIds->SetNumberOfIds(pntCohesiveIds.size());
626 for (
auto pit = pntCohesiveIds.begin(); pit != pntCohesiveIds.end(); pit++)
627 vtkCellIds->SetId(pit - pntCohesiveIds.begin(), *pit);
628 dataSetSurr->InsertNextCell(12, vtkCellIds);
631 int endNum = (int)(dataSetSurr->GetNumberOfCells());
635 std::vector<int> cohCellIds;
636 for (
int i = startNum; i < endNum; i++) { cohCellIds.push_back(i); }
638 int size3 = (int)cohCellIds.size();
640 vtkSmartPointer<vtkUnstructuredGrid> visDataSet =
643 std::vector<int> ptIdzz2;
644 for (
int i = 0; i < size3; i++) {
647 cell = dataSetSurr->GetCell(cohCellIds[i]);
649 vtkIdList *pts = cell->GetPointIds();
651 for (
int j = 0; j < 8; j++) { ptIdzz2.push_back((
int)(pts->GetId(j))); }
658 for (
int i = 0; i < (size3 * 8); i++) {
659 std::vector<double> getPt = std::vector<double>(3);
660 dataSetSurr->GetPoint(ptIdzz2[i], &getPt[0]);
661 pointsViz->InsertNextPoint(getPt[0], getPt[1], getPt[2]);
664 visDataSet->SetPoints(pointsViz);
666 for (
int i = 0; i < size3; i++) {
667 std::vector<int> ptnewIdz;
668 for (
int j = 0; j < 8; j++) {
669 ptnewIdz.push_back(lvar);
673 vtkCellIds->SetNumberOfIds(ptnewIdz.size());
674 for (
auto pit = ptnewIdz.begin(); pit != ptnewIdz.end(); pit++)
675 vtkCellIds->SetId(pit - ptnewIdz.begin(), *pit);
676 visDataSet->InsertNextCell(12, vtkCellIds);
679 auto vm = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
681 vm->write(
"CohesiveElements.vtu");
684 auto vm2 = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
690 std::string ofnameTet =
"Tetra" + outName;
693 vtkSmartPointer<vtkDataSetTriangleFilter> triFilter =
695 triFilter->SetInputData(dataSetSurr);
698 auto newData_tet = triFilter->GetOutput();
700 auto vm3 = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
702 vm3->write(ofnameTet);
708 double &tol,
const std::string &outName,
double &thickness) {
710 bool writeDicts =
true;
711 std::unique_ptr<getDicts> initFoam;
712 initFoam = std::unique_ptr<getDicts>(
new getDicts());
713 auto controlDict_ = initFoam->createControlDict(writeDicts);
715 Foam::Time runTime(controlDict_.get(),
".",
".");
717 auto _fmeshSurr = std::unique_ptr<NEM::MSH::foamGeoMesh>(
720 auto _fmeshPacks = std::unique_ptr<NEM::MSH::foamGeoMesh>(
724 vtkSmartPointer<vtkUnstructuredGrid> dataSetSurr =
727 vtkSmartPointer<vtkUnstructuredGrid> surrTmp =
729 auto objVfoamSurr = Foam::vtk::vtuAdaptor();
730 surrTmp = objVfoamSurr.internal(_fmeshSurr->getFoamMesh());
732 int impPts = (surrTmp->GetNumberOfPoints());
734 vtkSmartPointer<vtkUnstructuredGrid> pckTmp =
736 auto objVfoamPck = Foam::vtk::vtuAdaptor();
737 pckTmp = objVfoamPck.internal(_fmeshPacks->
getFoamMesh());
740 vtkSmartPointer<vtkAppendFilter> appendFilter =
742 appendFilter->AddInputData(surrTmp);
743 appendFilter->AddInputData(surrTmp);
744 appendFilter->MergePointsOn();
745 appendFilter->Update();
746 dataSetSurr = appendFilter->GetOutput();
748 int numPoints = (int)(dataSetSurr->GetNumberOfPoints());
751 ANNpointArray pntCrd;
752 pntCrd = annAllocPts(numPoints, nDim);
753 for (
int iPnt = 0; iPnt < numPoints; iPnt++) {
754 std::vector<double> getPt = std::vector<double>(3);
755 dataSetSurr->GetPoint(iPnt, &getPt[0]);
756 pntCrd[iPnt][0] = getPt[0];
757 pntCrd[iPnt][1] = getPt[1];
758 pntCrd[iPnt][2] = getPt[2];
761 ANNkd_tree *kdTree =
new ANNkd_tree(pntCrd, numPoints, nDim);
765 std::map<int, int> dupNdeMap;
768 ANNidxArray nnIdx =
new ANNidx[nNib];
769 ANNdistArray dists =
new ANNdist[nNib];
770 qryPnt = annAllocPt(nDim);
772 for (
int iNde = 0; iNde < impPts; iNde++) {
773 std::vector<double> getPt = std::vector<double>(3);
774 dataSetSurr->GetPoint(iNde, &getPt[0]);
775 qryPnt[0] = getPt[0];
776 qryPnt[1] = getPt[1];
777 qryPnt[2] = getPt[2];
778 kdTree->annkFRSearch(qryPnt, rad, nNib, nnIdx, dists, 0);
779 if (dists[1] <= tol) {
780 if ((nnIdx[1]) >= impPts) {
781 dupNdeMap[nnIdx[0]] = nnIdx[1];
783 dupNdeMap[nnIdx[1]] = nnIdx[0];
788 int numDupPnts = (int)dupNdeMap.size();
789 std::cout <<
"Found " << numDupPnts <<
" duplicate nodes.\n";
792 std::map<int, int>::iterator it = dupNdeMap.begin();
793 std::vector<int> cellID;
794 for (
int i = 0; i < (int)(dupNdeMap.size()); i++) {
799 dataSetSurr->GetPointCells(it->second, cells);
800 nCells = (int)(cells->GetNumberOfIds());
802 for (cellNum = 0; cellNum < nCells; cellNum++) {
804 (
int)(cells->GetId(cellNum)));
809 sort(cellID.begin(), cellID.end());
810 cellID.erase(unique(cellID.begin(), cellID.end()), cellID.end());
812 int know = cellID.size();
815 std::vector<int> newCellIds;
816 std::vector<int> debugCellIds;
818 for (
int i = 0; i < know; i++) {
820 std::vector<int> ptIdzz(8);
823 cell = dataSetSurr->GetCell(cellID[i]);
825 vtkIdList *pts = cell->GetPointIds();
827 for (
int j = 0; j < 8; j++) { ptIdzz[j] = pts->GetId(j); }
830 std::map<int, int>::iterator it2 = dupNdeMap.begin();
831 while (it2 != dupNdeMap.end()) {
832 for (
int k = 0; k < 8; k++) {
833 if ((it2->second) == ptIdzz[k]) {
843 newCellIds.push_back(cellID[i]);
845 debugCellIds.push_back(cellID[i]);
849 int size2 = (int)(newCellIds.size());
852 std::vector<int> globalPtIds;
853 std::vector<int> surroundingArray;
854 std::vector<int> packArray;
855 for (
int i = 0; i < size2; i++) {
857 cell = dataSetSurr->GetCell(newCellIds[i]);
858 vtkIdList *pts = cell->GetPointIds();
860 for (
int j = 0; j < 6; j++) {
862 int *ptFaces =
nullptr;
863 vtkCell3D *cell3d =
static_cast<vtkCell3D *
>(cell);
864 cell3d->GetFacePoints(j, ptFaces);
865 std::vector<int> keysDupMap = std::vector<int>(4);
866 std::map<int, int>::iterator it3 = dupNdeMap.begin();
867 while (it3 != dupNdeMap.end()) {
868 for (
int h = 0; h < 4; h++) {
869 if ((it3->second) == (pts->GetId(ptFaces[h]))) {
871 keysDupMap[h] = it3->first;
881 for (
int k = 0; k < 4; k++) { globalPtIds.push_back(keysDupMap[k]); }
886 std::map<int, int>::iterator it5;
889 std::unordered_multimap<int, int> cohesiveMap;
891 for (
int i = 0; i < (int)globalPtIds.size(); i++) {
892 it5 = dupNdeMap.find(globalPtIds[i]);
894 if (it5 == dupNdeMap.end()) {
897 surroundingArray.push_back(it5->first);
898 packArray.push_back(it5->second);
902 std::cout <<
"End of previous method" << std::endl;
905 vtkSmartPointer<vtkGeometryFilter> geometryFilter =
907 geometryFilter->SetInputData(dataSetSurr);
908 geometryFilter->Update();
911 polydata = geometryFilter->GetOutput();
913 vtkSmartPointer<vtkPolyDataNormals> polyDataNormal =
916 polyDataNormal->SetInputData(polydata);
919 polyDataNormal->ComputePointNormalsOn();
920 polyDataNormal->ComputeCellNormalsOff();
923 polyDataNormal->SetSplitting(0);
925 polyDataNormal->SetConsistency(1);
927 polyDataNormal->Update();
930 polydata = polyDataNormal->GetOutput();
933 vtkIdType numPointsNew = polydata->GetNumberOfPoints();
934 std::cout <<
"There are " << numPointsNew <<
" points." << std::endl;
936 vtkDataArray *normalsGeneric = polydata->GetPointData()->GetNormals();
939 std::cout <<
"There are " << normalsGeneric->GetNumberOfTuples()
940 <<
" normals in normalsGeneric" << std::endl;
945 for (
int i = 0; i < (int)surroundingArray.size(); i++) {
946 double normalOfPt[3];
947 normalsGeneric->GetTuple(surroundingArray[i], normalOfPt);
949 std::vector<double> getPt = std::vector<double>(3);
950 dataSetSurr->GetPoint(surroundingArray[i], &getPt[0]);
955 newCoords[0] = getPt[0] + 0.001 * normalOfPt[0];
956 newCoords[1] = getPt[1] + 0.001 * normalOfPt[1];
957 newCoords[2] = getPt[2] + 0.001 * normalOfPt[2];
959 dataSetSurr->GetPoints()->SetPoint(surroundingArray[i], newCoords);
963 for (
int i = 0; i < (int)packArray.size(); i++) {
964 double normalOfPt[3];
965 normalsGeneric->GetTuple(packArray[i], normalOfPt);
967 std::vector<double> getPt = std::vector<double>(3);
968 dataSetSurr->GetPoint(packArray[i], &getPt[0]);
971 newCoords[0] = (getPt[0] + 0.001 * normalOfPt[0]);
972 newCoords[1] = (getPt[1] + 0.001 * normalOfPt[1]);
973 newCoords[2] = (getPt[2] + 0.001 * normalOfPt[2]);
975 dataSetSurr->GetPoints()->SetPoint(packArray[i], newCoords);
979 int newCells = (int)(packArray.size() / 4);
980 int startNum = (int)(dataSetSurr->GetNumberOfCells());
984 std::vector<int> pntCohesiveIds;
985 int nCelCohesivePnts = 0;
986 for (
int icl = 0; icl < newCells; icl++) {
987 nCelCohesivePnts = 4;
988 pntCohesiveIds.resize((nCelCohesivePnts * 2), -1);
989 for (
int ip = 0; ip < nCelCohesivePnts; ip++) {
990 pntCohesiveIds[ip] = packArray[it7];
991 pntCohesiveIds[ip + 4] = surroundingArray[it7];
995 vtkCellIds->SetNumberOfIds(pntCohesiveIds.size());
996 for (
auto pit = pntCohesiveIds.begin(); pit != pntCohesiveIds.end(); pit++)
997 vtkCellIds->SetId(pit - pntCohesiveIds.begin(), *pit);
998 dataSetSurr->InsertNextCell(12, vtkCellIds);
1001 int endNum = dataSetSurr->GetNumberOfCells();
1005 std::vector<int> cohCellIds;
1006 for (
int i = startNum; i < endNum; i++) { cohCellIds.push_back(i); }
1008 int size3 = cohCellIds.size();
1010 vtkSmartPointer<vtkUnstructuredGrid> visDataSet =
1013 std::vector<int> ptIdzz2;
1014 for (
int i = 0; i < size3; i++) {
1016 cell = dataSetSurr->GetCell(cohCellIds[i]);
1018 vtkIdList *pts = cell->GetPointIds();
1020 for (
int j = 0; j < 8; j++) { ptIdzz2.push_back(pts->GetId(j)); }
1027 for (
int i = 0; i < (size3 * 8); i++) {
1028 std::vector<double> getPt = std::vector<double>(3);
1029 dataSetSurr->GetPoint(ptIdzz2[i], &getPt[0]);
1030 pointsViz->InsertNextPoint(getPt[0], getPt[1], getPt[2]);
1033 visDataSet->SetPoints(pointsViz);
1035 for (
int i = 0; i < size3; i++) {
1036 std::vector<int> ptnewIdz;
1037 for (
int j = 0; j < 8; j++) {
1038 ptnewIdz.push_back(lvar);
1042 vtkCellIds->SetNumberOfIds(ptnewIdz.size());
1043 for (
auto pit = ptnewIdz.begin(); pit != ptnewIdz.end(); pit++)
1044 vtkCellIds->SetId(pit - ptnewIdz.begin(), *pit);
1045 visDataSet->InsertNextCell(12, vtkCellIds);
1048 auto vm = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
1050 vm->write(
"ArtificialElements.vtu");
1053 auto vm2 = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
1055 vm2->write(outName);
1059 std::string ofnameTet =
"Tetra" + outName;
1062 vtkSmartPointer<vtkDataSetTriangleFilter> triFilter =
1064 triFilter->SetInputData(dataSetSurr);
1065 triFilter->Update();
1067 auto newData_tet = triFilter->GetOutput();
1069 auto vm3 = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
1071 vm3->write(ofnameTet);
1077 std::string &patch2) {
1078 bool writeDicts =
false;
1079 std::unique_ptr<getDicts> initFoam;
1080 initFoam = std::unique_ptr<getDicts>(
new getDicts());
1081 auto controlDict_ = initFoam->createControlDict(writeDicts);
1083 Foam::fileName one =
".";
1084 Foam::fileName two =
".";
1085 Foam::Time runTime(controlDict_.get(), one, two);
1094 auto fm = std::unique_ptr<NEM::MSH::foamGeoMesh>(
1097 const auto &_fmeshPacks = fm->getFoamMesh();
1100 int patchIDIn = _fmeshPacks.boundaryMesh().findPatchID(patch1);
1101 int patchIDOut = _fmeshPacks.boundaryMesh().findPatchID(patch2);
1103 const Foam::polyPatch &InPolyPatch = _fmeshPacks.boundaryMesh()[patchIDIn];
1104 const Foam::polyPatch &OutPolyPatch = _fmeshPacks.boundaryMesh()[patchIDOut];
1107 Foam::labelList inPts(InPolyPatch.meshPoints());
1108 Foam::labelList outPts(OutPolyPatch.meshPoints());
1110 if (inPts.size() != outPts.size()) {
1111 std::cerr <<
"Selected boundaries are not periodic!" 1112 <<
"\nExiting!" << std::endl;
1116 Foam::pointField packsPF = _fmeshPacks.points();
1119 std::map<int, int> periodicMap;
1121 for (
int i = 0; i < inPts.size(); i++) { periodicMap[inPts[i]] = outPts[i]; }
1124 myfile.open(
"PeriodicMap.csv");
1125 for (
int i = 0; i < inPts.size(); i++) {
1126 myfile << inPts[i] <<
"," << outPts[i] << std::endl;
1134 vtkSmartPointer<vtkUnstructuredGrid> dataSetTest =
1138 for (
int i = 0; i < packsPF.size(); i++) {
1139 pointsMesh->InsertNextPoint(packsPF[i].x(), packsPF[i].y(), packsPF[i].z());
1142 dataSetTest->SetPoints(pointsMesh);
1144 forAll (_fmeshPacks.boundaryMesh()[patchIDIn], facei) {
1145 const Foam::label &faceID =
1146 _fmeshPacks.boundaryMesh()[patchIDIn].start() + facei;
1147 std::vector<int> pntIds;
1148 pntIds.resize(4, -1);
1150 forAll (_fmeshPacks.faces()[faceID], nodei) {
1151 const Foam::label &nodeID = _fmeshPacks.faces()[faceID][nodei];
1156 vtkCellIds->SetNumberOfIds(pntIds.size());
1157 for (
auto pit = pntIds.begin(); pit != pntIds.end(); pit++)
1158 vtkCellIds->SetId(pit - pntIds.begin(), *pit);
1159 dataSetTest->InsertNextCell(9, vtkCellIds);
1162 forAll (_fmeshPacks.boundaryMesh()[patchIDOut], facei) {
1163 const Foam::label &faceID =
1164 _fmeshPacks.boundaryMesh()[patchIDOut].start() + facei;
1165 std::vector<int> pntIds;
1166 pntIds.resize(4, -1);
1168 forAll (_fmeshPacks.faces()[faceID], nodei) {
1169 const Foam::label &nodeID = _fmeshPacks.faces()[faceID][nodei];
1174 vtkCellIds->SetNumberOfIds(pntIds.size());
1175 for (
auto pit = pntIds.begin(); pit != pntIds.end(); pit++)
1176 vtkCellIds->SetId(pit - pntIds.begin(), *pit);
1177 dataSetTest->InsertNextCell(9, vtkCellIds);
1180 auto vm = std::unique_ptr<NEM::MSH::vtkGeoMesh>(
1182 vm->write(
"PeriodicMesh.vtu");
SplitMeshRegions splitMeshRegParams
void createPtch(int dirStat)
createPtch utility creates user-defined patches in Foam mesh.
std::unique_ptr< Foam::dictionary > cpDict_
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
std::pair< std::vector< int >, std::vector< std::string > > splitMshRegions()
splitMshRegions walks through mesh using cell-face-cell walk and identifies different cellZones as di...
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
MeshManipulationFoamParams * _mshMnipPrms
MeshManipulationFoam object.
SurfaceLambdaMuSmooth surfLMSmoothParams
A concrete implementation of geoMeshBase representing a mesh in a vtkUnstructuredGrid.
void surfLambdaMuSmooth()
surfLambdaMuSmooth performs laplacian smoothing over surface and writes it into output surface file...
std::string pathSurrounding
Defines surrounding mesh path from main directory.
void mergeMesh(int dirStat, int nDomains)
mergeMesh method merges two fvMesh datasets into one fvMesh including the patches and domain informat...
MergeMeshes mergeMeshesParams
void foamToSurf()
foamToSurf utility reads Foam mesh, extracts its surface and writes into an STL file.
~MeshManipulationFoam()
Standard MeshManipulationFoam Destructor.
SurfaceSplitByManifold surfSplitParams
int surfSpltByTopology()
surfSpltByTopology utility takes a surface file as an input and automatically divides disconnected re...
const Foam::fvMesh & getFoamMesh() const
Copy the mesh.
FoamToSurface foamToSurfParams
std::vector< vtkIdType > points
points given by id in .inp file
void createPatchDict(const int &dirStat, const bool &write)
createPatchDict utility creates a dictionary needed for createPatch method.
void addArtificialThicknessElements(double &tol, const std::string &outName, double &thickness)
This method adds connectivity elements with finite thickness at shared interface between two conforma...
void addCohesiveElements(double tol, const std::string &outName)
addCohesiveElements method supports addition of zero-sized connectivity elements at conformal shared ...
void periodicMeshMapper(std::string &patch1, std::string &patch2)
periodicMeshMapper method generates map of nodes on periodic mesh interfaces at boundaries for FEM an...
CreatePatch createPatchParams