Hardcoded the 22 hexagon test-surface
This commit is contained in:
parent
90dc2ac081
commit
b2bd12d8df
|
|
@ -1,7 +1,9 @@
|
||||||
#include "reducedmodelevaluator.hpp"
|
#include "reducedmodelevaluator.hpp"
|
||||||
#include "hexagonremesher.hpp"
|
#include "hexagonremesher.hpp"
|
||||||
#include "reducedmodel.hpp"
|
#include "reducedmodel.hpp"
|
||||||
|
#include "reducedmodeloptimizer.hpp"
|
||||||
#include "trianglepatterngeometry.hpp"
|
#include "trianglepatterngeometry.hpp"
|
||||||
|
#include <execution>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
using FullPatternVertexIndex = VertexIndex;
|
using FullPatternVertexIndex = VertexIndex;
|
||||||
|
|
@ -9,28 +11,77 @@ using ReducedPatternVertexIndex = VertexIndex;
|
||||||
|
|
||||||
ReducedModelEvaluator::ReducedModelEvaluator()
|
ReducedModelEvaluator::ReducedModelEvaluator()
|
||||||
{
|
{
|
||||||
|
pTileIntoSurface = [&]() {
|
||||||
|
std::istringstream inputStream_tileIntoTriSurface(tileIntoSurfaceFileContent);
|
||||||
|
VCGTriMesh tileInto_triMesh;
|
||||||
|
const bool surfaceLoadSuccessfull = tileInto_triMesh.load(inputStream_tileIntoTriSurface);
|
||||||
|
tileInto_triMesh.setLabel("instantMeshes_plane_34");
|
||||||
|
assert(surfaceLoadSuccessfull);
|
||||||
|
return PolygonalRemeshing::remeshWithPolygons(tileInto_triMesh);
|
||||||
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//double ReducedModelEvaluator::evaluateOptimizationSettings(
|
||||||
|
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||||
|
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||||
|
// std::vector<ReducedModelEvaluator::Results> &patternEvaluationResults)
|
||||||
|
//{
|
||||||
|
// assert(!pPatterns.empty());
|
||||||
|
// double optimizationError = 0;
|
||||||
|
// auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
// std::vector<double> averageNormalizedError(pPatterns.size(), 0);
|
||||||
|
// patternEvaluationResults.clear();
|
||||||
|
// patternEvaluationResults.resize(pPatterns.size());
|
||||||
|
// std::for_each(
|
||||||
|
// // std::execution::par_unseq,
|
||||||
|
// pPatterns.begin(),
|
||||||
|
// pPatterns.end(),
|
||||||
|
// [&](const std::shared_ptr<ConstPatternGeometry> &pPattern) {
|
||||||
|
// // std::cout << "Optimizing " << pPattern->getLabel() << std::endl;
|
||||||
|
// ReducedModelOptimization::Results optimizationResults;
|
||||||
|
// ReducedModelOptimizer optimizer;
|
||||||
|
// optimizer.optimize(*pPattern, optimizationSettings, optimizationResults);
|
||||||
|
// const auto evaluationResults
|
||||||
|
// = ReducedModelEvaluator::evaluateReducedModel(optimizationResults,
|
||||||
|
// tileIntoSurfaceFilePath,
|
||||||
|
// scenariosDirPath,
|
||||||
|
// fullPatternTessellatedResultsDirPath);
|
||||||
|
// const double averageNormalizedErrorOfPattern
|
||||||
|
// = std::reduce(evaluationResults.distances_normalizedDrm2reduced.begin(),
|
||||||
|
// evaluationResults.distances_normalizedDrm2reduced.end())
|
||||||
|
// / evaluationResults.distances_normalizedDrm2reduced.size();
|
||||||
|
// const int patternIndex = &pPattern - &patterns[0];
|
||||||
|
// averageNormalizedError[patternIndex] = averageNormalizedErrorOfPattern;
|
||||||
|
// patternsEvaluationResults[patternIndex] = evaluationResults;
|
||||||
|
// });
|
||||||
|
// const double strategyAverageNormalizedError = std::reduce(std::execution::par_unseq,
|
||||||
|
// averageNormalizedError.begin(),
|
||||||
|
// averageNormalizedError.end())
|
||||||
|
// / pPointers.size();
|
||||||
|
// const auto totalDuration_min = std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
|
// std::chrono::high_resolution_clock::now() - start)
|
||||||
|
// .count()
|
||||||
|
// / 60.0;
|
||||||
|
// std::cout << "Optimized pattern(s) in:" << totalDuration_min << " minutes." << std::endl;
|
||||||
|
// std::cout << "Average time per pattern:" << totalDuration_min / patternsPointers.size()
|
||||||
|
// << " minutes." << std::endl;
|
||||||
|
// std::cout << "Objective value:" << strategyAverageNormalizedError << std::endl;
|
||||||
|
// return strategyAverageNormalizedError;
|
||||||
|
// // std::cout << "After:" << ++numberOfOptimizationRoundsExecuted << " iterations." << std::endl;
|
||||||
|
//}
|
||||||
|
|
||||||
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||||
ReducedModelOptimization::Results &optimizationResult)
|
ReducedModelOptimization::Results &optimizationResult)
|
||||||
{
|
{
|
||||||
const std::filesystem::path tileInto_triMesh_filePath
|
|
||||||
= "/home/iason/Coding/build/PatternTillingReducedModel/Meshes/"
|
|
||||||
"instantMeshes_plane_34.ply";
|
|
||||||
const std::filesystem::path scenariosDirectoryPath
|
const std::filesystem::path scenariosDirectoryPath
|
||||||
= "/home/iason/Coding/Projects/Approximating shapes with flat "
|
= "/home/iason/Coding/Projects/Approximating shapes with flat "
|
||||||
"patterns/ReducedModelEvaluator/Scenarios";
|
"patterns/ReducedModelEvaluator/Scenarios";
|
||||||
// const std::filesystem::path reducedPatternFilePath
|
|
||||||
// = "/home/iason/Coding/Projects/Approximating shapes with flat "
|
|
||||||
// "patterns/ReducedModelOptimization/TestSet/ReducedPatterns/single_reduced.ply";
|
|
||||||
const std::filesystem::path fullPatternTessellatedResultsDirectoryPath
|
const std::filesystem::path fullPatternTessellatedResultsDirectoryPath
|
||||||
= "/home/iason/Coding/Projects/Approximating shapes with flat "
|
= "/home/iason/Coding/Projects/Approximating shapes with flat "
|
||||||
"patterns/ReducedModelEvaluator/TessellatedResults";
|
"patterns/ReducedModelEvaluator/TessellatedResults";
|
||||||
|
|
||||||
return evaluateReducedModel(optimizationResult,
|
return evaluateReducedModel(optimizationResult,
|
||||||
tileInto_triMesh_filePath,
|
|
||||||
scenariosDirectoryPath,
|
scenariosDirectoryPath,
|
||||||
// reducedPatternFilePath,
|
|
||||||
fullPatternTessellatedResultsDirectoryPath);
|
fullPatternTessellatedResultsDirectoryPath);
|
||||||
}
|
}
|
||||||
//void ReducedModelEvaluator::printResults(const Results &evaluationResults,
|
//void ReducedModelEvaluator::printResults(const Results &evaluationResults,
|
||||||
|
|
@ -77,6 +128,7 @@ void ReducedModelEvaluator::printResults(const Results &evaluationResults,
|
||||||
csvFile &csvOutput)
|
csvFile &csvOutput)
|
||||||
{
|
{
|
||||||
if (settings.shouldWriteHeader) {
|
if (settings.shouldWriteHeader) {
|
||||||
|
csvOutput << csvExportingDataStrings[settings.exportingData];
|
||||||
printHeader(settings, csvOutput);
|
printHeader(settings, csvOutput);
|
||||||
// csvOutput << "Average error";
|
// csvOutput << "Average error";
|
||||||
// csvOutput<<"Cumulative error";
|
// csvOutput<<"Cumulative error";
|
||||||
|
|
@ -95,8 +147,6 @@ void ReducedModelEvaluator::printResults(const Results &evaluationResults,
|
||||||
void ReducedModelEvaluator::printHeader(const Settings &settings, csvFile &csvOutput)
|
void ReducedModelEvaluator::printHeader(const Settings &settings, csvFile &csvOutput)
|
||||||
{
|
{
|
||||||
if (settings.exportingDirection == Horizontal) {
|
if (settings.exportingDirection == Horizontal) {
|
||||||
csvOutput << csvExportingDataStrings[settings.exportingData];
|
|
||||||
csvOutput.endrow();
|
|
||||||
// csvOutput << "Job label";
|
// csvOutput << "Job label";
|
||||||
for (int jobIndex = 0; jobIndex < ReducedModelEvaluator::scenariosTestSetLabels.size();
|
for (int jobIndex = 0; jobIndex < ReducedModelEvaluator::scenariosTestSetLabels.size();
|
||||||
jobIndex++) {
|
jobIndex++) {
|
||||||
|
|
@ -213,50 +263,49 @@ void ReducedModelEvaluator::printResultsVertically(const Results &evaluationResu
|
||||||
csvOutput << endrow;
|
csvOutput << endrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void ReducedModelEvaluator::createFullAndReducedPatternTessellations(){
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
//ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||||
|
// std::vector<ReducedModelOptimization::Results> &optimizationResults,
|
||||||
|
// const std::filesystem::path &tileInto_triMesh_filePath,
|
||||||
|
// const std::filesystem::path &scenariosDirectoryPath,
|
||||||
|
// // const std::filesystem::path &reducedPatternFilePath,
|
||||||
|
// const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath)
|
||||||
|
//{
|
||||||
|
// //Load surface
|
||||||
|
// std::shared_ptr<VCGPolyMesh> pTileIntoSurface = [&]() {
|
||||||
|
// VCGTriMesh tileInto_triMesh;
|
||||||
|
// const bool surfaceLoadSuccessfull = tileInto_triMesh.load(tileInto_triMesh_filePath);
|
||||||
|
// assert(surfaceLoadSuccessfull);
|
||||||
|
// return PolygonalRemeshing::remeshWithPolygons(tileInto_triMesh);
|
||||||
|
// }();
|
||||||
|
// const double optimizedBaseTriangleHeight = vcg::Distance(optimizationResult.baseTriangle.cP(0),
|
||||||
|
// (optimizationResult.baseTriangle.cP(1)
|
||||||
|
// + optimizationResult.baseTriangle.cP(
|
||||||
|
// 2))
|
||||||
|
// / 2);
|
||||||
|
// pTileIntoSurface->moveToCenter();
|
||||||
|
// const double scaleFactor = optimizedBaseTriangleHeight
|
||||||
|
// / pTileIntoSurface->getAverageFaceRadius();
|
||||||
|
// vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor);
|
||||||
|
// //Tile full pattern into surface
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||||
ReducedModelOptimization::Results &optimizationResult,
|
ReducedModelOptimization::Results &optimizationResult,
|
||||||
const std::filesystem::path &tileInto_triMesh_filePath,
|
|
||||||
const std::filesystem::path &scenariosDirectoryPath,
|
const std::filesystem::path &scenariosDirectoryPath,
|
||||||
// const std::filesystem::path &reducedPatternFilePath,
|
|
||||||
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath)
|
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath)
|
||||||
{
|
{
|
||||||
// std::shared_ptr<VCGPolyMesh> pTileIntoSurface = std::make_shared<VCGPolyMesh>();
|
// const double optimizedBaseTriangleHeight = vcg::Distance(optimizationResult.baseTriangle.cP(0),
|
||||||
// std::filesystem::path tileIntoSurfaceFilePath{
|
// (optimizationResult.baseTriangle.cP(1)
|
||||||
// "/home/iason/Coding/Projects/Approximating shapes with flat "
|
// + optimizationResult.baseTriangle.cP(
|
||||||
// "patterns/ReducedModelOptimization/TestSet/TileIntoSurface/plane_34Polygons.ply"};
|
// 2))
|
||||||
// assert(std::filesystem::exists(tileIntoSurfaceFilePath));
|
// / 2);
|
||||||
// pTileIntoSurface->load(tileIntoSurfaceFilePath);
|
|
||||||
|
|
||||||
//Set required file paths
|
|
||||||
// const std::filesystem::path drmSettingsFilePath
|
|
||||||
// = "/home/iason/Coding/Projects/Approximating shapes with flat "
|
|
||||||
// "patterns/ReducedModelOptimization/DefaultSettings/DRMSettings/"
|
|
||||||
// "defaultDRMSimulationSettings.json";
|
|
||||||
DRMSimulationModel::Settings drmSimulationSettings;
|
|
||||||
drmSimulationSettings.totalExternalForcesNormPercentageTermination = 1e-3;
|
|
||||||
// drmSimulationSettings.load(drmSettingsFilePath);
|
|
||||||
drmSimulationSettings.linearGuessForceScaleFactor = 0.5;
|
|
||||||
drmSimulationSettings.debugModeStep = 10000;
|
|
||||||
drmSimulationSettings.beVerbose = true;
|
|
||||||
drmSimulationSettings.maxDRMIterations = 1e6;
|
|
||||||
// drmSimulationSettings.translationalKineticEnergyThreshold = 1e-15;
|
|
||||||
// drmSimulationSettings.viscousDampingFactor = 1e-2;
|
|
||||||
constexpr bool shouldRerunFullPatternSimulation = false;
|
|
||||||
|
|
||||||
//Load surface
|
|
||||||
std::shared_ptr<VCGPolyMesh> pTileIntoSurface = [&]() {
|
|
||||||
VCGTriMesh tileInto_triMesh;
|
|
||||||
const bool surfaceLoadSuccessfull = tileInto_triMesh.load(tileInto_triMesh_filePath);
|
|
||||||
assert(surfaceLoadSuccessfull);
|
|
||||||
return PolygonalRemeshing::remeshWithPolygons(tileInto_triMesh);
|
|
||||||
}();
|
|
||||||
const double optimizedBaseTriangleHeight = vcg::Distance(optimizationResult.baseTriangle.cP(0),
|
|
||||||
(optimizationResult.baseTriangle.cP(1)
|
|
||||||
+ optimizationResult.baseTriangle.cP(
|
|
||||||
2))
|
|
||||||
/ 2);
|
|
||||||
pTileIntoSurface->moveToCenter();
|
pTileIntoSurface->moveToCenter();
|
||||||
const double scaleFactor = optimizedBaseTriangleHeight
|
const double scaleFactor = optimizationResult.settings.targetBaseTriangleSize
|
||||||
/ pTileIntoSurface->getAverageFaceRadius();
|
/ pTileIntoSurface->getAverageFaceRadius();
|
||||||
vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor);
|
vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor);
|
||||||
// tileIntoSurface.registerForDrawing();
|
// tileIntoSurface.registerForDrawing();
|
||||||
|
|
@ -291,7 +340,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||||
std::vector<PatternGeometry> reducedPatterns(1);
|
std::vector<PatternGeometry> reducedPatterns(1);
|
||||||
reducedPatterns[0].copy(reducedModel);
|
reducedPatterns[0].copy(reducedModel);
|
||||||
const auto reducedPatternBaseTriangle = reducedModel.computeBaseTriangle();
|
const auto reducedPatternBaseTriangle = reducedModel.computeBaseTriangle();
|
||||||
ReducedModelOptimization::Results::applyOptimizationResults_innerHexagon(
|
ReducedModelOptimization::Results::applyOptimizationResults_reducedModel_nonFanned(
|
||||||
optimizationResult, reducedPatternBaseTriangle, reducedPatterns[0]);
|
optimizationResult, reducedPatternBaseTriangle, reducedPatterns[0]);
|
||||||
|
|
||||||
std::vector<std::vector<size_t>> perPatternIndexTiledReducedPatternEdgeIndices;
|
std::vector<std::vector<size_t>> perPatternIndexTiledReducedPatternEdgeIndices;
|
||||||
|
|
@ -345,139 +394,178 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||||
= perPatternIndexTiledReducedPatternEdgeIndices[0];
|
= perPatternIndexTiledReducedPatternEdgeIndices[0];
|
||||||
ReducedModelOptimization::Results::applyOptimizationResults_elements(
|
ReducedModelOptimization::Results::applyOptimizationResults_elements(
|
||||||
optimizationResult, pTiledReducedPattern_simulationMesh);
|
optimizationResult, pTiledReducedPattern_simulationMesh);
|
||||||
pTiledReducedPattern_simulationMesh->reset();
|
// pTiledReducedPattern_simulationMesh->reset();
|
||||||
Results evaluationResults;
|
Results evaluationResults;
|
||||||
evaluationResults.distances_drm2reduced.fill(-1);
|
evaluationResults.distances_drm2reduced.fill(-1);
|
||||||
evaluationResults.distances_normalizedDrm2reduced.fill(-1);
|
evaluationResults.distances_normalizedDrm2reduced.fill(-1);
|
||||||
for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) {
|
DRMSimulationModel::Settings drmSimulationSettings;
|
||||||
const std::string &jobLabel = scenariosTestSetLabels[jobIndex];
|
drmSimulationSettings.totalExternalForcesNormPercentageTermination = 1e-3;
|
||||||
const std::filesystem::path tiledReducedPatternJobFilePath
|
// drmSimulationSettings.load(drmSettingsFilePath);
|
||||||
= std::filesystem::path(scenariosDirectoryPath)
|
drmSimulationSettings.beVerbose = true;
|
||||||
.append(pTileIntoSurface->getLabel())
|
drmSimulationSettings.maxDRMIterations = 5e6;
|
||||||
.append(jobLabel)
|
drmSimulationSettings.debugModeStep = 100000;
|
||||||
.append("ReducedJob")
|
drmSimulationSettings.translationalKineticEnergyThreshold = 1e-15;
|
||||||
.append(SimulationJob::jsonDefaultFileName);
|
drmSimulationSettings.linearGuessForceScaleFactor = 0.8;
|
||||||
if (!std::filesystem::exists(tiledReducedPatternJobFilePath)) {
|
drmSimulationSettings.viscousDampingFactor = 7e-3;
|
||||||
std::cerr << "Scenario " << jobLabel
|
drmSimulationSettings.xi = 0.9999;
|
||||||
<< " not found in:" << tiledReducedPatternJobFilePath << std::endl;
|
// drmSimulationSettings.Dtini = 5.86;
|
||||||
continue;
|
drmSimulationSettings.gamma = 0.25;
|
||||||
}
|
#ifdef POLYSCOPE_DEFINED
|
||||||
//set jobs
|
// drmSimulationSettings.shouldDraw = true;
|
||||||
std::shared_ptr<SimulationJob> pJob_tiledReducedPattern;
|
drmSimulationSettings.shouldCreatePlots = true;
|
||||||
pJob_tiledReducedPattern = std::make_shared<SimulationJob>(SimulationJob());
|
#endif
|
||||||
pJob_tiledReducedPattern->load(tiledReducedPatternJobFilePath, false);
|
constexpr bool shouldRerunFullPatternSimulation = false;
|
||||||
pJob_tiledReducedPattern->pMesh = pTiledReducedPattern_simulationMesh;
|
// for (int jobIndex = 0; jobIndex < scenariosTestSetLabels.size(); jobIndex++) {
|
||||||
std::shared_ptr<SimulationJob> pJob_tiledFullPattern;
|
std::for_each(
|
||||||
pJob_tiledFullPattern = std::make_shared<SimulationJob>(SimulationJob());
|
//#ifndef POLYSCOPE_DEFINED
|
||||||
pJob_tiledFullPattern->pMesh = pTiledFullPattern_simulationMesh;
|
// std::execution::par_unseq,
|
||||||
pJob_tiledReducedPattern->remap(reducedToFullViMap, *pJob_tiledFullPattern);
|
//#endif
|
||||||
// pJob_tiledReducedPattern->registerForDrawing(pTiledReducedPattern->getLabel());
|
scenariosTestSetLabels.begin(),
|
||||||
// pJob_tiledFullPattern->registerForDrawing(pTiledFullPattern->getLabel());
|
scenariosTestSetLabels.end(),
|
||||||
// polyscope::show();
|
[&](const std::string &jobLabel) {
|
||||||
//Save reduced job
|
//check if reduced model scenario exists
|
||||||
|
// const std::string &jobLabel = scenariosTestSetLabels[jobIndex];
|
||||||
|
const std::filesystem::path tiledReducedPatternJobFilePath
|
||||||
|
= std::filesystem::path(scenariosDirectoryPath)
|
||||||
|
.append(pTileIntoSurface->getLabel())
|
||||||
|
.append(jobLabel)
|
||||||
|
.append("ReducedJob")
|
||||||
|
.append(SimulationJob::jsonDefaultFileName);
|
||||||
|
if (!std::filesystem::exists(tiledReducedPatternJobFilePath)) {
|
||||||
|
std::cerr << "Scenario " << jobLabel
|
||||||
|
<< " not found in:" << tiledReducedPatternJobFilePath << std::endl;
|
||||||
|
// continue; //if not move on to the next scenario
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Map the reduced job to the job on the pattern tessellation
|
||||||
|
//set jobs
|
||||||
|
std::shared_ptr<SimulationJob> pJob_tiledReducedPattern;
|
||||||
|
pJob_tiledReducedPattern = std::make_shared<SimulationJob>(SimulationJob());
|
||||||
|
pJob_tiledReducedPattern->load(tiledReducedPatternJobFilePath, false);
|
||||||
|
pJob_tiledReducedPattern->pMesh = pTiledReducedPattern_simulationMesh;
|
||||||
|
std::shared_ptr<SimulationJob> pJob_tiledFullPattern;
|
||||||
|
pJob_tiledFullPattern = std::make_shared<SimulationJob>(SimulationJob());
|
||||||
|
pJob_tiledFullPattern->pMesh = pTiledFullPattern_simulationMesh;
|
||||||
|
pJob_tiledReducedPattern->remap(reducedToFullViMap, *pJob_tiledFullPattern);
|
||||||
|
// pJob_tiledReducedPattern->registerForDrawing(pTiledReducedPattern->getLabel());
|
||||||
|
// pJob_tiledFullPattern->registerForDrawing(pTiledFullPattern->getLabel());
|
||||||
|
// polyscope::show();
|
||||||
|
const std::filesystem::path surfaceFolderPath
|
||||||
|
= std::filesystem::path(fullPatternTessellatedResultsDirectoryPath)
|
||||||
|
.append(pTileIntoSurface->getLabel());
|
||||||
|
const std::string scenarioLabel = pJob_tiledFullPattern->getLabel();
|
||||||
|
const std::filesystem::path scenarioDirectoryPath
|
||||||
|
= std::filesystem::path(surfaceFolderPath).append(scenarioLabel);
|
||||||
|
//Save reduced job
|
||||||
|
constexpr bool exportReducedJob = false;
|
||||||
|
if (exportReducedJob) {
|
||||||
|
const std::filesystem::path reducedJobDirectoryPath
|
||||||
|
= std::filesystem::path(scenarioDirectoryPath).append("ReducedJob");
|
||||||
|
std::filesystem::create_directories(reducedJobDirectoryPath);
|
||||||
|
pJob_tiledReducedPattern->save(reducedJobDirectoryPath);
|
||||||
|
}
|
||||||
|
//Check if the drm simulation of the full pattern has already been computed
|
||||||
|
////Full
|
||||||
|
const std::string &patternLabel = [&]() {
|
||||||
|
const std::string patternLabel = optimizationResult.baseTriangleFullPattern
|
||||||
|
.getLabel();
|
||||||
|
if (patternLabel.find("_") == std::string::npos) {
|
||||||
|
return std::to_string(optimizationResult.baseTriangleFullPattern.EN()) + "_"
|
||||||
|
+ patternLabel;
|
||||||
|
} else {
|
||||||
|
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 std::filesystem::path surfaceFolderPath
|
const std::filesystem::path fullPatternJobFolderPath = std::filesystem::path(
|
||||||
= std::filesystem::path(fullPatternTessellatedResultsDirectoryPath)
|
scenarioDirectoryPath)
|
||||||
.append(pTileIntoSurface->getLabel());
|
.append(patternLabel)
|
||||||
const std::string scenarioLabel = pJob_tiledFullPattern->getLabel();
|
.append("SimulationJob");
|
||||||
const std::filesystem::path scenarioDirectoryPath = std::filesystem::path(surfaceFolderPath)
|
SimulationResults simulationResults_tiledFullPattern_drm;
|
||||||
.append(scenarioLabel);
|
if (std::filesystem::exists(fullResultsFolderPath)) {
|
||||||
const std::filesystem::path reducedJobDirectoryPath
|
//Load full pattern results
|
||||||
= std::filesystem::path(scenarioDirectoryPath).append("ReducedJob");
|
assert(std::filesystem::exists(fullPatternJobFolderPath));
|
||||||
std::filesystem::create_directories(reducedJobDirectoryPath);
|
simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath,
|
||||||
pJob_tiledReducedPattern->save(reducedJobDirectoryPath);
|
fullPatternJobFolderPath);
|
||||||
//Run scenario
|
//#ifdef POLYSCOPE_DEFINED
|
||||||
////Full
|
// std::array<double, 3> resultsColor({28.0, 99.0, 227.0});
|
||||||
// const std::string patternLabel = std::to_string(
|
// simulationResults_tiledFullPattern_drm.registerForDrawing(resultsColor);
|
||||||
// optimizationResult.baseTriangleFullPattern.EN())
|
// std::ifstream ifs("CameraSettings.json");
|
||||||
// + "_"
|
// nlohmann::json json;
|
||||||
// + optimizationResult.baseTriangleFullPattern.getLabel();
|
// ifs >> json;
|
||||||
const std::string &patternLabel = optimizationResult.baseTriangleFullPattern.getLabel();
|
// polyscope::view::setCameraFromJson(json.dump(), false);
|
||||||
const auto fullResultsFolderPath
|
// // polyscope::show();
|
||||||
= std::filesystem::path(scenarioDirectoryPath).append(patternLabel).append("Results");
|
// const std::string cameraJson = polyscope::view::getCameraJson();
|
||||||
if (shouldRerunFullPatternSimulation && std::filesystem::exists(fullResultsFolderPath)) {
|
// std::filesystem::path jsonFilePath("CameraSettings.json");
|
||||||
std::filesystem::remove_all(fullResultsFolderPath);
|
// std::ofstream jsonFile_cameraSettings(jsonFilePath.string());
|
||||||
}
|
// jsonFile_cameraSettings << cameraJson;
|
||||||
|
// jsonFile_cameraSettings.close();
|
||||||
|
// std::filesystem::create_directories("screenshots");
|
||||||
|
// const std::string screenshotOutputFilePath
|
||||||
|
// = (std::filesystem::current_path()
|
||||||
|
// .append("screenshots")
|
||||||
|
// .append(optimizationResult.label + "_" + pJob_tiledFullPattern->getLabel()))
|
||||||
|
// .string()
|
||||||
|
// + ".png";
|
||||||
|
// // std::cout << "Saving image to:" << screenshotOutputFilePath << std::endl;
|
||||||
|
// polyscope::screenshot(screenshotOutputFilePath, false);
|
||||||
|
// simulationResults_tiledFullPattern_drm.unregister();
|
||||||
|
//#endif
|
||||||
|
|
||||||
const std::filesystem::path fullPatternJobFolderPath = std::filesystem::path(
|
simulationResults_tiledFullPattern_drm.converged = true;
|
||||||
scenarioDirectoryPath)
|
} else {
|
||||||
.append(patternLabel)
|
std::cout << "Drm results not found in:" << fullResultsFolderPath << std::endl;
|
||||||
.append("SimulationJob");
|
//Full
|
||||||
SimulationResults simulationResults_tiledFullPattern_drm;
|
std::cout << "Executing:" << jobLabel << std::endl;
|
||||||
if (std::filesystem::exists(fullResultsFolderPath)) {
|
DRMSimulationModel drmSimulationModel;
|
||||||
//Load full pattern results
|
simulationResults_tiledFullPattern_drm
|
||||||
assert(std::filesystem::exists(fullPatternJobFolderPath));
|
= drmSimulationModel.executeSimulation(pJob_tiledFullPattern,
|
||||||
simulationResults_tiledFullPattern_drm.load(fullResultsFolderPath,
|
drmSimulationSettings);
|
||||||
fullPatternJobFolderPath);
|
simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM");
|
||||||
//#ifdef POLYSCOPE_DEFINED
|
}
|
||||||
// std::array<double, 3> resultsColor({28.0, 99.0, 227.0});
|
if (!simulationResults_tiledFullPattern_drm.converged) {
|
||||||
// simulationResults_tiledFullPattern_drm.registerForDrawing(resultsColor);
|
std::cerr << "Full pattern simulation failed." << std::endl;
|
||||||
// std::ifstream ifs("CameraSettings.json");
|
std::cerr << "Not saving results" << std::endl;
|
||||||
// nlohmann::json json;
|
// continue;
|
||||||
// ifs >> json;
|
return;
|
||||||
// polyscope::view::setCameraFromJson(json.dump(), false);
|
}
|
||||||
// // polyscope::show();
|
std::filesystem::create_directories(fullResultsFolderPath);
|
||||||
// const std::string cameraJson = polyscope::view::getCameraJson();
|
const std::filesystem::path drmResultsOutputPath
|
||||||
// std::filesystem::path jsonFilePath("CameraSettings.json");
|
= std::filesystem::path(scenarioDirectoryPath).append(patternLabel);
|
||||||
// std::ofstream jsonFile_cameraSettings(jsonFilePath.string());
|
simulationResults_tiledFullPattern_drm.save(drmResultsOutputPath);
|
||||||
// jsonFile_cameraSettings << cameraJson;
|
|
||||||
// jsonFile_cameraSettings.close();
|
|
||||||
// std::filesystem::create_directories("screenshots");
|
|
||||||
// const std::string screenshotOutputFilePath
|
|
||||||
// = (std::filesystem::current_path()
|
|
||||||
// .append("screenshots")
|
|
||||||
// .append(optimizationResult.label + "_" + pJob_tiledFullPattern->getLabel()))
|
|
||||||
// .string()
|
|
||||||
// + ".png";
|
|
||||||
// // std::cout << "Saving image to:" << screenshotOutputFilePath << std::endl;
|
|
||||||
// polyscope::screenshot(screenshotOutputFilePath, false);
|
|
||||||
// simulationResults_tiledFullPattern_drm.unregister();
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
simulationResults_tiledFullPattern_drm.converged = true;
|
LinearSimulationModel linearSimulationModel;
|
||||||
} else {
|
SimulationResults simulationResults_tiledReducedPattern
|
||||||
std::cout << "Drm results not found in:" << fullResultsFolderPath << std::endl;
|
= linearSimulationModel.executeSimulation(pJob_tiledReducedPattern);
|
||||||
//Full
|
|
||||||
std::cout << "Executing:" << jobLabel << std::endl;
|
|
||||||
DRMSimulationModel drmSimulationModel;
|
|
||||||
simulationResults_tiledFullPattern_drm
|
|
||||||
= drmSimulationModel.executeSimulation(pJob_tiledFullPattern, drmSimulationSettings);
|
|
||||||
simulationResults_tiledFullPattern_drm.setLabelPrefix("DRM");
|
|
||||||
}
|
|
||||||
std::filesystem::create_directories(fullResultsFolderPath);
|
|
||||||
const std::filesystem::path drmResultsOutputPath
|
|
||||||
= std::filesystem::path(scenarioDirectoryPath).append(patternLabel);
|
|
||||||
simulationResults_tiledFullPattern_drm.save(drmResultsOutputPath);
|
|
||||||
if (!simulationResults_tiledFullPattern_drm.converged) {
|
|
||||||
std::cerr << "Full pattern simulation failed." << std::endl;
|
|
||||||
std::cerr << "Saved failed simulation to:" << drmResultsOutputPath << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearSimulationModel linearSimulationModel;
|
// simulationResults_tiledReducedPattern.registerForDrawing();
|
||||||
SimulationResults simulationResults_tiledReducedPattern
|
// simulationResults_tiledFullPattern_drm.registerForDrawing();
|
||||||
= linearSimulationModel.executeSimulation(pJob_tiledReducedPattern);
|
// polyscope::show();
|
||||||
|
|
||||||
// simulationResults_tiledReducedPattern.registerForDrawing();
|
//compute the full2reduced distance
|
||||||
// simulationResults_tiledFullPattern_drm.registerForDrawing();
|
const double distance_fullDrmToReduced
|
||||||
// polyscope::show();
|
= simulationResults_tiledFullPattern_drm
|
||||||
//measure distance
|
.computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap);
|
||||||
const double distance_fullDrmToReduced
|
double distance_fullSumOfAllVerts = 0;
|
||||||
= simulationResults_tiledFullPattern_drm
|
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
|
||||||
.computeDistance(simulationResults_tiledReducedPattern, fullToReducedViMap);
|
distance_fullSumOfAllVerts += simulationResults_tiledFullPattern_drm
|
||||||
double distance_fullSumOfAllVerts = 0;
|
.displacements[fullToReducedPair.first]
|
||||||
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
|
.getTranslation()
|
||||||
distance_fullSumOfAllVerts += simulationResults_tiledFullPattern_drm
|
.norm();
|
||||||
.displacements[fullToReducedPair.first]
|
}
|
||||||
.getTranslation()
|
const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced
|
||||||
.norm();
|
/ distance_fullSumOfAllVerts;
|
||||||
}
|
const int jobIndex = &jobLabel - &scenariosTestSetLabels[0];
|
||||||
const double distance_normalizedFullDrmToReduced = distance_fullDrmToReduced
|
evaluationResults.distances_drm2reduced[jobIndex] = distance_fullDrmToReduced;
|
||||||
/ distance_fullSumOfAllVerts;
|
evaluationResults.distances_normalizedDrm2reduced[jobIndex]
|
||||||
evaluationResults.distances_drm2reduced[jobIndex] = distance_fullDrmToReduced;
|
= distance_normalizedFullDrmToReduced;
|
||||||
evaluationResults.distances_normalizedDrm2reduced[jobIndex]
|
});
|
||||||
= distance_normalizedFullDrmToReduced;
|
|
||||||
}
|
|
||||||
|
|
||||||
return evaluationResults;
|
return evaluationResults;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,12 @@ public:
|
||||||
std::array<std::string, NumberOfEvaluationScenarios> evaluationScenarioLabels;
|
std::array<std::string, NumberOfEvaluationScenarios> evaluationScenarioLabels;
|
||||||
};
|
};
|
||||||
ReducedModelEvaluator();
|
ReducedModelEvaluator();
|
||||||
static Results evaluateReducedModel(
|
Results evaluateReducedModel(
|
||||||
ReducedModelOptimization::Results &optimizationResult,
|
ReducedModelOptimization::Results &optimizationResult,
|
||||||
const std::filesystem::path &tileInto_triMesh_filePath,
|
|
||||||
const std::filesystem::path &scenariosDirectoryPath,
|
const std::filesystem::path &scenariosDirectoryPath,
|
||||||
// const std::filesystem::path &reducedPatternFilePath,
|
// const std::filesystem::path &reducedPatternFilePath,
|
||||||
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath);
|
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath);
|
||||||
static Results evaluateReducedModel(ReducedModelOptimization::Results &optimizationResult);
|
Results evaluateReducedModel(ReducedModelOptimization::Results &optimizationResult);
|
||||||
static void printResultsVertically(const ReducedModelEvaluator::Results &evaluationResults,
|
static void printResultsVertically(const ReducedModelEvaluator::Results &evaluationResults,
|
||||||
csvFile &csvOutput);
|
csvFile &csvOutput);
|
||||||
static void printResults(const ReducedModelEvaluator::Results &evaluationResults,
|
static void printResults(const ReducedModelEvaluator::Results &evaluationResults,
|
||||||
|
|
@ -93,6 +92,126 @@ public:
|
||||||
const Settings &settings,
|
const Settings &settings,
|
||||||
csvFile &csvOutput);
|
csvFile &csvOutput);
|
||||||
static void printHeader(const Settings &settings, csvFile &csvOutput);
|
static void printHeader(const Settings &settings, csvFile &csvOutput);
|
||||||
|
// static double evaluateOptimizationSettings(
|
||||||
|
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||||
|
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||||
|
// std::vector<ReducedModelEvaluator::Results> &patternEvaluationResults);
|
||||||
|
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
||||||
|
inline static constexpr char *tileIntoSurfaceFileContent = R"~(OFF
|
||||||
|
46 66 0
|
||||||
|
-0.0745923 0.03573945 0
|
||||||
|
-0.07464622 0.02191801 0
|
||||||
|
-0.06264956 0.02878203 0
|
||||||
|
-0.08658896 0.02887542 0
|
||||||
|
-0.06270347 0.01496059 0
|
||||||
|
-0.06259564 0.04260346 0
|
||||||
|
-0.08664289 0.01505398 0
|
||||||
|
-0.08653505 0.04269686 0
|
||||||
|
-0.0507068 0.02182462 0
|
||||||
|
-0.07453838 0.04956088 0
|
||||||
|
-0.05065288 0.03564605 0
|
||||||
|
-0.09858564 0.02201139 0
|
||||||
|
-0.09853172 0.03583283 0
|
||||||
|
-0.06254172 0.0564249 0
|
||||||
|
-0.05059896 0.04946748 0
|
||||||
|
-0.08648112 0.0565183 0
|
||||||
|
-0.09847781 0.04965428 0
|
||||||
|
-0.03871013 0.02868864 0
|
||||||
|
-0.07448447 0.06338232 0
|
||||||
|
-0.03865621 0.04251007 0
|
||||||
|
-0.1105284 0.02896881 0
|
||||||
|
-0.1104745 0.04279025 0
|
||||||
|
-0.03876406 0.0148672 0
|
||||||
|
-0.05054504 0.06328891 0
|
||||||
|
-0.0624878 0.07024634 0
|
||||||
|
-0.03860229 0.0563315 0
|
||||||
|
-0.1105823 0.01514738 0
|
||||||
|
-0.08642721 0.07033974 0
|
||||||
|
-0.09842389 0.06347572 0
|
||||||
|
-0.1104206 0.05661169 0
|
||||||
|
-0.07443054 0.07720376 0
|
||||||
|
-0.05049112 0.07711035 0
|
||||||
|
-0.03854837 0.07015293 0
|
||||||
|
-0.06243387 0.08406778 0
|
||||||
|
-0.08637329 0.08416118 0
|
||||||
|
-0.09836997 0.07729716 0
|
||||||
|
-0.1103666 0.07043312 0
|
||||||
|
-0.07437663 0.09102518 0
|
||||||
|
-0.03849445 0.08397438 0
|
||||||
|
-0.0504372 0.0909318 0
|
||||||
|
-0.06237995 0.09788923 0
|
||||||
|
-0.08631937 0.09798261 0
|
||||||
|
-0.09831604 0.09111859 0
|
||||||
|
-0.1103127 0.08425456 0
|
||||||
|
-0.03844052 0.09779582 0
|
||||||
|
-0.1102588 0.09807601 0
|
||||||
|
3 0 1 2
|
||||||
|
3 3 1 0
|
||||||
|
3 4 2 1
|
||||||
|
3 5 0 2
|
||||||
|
3 3 6 1
|
||||||
|
3 3 0 7
|
||||||
|
3 8 2 4
|
||||||
|
3 5 9 0
|
||||||
|
3 10 5 2
|
||||||
|
3 3 11 6
|
||||||
|
3 7 0 9
|
||||||
|
3 12 3 7
|
||||||
|
3 10 2 8
|
||||||
|
3 5 13 9
|
||||||
|
3 10 14 5
|
||||||
|
3 12 11 3
|
||||||
|
3 7 9 15
|
||||||
|
3 12 7 16
|
||||||
|
3 10 8 17
|
||||||
|
3 14 13 5
|
||||||
|
3 18 9 13
|
||||||
|
3 19 14 10
|
||||||
|
3 12 20 11
|
||||||
|
3 18 15 9
|
||||||
|
3 16 7 15
|
||||||
|
3 21 12 16
|
||||||
|
3 22 17 8
|
||||||
|
3 19 10 17
|
||||||
|
3 23 13 14
|
||||||
|
3 18 13 24
|
||||||
|
3 19 25 14
|
||||||
|
3 21 20 12
|
||||||
|
3 26 11 20
|
||||||
|
3 18 27 15
|
||||||
|
3 16 15 28
|
||||||
|
3 21 16 29
|
||||||
|
3 23 24 13
|
||||||
|
3 23 14 25
|
||||||
|
3 30 18 24
|
||||||
|
3 30 27 18
|
||||||
|
3 15 27 28
|
||||||
|
3 29 16 28
|
||||||
|
3 23 31 24
|
||||||
|
3 23 25 32
|
||||||
|
3 30 24 33
|
||||||
|
3 30 34 27
|
||||||
|
3 35 28 27
|
||||||
|
3 29 28 36
|
||||||
|
3 23 32 31
|
||||||
|
3 24 31 33
|
||||||
|
3 30 33 37
|
||||||
|
3 30 37 34
|
||||||
|
3 35 27 34
|
||||||
|
3 35 36 28
|
||||||
|
3 32 38 31
|
||||||
|
3 33 31 39
|
||||||
|
3 40 37 33
|
||||||
|
3 34 37 41
|
||||||
|
3 35 34 42
|
||||||
|
3 35 43 36
|
||||||
|
3 38 39 31
|
||||||
|
3 40 33 39
|
||||||
|
3 34 41 42
|
||||||
|
3 35 42 43
|
||||||
|
3 44 39 38
|
||||||
|
3 45 43 42
|
||||||
|
)~";
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REDUCEDMODELEVALUATOR_HPP
|
#endif // REDUCEDMODELEVALUATOR_HPP
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue