Removed some scenarios. Scaling the forces of the scenarios
This commit is contained in:
parent
6e08bc039b
commit
db8aa4124e
|
|
@ -26,7 +26,8 @@ ReducedModelEvaluator::ReducedModelEvaluator() {
|
|||
}
|
||||
|
||||
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult) {
|
||||
ReducedModelOptimization::Results& optimizationResult,
|
||||
const Settings& settings) {
|
||||
const std::filesystem::path scenariosDirectoryPath =
|
||||
"/home/iason/Coding/Projects/Approximating shapes with flat "
|
||||
"patterns/ReducedModelEvaluator/Scenarios";
|
||||
|
|
@ -35,40 +36,43 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
"patterns/ReducedModelEvaluator/TessellatedResults";
|
||||
|
||||
return evaluateReducedModel(optimizationResult, scenariosDirectoryPath,
|
||||
fullPatternTessellatedResultsDirectoryPath);
|
||||
fullPatternTessellatedResultsDirectoryPath,
|
||||
settings);
|
||||
}
|
||||
|
||||
void ReducedModelEvaluator::printResults(const Results& evaluationResults,
|
||||
const std::string& resultsLabel) {
|
||||
csvFile csvOutputToCout({}, true);
|
||||
Settings exportSettings;
|
||||
exportSettings.exportingDirection = Vertical;
|
||||
CSVFile csvOutputToCout({}, true);
|
||||
ExportingSettings exportSettings;
|
||||
exportSettings.direction = Vertical;
|
||||
exportSettings.shouldWriteHeader = false;
|
||||
exportSettings.resultsLabel = resultsLabel;
|
||||
printResults(evaluationResults, exportSettings, csvOutputToCout);
|
||||
}
|
||||
|
||||
void ReducedModelEvaluator::printResults(const Results& evaluationResults,
|
||||
const Settings& settings,
|
||||
csvFile& csvOutput) {
|
||||
if (settings.shouldWriteHeader) {
|
||||
csvOutput << csvExportingDataStrings[settings.exportingData];
|
||||
printHeader(settings, csvOutput);
|
||||
void ReducedModelEvaluator::printResults(
|
||||
const Results& evaluationResults,
|
||||
const ExportingSettings& exportingSettings,
|
||||
CSVFile& csvOutput) {
|
||||
if (exportingSettings.shouldWriteHeader) {
|
||||
csvOutput << csvExportingDataStrings[exportingSettings.data];
|
||||
printHeader(exportingSettings, csvOutput);
|
||||
csvOutput << endrow;
|
||||
}
|
||||
if (!settings.resultsLabel.empty()) {
|
||||
csvOutput << settings.resultsLabel;
|
||||
if (!exportingSettings.resultsLabel.empty()) {
|
||||
csvOutput << exportingSettings.resultsLabel;
|
||||
}
|
||||
if (settings.exportingDirection == Vertical) {
|
||||
if (exportingSettings.direction == Vertical) {
|
||||
printResultsVertically(evaluationResults, csvOutput);
|
||||
} else {
|
||||
printResultsHorizontally(evaluationResults, csvOutput);
|
||||
}
|
||||
}
|
||||
|
||||
void ReducedModelEvaluator::printHeader(const Settings& settings,
|
||||
csvFile& csvOutput) {
|
||||
if (settings.exportingDirection == Horizontal) {
|
||||
void ReducedModelEvaluator::printHeader(
|
||||
const ExportingSettings& exportingSettings,
|
||||
CSVFile& csvOutput) {
|
||||
if (exportingSettings.direction == Horizontal) {
|
||||
// csvOutput << "Job label";
|
||||
for (int jobIndex = 0;
|
||||
jobIndex < ReducedModelEvaluator::scenariosTestSetLabels.size();
|
||||
|
|
@ -86,7 +90,7 @@ void ReducedModelEvaluator::printHeader(const Settings& settings,
|
|||
|
||||
void ReducedModelEvaluator::printResultsHorizontally(
|
||||
const Results& evaluationResults,
|
||||
csvFile& csvOutput) {
|
||||
CSVFile& csvOutput) {
|
||||
// print header
|
||||
// print raw error
|
||||
constexpr bool shouldPrintRawError = false;
|
||||
|
|
@ -113,7 +117,7 @@ void ReducedModelEvaluator::printResultsHorizontally(
|
|||
jobIndex < ReducedModelEvaluator::scenariosTestSetLabels.size();
|
||||
jobIndex++) {
|
||||
const double& distance_normalizedFullDrmToReduced =
|
||||
evaluationResults.distances_normalizedDrm2reduced[jobIndex];
|
||||
evaluationResults.distances_normalizedGroundTruth2reduced[jobIndex];
|
||||
if (distance_normalizedFullDrmToReduced == -1) {
|
||||
csvOutput << "notEvaluated";
|
||||
} else {
|
||||
|
|
@ -125,7 +129,7 @@ void ReducedModelEvaluator::printResultsHorizontally(
|
|||
|
||||
void ReducedModelEvaluator::printResultsVertically(
|
||||
const Results& evaluationResults,
|
||||
csvFile& csvOutput) {
|
||||
CSVFile& csvOutput) {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
csvOutput << "pattern2Reduced"
|
||||
<< "norm_pattern2Reduced";
|
||||
|
|
@ -145,7 +149,7 @@ void ReducedModelEvaluator::printResultsVertically(
|
|||
const double& distance_fullDrmToReduced =
|
||||
evaluationResults.distances_drm2reduced[jobIndex];
|
||||
const double& distance_normalizedFullDrmToReduced =
|
||||
evaluationResults.distances_normalizedDrm2reduced[jobIndex];
|
||||
evaluationResults.distances_normalizedGroundTruth2reduced[jobIndex];
|
||||
#ifndef POLYSCOPE_DEFINED
|
||||
const std::string& jobLabel =
|
||||
ReducedModelEvaluator::scenariosTestSetLabels[jobIndex];
|
||||
|
|
@ -187,7 +191,9 @@ void ReducedModelEvaluator::printResultsVertically(
|
|||
ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult,
|
||||
const std::filesystem::path& scenariosDirectoryPath,
|
||||
const std::filesystem::path& patternTessellatedResultsDirectoryPath) {
|
||||
const std::filesystem::path& patternTessellatedResultsDirectoryPath,
|
||||
const ReducedModelEvaluator::Settings& evaluationSettings) {
|
||||
std::cout << evaluationSettings.toString() << std::endl;
|
||||
// Apply optimization results to the reduced model
|
||||
ReducedModel reducedModel;
|
||||
reducedModel.deleteDanglingVertices();
|
||||
|
|
@ -207,7 +213,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
pTileIntoSurface->getAverageFaceRadius();
|
||||
vcg::tri::UpdatePosition<VCGPolyMesh>::Scale(*pTileIntoSurface, scaleFactor);
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
pTileIntoSurface->registerForDrawing(color_tileIntoSurface);
|
||||
pTileIntoSurface->registerForDrawing(color_tileIntoSurface, false);
|
||||
#endif
|
||||
|
||||
// Tile full pattern into surface
|
||||
|
|
@ -239,20 +245,20 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
pTilled_reducedModel->setLabel("Tilled_reduced_model");
|
||||
|
||||
std::unordered_map<PatternVertexIndex, ReducedModelVertexIndex>
|
||||
fullToReducedViMap; // of only the common vertices
|
||||
patternToReducedViMap; // of only the common vertices
|
||||
std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>
|
||||
reducedToFullViMap; // of only the common vertices
|
||||
for (int ei = 0; ei < pTileIntoSurface->EN(); ei++) {
|
||||
fullToReducedViMap[tileIntoEdgeToTiledFullVi[ei]] =
|
||||
patternToReducedViMap[tileIntoEdgeToTiledFullVi[ei]] =
|
||||
tileIntoEdgeToTiledReducedVi[ei];
|
||||
}
|
||||
constructInverseMap(fullToReducedViMap, reducedToFullViMap);
|
||||
constructInverseMap(patternToReducedViMap, reducedToFullViMap);
|
||||
|
||||
std::vector<size_t> tilledFullPatternInterfaceVi;
|
||||
tilledFullPatternInterfaceVi.clear();
|
||||
tilledFullPatternInterfaceVi.resize(fullToReducedViMap.size());
|
||||
tilledFullPatternInterfaceVi.resize(patternToReducedViMap.size());
|
||||
size_t viIndex = 0;
|
||||
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
|
||||
for (std::pair<size_t, size_t> fullToReducedPair : patternToReducedViMap) {
|
||||
tilledFullPatternInterfaceVi[viIndex++] = fullToReducedPair.first;
|
||||
}
|
||||
|
||||
|
|
@ -284,17 +290,19 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
pSimulationEdgeMesh_tilledReducedModel->reset();
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
pSimulationEdgeMesh_tilledReducedModel->registerForDrawing(
|
||||
color_tesselatedReducedModels);
|
||||
polyscope::show();
|
||||
color_tesselatedReducedModels, false,
|
||||
pSimulationEdgeMesh_tilledPattern->elements[0]
|
||||
.dimensions.getDrawingRadius());
|
||||
#endif
|
||||
|
||||
Results evaluationResults;
|
||||
evaluationResults.evaluationScenarioLabels = scenariosTestSetLabels;
|
||||
evaluationResults.distances_drm2reduced.fill(-1);
|
||||
evaluationResults.distances_normalizedDrm2reduced.fill(-1);
|
||||
evaluationResults.distances_normalizedGroundTruth2reduced.fill(-1);
|
||||
DRMSimulationModel::Settings drmSimulationSettings;
|
||||
// drmSimulationSettings.threshold_residualToExternalForcesNorm = 1e-3;
|
||||
// drmSimulationSettings.load(drmSettingsFilePath);
|
||||
drmSimulationSettings.beVerbose = true;
|
||||
drmSimulationSettings.beVerbose = evaluationSettings.beVerbose;
|
||||
drmSimulationSettings.maxDRMIterations = 5e6;
|
||||
drmSimulationSettings.debugModeStep = 100000;
|
||||
drmSimulationSettings.threshold_totalTranslationalKineticEnergy = 1e-14;
|
||||
|
|
@ -309,22 +317,17 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
#ifdef POLYSCOPE_DEFINED
|
||||
// drmSimulationSettings.shouldDraw = true;
|
||||
drmSimulationSettings.shouldCreatePlots = false;
|
||||
constexpr bool shouldDrawScenarioResults = true;
|
||||
if (shouldDrawScenarioResults) {
|
||||
if (evaluationSettings.shouldDraw) {
|
||||
pSimulationEdgeMesh_tilledPattern->registerForDrawing(
|
||||
ReducedModelOptimization::Colors::patternInitial);
|
||||
ReducedModelOptimization::Colors::patternInitial, true);
|
||||
}
|
||||
#endif
|
||||
const std::string& simulationModelLabel_pattern =
|
||||
optimizationResult.settings.simulationModelLabel_groundTruth;
|
||||
const std::string& simulationModelLabel_reducedModel =
|
||||
optimizationResult.settings.simulationModelLabel_reducedModel;
|
||||
const bool shouldRerunFullPatternSimulation = [&]() {
|
||||
// if (simulationModelLabel_pattern == DRMSimulationModel::label) {
|
||||
return false;
|
||||
// }
|
||||
// return true;
|
||||
}();
|
||||
// ChronosEulerLinearSimulationModel::label;
|
||||
|
||||
std::for_each(
|
||||
#ifndef POLYSCOPE_DEFINED
|
||||
std::execution::par_unseq,
|
||||
|
|
@ -341,9 +344,11 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
.append("ReducedJob")
|
||||
.append(SimulationJob::jsonDefaultFileName);
|
||||
if (!std::filesystem::exists(tiledReducedPatternJobFilePath)) {
|
||||
std::cerr << "Scenario " << jobLabel
|
||||
<< " not found in:" << tiledReducedPatternJobFilePath
|
||||
<< std::endl;
|
||||
if (evaluationSettings.beVerbose) {
|
||||
std::cerr << "Scenario " << jobLabel
|
||||
<< " not found in:" << tiledReducedPatternJobFilePath
|
||||
<< std::endl;
|
||||
}
|
||||
// continue; //if not move on to the next scenario
|
||||
return;
|
||||
}
|
||||
|
|
@ -353,6 +358,12 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
pJob_tiledReducedModel =
|
||||
std::make_shared<SimulationJob>(SimulationJob());
|
||||
pJob_tiledReducedModel->load(tiledReducedPatternJobFilePath, false);
|
||||
std::for_each(pJob_tiledReducedModel->nodalExternalForces.begin(),
|
||||
pJob_tiledReducedModel->nodalExternalForces.end(),
|
||||
[&](std::pair<const VertexIndex, Vector6d>& viForcePair) {
|
||||
viForcePair.second =
|
||||
viForcePair.second * forceScalingFactor;
|
||||
});
|
||||
pJob_tiledReducedModel->pMesh = pSimulationEdgeMesh_tilledReducedModel;
|
||||
std::shared_ptr<SimulationJob> pJob_tilledPattern;
|
||||
pJob_tilledPattern = std::make_shared<SimulationJob>(SimulationJob());
|
||||
|
|
@ -393,7 +404,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
std::filesystem::path(scenarioDirectoryPath)
|
||||
.append(patternLabel)
|
||||
.append("Results");
|
||||
if (shouldRerunFullPatternSimulation &&
|
||||
if (evaluationSettings.shouldRecomputeGroundTruthResults &&
|
||||
std::filesystem::exists(tilledPatternResultsFolderPath)) {
|
||||
std::filesystem::remove_all(tilledPatternResultsFolderPath);
|
||||
}
|
||||
|
|
@ -408,39 +419,12 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
assert(std::filesystem::exists(fullPatternJobFolderPath));
|
||||
simulationResults_tilledPattern.load(tilledPatternResultsFolderPath,
|
||||
fullPatternJobFolderPath);
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
simulationResults_tilledPattern.registerForDrawing(
|
||||
color_tesselatedPatterns);
|
||||
// std::ifstream ifs("CameraSettings.json");
|
||||
// nlohmann::json json;
|
||||
// ifs >> json;
|
||||
// polyscope::view::setCameraFromJson(json.dump(), false);
|
||||
polyscope::show();
|
||||
const std::string cameraJson = polyscope::view::getCameraJson();
|
||||
std::filesystem::path jsonFilePath("CameraSettings.json");
|
||||
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_tilledPattern->getLabel()))
|
||||
.string() +
|
||||
".png";
|
||||
std::cout << "Saving image to:" << screenshotOutputFilePath
|
||||
<< std::endl;
|
||||
polyscope::screenshot(screenshotOutputFilePath, false);
|
||||
simulationResults_tilledPattern.unregister();
|
||||
#endif
|
||||
|
||||
simulationResults_tilledPattern.converged = true;
|
||||
} else {
|
||||
std::cout << "Tilled pattern simulation results not found in:"
|
||||
<< tilledPatternResultsFolderPath << std::endl;
|
||||
// Full
|
||||
std::cout << "Executing:" << jobLabel << std::endl;
|
||||
if (evaluationSettings.beVerbose) {
|
||||
std::cout << "Executing:" << jobLabel << std::endl;
|
||||
}
|
||||
SimulationModelFactory factory;
|
||||
std::unique_ptr<SimulationModel> pTilledPatternSimulationModel =
|
||||
factory.create(simulationModelLabel_pattern);
|
||||
|
|
@ -450,7 +434,7 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
// SimulationSettings argument
|
||||
if (simulationModelLabel_pattern == DRMSimulationModel::label) {
|
||||
simulationResults_tilledPattern =
|
||||
static_cast<DRMSimulationModel*>(
|
||||
reinterpret_cast<DRMSimulationModel*>(
|
||||
pTilledPatternSimulationModel.get())
|
||||
->executeSimulation(pJob_tilledPattern,
|
||||
drmSimulationSettings);
|
||||
|
|
@ -479,54 +463,232 @@ ReducedModelEvaluator::Results ReducedModelEvaluator::evaluateReducedModel(
|
|||
pSimulationModel_tilledReducedModel->executeSimulation(
|
||||
pJob_tiledReducedModel);
|
||||
|
||||
// ChronosEulerNonLinearSimulationModel
|
||||
// debug_chronosNonLinearSimulationModel;
|
||||
// const auto debug_chronosResults =
|
||||
// debug_chronosNonLinearSimulationModel.executeSimulation(
|
||||
// pJob_tilledPattern);
|
||||
// LinearSimulationModel debug_linearSimulationModel;
|
||||
// const auto debug_linearSimResults =
|
||||
// debug_linearSimulationModel.executeSimulation(pJob_tilledPattern);
|
||||
// ChronosEulerNonLinearSimulationModel
|
||||
// debug_chronosNonLinearSimulationModel;
|
||||
// const auto debug_chronosResults =
|
||||
// debug_chronosNonLinearSimulationModel.executeSimulation(
|
||||
// pJob_tilledPattern);
|
||||
// LinearSimulationModel debug_linearSimulationModel;
|
||||
// const auto debug_linearSimResults =
|
||||
// debug_linearSimulationModel.executeSimulation(pJob_tilledPattern);
|
||||
|
||||
const int jobIndex = &jobLabel - &scenariosTestSetLabels[0];
|
||||
evaluationResults.maxDisplacements[jobIndex] =
|
||||
std::max_element(
|
||||
simulationResults_tilledPattern.displacements.begin(),
|
||||
simulationResults_tilledPattern.displacements.end(),
|
||||
[](const Vector6d& d1, const Vector6d& d2) {
|
||||
return d1.getTranslation().norm() <
|
||||
d2.getTranslation().norm();
|
||||
})
|
||||
->getTranslation()
|
||||
.norm();
|
||||
const std::vector<double> distance_perVertexPatternToReduced =
|
||||
SimulationResults::computeDistance_PerVertex(
|
||||
simulationResults_tilledPattern,
|
||||
simulationResults_tiledReducedModel, patternToReducedViMap);
|
||||
std::vector<double> distance_normalizedPerVertexPatternToReduced =
|
||||
distance_perVertexPatternToReduced;
|
||||
// compute the full2reduced distance
|
||||
double distance_patternSumOfAllVerts = 0;
|
||||
for (const std::pair<size_t, size_t>& fullToReducedPair :
|
||||
patternToReducedViMap) {
|
||||
VertexIndex patternVi = fullToReducedPair.first;
|
||||
const double patternVertexDisplacement =
|
||||
simulationResults_tilledPattern.displacements[patternVi]
|
||||
.getTranslation()
|
||||
.norm();
|
||||
distance_patternSumOfAllVerts += patternVertexDisplacement;
|
||||
}
|
||||
int pairIndex = 0;
|
||||
for (const std::pair<size_t, size_t>& fullToReducedPair :
|
||||
patternToReducedViMap) {
|
||||
VertexIndex patternVi = fullToReducedPair.first;
|
||||
const double patternVertexDisplacement =
|
||||
simulationResults_tilledPattern.displacements[patternVi]
|
||||
.getTranslation()
|
||||
.norm();
|
||||
distance_normalizedPerVertexPatternToReduced[pairIndex] =
|
||||
distance_perVertexPatternToReduced[pairIndex] /
|
||||
evaluationResults.maxDisplacements[jobIndex];
|
||||
assert(!std::isnan(
|
||||
distance_normalizedPerVertexPatternToReduced[pairIndex]));
|
||||
pairIndex++;
|
||||
}
|
||||
|
||||
double distance_averageNormalizedPerVertexPatternToReduced =
|
||||
std::accumulate(
|
||||
distance_normalizedPerVertexPatternToReduced.begin(),
|
||||
distance_normalizedPerVertexPatternToReduced.end(), 0.0) /
|
||||
patternToReducedViMap.size();
|
||||
const double distance_patternToReduced =
|
||||
simulationResults_tilledPattern.computeDistance_comulative(
|
||||
simulationResults_tiledReducedModel, patternToReducedViMap);
|
||||
const double distance_normalizedPatternToReduced =
|
||||
distance_patternToReduced / distance_patternSumOfAllVerts;
|
||||
evaluationResults.distances_drm2reduced[jobIndex] =
|
||||
distance_patternToReduced;
|
||||
// evaluationResults.distances_normalizedGroundTruth2reduced[jobIndex]
|
||||
// =
|
||||
// distance_normalizedPatternToReduced;
|
||||
evaluationResults.distances_normalizedGroundTruth2reduced[jobIndex] =
|
||||
distance_averageNormalizedPerVertexPatternToReduced;
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
if (shouldDrawScenarioResults) {
|
||||
if (evaluationSettings.shouldDraw) {
|
||||
std::cout << "maxError/maxDisp="
|
||||
<< *std::max_element(
|
||||
distance_perVertexPatternToReduced.begin(),
|
||||
distance_perVertexPatternToReduced.end()) /
|
||||
evaluationResults.maxDisplacements[jobIndex]
|
||||
<< std::endl;
|
||||
std::cout << "max displacement:"
|
||||
<< evaluationResults.maxDisplacements[jobIndex]
|
||||
<< std::endl;
|
||||
std::cout << "average normalized per vertex:"
|
||||
<< distance_averageNormalizedPerVertexPatternToReduced
|
||||
<< std::endl;
|
||||
simulationResults_tiledReducedModel.registerForDrawing(
|
||||
ReducedModelOptimization::Colors::reducedDeformed, true,
|
||||
ReducedModelOptimization::Colors::reducedDeformed, false,
|
||||
simulationResults_tilledPattern.pJob->pMesh
|
||||
->getBeamDimensions()[0]
|
||||
.getDrawingRadius());
|
||||
simulationResults_tilledPattern.registerForDrawing(
|
||||
ReducedModelOptimization::Colors::patternDeformed);
|
||||
// debug_chronosResults.registerForDrawing();
|
||||
// debug_linearSimResults.registerForDrawing();
|
||||
polyscope::CurveNetwork* patternHandle =
|
||||
simulationResults_tilledPattern.registerForDrawing(
|
||||
ReducedModelOptimization::Colors::patternDeformed);
|
||||
pJob_tilledPattern->registerForDrawing(patternHandle->name, true);
|
||||
pJob_tilledPattern->registerForDrawing(
|
||||
pSimulationEdgeMesh_tilledPattern->getLabel(), false);
|
||||
std::vector<double> distances_perVertexAverage(
|
||||
pSimulationEdgeMesh_tilledPattern->VN(), 0.0);
|
||||
int interfaceVi = 0;
|
||||
for (const std::pair<size_t, size_t>& fullToReducedPair :
|
||||
patternToReducedViMap) {
|
||||
VertexIndex patternVi = fullToReducedPair.first;
|
||||
distances_perVertexAverage[patternVi] =
|
||||
distance_normalizedPerVertexPatternToReduced[interfaceVi++];
|
||||
}
|
||||
|
||||
// patternHandle
|
||||
// ->addNodeScalarQuantity(
|
||||
// "average normalized distance "
|
||||
// "per vertex ",
|
||||
// distances_perVertexAverage)
|
||||
// ->setEnabled(true);
|
||||
|
||||
// pJob_tiledReducedModel->registerForDrawing(
|
||||
// pSimulationEdgeMesh_tilledReducedModel->getLabel());
|
||||
// debug_chronosResults.registerForDrawing();
|
||||
// debug_linearSimResults.registerForDrawing();
|
||||
std::cout << "normalized distance pattern2reduced:"
|
||||
<< distance_normalizedPatternToReduced << std::endl;
|
||||
// std::filesystem::path outputFolderPath(
|
||||
// "/home/iason/Documents/PhD/Thesis/images/RME/scenarios/"
|
||||
// "screenshots/");
|
||||
polyscope::show();
|
||||
// const std::string screenshotOutputFilePath_custom =
|
||||
// (std::filesystem::path(outputFolderPath)
|
||||
// .append(optimizationResult.label + "_" +
|
||||
// pJob_tilledPattern->getLabel()))
|
||||
// .string() +
|
||||
// "_custom"
|
||||
// ".png";
|
||||
// polyscope::screenshot(screenshotOutputFilePath_custom,
|
||||
// false);
|
||||
// top
|
||||
// const std::filesystem::path jsonFilePath_topView(
|
||||
// "/home/iason/Documents/PhD/Thesis/images/RME/scenarios/"
|
||||
// "cammeraSettings_.json");
|
||||
// std::ifstream f_top(jsonFilePath_topView);
|
||||
// polyscope::view::setCameraFromJson(
|
||||
// nlohmann::json::parse(f_top).dump(), false);
|
||||
// // polyscope::show();
|
||||
// const std::string screenshotOutputFilePath_top =
|
||||
// (std::filesystem::path(outputFolderPath)
|
||||
// .append(optimizationResult.label + "_" +
|
||||
// pJob_tilledPattern->getLabel()))
|
||||
// .string() +
|
||||
// "_top"
|
||||
// ".png";
|
||||
// std::cout << "Saving image to:" <<
|
||||
// screenshotOutputFilePath_top
|
||||
// << std::endl;
|
||||
// polyscope::screenshot(screenshotOutputFilePath_top,
|
||||
// false);
|
||||
// side
|
||||
// const std::filesystem::path jsonFilePath_sideView(
|
||||
// "/home/iason/Documents/PhD/Thesis/images/RME/scenarios/"
|
||||
// "cammeraSettings_sideView.json");
|
||||
// std::ifstream f_side(jsonFilePath_sideView);
|
||||
// polyscope::view::setCameraFromJson(
|
||||
// nlohmann::json::parse(f_side).dump(), false);
|
||||
// // polyscope::show();
|
||||
// const std::string screenshotOutputFilePath_side =
|
||||
// (std::filesystem::path(outputFolderPath)
|
||||
// .append(optimizationResult.label + "_" +
|
||||
// pJob_tilledPattern->getLabel()))
|
||||
// .string() +
|
||||
// "_side"
|
||||
// ".png";
|
||||
// std::cout << "Saving image to:" <<
|
||||
// screenshotOutputFilePath_side
|
||||
// << std::endl;
|
||||
// polyscope::screenshot(screenshotOutputFilePath_side,
|
||||
// false);
|
||||
pJob_tilledPattern->unregister(
|
||||
pSimulationEdgeMesh_tilledPattern->getLabel());
|
||||
pJob_tiledReducedModel->unregister(
|
||||
pSimulationEdgeMesh_tilledReducedModel->getLabel());
|
||||
// debug_linearSimResults.unregister();
|
||||
simulationResults_tiledReducedModel.unregister();
|
||||
simulationResults_tilledPattern.unregister();
|
||||
// debug_chronosResults.unregister();
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute the full2reduced distance
|
||||
const double distance_patternToReduced =
|
||||
simulationResults_tilledPattern.computeDistance(
|
||||
simulationResults_tiledReducedModel, fullToReducedViMap);
|
||||
double distance_patternSumOfAllVerts = 0;
|
||||
for (std::pair<size_t, size_t> fullToReducedPair : fullToReducedViMap) {
|
||||
distance_patternSumOfAllVerts +=
|
||||
simulationResults_tilledPattern
|
||||
.displacements[fullToReducedPair.first]
|
||||
.getTranslation()
|
||||
.norm();
|
||||
}
|
||||
const double distance_normalizedPatternToReduced =
|
||||
distance_patternToReduced / distance_patternSumOfAllVerts;
|
||||
const int jobIndex = &jobLabel - &scenariosTestSetLabels[0];
|
||||
evaluationResults.distances_drm2reduced[jobIndex] =
|
||||
distance_patternToReduced;
|
||||
evaluationResults.distances_normalizedDrm2reduced[jobIndex] =
|
||||
distance_normalizedPatternToReduced;
|
||||
});
|
||||
|
||||
return evaluationResults;
|
||||
}
|
||||
|
||||
bool ReducedModelEvaluator::Settings::save(
|
||||
const std::filesystem::path& jsonFilePath) const {
|
||||
if (std::filesystem::path(jsonFilePath).extension() != ".json") {
|
||||
std::cerr << "A json file is expected as input. The given file has the "
|
||||
"following extension:"
|
||||
<< std::filesystem::path(jsonFilePath).extension() << std::endl;
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json json = *this;
|
||||
std::ofstream jsonFile(jsonFilePath.string());
|
||||
jsonFile << json;
|
||||
jsonFile.close();
|
||||
}
|
||||
|
||||
bool ReducedModelEvaluator::Settings::load(
|
||||
const std::filesystem::path& jsonFilePath) {
|
||||
if (!std::filesystem::exists(jsonFilePath)) {
|
||||
std::cerr << "Evaluation settings could not be loaded because input "
|
||||
"filepath does "
|
||||
"not exist:"
|
||||
<< jsonFilePath << std::endl;
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::filesystem::path(jsonFilePath).extension() != ".json") {
|
||||
std::cerr << "A json file is expected as input. The given file has the "
|
||||
"following extension:"
|
||||
<< std::filesystem::path(jsonFilePath).extension() << std::endl;
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream ifs(jsonFilePath);
|
||||
nlohmann::json json;
|
||||
ifs >> json;
|
||||
*this = json;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,84 +9,113 @@ class ReducedModelEvaluator {
|
|||
enum CSVExportingDirection { Vertical = 0, Horizontal };
|
||||
enum CSVExportingData {
|
||||
raw_drm2Reduced = 0,
|
||||
norm_drm2Reduced,
|
||||
norm_groundTruth2Reduced,
|
||||
raw_and_norm_drm2Reduced,
|
||||
NumberOfDataTypes
|
||||
};
|
||||
inline static std::array<std::string, NumberOfDataTypes>
|
||||
csvExportingDataStrings{"raw_drm2Reduced", "norm_drm2Reduced",
|
||||
"raw_and_norm_drm2Reduced"};
|
||||
struct Settings {
|
||||
CSVExportingDirection exportingDirection{Horizontal};
|
||||
CSVExportingData exportingData{norm_drm2Reduced};
|
||||
struct ExportingSettings {
|
||||
// exporting settings
|
||||
CSVExportingDirection direction{Horizontal};
|
||||
CSVExportingData data{norm_groundTruth2Reduced};
|
||||
bool shouldWriteHeader{true};
|
||||
std::string resultsLabel;
|
||||
};
|
||||
|
||||
inline static constexpr int NumberOfEvaluationScenarios{22};
|
||||
struct Settings {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
bool shouldDraw{false};
|
||||
#endif
|
||||
bool shouldRecomputeGroundTruthResults{false};
|
||||
bool beVerbose{true};
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(
|
||||
Settings,
|
||||
shouldRecomputeGroundTruthResults,
|
||||
beVerbose
|
||||
//#ifdef POLYSCOPE_DEFINED
|
||||
// ,
|
||||
// shouldDraw
|
||||
|
||||
//#endif
|
||||
)
|
||||
bool save(const std::filesystem::path& jsonFilePath) const;
|
||||
bool load(const std::filesystem::path& jsonFilePath);
|
||||
std::string toString() const {
|
||||
nlohmann::json json = *this;
|
||||
return std::string("Reduced model evaluation settings:" + json.dump());
|
||||
}
|
||||
};
|
||||
|
||||
inline static constexpr int NumberOfEvaluationScenarios = 17;
|
||||
inline static const std::array<std::string, NumberOfEvaluationScenarios>
|
||||
scenariosTestSetLabels{
|
||||
"22Hex_randomBending0",
|
||||
"22Hex_randomBending1",
|
||||
"22Hex_randomBending2",
|
||||
"22Hex_randomBending4",
|
||||
"22Hex_randomBending5",
|
||||
"22Hex_randomBending8",
|
||||
"22Hex_randomBending9",
|
||||
"22Hex_randomBending11",
|
||||
"22Hex_randomBending12",
|
||||
"22Hex_randomBending16",
|
||||
"22Hex_randomBending17",
|
||||
"22Hex_randomBending18",
|
||||
"22Hex_randomBending19",
|
||||
"22Hex_bending_0.01N",
|
||||
"22Hex_pullOppositeVerts_0.05N",
|
||||
"22Hex_cylinder_0.1N",
|
||||
"22Hex_s_0.05N",
|
||||
};
|
||||
inline static constexpr double forceScalingFactor = 1.5;
|
||||
struct Results {
|
||||
std::array<double, NumberOfEvaluationScenarios> distances_drm2reduced;
|
||||
std::array<double, NumberOfEvaluationScenarios>
|
||||
distances_normalizedDrm2reduced;
|
||||
distances_normalizedGroundTruth2reduced;
|
||||
std::array<std::string, NumberOfEvaluationScenarios>
|
||||
evaluationScenarioLabels;
|
||||
std::array<double, NumberOfEvaluationScenarios> maxDisplacements;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Results,
|
||||
evaluationScenarioLabels,
|
||||
maxDisplacements)
|
||||
|
||||
inline static std::string defaultFileName{"evaluationResults.json"};
|
||||
void save(const std::filesystem::path& saveToPath) {
|
||||
assert(std::filesystem::is_directory(saveToPath));
|
||||
nlohmann::json json = *this;
|
||||
std::filesystem::path jsonFilePath(
|
||||
std::filesystem::path(saveToPath).append(defaultFileName));
|
||||
std::ofstream jsonFile(jsonFilePath.string());
|
||||
jsonFile << json;
|
||||
jsonFile.close();
|
||||
}
|
||||
};
|
||||
ReducedModelEvaluator();
|
||||
Results evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult,
|
||||
const std::filesystem::path& scenariosDirectoryPath,
|
||||
// const std::filesystem::path &reducedPatternFilePath,
|
||||
const std::filesystem::path& fullPatternTessellatedResultsDirectoryPath);
|
||||
const std::filesystem::path& fullPatternTessellatedResultsDirectoryPath,
|
||||
const ReducedModelEvaluator::Settings& settings);
|
||||
Results evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult);
|
||||
ReducedModelOptimization::Results& optimizationResult,
|
||||
const Settings& settings);
|
||||
static void printResultsVertically(
|
||||
const ReducedModelEvaluator::Results& evaluationResults,
|
||||
csvFile& csvOutput);
|
||||
CSVFile& csvOutput);
|
||||
static void printResults(
|
||||
const ReducedModelEvaluator::Results& evaluationResults,
|
||||
const std::string& resultsLabel);
|
||||
|
||||
inline static std::array<std::string, NumberOfEvaluationScenarios>
|
||||
scenariosTestSetLabels{
|
||||
"22Hex_randomBending0", "22Hex_randomBending1",
|
||||
"22Hex_randomBending2",
|
||||
// "22Hex_randomBending3",
|
||||
"22Hex_randomBending4", "22Hex_randomBending5",
|
||||
// "22Hex_randomBending6",
|
||||
// "22Hex_randomBending7",
|
||||
"22Hex_randomBending8", "22Hex_randomBending9",
|
||||
"22Hex_randomBending10", "22Hex_randomBending11",
|
||||
"22Hex_randomBending12",
|
||||
// "22Hex_randomBending13",
|
||||
// "22Hex_randomBending14",
|
||||
// "22Hex_randomBending15",
|
||||
"22Hex_randomBending16", "22Hex_randomBending17",
|
||||
"22Hex_randomBending18", "22Hex_randomBending19",
|
||||
// "22Hex_randomBending20",
|
||||
"22Hex_bending_0.005N", "22Hex_bending_0.01N", "22Hex_bending_0.03N",
|
||||
// "22Hex_bending_0.05N",
|
||||
"22Hex_pullOppositeVerts_0.05N", "22Hex_pullOppositeVerts_0.1N",
|
||||
// "22Hex_pullOppositeVerts_0.3N",
|
||||
//#ifdef POLYSCOPE_DEFINED
|
||||
// "22Hex_shear_2N",
|
||||
// "22Hex_shear_5N",
|
||||
// "22Hex_axial_10N",
|
||||
// "22Hex_axial_20N",
|
||||
//#else
|
||||
// "notUsed_22Hex_shear_2N",
|
||||
// "notUsed_22Hex_shear_5N",
|
||||
// "notUsed_22Hex_axial_10N",
|
||||
// "notUsed_22Hex_axial_20N",
|
||||
//#endif
|
||||
"22Hex_cylinder_0.05N", "22Hex_cylinder_0.1N", "22Hex_s_0.05N",
|
||||
// "22Hex_s_0.1N"
|
||||
};
|
||||
static void printResultsHorizontally(const Results& evaluationResults,
|
||||
csvFile& csvOutput);
|
||||
CSVFile& csvOutput);
|
||||
static void printResults(const Results& evaluationResults,
|
||||
const Settings& settings,
|
||||
csvFile& csvOutput);
|
||||
static void printHeader(const Settings& settings, csvFile& csvOutput);
|
||||
const ExportingSettings& exportingSettings,
|
||||
CSVFile& csvOutput);
|
||||
static void printHeader(const ExportingSettings& exportingSettings,
|
||||
CSVFile& csvOutput);
|
||||
// static double evaluateOptimizationSettings(
|
||||
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||
|
|
@ -98,7 +127,8 @@ class ReducedModelEvaluator {
|
|||
ReducedModelOptimization::Colors::RGBColor color_tesselatedReducedModels{
|
||||
67.0 / 255, 160.00 / 255, 232.0 / 255};
|
||||
ReducedModelOptimization::Colors::RGBColor color_tileIntoSurface{
|
||||
222 / 255.0, 235 / 255.0, 255 / 255.0};
|
||||
// 222 / 255.0, 235 / 255.0, 255 / 255.0};
|
||||
156 / 255.0, 195 / 255.0, 254 / 255.0};
|
||||
ReducedModelOptimization::Colors::RGBColor interfaceNodes_color{
|
||||
63.0 / 255, 85.0 / 255, 42.0 / 255};
|
||||
inline static constexpr char* tileIntoSurfaceFileContent = R"~(OFF
|
||||
|
|
|
|||
Loading…
Reference in New Issue