Refactoring.Addded multiple simulation scenarios
This commit is contained in:
parent
49494ccef8
commit
b54662be9e
23
src/main.cpp
23
src/main.cpp
|
|
@ -40,21 +40,21 @@ int main(int argc, char *argv[]) {
|
||||||
reducedPattern.scale(0.03, interfaceNodeIndex);
|
reducedPattern.scale(0.03, interfaceNodeIndex);
|
||||||
|
|
||||||
// Set the optization settings
|
// Set the optization settings
|
||||||
ReducedModelOptimization::xRange beamE{"E", 0.001, 1000};
|
ReducedPatternOptimization::xRange beamE{"E", 0.001, 1000};
|
||||||
ReducedModelOptimization::xRange beamA{"A", 0.001, 1000};
|
ReducedPatternOptimization::xRange beamA{"A", 0.001, 1000};
|
||||||
ReducedModelOptimization::xRange beamI2{"I2", 0.001, 1000};
|
ReducedPatternOptimization::xRange beamI2{"I2", 0.001, 1000};
|
||||||
ReducedModelOptimization::xRange beamI3{"I3", 0.001, 1000};
|
ReducedPatternOptimization::xRange beamI3{"I3", 0.001, 1000};
|
||||||
ReducedModelOptimization::xRange beamJ{"J", 0.001, 1000};
|
ReducedPatternOptimization::xRange beamJ{"J", 0.001, 1000};
|
||||||
ReducedModelOptimization::xRange innerHexagonSize{"HexSize", 0.05, 0.95};
|
ReducedPatternOptimization::xRange innerHexagonSize{"HexSize", 0.05, 0.95};
|
||||||
ReducedModelOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0};
|
ReducedPatternOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0};
|
||||||
ReducedModelOptimization::Settings settings_optimization;
|
ReducedPatternOptimization::Settings settings_optimization;
|
||||||
settings_optimization.xRanges = {beamE,beamA,beamJ,beamI2,beamI3,
|
settings_optimization.xRanges = {beamE,beamA,beamJ,beamI2,beamI3,
|
||||||
innerHexagonSize, innerHexagonAngle};
|
innerHexagonSize, innerHexagonAngle};
|
||||||
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
||||||
settings_optimization.numberOfFunctionCalls =
|
settings_optimization.numberOfFunctionCalls =
|
||||||
input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100;
|
input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100;
|
||||||
settings_optimization.normalizationStrategy
|
settings_optimization.normalizationStrategy
|
||||||
= ReducedModelOptimization::Settings::NormalizationStrategy::Epsilon;
|
= ReducedPatternOptimization::Settings::NormalizationStrategy::Epsilon;
|
||||||
settings_optimization.normalizationParameter = 0.0003;
|
settings_optimization.normalizationParameter = 0.0003;
|
||||||
settings_optimization.solutionAccuracy = 0.001;
|
settings_optimization.solutionAccuracy = 0.001;
|
||||||
|
|
||||||
|
|
@ -66,7 +66,8 @@ int main(int argc, char *argv[]) {
|
||||||
assert(interfaceNodeIndex==numberOfNodesPerSlot[0]+numberOfNodesPerSlot[3]);
|
assert(interfaceNodeIndex==numberOfNodesPerSlot[0]+numberOfNodesPerSlot[3]);
|
||||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||||
optimizer.initializePatterns(fullPattern, reducedPattern, settings_optimization.xRanges.size());
|
optimizer.initializePatterns(fullPattern, reducedPattern, settings_optimization.xRanges.size());
|
||||||
ReducedModelOptimization::Results optimizationResults = optimizer.optimize(settings_optimization);
|
ReducedPatternOptimization::Results optimizationResults = optimizer.optimize(
|
||||||
|
settings_optimization);
|
||||||
|
|
||||||
// Export results
|
// Export results
|
||||||
const bool input_resultDirectoryDefined = argc >= 5;
|
const bool input_resultDirectoryDefined = argc >= 5;
|
||||||
|
|
@ -105,7 +106,9 @@ int main(int argc, char *argv[]) {
|
||||||
csv_results << endrow;
|
csv_results << endrow;
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
|
optimizationResults.saveMeshFiles();
|
||||||
optimizationResults.draw();
|
optimizationResults.draw();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@
|
||||||
#include "trianglepatterngeometry.hpp"
|
#include "trianglepatterngeometry.hpp"
|
||||||
#include "trianglepattterntopology.hpp"
|
#include "trianglepattterntopology.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <dlib/global_optimization.h>
|
|
||||||
#include <dlib/optimization.h>
|
|
||||||
|
|
||||||
using namespace ReducedModelOptimization;
|
using namespace ReducedPatternOptimization;
|
||||||
|
|
||||||
struct GlobalOptimizationVariables {
|
struct GlobalOptimizationVariables {
|
||||||
// std::vector<std::vector<Vector6d>> fullPatternDisplacements;
|
// std::vector<std::vector<Vector6d>> fullPatternDisplacements;
|
||||||
|
|
@ -22,15 +20,12 @@ struct GlobalOptimizationVariables {
|
||||||
std::vector<double> objectiveValueHistory;
|
std::vector<double> objectiveValueHistory;
|
||||||
Eigen::VectorXd initialParameters;
|
Eigen::VectorXd initialParameters;
|
||||||
std::vector<int> simulationScenarioIndices;
|
std::vector<int> simulationScenarioIndices;
|
||||||
std::vector<VectorType> g_innerHexagonVectors{6, VectorType(0, 0, 0)};
|
|
||||||
double innerHexagonInitialRotationAngle{30};
|
|
||||||
double innerHexagonInitialPos{0};
|
|
||||||
double minY{DBL_MAX};
|
double minY{DBL_MAX};
|
||||||
std::vector<double> minX;
|
std::vector<double> minX;
|
||||||
int numOfSimulationCrashes{false};
|
int numOfSimulationCrashes{false};
|
||||||
int numberOfFunctionCalls{0};
|
int numberOfFunctionCalls{0};
|
||||||
int numberOfOptimizationParameters{5};
|
int numberOfOptimizationParameters{5};
|
||||||
ReducedModelOptimization::Settings optimizationSettings;
|
ReducedPatternOptimization::Settings optimizationSettings;
|
||||||
vcg::Triangle3<double> baseTriangle;
|
vcg::Triangle3<double> baseTriangle;
|
||||||
} global;
|
} global;
|
||||||
|
|
||||||
|
|
@ -41,13 +36,13 @@ double ReducedModelOptimizer::computeDisplacementError(
|
||||||
&reducedToFullInterfaceViMap,
|
&reducedToFullInterfaceViMap,
|
||||||
const double &normalizationFactor)
|
const double &normalizationFactor)
|
||||||
{
|
{
|
||||||
const double rawError = computeRawDisplacementError(fullPatternDisplacements,
|
const double rawError = computeRawTranslationalError(fullPatternDisplacements,
|
||||||
reducedPatternDisplacements,
|
reducedPatternDisplacements,
|
||||||
reducedToFullInterfaceViMap);
|
reducedToFullInterfaceViMap);
|
||||||
return rawError / normalizationFactor;
|
return rawError / normalizationFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ReducedModelOptimizer::computeRawDisplacementError(
|
double ReducedModelOptimizer::computeRawTranslationalError(
|
||||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
const std::vector<Vector6d> &fullPatternDisplacements,
|
||||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
const std::vector<Vector6d> &reducedPatternDisplacements,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||||
|
|
@ -56,18 +51,14 @@ double ReducedModelOptimizer::computeRawDisplacementError(
|
||||||
double error = 0;
|
double error = 0;
|
||||||
for (const auto reducedFullViPair : reducedToFullInterfaceViMap) {
|
for (const auto reducedFullViPair : reducedToFullInterfaceViMap) {
|
||||||
const VertexIndex reducedModelVi = reducedFullViPair.first;
|
const VertexIndex reducedModelVi = reducedFullViPair.first;
|
||||||
Eigen::Vector3d reducedVertexDisplacement(
|
|
||||||
reducedPatternDisplacements[reducedModelVi][0],
|
|
||||||
reducedPatternDisplacements[reducedModelVi][1],
|
|
||||||
reducedPatternDisplacements[reducedModelVi][2]);
|
|
||||||
const VertexIndex fullModelVi = reducedFullViPair.second;
|
const VertexIndex fullModelVi = reducedFullViPair.second;
|
||||||
Eigen::Vector3d fullVertexDisplacement(
|
const Eigen::Vector3d fullPatternVertexDiplacement = fullPatternDisplacements[fullModelVi]
|
||||||
fullPatternDisplacements[fullModelVi][0],
|
.getTranslation();
|
||||||
fullPatternDisplacements[fullModelVi][1],
|
const Eigen::Vector3d reducedPatternVertexDiplacement
|
||||||
fullPatternDisplacements[fullModelVi][2]);
|
= reducedPatternDisplacements[reducedModelVi].getTranslation();
|
||||||
Eigen::Vector3d errorVector =
|
const double vertexError = (fullPatternVertexDiplacement - reducedPatternVertexDiplacement)
|
||||||
fullVertexDisplacement - reducedVertexDisplacement;
|
.norm();
|
||||||
error += errorVector.norm();
|
error += vertexError;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
@ -121,7 +112,7 @@ double ReducedModelOptimizer::computeError(
|
||||||
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||||
reducedToFullInterfaceViMap,
|
reducedToFullInterfaceViMap,
|
||||||
normalizationFactor_rotationalDisplacement);
|
normalizationFactor_rotationalDisplacement);
|
||||||
return translationalError + rotationalError;
|
return 1.5 * translationalError + 0.5 * rotationalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ReducedModelOptimizer::objective(double E,double A,double J,double I2,double I3,
|
double ReducedModelOptimizer::objective(double E,double A,double J,double I2,double I3,
|
||||||
|
|
@ -226,10 +217,10 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
||||||
global.minX.assign(x, x + n);
|
global.minX.assign(x, x + n);
|
||||||
}
|
}
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
// if (++global.numberOfFunctionCalls % 100 == 0) {
|
++global.numberOfFunctionCalls;
|
||||||
// std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
if (global.numberOfFunctionCalls % 100 == 0) {
|
||||||
// << std::endl;
|
std::cout << "Number of function calls:" << global.numberOfFunctionCalls << std::endl;
|
||||||
// }
|
}
|
||||||
#endif
|
#endif
|
||||||
// compute error and return it
|
// compute error and return it
|
||||||
// global.objectiveValueHistory.push_back(totalError);
|
// global.objectiveValueHistory.push_back(totalError);
|
||||||
|
|
@ -517,9 +508,6 @@ void ReducedModelOptimizer::initializeOptimizationParameters(
|
||||||
global.initialParameters(2) = mesh->elements[0].J;
|
global.initialParameters(2) = mesh->elements[0].J;
|
||||||
global.initialParameters(3) = mesh->elements[0].I2;
|
global.initialParameters(3) = mesh->elements[0].I2;
|
||||||
global.initialParameters(4) = mesh->elements[0].I3;
|
global.initialParameters(4) = mesh->elements[0].I3;
|
||||||
global.initialParameters(optimizationParamters-2) = global.innerHexagonInitialPos;
|
|
||||||
global.innerHexagonInitialRotationAngle = 30;
|
|
||||||
global.initialParameters(optimizationParamters-1) = global.innerHexagonInitialRotationAngle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReducedModelOptimizer::computeReducedModelSimulationJob(
|
void ReducedModelOptimizer::computeReducedModelSimulationJob(
|
||||||
|
|
@ -674,89 +662,105 @@ void ReducedModelOptimizer::computeDesiredReducedModelDisplacements(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReducedModelOptimization::Results
|
ReducedPatternOptimization::Results ReducedModelOptimizer::getResults(
|
||||||
ReducedModelOptimizer::runOptimization(const Settings &settings) {
|
const dlib::function_evaluation &optimizationResult_dlib, const Settings &settings)
|
||||||
|
{
|
||||||
|
ReducedPatternOptimization::Results results;
|
||||||
|
|
||||||
global.objectiveValueHistory.clear();
|
results.baseTriangle = global.baseTriangle;
|
||||||
dlib::matrix<double, 0, 1> xMin(global.numberOfOptimizationParameters);
|
//Number of crashes
|
||||||
dlib::matrix<double, 0, 1> xMax(global.numberOfOptimizationParameters);
|
results.numberOfSimulationCrashes = global.numOfSimulationCrashes;
|
||||||
for (int i = 0; i < global.numberOfOptimizationParameters; i++) {
|
//Value of optimal objective Y
|
||||||
xMin(i) = settings.xRanges[i].min;
|
results.objectiveValue.total = optimizationResult_dlib.y;
|
||||||
xMax(i) = settings.xRanges[i].max;
|
//Optimal X values
|
||||||
|
results.optimalXNameValuePairs.resize(settings.xRanges.size());
|
||||||
|
std::vector<double> optimalX(settings.xRanges.size());
|
||||||
|
for (int xVariableIndex = 0; xVariableIndex < settings.xRanges.size(); xVariableIndex++) {
|
||||||
|
if (xVariableIndex < 5) {
|
||||||
|
results.optimalXNameValuePairs[xVariableIndex]
|
||||||
|
= std::make_pair(settings.xRanges[xVariableIndex].label,
|
||||||
|
global.minX[xVariableIndex]
|
||||||
|
* global.initialParameters(xVariableIndex));
|
||||||
|
} else {
|
||||||
|
//Hex size and angle are pure values (not multipliers of the initial values)
|
||||||
|
results.optimalXNameValuePairs[xVariableIndex]
|
||||||
|
= std::make_pair(settings.xRanges[xVariableIndex].label,
|
||||||
|
global.minX[xVariableIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
assert(global.minX[xVariableIndex] == optimizationResult_dlib.x(xVariableIndex));
|
||||||
dlib::function_evaluation result;
|
optimalX[xVariableIndex] = optimizationResult_dlib.x(xVariableIndex);
|
||||||
double (*objF)(double, double, double, double, double,double,double) = &objective;
|
|
||||||
result = dlib::find_min_global(
|
|
||||||
objF, xMin, xMax,
|
|
||||||
dlib::max_function_calls(settings.numberOfFunctionCalls),
|
|
||||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
|
||||||
auto end = std::chrono::system_clock::now();
|
|
||||||
auto elapsed =
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
|
||||||
ReducedModelOptimization::Results results;
|
|
||||||
results.numberOfSimulationCrashes = global.numOfSimulationCrashes;
|
|
||||||
results.optimalXNameValuePairs.resize(settings.xRanges.size());
|
|
||||||
for(int xVariableIndex=0;xVariableIndex<settings.xRanges.size();xVariableIndex++){
|
|
||||||
results.optimalXNameValuePairs[xVariableIndex]
|
|
||||||
= std::make_pair(settings.xRanges[xVariableIndex].label, global.minX[xVariableIndex]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute obj value per simulation scenario and the raw objective value
|
// Compute obj value per simulation scenario and the raw objective value
|
||||||
results.rawObjectiveValue=0;
|
|
||||||
std::vector<double> optimalX(results.optimalXNameValuePairs.size());
|
|
||||||
for (int xVariableIndex = 0; xVariableIndex < global.numberOfOptimizationParameters;
|
|
||||||
xVariableIndex++) {
|
|
||||||
optimalX[xVariableIndex] = global.minX[xVariableIndex];
|
|
||||||
assert(global.minX[xVariableIndex] == result.x(xVariableIndex));
|
|
||||||
}
|
|
||||||
updateMesh(optimalX.size(), optimalX.data());
|
updateMesh(optimalX.size(), optimalX.data());
|
||||||
results.objectiveValuePerSimulationScenario.resize(totalNumberOfSimulationScenarios);
|
// results.objectiveValue.totalPerSimulationScenario.resize(totalNumberOfSimulationScenarios);
|
||||||
LinearSimulationModel simulator;
|
LinearSimulationModel simulator;
|
||||||
double totalObjectiveValue = 0;
|
results.objectiveValue.totalRaw = 0;
|
||||||
double totalRawObjectiveValue = 0;
|
results.objectiveValue.perSimulationScenario_translational.resize(
|
||||||
|
totalNumberOfSimulationScenarios);
|
||||||
|
results.objectiveValue.perSimulationScenario_rawTranslational.resize(
|
||||||
|
totalNumberOfSimulationScenarios);
|
||||||
|
results.objectiveValue.perSimulationScenario_rotational.resize(totalNumberOfSimulationScenarios);
|
||||||
|
results.objectiveValue.perSimulationScenario_rawRotational.resize(
|
||||||
|
totalNumberOfSimulationScenarios);
|
||||||
|
results.objectiveValue.perSimulationScenario_total.resize(totalNumberOfSimulationScenarios);
|
||||||
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||||
SimulationResults reducedModelResults = simulator.executeSimulation(
|
SimulationResults reducedModelResults = simulator.executeSimulation(
|
||||||
global.reducedPatternSimulationJobs[simulationScenarioIndex]);
|
global.reducedPatternSimulationJobs[simulationScenarioIndex]);
|
||||||
|
|
||||||
totalObjectiveValue += computeError(
|
results.objectiveValue.perSimulationScenario_total[simulationScenarioIndex] = computeError(
|
||||||
global.fullPatternResults[simulationScenarioIndex],
|
global.fullPatternResults[simulationScenarioIndex],
|
||||||
reducedModelResults,
|
reducedModelResults,
|
||||||
global.reducedToFullInterfaceViMap,
|
global.reducedToFullInterfaceViMap,
|
||||||
global.translationalDisplacementNormalizationValues[simulationScenarioIndex],
|
global.translationalDisplacementNormalizationValues[simulationScenarioIndex],
|
||||||
global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
||||||
|
|
||||||
const double rawTranslationalError = computeRawDisplacementError(
|
//Raw translational
|
||||||
|
const double rawTranslationalError = computeRawTranslationalError(
|
||||||
global.fullPatternResults[simulationScenarioIndex].displacements,
|
global.fullPatternResults[simulationScenarioIndex].displacements,
|
||||||
reducedModelResults.displacements,
|
reducedModelResults.displacements,
|
||||||
global.reducedToFullInterfaceViMap);
|
global.reducedToFullInterfaceViMap);
|
||||||
|
results.objectiveValue.perSimulationScenario_rawTranslational[simulationScenarioIndex]
|
||||||
|
= rawTranslationalError;
|
||||||
|
//Raw rotational
|
||||||
const double rawRotationalError = computeRawRotationalError(
|
const double rawRotationalError = computeRawRotationalError(
|
||||||
global.fullPatternResults[simulationScenarioIndex].rotationalDisplacementQuaternion,
|
global.fullPatternResults[simulationScenarioIndex].rotationalDisplacementQuaternion,
|
||||||
reducedModelResults.rotationalDisplacementQuaternion,
|
reducedModelResults.rotationalDisplacementQuaternion,
|
||||||
global.reducedToFullInterfaceViMap);
|
global.reducedToFullInterfaceViMap);
|
||||||
|
results.objectiveValue.perSimulationScenario_rawRotational[simulationScenarioIndex]
|
||||||
|
= rawRotationalError;
|
||||||
|
|
||||||
results.rawObjectiveValue += rawTranslationalError + rawRotationalError;
|
//Normalized translational
|
||||||
|
const double normalizedTranslationalError = computeDisplacementError(
|
||||||
const double normalizedTranslationalError
|
|
||||||
= rawTranslationalError
|
|
||||||
/ global.translationalDisplacementNormalizationValues[simulationScenarioIndex];
|
|
||||||
const double test_normalizedTranslationError = computeDisplacementError(
|
|
||||||
global.fullPatternResults[simulationScenarioIndex].displacements,
|
global.fullPatternResults[simulationScenarioIndex].displacements,
|
||||||
reducedModelResults.displacements,
|
reducedModelResults.displacements,
|
||||||
global.reducedToFullInterfaceViMap,
|
global.reducedToFullInterfaceViMap,
|
||||||
global.translationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
global.translationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
||||||
const double normalizedRotationalError
|
results.objectiveValue.perSimulationScenario_translational[simulationScenarioIndex]
|
||||||
= rawRotationalError
|
= normalizedTranslationalError;
|
||||||
/ global.rotationalDisplacementNormalizationValues[simulationScenarioIndex];
|
// const double test_normalizedTranslationError = computeDisplacementError(
|
||||||
const double test_normalizedRotationalError = computeRotationalError(
|
// global.fullPatternResults[simulationScenarioIndex].displacements,
|
||||||
|
// reducedModelResults.displacements,
|
||||||
|
// global.reducedToFullInterfaceViMap,
|
||||||
|
// global.translationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
||||||
|
//Normalized rotational
|
||||||
|
const double normalizedRotationalError = computeRotationalError(
|
||||||
global.fullPatternResults[simulationScenarioIndex].rotationalDisplacementQuaternion,
|
global.fullPatternResults[simulationScenarioIndex].rotationalDisplacementQuaternion,
|
||||||
reducedModelResults.rotationalDisplacementQuaternion,
|
reducedModelResults.rotationalDisplacementQuaternion,
|
||||||
global.reducedToFullInterfaceViMap,
|
global.reducedToFullInterfaceViMap,
|
||||||
global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
||||||
assert(test_normalizedTranslationError == normalizedTranslationalError);
|
results.objectiveValue.perSimulationScenario_rotational[simulationScenarioIndex]
|
||||||
assert(test_normalizedRotationalError == normalizedRotationalError);
|
= normalizedRotationalError;
|
||||||
std::cout << "Simulation scenario:" << baseSimulationScenarioNames[simulationScenarioIndex]
|
// const double test_normalizedRotationalError = computeRotationalError(
|
||||||
|
// global.fullPatternResults[simulationScenarioIndex].rotationalDisplacementQuaternion,
|
||||||
|
// reducedModelResults.rotationalDisplacementQuaternion,
|
||||||
|
// global.reducedToFullInterfaceViMap,
|
||||||
|
// global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]);
|
||||||
|
// assert(test_normalizedTranslationError == normalizedTranslationalError);
|
||||||
|
// assert(test_normalizedRotationalError == normalizedRotationalError);
|
||||||
|
std::cout << "Simulation scenario:"
|
||||||
|
<< global.reducedPatternSimulationJobs[simulationScenarioIndex]->getLabel()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "raw translational error:" << rawTranslationalError << std::endl;
|
std::cout << "raw translational error:" << rawTranslationalError << std::endl;
|
||||||
std::cout << "translation normalization value:"
|
std::cout << "translation normalization value:"
|
||||||
|
|
@ -768,50 +772,93 @@ ReducedModelOptimizer::runOptimization(const Settings &settings) {
|
||||||
<< global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]
|
<< global.rotationalDisplacementNormalizationValues[simulationScenarioIndex]
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "Rotational error:" << normalizedRotationalError << std::endl;
|
std::cout << "Rotational error:" << normalizedRotationalError << std::endl;
|
||||||
results.objectiveValuePerSimulationScenario[simulationScenarioIndex]
|
// results.objectiveValuePerSimulationScenario[simulationScenarioIndex]
|
||||||
= normalizedTranslationalError + normalizedRotationalError;
|
// = normalizedTranslationalError + normalizedRotationalError;
|
||||||
std::cout << "Objective value:"
|
std::cout << "Objective value:"
|
||||||
<< results.objectiveValuePerSimulationScenario[simulationScenarioIndex]
|
<< results.objectiveValue.perSimulationScenario_total[simulationScenarioIndex]
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
// totalObjectiveValue += results.objectiveValuePerSimulationScenario[simulationScenarioIndex];
|
results.objectiveValue.totalRaw += rawTranslationalError + rawRotationalError;
|
||||||
totalRawObjectiveValue += rawTranslationalError + rawRotationalError;
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
assert(result.y == global.minY);
|
|
||||||
results.objectiveValue = result.y;
|
|
||||||
auto functionReturnValue = objective(optimalX.size(), optimalX.data());
|
|
||||||
std::cout << "Total (functionReturn)" << functionReturnValue << std::endl;
|
|
||||||
std::cout << "Total:" << totalObjectiveValue << std::endl;
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
|
||||||
std::cout << "Total optimal objective value:" << results.objectiveValue << std::endl;
|
|
||||||
// std::cout << "Total raw objective value:" << global.minY << std::endl;
|
|
||||||
if (global.minY != result.y) {
|
|
||||||
std::cerr << "Global min objective is not equal to result objective" << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
results.time = elapsed.count() / 1000.0;
|
|
||||||
const bool printDebugInfo = false;
|
const bool printDebugInfo = false;
|
||||||
if (printDebugInfo) {
|
if (printDebugInfo) {
|
||||||
std::cout << "Finished optimizing." << endl;
|
std::cout << "Finished optimizing." << endl;
|
||||||
// std::cout << "Solution x:" << endl;
|
std::cout << "Total optimal objective value:" << results.objectiveValue.total << std::endl;
|
||||||
// std::cout << result.x << endl;
|
assert(global.minY == optimizationResult_dlib.y);
|
||||||
std::cout << "Objective value:" << global.minY << endl;
|
}
|
||||||
|
|
||||||
|
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||||
|
results.fullPatternSimulationJobs.push_back(
|
||||||
|
global.fullPatternSimulationJobs[simulationScenarioIndex]);
|
||||||
|
results.reducedPatternSimulationJobs.push_back(
|
||||||
|
global.reducedPatternSimulationJobs[simulationScenarioIndex]);
|
||||||
|
// const std::string temp = global.reducedPatternSimulationJobs[simulationScenarioIndex]
|
||||||
|
// ->pMesh->getLabel();
|
||||||
|
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->setLabel("temp");
|
||||||
|
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->registerForDrawing();
|
||||||
|
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->setLabel(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReducedPatternOptimization::Results ReducedModelOptimizer::runOptimization(const Settings &settings)
|
||||||
|
{
|
||||||
|
global.objectiveValueHistory.clear();
|
||||||
|
dlib::matrix<double, 0, 1> xMin(global.numberOfOptimizationParameters);
|
||||||
|
dlib::matrix<double, 0, 1> xMax(global.numberOfOptimizationParameters);
|
||||||
|
for (int i = 0; i < global.numberOfOptimizationParameters; i++) {
|
||||||
|
xMin(i) = settings.xRanges[i].min;
|
||||||
|
xMax(i) = settings.xRanges[i].max;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
dlib::function_evaluation result_dlib;
|
||||||
|
double (*objF)(double, double, double, double, double,double,double) = &objective;
|
||||||
|
result_dlib = dlib::find_min_global(objF,
|
||||||
|
xMin,
|
||||||
|
xMax,
|
||||||
|
dlib::max_function_calls(settings.numberOfFunctionCalls),
|
||||||
|
std::chrono::hours(24 * 365 * 290),
|
||||||
|
settings.solutionAccuracy);
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
auto elapsed =
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||||
|
ReducedPatternOptimization::Results results = getResults(result_dlib, settings);
|
||||||
|
results.time = elapsed.count() / 1000.0;
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: create a function that takes as arguments the magnitude range, a lambda that generates the simulation job and the base sim scenario index
|
||||||
std::vector<std::shared_ptr<SimulationJob>>
|
std::vector<std::shared_ptr<SimulationJob>>
|
||||||
ReducedModelOptimizer::createScenarios(
|
ReducedModelOptimizer::createFullPatternSimulationScenarios(
|
||||||
const std::shared_ptr<SimulationMesh> &pMesh) {
|
const std::shared_ptr<SimulationMesh> &pMesh)
|
||||||
|
{
|
||||||
std::vector<std::shared_ptr<SimulationJob>> scenarios;
|
std::vector<std::shared_ptr<SimulationJob>> scenarios;
|
||||||
scenarios.resize(totalNumberOfSimulationScenarios);
|
scenarios.resize(totalNumberOfSimulationScenarios);
|
||||||
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
||||||
std::unordered_map<VertexIndex, Vector6d> nodalForces;
|
std::unordered_map<VertexIndex, Vector6d> nodalForces;
|
||||||
|
|
||||||
//// Axial
|
//// Axial
|
||||||
int simulationScenarioIndex = BaseSimulationScenario::Axial;
|
const double maxForceMagnitude_axial = 500;
|
||||||
|
const double minForceMagnitude_axial = -500;
|
||||||
|
const int numberOfSimulationScenarios_axial
|
||||||
|
= simulationScenariosResolution[BaseSimulationScenario::Axial];
|
||||||
|
const double forceMagnitudeStep_axial = numberOfSimulationScenarios_axial == 1
|
||||||
|
? maxForceMagnitude_axial
|
||||||
|
: (maxForceMagnitude_axial - minForceMagnitude_axial)
|
||||||
|
/ (numberOfSimulationScenarios_axial - 1);
|
||||||
|
const int baseSimulationScenarioIndexOffset_axial
|
||||||
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
|
simulationScenariosResolution.begin() + BaseSimulationScenario::Axial,
|
||||||
|
0);
|
||||||
|
|
||||||
|
for (int axialSimulationScenarioIndex = 0;
|
||||||
|
axialSimulationScenarioIndex < numberOfSimulationScenarios_axial;
|
||||||
|
axialSimulationScenarioIndex++) {
|
||||||
|
const double forceMagnitude = (forceMagnitudeStep_axial * axialSimulationScenarioIndex
|
||||||
|
+ minForceMagnitude_axial);
|
||||||
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
||||||
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
||||||
viPairIt++) {
|
viPairIt++) {
|
||||||
|
|
@ -820,23 +867,41 @@ ReducedModelOptimizer::createScenarios(
|
||||||
const auto viPair = *viPairIt;
|
const auto viPair = *viPairIt;
|
||||||
nodalForces[viPair.first]
|
nodalForces[viPair.first]
|
||||||
= Vector6d({forceDirection[0], forceDirection[1], forceDirection[2], 0, 0, 0})
|
= Vector6d({forceDirection[0], forceDirection[1], forceDirection[2], 0, 0, 0})
|
||||||
* 500;
|
* forceMagnitude;
|
||||||
fixedVertices[viPair.second] =
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
||||||
std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scenarios[simulationScenarioIndex] = std::make_shared<SimulationJob>(
|
|
||||||
|
scenarios[baseSimulationScenarioIndexOffset_axial + axialSimulationScenarioIndex]
|
||||||
|
= std::make_shared<SimulationJob>(
|
||||||
SimulationJob(pMesh,
|
SimulationJob(pMesh,
|
||||||
"Axial_" + std::to_string(simulationScenarioIndex),
|
baseSimulationScenarioNames[BaseSimulationScenario::Axial] + "_"
|
||||||
|
+ std::to_string(axialSimulationScenarioIndex),
|
||||||
fixedVertices,
|
fixedVertices,
|
||||||
nodalForces,
|
nodalForces,
|
||||||
{}));
|
{}));
|
||||||
|
}
|
||||||
|
|
||||||
//// Shear
|
//// Shear
|
||||||
simulationScenarioIndex = BaseSimulationScenario::Shear;
|
const double maxForceMagnitude_shear = 50;
|
||||||
|
const double minForceMagnitude_shear = -50;
|
||||||
|
const int numberOfSimulationScenarios_shear
|
||||||
|
= simulationScenariosResolution[BaseSimulationScenario::Shear];
|
||||||
|
const double forceMagnitudeStep_shear = numberOfSimulationScenarios_shear == 1
|
||||||
|
? maxForceMagnitude_shear
|
||||||
|
: (maxForceMagnitude_shear - minForceMagnitude_shear)
|
||||||
|
/ (numberOfSimulationScenarios_shear - 1);
|
||||||
|
const int baseSimulationScenarioIndexOffset_shear
|
||||||
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
|
simulationScenariosResolution.begin() + BaseSimulationScenario::Shear,
|
||||||
|
0);
|
||||||
|
for (int shearSimulationScenarioIndex = 0;
|
||||||
|
shearSimulationScenarioIndex < numberOfSimulationScenarios_shear;
|
||||||
|
shearSimulationScenarioIndex++) {
|
||||||
fixedVertices.clear();
|
fixedVertices.clear();
|
||||||
nodalForces.clear();
|
nodalForces.clear();
|
||||||
// NewMethod
|
const double forceMagnitude = (forceMagnitudeStep_shear * shearSimulationScenarioIndex
|
||||||
|
+ minForceMagnitude_shear);
|
||||||
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
||||||
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
||||||
viPairIt++) {
|
viPairIt++) {
|
||||||
|
|
@ -844,54 +909,94 @@ ReducedModelOptimizer::createScenarios(
|
||||||
CoordType forceDirection(0, 1, 0);
|
CoordType forceDirection(0, 1, 0);
|
||||||
const auto viPair = *viPairIt;
|
const auto viPair = *viPairIt;
|
||||||
nodalForces[viPair.first]
|
nodalForces[viPair.first]
|
||||||
= Vector6d({forceDirection[0], forceDirection[1], forceDirection[2], 0, 0, 0}) * 40;
|
= Vector6d({forceDirection[0], forceDirection[1], forceDirection[2], 0, 0, 0})
|
||||||
fixedVertices[viPair.second] =
|
* forceMagnitude;
|
||||||
std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scenarios[simulationScenarioIndex] = std::make_shared<SimulationJob>(
|
scenarios[baseSimulationScenarioIndexOffset_shear + shearSimulationScenarioIndex]
|
||||||
|
= std::make_shared<SimulationJob>(
|
||||||
SimulationJob(pMesh,
|
SimulationJob(pMesh,
|
||||||
baseSimulationScenarioNames[simulationScenarioIndex],
|
baseSimulationScenarioNames[BaseSimulationScenario::Shear] + "_"
|
||||||
|
+ std::to_string(shearSimulationScenarioIndex),
|
||||||
fixedVertices,
|
fixedVertices,
|
||||||
nodalForces,
|
nodalForces,
|
||||||
{}));
|
{}));
|
||||||
|
}
|
||||||
|
|
||||||
//// Bending
|
//// Bending
|
||||||
simulationScenarioIndex = BaseSimulationScenario::Bending;
|
const double maxForceMagnitude_bending = 0.005;
|
||||||
|
const double minForceMagnitude_bending = -0.005;
|
||||||
|
const int numberOfSimulationScenarios_bending
|
||||||
|
= simulationScenariosResolution[BaseSimulationScenario::Bending];
|
||||||
|
const double forceMagnitudeStep_bending = numberOfSimulationScenarios_bending == 1
|
||||||
|
? maxForceMagnitude_bending
|
||||||
|
: (maxForceMagnitude_bending
|
||||||
|
- minForceMagnitude_bending)
|
||||||
|
/ (numberOfSimulationScenarios_bending - 1);
|
||||||
|
const int baseSimulationScenarioIndexOffset_bending
|
||||||
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
|
simulationScenariosResolution.begin() + BaseSimulationScenario::Bending,
|
||||||
|
0);
|
||||||
|
for (int bendingSimulationScenarioIndex = 0;
|
||||||
|
bendingSimulationScenarioIndex < numberOfSimulationScenarios_bending;
|
||||||
|
bendingSimulationScenarioIndex++) {
|
||||||
fixedVertices.clear();
|
fixedVertices.clear();
|
||||||
nodalForces.clear();
|
nodalForces.clear();
|
||||||
|
const double forceMagnitude = (forceMagnitudeStep_bending * bendingSimulationScenarioIndex
|
||||||
|
+ minForceMagnitude_bending);
|
||||||
for (const auto &viPair : m_fullPatternOppositeInterfaceViPairs) {
|
for (const auto &viPair : m_fullPatternOppositeInterfaceViPairs) {
|
||||||
nodalForces[viPair.first] = Vector6d({0, 0, 1, 0, 0, 0}) * 0.005;
|
nodalForces[viPair.first] = Vector6d({0, 0, 1, 0, 0, 0}) * forceMagnitude;
|
||||||
fixedVertices[viPair.second] =
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
||||||
std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
|
||||||
}
|
}
|
||||||
scenarios[simulationScenarioIndex] = std::make_shared<SimulationJob>(
|
scenarios[baseSimulationScenarioIndexOffset_bending + bendingSimulationScenarioIndex]
|
||||||
|
= std::make_shared<SimulationJob>(
|
||||||
SimulationJob(pMesh,
|
SimulationJob(pMesh,
|
||||||
baseSimulationScenarioNames[simulationScenarioIndex],
|
baseSimulationScenarioNames[BaseSimulationScenario::Bending] + "_"
|
||||||
|
+ std::to_string(bendingSimulationScenarioIndex),
|
||||||
fixedVertices,
|
fixedVertices,
|
||||||
nodalForces,
|
nodalForces,
|
||||||
{}));
|
{}));
|
||||||
|
}
|
||||||
|
|
||||||
//// Dome
|
//// Dome
|
||||||
simulationScenarioIndex = BaseSimulationScenario::Dome;
|
const double maxForceMagnitude_dome = 0.025;
|
||||||
|
const double minForceMagnitude_dome = -0.025;
|
||||||
|
const int numberOfSimulationScenarios_dome
|
||||||
|
= simulationScenariosResolution[BaseSimulationScenario::Dome];
|
||||||
|
const double forceMagnitudeStep_dome = numberOfSimulationScenarios_dome == 1
|
||||||
|
? maxForceMagnitude_dome
|
||||||
|
: (maxForceMagnitude_dome - minForceMagnitude_dome)
|
||||||
|
/ (numberOfSimulationScenarios_dome - 1);
|
||||||
|
const int baseSimulationScenarioIndexOffset_dome
|
||||||
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
|
simulationScenariosResolution.begin() + BaseSimulationScenario::Dome,
|
||||||
|
0);
|
||||||
|
for (int domeSimulationScenarioIndex = 0;
|
||||||
|
domeSimulationScenarioIndex < numberOfSimulationScenarios_dome;
|
||||||
|
domeSimulationScenarioIndex++) {
|
||||||
fixedVertices.clear();
|
fixedVertices.clear();
|
||||||
nodalForces.clear();
|
nodalForces.clear();
|
||||||
std::unordered_map<VertexIndex, Eigen::Vector3d> nodalForcedDisplacements;
|
std::unordered_map<VertexIndex, Eigen::Vector3d> nodalForcedDisplacements;
|
||||||
|
const double forceMagnitude = (forceMagnitudeStep_dome * domeSimulationScenarioIndex
|
||||||
|
+ minForceMagnitude_dome);
|
||||||
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
||||||
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
||||||
viPairIt++) {
|
viPairIt++) {
|
||||||
const auto viPair = *viPairIt;
|
const auto viPair = *viPairIt;
|
||||||
if (viPairIt == m_fullPatternOppositeInterfaceViPairs.begin()) {
|
CoordType interfaceVector = (pMesh->vert[viPair.first].cP()
|
||||||
CoordType interfaceV = (pMesh->vert[viPair.first].cP()
|
|
||||||
- pMesh->vert[viPair.second].cP());
|
- pMesh->vert[viPair.second].cP());
|
||||||
nodalForcedDisplacements[viPair.first] = Eigen::Vector3d(-interfaceV[0],
|
VectorType momentAxis = vcg::RotationMatrix(VectorType(0, 0, 1), vcg::math::ToRad(90.0))
|
||||||
-interfaceV[1],
|
* interfaceVector.Normalize();
|
||||||
|
if (viPairIt == m_fullPatternOppositeInterfaceViPairs.begin()) {
|
||||||
|
nodalForcedDisplacements[viPair.first] = Eigen::Vector3d(-interfaceVector[0],
|
||||||
|
-interfaceVector[1],
|
||||||
0)
|
0)
|
||||||
* 0.025;
|
* std::abs(forceMagnitude);
|
||||||
nodalForcedDisplacements[viPair.second] = Eigen::Vector3d(interfaceV[0],
|
nodalForcedDisplacements[viPair.second] = Eigen::Vector3d(interfaceVector[0],
|
||||||
interfaceV[1],
|
interfaceVector[1],
|
||||||
0)
|
0)
|
||||||
* 0.025;
|
* std::abs(forceMagnitude);
|
||||||
// CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
// CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
// ^ CoordType(0, 0, -1).Normalize();
|
// ^ CoordType(0, 0, -1).Normalize();
|
||||||
// nodalForces[viPair.first] = Vector6d({0, 0, 0, v[0], v[1], 0}) * forceMagnitude
|
// nodalForces[viPair.first] = Vector6d({0, 0, 0, v[0], v[1], 0}) * forceMagnitude
|
||||||
|
|
@ -899,49 +1004,75 @@ ReducedModelOptimizer::createScenarios(
|
||||||
// nodalForces[viPair.second] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * forceMagnitude
|
// nodalForces[viPair.second] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * forceMagnitude
|
||||||
// * 0.0001;
|
// * 0.0001;
|
||||||
} else {
|
} else {
|
||||||
|
nodalForces[viPair.first]
|
||||||
|
= Vector6d({0, 0, 0, momentAxis[0], momentAxis[1], momentAxis[2]})
|
||||||
|
* forceMagnitude / 5;
|
||||||
|
nodalForces[viPair.second]
|
||||||
|
= Vector6d({0, 0, 0, -momentAxis[0], -momentAxis[1], -momentAxis[2]})
|
||||||
|
* forceMagnitude / 5;
|
||||||
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
||||||
fixedVertices[viPair.second] = std::unordered_set<DoFType>{2};
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{2};
|
||||||
CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
|
||||||
^ CoordType(0, 0, -1).Normalize();
|
|
||||||
nodalForces[viPair.first] = Vector6d({0, 0, 0, v[0], v[1], 0}) * 0.005;
|
|
||||||
nodalForces[viPair.second] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 0.005;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scenarios[simulationScenarioIndex] = std::make_shared<SimulationJob>(
|
scenarios[baseSimulationScenarioIndexOffset_dome + domeSimulationScenarioIndex]
|
||||||
|
= std::make_shared<SimulationJob>(
|
||||||
SimulationJob(pMesh,
|
SimulationJob(pMesh,
|
||||||
baseSimulationScenarioNames[simulationScenarioIndex],
|
baseSimulationScenarioNames[BaseSimulationScenario::Dome] + "_"
|
||||||
|
+ std::to_string(domeSimulationScenarioIndex),
|
||||||
fixedVertices,
|
fixedVertices,
|
||||||
nodalForces,
|
nodalForces,
|
||||||
nodalForcedDisplacements));
|
nodalForcedDisplacements));
|
||||||
|
}
|
||||||
|
|
||||||
//// Saddle
|
//// Saddle
|
||||||
simulationScenarioIndex = BaseSimulationScenario::Saddle;
|
const double maxForceMagnitude_saddle = 0.005;
|
||||||
|
const double minForceMagnitude_saddle = -0.005;
|
||||||
|
const int numberOfSimulationScenarios_saddle
|
||||||
|
= simulationScenariosResolution[BaseSimulationScenario::Saddle];
|
||||||
|
const double forceMagnitudeStep_saddle = numberOfSimulationScenarios_saddle == 1
|
||||||
|
? maxForceMagnitude_saddle
|
||||||
|
: (maxForceMagnitude_saddle
|
||||||
|
- minForceMagnitude_saddle)
|
||||||
|
/ (numberOfSimulationScenarios_saddle - 1);
|
||||||
|
const int baseSimulationScenarioIndexOffset_saddle
|
||||||
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
|
simulationScenariosResolution.begin() + BaseSimulationScenario::Saddle,
|
||||||
|
0);
|
||||||
|
for (int saddleSimulationScenarioIndex = 0;
|
||||||
|
saddleSimulationScenarioIndex < numberOfSimulationScenarios_saddle;
|
||||||
|
saddleSimulationScenarioIndex++) {
|
||||||
fixedVertices.clear();
|
fixedVertices.clear();
|
||||||
nodalForces.clear();
|
nodalForces.clear();
|
||||||
|
const double forceMagnitude = (forceMagnitudeStep_saddle * saddleSimulationScenarioIndex
|
||||||
|
+ minForceMagnitude_saddle);
|
||||||
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
for (auto viPairIt = m_fullPatternOppositeInterfaceViPairs.begin();
|
||||||
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
viPairIt != m_fullPatternOppositeInterfaceViPairs.end();
|
||||||
viPairIt++) {
|
viPairIt++) {
|
||||||
const auto &viPair = *viPairIt;
|
const auto &viPair = *viPairIt;
|
||||||
CoordType v =
|
CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
(pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP()) ^
|
^ CoordType(0, 0, -1).Normalize();
|
||||||
CoordType(0, 0, -1).Normalize();
|
|
||||||
if (viPairIt == m_fullPatternOppositeInterfaceViPairs.begin()) {
|
if (viPairIt == m_fullPatternOppositeInterfaceViPairs.begin()) {
|
||||||
nodalForces[viPair.first] = Vector6d({0, 0, 0, v[0], v[1], 0}) * 0.002;
|
nodalForces[viPair.first] = Vector6d({0, 0, 0, v[0], v[1], 0}) * forceMagnitude;
|
||||||
nodalForces[viPair.second] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 0.002;
|
nodalForces[viPair.second] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * forceMagnitude;
|
||||||
} else {
|
} else {
|
||||||
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
||||||
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
|
|
||||||
nodalForces[viPair.first] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 0.001;
|
nodalForces[viPair.first] = Vector6d({0, 0, 0, -v[0], -v[1], 0}) * forceMagnitude
|
||||||
nodalForces[viPair.second] = Vector6d({0, 0, 0, v[0], v[1], 0}) * 0.001;
|
/ 2;
|
||||||
|
nodalForces[viPair.second] = Vector6d({0, 0, 0, v[0], v[1], 0}) * forceMagnitude
|
||||||
|
/ 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scenarios[simulationScenarioIndex] = std::make_shared<SimulationJob>(
|
scenarios[baseSimulationScenarioIndexOffset_saddle + saddleSimulationScenarioIndex]
|
||||||
|
= std::make_shared<SimulationJob>(
|
||||||
SimulationJob(pMesh,
|
SimulationJob(pMesh,
|
||||||
baseSimulationScenarioNames[simulationScenarioIndex],
|
baseSimulationScenarioNames[BaseSimulationScenario::Saddle] + "_"
|
||||||
|
+ std::to_string(saddleSimulationScenarioIndex),
|
||||||
fixedVertices,
|
fixedVertices,
|
||||||
nodalForces,
|
nodalForces,
|
||||||
{}));
|
{}));
|
||||||
|
}
|
||||||
|
|
||||||
return scenarios;
|
return scenarios;
|
||||||
}
|
}
|
||||||
|
|
@ -1050,13 +1181,14 @@ Results ReducedModelOptimizer::optimize(
|
||||||
global.numOfSimulationCrashes = 0;
|
global.numOfSimulationCrashes = 0;
|
||||||
global.numberOfFunctionCalls = 0;
|
global.numberOfFunctionCalls = 0;
|
||||||
global.optimizationSettings = optimizationSettings;
|
global.optimizationSettings = optimizationSettings;
|
||||||
global.fullPatternSimulationJobs = createScenarios(m_pFullPatternSimulationMesh);
|
global.fullPatternSimulationJobs = createFullPatternSimulationScenarios(
|
||||||
|
m_pFullPatternSimulationMesh);
|
||||||
// polyscope::removeAllStructures();
|
// polyscope::removeAllStructures();
|
||||||
|
|
||||||
DRMSimulationModel::Settings simulationSettings;
|
DRMSimulationModel::Settings simulationSettings;
|
||||||
simulationSettings.shouldDraw = false;
|
simulationSettings.shouldDraw = false;
|
||||||
// global.fullPatternSimulationJobs[0]->pMesh->registerForDrawing(
|
// global.fullPatternSimulationJobs[0]->pMesh->registerForDrawing(
|
||||||
// ReducedModelOptimization::Colors::fullInitial);
|
// ReducedPatternOptimization::Colors::fullInitial);
|
||||||
// LinearSimulationModel linearSimulator;
|
// LinearSimulationModel linearSimulator;
|
||||||
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||||
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob
|
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob
|
||||||
|
|
@ -1065,7 +1197,7 @@ Results ReducedModelOptimizer::optimize(
|
||||||
simulationSettings);
|
simulationSettings);
|
||||||
// SimulationResults fullPatternResults_linear = linearSimulator.executeSimulation(
|
// SimulationResults fullPatternResults_linear = linearSimulator.executeSimulation(
|
||||||
// pFullPatternSimulationJob);
|
// pFullPatternSimulationJob);
|
||||||
// fullPatternResults.registerForDrawing(ReducedModelOptimization::Colors::fullDeformed,
|
// fullPatternResults.registerForDrawing(ReducedPatternOptimization::Colors::fullDeformed,
|
||||||
// true,
|
// true,
|
||||||
// true);
|
// true);
|
||||||
// fullPatternResults_linear.labelPrefix += "_linear";
|
// fullPatternResults_linear.labelPrefix += "_linear";
|
||||||
|
|
@ -1083,6 +1215,7 @@ Results ReducedModelOptimizer::optimize(
|
||||||
reducedPatternSimulationJob);
|
reducedPatternSimulationJob);
|
||||||
global.reducedPatternSimulationJobs[simulationScenarioIndex]
|
global.reducedPatternSimulationJobs[simulationScenarioIndex]
|
||||||
= std::make_shared<SimulationJob>(reducedPatternSimulationJob);
|
= std::make_shared<SimulationJob>(reducedPatternSimulationJob);
|
||||||
|
// std::cout << "Ran sim scenario:" << simulationScenarioIndex << std::endl;
|
||||||
}
|
}
|
||||||
// global.fullPatternSimulationJobs[0]->pMesh->unregister();
|
// global.fullPatternSimulationJobs[0]->pMesh->unregister();
|
||||||
|
|
||||||
|
|
@ -1091,12 +1224,6 @@ Results ReducedModelOptimizer::optimize(
|
||||||
computeObjectiveValueNormalizationFactors();
|
computeObjectiveValueNormalizationFactors();
|
||||||
// }
|
// }
|
||||||
Results optResults = runOptimization(optimizationSettings);
|
Results optResults = runOptimization(optimizationSettings);
|
||||||
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
|
||||||
optResults.fullPatternSimulationJobs.push_back(
|
|
||||||
global.fullPatternSimulationJobs[simulationScenarioIndex]);
|
|
||||||
optResults.reducedPatternSimulationJobs.push_back(
|
|
||||||
global.reducedPatternSimulationJobs[simulationScenarioIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return optResults;
|
return optResults;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
#include "reducedmodeloptimizer_structs.hpp"
|
#include "reducedmodeloptimizer_structs.hpp"
|
||||||
#include "simulationmesh.hpp"
|
#include "simulationmesh.hpp"
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
|
#include <dlib/global_optimization.h>
|
||||||
|
#include <dlib/optimization.h>
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
#include "polyscope/color_management.h"
|
#include "polyscope/color_management.h"
|
||||||
|
|
@ -28,17 +30,17 @@ class ReducedModelOptimizer
|
||||||
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static std::array<int, 5> simulationScenariosResolution = {1, 1, 1, 1, 1};
|
constexpr static std::array<int, 5> simulationScenariosResolution = {2, 2, 6, 6, 6};
|
||||||
inline static int totalNumberOfSimulationScenarios
|
inline static int totalNumberOfSimulationScenarios
|
||||||
= std::accumulate(simulationScenariosResolution.begin(),
|
= std::accumulate(simulationScenariosResolution.begin(),
|
||||||
simulationScenariosResolution.end(),
|
simulationScenariosResolution.end(),
|
||||||
0);
|
0);
|
||||||
inline static int fanSize{6};
|
inline static int fanSize{6};
|
||||||
inline static VectorType patternPlaneNormal{0, 0, 1};
|
inline static VectorType patternPlaneNormal{0, 0, 1};
|
||||||
ReducedModelOptimization::Results optimize(
|
ReducedPatternOptimization::Results optimize(
|
||||||
const ReducedModelOptimization::Settings &xRanges,
|
const ReducedPatternOptimization::Settings &xRanges,
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario> &simulationScenarios
|
||||||
= std::vector<ReducedModelOptimization::BaseSimulationScenario>());
|
= std::vector<ReducedPatternOptimization::BaseSimulationScenario>());
|
||||||
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
||||||
|
|
||||||
ReducedModelOptimizer(const std::vector<size_t> &numberOfNodesPerSlot);
|
ReducedModelOptimizer(const std::vector<size_t> &numberOfNodesPerSlot);
|
||||||
|
|
@ -64,7 +66,7 @@ public:
|
||||||
double innerHexagonRotationAngle);
|
double innerHexagonRotationAngle);
|
||||||
static double objective(double b, double r, double E);
|
static double objective(double b, double r, double E);
|
||||||
|
|
||||||
static std::vector<std::shared_ptr<SimulationJob>> createScenarios(
|
static std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationScenarios(
|
||||||
const std::shared_ptr<SimulationMesh> &pMesh,
|
const std::shared_ptr<SimulationMesh> &pMesh,
|
||||||
const std::unordered_map<size_t, size_t> &fullPatternOppositeInterfaceViMap);
|
const std::unordered_map<size_t, size_t> &fullPatternOppositeInterfaceViMap);
|
||||||
|
|
||||||
|
|
@ -85,7 +87,7 @@ public:
|
||||||
static void visualizeResults(
|
static void visualizeResults(
|
||||||
const std::vector<std::shared_ptr<SimulationJob>> &fullPatternSimulationJobs,
|
const std::vector<std::shared_ptr<SimulationJob>> &fullPatternSimulationJobs,
|
||||||
const std::vector<std::shared_ptr<SimulationJob>> &reducedPatternSimulationJobs,
|
const std::vector<std::shared_ptr<SimulationJob>> &reducedPatternSimulationJobs,
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios,
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario> &simulationScenarios,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||||
&reducedToFullInterfaceViMap);
|
&reducedToFullInterfaceViMap);
|
||||||
static void registerResultsForDrawing(
|
static void registerResultsForDrawing(
|
||||||
|
|
@ -94,7 +96,7 @@ public:
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||||
&reducedToFullInterfaceViMap);
|
&reducedToFullInterfaceViMap);
|
||||||
|
|
||||||
static double computeRawDisplacementError(
|
static double computeRawTranslationalError(
|
||||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
const std::vector<Vector6d> &fullPatternDisplacements,
|
||||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
const std::vector<Vector6d> &reducedPatternDisplacements,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||||
|
|
@ -136,9 +138,9 @@ private:
|
||||||
const SimulationResults &fullModelResults,
|
const SimulationResults &fullModelResults,
|
||||||
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
||||||
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
||||||
static ReducedModelOptimization::Results runOptimization(
|
static ReducedPatternOptimization::Results runOptimization(
|
||||||
const ReducedModelOptimization::Settings &settings);
|
const ReducedPatternOptimization::Settings &settings);
|
||||||
std::vector<std::shared_ptr<SimulationJob>> createScenarios(
|
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationScenarios(
|
||||||
const std::shared_ptr<SimulationMesh> &pMesh);
|
const std::shared_ptr<SimulationMesh> &pMesh);
|
||||||
void computeMaps(PatternGeometry &fullModel, PatternGeometry &reducedPattern);
|
void computeMaps(PatternGeometry &fullModel, PatternGeometry &reducedPattern);
|
||||||
void createSimulationMeshes(PatternGeometry &fullModel, PatternGeometry &reducedModel);
|
void createSimulationMeshes(PatternGeometry &fullModel, PatternGeometry &reducedModel);
|
||||||
|
|
@ -148,6 +150,9 @@ private:
|
||||||
static double objective(long n, const double *x);
|
static double objective(long n, const double *x);
|
||||||
DRMSimulationModel simulator;
|
DRMSimulationModel simulator;
|
||||||
void computeObjectiveValueNormalizationFactors();
|
void computeObjectiveValueNormalizationFactors();
|
||||||
|
static ReducedPatternOptimization::Results getResults(
|
||||||
|
const dlib::function_evaluation &optimizationResult_dlib,
|
||||||
|
const ReducedPatternOptimization::Settings &settings);
|
||||||
};
|
};
|
||||||
void updateMesh(long n, const double *x);
|
void updateMesh(long n, const double *x);
|
||||||
#endif // REDUCEDMODELOPTIMIZER_HPP
|
#endif // REDUCEDMODELOPTIMIZER_HPP
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue