#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 &mOptimizationResults; std::shared_ptr pTiledFullPattern_simulationMesh; std::shared_ptr pTiledReducedPattern_simulationMesh; std::shared_ptr pJob_tiledReducedPattern; std::shared_ptr pJob_tiledFullPattern; std::shared_ptr pTileIntoSurface; const Vector6d externalForce{0, 0, 0.1, 0, 0, 0}; double minInputForceMagnitude = std::numeric_limits::max(); std::string gui_jobLabel; std::string gui_tessellationLabel; bool gui_shouldRerunFullPatternSimulation{false}; float gui_scaleFactor{1}; std::vector gui_fullVerticesColors; std::vector gui_reducedVerticesColors; std::array gui_externalForce{0, 0, 0}; std::array gui_externalMoment{0, 0, 0}; std::array gui_randomnessParams{0.02, 0.02, 0.1, 0.3}; std::vector gui_faceToPatternIndex; std::vector gui_fullPatternSelectedVertices; std::pair gui_currentColorPatternIndexPair{glm::vec3(1, 0, 0), 0}; std::vector gui_colorsPerFace; std::unordered_map fullToReducedViMap; //of only the common vertices std::unordered_map reducedToFullViMap; //of only the common vertices std::vector tilledFullPatternInterfaceVi; double surfaceBaseTriangleHeight{-1}; std::array color_tesselatedFullPatterns{0.89, 0.61, 0.11}; std::array 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 reducedPatternBaseTriangle; PatternGeometry reducedPattern; const bool randomTesselationIsEnabled{false}; const std::vector 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 shuffleToNumOfOccur; public: ReducedPatternSimulator(std::vector &optimizationResults); void simulate(std::shared_ptr &tileIntoSurface, std::vector &optimizationResults, PatternGeometry &reducedPattern, const std::vector &perSurfaceFacePatternIndices = std::vector()); /* * 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 &pTiledReducedPattern_simulationMesh, const std::vector &elementIndices); static void applyOptimizationResults_innerHexagon( const ReducedPatternOptimization::Results &reducedPattern_optimizationResults, const vcg::Triangle3 &patternBaseTriangle, PatternGeometry &reducedPattern); static std::vector loadOptimizationResults( const std::filesystem::path &optimizationResultsFolderPath); private: std::vector fullPatterns; static void createSimulationJobs(const Vector6d &externalForce, SimulationJob &job_fullPattern, SimulationJob &job_reducedPattern); void createGuiMenu(); std::pair getPickedInterfaceVertices( const std::pair &selection) const; void reset(); void saveJobs(const filesystem::__cxx11::path &outputFolderPath); void saveResults(const std::string &outputFolderPath, SimulationResults &fullResults, SimulationResults &reducedResults); void createTiledSimulationMeshes(std::vector &fullPatterns, std::vector &reducedPatterns); void createTiledSimulationMeshes( const std::shared_ptr &pTileIntoSurface, std::vector &optimizationResults, const std::vector &perSurfaceFacePatternIndices); void createTiledSimulationMeshes( const std::shared_ptr &tileIntoSurface, std::vector &optimizationResults, const std::vector &perSurfaceFacePatterns, std::vector &tileIntoEdgeToTiledFullPattern); void loadScenario(const std::string &scenarioLabel); std::pair runSimulations( const std::string &scenarioLabel, const bool &shouldRerunFullPatternSimulation = false, const bool &showReducedPatternResultsBeforeRunningDRM = false); void runShufflingEvaluation( const std::vector &optimizationResults, const std::vector &tileIntoEiToTiledFullVi); void shuffleReducedPatterns( std::shared_ptr &pSimulationMesh_tiledShuffledReduced, std::unordered_map &fullToShuffledReduced); double computeDistance( const SimulationResults &resultsA, const SimulationResults &resultsB, const std::unordered_map &resultAToResultsBViMap) const; std::vector computeDistancesPerScenario( const std::vector &scenarioLabels = std::vector(), 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 &optimizationResults, const std::vector &perSurfaceFacePatternIndices, std::shared_ptr &pSimulationMesh_tiledReduced, std::vector &tileIntoEdgeToTiledReduced); void shuffleReducedPatterns( const std::vector &optimizationResults, const std::vector &tileIntoEdgeToTiledFullPattern, const std::vector &perSurfaceFacePatternIndices); void runWeightEvaluation(const std::filesystem::path &optimizationResultsFolderPath); void constructViMaps(const std::vector &tileIntoEdgeToTiledFullPattern, const std::vector &tileIntoEdgeToTiledReducedPattern); std::vector computePerSurfaceFacePatternsIndices( const std::vector &optimizationResults) const; void tileFullPatterns(std::vector &fullPatterns, const std::vector &perSurfaceFacePatternIndices, std::shared_ptr &pTiledFullPattern_simulationMesh, std::vector &tileIntoEdgeToTiledFullVi); void fillFullPatterns(std::vector &optimizationResults); void computeLabels(const std::vector &optimizationResults, const std::vector &perSurfaceFacePatternIndex); void createShufflings(std::vector &optimizationResults); void generateRandomSimulationScenario(const std::array &randomScenarioParameters); std::tuple runAllSimulations(const string &jobLabel, const bool &shouldRerunDRMFullPatternSimulation = false, const bool &showReducedPatternResultsBeforeDRM = true); void reportDistances(const std::tuple &simulationResults, const string &csvFilePath = {}); void reportDistances(const std::vector &scenarioLabels); void saveTesselation(const std::filesystem::path &saveTo); void removeDrawnSimulationJobs(); void loadTessellation(const std::filesystem::path &jsonFilePath); void computeSurfaceColorsFromPerFacePatterns(const std::vector &faceToPatternIndex); void resetTilledMeshes(); std::string computeFullPatternSetLabel( const std::vector &optimizationResults); void resetUserSelectedVertices(); void resetUserSelectedFaces(); void removeTesselatedPatterns(); void updateTesselationColors(); }; #endif // REDUCEDPATTERNSIMULATOR_HPP