#include "csvfile.hpp" #include "drmsimulationmodel.hpp" #include "edgemesh.hpp" #include "reducedmodeloptimizer.hpp" #include "simulationhistoryplotter.hpp" #include "trianglepattterntopology.hpp" #include #include #include #include #include #include #include #ifdef POLYSCOPE_DEFINED #include "polyscope/curve_network.h" #include "polyscope/point_cloud.h" #include "polyscope/polyscope.h" #endif int main(int argc, char *argv[]) { if (argc < 3) { std::cerr << "Specify at least the two pattern filepaths to be " "optimized.Exiting.." << std::endl; std::terminate(); } // Populate the pattern pair to be optimized const int interfaceNodeIndex=3; ////Full pattern const std::string filepath_fullPattern = argv[1]; PatternGeometry fullPattern(filepath_fullPattern); fullPattern.setLabel( std::filesystem::path(filepath_fullPattern).stem().string()); fullPattern.scale(0.03,interfaceNodeIndex); ////Reduced pattern const std::string filepath_reducedPattern = argv[2]; PatternGeometry reducedPattern(filepath_reducedPattern); reducedPattern.setLabel(std::filesystem::path(filepath_reducedPattern).stem().string()); reducedPattern.scale(0.03, interfaceNodeIndex); // Set the optization settings ReducedPatternOptimization::xRange beamE{"E", 0.001, 1000}; ReducedPatternOptimization::xRange beamA{"A", 0.001, 1000}; ReducedPatternOptimization::xRange beamI2{"I2", 0.001, 1000}; ReducedPatternOptimization::xRange beamI3{"I3", 0.001, 1000}; ReducedPatternOptimization::xRange beamJ{"J", 0.001, 1000}; ReducedPatternOptimization::xRange innerHexagonSize{"HexSize", 0.05, 0.95}; ReducedPatternOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0}; ReducedPatternOptimization::Settings settings_optimization; settings_optimization.xRanges = {beamE,beamA,beamJ,beamI2,beamI3, innerHexagonSize, innerHexagonAngle}; const bool input_numberOfFunctionCallsDefined = argc >= 4; settings_optimization.numberOfFunctionCalls = input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100; settings_optimization.normalizationStrategy = ReducedPatternOptimization::Settings::NormalizationStrategy::Epsilon; settings_optimization.normalizationParameter = 0.0003; settings_optimization.solutionAccuracy = 0.001; settings_optimization.objectiveWeights.translational = std::atof(argv[4]); settings_optimization.objectiveWeights.rotational = 2 - std::atof(argv[4]); // Optimize pair const std::string pairName = fullPattern.getLabel() + "@" + reducedPattern.getLabel(); const std::vector numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1}; assert(interfaceNodeIndex==numberOfNodesPerSlot[0]+numberOfNodesPerSlot[3]); ReducedModelOptimizer optimizer(numberOfNodesPerSlot); optimizer.initializePatterns(fullPattern, reducedPattern, settings_optimization.xRanges.size()); ReducedPatternOptimization::Results optimizationResults // = optimizer.optimize( // settings_optimization); = optimizer.optimize(settings_optimization); // Export results const bool input_resultDirectoryDefined = argc >= 6; std::string optimizationResultsDirectory = input_resultDirectoryDefined ? argv[5] : std::filesystem::current_path().append( "OptimizationResults"); std::string resultsOutputDir; if (optimizationResults.numberOfSimulationCrashes != 0) { const auto crashedJobsDirPath = std::filesystem::path( optimizationResultsDirectory.append("CrashedJobs") .append( pairName + "(" + std::to_string(settings_optimization.numberOfFunctionCalls) + "_" + to_string_with_precision(settings_optimization.objectiveWeights.translational) + ")")); std::filesystem::create_directories(crashedJobsDirPath); resultsOutputDir = crashedJobsDirPath.string(); } else { std::filesystem::path convergedJobsDirPath( std::filesystem::path(optimizationResultsDirectory) .append("ConvergedJobs") .append( pairName + "(" + std::to_string(settings_optimization.numberOfFunctionCalls) + "_" + to_string_with_precision(settings_optimization.objectiveWeights.translational) + ")")); std::filesystem::create_directories(convergedJobsDirPath); resultsOutputDir = convergedJobsDirPath.string(); } optimizationResults.save(resultsOutputDir); // Write results in csv csvFile csv_results({}, false); // csvFile csv_results(std::filesystem::path(dirPath_thisOptimization) // .append("results.csv") // .string(), // false); csv_results << "Name"; optimizationResults.writeHeaderTo(csv_results); settings_optimization.writeHeaderTo(csv_results); csv_results << endrow; csv_results << pairName; optimizationResults.writeResultsTo(settings_optimization, csv_results); settings_optimization.writeSettingsTo(csv_results); csv_results << endrow; #ifdef POLYSCOPE_DEFINED optimizationResults.saveMeshFiles(); optimizationResults.draw(); #endif return 0; }