206 lines
12 KiB
C++
206 lines
12 KiB
C++
#ifndef REDUCEDPATTERNSIMULATOR_HPP
|
|
#define REDUCEDPATTERNSIMULATOR_HPP
|
|
|
|
#include "reducedmodeloptimizer_structs.hpp"
|
|
#include "simulationmesh.hpp"
|
|
#include "trianglepatterngeometry.hpp"
|
|
#include "utilities.hpp"
|
|
|
|
using DRMFullSimulationResults = SimulationResults;
|
|
using LinearFullSimulationResults = SimulationResults;
|
|
using ReducedSimulationResults = SimulationResults;
|
|
using FullPatternVertexIndex = int;
|
|
using ReducedPatternVertexIndex = int;
|
|
using OptimizationResultsIndex = int;
|
|
class ReducedPatternSimulator
|
|
{
|
|
std::vector<ReducedPatternOptimization::Results> &mOptimizationResults;
|
|
std::shared_ptr<SimulationMesh> pTiledFullPattern_simulationMesh;
|
|
std::shared_ptr<SimulationMesh> pTiledReducedPattern_simulationMesh;
|
|
std::shared_ptr<SimulationJob> pJob_tiledReducedPattern;
|
|
std::shared_ptr<SimulationJob> pJob_tiledFullPattern;
|
|
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
|
const Vector6d externalForce{0, 0, 0.1, 0, 0, 0};
|
|
double minInputForceMagnitude = std::numeric_limits<double>::max();
|
|
std::string gui_jobLabel;
|
|
std::string gui_tessellationLabel;
|
|
bool gui_shouldRerunFullPatternSimulation{false};
|
|
float gui_scaleFactor{1};
|
|
std::vector<glm::vec3> gui_fullVerticesColors;
|
|
std::vector<glm::vec3> gui_reducedVerticesColors;
|
|
std::array<float, 3> gui_externalForce{0, 0, 0};
|
|
std::array<float, 3> gui_externalMoment{0, 0, 0};
|
|
std::array<float, 4> gui_randomnessParams{0.02, 0.02, 0.1, 0.3};
|
|
std::vector<int> gui_faceToPatternIndex;
|
|
std::vector<int> gui_fullPatternSelectedVertices;
|
|
std::pair<glm::vec3, size_t> gui_currentColorPatternIndexPair{glm::vec3(1, 0, 0), 0};
|
|
std::vector<glm::vec3> gui_colorsPerFace;
|
|
std::unordered_map<VertexIndex, VertexIndex> fullToReducedViMap; //of only the common vertices
|
|
std::unordered_map<VertexIndex, VertexIndex> reducedToFullViMap; //of only the common vertices
|
|
std::vector<size_t> tilledFullPatternInterfaceVi;
|
|
double surfaceBaseTriangleHeight{-1};
|
|
std::array<double, 3> color_tesselatedFullPatterns{0.89, 0.61, 0.11};
|
|
std::array<double, 3> color_tesselatedReducedPatterns{0.11, 0.89, 0.22};
|
|
std::string fullPatternsSurfacelabel{"Empty label"};
|
|
std::string fullPatternsLabel{"Empty label"};
|
|
std::string surfaceLabel{"Empty label"};
|
|
std::string fullPatternsOrderLabel{"Empty label"};
|
|
|
|
vcg::Triangle3<double> reducedPatternBaseTriangle;
|
|
PatternGeometry reducedPattern;
|
|
const bool randomTesselationIsEnabled{false};
|
|
const std::vector<std::string> scenariosTestSetLabels{"22Hex_randomBending0",
|
|
"22Hex_randomBending1",
|
|
"22Hex_randomBending2",
|
|
"22Hex_randomBending3",
|
|
"22Hex_randomBending4",
|
|
"22Hex_randomBending5",
|
|
"22Hex_randomBending6",
|
|
"22Hex_randomBending7",
|
|
"22Hex_randomBending8",
|
|
"22Hex_randomBending9",
|
|
"22Hex_randomBending10",
|
|
"22Hex_randomBending11",
|
|
"22Hex_randomBending12",
|
|
"22Hex_randomBending13",
|
|
"22Hex_randomBending14",
|
|
"22Hex_randomBending15",
|
|
"22Hex_randomBending16",
|
|
"22Hex_randomBending17",
|
|
"22Hex_randomBending18",
|
|
"22Hex_randomBending19",
|
|
"22Hex_randomBending20",
|
|
"22Hex_bending_0.005N",
|
|
"22Hex_bending_0.01N",
|
|
"22Hex_bending_0.03N",
|
|
"22Hex_bending_0.05N",
|
|
"22Hex_pullOppositeVerts_0.05N",
|
|
"22Hex_pullOppositeVerts_0.1N",
|
|
"22Hex_pullOppositeVerts_0.3N",
|
|
"22Hex_shear_2N",
|
|
"22Hex_shear_5N",
|
|
"22Hex_axial_10N",
|
|
"22Hex_axial_20N",
|
|
"22Hex_cylinder_0.05N",
|
|
"22Hex_cylinder_0.1N",
|
|
"22Hex_s_0.05N",
|
|
"22Hex_s_0.1N"};
|
|
|
|
std::unordered_map<size_t, size_t> shuffleToNumOfOccur;
|
|
|
|
public:
|
|
ReducedPatternSimulator(std::vector<ReducedPatternOptimization::Results> &optimizationResults);
|
|
void simulate(std::shared_ptr<VCGPolyMesh> &tileIntoSurface,
|
|
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
PatternGeometry &reducedPattern,
|
|
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatternIndices
|
|
= std::vector<OptimizationResultsIndex>());
|
|
/*
|
|
* centers the surface
|
|
* scales it such that its average base triangle size matches a desired one. This is done in order to match the base triangle on which the reduced pattern was optimized on
|
|
* */
|
|
void preprocessSurface(const double &desiredBaseTriangleHeight, VCGPolyMesh &surface);
|
|
static void applyOptimizationResults_elements(
|
|
const ReducedPatternOptimization::Results &reducedPattern_optimizationResults,
|
|
const std::shared_ptr<SimulationMesh> &pTiledReducedPattern_simulationMesh,
|
|
const std::vector<size_t> &elementIndices);
|
|
static void applyOptimizationResults_innerHexagon(
|
|
const ReducedPatternOptimization::Results &reducedPattern_optimizationResults,
|
|
const vcg::Triangle3<double> &patternBaseTriangle,
|
|
PatternGeometry &reducedPattern);
|
|
static std::vector<ReducedPatternOptimization::Results> loadOptimizationResults(
|
|
const std::filesystem::path &optimizationResultsFolderPath);
|
|
|
|
private:
|
|
std::vector<PatternGeometry> fullPatterns;
|
|
static void createSimulationJobs(const Vector6d &externalForce,
|
|
SimulationJob &job_fullPattern,
|
|
SimulationJob &job_reducedPattern);
|
|
void createGuiMenu();
|
|
std::pair<FullPatternVertexIndex, ReducedPatternVertexIndex> getPickedInterfaceVertices(
|
|
const std::pair<std::string, size_t> &selection) const;
|
|
void reset();
|
|
void saveJobs(const std::filesystem::path &outputFolderPath);
|
|
void saveResults(const std::string &outputFolderPath,
|
|
SimulationResults &fullResults,
|
|
SimulationResults &reducedResults);
|
|
void createTiledSimulationMeshes(std::vector<PatternGeometry> &fullPatterns,
|
|
std::vector<PatternGeometry> &reducedPatterns);
|
|
void createTiledSimulationMeshes(
|
|
const std::shared_ptr<ConstVCGPolyMesh> &pTileIntoSurface,
|
|
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatternIndices);
|
|
void createTiledSimulationMeshes(
|
|
const std::shared_ptr<ConstVCGPolyMesh> &tileIntoSurface,
|
|
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatterns,
|
|
std::vector<size_t> &tileIntoEdgeToTiledFullPattern);
|
|
void loadScenario(const std::string &scenarioLabel);
|
|
std::pair<DRMFullSimulationResults, ReducedSimulationResults> runSimulations(
|
|
const std::string &scenarioLabel,
|
|
const bool &shouldRerunFullPatternSimulation = false,
|
|
const bool &showReducedPatternResultsBeforeRunningDRM = false);
|
|
void runShufflingEvaluation(
|
|
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<size_t> &tileIntoEiToTiledFullVi);
|
|
void shuffleReducedPatterns(
|
|
std::shared_ptr<SimulationMesh> &pSimulationMesh_tiledShuffledReduced,
|
|
std::unordered_map<VertexIndex, VertexIndex> &fullToShuffledReduced);
|
|
double computeDistance(
|
|
const SimulationResults &resultsA,
|
|
const SimulationResults &resultsB,
|
|
const std::unordered_map<VertexIndex, VertexIndex> &resultAToResultsBViMap) const;
|
|
std::vector<double> computeDistancesPerScenario(
|
|
const std::vector<std::string> &scenarioLabels = std::vector<std::string>(),
|
|
const bool &shouldRerunDRMSimulation = false,
|
|
const bool &shouldDraw = false);
|
|
double computeDistance(const std::string &scenarioLabel,
|
|
const bool &shouldRerunDRMSimulation,
|
|
const bool &shouldDraw);
|
|
void tileReducedPatterns(
|
|
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<int> &perSurfaceFacePatternIndices,
|
|
std::shared_ptr<SimulationMesh> &pSimulationMesh_tiledReduced,
|
|
std::vector<size_t> &tileIntoEdgeToTiledReduced);
|
|
void shuffleReducedPatterns(
|
|
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<size_t> &tileIntoEdgeToTiledFullPattern,
|
|
const std::vector<int> &perSurfaceFacePatternIndices);
|
|
void runWeightEvaluation(const std::filesystem::path &optimizationResultsFolderPath);
|
|
void constructViMaps(const std::vector<size_t> &tileIntoEdgeToTiledFullPattern,
|
|
const std::vector<size_t> &tileIntoEdgeToTiledReducedPattern);
|
|
std::vector<int> computePerSurfaceFacePatternsIndices(
|
|
const std::vector<ReducedPatternOptimization::Results> &optimizationResults) const;
|
|
void tileFullPatterns(std::vector<ConstPatternGeometry> &fullPatterns,
|
|
const std::vector<int> &perSurfaceFacePatternIndices,
|
|
std::shared_ptr<SimulationMesh> &pTiledFullPattern_simulationMesh,
|
|
std::vector<size_t> &tileIntoEdgeToTiledFullVi);
|
|
void fillFullPatterns(std::vector<ReducedPatternOptimization::Results> &optimizationResults);
|
|
void computeLabels(const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
|
|
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatternIndex);
|
|
void createShufflings(std::vector<ReducedPatternOptimization::Results> &optimizationResults);
|
|
void generateRandomSimulationScenario(const std::array<float, 4> &randomScenarioParameters);
|
|
std::tuple<DRMFullSimulationResults, ReducedSimulationResults, LinearFullSimulationResults>
|
|
runAllSimulations(const string &jobLabel,
|
|
const bool &shouldRerunDRMFullPatternSimulation = false,
|
|
const bool &showReducedPatternResultsBeforeDRM = true);
|
|
void reportDistances(const std::tuple<DRMFullSimulationResults,
|
|
ReducedSimulationResults,
|
|
LinearFullSimulationResults> &simulationResults,
|
|
const string &csvFilePath = {});
|
|
void reportDistances(const std::vector<std::string> &scenarioLabels);
|
|
void saveTesselation(const std::filesystem::path &saveTo);
|
|
void removeDrawnSimulationJobs();
|
|
void loadTessellation(const std::filesystem::path &jsonFilePath);
|
|
void computeSurfaceColorsFromPerFacePatterns(const std::vector<int> &faceToPatternIndex);
|
|
void resetTilledMeshes();
|
|
std::string computeFullPatternSetLabel(
|
|
const std::vector<ReducedPatternOptimization::Results> &optimizationResults);
|
|
void resetUserSelectedVertices();
|
|
void resetUserSelectedFaces();
|
|
void removeTesselatedPatterns();
|
|
void updateTesselationColors();
|
|
};
|
|
|
|
#endif // REDUCEDPATTERNSIMULATOR_HPP
|