From eaad6cb308d30e5c84986ae95e948cdf8557c84f Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Fri, 14 Jan 2022 14:27:21 +0200 Subject: [PATCH 1/6] Added potential energy error term in addition to the displacement error term --- src/main.cpp | 101 +++++++++++++++++----------------- src/reducedmodeloptimizer.cpp | 38 ++++++------- src/reducedmodeloptimizer.hpp | 2 +- 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d0fd56e..85e265f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,60 +153,63 @@ int main(int argc, char *argv[]) csv_resultsLocalFile << endrow; } + ReducedModelEvaluator::evaluateReducedModel(optimizationResults); #ifdef POLYSCOPE_DEFINED - std::vector 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 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; + std::vector 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 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("Bending", 0) == 0) { - colors[scenarioIndex] = colorBending; + } else if (scenarioLabels[scenarioIndex].rfind("Shear", 0) == 0) { + colors[scenarioIndex] = colorShear; - } 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 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 x = matplot::linspace(0, y.size() - 1, y.size()); - std::vector 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("Bending", 0) == 0) { + colors[scenarioIndex] = colorBending; - // ReducedModelOptimization::Results optResults; - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); - ReducedModelEvaluator::evaluateReducedModel(optimizationResults); + } 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 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 x = matplot::linspace(0, y.size() - 1, y.size()); + std::vector 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)"); #endif return 0; } diff --git a/src/reducedmodeloptimizer.cpp b/src/reducedmodeloptimizer.cpp index 2f681dd..4791a5f 100644 --- a/src/reducedmodeloptimizer.cpp +++ b/src/reducedmodeloptimizer.cpp @@ -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 &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 &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 &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 &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] - .rotationalDisplacementQuaternion[fullPatternVi] - .angularDistance(Eigen::Quaterniond::Identity()); + angularDistanceSum += std::abs(global.fullPatternResults[simulationScenarioIndex] + .rotationalDisplacementQuaternion[fullPatternVi] + .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"), diff --git a/src/reducedmodeloptimizer.hpp b/src/reducedmodeloptimizer.hpp index 7271256..d22d0bb 100644 --- a/src/reducedmodeloptimizer.hpp +++ b/src/reducedmodeloptimizer.hpp @@ -66,7 +66,7 @@ public: // inline constexpr static ParameterLabels parameterLabels(); inline static std::array - parameterLabels = {"R", "A", "I2", "I3", "J", "Theta", "R"}; + parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"}; constexpr static std::array simulationScenariosResolution = {11, 11, 20, 20, 20}; constexpr static std::array From 9f1a13d30c79609125ed2a97e5deaa38d8d1d142 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Tue, 18 Jan 2022 10:37:07 +0200 Subject: [PATCH 2/6] Added evaluateReducedModel in POLYSCOPE_DEFINED block --- src/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 85e265f..544ca53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,8 @@ #endif int main(int argc, char *argv[]) { - // ReducedModelOptimization::Results optResults; +#ifdef POLYSCOPE_DEFINED + ReducedModelOptimization::Results optResults; // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" // "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); // optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat " @@ -32,7 +33,11 @@ int main(int argc, char *argv[]) // "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)"); // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" // "singlePattern_ensmallen_AllVars_optParameters/7#12"); - // ReducedModelEvaluator::evaluateReducedModel(optResults); + optResults.load("/home/iason/Desktop/finding_submissionCode/" + "build-ReducedModelOptimization-Clang-RelWithDebInfo/OptimizationResults/" + "ConvergedJobs/12@single_reduced(100000_1.20)"); + ReducedModelEvaluator::evaluateReducedModel(optResults); +#endif if (argc <= 5) { std::cerr << "Wrong number of input parameters. Expects at least 4 input parameters." "Usage:\n" @@ -153,8 +158,8 @@ int main(int argc, char *argv[]) csv_resultsLocalFile << endrow; } - ReducedModelEvaluator::evaluateReducedModel(optimizationResults); #ifdef POLYSCOPE_DEFINED + ReducedModelEvaluator::evaluateReducedModel(optimizationResults); std::vector scenarioLabels( optimizationResults.objectiveValue.perSimulationScenario_total.size()); From 992f821c0b6b20953a10f55fe35e763ae01d7809 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Wed, 19 Jan 2022 12:09:20 +0200 Subject: [PATCH 3/6] Removed optimization settings as compulsory argument --- src/main.cpp | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 544ca53..8175465 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,28 +23,27 @@ int main(int argc, char *argv[]) { #ifdef POLYSCOPE_DEFINED - ReducedModelOptimization::Results optResults; - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); - // optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat " - // "patterns/ReducedModelOptimization/Results/OptimizationResults/" - // "objectiveFunction/ConvergedJobs/testSet/7#12"); - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)"); - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_ensmallen_AllVars_optParameters/7#12"); - optResults.load("/home/iason/Desktop/finding_submissionCode/" - "build-ReducedModelOptimization-Clang-RelWithDebInfo/OptimizationResults/" - "ConvergedJobs/12@single_reduced(100000_1.20)"); - ReducedModelEvaluator::evaluateReducedModel(optResults); +// ReducedModelOptimization::Results optResults; +// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" +// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); +// optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat " +// "patterns/ReducedModelOptimization/Results/OptimizationResults/" +// "objectiveFunction/ConvergedJobs/testSet/7#12"); +// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" +// "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)"); +// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" +// "singlePattern_ensmallen_AllVars_optParameters/7#12"); +// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/dlib_firstSubmission/" +// "ConvergedJobs/72@single_reduced(100000_1.20)"); +// ReducedModelEvaluator::evaluateReducedModel(optResults); #endif - if (argc <= 5) { + 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" + "3)Optimization results directory path\n" + "4)[optional]Optimization settings json file path\n" "5)[optional]Intermediate results directory path\n" "Exiting.." << std::endl; @@ -66,25 +65,27 @@ 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 > 3) { + const std::filesystem::path optimizationSettingsFilePath = argv[4]; + 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[4]; + const std::string optimizationResultsDirectory = argv[3]; std::string resultsOutputDir; bool optimizationResultFolderExists = false; const std::filesystem::path crashedJobsDirPath( From 411b8b47c8de10c4841e842612a2d4fbf7dbe400 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Wed, 19 Jan 2022 12:18:25 +0200 Subject: [PATCH 4/6] Added MySources as a submodule --- .gitmodules | 3 +++ deps/MySources | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 deps/MySources diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8708fe2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/MySources"] + path = deps/MySources + url = https://gitea-s2i2s.isti.cnr.it/manolas/MySources diff --git a/deps/MySources b/deps/MySources new file mode 160000 index 0000000..f79e0ac --- /dev/null +++ b/deps/MySources @@ -0,0 +1 @@ +Subproject commit f79e0acb4f3361939cc495956b7afb52a318d02b From ace90996bb77b9254995a0e5f14f524ed3efe8c9 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Wed, 19 Jan 2022 12:20:43 +0200 Subject: [PATCH 5/6] Removed optimization settings as compulsory argument --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8175465..bf43bc8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) // 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.setDefault(); From 1e384c14a75bce89a92256bf29a1731ee827149c Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Mon, 24 Jan 2022 11:17:02 +0200 Subject: [PATCH 6/6] Updated the base scenario max displacements --- src/main.cpp | 32 ++++-------- src/reducedmodeloptimizer.cpp | 95 +++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 65 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bf43bc8..c70781a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,18 +24,10 @@ int main(int argc, char *argv[]) { #ifdef POLYSCOPE_DEFINED // ReducedModelOptimization::Results optResults; -// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" -// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); -// optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat " -// "patterns/ReducedModelOptimization/Results/OptimizationResults/" -// "objectiveFunction/ConvergedJobs/testSet/7#12"); -// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" -// "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)"); -// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" -// "singlePattern_ensmallen_AllVars_optParameters/7#12"); -// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/dlib_firstSubmission/" -// "ConvergedJobs/72@single_reduced(100000_1.20)"); +// 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." @@ -43,8 +35,8 @@ int main(int argc, char *argv[]) "1)full pattern file path\n" "2)reduced pattern file path\n" "3)Optimization results directory path\n" - "4)[optional]Optimization settings json file path\n" - "5)[optional]Intermediate 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; @@ -66,8 +58,8 @@ int main(int argc, char *argv[]) // Set the optization settings ReducedModelOptimization::Settings settings_optimization; - if (argc > 3) { - const std::filesystem::path optimizationSettingsFilePath = argv[4]; + 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; @@ -120,9 +112,9 @@ int main(int argc, char *argv[]) const std::vector 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, @@ -161,7 +153,6 @@ int main(int argc, char *argv[]) #ifdef POLYSCOPE_DEFINED ReducedModelEvaluator::evaluateReducedModel(optimizationResults); - std::vector scenarioLabels( optimizationResults.objectiveValue.perSimulationScenario_total.size()); const double colorAxial = 1; @@ -211,11 +202,8 @@ int main(int argc, char *argv[]) .append("perScenarioObjectiveValues.png")); // optimizationResults.saveMeshFiles(); std::cout << "Saved results to:" << resultsOutputDir << std::endl; - // optimizationResults.draw(); + optimizationResults.draw(); - // ReducedModelOptimization::Results optResults; - // optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/" - // "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)"); #endif return 0; } diff --git a/src/reducedmodeloptimizer.cpp b/src/reducedmodeloptimizer.cpp index 4791a5f..cb487d9 100644 --- a/src/reducedmodeloptimizer.cpp +++ b/src/reducedmodeloptimizer.cpp @@ -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; @@ -186,16 +186,16 @@ struct EnsmallenOptimizationObjective //#ifdef POLYSCOPE_DEFINED // std::cout << "Out of range" << std::endl; //#endif - // return std::numeric_limits::max(); - // return 1000; - x[xi] = global.xMax[xi]; + return std::numeric_limits::max(); + // return 1e10; + // x[xi] = global.xMax[xi]; } else if (x[xi] < global.xMin[xi]) { //#ifdef POLYSCOPE_DEFINED // std::cout << "Out of range" << std::endl; //#endif - // return std::numeric_limits::max(); - // return 1000; - x[xi] = global.xMin[xi]; + return std::numeric_limits::max(); + // return 1e10; + // x[xi] = global.xMin[xi]; } } return ReducedModelOptimizer::objective(x); @@ -247,7 +247,7 @@ double ReducedModelOptimizer::objective(const std::vector &x) // FormFinder simulator; std::for_each( - // std::execution::par_unseq, + std::execution::par_unseq, global.simulationScenarioIndices.begin(), global.simulationScenarioIndices.end(), [&](const int &simulationScenarioIndex) { @@ -267,10 +267,10 @@ double ReducedModelOptimizer::objective(const std::vector &x) std::cout << "Failed simulation" << std::endl; #endif } else { - const double simulationScenarioError_PE = std::abs( - (reducedModelResults.internalPotentialEnergy - - global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy) - / global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy); +// const double simulationScenarioError_PE = std::abs( +// (reducedModelResults.internalPotentialEnergy +// - global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy) +// / global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy); // else { #ifdef POLYSCOPE_DEFINED #ifdef USE_SCENARIO_WEIGHTS @@ -291,7 +291,7 @@ double ReducedModelOptimizer::objective(const std::vector &x) global.objectiveWeights[simulationScenarioIndex]); simulationErrorsPerScenario[simulationScenarioIndex] - = simulationScenarioError_displacements + simulationScenarioError_PE; + = simulationScenarioError_displacements /*+ simulationScenarioError_PE*/; // } // #ifdef POLYSCOPE_DEFINED // reducedJob->pMesh->registerForDrawing(Colors::reducedInitial); @@ -309,9 +309,9 @@ double ReducedModelOptimizer::objective(const std::vector &x) // double totalError = std::accumulate(simulationErrorsPerScenario.begin(), // simulationErrorsPerScenario.end(), // 0); - double totalError = std::reduce(std::execution::par_unseq, - simulationErrorsPerScenario.begin(), - simulationErrorsPerScenario.end()); + const double totalError = std::reduce(std::execution::par_unseq, + simulationErrorsPerScenario.begin(), + simulationErrorsPerScenario.end()); // std::cout << totalError << std::endl; // global.objectiveValueHistory.push_back(totalError); // global.plotColors.push_back(10); @@ -975,7 +975,7 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces( .append(m_pFullPatternSimulationMesh->getLabel() + ".json")); const bool fullPatternScenarioMagnitudesExist = std::filesystem::exists( patternMaxForceMagnitudesFilePath); - constexpr bool recomputeMagnitudes = false; + constexpr bool recomputeMagnitudes = true; if (fullPatternScenarioMagnitudesExist && !recomputeMagnitudes) { nlohmann::json json; std::ifstream ifs(patternMaxForceMagnitudesFilePath.string()); @@ -996,6 +996,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()); @@ -1094,12 +1099,12 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings, // ens::CNE optimizer; // ens::DE optimizer; // ens::SPSA optimizer; - // arma::mat xMin_arma(global.xMin); - // arma::mat xMax_arma(global.xMax); + arma::mat xMin_arma(global.xMin); + arma::mat xMax_arma(global.xMax); // ens::LBestPSO optimizer(64, xMin_arma, xMax_arma, 1000); - ens::LBestPSO optimizer(64, - 1, - 1, + ens::LBestPSO optimizer(200, + xMin_arma, + xMax_arma, settings.numberOfFunctionCalls, 500, settings.solverAccuracy, @@ -1322,14 +1327,14 @@ void ReducedModelOptimizer::constructDomeSimulationScenario( = Eigen::Vector3d(-interfaceVector[0], -interfaceVector[1], 0) - * 0.005 + * 0.001 * std::abs( forceMagnitude); //NOTE:Should the forced displacement change relatively to the magnitude? // * std::abs(forceMagnitude / maxForceMagnitude_dome); job.nodalForcedDisplacements[viPair.second] = Eigen::Vector3d(interfaceVector[0], interfaceVector[1], 0) - * 0.005 * std::abs(forceMagnitude); + * 0.001 * std::abs(forceMagnitude); // * std::abs(forceMagnitude / maxForceMagnitude_dome); // CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP()) // ^ CoordType(0, 0, -1).Normalize(); @@ -1560,19 +1565,22 @@ double ReducedModelOptimizer::computeFullPatternMaxSimulationForce( global.desiredMaxDisplacementValue = 0.03 * baseTriangleHeight; break; case Shear: - global.desiredMaxDisplacementValue = 0.03 * baseTriangleHeight; + global.desiredMaxDisplacementValue = 0.04 * baseTriangleHeight; break; case Bending: + global.interfaceViForComputingScenarioError = global.fullPatternInterfaceViPairs[0].first; + global.desiredMaxDisplacementValue = 0.05 * baseTriangleHeight; break; case Dome: - global.desiredMaxRotationAngle = vcg::math::ToRad(35.0); + global.desiredMaxRotationAngle = vcg::math::ToRad(20.0); objectiveFunction = &fullPatternMaxSimulationForceRotationalObjective; forceMagnitudeEpsilon *= 1e-2; - objectiveEpsilon = vcg::math::ToRad(3.0); + objectiveEpsilon = vcg::math::ToRad(1.0); forceMagnitude = 0.6; break; case Saddle: global.interfaceViForComputingScenarioError = global.fullPatternInterfaceViPairs[0].first; + global.desiredMaxDisplacementValue = 0.05 * baseTriangleHeight; break; } @@ -1907,6 +1915,7 @@ void ReducedModelOptimizer::optimize( for (int simulationScenarioIndex : global.simulationScenarioIndices) { const std::shared_ptr &pFullPatternSimulationJob = global.fullPatternSimulationJobs[simulationScenarioIndex]; + // std::cout << pFullPatternSimulationJob->getLabel() << std::endl; std::filesystem::path jobResultsDirectoryPath( std::filesystem::path(intermediateResultsDirectoryPath) @@ -1914,7 +1923,7 @@ void ReducedModelOptimizer::optimize( .append(m_pFullPatternSimulationMesh->getLabel()) .append(pFullPatternSimulationJob->getLabel())); // .append(pFullPatternSimulationJob->getLabel() + ".json") - constexpr bool recomputeFullPatternResults = true; + constexpr bool recomputeFullPatternResults = false; SimulationResults fullPatternResults; if (!recomputeFullPatternResults && std::filesystem::exists(jobResultsDirectoryPath)) { fullPatternResults.load(std::filesystem::path(jobResultsDirectoryPath).append("Results"),