Added potential energy error term in addition to the displacement error term

This commit is contained in:
iasonmanolas 2022-01-14 14:27:21 +02:00
parent 534efb98bb
commit eaad6cb308
3 changed files with 71 additions and 70 deletions

View File

@ -153,7 +153,9 @@ int main(int argc, char *argv[])
csv_resultsLocalFile << endrow;
}
ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
#ifdef POLYSCOPE_DEFINED
std::vector<std::string> scenarioLabels(
optimizationResults.objectiveValue.perSimulationScenario_total.size());
const double colorAxial = 1;
@ -161,7 +163,8 @@ int main(int argc, char *argv[])
const double colorBending = 5;
const double colorDome = 0.1;
const double colorSaddle = 0;
std::vector<double> colors(optimizationResults.objectiveValue.perSimulationScenario_total.size());
std::vector<double> colors(
optimizationResults.objectiveValue.perSimulationScenario_total.size());
for (int scenarioIndex = 0; scenarioIndex < scenarioLabels.size(); scenarioIndex++) {
scenarioLabels[scenarioIndex]
= optimizationResults.reducedPatternSimulationJobs[scenarioIndex]->getLabel();
@ -187,7 +190,8 @@ int main(int argc, char *argv[])
y[scenarioIndex]
// = optimizationResults.objectiveValue.perSimulationScenario_rawTranslational[scenarioIndex]
// + optimizationResults.objectiveValue.perSimulationScenario_rawRotational[scenarioIndex];
= optimizationResults.objectiveValue.perSimulationScenario_total_unweighted[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);
@ -206,7 +210,6 @@ int main(int argc, char *argv[])
// ReducedModelOptimization::Results optResults;
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)");
ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
#endif
return 0;
}

View File

@ -108,9 +108,9 @@ double ReducedModelOptimizer::computeRawRotationalError(
{
double rawRotationalError = 0;
for (const auto &reducedToFullInterfaceViPair : reducedToFullInterfaceViMap) {
const double vertexRotationalError
= rotatedQuaternion_fullPattern[reducedToFullInterfaceViPair.second].angularDistance(
rotatedQuaternion_reducedPattern[reducedToFullInterfaceViPair.first]);
const double vertexRotationalError = std::abs(
rotatedQuaternion_fullPattern[reducedToFullInterfaceViPair.second].angularDistance(
rotatedQuaternion_reducedPattern[reducedToFullInterfaceViPair.first]));
rawRotationalError += vertexRotationalError;
}
@ -247,7 +247,7 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
// FormFinder simulator;
std::for_each(
std::execution::par_unseq,
// std::execution::par_unseq,
global.simulationScenarioIndices.begin(),
global.simulationScenarioIndices.end(),
[&](const int &simulationScenarioIndex) {
@ -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);
@ -978,7 +975,8 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
.append(m_pFullPatternSimulationMesh->getLabel() + ".json"));
const bool fullPatternScenarioMagnitudesExist = std::filesystem::exists(
patternMaxForceMagnitudesFilePath);
if (fullPatternScenarioMagnitudesExist) {
constexpr bool recomputeMagnitudes = false;
if (fullPatternScenarioMagnitudesExist && !recomputeMagnitudes) {
nlohmann::json json;
std::ifstream ifs(patternMaxForceMagnitudesFilePath.string());
ifs >> json;
@ -1798,9 +1796,9 @@ void ReducedModelOptimizer::computeObjectiveValueNormalizationFactors()
continue;
}
}
angularDistanceSum += global.fullPatternResults[simulationScenarioIndex]
angularDistanceSum += std::abs(global.fullPatternResults[simulationScenarioIndex]
.rotationalDisplacementQuaternion[fullPatternVi]
.angularDistance(Eigen::Quaterniond::Identity());
.angularDistance(Eigen::Quaterniond::Identity()));
}
fullPatternTranslationalDisplacementNormSum[simulationScenarioIndex]
@ -1916,7 +1914,7 @@ void ReducedModelOptimizer::optimize(
.append(m_pFullPatternSimulationMesh->getLabel())
.append(pFullPatternSimulationJob->getLabel()));
// .append(pFullPatternSimulationJob->getLabel() + ".json")
constexpr bool recomputeFullPatternResults = false;
constexpr bool recomputeFullPatternResults = true;
SimulationResults fullPatternResults;
if (!recomputeFullPatternResults && std::filesystem::exists(jobResultsDirectoryPath)) {
fullPatternResults.load(std::filesystem::path(jobResultsDirectoryPath).append("Results"),

View File

@ -66,7 +66,7 @@ public:
// inline constexpr static ParameterLabels parameterLabels();
inline static std::array<std::string, ReducedModelOptimization::NumberOfOptimizationVariables>
parameterLabels = {"R", "A", "I2", "I3", "J", "Theta", "R"};
parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"};
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
simulationScenariosResolution = {11, 11, 20, 20, 20};
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>