Decreased the linear guess factor to 0.7 from 1 in the drm settings

This commit is contained in:
iasonmanolas 2022-01-21 14:29:50 +02:00
parent 5fe427ab2d
commit c5150a2e14
1 changed files with 286 additions and 286 deletions

View File

@ -12,306 +12,306 @@ ReducedModelEvaluator::ReducedModelEvaluator()
} }
std::vector<double> ReducedModelEvaluator::evaluateReducedModel( std::vector<double> ReducedModelEvaluator::evaluateReducedModel(
ReducedModelOptimization::Results &optimizationResults) ReducedModelOptimization::Results &optimizationResults)
{ {
// std::shared_ptr<VCGPolyMesh> pTileIntoSurface = std::make_shared<VCGPolyMesh>(); // std::shared_ptr<VCGPolyMesh> pTileIntoSurface = std::make_shared<VCGPolyMesh>();
// std::filesystem::path tileIntoSurfaceFilePath{ // std::filesystem::path tileIntoSurfaceFilePath{
// "/home/iason/Coding/Projects/Approximating shapes with flat " // "/home/iason/Coding/Projects/Approximating shapes with flat "
// "patterns/ReducedModelOptimization/TestSet/TileIntoSurface/plane_34Polygons.ply"}; // "patterns/ReducedModelOptimization/TestSet/TileIntoSurface/plane_34Polygons.ply"};
// assert(std::filesystem::exists(tileIntoSurfaceFilePath)); // assert(std::filesystem::exists(tileIntoSurfaceFilePath));
// pTileIntoSurface->load(tileIntoSurfaceFilePath); // pTileIntoSurface->load(tileIntoSurfaceFilePath);
//Set required file paths //Set required file paths
const std::filesystem::path tileInto_triMesh_filename const std::filesystem::path tileInto_triMesh_filename
= "/home/iason/Coding/build/PatternTillingReducedModel/Meshes/" = "/home/iason/Coding/build/PatternTillingReducedModel/Meshes/"
"instantMeshes_plane_34.ply"; "instantMeshes_plane_34.ply";
const std::filesystem::path reducedPatternFilePath const std::filesystem::path reducedPatternFilePath
= "/home/iason/Coding/Projects/Approximating shapes with flat " = "/home/iason/Coding/Projects/Approximating shapes with flat "
"patterns/ReducedModelOptimization/TestSet/ReducedPatterns/single_reduced.ply"; "patterns/ReducedModelOptimization/TestSet/ReducedPatterns/single_reduced.ply";
const std::filesystem::path intermediateResultsDirectoryPath const std::filesystem::path intermediateResultsDirectoryPath
= "/home/iason/Coding/build/ReducedModelOptimization/IntermediateResults"; = "/home/iason/Coding/build/ReducedModelOptimization/IntermediateResults";
// const std::filesystem::path drmSettingsFilePath // const std::filesystem::path drmSettingsFilePath
// = "/home/iason/Coding/Projects/Approximating shapes with flat " // = "/home/iason/Coding/Projects/Approximating shapes with flat "
// "patterns/ReducedModelOptimization/DefaultSettings/DRMSettings/" // "patterns/ReducedModelOptimization/DefaultSettings/DRMSettings/"
// "defaultDRMSimulationSettings.json"; // "defaultDRMSimulationSettings.json";
DRMSimulationModel::Settings drmSimulationSettings; DRMSimulationModel::Settings drmSimulationSettings;
// drmSimulationSettings.load(drmSettingsFilePath); // drmSimulationSettings.load(drmSettingsFilePath);
drmSimulationSettings.linearGuessForceScaleFactor = 1; drmSimulationSettings.linearGuessForceScaleFactor = 0.7;
drmSimulationSettings.debugModeStep = 1000; drmSimulationSettings.debugModeStep = 10000;
drmSimulationSettings.beVerbose = true; drmSimulationSettings.beVerbose = true;
constexpr bool shouldRerunFullPatternSimulation = false; constexpr bool shouldRerunFullPatternSimulation = false;
const std::vector<std::string> scenariosTestSetLabels{"22Hex_randomBending0", const std::vector<std::string> scenariosTestSetLabels{"22Hex_randomBending0",
"22Hex_randomBending1", "22Hex_randomBending1",
"22Hex_randomBending2", "22Hex_randomBending2",
"22Hex_randomBending3", "22Hex_randomBending3",
"22Hex_randomBending4", "22Hex_randomBending4",
"22Hex_randomBending5", "22Hex_randomBending5",
"22Hex_randomBending6", "22Hex_randomBending6",
"22Hex_randomBending7", "22Hex_randomBending7",
"22Hex_randomBending8", "22Hex_randomBending8",
"22Hex_randomBending9", "22Hex_randomBending9",
"22Hex_randomBending10", "22Hex_randomBending10",
"22Hex_randomBending11", "22Hex_randomBending11",
"22Hex_randomBending12", "22Hex_randomBending12",
"22Hex_randomBending13", "22Hex_randomBending13",
"22Hex_randomBending14", "22Hex_randomBending14",
"22Hex_randomBending15", "22Hex_randomBending15",
"22Hex_randomBending16", "22Hex_randomBending16",
"22Hex_randomBending17", "22Hex_randomBending17",
"22Hex_randomBending18", "22Hex_randomBending18",
"22Hex_randomBending19", "22Hex_randomBending19",
"22Hex_randomBending20", "22Hex_randomBending20",
"22Hex_bending_0.005N", "22Hex_bending_0.005N",
"22Hex_bending_0.01N", "22Hex_bending_0.01N",
"22Hex_bending_0.03N", "22Hex_bending_0.03N",
"22Hex_bending_0.05N", "22Hex_bending_0.05N",
"22Hex_pullOppositeVerts_0.05N", "22Hex_pullOppositeVerts_0.05N",
"22Hex_pullOppositeVerts_0.1N", "22Hex_pullOppositeVerts_0.1N",
"22Hex_pullOppositeVerts_0.3N", "22Hex_pullOppositeVerts_0.3N",
"22Hex_shear_2N", "22Hex_shear_2N",
"22Hex_shear_5N", "22Hex_shear_5N",
"22Hex_axial_10N", "22Hex_axial_10N",
"22Hex_axial_20N", "22Hex_axial_20N",
"22Hex_cylinder_0.05N", "22Hex_cylinder_0.05N",
"22Hex_cylinder_0.1N", "22Hex_cylinder_0.1N",
"22Hex_s_0.05N", "22Hex_s_0.05N",
"22Hex_s_0.1N"}; "22Hex_s_0.1N"};
//Load surface //Load surface
std::shared_ptr<VCGPolyMesh> pTileIntoSurface = [&]() { std::shared_ptr<VCGPolyMesh> pTileIntoSurface = [&]() {
VCGTriMesh tileInto_triMesh; VCGTriMesh tileInto_triMesh;
const bool surfaceLoadSuccessfull = tileInto_triMesh.load(tileInto_triMesh_filename); const bool surfaceLoadSuccessfull = tileInto_triMesh.load(tileInto_triMesh_filename);
assert(surfaceLoadSuccessfull); assert(surfaceLoadSuccessfull);
return PolygonalRemeshing::remeshWithPolygons(tileInto_triMesh); return PolygonalRemeshing::remeshWithPolygons(tileInto_triMesh);
}(); }();
const double optimizedBaseTriangleHeight = vcg::Distance(optimizationResults.baseTriangle.cP(0), const double optimizedBaseTriangleHeight = vcg::Distance(optimizationResults.baseTriangle.cP(0),
(optimizationResults.baseTriangle.cP(1) (optimizationResults.baseTriangle.cP(1)
+ optimizationResults.baseTriangle.cP( + optimizationResults.baseTriangle.cP(
2)) 2))
/ 2); / 2);
pTileIntoSurface->moveToCenter(); pTileIntoSurface->moveToCenter();
const double scaleFactor = optimizedBaseTriangleHeight const double scaleFactor = optimizedBaseTriangleHeight
/ pTileIntoSurface->getAverageFaceRadius(); / pTileIntoSurface->getAverageFaceRadius();
vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor); vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor);
// tileIntoSurface.registerForDrawing(); // tileIntoSurface.registerForDrawing();
// polyscope::show(); // polyscope::show();
//Tile full pattern into surface //Tile full pattern into surface
std::vector<PatternGeometry> fullPatterns(1); std::vector<PatternGeometry> fullPatterns(1);
fullPatterns[0].copy(optimizationResults.baseTriangleFullPattern); fullPatterns[0].copy(optimizationResults.baseTriangleFullPattern);
//// Base triangle pattern might contain dangling vertices.Remove those //// Base triangle pattern might contain dangling vertices.Remove those
fullPatterns[0].interfaceNodeIndex = 3; fullPatterns[0].interfaceNodeIndex = 3;
fullPatterns[0].deleteDanglingVertices(); fullPatterns[0].deleteDanglingVertices();
std::vector<int> perSurfaceFacePatternIndices(pTileIntoSurface->FN(), 0); std::vector<int> perSurfaceFacePatternIndices(pTileIntoSurface->FN(), 0);
std::vector<std::vector<size_t>> perPatternIndexTiledFullPatternEdgeIndices; std::vector<std::vector<size_t>> perPatternIndexTiledFullPatternEdgeIndices;
std::vector<size_t> tileIntoEdgeToTiledFullVi; std::vector<size_t> tileIntoEdgeToTiledFullVi;
std::shared_ptr<PatternGeometry> pTiledFullPattern std::shared_ptr<PatternGeometry> pTiledFullPattern
= PatternGeometry::tilePattern(fullPatterns, = PatternGeometry::tilePattern(fullPatterns,
{}, {},
*pTileIntoSurface, *pTileIntoSurface,
perSurfaceFacePatternIndices, perSurfaceFacePatternIndices,
tileIntoEdgeToTiledFullVi, tileIntoEdgeToTiledFullVi,
perPatternIndexTiledFullPatternEdgeIndices); perPatternIndexTiledFullPatternEdgeIndices);
pTiledFullPattern->setLabel("Tiled_full_patterns"); pTiledFullPattern->setLabel("Tiled_full_patterns");
// pTiledFullPattern->registerForDrawing(); // pTiledFullPattern->registerForDrawing();
//Tile reduced pattern into surface //Tile reduced pattern into surface
PatternGeometry reducedPattern; PatternGeometry reducedPattern;
reducedPattern.load(reducedPatternFilePath); reducedPattern.load(reducedPatternFilePath);
reducedPattern.deleteDanglingVertices(); reducedPattern.deleteDanglingVertices();
assert(reducedPattern.interfaceNodeIndex == 1); assert(reducedPattern.interfaceNodeIndex == 1);
std::vector<PatternGeometry> reducedPatterns(1); std::vector<PatternGeometry> reducedPatterns(1);
reducedPatterns[0].copy(reducedPattern); reducedPatterns[0].copy(reducedPattern);
const auto reducedPatternBaseTriangle = reducedPattern.computeBaseTriangle(); const auto reducedPatternBaseTriangle = reducedPattern.computeBaseTriangle();
ReducedModelOptimization::Results::applyOptimizationResults_innerHexagon( ReducedModelOptimization::Results::applyOptimizationResults_innerHexagon(
optimizationResults, reducedPatternBaseTriangle, reducedPatterns[0]); optimizationResults, reducedPatternBaseTriangle, reducedPatterns[0]);
std::vector<std::vector<size_t>> perPatternIndexTiledReducedPatternEdgeIndices; std::vector<std::vector<size_t>> perPatternIndexTiledReducedPatternEdgeIndices;
std::vector<size_t> tileIntoEdgeToTiledReducedVi; std::vector<size_t> tileIntoEdgeToTiledReducedVi;
std::shared_ptr<PatternGeometry> pTiledReducedPattern std::shared_ptr<PatternGeometry> pTiledReducedPattern
= PatternGeometry::tilePattern(reducedPatterns, = PatternGeometry::tilePattern(reducedPatterns,
{0}, {0},
*pTileIntoSurface, *pTileIntoSurface,
perSurfaceFacePatternIndices, perSurfaceFacePatternIndices,
tileIntoEdgeToTiledReducedVi, tileIntoEdgeToTiledReducedVi,
perPatternIndexTiledReducedPatternEdgeIndices); perPatternIndexTiledReducedPatternEdgeIndices);
pTiledReducedPattern->setLabel("Tiled_reduced_patterns"); pTiledReducedPattern->setLabel("Tiled_reduced_patterns");
// pTiledReducedPattern->registerForDrawing(); // pTiledReducedPattern->registerForDrawing();
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex> std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
fullToReducedViMap; //of only the common vertices fullToReducedViMap; //of only the common vertices
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex> std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
reducedToFullViMap; //of only the common vertices reducedToFullViMap; //of only the common vertices
for (int ei = 0; ei < pTileIntoSurface->EN(); ei++) { for (int ei = 0; ei < pTileIntoSurface->EN(); ei++) {
fullToReducedViMap[tileIntoEdgeToTiledFullVi[ei]] = tileIntoEdgeToTiledReducedVi[ei]; fullToReducedViMap[tileIntoEdgeToTiledFullVi[ei]] = tileIntoEdgeToTiledReducedVi[ei];
} }
constructInverseMap(fullToReducedViMap, reducedToFullViMap); constructInverseMap(fullToReducedViMap, reducedToFullViMap);
std::vector<size_t> tilledFullPatternInterfaceVi; std::vector<size_t> tilledFullPatternInterfaceVi;
tilledFullPatternInterfaceVi.clear(); tilledFullPatternInterfaceVi.clear();
tilledFullPatternInterfaceVi.resize(fullToReducedViMap.size()); tilledFullPatternInterfaceVi.resize(fullToReducedViMap.size());
size_t viIndex = 0; size_t viIndex = 0;
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) { for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
tilledFullPatternInterfaceVi[viIndex++] = fullToReducedPair.first; tilledFullPatternInterfaceVi[viIndex++] = fullToReducedPair.first;
} }
//Create simulation meshes //Create simulation meshes
////Tessellated full pattern simulation mesh ////Tessellated full pattern simulation mesh
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}); pTiledFullPattern_simulationMesh->setBeamCrossSection(CrossSectionType{0.002, 0.002});
if (optimizationResults.fullPatternYoungsModulus == 0) { if (optimizationResults.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();
} }
pTiledFullPattern_simulationMesh->setBeamMaterial(0.3, pTiledFullPattern_simulationMesh->setBeamMaterial(0.3,
optimizationResults.fullPatternYoungsModulus); optimizationResults.fullPatternYoungsModulus);
pTiledFullPattern_simulationMesh->reset(); pTiledFullPattern_simulationMesh->reset();
////Tessellated reduced pattern simulation mesh ////Tessellated reduced pattern simulation mesh
std::shared_ptr<SimulationMesh> pTiledReducedPattern_simulationMesh; std::shared_ptr<SimulationMesh> pTiledReducedPattern_simulationMesh;
pTiledReducedPattern_simulationMesh = std::make_shared<SimulationMesh>(*pTiledReducedPattern); pTiledReducedPattern_simulationMesh = std::make_shared<SimulationMesh>(*pTiledReducedPattern);
const std::vector<size_t> &tiledPatternElementIndicesForReducedPattern const std::vector<size_t> &tiledPatternElementIndicesForReducedPattern
= perPatternIndexTiledReducedPatternEdgeIndices[0]; = perPatternIndexTiledReducedPatternEdgeIndices[0];
ReducedModelOptimization::Results::applyOptimizationResults_elements( ReducedModelOptimization::Results::applyOptimizationResults_elements(
optimizationResults, pTiledReducedPattern_simulationMesh); optimizationResults, pTiledReducedPattern_simulationMesh);
pTiledReducedPattern_simulationMesh->reset(); pTiledReducedPattern_simulationMesh->reset();
std::vector<double> distances_drm2reduced(scenariosTestSetLabels.size(), 0); std::vector<double> distances_drm2reduced(scenariosTestSetLabels.size(), 0);
std::vector<double> distances_normalizedDrm2reduced(scenariosTestSetLabels.size(), 0); std::vector<double> distances_normalizedDrm2reduced(scenariosTestSetLabels.size(), 0);
for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) { for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) {
const std::string &jobLabel = scenariosTestSetLabels[jobIndex]; const std::string &jobLabel = scenariosTestSetLabels[jobIndex];
const std::filesystem::path scenariosDirectoryPath const std::filesystem::path scenariosDirectoryPath
= "/home/iason/Coding/build/PatternTillingReducedModel/Scenarios/"; = "/home/iason/Coding/build/PatternTillingReducedModel/Scenarios/";
const std::filesystem::path tiledReducedPatternJobFilePath const std::filesystem::path tiledReducedPatternJobFilePath
= std::filesystem::path(scenariosDirectoryPath) = std::filesystem::path(scenariosDirectoryPath)
.append(jobLabel) .append(jobLabel)
.append("SimulationJobs") .append("SimulationJobs")
.append("Reduced") .append("Reduced")
.append(SimulationJob::jsonDefaultFileName); .append(SimulationJob::jsonDefaultFileName);
//set jobs //set jobs
std::shared_ptr<SimulationJob> pJob_tiledReducedPattern; std::shared_ptr<SimulationJob> pJob_tiledReducedPattern;
pJob_tiledReducedPattern = std::make_shared<SimulationJob>(SimulationJob()); pJob_tiledReducedPattern = std::make_shared<SimulationJob>(SimulationJob());
pJob_tiledReducedPattern->load(tiledReducedPatternJobFilePath, false); pJob_tiledReducedPattern->load(tiledReducedPatternJobFilePath, false);
pJob_tiledReducedPattern->pMesh = pTiledReducedPattern_simulationMesh; pJob_tiledReducedPattern->pMesh = pTiledReducedPattern_simulationMesh;
std::shared_ptr<SimulationJob> pJob_tiledFullPattern; std::shared_ptr<SimulationJob> pJob_tiledFullPattern;
pJob_tiledFullPattern = std::make_shared<SimulationJob>(SimulationJob()); pJob_tiledFullPattern = std::make_shared<SimulationJob>(SimulationJob());
pJob_tiledFullPattern->pMesh = pTiledFullPattern_simulationMesh; pJob_tiledFullPattern->pMesh = pTiledFullPattern_simulationMesh;
pJob_tiledReducedPattern->remap(reducedToFullViMap, *pJob_tiledFullPattern); pJob_tiledReducedPattern->remap(reducedToFullViMap, *pJob_tiledFullPattern);
// pJob_tiledReducedPattern->registerForDrawing(pTiledReducedPattern->getLabel()); // pJob_tiledReducedPattern->registerForDrawing(pTiledReducedPattern->getLabel());
// pJob_tiledFullPattern->registerForDrawing(pTiledFullPattern->getLabel()); // pJob_tiledFullPattern->registerForDrawing(pTiledFullPattern->getLabel());
// polyscope::show(); // polyscope::show();
//Save reduced job //Save reduced job
const std::filesystem::path tesellatedResultsFolderPath const std::filesystem::path tesellatedResultsFolderPath
= std::filesystem::path(intermediateResultsDirectoryPath).append("TessellatedResults"); = std::filesystem::path(intermediateResultsDirectoryPath).append("TessellatedResults");
const std::filesystem::path surfaceFolderPath = std::filesystem::path( const std::filesystem::path surfaceFolderPath = std::filesystem::path(
tesellatedResultsFolderPath) tesellatedResultsFolderPath)
.append(pTileIntoSurface->getLabel()); .append(pTileIntoSurface->getLabel());
const std::string scenarioLabel = pJob_tiledFullPattern->getLabel(); const std::string scenarioLabel = pJob_tiledFullPattern->getLabel();
const std::filesystem::path scenarioDirectoryPath = std::filesystem::path(surfaceFolderPath) const std::filesystem::path scenarioDirectoryPath = std::filesystem::path(surfaceFolderPath)
.append(scenarioLabel); .append(scenarioLabel);
const std::filesystem::path reducedJobDirectoryPath const std::filesystem::path reducedJobDirectoryPath
= std::filesystem::path(scenarioDirectoryPath).append("ReducedJob"); = std::filesystem::path(scenarioDirectoryPath).append("ReducedJob");
std::filesystem::create_directories(reducedJobDirectoryPath); std::filesystem::create_directories(reducedJobDirectoryPath);
pJob_tiledReducedPattern->save(reducedJobDirectoryPath); pJob_tiledReducedPattern->save(reducedJobDirectoryPath);
//Run scenario //Run scenario
////Full ////Full
const std::string patternLabel = [&]() { const std::string patternLabel = [&]() {
const std::string patternLabel = optimizationResults.baseTriangleFullPattern.getLabel(); const std::string patternLabel = optimizationResults.baseTriangleFullPattern.getLabel();
const int numberOfOccurences = std::count_if(patternLabel.begin(), const int numberOfOccurences = std::count_if(patternLabel.begin(),
patternLabel.end(), patternLabel.end(),
[](char c) { return c == '#'; }); [](char c) { return c == '#'; });
if (numberOfOccurences == 0) { if (numberOfOccurences == 0) {
return std::to_string(optimizationResults.baseTriangleFullPattern.EN()) + "#" return std::to_string(optimizationResults.baseTriangleFullPattern.EN()) + "#"
+ optimizationResults.baseTriangleFullPattern.getLabel(); + optimizationResults.baseTriangleFullPattern.getLabel();
} else if (numberOfOccurences == 1) { } else if (numberOfOccurences == 1) {
return optimizationResults.baseTriangleFullPattern.getLabel(); return optimizationResults.baseTriangleFullPattern.getLabel();
} }
}(); }();
const auto fullResultsFolderPath const auto fullResultsFolderPath
= std::filesystem::path(scenarioDirectoryPath).append(patternLabel).append("Results"); = std::filesystem::path(scenarioDirectoryPath).append(patternLabel).append("Results");
if (shouldRerunFullPatternSimulation && std::filesystem::exists(fullResultsFolderPath)) { if (shouldRerunFullPatternSimulation && std::filesystem::exists(fullResultsFolderPath)) {
std::filesystem::remove_all(fullResultsFolderPath); std::filesystem::remove_all(fullResultsFolderPath);
} }
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_tiledFullPattern_drm;
if (std::filesystem::exists(fullResultsFolderPath)) { if (std::filesystem::exists(fullResultsFolderPath)) {
//Load full pattern results //Load full pattern results
assert(std::filesystem::exists(fullPatternJobFolderPath)); assert(std::filesystem::exists(fullPatternJobFolderPath));
simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath, simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath,
fullPatternJobFolderPath); fullPatternJobFolderPath);
simulationResults_tiledFullPattern_drm.converged = true; simulationResults_tiledFullPattern_drm.converged = true;
} else { } else {
//Full //Full
std::cout << "Executing:" << jobLabel << std::endl; std::cout << "Executing:" << jobLabel << std::endl;
DRMSimulationModel drmSimulationModel; DRMSimulationModel drmSimulationModel;
simulationResults_tiledFullPattern_drm simulationResults_tiledFullPattern_drm
= drmSimulationModel.executeSimulation(pJob_tiledFullPattern, drmSimulationSettings); = drmSimulationModel.executeSimulation(pJob_tiledFullPattern, drmSimulationSettings);
simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM"); simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM");
} }
std::filesystem::create_directories(fullResultsFolderPath); std::filesystem::create_directories(fullResultsFolderPath);
simulationResults_tiledFullPattern_drm.save( simulationResults_tiledFullPattern_drm.save(
std::filesystem::path(scenarioDirectoryPath).append(patternLabel)); std::filesystem::path(scenarioDirectoryPath).append(patternLabel));
if (!simulationResults_tiledFullPattern_drm.converged) { if (!simulationResults_tiledFullPattern_drm.converged) {
std::cerr << "Full pattern simulation failed." << std::endl; std::cerr << "Full pattern simulation failed." << std::endl;
} }
LinearSimulationModel linearSimulationModel; LinearSimulationModel linearSimulationModel;
SimulationResults simulationResults_tiledReducedPattern SimulationResults simulationResults_tiledReducedPattern
= linearSimulationModel.executeSimulation(pJob_tiledReducedPattern); = linearSimulationModel.executeSimulation(pJob_tiledReducedPattern);
// simulationResults_tiledReducedPattern.registerForDrawing(); // simulationResults_tiledReducedPattern.registerForDrawing();
// simulationResults_tiledFullPattern_drm.registerForDrawing(); // simulationResults_tiledFullPattern_drm.registerForDrawing();
// polyscope::show(); // polyscope::show();
//measure distance //measure distance
const double distance_fullDrmToReduced const double distance_fullDrmToReduced
= simulationResults_tiledFullPattern_drm = simulationResults_tiledFullPattern_drm
.computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap); .computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap);
double distance_fullSumOfAllVerts = 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_fullSumOfAllVerts += simulationResults_tiledFullPattern_drm
.displacements[fullToReducedPair.first] .displacements[fullToReducedPair.first]
.getTranslation() .getTranslation()
.norm(); .norm();
} }
const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced
/ distance_fullSumOfAllVerts; / distance_fullSumOfAllVerts;
distances_drm2reduced[jobIndex] = distance_fullDrmToReduced; distances_drm2reduced[jobIndex] = distance_fullDrmToReduced;
distances_normalizedDrm2reduced[jobIndex] = distance_normalizedFullDrmToReduced; distances_normalizedDrm2reduced[jobIndex] = distance_normalizedFullDrmToReduced;
} }
//#ifndef POLYSCOPE_DEFINED //#ifndef POLYSCOPE_DEFINED
// return distances_drm2reduced; // return distances_drm2reduced;
//#else //#else
//report distance //report distance
// csvFile csv_results("", flse); // csvFile csv_results("", flse);
csvFile csv_results({}, false); csvFile csv_results({}, false);
// csvFile csv_results(std::filesystem::path(dirPath_thisOptimization) // csvFile csv_results(std::filesystem::path(dirPath_thisOptimization)
// .append("results.csv") // .append("results.csv")
// .string(), // .string(),
// false); // false);
csv_results /*<< "Job Label"*/ csv_results /*<< "Job Label"*/
<< "drm2Reduced" << "drm2Reduced"
<< "norm_drm2Reduced"; << "norm_drm2Reduced";
csv_results << endrow; csv_results << endrow;
double sumOfNormalizedFull2Reduced = 0; double sumOfNormalizedFull2Reduced = 0;
for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) { for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) {
const std::string &jobLabel = scenariosTestSetLabels[jobIndex]; const std::string &jobLabel = scenariosTestSetLabels[jobIndex];
const double &distance_fullDrmToReduced = distances_drm2reduced[jobIndex]; const double &distance_fullDrmToReduced = distances_drm2reduced[jobIndex];
const double &distance_normalizedFullDrmToReduced = distances_normalizedDrm2reduced[jobIndex]; const double &distance_normalizedFullDrmToReduced = distances_normalizedDrm2reduced[jobIndex];
csv_results /*<< jobLabel*/ << distance_fullDrmToReduced csv_results /*<< jobLabel*/ << distance_fullDrmToReduced
<< distance_normalizedFullDrmToReduced; << distance_normalizedFullDrmToReduced;
csv_results << endrow; csv_results << endrow;
sumOfNormalizedFull2Reduced += distance_normalizedFullDrmToReduced; sumOfNormalizedFull2Reduced += distance_normalizedFullDrmToReduced;
} }
std::cout << "Average normalized error per scenario:" std::cout << "Average normalized error per scenario:"
<< sumOfNormalizedFull2Reduced / scenariosTestSetLabels.size() << std::endl; << sumOfNormalizedFull2Reduced / scenariosTestSetLabels.size() << std::endl;
return distances_normalizedDrm2reduced; return distances_normalizedDrm2reduced;
//#endif //#endif
} }