2021-03-23 18:20:46 +01:00
|
|
|
#include "drmsimulationmodel.hpp"
|
2021-01-22 15:39:36 +01:00
|
|
|
#include "csvfile.hpp"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include "edgemesh.hpp"
|
|
|
|
#include "reducedmodeloptimizer.hpp"
|
|
|
|
#include "simulationhistoryplotter.hpp"
|
2020-12-09 16:58:48 +01:00
|
|
|
#include "trianglepattterntopology.hpp"
|
2020-11-23 10:06:45 +01:00
|
|
|
#include <chrono>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
2021-02-01 15:10:24 +01:00
|
|
|
#include <iterator>
|
2020-11-23 10:06:45 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2020-12-09 16:58:48 +01:00
|
|
|
#include <vcg/complex/algorithms/update/position.h>
|
|
|
|
|
2021-02-24 18:41:12 +01:00
|
|
|
#ifdef POLYSCOPE_DEFINED
|
|
|
|
#include "polyscope/curve_network.h"
|
|
|
|
#include "polyscope/point_cloud.h"
|
|
|
|
#include "polyscope/polyscope.h"
|
|
|
|
#endif
|
2020-11-23 10:06:45 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
2021-02-22 18:23:58 +01:00
|
|
|
if (argc < 3) {
|
|
|
|
std::cerr << "Specify at least the two pattern filepaths to be "
|
|
|
|
"optimized.Exiting.."
|
2021-02-19 16:32:15 +01:00
|
|
|
<< std::endl;
|
2021-02-18 14:33:31 +01:00
|
|
|
std::terminate();
|
|
|
|
}
|
2021-02-19 16:32:15 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Populate the pattern pair to be optimized
|
2021-03-16 10:57:27 +01:00
|
|
|
const int interfaceNodeIndex=3;
|
2021-02-18 14:33:31 +01:00
|
|
|
////Full pattern
|
2021-02-22 18:23:58 +01:00
|
|
|
const std::string filepath_fullPattern = argv[1];
|
2021-03-15 18:56:14 +01:00
|
|
|
PatternGeometry fullPattern(filepath_fullPattern);
|
2021-02-18 14:33:31 +01:00
|
|
|
fullPattern.setLabel(
|
|
|
|
std::filesystem::path(filepath_fullPattern).stem().string());
|
2021-03-16 10:57:27 +01:00
|
|
|
fullPattern.scale(0.03,interfaceNodeIndex);
|
2021-02-18 14:33:31 +01:00
|
|
|
////Reduced pattern
|
2021-02-22 18:23:58 +01:00
|
|
|
const std::string filepath_reducedPattern = argv[2];
|
2021-03-15 18:56:14 +01:00
|
|
|
PatternGeometry reducedPattern(filepath_reducedPattern);
|
2021-03-26 10:58:13 +01:00
|
|
|
reducedPattern.setLabel(std::filesystem::path(filepath_reducedPattern).stem().string());
|
|
|
|
reducedPattern.scale(0.03, interfaceNodeIndex);
|
2021-02-18 14:33:31 +01:00
|
|
|
|
|
|
|
// Set the optization settings
|
2021-03-26 10:58:13 +01:00
|
|
|
ReducedModelOptimization::xRange beamE{"E", 0.001, 1000};
|
|
|
|
ReducedModelOptimization::xRange beamA{"A", 0.001, 1000};
|
|
|
|
ReducedModelOptimization::xRange beamI2{"I2", 0.001, 1000};
|
|
|
|
ReducedModelOptimization::xRange beamI3{"I3", 0.001, 1000};
|
|
|
|
ReducedModelOptimization::xRange beamJ{"J", 0.001, 1000};
|
|
|
|
ReducedModelOptimization::xRange innerHexagonSize{"HexSize", 0.05, 0.95};
|
|
|
|
ReducedModelOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0};
|
2021-03-23 18:20:46 +01:00
|
|
|
ReducedModelOptimization::Settings settings_optimization;
|
2021-03-16 10:57:27 +01:00
|
|
|
settings_optimization.xRanges = {beamE,beamA,beamJ,beamI2,beamI3,
|
2021-03-15 18:56:14 +01:00
|
|
|
innerHexagonSize, innerHexagonAngle};
|
2021-02-25 09:09:38 +01:00
|
|
|
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
2021-02-18 14:33:31 +01:00
|
|
|
settings_optimization.numberOfFunctionCalls =
|
2021-02-25 09:09:38 +01:00
|
|
|
input_numberOfFunctionCallsDefined ? std::atoi(argv[3]) : 100;
|
2021-03-26 10:58:13 +01:00
|
|
|
settings_optimization.normalizationStrategy
|
|
|
|
= ReducedModelOptimization::Settings::NormalizationStrategy::Epsilon;
|
2021-03-02 19:32:43 +01:00
|
|
|
settings_optimization.normalizationParameter = 0.0003;
|
2021-03-30 11:35:00 +02:00
|
|
|
settings_optimization.solutionAccuracy = 0.001;
|
2021-02-22 10:28:01 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Optimize pair
|
|
|
|
const std::string pairName =
|
|
|
|
fullPattern.getLabel() + "@" + reducedPattern.getLabel();
|
2021-02-19 16:32:15 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
2021-03-16 10:57:27 +01:00
|
|
|
assert(interfaceNodeIndex==numberOfNodesPerSlot[0]+numberOfNodesPerSlot[3]);
|
2021-02-18 14:33:31 +01:00
|
|
|
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
2021-03-30 18:30:49 +02:00
|
|
|
optimizer.initializePatterns(fullPattern, reducedPattern, settings_optimization.xRanges.size());
|
2021-04-05 11:41:05 +02:00
|
|
|
ReducedModelOptimization::Results optimizationResults = optimizer.optimize(settings_optimization);
|
2021-02-22 10:28:01 +01:00
|
|
|
|
2021-02-18 14:33:31 +01:00
|
|
|
// Export results
|
2021-02-25 09:09:38 +01:00
|
|
|
const bool input_resultDirectoryDefined = argc >= 5;
|
2021-02-22 10:28:01 +01:00
|
|
|
std::string optimizationResultsDirectory =
|
2021-03-17 14:43:31 +01:00
|
|
|
input_resultDirectoryDefined ? argv[4] : std::filesystem::current_path().append("OptimizationResults");
|
2021-03-01 13:34:27 +01:00
|
|
|
std::string resultsOutputDir;
|
2021-02-22 10:28:01 +01:00
|
|
|
if (optimizationResults.numberOfSimulationCrashes != 0) {
|
|
|
|
const auto crashedJobsDirPath =
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::path(optimizationResultsDirectory)
|
2021-02-22 10:28:01 +01:00
|
|
|
.append("CrashedJobs")
|
|
|
|
.append(pairName);
|
|
|
|
std::filesystem::create_directories(crashedJobsDirPath);
|
2021-03-01 13:34:27 +01:00
|
|
|
resultsOutputDir = crashedJobsDirPath.string();
|
2021-02-22 10:28:01 +01:00
|
|
|
} else {
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::path convergedJobsDirPath(
|
|
|
|
std::filesystem::path(optimizationResultsDirectory)
|
2021-02-22 10:28:01 +01:00
|
|
|
.append("ConvergedJobs")
|
|
|
|
.append(pairName));
|
2021-02-22 18:43:10 +01:00
|
|
|
std::filesystem::create_directories(convergedJobsDirPath);
|
2021-03-01 13:34:27 +01:00
|
|
|
resultsOutputDir = convergedJobsDirPath.string();
|
2021-02-22 10:28:01 +01:00
|
|
|
}
|
2021-03-01 13:34:27 +01:00
|
|
|
optimizationResults.save(resultsOutputDir);
|
|
|
|
// Write results in csv
|
2021-02-19 16:32:15 +01:00
|
|
|
csvFile csv_results({}, false);
|
|
|
|
// csvFile csv_results(std::filesystem::path(dirPath_thisOptimization)
|
|
|
|
// .append("results.csv")
|
|
|
|
// .string(),
|
|
|
|
// false);
|
2021-02-22 10:28:01 +01:00
|
|
|
csv_results << "Name";
|
2021-03-30 11:35:00 +02:00
|
|
|
optimizationResults.writeHeaderTo(csv_results);
|
2021-02-22 10:28:01 +01:00
|
|
|
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;
|
2021-02-18 14:33:31 +01:00
|
|
|
|
2021-03-16 10:57:27 +01:00
|
|
|
#ifdef POLYSCOPE_DEFINED
|
2021-03-30 18:30:49 +02:00
|
|
|
optimizationResults.draw();
|
2021-03-16 10:57:27 +01:00
|
|
|
#endif
|
2020-11-23 10:06:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|