Merged potentialEnergyError branch
This commit is contained in:
commit
941a766ec8
148
src/main.cpp
148
src/main.cpp
|
@ -22,19 +22,21 @@
|
|||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/finding_submissionCode/"
|
||||
// "build-ReducedModelOptimization-Clang-RelWithDebInfo/OptimizationResults/"
|
||||
// "ConvergedJobs/12@single_reduced(100000_1.20)");
|
||||
// ReducedModelEvaluator::evaluateReducedModel(optResults);
|
||||
if (argc <= 5) {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/selectionOfPatterns_0.2To1.6/selectionOfPatterns/1.2/"
|
||||
// "ConvergedJobs/12@single_reduced(100000_1.20)");
|
||||
// ReducedModelEvaluator::evaluateReducedModel(optResults);
|
||||
// return 0;
|
||||
#endif
|
||||
if (argc < 3) {
|
||||
std::cerr << "Wrong number of input parameters. Expects at least 4 input parameters."
|
||||
"Usage:\n"
|
||||
"1)full pattern file path\n"
|
||||
"2)reduced pattern file path\n"
|
||||
"3)Optimization settings json file path\n"
|
||||
"4)Optimization results directory path\n"
|
||||
"5)[optional]Intermediate results directory path\n"
|
||||
"3)Optimization results directory path\n"
|
||||
"4)[optional]Intermediate results directory path\n"
|
||||
"5)[optional]Optimization settings json file path\n"
|
||||
"Exiting.."
|
||||
<< std::endl;
|
||||
std::cerr << "Input arguments are:" << std::endl;
|
||||
|
@ -55,25 +57,35 @@ int main(int argc, char *argv[])
|
|||
reducedPattern.scale(0.03, interfaceNodeIndex);
|
||||
|
||||
// Set the optization settings
|
||||
const std::filesystem::path optimizationSettingsFilePath = argv[3];
|
||||
if (!std::filesystem::exists(optimizationSettingsFilePath)) {
|
||||
std::cerr << "Input optimization settings file does not exist:"
|
||||
<< optimizationSettingsFilePath << std::endl;
|
||||
}
|
||||
ReducedModelOptimization::Settings settings_optimization;
|
||||
if (argc > 5) {
|
||||
const std::filesystem::path optimizationSettingsFilePath = argv[5];
|
||||
if (!std::filesystem::exists(optimizationSettingsFilePath)) {
|
||||
std::cerr << "Input optimization settings file does not exist:"
|
||||
<< optimizationSettingsFilePath << std::endl;
|
||||
}
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// settings_optimization.save(optimizationSettingsFilePath.parent_path());
|
||||
// std::cout << "Save settings to:" << optimizationSettingsFilePath << std::endl;
|
||||
#else
|
||||
settings_optimization.load(optimizationSettingsFilePath);
|
||||
// settings_optimization.load(optimizationSettingsFilePath);
|
||||
#endif
|
||||
}
|
||||
// settings_optimization.normalizationStrategy
|
||||
// = ReducedModelOptimization::Settings::NormalizationStrategy::NonNormalized;
|
||||
settings_optimization.optimizationStrategy = {{ReducedModelOptimization::A,
|
||||
ReducedModelOptimization::I2,
|
||||
ReducedModelOptimization::I3,
|
||||
ReducedModelOptimization::J,
|
||||
ReducedModelOptimization::R,
|
||||
ReducedModelOptimization::Theta}};
|
||||
// settings_optimization.setDefault();
|
||||
// settings_optimization.rotationNormalizationEpsilon = 0;
|
||||
|
||||
// Optimize pairthere
|
||||
const std::string optimizationName = std::to_string(fullPattern.EN()) + "#"
|
||||
+ fullPattern.getLabel();
|
||||
const std::string optimizationResultsDirectory = argv[4];
|
||||
const std::string optimizationResultsDirectory = argv[3];
|
||||
std::string resultsOutputDir;
|
||||
bool optimizationResultFolderExists = false;
|
||||
const std::filesystem::path crashedJobsDirPath(
|
||||
|
@ -108,9 +120,9 @@ int main(int argc, char *argv[])
|
|||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
assert(interfaceNodeIndex == numberOfNodesPerSlot[0] + numberOfNodesPerSlot[3]);
|
||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||
const bool input_intermediateResultsDirectoryDefined = argc == 6;
|
||||
const bool input_intermediateResultsDirectoryDefined = argc == 5;
|
||||
if (input_intermediateResultsDirectoryDefined) {
|
||||
optimizer.setIntermediateResultsDirectoryPath(std::filesystem::path(argv[5]));
|
||||
optimizer.setIntermediateResultsDirectoryPath(std::filesystem::path(argv[4]));
|
||||
}
|
||||
optimizer.initializePatterns(fullPattern,
|
||||
reducedPattern,
|
||||
|
@ -148,59 +160,59 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
std::vector<std::string> scenarioLabels(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
const double colorAxial = 1;
|
||||
const double colorShear = 3;
|
||||
const double colorBending = 5;
|
||||
const double colorDome = 0.1;
|
||||
const double colorSaddle = 0;
|
||||
std::vector<double> colors(optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
scenarioLabels[scenarioIndex]
|
||||
= optimizationResults.reducedPatternSimulationJobs[scenarioIndex]->getLabel();
|
||||
if (scenarioLabels[scenarioIndex].rfind("Axial", 0) == 0) {
|
||||
colors[scenarioIndex] = colorAxial;
|
||||
std::vector<std::string> scenarioLabels(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
const double colorAxial = 1;
|
||||
const double colorShear = 3;
|
||||
const double colorBending = 5;
|
||||
const double colorDome = 0.1;
|
||||
const double colorSaddle = 0;
|
||||
std::vector<double> colors(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
scenarioLabels[scenarioIndex]
|
||||
= optimizationResults.reducedPatternSimulationJobs[scenarioIndex]->getLabel();
|
||||
if (scenarioLabels[scenarioIndex].rfind("Axial", 0) == 0) {
|
||||
colors[scenarioIndex] = colorAxial;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Shear", 0) == 0) {
|
||||
colors[scenarioIndex] = colorShear;
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Shear", 0) == 0) {
|
||||
colors[scenarioIndex] = colorShear;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Bending", 0) == 0) {
|
||||
colors[scenarioIndex] = colorBending;
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Bending", 0) == 0) {
|
||||
colors[scenarioIndex] = colorBending;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Dome", 0) == 0) {
|
||||
colors[scenarioIndex] = colorDome;
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Saddle", 0) == 0) {
|
||||
colors[scenarioIndex] = colorSaddle;
|
||||
} else {
|
||||
std::cerr << "Label could not be identified" << std::endl;
|
||||
}
|
||||
}
|
||||
std::vector<double> y(optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
y[scenarioIndex]
|
||||
// = optimizationResults.objectiveValue.perSimulationScenario_rawTranslational[scenarioIndex]
|
||||
// + optimizationResults.objectiveValue.perSimulationScenario_rawRotational[scenarioIndex];
|
||||
= optimizationResults.objectiveValue.perSimulationScenario_total_unweighted[scenarioIndex];
|
||||
}
|
||||
std::vector<double> x = matplot::linspace(0, y.size() - 1, y.size());
|
||||
std::vector<double> markerSizes(y.size(), 5);
|
||||
SimulationResultsReporter::createPlot("scenario index",
|
||||
"error",
|
||||
x,
|
||||
y,
|
||||
markerSizes,
|
||||
colors,
|
||||
std::filesystem::path(resultsOutputDir)
|
||||
.append("perScenarioObjectiveValues.png"));
|
||||
// optimizationResults.saveMeshFiles();
|
||||
std::cout << "Saved results to:" << resultsOutputDir << std::endl;
|
||||
// optimizationResults.draw();
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Dome", 0) == 0) {
|
||||
colors[scenarioIndex] = colorDome;
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Saddle", 0) == 0) {
|
||||
colors[scenarioIndex] = colorSaddle;
|
||||
} else {
|
||||
std::cerr << "Label could not be identified" << std::endl;
|
||||
}
|
||||
}
|
||||
std::vector<double> y(optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
y[scenarioIndex]
|
||||
// = optimizationResults.objectiveValue.perSimulationScenario_rawTranslational[scenarioIndex]
|
||||
// + optimizationResults.objectiveValue.perSimulationScenario_rawRotational[scenarioIndex];
|
||||
= optimizationResults.objectiveValue
|
||||
.perSimulationScenario_total_unweighted[scenarioIndex];
|
||||
}
|
||||
std::vector<double> x = matplot::linspace(0, y.size() - 1, y.size());
|
||||
std::vector<double> markerSizes(y.size(), 5);
|
||||
SimulationResultsReporter::createPlot("scenario index",
|
||||
"error",
|
||||
x,
|
||||
y,
|
||||
markerSizes,
|
||||
colors,
|
||||
std::filesystem::path(resultsOutputDir)
|
||||
.append("perScenarioObjectiveValues.png"));
|
||||
// optimizationResults.saveMeshFiles();
|
||||
std::cout << "Saved results to:" << resultsOutputDir << std::endl;
|
||||
// optimizationResults.draw();
|
||||
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
|
||||
// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)");
|
||||
ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
|
||||
const auto evaluationResults = ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
|
||||
ReducedModelEvaluator::printResults(evaluationResults, optimizationResults.label);
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
#include "csvfile.hpp"
|
||||
#include "drmsimulationmodel.hpp"
|
||||
#include "edgemesh.hpp"
|
||||
#include "reducedmodelevaluator.hpp"
|
||||
#include "reducedmodeloptimizer.hpp"
|
||||
#include "simulationhistoryplotter.hpp"
|
||||
#include "trianglepattterntopology.hpp"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vcg/complex/algorithms/update/position.h>
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#include "polyscope/curve_network.h"
|
||||
#include "polyscope/point_cloud.h"
|
||||
#include "polyscope/polyscope.h"
|
||||
#endif
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/finding_submissionCode/"
|
||||
// "build-ReducedModelOptimization-Clang-RelWithDebInfo/OptimizationResults/"
|
||||
// "ConvergedJobs/12@single_reduced(100000_1.20)");
|
||||
// ReducedModelEvaluator::evaluateReducedModel(optResults);
|
||||
if (argc <= 5) {
|
||||
=======
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/selectionOfPatterns_0.2To1.6/selectionOfPatterns/1.2/"
|
||||
// "ConvergedJobs/12@single_reduced(100000_1.20)");
|
||||
// ReducedModelEvaluator::evaluateReducedModel(optResults);
|
||||
// return 0;
|
||||
#endif
|
||||
if (argc < 3) {
|
||||
>>>>>>> potentialEnergyError
|
||||
std::cerr << "Wrong number of input parameters. Expects at least 4 input parameters."
|
||||
"Usage:\n"
|
||||
"1)full pattern file path\n"
|
||||
"2)reduced pattern file path\n"
|
||||
"3)Optimization results directory path\n"
|
||||
"4)[optional]Intermediate results directory path\n"
|
||||
"5)[optional]Optimization settings json file path\n"
|
||||
"Exiting.."
|
||||
<< std::endl;
|
||||
std::cerr << "Input arguments are:" << std::endl;
|
||||
std::copy(argv + 1, argv + argc, std::ostream_iterator<const char *>(std::cout, "\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Populate the pattern pair to be optimized
|
||||
const int interfaceNodeIndex = 3;
|
||||
////Full pattern
|
||||
const std::string filepath_fullPattern = argv[1];
|
||||
PatternGeometry fullPattern(filepath_fullPattern);
|
||||
// fullPattern.prependToLabel(std::to_string(fullPattern.EN()) + "#");
|
||||
fullPattern.scale(0.03, interfaceNodeIndex);
|
||||
////Reduced pattern
|
||||
const std::string filepath_reducedPattern = argv[2];
|
||||
PatternGeometry reducedPattern(filepath_reducedPattern);
|
||||
reducedPattern.scale(0.03, interfaceNodeIndex);
|
||||
|
||||
// Set the optization settings
|
||||
ReducedModelOptimization::Settings settings_optimization;
|
||||
if (argc > 5) {
|
||||
const std::filesystem::path optimizationSettingsFilePath = argv[5];
|
||||
if (!std::filesystem::exists(optimizationSettingsFilePath)) {
|
||||
std::cerr << "Input optimization settings file does not exist:"
|
||||
<< optimizationSettingsFilePath << std::endl;
|
||||
}
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// settings_optimization.save(optimizationSettingsFilePath.parent_path());
|
||||
// std::cout << "Save settings to:" << optimizationSettingsFilePath << std::endl;
|
||||
#else
|
||||
settings_optimization.load(optimizationSettingsFilePath);
|
||||
#endif
|
||||
}
|
||||
// settings_optimization.setDefault();
|
||||
// settings_optimization.rotationNormalizationEpsilon = 0;
|
||||
|
||||
// Optimize pairthere
|
||||
const std::string optimizationName = std::to_string(fullPattern.EN()) + "#"
|
||||
+ fullPattern.getLabel();
|
||||
const std::string optimizationResultsDirectory = argv[3];
|
||||
std::string resultsOutputDir;
|
||||
bool optimizationResultFolderExists = false;
|
||||
const std::filesystem::path crashedJobsDirPath(
|
||||
std::filesystem::path(optimizationResultsDirectory)
|
||||
.append("CrashedJobs")
|
||||
.append(optimizationName));
|
||||
if (std::filesystem::exists(crashedJobsDirPath)) {
|
||||
resultsOutputDir = crashedJobsDirPath.string();
|
||||
optimizationResultFolderExists = true;
|
||||
}
|
||||
const std::filesystem::path convergedJobsDirPath(
|
||||
std::filesystem::path(optimizationResultsDirectory)
|
||||
.append("ConvergedJobs")
|
||||
.append(optimizationName));
|
||||
if (std::filesystem::exists(convergedJobsDirPath)) {
|
||||
resultsOutputDir = convergedJobsDirPath.string();
|
||||
optimizationResultFolderExists = true;
|
||||
}
|
||||
|
||||
ReducedModelOptimization::Results optimizationResults;
|
||||
constexpr bool shouldReoptimize = true;
|
||||
bool optimizationAlreadyComputed = false;
|
||||
if (!shouldReoptimize && optimizationResultFolderExists) {
|
||||
const bool resultsWereSuccessfullyLoaded = optimizationResults.load(resultsOutputDir);
|
||||
if (resultsWereSuccessfullyLoaded && optimizationResults.settings == settings_optimization) {
|
||||
optimizationAlreadyComputed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!optimizationAlreadyComputed) {
|
||||
auto start = std::chrono::system_clock::now();
|
||||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
assert(interfaceNodeIndex == numberOfNodesPerSlot[0] + numberOfNodesPerSlot[3]);
|
||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||
const bool input_intermediateResultsDirectoryDefined = argc == 5;
|
||||
if (input_intermediateResultsDirectoryDefined) {
|
||||
optimizer.setIntermediateResultsDirectoryPath(std::filesystem::path(argv[4]));
|
||||
}
|
||||
optimizer.initializePatterns(fullPattern,
|
||||
reducedPattern,
|
||||
settings_optimization.variablesRanges);
|
||||
optimizer.optimize(settings_optimization, optimizationResults);
|
||||
optimizationResults.label = optimizationName;
|
||||
optimizationResults.baseTriangleFullPattern.copy(fullPattern);
|
||||
optimizationResults.settings = settings_optimization;
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
optimizationResults.time = elapsed.count() / 1000.0;
|
||||
|
||||
if (!optimizationResults.wasSuccessful) {
|
||||
// resultsOutputDir = crashedJobsDirPath.string();
|
||||
return 1;
|
||||
}
|
||||
resultsOutputDir = convergedJobsDirPath.string();
|
||||
optimizationResults.save(resultsOutputDir, true);
|
||||
csvFile csv_resultsLocalFile(std::filesystem::path(resultsOutputDir).append("results.csv"),
|
||||
true);
|
||||
csvFile csv_results({}, false);
|
||||
std::vector<csvFile *> csvVector{&csv_resultsLocalFile, &csv_results};
|
||||
csv_results << "Name";
|
||||
csv_resultsLocalFile << "Name";
|
||||
optimizationResults.writeHeaderTo(csvVector);
|
||||
settings_optimization.writeHeaderTo(csv_results);
|
||||
csv_results << endrow;
|
||||
csv_resultsLocalFile << endrow;
|
||||
csv_results << optimizationName;
|
||||
csv_resultsLocalFile << optimizationName;
|
||||
optimizationResults.writeResultsTo(csvVector);
|
||||
settings_optimization.writeSettingsTo(csv_results);
|
||||
csv_results << endrow;
|
||||
csv_resultsLocalFile << endrow;
|
||||
}
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
|
||||
std::vector<std::string> scenarioLabels(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
const double colorAxial = 1;
|
||||
const double colorShear = 3;
|
||||
const double colorBending = 5;
|
||||
const double colorDome = 0.1;
|
||||
const double colorSaddle = 0;
|
||||
std::vector<double> colors(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
scenarioLabels[scenarioIndex]
|
||||
= optimizationResults.reducedPatternSimulationJobs[scenarioIndex]->getLabel();
|
||||
if (scenarioLabels[scenarioIndex].rfind("Axial", 0) == 0) {
|
||||
colors[scenarioIndex] = colorAxial;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Shear", 0) == 0) {
|
||||
colors[scenarioIndex] = colorShear;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Bending", 0) == 0) {
|
||||
colors[scenarioIndex] = colorBending;
|
||||
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Dome", 0) == 0) {
|
||||
colors[scenarioIndex] = colorDome;
|
||||
} else if (scenarioLabels[scenarioIndex].rfind("Saddle", 0) == 0) {
|
||||
colors[scenarioIndex] = colorSaddle;
|
||||
} else {
|
||||
std::cerr << "Label could not be identified" << std::endl;
|
||||
}
|
||||
}
|
||||
std::vector<double> y(optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
|
||||
y[scenarioIndex]
|
||||
// = optimizationResults.objectiveValue.perSimulationScenario_rawTranslational[scenarioIndex]
|
||||
// + optimizationResults.objectiveValue.perSimulationScenario_rawRotational[scenarioIndex];
|
||||
= optimizationResults.objectiveValue
|
||||
.perSimulationScenario_total_unweighted[scenarioIndex];
|
||||
}
|
||||
std::vector<double> x = matplot::linspace(0, y.size() - 1, y.size());
|
||||
std::vector<double> markerSizes(y.size(), 5);
|
||||
SimulationResultsReporter::createPlot("scenario index",
|
||||
"error",
|
||||
x,
|
||||
y,
|
||||
markerSizes,
|
||||
colors,
|
||||
std::filesystem::path(resultsOutputDir)
|
||||
.append("perScenarioObjectiveValues.png"));
|
||||
// optimizationResults.saveMeshFiles();
|
||||
std::cout << "Saved results to:" << resultsOutputDir << std::endl;
|
||||
optimizationResults.draw();
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
|
@ -140,27 +140,27 @@ double ReducedModelOptimizer::computeError(
|
|||
const double &scenarioWeight,
|
||||
const Settings::ObjectiveWeights &objectiveWeights)
|
||||
{
|
||||
// const double translationalError
|
||||
// = computeDisplacementError(simulationResults_fullPattern.displacements,
|
||||
// simulationResults_reducedPattern.displacements,
|
||||
// reducedToFullInterfaceViMap,
|
||||
// normalizationFactor_translationalDisplacement);
|
||||
const double translationalError
|
||||
= computeRawTranslationalError(simulationResults_fullPattern.displacements,
|
||||
simulationResults_reducedPattern.displacements,
|
||||
reducedToFullInterfaceViMap);
|
||||
= computeDisplacementError(simulationResults_fullPattern.displacements,
|
||||
simulationResults_reducedPattern.displacements,
|
||||
reducedToFullInterfaceViMap,
|
||||
normalizationFactor_translationalDisplacement);
|
||||
// const double translationalError
|
||||
// = computeRawTranslationalError(simulationResults_fullPattern.displacements,
|
||||
// simulationResults_reducedPattern.displacements,
|
||||
// reducedToFullInterfaceViMap);
|
||||
|
||||
// std::cout << "normalization factor:" << normalizationFactor_rotationalDisplacement << std::endl;
|
||||
// std::cout << "trans error:" << translationalError << std::endl;
|
||||
// const double rotationalError
|
||||
// = computeRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
// simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
// reducedToFullInterfaceViMap,
|
||||
// normalizationFactor_rotationalDisplacement);
|
||||
const double rotationalError
|
||||
= computeRawRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
reducedToFullInterfaceViMap);
|
||||
= computeRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
reducedToFullInterfaceViMap,
|
||||
normalizationFactor_rotationalDisplacement);
|
||||
// const double rotationalError
|
||||
// = computeRawRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
// simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
// reducedToFullInterfaceViMap);
|
||||
// std::cout << "rot error:" << rotationalError<< std::endl;
|
||||
const double simulationError = objectiveWeights.translational * translationalError
|
||||
+ objectiveWeights.rotational * rotationalError;
|
||||
|
@ -267,15 +267,11 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
std::cout << "Failed simulation" << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
// double simulationScenarioError = 0;
|
||||
// constexpr bool usePotentialEnergy = false;
|
||||
// if (usePotentialEnergy) {
|
||||
// simulationScenarioError += std::abs(
|
||||
// reducedModelResults.internalPotentialEnergy
|
||||
// - global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy
|
||||
// / global.fullPatternResults[simulationScenarioIndex]
|
||||
// .internalPotentialEnergy);
|
||||
// } else {
|
||||
// const double simulationScenarioError_PE = std::abs(
|
||||
// (reducedModelResults.internalPotentialEnergy
|
||||
// - global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy)
|
||||
// / global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy);
|
||||
// else {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#ifdef USE_SCENARIO_WEIGHTS
|
||||
const double scenarioWeight = global.scenarioWeights[simulationScenarioIndex];
|
||||
|
@ -285,7 +281,7 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
#else
|
||||
const double scenarioWeight = 1;
|
||||
#endif
|
||||
const double simulationScenarioError = computeError(
|
||||
const double simulationScenarioError_displacements = computeError(
|
||||
global.fullPatternResults[simulationScenarioIndex],
|
||||
reducedModelResults,
|
||||
global.reducedToFullInterfaceViMap,
|
||||
|
@ -294,7 +290,8 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
scenarioWeight,
|
||||
global.objectiveWeights[simulationScenarioIndex]);
|
||||
|
||||
simulationErrorsPerScenario[simulationScenarioIndex] = simulationScenarioError;
|
||||
simulationErrorsPerScenario[simulationScenarioIndex]
|
||||
= simulationScenarioError_displacements /*+ simulationScenarioError_PE*/;
|
||||
// }
|
||||
// #ifdef POLYSCOPE_DEFINED
|
||||
// reducedJob->pMesh->registerForDrawing(Colors::reducedInitial);
|
||||
|
@ -979,7 +976,12 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
|||
.append(m_pFullPatternSimulationMesh->getLabel() + ".json"));
|
||||
const bool fullPatternScenarioMagnitudesExist = std::filesystem::exists(
|
||||
patternMaxForceMagnitudesFilePath);
|
||||
if (fullPatternScenarioMagnitudesExist && !recomputeForceMagnitudes) {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
constexpr bool recomputeMagnitudes = true;
|
||||
#else
|
||||
constexpr bool recomputeMagnitudes = true;
|
||||
#endif
|
||||
if (fullPatternScenarioMagnitudesExist && !recomputeMagnitudes) {
|
||||
nlohmann::json json;
|
||||
std::ifstream ifs(patternMaxForceMagnitudesFilePath.string());
|
||||
ifs >> json;
|
||||
|
@ -987,6 +989,7 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
|||
= static_cast<std::array<double, NumberOfBaseSimulationScenarios>>(json.at("maxMagn"));
|
||||
return fullPatternSimulationScenarioMaxMagnitudes;
|
||||
}
|
||||
|
||||
//#endif
|
||||
fullPatternSimulationScenarioMaxMagnitudes = computeFullPatternMaxSimulationForces(
|
||||
desiredBaseSimulationScenarioIndices);
|
||||
|
@ -999,6 +1002,11 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
|||
std::ofstream jsonFile(patternMaxForceMagnitudesFilePath.string());
|
||||
jsonFile << json;
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
std::cout << "Saved base scenario max magnitudes to:" << patternMaxForceMagnitudesFilePath
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
//#endif
|
||||
assert(fullPatternSimulationScenarioMaxMagnitudes.size()
|
||||
== desiredBaseSimulationScenarioIndices.size());
|
||||
|
@ -1405,7 +1413,6 @@ double fullPatternMaxSimulationForceRotationalObjective(const double &forceMagni
|
|||
settings);
|
||||
const double &desiredRotationAngle = global.desiredMaxRotationAngle;
|
||||
double error;
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// job.pMesh->setLabel("initial");
|
||||
// job.pMesh->registerForDrawing();
|
||||
// results.registerForDrawing();
|
||||
|
@ -1444,6 +1451,7 @@ double fullPatternMaxSimulationForceRotationalObjective(const double &forceMagni
|
|||
// job.save(outputPath);
|
||||
// settings.save(outputPath);
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
std::cout << "Force:" << forceMagnitude << " Error is:" << vcg::math::ToDeg(error) << std::endl;
|
||||
#endif
|
||||
return error;
|
||||
|
@ -1560,7 +1568,7 @@ double ReducedModelOptimizer::computeFullPatternMaxSimulationForce(
|
|||
|
||||
switch (scenario) {
|
||||
case Axial:
|
||||
global.desiredMaxDisplacementValue = 0.03 * baseTriangleHeight;
|
||||
global.desiredMaxDisplacementValue = 0.04 * baseTriangleHeight;
|
||||
break;
|
||||
case Shear:
|
||||
global.desiredMaxDisplacementValue = 0.04 * baseTriangleHeight;
|
||||
|
@ -1922,7 +1930,11 @@ void ReducedModelOptimizer::optimize(
|
|||
.append(m_pFullPatternSimulationMesh->getLabel())
|
||||
.append(pFullPatternSimulationJob->getLabel()));
|
||||
// .append(pFullPatternSimulationJob->getLabel() + ".json")
|
||||
constexpr bool recomputeFullPatternResults = false;
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
constexpr bool recomputeFullPatternResults = true;
|
||||
#else
|
||||
constexpr bool recomputeFullPatternResults = true;
|
||||
#endif
|
||||
SimulationResults fullPatternResults;
|
||||
if (!recomputeFullPatternResults && std::filesystem::exists(jobResultsDirectoryPath)) {
|
||||
fullPatternResults.load(std::filesystem::path(jobResultsDirectoryPath).append("Results"),
|
||||
|
@ -2034,10 +2046,10 @@ void ReducedModelOptimizer::optimize(
|
|||
global.fullPatternSimulationJobs[0]->pMesh->unregister();
|
||||
}
|
||||
#endif
|
||||
if (global.optimizationSettings.normalizationStrategy
|
||||
== Settings::NormalizationStrategy::Epsilon) {
|
||||
computeObjectiveValueNormalizationFactors();
|
||||
}
|
||||
// if (global.optimizationSettings.normalizationStrategy
|
||||
// == Settings::NormalizationStrategy::Epsilon) {
|
||||
computeObjectiveValueNormalizationFactors();
|
||||
// }
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
std::cout << "Running reduced model optimization" << std::endl;
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue