28 int SAFE_ALGO_TestConn(
snake &snakein)
32 if (snakein.Check3D())
35 ret = snakein.snakeconn.TestConnectivityBiDir(__PRETTY_FUNCTION__);
42 void SnakeConnectivityUpdate_legacy(
snake &snakein, vector<int> &isImpact)
48 start_s = rsvs3d::TimeStamp(
"position: ", start_s);
50 snakein.SnaxImpactDetection(isImpact);
51 MergeAllContactVertices(snakein, isImpact);
52 snakein.PrepareForUse();
54 start_s = rsvs3d::TimeStamp(
"Merge: ", start_s);
56 CleanupSnakeConnec(snakein);
58 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
59 snakein.SnaxImpactDetection(isImpact);
60 SpawnArrivedSnaxels(snakein, isImpact);
62 start_s = rsvs3d::TimeStamp(
"Spawn: ", start_s);
64 snakein.SnaxImpactDetection(isImpact);
65 snakein.SnaxAlmostImpactDetection(isImpact, 0.01);
66 snakein.PrepareForUse();
67 SAFE_ALGO_TestConn(snakein);
68 MergeAllContactVertices(snakein, isImpact);
69 snakein.PrepareForUse();
70 SAFE_ALGO_TestConn(snakein);
72 start_s = rsvs3d::TimeStamp(
"Impact: ", start_s);
74 CleanupSnakeConnec(snakein);
76 SAFE_ALGO_TestConn(snakein);
77 snakein.OrientFaces();
79 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
82 void SnakeConnectivityUpdate_robust(
snake &snakein, vector<int> &isImpact)
93 double impactAlmostRange = 0.2;
102 SAFE_ALGO_TestConn(snakein);
103 snakein.SnaxImpactDetection(isImpact);
104 snakein.PrepareForUse();
105 start_s = rsvs3d::TimeStamp(
"Impact: ", start_f);
108 MergeAllContactVertices(snakein, isImpact);
109 snakein.PrepareForUse();
110 start_s = rsvs3d::TimeStamp(
"Merge: ", start_s);
113 CleanupSnakeConnec(snakein);
114 snakein.PrepareForUse();
115 SAFE_ALGO_TestConn(snakein);
116 snakein.OrientFaces();
117 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
123 SAFE_ALGO_TestConn(snakein);
124 snakein.SnaxImpactDetection(isImpact);
125 snakein.SnaxAlmostImpactDetection(isImpact, impactAlmostRange);
126 snakein.PrepareForUse();
127 start_s = rsvs3d::TimeStamp(
"Impact: ", start_s);
130 SAFE_ALGO_TestConn(snakein);
131 snakein.SnaxImpactDetection(isImpact);
132 SpawnArrivedSnaxels(snakein, isImpact);
133 start_s = rsvs3d::TimeStamp(
"Spawn: ", start_s);
136 SAFE_ALGO_TestConn(snakein);
137 snakein.SnaxImpactDetection(isImpact);
138 snakein.PrepareForUse();
139 start_s = rsvs3d::TimeStamp(
"Impact: ", start_s);
142 MergeAllContactVertices(snakein, isImpact);
143 snakein.PrepareForUse();
144 start_s = rsvs3d::TimeStamp(
"Merge: ", start_s);
147 CleanupSnakeConnec(snakein);
148 snakein.PrepareForUse();
149 SAFE_ALGO_TestConn(snakein);
150 snakein.OrientFaces();
151 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
153 rsvs3d::TimeStamp(
" - Connec Update: ", start_f);
156 void SnakeConnectivityUpdate(
snake &snakein, vector<int> &isImpact,
double impactAlmostRange)
166 int start_s, start_f;
173 SAFE_ALGO_TestConn(snakein);
174 snakein.SnaxImpactDetection(isImpact);
175 snakein.SnaxAlmostImpactDetection(isImpact, impactAlmostRange);
176 snakein.PrepareForUse();
177 start_s = rsvs3d::TimeStamp(
"Impact: ", start_f);
180 SAFE_ALGO_TestConn(snakein);
181 snakein.SnaxImpactDetection(isImpact);
182 snakein.snaxs.SetMaxIndex();
184 SpawnArrivedSnaxels(snakein, isImpact);
185 start_s = rsvs3d::TimeStamp(
"Spawn: ", start_s);
194 SAFE_ALGO_TestConn(snakein);
195 snakein.SnaxImpactDetection(isImpact);
196 snakein.PrepareForUse();
197 start_s = rsvs3d::TimeStamp(
"Impact: ", start_s);
200 MergeAllContactVertices(snakein, isImpact);
201 snakein.PrepareForUse();
202 start_s = rsvs3d::TimeStamp(
"Merge: ", start_s);
205 CleanupSnakeConnec(snakein);
207 snakein.PrepareForUse();
208 SAFE_ALGO_TestConn(snakein);
209 snakein.OrientFaces();
210 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
211 rsvs3d::TimeStamp(
" - Connec Update: ", start_f);
214 void SnakeSpawnStep(
snake &snakein,
int maxIndPreSpawn,
double stepLength, std::string smmoothMethod)
218 snakein.TakeSpawnStep(maxIndPreSpawn, stepLength);
219 snakein.PrepareForUse();
220 snakein.UpdateCoord();
221 snakein.OrientFaces();
222 snakein.TakeSmoothSpawnStep(maxIndPreSpawn, stepLength, smmoothMethod);
223 snakein.PrepareForUse();
224 snakein.UpdateCoord();
227 void SnakeConnectivityUpdate_2D(
snake &snakein, vector<int> &isImpact)
236 double impactAlmostRange = 0.2;
238 int start_s, start_f;
245 SAFE_ALGO_TestConn(snakein);
246 snakein.SnaxImpactDetection(isImpact);
247 snakein.SnaxAlmostImpactDetection(isImpact, impactAlmostRange);
248 snakein.PrepareForUse();
249 start_s = rsvs3d::TimeStamp(
"Impact: ", start_f);
252 SAFE_ALGO_TestConn(snakein);
253 snakein.SnaxImpactDetection(isImpact);
254 SpawnArrivedSnaxels(snakein, isImpact);
255 start_s = rsvs3d::TimeStamp(
"Spawn: ", start_s);
258 SAFE_ALGO_TestConn(snakein);
259 snakein.SnaxImpactDetection(isImpact);
260 snakein.PrepareForUse();
261 start_s = rsvs3d::TimeStamp(
"Impact: ", start_s);
264 MergeAllContactVertices(snakein, isImpact);
265 snakein.PrepareForUse();
266 start_s = rsvs3d::TimeStamp(
"Merge: ", start_s);
269 CleanupSnakeConnec(snakein);
270 snakein.PrepareForUse();
271 SAFE_ALGO_TestConn(snakein);
272 snakein.OrientFaces();
273 start_s = rsvs3d::TimeStamp(
"Clean: ", start_s);
275 rsvs3d::TimeStamp(
" - Connec Update: ", start_f);
278 double SnakePositionUpdate(
snake &rsvsSnake, std::vector<double> &dt,
double snaxtimestep,
double snaxdiststep)
280 rsvsSnake.CalculateTimeStep(dt, snaxtimestep, snaxdiststep);
281 rsvsSnake.UpdateDistance(dt, snaxdiststep,
true);
283 rsvsSnake.UpdateCoord();
284 rsvsSnake.PrepareForUse();
285 return *max_element(dt.begin(), dt.end());
305 origconf = RSVSobj.paramconf;
306 RSVSobj.paramconf.PrepareForUse();
307 RSVSobj.setVelocityEngine(origconf.snak.engine);
308 integrate::ApplyDevSettings(RSVSobj);
310 RSVSobj.rsvsSnake.clear();
311 RSVSobj.voluMesh.clear();
312 RSVSobj.snakeMesh.clear();
313 RSVSobj.rsvsTri.
clear();
315 integrate::prepare::Mesh(RSVSobj.paramconf.grid, RSVSobj.paramconf.files.ioin, RSVSobj.snakeMesh, RSVSobj.voluMesh);
316 integrate::prepare::Snake(RSVSobj.paramconf.snak, RSVSobj.paramconf.rsvs, RSVSobj.paramconf.files.ioin,
317 RSVSobj.snakeMesh, RSVSobj.voluMesh, RSVSobj.rsvsSnake);
318 integrate::prepare::Triangulation(RSVSobj.snakeMesh, RSVSobj.rsvsSnake, RSVSobj.rsvsTri);
319 integrate::prepare::Output(RSVSobj.paramconf, origconf, RSVSobj.outSnake, RSVSobj.outgradientsnake,
320 RSVSobj.outvectorsnake, RSVSobj.logFile, RSVSobj.coutFile, RSVSobj.cerrFile);
322 RSVSobj.voluMesh.SetEdgeLengths();
323 RSVSobj.voluMesh.PrepareForUse();
324 RSVSobj.snakeMesh.SetEdgeLengths();
325 RSVSobj.snakeMesh.PrepareForUse();
326 RSVSobj.rsvsSnake.PrepareForUse();
327 RSVSobj.rsvsTri.PrepareForUse();
332 auto &devset = RSVSobj.paramconf.dev;
334 RSVSobj.calcObj->setDevParameters(devset);
335 RSVSobj.rsvsSnake.SetSnaxDistanceLimit_conserveShape(devset.snaxDistanceLimit_conserveShape);
336 SetEnvironmentEpsilon(devset.rsvsepsilons);
346 if (gridconf.
activegrid.compare(
"voxel") == 0)
348 integrate::prepare::grid::Voxel(gridconf, snakeMesh, voluMesh);
350 else if (gridconf.
activegrid.compare(
"voronoi") == 0)
352 integrate::prepare::grid::Voronoi(gridconf, snakeMesh, voluMesh);
354 else if (gridconf.
activegrid.compare(
"load") == 0)
356 integrate::prepare::grid::Load(ioinconf, snakeMesh, voluMesh);
361 "Invalid parameter activegrid passed to "
366 snakeMesh.PrepareForUse();
371 voluMesh.PrepareForUse();
376 std::cout <<
"Meshes prepared..." << std::endl;
379 void integrate::prepare::grid::Voxel(
const param::grid &gridconf,
mesh &snakeMesh,
mesh &voluMesh)
383 vector<int> elmMapping, backgroundGrid;
385 backgroundGrid.reserve(
int(gridSize.size()));
386 for (
int i = 0; i < int(gridSize.size()); ++i)
388 backgroundGrid.push_back(gridSize[i]);
393 BuildBlockGrid(gridSize, snakeMesh);
394 snakeMesh.Scale(gridconf.
domain);
395 snakeMesh.PrepareForUse();
399 if (snakeMesh.WhatDim() == 3)
401 for (ii = 0; ii < snakeMesh.volus.size(); ++ii)
403 elmMapping.push_back(1);
406 else if (snakeMesh.WhatDim() == 2)
408 for (ii = 0; ii < snakeMesh.surfs.size(); ++ii)
410 elmMapping.push_back(1);
417 CartesianMapping(snakeMesh, elmMapping, backgroundGrid);
419 snakeMesh.AddParent(&voluMesh, elmMapping);
422 void integrate::prepare::grid::Voronoi(
const param::grid &gridconf,
mesh &snakeMesh,
mesh &voluMesh)
428 for (
int i = 0; i < 3; ++i)
436 void integrate::prepare::grid::Load(
const param::ioin &ioinconf,
mesh &snakeMesh,
mesh &voluMesh)
438 snakeMesh.read(ioinconf.snakemeshname.c_str());
439 voluMesh.read(ioinconf.volumeshname.c_str());
440 snakeMesh.PrepareForUse(
true);
441 voluMesh.PrepareForUse(
true);
447 snakeMesh.AddParent(&voluMesh, elmMapping);
449 snakeMesh.PrepareForUse();
450 voluMesh.PrepareForUse();
459 if (voluMesh.WhatDim() == 3)
461 nElms = voluMesh.volus.size();
464 voluMesh.LoadTargetFill(rsvsconf.
filefill.fill);
470 else if (rsvsconf.
cstfill.active)
472 for (
int i = 0; i < nElms; ++i)
474 voluMesh.volus[i].target = rsvsconf.
cstfill.fill;
478 else if (voluMesh.WhatDim() == 2)
480 nElms = voluMesh.surfs.size();
483 voluMesh.LoadTargetFill(rsvsconf.
filefill.fill);
489 else if (rsvsconf.
cstfill.active)
491 for (
int i = 0; i < nElms; ++i)
493 voluMesh.surfs[i].target = rsvsconf.
cstfill.fill;
497 voluMesh.PrepareForUse();
499 rsvsSnake.SetSnakeMesh(&snakeMesh);
500 if (!ioinconf.snakefile.empty())
502 rsvsSnake.read(ioinconf.snakefile.c_str());
503 rsvsSnake.SetSnakeMesh(&snakeMesh);
504 rsvsSnake.PrepareForUse(
true);
505 rsvsSnake.OrientFaces();
506 rsvsSnake.AssignInternalVerts();
512 rsvsSnake.PrepareForUse(
true);
513 rsvsSnake.OrientFaces();
518 rsvsTri.PrepareForUse();
519 TriangulateMesh(snakeMesh, rsvsTri);
520 rsvsTri.PrepareForUse();
521 TriangulateSnake(rsvsSnake, rsvsTri);
522 rsvsTri.PrepareForUse();
523 rsvsTri.CalcTriVertPos();
524 rsvsTri.PrepareForUse();
525 MaintainTriangulateSnake(rsvsTri);
526 rsvsTri.PrepareForUse();
531 std::ofstream &logFile, std::ofstream &coutFile, std::ofstream &cerrFile)
533 std::string outSnakeName;
535 if (paramconf.files.ioout.outdir.size() != 0)
537 filesystem::create_directories(paramconf.files.ioout.outdir);
540 outSnakeName = utils::OutputFileName(paramconf, constants::tecplotsnake,
".plt");
541 outSnake.OpenFile(outSnakeName.c_str());
543 if (integrate::constants::outputs::printGradientsSnake(paramconf.files.ioout.logginglvl))
545 outSnakeName = utils::OutputFileName(paramconf, constants::tecplotgradient,
".plt");
546 outgradientsnake.OpenFile(outSnakeName.c_str());
548 if (integrate::constants::outputs::printVectorSnake(paramconf.files.ioout.logginglvl))
550 outSnakeName = utils::OutputFileName(paramconf, constants::tecplotvectors,
".plt");
551 outvectorsnake.OpenFile(outSnakeName.c_str());
554 outSnakeName = utils::OutputFileName(paramconf,
"config_call_",
".json");
555 param::io::writeflat(outSnakeName, origconf);
557 outSnakeName = utils::OutputFileName(paramconf,
"config_active_",
".json");
558 param::io::writeflat(outSnakeName, paramconf);
561 outSnakeName = utils::OutputFileName(paramconf,
"convergence_",
".log");
562 logFile.open(outSnakeName);
563 logFile.precision(16);
564 logFile << std::scientific;
566 if (paramconf.files.ioout.redirectcout)
568 outSnakeName = utils::OutputFileName(paramconf,
"cout_",
".txt");
569 coutFile.open(outSnakeName);
570 std::cout.rdbuf(coutFile.rdbuf());
572 if (paramconf.files.ioout.redirectcerr)
574 outSnakeName = utils::OutputFileName(paramconf,
"cerr_",
".txt");
575 cerrFile.open(outSnakeName);
576 std::cerr.rdbuf(cerrFile.rdbuf());
578 integrate::utils::SpecialiseTemplateFiles(paramconf);
588 auto coutbuff = std::cout.rdbuf();
589 auto cerrbuff = std::cerr.rdbuf();
591 auto startTime = rsvs3d::TimeStamp(NULL, 0);
592 std::cout <<
"Start RSVS preparation" << std::endl;
593 integrate::Prepare(RSVSobj);
595 std::cout <<
"Preparation finished - start iteration" << std::endl;
596 auto iterateInfo = integrate::execute::RSVSiterate(RSVSobj);
598 std::cout <<
"Iteration finished - start PostProcessing" << std::endl;
599 integrate::execute::PostProcessing(RSVSobj, iterateInfo.timeT, iterateInfo.nVoluZone, iterateInfo.stepNum);
601 std::cout <<
"PostProcessing finished - start Exporting" << std::endl;
602 integrate::execute::Exporting(RSVSobj);
604 std::cout <<
"Exporting finished - close." << std::endl;
605 auto endTime = rsvs3d::TimeStamp(NULL, 0);
606 std::cout <<
"3D-RSVS completed in " << ceil(rsvs3d::Clock2ms(endTime - startTime) / 1000.0) <<
" seconds.";
608 std::cout.rdbuf(coutbuff);
609 std::cerr.rdbuf(cerrbuff);
614 auto coutbuff = std::cout.rdbuf();
615 auto cerrbuff = std::cerr.rdbuf();
617 auto startTime = rsvs3d::TimeStamp(NULL, 0);
618 std::cout <<
"Start RSVS preparation" << std::endl;
619 integrate::Prepare(RSVSobj);
622 RSVSobj.viewer.
show();
623 auto endTime = rsvs3d::TimeStamp(NULL, 0);
624 std::cout <<
"3D-RSVS completed in " << ceil(rsvs3d::Clock2ms(endTime - startTime) / 1000.0) <<
" seconds.";
626 std::cout.rdbuf(coutbuff);
627 std::cerr.rdbuf(cerrbuff);
633 vector<int> isImpact;
634 int stepNum, maxStep, nVoluZone;
637 auto start_s = clock();
639 RSVSobj.setVelocityEngine(RSVSobj.paramconf.snak.engine);
640 integrate::ApplyDevSettings(RSVSobj);
642 RSVSobj.voluMesh.PrepareForUse();
643 RSVSobj.outSnake.PrintMesh(RSVSobj.snakeMesh);
644 RSVSobj.outSnake.PrintMesh(RSVSobj.voluMesh);
645 nVoluZone = RSVSobj.outSnake.ZoneNum();
647 maxStep = RSVSobj.paramconf.snak.
maxsteps;
648 for (stepNum = 0; stepNum < maxStep; ++stepNum)
652 std::cout << std::endl <<
"Step " << std::setw(4) << stepNum <<
" ";
653 RSVSobj.calcObj->CalculateVelocities(RSVSobj.rsvsTri, RSVSobj.paramconf.rsvs.
solveralgorithm);
654 start_s = rsvs3d::TimeStamp(
" solve:", start_s);
656 CalculateNoNanSnakeVel(RSVSobj.rsvsSnake);
658 integrate::execute::Logging(RSVSobj, totT, nVoluZone, stepNum);
660 totT += SnakePositionUpdate(RSVSobj.rsvsSnake, dt, RSVSobj.paramconf.snak.
snaxtimestep,
663 int maxIndPreSpawn = RSVSobj.rsvsSnake.snaxs.GetMaxIndex();
666 SnakeSpawnStep(RSVSobj.rsvsSnake, maxIndPreSpawn, RSVSobj.paramconf.snak.
spawnposition,
667 RSVSobj.paramconf.dev.smoothstepmethod);
668 std::cout << RSVSobj.paramconf.dev.smoothstepmethod <<
" ; ";
669 start_s = rsvs3d::TimeStamp(
" spawn step:", start_s);
670 MaintainTriangulateSnake(RSVSobj.rsvsTri);
671 start_s = rsvs3d::TimeStamp(
" triangulate:", start_s);
673 std::cout << std::endl <<
"RSVS iteration finished" << std::endl;
678 bool integrate::constants::outputs::plotSnakeInPolyscope(
int lvl)
681 return integrate::constants::outputs::printBaseSnake(lvl) || integrate::constants::outputs::printFullSnake(lvl) ||
682 integrate::constants::outputs::printGradientsSnake(lvl) ||
683 integrate::constants::outputs::printVectorSnake(lvl);
689 void integrate::execute::Logging(
integrate::RSVSclass &RSVSobj,
double totT,
int nVoluZone,
int stepNum)
692 int logLvl = RSVSobj.paramconf.files.ioout.logginglvl;
700 RSVSobj.logFile <<
"> step" << stepNum <<
" :,";
701 RSVSobj.logFile << totT << endl;
702 integrate::execute::logging::Log(RSVSobj.logFile, RSVSobj.calcObj, RSVSobj.paramconf.files.ioout.logginglvl);
704 if (integrate::constants::outputs::printBaseSnake(logLvl))
706 integrate::execute::logging::Snake(RSVSobj.outSnake, RSVSobj.rsvsSnake, RSVSobj.voluMesh, totT, nVoluZone);
708 if (integrate::constants::outputs::printFullSnake(logLvl))
710 integrate::execute::logging::FullTecplot(RSVSobj.outSnake, RSVSobj.rsvsSnake, RSVSobj.rsvsTri, RSVSobj.voluMesh,
711 totT, nVoluZone, stepNum);
713 if (integrate::constants::outputs::printGradientsSnake(logLvl))
715 integrate::execute::logging::Gradients(RSVSobj.calcObj, RSVSobj.rsvsTri, RSVSobj.outgradientsnake, totT,
716 RSVSobj.paramconf.snak.engine);
718 if (integrate::constants::outputs::printVectorSnake(logLvl))
720 integrate::execute::logging::SnakeVectors(RSVSobj.outvectorsnake, RSVSobj.rsvsSnake, totT);
722 if (integrate::constants::outputs::plotSnakeInPolyscope(logLvl))
724 RSVSobj.viewer.
addSnake(integrate::constants::polyscopeSnakeName, RSVSobj.rsvsSnake);
725 if (integrate::constants::outputs::printVectorSnake(logLvl))
727 RSVSobj.viewer.
addSurfaceProperties(integrate::constants::polyscopeSnakeName, RSVSobj.rsvsSnake.snakeconn);
729 RSVSobj.viewer.
show(0);
733 void integrate::execute::PostProcessing(
integrate::RSVSclass &RSVSobj,
double totT,
int nVoluZone,
int stepNum)
735 int logLvl = RSVSobj.paramconf.files.ioout.outputlvl;
736 if (RSVSobj.paramconf.files.ioout.logginglvl != 5)
738 logLvl = max(RSVSobj.paramconf.files.ioout.outputlvl, RSVSobj.paramconf.files.ioout.logginglvl);
743 integrate::execute::postprocess::Snake(RSVSobj.rsvsSnake, RSVSobj.voluMesh, RSVSobj.paramconf);
748 RSVSobj.logFile <<
"> final step" << stepNum <<
" :,";
749 RSVSobj.logFile << totT << endl;
750 RSVSobj.logFile << totT << endl;
751 integrate::execute::postprocess::Log(RSVSobj.logFile, RSVSobj.calcObj,
752 RSVSobj.paramconf.files.ioout.logginglvl);
753 std::cout << std::endl;
755 if (integrate::constants::outputs::printBaseSnake(logLvl))
757 integrate::execute::logging::Snake(RSVSobj.outSnake, RSVSobj.rsvsSnake, RSVSobj.voluMesh, totT, nVoluZone);
759 if (integrate::constants::outputs::printFullSnake(logLvl))
761 integrate::execute::postprocess::FullTecplot(RSVSobj.outSnake, RSVSobj.rsvsSnake, RSVSobj.rsvsTri,
762 RSVSobj.voluMesh, totT, nVoluZone, stepNum);
764 if (integrate::constants::outputs::printGradientsSnake(logLvl))
766 integrate::execute::postprocess::Gradients(RSVSobj.calcObj, RSVSobj.rsvsTri, RSVSobj.outgradientsnake, totT,
767 RSVSobj.paramconf.snak.engine);
769 if (integrate::constants::outputs::printVectorSnake(logLvl))
771 integrate::execute::logging::SnakeVectors(RSVSobj.outvectorsnake, RSVSobj.rsvsSnake, totT);
773 if (integrate::constants::outputs::plotSnakeInPolyscope(logLvl))
775 RSVSobj.viewer.
show();
781 RSVSobj.rsvsSnake.Scale(RSVSobj.paramconf.grid.
physdomain);
782 auto ¶mconf = RSVSobj.paramconf;
783 auto outSnakeName = utils::OutputFileName(paramconf,
"rsvs3D_export_",
".plt");
786 outSnake.OpenFile(outSnakeName.c_str());
788 outSnake.PrintSnake(RSVSobj.rsvsSnake);
789 outSnake.PrintMesh(*RSVSobj.rsvsSnake.snakemesh());
790 outSnake.PrintMesh(RSVSobj.voluMesh);
792 for (
auto exportType : RSVSobj.paramconf.files.exportconfig)
794 if (exportType.first.compare(
"su2") == 0)
796 integrate::execute::exporting::SU2(exportType.second, RSVSobj.rsvsSnake, RSVSobj.paramconf);
798 else if (exportType.first.compare(
"") == 0 && exportType.second.compare(
"") == 0)
802 else if (exportType.first.compare(
"snake") == 0)
804 RSVSobj.rsvsSnake.Scale(RSVSobj.paramconf.grid.
domain);
805 auto fileToOpen = utils::OutputFileName(paramconf,
"SnakeConnExport_",
".msh");
806 auto tecFileToOpen = utils::OutputFileName(paramconf,
"SnakeSensitivity_",
".plt");
807 auto tecconfig = RSVSobj.paramconf.files.ioout.tecplot;
808 tecconfig.loglvlspecialisation.push_back({-1,
"RSVS_sensitivity"});
809 integrate::utils::SpecialiseTemplateFile(tecconfig, -1, paramconf.files.ioout,
"SnakeSensitivity_");
810 RSVSobj.rsvsSnake.snakeconn.write(fileToOpen.c_str());
812 tecsens.OpenFile(tecFileToOpen.c_str());
813 if (RSVSobj.paramconf.snak.engine ==
"rsvs")
818 RSVSobj.rsvsSnake.Scale(RSVSobj.paramconf.grid.
physdomain);
819 tecsens.PrintSnakeSensitivityVector(RSVSobj.rsvsTri, *calcObj);
825 "' is not known. Check <input file>.json for parameter : "
826 "/files/exportconfig/...")
831 RSVSobj.rsvsSnake.Scale(RSVSobj.paramconf.grid.
domain);
840 void integrate::execute::logging::Log(std::ofstream &logFile, RSVSCalculator &calcObj,
int loglvl)
844 calcObj->ConvergenceLog(logFile, loglvl);
847 void integrate::execute::logging::Snake(
tecplotfile &outSnake,
snake &rsvsSnake,
mesh &voluMesh,
double totT,
850 rsvsSnake.snakeconn.PrepareForUse();
852 outSnake.PrintVolumeDat(voluMesh, nVoluZone, 1, totT);
853 outSnake.PrintSnake(rsvsSnake, 2, totT, rsvs3d::constants::tecplot::polygon);
857 mesh &voluMesh,
double totT,
int nVoluZone,
int stepNum)
859 std::vector<int> vertList;
861 if (rsvsSnake.snaxs.size() > 0)
863 rsvsSnake.snakeconn.PrepareForUse();
864 outSnake.PrintSnake(rsvsSnake, 1, totT, rsvs3d::constants::tecplot::polygon);
865 outSnake.PrintTriangulation(rsvsTri, &triangulation::dynatri, 2, totT, rsvs3d::constants::tecplot::polygon);
866 outSnake.PrintTriangulation(rsvsTri, &triangulation::intertri, 3, totT, rsvs3d::constants::tecplot::line);
867 if (stepNum == 0 && rsvsTri.intertri.size() == 0)
869 outSnake.PrintTriangulation(rsvsTri, &triangulation::dynatri, 3, totT, rsvs3d::constants::tecplot::line,
870 {rsvsTri.dynatri(0)->index});
872 outSnake.PrintTriangulation(rsvsTri, &triangulation::trisurf, 4, totT, rsvs3d::constants::tecplot::line);
873 if (stepNum == 0 && rsvsTri.trisurf.size() == 0)
875 outSnake.PrintTriangulation(rsvsTri, &triangulation::dynatri, 4, totT, rsvs3d::constants::tecplot::line,
876 {rsvsTri.dynatri(0)->index});
878 if (
int(rsvsTri.acttri.size()) > 0)
880 outSnake.PrintTriangulation(rsvsTri, &triangulation::stattri, 5, totT, rsvs3d::constants::tecplot::line,
883 else if (stepNum == 0)
885 outSnake.PrintTriangulation(rsvsTri, &triangulation::dynatri, 5, totT, rsvs3d::constants::tecplot::line,
886 {rsvsTri.dynatri(0)->index});
890 for (jj = 0; jj < int(rsvsSnake.isMeshVertIn.size()); ++jj)
892 if (rsvsSnake.isMeshVertIn[jj])
894 vertList.push_back(rsvsSnake.snakemesh()->verts(jj)->index);
897 if (
int(rsvsSnake.isMeshVertIn.size()) == 0)
899 vertList.push_back(rsvsSnake.snakemesh()->verts(0)->index);
901 outSnake.PrintMesh(*(rsvsSnake.snakemesh()), 6, totT, rsvs3d::constants::tecplot::point, vertList);
902 outSnake.PrintVolumeDat(voluMesh, nVoluZone, 7, totT);
903 outSnake.PrintSnake(rsvsSnake, 8, totT);
907 void integrate::execute::logging::Gradients(
const RSVSCalculator &calcObj,
const triangulation &rsvsTri,
909 const std::string &snakingEngine)
911 if (snakingEngine ==
"rsvs")
914 outgradientsnake.PrintSnakeGradients(rsvsTri, *calcObjChild, 1, totT);
918 void integrate::execute::logging::SnakeVectors(
tecplotfile &outSnake,
snake &rsvsSnake,
double totT)
920 outSnake.PrintSnake(rsvs3d::constants::tecplot::snakedata::snaxel, rsvsSnake, 1, totT,
921 rsvs3d::constants::tecplot::polygon);
922 int zoneShare = outSnake.ZoneNum();
923 outSnake.PrintSnake(rsvs3d::constants::tecplot::snakedata::normal, rsvsSnake, 2, totT,
924 rsvs3d::constants::tecplot::polygon, zoneShare);
925 outSnake.PrintSnake(rsvs3d::constants::tecplot::snakedata::laplacian, rsvsSnake, 3, totT,
926 rsvs3d::constants::tecplot::polygon, zoneShare);
927 outSnake.PrintSnake(rsvs3d::constants::tecplot::snakedata::direction, rsvsSnake, 4, totT,
928 rsvs3d::constants::tecplot::polygon, zoneShare);
933 viewer.
addSnake(integrate::constants::polyscopeSnakeName, rsvsSnake);
942 void integrate::execute::postprocess::Log(std::ofstream &logFile, RSVSCalculator &calcObj,
int loglvl)
944 integrate::execute::logging::Log(logFile, calcObj, loglvl + 2);
949 std::string fileToOpen;
951 fileToOpen = utils::OutputFileName(paramconf,
"VoluMesh_",
".msh");
952 voluMesh.write(fileToOpen.c_str());
953 paramconf.files.ioin.volumeshname = fileToOpen;
955 fileToOpen = utils::OutputFileName(paramconf,
"SnakeMesh_",
".msh");
956 rsvsSnake.snakemesh()->write(fileToOpen.c_str());
957 paramconf.files.ioin.snakemeshname = fileToOpen;
959 fileToOpen = utils::OutputFileName(paramconf,
"SnakeConn_",
".msh");
960 rsvsSnake.snakeconn.write(fileToOpen.c_str());
962 fileToOpen = utils::OutputFileName(paramconf,
"Snake_",
".3snk");
963 rsvsSnake.write(fileToOpen.c_str());
964 paramconf.files.ioin.snakefile = fileToOpen;
966 paramconf.files.ioin.casename =
"restart_" + paramconf.files.ioout.pattern;
967 fileToOpen = utils::OutputFileName(paramconf,
"config_restart_",
".json");
968 param::io::writeflat(fileToOpen, paramconf);
972 mesh &voluMesh,
double totT,
int nVoluZone,
int stepNum)
974 integrate::execute::logging::FullTecplot(outSnake, rsvsSnake, rsvsTri, voluMesh, totT, nVoluZone, stepNum);
977 void integrate::execute::postprocess::Gradients(
const RSVSCalculator &calcObj,
const triangulation &rsvsTri,
979 const std::string &snakingEngine)
981 integrate::execute::logging::Gradients(calcObj, rsvsTri, outgradientsnake, totT, snakingEngine);
989 void integrate::execute::exporting::SU2(std::string su2ConfStr,
snake &rsvsSnake,
param::parameters ¶mconf)
991 std::string su2Path =
"", patternReplace =
"<pattern>";
992 std::string su2FileStr = su2ConfStr.substr(0, su2ConfStr.find(
","));
994 su2Path += paramconf.files.ioout.outdir +
"/";
996 auto patternIt = su2FileStr.find(patternReplace);
997 if (patternIt < su2FileStr.size())
999 su2Path += su2FileStr.substr(0, patternIt) + paramconf.files.ioout.pattern +
1000 su2FileStr.substr(patternIt + patternReplace.size());
1004 su2Path += su2FileStr;
1007 const filesystem::path pathout = su2Path;
1008 filesystem::create_directories(pathout.parent_path());
1010 tetgen::apiparam su2MeshParam(su2ConfStr.substr(su2ConfStr.find(
",") + 1));
1020 void integrate::utils::WriteModifiedTemplate(
const std::string &fileIn,
const std::string &fileOut,
1021 const std::string &oldLine,
const std::string newLine)
1023 ifstream in(fileIn, ios::in);
1031 ofstream out(fileOut, ios::out);
1032 std::string tempString;
1035 getline(in, tempString);
1036 auto pos = tempString.find(oldLine);
1037 if (pos != std::string::npos)
1039 out << tempString.substr(0, pos) << newLine << std::endl;
1044 out << tempString << std::endl;
1051 void integrate::utils::SpecialiseTemplateFiles(
const param::parameters ¶mconf)
1054 auto &tecconfig = paramconf.files.ioout.tecplot;
1055 int loglvl = paramconf.files.ioout.logginglvl;
1057 if (integrate::constants::outputs::printBaseSnake(loglvl))
1059 SpecialiseTemplateFile(tecconfig, 2, paramconf.files.ioout, constants::tecplotsnake);
1061 else if (integrate::constants::outputs::printFullSnake(loglvl))
1063 SpecialiseTemplateFile(tecconfig, 3, paramconf.files.ioout, constants::tecplotsnake);
1065 if (integrate::constants::outputs::printGradientsSnake(loglvl))
1067 SpecialiseTemplateFile(tecconfig, 5, paramconf.files.ioout, constants::tecplotgradient);
1069 if (integrate::constants::outputs::printVectorSnake(loglvl))
1071 SpecialiseTemplateFile(tecconfig, 6, paramconf.files.ioout, constants::tecplotvectors);
1073 if (loglvl > integrate::constants::outputs::numberdefined)
1075 SpecialiseTemplateFile(tecconfig, loglvl, paramconf.files.ioout, constants::tecplotsnake);
1083 std::string templateLayout, outputLayout;
1084 templateLayout = tecconfig.TemplateLogging(logLvl);
1085 outputLayout = ioout.outdir +
"/";
1086 outputLayout += tecconfig.TemplateLogging(logLvl,
false, std::string(
"_") + ioout.pattern);
1087 std::string lineOut =
1089 integrate::utils::WriteModifiedTemplate(templateLayout, outputLayout, tecconfig.filenameregex, lineOut);
1093 std::string extension)
1095 return OutputFileName(paramconf.files.ioout.outdir, paramconf.files.ioout.pattern, fileName, extension);
1099 std::string fileName, std::string extension)
1101 if (rootDirectory.compare(
"") == 0)
1103 return fileName + filePattern + extension;
1105 return rootDirectory +
"/" + fileName + filePattern + extension;
1112 int integrate::test::Prepare()
1122 std::ofstream logFile;
1123 std::ofstream coutFile;
1124 std::ofstream cerrFile;
1126 origconf = paramconf;
1127 paramconf.PrepareForUse();
1130 integrate::prepare::Mesh(paramconf.grid, paramconf.files.ioin, snakeMesh, voluMesh);
1131 voluMesh.volus.disp();
1133 catch (std::exception
const &ex)
1135 cerr <<
"integrate::prepare::Mesh(paramconf.grid, snakeMesh, "
1138 cerr <<
"Exception: " << ex.what() << endl;
1144 integrate::prepare::Snake(paramconf.snak, paramconf.rsvs, paramconf.files.ioin, snakeMesh, voluMesh, rsvsSnake);
1146 catch (std::exception
const &ex)
1148 cerr <<
"integrate::prepare::Snake(paramconf.snak, snakeMesh,"
1151 cerr <<
"Exception: " << ex.what() << endl;
1157 integrate::prepare::Triangulation(snakeMesh, rsvsSnake, rsvsTri);
1159 catch (std::exception
const &ex)
1161 cerr <<
"integrate::prepare::Triangulation" << endl;
1162 cerr <<
"Exception: " << ex.what() << endl;
1168 integrate::prepare::Output(paramconf, origconf, outSnake, outgradientSnake, outvectorSnake, logFile, coutFile,
1171 catch (std::exception
const &ex)
1173 cerr <<
"integrate::prepare::Output" << endl;
1174 cerr <<
"Exception: " << ex.what() << endl;
1181 int integrate::test::All()
1184 auto coutbuff = std::cout.rdbuf();
1185 auto cerrbuff = std::cout.rdbuf();
1187 integrate::Prepare(RSVSobj);
1188 auto iterateInfo = integrate::execute::RSVSiterate(RSVSobj);
1190 integrate::execute::PostProcessing(RSVSobj, iterateInfo.timeT, iterateInfo.nVoluZone, iterateInfo.stepNum);
1191 std::cout.rdbuf(coutbuff);
1192 std::cerr.rdbuf(cerrbuff);
1193 std::cout << std::endl <<
" cout Buffer restored" << std::endl;
1194 std::cerr <<
" cerr Buffer restored" << std::endl;
1198 bool integrate::constants::outputs::printBaseSnake(
int lvl)
1200 return lvl == 2 || lvl == 5 || lvl == 7;
1202 bool integrate::constants::outputs::printFullSnake(
int lvl)
1204 return lvl == 3 || lvl == 4 || numberdefined < lvl;
1206 bool integrate::constants::outputs::printGradientsSnake(
int lvl)
1208 return lvl == 4 || lvl == 5 || lvl == 7 || numberdefined < lvl;
1210 bool integrate::constants::outputs::printVectorSnake(
int lvl)
1212 return lvl == 6 || lvl == 7 || numberdefined < lvl;
Functions which are part of the RSVS algorithm but not core to the snaking process.
Provides the infrastructure for calculation of the RSVS equations.
Simple class containing all the information needed for the 3D-RSVS execution.
Integration into the full 3 dimensional Restricted Snake Volume of Solid method.
std::string OutputFileName(const param::parameters ¶mconf, std::string fileName, std::string extension)
Convenience function to generate file names for RSVS.
Performs Volume and Area calculations for the RSVS process.
Class to handle the RSVS calculation.
void CalculateMesh(mesh &meshin)
Calculates the mesh volumes.
void ReturnConstrToMesh(triangulation &triRSVS) const
Returns a constraint to the triangulation::meshDep.
void CheckAndCompute(int calcMethod=0, bool sensCalc=false)
Prepare the active arrays for SQP calculation and calculate the SQP step.
void CalculateTriangulation(const triangulation &triRSVS, int derivMethod=0)
Calculates the triangulation volume and area derivatives.
std::vector< int > VertexInVolume(const std::vector< double > testVertices, int sizeVert=3) const
Finds for each vertex, the volume object containing it.
void OrientFaces()
Orients either surfaces or edges depending on the dimensionality of the object.
Class for parameters of the grid generation.
std::string activegrid
The type of grid to use either "voxel" or "voronoi" .
std::array< realbounds, 3 > physdomain
Physical domain size for export.
std::array< realbounds, 3 > domain
Domain size in internal coordinates.
Class containing the input configuration these are files to load.
Class containing the output configuration these are files to store and where to store them.
Root class for all the parameters.
Parameters related to the Velocity calculation and VOS steps.
filltype< double > cstfill
Fill the VOS values with a constant value.
int solveralgorithm
Algorithm used by Eigen to solve the SQP system.
filltype< std::string > filefill
Fill the VOS values from file filefill.fill.
filltype< std::string > makefill
Fill the VOS values from a run time function accessible from makefill.fill.
Parameters controlling tuning parameters for the stepping of the restricted surface.
double snaxtimestep
maximum snake time step length
int initboundary
Initialisation boundary (either 0 (outer border), 1 (inner border))
int maxsteps
maximum number of steps
double multiarrivaltolerance
Distance along edge at which converging snaxels are considered arrived.
double snaxdiststep
maximum snaxel distance movement
double spawnposition
Position of spawn.
double distancebox
Distance at which to build the bounding box of the mesh.
double snakecoarseness
The coarseneness level of the snaking mesh that will be generated.
int vorosnakelayers
The number of layers making up the snaking mesh inside each VOS cell [6 6 6] is roughly equal to 2.
std::vector< double > inputpoints
Vector of input points, 4 datums per point.
std::array< int, 3 > gridsizesnake
Size of the Snaking grid on which the snake is defined.
std::array< int, 3 > gridsizebackground
Size of the Background grid on which the VOS is defined.
A structure containing the information about the polyscope display and the RSVS elements to display.
void addSurfaceProperties(std::string name, const mesh &surfaceMesh)
Adds properties of the surface of a snake to it's mesh as scalar quantities.
void show(size_t forFrames=SIZE_MAX)
Show the polyscope window.
void setInteractiveCallback(integrate::RSVSclass &RSVSobj)
Set polyscope's user callback to a lambda which allows control of the RSVSobj.
void addSnake(std::string name, const snake &snakeIn)
PLot a snake with it's velocity in the given polyscope window.
double distanceTol
Distance tolerance.
std::vector< double > edgelengths
Controls the edgelengths at regular intervals.
std::array< double, 3 > lowerB
Lower domain bound.
std::array< double, 3 > upperB
Upper domain bound.
void clear()
Clears the contents of the triangulation making sure we can restart the process.
Custom filesystem header Faff about with filesystem depending on version To give a readable compile t...
Tools for the mathematical processing of meshes.
std::vector< double > CoordInVolume(const mesh &meshin)
Generate a vector of coordinates of points probably inside volumes.
Tools for the refinement and coarsening of meshes.
void CoarsenMesh(const mesh &meshchild, mesh &newparent, const std::vector< int > &elmMapping)
Parameters for the integrated 3DRSVS.
Provide tecplot file formating for mesh and snake outputs.
Provides the core restricted surface snake container.
Functions needed to evolve the r-surface snake.
Interface between the RSVS project and tetgen.
std::vector< int > RSVSVoronoiMesh(const std::vector< double > &vecPts, mesh &vosMesh, mesh &snakMesh, tetgen::apiparam &inparam)
Genrates Snaking and VOS RSVS meshes from the voronoi diagram of a set of points.
void SnakeToSU2(const snake &snakein, const std::string &fileName, tetgen::apiparam &inparam)
Genrates an SU2 mesh file from a snake.
Generation of cartesian grids.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_NOTHROW(M)
Generic rsvs warning.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.