diff --git a/reducedmodelevaluator.cpp b/reducedmodelevaluator.cpp index 8e8cdcf..726fafc 100644 --- a/reducedmodelevaluator.cpp +++ b/reducedmodelevaluator.cpp @@ -1,4 +1,5 @@ #include "reducedmodelevaluator.hpp" +#include "chronoseulersimulationmodel.hpp" #include "hexagonremesher.hpp" #include "reducedmodel.hpp" #include "reducedmodeloptimizer.hpp" @@ -212,8 +213,8 @@ void ReducedModelEvaluator::printResultsVertically(const Results &evaluationResu csvFile &csvOutput) { #ifdef POLYSCOPE_DEFINED - csvOutput << "drm2Reduced" - << "norm_drm2Reduced"; + csvOutput << "pattern2Reduced" + << "norm_pattern2Reduced"; #else csvOutput << "Job Label" << "drm2Reduced" @@ -378,7 +379,9 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( std::shared_ptr pTiledFullPattern_simulationMesh; pTiledFullPattern_simulationMesh = std::make_shared(*pTiledFullPattern); //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) { std::cerr << "Full pattern's young modulus not found." << std::endl; std::terminate(); @@ -415,10 +418,20 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( drmSimulationSettings.shouldCreatePlots = true; #endif 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++) { std::for_each( //#ifndef POLYSCOPE_DEFINED - // std::execution::par_unseq, + std::execution::par_unseq, //#endif scenariosTestSetLabels.begin(), scenariosTestSetLabels.end(), @@ -452,7 +465,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( // polyscope::show(); const std::filesystem::path surfaceFolderPath = std::filesystem::path(fullPatternTessellatedResultsDirectoryPath) - .append(pTileIntoSurface->getLabel()); + .append(simulationModelLabel + "_" + pTileIntoSurface->getLabel()); const std::string scenarioLabel = pJob_tiledFullPattern->getLabel(); const std::filesystem::path scenarioDirectoryPath = std::filesystem::path(surfaceFolderPath).append(scenarioLabel); @@ -476,23 +489,24 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( return patternLabel; } }(); - const auto fullResultsFolderPath = std::filesystem::path(scenarioDirectoryPath) - .append(patternLabel) - .append("Results"); - if (shouldRerunFullPatternSimulation && std::filesystem::exists(fullResultsFolderPath)) { - std::filesystem::remove_all(fullResultsFolderPath); + const auto tilledPatternResultsFolderPath = std::filesystem::path(scenarioDirectoryPath) + .append(patternLabel) + .append("Results"); + if (shouldRerunFullPatternSimulation + && std::filesystem::exists(tilledPatternResultsFolderPath)) { + std::filesystem::remove_all(tilledPatternResultsFolderPath); } const std::filesystem::path fullPatternJobFolderPath = std::filesystem::path( scenarioDirectoryPath) .append(patternLabel) .append("SimulationJob"); - SimulationResults simulationResults_tiledFullPattern_drm; - if (std::filesystem::exists(fullResultsFolderPath)) { + SimulationResults simulationResults_tiledPattern; + if (std::filesystem::exists(tilledPatternResultsFolderPath)) { //Load full pattern results assert(std::filesystem::exists(fullPatternJobFolderPath)); - simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath, - fullPatternJobFolderPath); + simulationResults_tiledPattern.load(tilledPatternResultsFolderPath, + fullPatternJobFolderPath); //#ifdef POLYSCOPE_DEFINED // std::array resultsColor({28.0, 99.0, 227.0}); // simulationResults_tiledFullPattern_drm.registerForDrawing(resultsColor); @@ -518,27 +532,38 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( // simulationResults_tiledFullPattern_drm.unregister(); //#endif - simulationResults_tiledFullPattern_drm.converged = true; + simulationResults_tiledPattern.converged = true; } else { - std::cout << "Drm results not found in:" << fullResultsFolderPath << std::endl; + std::cout << "Tilled pattern simulation results not found in:" + << tilledPatternResultsFolderPath << std::endl; //Full std::cout << "Executing:" << jobLabel << std::endl; - DRMSimulationModel drmSimulationModel; - simulationResults_tiledFullPattern_drm - = drmSimulationModel.executeSimulation(pJob_tiledFullPattern, - drmSimulationSettings); - simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM"); + switch (simulationModelTag) { + case DRM: { + DRMSimulationModel drmSimulationModel; + simulationResults_tiledPattern = drmSimulationModel + .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 << "Not saving results" << std::endl; // continue; return; } - std::filesystem::create_directories(fullResultsFolderPath); + std::filesystem::create_directories(tilledPatternResultsFolderPath); const std::filesystem::path drmResultsOutputPath = std::filesystem::path(scenarioDirectoryPath).append(patternLabel); - simulationResults_tiledFullPattern_drm.save(drmResultsOutputPath); + simulationResults_tiledPattern.save(drmResultsOutputPath); LinearSimulationModel linearSimulationModel; SimulationResults simulationResults_tiledReducedPattern @@ -549,22 +574,21 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel( // polyscope::show(); //compute the full2reduced distance - const double distance_fullDrmToReduced - = simulationResults_tiledFullPattern_drm - .computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap); - double distance_fullSumOfAllVerts = 0; + const double distance_patternToReduced = simulationResults_tiledPattern.computeDistance( + simulationResults_tiledReducedPattern, fullToReducedViMap); + double distance_patternSumOfAllVerts = 0; for (std::pair fullToReducedPair : fullToReducedViMap) { - distance_fullSumOfAllVerts += simulationResults_tiledFullPattern_drm - .displacements[fullToReducedPair.first] - .getTranslation() - .norm(); + distance_patternSumOfAllVerts += simulationResults_tiledPattern + .displacements[fullToReducedPair.first] + .getTranslation() + .norm(); } - const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced - / distance_fullSumOfAllVerts; + const double distance_normalizedPatternToReduced = distance_patternToReduced + / distance_patternSumOfAllVerts; const int jobIndex = &jobLabel - &scenariosTestSetLabels[0]; - evaluationResults.distances_drm2reduced[jobIndex] = distance_fullDrmToReduced; + evaluationResults.distances_drm2reduced[jobIndex] = distance_patternToReduced; evaluationResults.distances_normalizedDrm2reduced[jobIndex] - = distance_normalizedFullDrmToReduced; + = distance_normalizedPatternToReduced; }); return evaluationResults;