Added choice of simulation model for the pattern tessellation simulation. Refactoring

This commit is contained in:
iasonmanolas 2022-07-12 13:09:25 +03:00
parent 2c462d9ebf
commit a0ed388c56
1 changed files with 60 additions and 36 deletions

View File

@ -1,4 +1,5 @@
#include "reducedmodelevaluator.hpp" #include "reducedmodelevaluator.hpp"
#include "chronoseulersimulationmodel.hpp"
#include "hexagonremesher.hpp" #include "hexagonremesher.hpp"
#include "reducedmodel.hpp" #include "reducedmodel.hpp"
#include "reducedmodeloptimizer.hpp" #include "reducedmodeloptimizer.hpp"
@ -212,8 +213,8 @@ void ReducedModelEvaluator::printResultsVertically(const Results &evaluationResu
csvFile &csvOutput) csvFile &csvOutput)
{ {
#ifdef POLYSCOPE_DEFINED #ifdef POLYSCOPE_DEFINED
csvOutput << "drm2Reduced" csvOutput << "pattern2Reduced"
<< "norm_drm2Reduced"; << "norm_pattern2Reduced";
#else #else
csvOutput << "Job Label" csvOutput << "Job Label"
<< "drm2Reduced" << "drm2Reduced"
@ -378,7 +379,9 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
std::shared_ptr<SimulationMesh> pTiledFullPattern_simulationMesh; std::shared_ptr<SimulationMesh> pTiledFullPattern_simulationMesh;
pTiledFullPattern_simulationMesh = std::make_shared<SimulationMesh>(*pTiledFullPattern); pTiledFullPattern_simulationMesh = std::make_shared<SimulationMesh>(*pTiledFullPattern);
//NOTE: Those should be derived from the optimization results instead of hardcoding them //NOTE: Those should be derived from the optimization results instead of hardcoding them
pTiledFullPattern_simulationMesh->setBeamCrossSection(CrossSectionType{0.002, 0.002}); constexpr double beamWidth = 0.001;
constexpr double beamHeight = 0.001;
pTiledFullPattern_simulationMesh->setBeamCrossSection(CrossSectionType{beamWidth, beamHeight});
if (optimizationResult.fullPatternYoungsModulus == 0) { if (optimizationResult.fullPatternYoungsModulus == 0) {
std::cerr << "Full pattern's young modulus not found." << std::endl; std::cerr << "Full pattern's young modulus not found." << std::endl;
std::terminate(); std::terminate();
@ -415,10 +418,20 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
drmSimulationSettings.shouldCreatePlots = true; drmSimulationSettings.shouldCreatePlots = true;
#endif #endif
constexpr bool shouldRerunFullPatternSimulation = false; constexpr bool shouldRerunFullPatternSimulation = false;
enum PatternSimulationModelTag { DRM, Chronos };
const PatternSimulationModelTag simulationModelTag{DRM};
const std::string simulationModelLabel = [&]() {
switch (simulationModelTag) {
case DRM:
return DRMSimulationModel::label;
case Chronos:
return ChronosEulerSimulationModel::label;
}
}();
// for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) { // for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) {
std::for_each( std::for_each(
//#ifndef POLYSCOPE_DEFINED //#ifndef POLYSCOPE_DEFINED
// std::execution::par_unseq, std::execution::par_unseq,
//#endif //#endif
scenariosTestSetLabels.begin(), scenariosTestSetLabels.begin(),
scenariosTestSetLabels.end(), scenariosTestSetLabels.end(),
@ -452,7 +465,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
// polyscope::show(); // polyscope::show();
const std::filesystem::path surfaceFolderPath const std::filesystem::path surfaceFolderPath
= std::filesystem::path(fullPatternTessellatedResultsDirectoryPath) = std::filesystem::path(fullPatternTessellatedResultsDirectoryPath)
.append(pTileIntoSurface->getLabel()); .append(simulationModelLabel + "_" + pTileIntoSurface->getLabel());
const std::string scenarioLabel = pJob_tiledFullPattern->getLabel(); const std::string scenarioLabel = pJob_tiledFullPattern->getLabel();
const std::filesystem::path scenarioDirectoryPath const std::filesystem::path scenarioDirectoryPath
= std::filesystem::path(surfaceFolderPath).append(scenarioLabel); = std::filesystem::path(surfaceFolderPath).append(scenarioLabel);
@ -476,23 +489,24 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
return patternLabel; return patternLabel;
} }
}(); }();
const auto fullResultsFolderPath = std::filesystem::path(scenarioDirectoryPath) const auto tilledPatternResultsFolderPath = std::filesystem::path(scenarioDirectoryPath)
.append(patternLabel) .append(patternLabel)
.append("Results"); .append("Results");
if (shouldRerunFullPatternSimulation && std::filesystem::exists(fullResultsFolderPath)) { if (shouldRerunFullPatternSimulation
std::filesystem::remove_all(fullResultsFolderPath); && std::filesystem::exists(tilledPatternResultsFolderPath)) {
std::filesystem::remove_all(tilledPatternResultsFolderPath);
} }
const std::filesystem::path fullPatternJobFolderPath = std::filesystem::path( const std::filesystem::path fullPatternJobFolderPath = std::filesystem::path(
scenarioDirectoryPath) scenarioDirectoryPath)
.append(patternLabel) .append(patternLabel)
.append("SimulationJob"); .append("SimulationJob");
SimulationResults simulationResults_tiledFullPattern_drm; SimulationResults simulationResults_tiledPattern;
if (std::filesystem::exists(fullResultsFolderPath)) { if (std::filesystem::exists(tilledPatternResultsFolderPath)) {
//Load full pattern results //Load full pattern results
assert(std::filesystem::exists(fullPatternJobFolderPath)); assert(std::filesystem::exists(fullPatternJobFolderPath));
simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath, simulationResults_tiledPattern.load(tilledPatternResultsFolderPath,
fullPatternJobFolderPath); fullPatternJobFolderPath);
//#ifdef POLYSCOPE_DEFINED //#ifdef POLYSCOPE_DEFINED
// std::array<double, 3> resultsColor({28.0, 99.0, 227.0}); // std::array<double, 3> resultsColor({28.0, 99.0, 227.0});
// simulationResults_tiledFullPattern_drm.registerForDrawing(resultsColor); // simulationResults_tiledFullPattern_drm.registerForDrawing(resultsColor);
@ -518,27 +532,38 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
// simulationResults_tiledFullPattern_drm.unregister(); // simulationResults_tiledFullPattern_drm.unregister();
//#endif //#endif
simulationResults_tiledFullPattern_drm.converged = true; simulationResults_tiledPattern.converged = true;
} else { } else {
std::cout << "Drm results not found in:" << fullResultsFolderPath << std::endl; std::cout << "Tilled pattern simulation results not found in:"
<< tilledPatternResultsFolderPath << std::endl;
//Full //Full
std::cout << "Executing:" << jobLabel << std::endl; std::cout << "Executing:" << jobLabel << std::endl;
DRMSimulationModel drmSimulationModel; switch (simulationModelTag) {
simulationResults_tiledFullPattern_drm case DRM: {
= drmSimulationModel.executeSimulation(pJob_tiledFullPattern, DRMSimulationModel drmSimulationModel;
drmSimulationSettings); simulationResults_tiledPattern = drmSimulationModel
simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM"); .executeSimulation(pJob_tiledFullPattern,
drmSimulationSettings);
break;
}
case Chronos: {
ChronosEulerSimulationModel chronosSimulationModel;
simulationResults_tiledPattern = chronosSimulationModel.executeSimulation(
pJob_tiledFullPattern);
break;
}
}
} }
if (!simulationResults_tiledFullPattern_drm.converged) { if (!simulationResults_tiledPattern.converged) {
std::cerr << "Full pattern simulation failed." << std::endl; std::cerr << "Full pattern simulation failed." << std::endl;
std::cerr << "Not saving results" << std::endl; std::cerr << "Not saving results" << std::endl;
// continue; // continue;
return; return;
} }
std::filesystem::create_directories(fullResultsFolderPath); std::filesystem::create_directories(tilledPatternResultsFolderPath);
const std::filesystem::path drmResultsOutputPath const std::filesystem::path drmResultsOutputPath
= std::filesystem::path(scenarioDirectoryPath).append(patternLabel); = std::filesystem::path(scenarioDirectoryPath).append(patternLabel);
simulationResults_tiledFullPattern_drm.save(drmResultsOutputPath); simulationResults_tiledPattern.save(drmResultsOutputPath);
LinearSimulationModel linearSimulationModel; LinearSimulationModel linearSimulationModel;
SimulationResults simulationResults_tiledReducedPattern SimulationResults simulationResults_tiledReducedPattern
@ -549,22 +574,21 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
// polyscope::show(); // polyscope::show();
//compute the full2reduced distance //compute the full2reduced distance
const double distance_fullDrmToReduced const double distance_patternToReduced = simulationResults_tiledPattern.computeDistance(
= simulationResults_tiledFullPattern_drm simulationResults_tiledReducedPattern, fullToReducedViMap);
.computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap); double distance_patternSumOfAllVerts = 0;
double distance_fullSumOfAllVerts = 0;
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) { for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
distance_fullSumOfAllVerts += simulationResults_tiledFullPattern_drm distance_patternSumOfAllVerts += simulationResults_tiledPattern
.displacements[fullToReducedPair.first] .displacements[fullToReducedPair.first]
.getTranslation() .getTranslation()
.norm(); .norm();
} }
const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced const double distance_normalizedPatternToReduced = distance_patternToReduced
/ distance_fullSumOfAllVerts; / distance_patternSumOfAllVerts;
const int jobIndex = &jobLabel - &scenariosTestSetLabels[0]; const int jobIndex = &jobLabel - &scenariosTestSetLabels[0];
evaluationResults.distances_drm2reduced[jobIndex] = distance_fullDrmToReduced; evaluationResults.distances_drm2reduced[jobIndex] = distance_patternToReduced;
evaluationResults.distances_normalizedDrm2reduced[jobIndex] evaluationResults.distances_normalizedDrm2reduced[jobIndex]
= distance_normalizedFullDrmToReduced; = distance_normalizedPatternToReduced;
}); });
return evaluationResults; return evaluationResults;