2020-11-23 10:06:45 +01:00
|
|
|
#ifndef REDUCEDMODELOPTIMIZER_HPP
|
|
|
|
#define REDUCEDMODELOPTIMIZER_HPP
|
|
|
|
|
|
|
|
#include "beamformfinder.hpp"
|
|
|
|
#include "edgemesh.hpp"
|
|
|
|
#include "elementalmesh.hpp"
|
2020-12-09 16:58:48 +01:00
|
|
|
#include "matplot/matplot.h"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
2020-12-14 10:07:43 +01:00
|
|
|
using FullPatternVertexIndex = VertexIndex;
|
|
|
|
using ReducedPatternVertexIndex = VertexIndex;
|
2020-11-23 10:06:45 +01:00
|
|
|
|
|
|
|
class ReducedModelOptimizer {
|
2020-12-16 20:31:58 +01:00
|
|
|
std::shared_ptr<SimulationMesh> m_pReducedPatternSimulationMesh;
|
2021-01-04 13:12:25 +01:00
|
|
|
std::shared_ptr<SimulationMesh> m_pFullPatternSimulationMesh;
|
2020-12-14 10:07:43 +01:00
|
|
|
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
2020-11-27 11:45:20 +01:00
|
|
|
m_fullToReducedInterfaceViMap;
|
2020-12-14 10:07:43 +01:00
|
|
|
std::unordered_map<FullPatternVertexIndex, FullPatternVertexIndex>
|
2020-11-27 11:45:20 +01:00
|
|
|
m_fullPatternOppositeInterfaceViMap;
|
|
|
|
std::unordered_map<size_t, size_t> nodeToSlot;
|
|
|
|
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
2020-12-16 20:31:58 +01:00
|
|
|
std::vector<double> initialGuess;
|
2020-11-23 10:06:45 +01:00
|
|
|
|
|
|
|
public:
|
2020-12-21 16:56:21 +01:00
|
|
|
enum SimulationScenario {
|
|
|
|
Axial,
|
|
|
|
Shear,
|
|
|
|
Bending,
|
2021-01-04 13:12:25 +01:00
|
|
|
Dome,
|
2020-12-21 16:56:21 +01:00
|
|
|
Saddle,
|
|
|
|
NumberOfSimulationScenarios
|
|
|
|
};
|
2021-01-22 15:39:36 +01:00
|
|
|
struct Results {
|
|
|
|
int numberOfSimulationCrashes{0};
|
|
|
|
std::vector<double> x;
|
|
|
|
double objectiveValue;
|
|
|
|
};
|
|
|
|
struct xRange {
|
|
|
|
std::string label;
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
std::string toString() const {
|
|
|
|
return label + "=[" + std::to_string(min) + "," + std::to_string(max) +
|
|
|
|
"]";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Settings {
|
|
|
|
std::vector<xRange> xRanges;
|
2021-01-29 18:07:13 +01:00
|
|
|
int maxSimulations{100};
|
|
|
|
double solutionAccuracy{1e-5};
|
2021-01-22 15:39:36 +01:00
|
|
|
};
|
|
|
|
|
2021-01-04 13:12:25 +01:00
|
|
|
inline static const std::string simulationScenarioStrings[] = {
|
2020-12-21 16:56:21 +01:00
|
|
|
"Axial", "Shear", "Bending", "Double", "Saddle"};
|
2021-01-22 15:39:36 +01:00
|
|
|
Results optimize(const Settings &xRanges,
|
|
|
|
const std::vector<SimulationScenario> &simulationScenarios =
|
|
|
|
std::vector<SimulationScenario>());
|
2020-11-23 10:06:45 +01:00
|
|
|
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
|
|
|
|
2020-11-27 11:45:20 +01:00
|
|
|
ReducedModelOptimizer(const std::vector<size_t> &numberOfNodesPerSlot);
|
2021-01-04 13:12:25 +01:00
|
|
|
static void computeReducedModelSimulationJob(
|
2020-11-23 10:06:45 +01:00
|
|
|
const SimulationJob &simulationJobOfFullModel,
|
2021-01-04 13:12:25 +01:00
|
|
|
const std::unordered_map<size_t, size_t> &simulationJobFullToReducedMap,
|
2020-11-23 10:06:45 +01:00
|
|
|
SimulationJob &simulationJobOfReducedModel);
|
|
|
|
|
|
|
|
SimulationJob
|
|
|
|
getReducedSimulationJob(const SimulationJob &fullModelSimulationJob);
|
|
|
|
|
2020-12-21 16:56:21 +01:00
|
|
|
void initializePatterns(
|
|
|
|
FlatPattern &fullPattern, FlatPattern &reducedPatterm,
|
|
|
|
const std::unordered_set<size_t> &reducedModelExcludedEges);
|
2020-11-27 11:45:20 +01:00
|
|
|
|
2020-12-16 20:31:58 +01:00
|
|
|
void setInitialGuess(std::vector<double> v);
|
|
|
|
|
2021-01-04 13:12:25 +01:00
|
|
|
static void runBeamOptimization();
|
|
|
|
|
|
|
|
static void runSimulation(const std::string &filename,
|
|
|
|
std::vector<double> &x);
|
|
|
|
|
2021-01-12 13:41:40 +01:00
|
|
|
static double objective(double x0, double x1, double x2, double x3);
|
2021-01-22 15:39:36 +01:00
|
|
|
static double objective(double b, double h, double E);
|
2021-01-12 13:41:40 +01:00
|
|
|
|
2020-11-23 10:06:45 +01:00
|
|
|
private:
|
2021-01-04 13:12:25 +01:00
|
|
|
void
|
|
|
|
visualizeResults(const std::vector<std::shared_ptr<SimulationJob>>
|
|
|
|
&fullPatternSimulationJobs,
|
|
|
|
const std::vector<SimulationScenario> &simulationScenarios);
|
|
|
|
static void computeDesiredReducedModelDisplacements(
|
2020-11-23 10:06:45 +01:00
|
|
|
const SimulationResults &fullModelResults,
|
2021-01-04 13:12:25 +01:00
|
|
|
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
2020-11-27 11:45:20 +01:00
|
|
|
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
2021-01-22 15:39:36 +01:00
|
|
|
static Results runOptimization(const Settings &settings,
|
|
|
|
double (*pObjectiveFunction)(long,
|
|
|
|
const double *));
|
2021-01-04 13:12:25 +01:00
|
|
|
std::vector<std::shared_ptr<SimulationJob>>
|
2020-11-27 11:45:20 +01:00
|
|
|
createScenarios(const std::shared_ptr<SimulationMesh> &pMesh);
|
|
|
|
void computeMaps(FlatPattern &fullModel, FlatPattern &reducedPattern,
|
|
|
|
const std::unordered_set<size_t> &reducedModelExcludedEges);
|
|
|
|
void createSimulationMeshes(FlatPattern &fullModel,
|
|
|
|
FlatPattern &reducedModel);
|
2021-01-04 13:12:25 +01:00
|
|
|
static void
|
2021-01-17 12:46:33 +01:00
|
|
|
initializeOptimizationParameters(const std::shared_ptr<SimulationMesh> &mesh);
|
2020-12-09 16:58:48 +01:00
|
|
|
|
2020-12-21 16:56:21 +01:00
|
|
|
static double
|
|
|
|
computeError(const SimulationResults &reducedPatternResults,
|
|
|
|
const Eigen::MatrixX3d &optimalReducedPatternDisplacements);
|
2021-01-04 13:12:25 +01:00
|
|
|
static double objective(long n, const double *x);
|
2020-11-23 10:06:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // REDUCEDMODELOPTIMIZER_HPP
|