2020-11-23 10:06:45 +01:00
|
|
|
#ifndef REDUCEDMODELOPTIMIZER_HPP
|
|
|
|
#define REDUCEDMODELOPTIMIZER_HPP
|
|
|
|
|
2021-02-10 12:19:37 +01:00
|
|
|
#include "csvfile.hpp"
|
2021-03-26 10:58:13 +01:00
|
|
|
#include "drmsimulationmodel.hpp"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include "edgemesh.hpp"
|
2021-03-15 18:56:14 +01:00
|
|
|
#include "linearsimulationmodel.hpp"
|
2020-12-09 16:58:48 +01:00
|
|
|
#include "matplot/matplot.h"
|
2021-03-23 18:20:46 +01:00
|
|
|
#include "reducedmodeloptimizer_structs.hpp"
|
2021-03-26 10:58:13 +01:00
|
|
|
#include "simulationmesh.hpp"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include <Eigen/Dense>
|
2021-04-08 19:55:56 +02:00
|
|
|
#include <dlib/global_optimization.h>
|
|
|
|
#include <dlib/optimization.h>
|
2020-11-23 10:06:45 +01:00
|
|
|
|
2021-03-01 13:34:27 +01:00
|
|
|
#ifdef POLYSCOPE_DEFINED
|
|
|
|
#include "polyscope/color_management.h"
|
|
|
|
#endif // POLYSCOPE_DEFINED
|
2020-12-14 10:07:43 +01:00
|
|
|
using FullPatternVertexIndex = VertexIndex;
|
|
|
|
using ReducedPatternVertexIndex = VertexIndex;
|
2020-11-23 10:06:45 +01:00
|
|
|
|
2021-03-26 10:58:13 +01:00
|
|
|
class ReducedModelOptimizer
|
|
|
|
{
|
|
|
|
std::shared_ptr<SimulationMesh> m_pReducedPatternSimulationMesh;
|
|
|
|
std::shared_ptr<SimulationMesh> m_pFullPatternSimulationMesh;
|
|
|
|
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
|
|
|
m_fullToReducedInterfaceViMap;
|
2021-04-05 11:41:05 +02:00
|
|
|
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
m_fullPatternOppositeInterfaceViPairs;
|
2021-03-26 10:58:13 +01:00
|
|
|
std::unordered_map<size_t, size_t> nodeToSlot;
|
|
|
|
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
2021-06-30 09:24:54 +02:00
|
|
|
std::string optimizationNotes;
|
2021-07-14 16:47:47 +02:00
|
|
|
std::vector<std::function<
|
|
|
|
void(const double &,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>> &,
|
|
|
|
SimulationJob &)>>
|
|
|
|
constructBaseScenarioFunctions;
|
|
|
|
std::vector<bool> scenarioIsSymmetrical;
|
2021-07-20 15:30:41 +02:00
|
|
|
int fullPatternNumberOfEdges;
|
2020-11-23 10:06:45 +01:00
|
|
|
|
|
|
|
public:
|
2021-10-14 13:58:34 +02:00
|
|
|
constexpr static std::array<int, 5> simulationScenariosResolution = {11, 11, 20, 20, 20};
|
|
|
|
// constexpr static std::array<int, 5> simulationScenariosResolution = {3, 3, 3, 3, 3};
|
2021-04-05 11:41:05 +02:00
|
|
|
inline static int totalNumberOfSimulationScenarios
|
|
|
|
= std::accumulate(simulationScenariosResolution.begin(),
|
|
|
|
simulationScenariosResolution.end(),
|
|
|
|
0);
|
|
|
|
inline static int fanSize{6};
|
2021-04-16 10:41:40 +02:00
|
|
|
inline static double initialHexagonSize{0.3};
|
2021-04-05 11:41:05 +02:00
|
|
|
inline static VectorType patternPlaneNormal{0, 0, 1};
|
2021-04-30 11:47:50 +02:00
|
|
|
void optimize(
|
2021-04-08 19:55:56 +02:00
|
|
|
const ReducedPatternOptimization::Settings &xRanges,
|
2021-04-30 11:47:50 +02:00
|
|
|
ReducedPatternOptimization::Results &results,
|
2021-04-08 19:55:56 +02:00
|
|
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario> &simulationScenarios
|
2021-07-14 16:47:47 +02:00
|
|
|
= std::vector<ReducedPatternOptimization::BaseSimulationScenario>(
|
|
|
|
{ReducedPatternOptimization::Axial,
|
|
|
|
ReducedPatternOptimization::Shear,
|
|
|
|
ReducedPatternOptimization::Bending,
|
|
|
|
ReducedPatternOptimization::Dome,
|
|
|
|
ReducedPatternOptimization::Saddle}));
|
2021-04-05 11:41:05 +02:00
|
|
|
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
|
|
|
|
|
|
|
ReducedModelOptimizer(const std::vector<size_t> &numberOfNodesPerSlot);
|
|
|
|
static void computeReducedModelSimulationJob(
|
|
|
|
const SimulationJob &simulationJobOfFullModel,
|
|
|
|
const std::unordered_map<size_t, size_t> &fullToReducedMap,
|
|
|
|
SimulationJob &simulationJobOfReducedModel);
|
|
|
|
|
|
|
|
SimulationJob getReducedSimulationJob(const SimulationJob &fullModelSimulationJob);
|
|
|
|
|
|
|
|
void initializePatterns(PatternGeometry &fullPattern,
|
|
|
|
PatternGeometry &reducedPatterm,
|
|
|
|
const int &optimizationParameters);
|
|
|
|
|
|
|
|
static void runSimulation(const std::string &filename, std::vector<double> &x);
|
|
|
|
|
|
|
|
static double objective(double x2,
|
|
|
|
double A,
|
|
|
|
double J,
|
|
|
|
double I2,
|
|
|
|
double I3,
|
|
|
|
double x3,
|
|
|
|
double innerHexagonRotationAngle);
|
|
|
|
static double objective(double b, double r, double E);
|
|
|
|
|
2021-07-14 16:47:47 +02:00
|
|
|
static std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
2021-04-05 11:41:05 +02:00
|
|
|
const std::shared_ptr<SimulationMesh> &pMesh,
|
|
|
|
const std::unordered_map<size_t, size_t> &fullPatternOppositeInterfaceViMap);
|
|
|
|
|
|
|
|
static void createSimulationMeshes(
|
|
|
|
PatternGeometry &fullModel,
|
|
|
|
PatternGeometry &reducedModel,
|
|
|
|
std::shared_ptr<SimulationMesh> &pFullPatternSimulationMesh,
|
|
|
|
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh);
|
|
|
|
static void computeMaps(const std::unordered_map<size_t, std::unordered_set<size_t>> &slotToNode,
|
|
|
|
PatternGeometry &fullPattern,
|
|
|
|
PatternGeometry &reducedPattern,
|
|
|
|
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap,
|
|
|
|
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
|
|
|
&fullToReducedInterfaceViMap,
|
|
|
|
std::vector<std::pair<FullPatternVertexIndex, ReducedPatternVertexIndex>>
|
|
|
|
&fullPatternOppositeInterfaceViMap);
|
|
|
|
static void visualizeResults(
|
|
|
|
const std::vector<std::shared_ptr<SimulationJob>> &fullPatternSimulationJobs,
|
|
|
|
const std::vector<std::shared_ptr<SimulationJob>> &reducedPatternSimulationJobs,
|
2021-04-08 19:55:56 +02:00
|
|
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario> &simulationScenarios,
|
2021-04-05 11:41:05 +02:00
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap);
|
|
|
|
static void registerResultsForDrawing(
|
|
|
|
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob,
|
|
|
|
const std::shared_ptr<SimulationJob> &pReducedPatternSimulationJob,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap);
|
|
|
|
|
2021-04-08 19:55:56 +02:00
|
|
|
static double computeRawTranslationalError(
|
2021-04-05 11:41:05 +02:00
|
|
|
const std::vector<Vector6d> &fullPatternDisplacements,
|
|
|
|
const std::vector<Vector6d> &reducedPatternDisplacements,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap);
|
|
|
|
|
|
|
|
static double computeDisplacementError(
|
|
|
|
const std::vector<Vector6d> &fullPatternDisplacements,
|
|
|
|
const std::vector<Vector6d> &reducedPatternDisplacements,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap,
|
|
|
|
const double &normalizationFactor);
|
|
|
|
|
|
|
|
static double objective(double E,
|
|
|
|
double A,
|
|
|
|
double innerHexagonSize,
|
|
|
|
double innerHexagonRotationAngle);
|
|
|
|
static double computeRawRotationalError(
|
|
|
|
const std::vector<Eigen::Quaternion<double>> &rotatedQuaternion_fullPattern,
|
|
|
|
const std::vector<Eigen::Quaternion<double>> &rotatedQuaternion_reducedPattern,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap);
|
|
|
|
|
|
|
|
static double computeRotationalError(
|
|
|
|
const std::vector<Eigen::Quaternion<double>> &rotatedQuaternion_fullPattern,
|
|
|
|
const std::vector<Eigen::Quaternion<double>> &rotatedQuaternion_reducedPattern,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap,
|
|
|
|
const double &normalizationFactor);
|
|
|
|
static double computeError(
|
|
|
|
const SimulationResults &simulationResults_fullPattern,
|
|
|
|
const SimulationResults &simulationResults_reducedPattern,
|
|
|
|
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
|
|
|
&reducedToFullInterfaceViMap,
|
|
|
|
const double &normalizationFactor_translationalDisplacement,
|
|
|
|
const double &normalizationFactor_rotationalDisplacement);
|
2021-04-16 10:41:40 +02:00
|
|
|
static void constructAxialSimulationScenario(
|
|
|
|
const double &forceMagnitude,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
&oppositeInterfaceViPairs,
|
|
|
|
SimulationJob &job);
|
|
|
|
|
|
|
|
static void constructShearSimulationScenario(
|
|
|
|
const double &forceMagnitude,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
&oppositeInterfaceViPairs,
|
|
|
|
SimulationJob &job);
|
|
|
|
|
|
|
|
static void constructBendingSimulationScenario(
|
|
|
|
const double &forceMagnitude,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
&oppositeInterfaceViPairs,
|
|
|
|
SimulationJob &job);
|
|
|
|
|
|
|
|
static void constructDomeSimulationScenario(
|
|
|
|
const double &forceMagnitude,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
&oppositeInterfaceViPairs,
|
|
|
|
SimulationJob &job);
|
|
|
|
|
|
|
|
static void constructSaddleSimulationScenario(
|
|
|
|
const double &forceMagnitude,
|
|
|
|
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
|
|
|
&oppositeInterfaceViPairs,
|
|
|
|
SimulationJob &job);
|
2021-04-05 11:41:05 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void computeDesiredReducedModelDisplacements(
|
|
|
|
const SimulationResults &fullModelResults,
|
|
|
|
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
|
|
|
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
2021-04-30 11:47:50 +02:00
|
|
|
static void runOptimization(const ReducedPatternOptimization::Settings &settings,
|
|
|
|
ReducedPatternOptimization::Results &results);
|
2021-07-14 16:47:47 +02:00
|
|
|
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
|
|
|
const std::shared_ptr<SimulationMesh> &pMesh,
|
|
|
|
const std::vector<std::pair<ReducedPatternOptimization::BaseSimulationScenario, double>>
|
|
|
|
&maxForceMagnitudes);
|
2021-04-05 11:41:05 +02:00
|
|
|
void computeMaps(PatternGeometry &fullModel, PatternGeometry &reducedPattern);
|
|
|
|
void createSimulationMeshes(PatternGeometry &fullModel, PatternGeometry &reducedModel);
|
|
|
|
static void initializeOptimizationParameters(const std::shared_ptr<SimulationMesh> &mesh,
|
|
|
|
const int &optimizationParamters);
|
|
|
|
|
|
|
|
static double objective(long n, const double *x);
|
|
|
|
DRMSimulationModel simulator;
|
|
|
|
void computeObjectiveValueNormalizationFactors();
|
2021-04-30 11:47:50 +02:00
|
|
|
static void getResults(const dlib::function_evaluation &optimizationResult_dlib,
|
|
|
|
const ReducedPatternOptimization::Settings &settings,
|
|
|
|
ReducedPatternOptimization::Results &results);
|
2021-07-14 16:47:47 +02:00
|
|
|
double computeFullPatternMaxSimulationForce(
|
|
|
|
const ReducedPatternOptimization::BaseSimulationScenario &scenario);
|
|
|
|
std::vector<std::pair<ReducedPatternOptimization::BaseSimulationScenario, double>>
|
|
|
|
computeFullPatternMaxSimulationForces(
|
|
|
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario>
|
|
|
|
&desiredBaseSimulationScenarioIndices);
|
|
|
|
|
|
|
|
std::vector<std::pair<ReducedPatternOptimization::BaseSimulationScenario, double>>
|
|
|
|
getFullPatternMaxSimulationForces(
|
|
|
|
const std::vector<ReducedPatternOptimization::BaseSimulationScenario>
|
|
|
|
&desiredBaseSimulationScenarioIndices);
|
2020-11-23 10:06:45 +01:00
|
|
|
};
|
2021-03-23 18:20:46 +01:00
|
|
|
void updateMesh(long n, const double *x);
|
2020-11-23 10:06:45 +01:00
|
|
|
#endif // REDUCEDMODELOPTIMIZER_HPP
|