Refactoring"
This commit is contained in:
parent
e644a069d4
commit
8e57909f3d
25
src/main.cpp
25
src/main.cpp
|
|
@ -17,7 +17,6 @@
|
|||
#include <vcg/complex/algorithms/update/position.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Create reduced models
|
||||
// FormFinder::runUnitTests();
|
||||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
|
|
@ -48,7 +47,7 @@ int main(int argc, char *argv[]) {
|
|||
ReducedModelOptimizer::xRange beamE{"E", 0.1, 1.9};
|
||||
ReducedModelOptimizer::xRange innerHexagonSize{"HexagonSize", 0.1, 0.9};
|
||||
// Test set of full patterns
|
||||
std::string fullPatternsTestSetDirectory = "../TestSet";
|
||||
std::string fullPatternsTestSetDirectory = "TestSet";
|
||||
if (!std::filesystem::exists(
|
||||
std::filesystem::path(fullPatternsTestSetDirectory))) {
|
||||
std::cerr << "Full pattern directory does not exist: "
|
||||
|
|
@ -70,14 +69,16 @@ int main(int argc, char *argv[]) {
|
|||
continue;
|
||||
}
|
||||
|
||||
FlatPattern fullPattern(filepathString);
|
||||
fullPattern.setLabel(filepath.stem().string());
|
||||
fullPattern.scale(0.03);
|
||||
for (int reducedPatternIndex = 0;
|
||||
reducedPatternIndex < reducedModels.size(); reducedPatternIndex++) {
|
||||
FlatPattern *pFullPattern = new FlatPattern(filepathString);
|
||||
pFullPattern->setLabel(filepath.stem().string());
|
||||
pFullPattern->scale(0.03);
|
||||
FlatPattern *pFullPattern = new FlatPattern();
|
||||
pFullPattern->copy(fullPattern);
|
||||
FlatPattern *pReducedPattern = new FlatPattern();
|
||||
pReducedPattern->copy(*reducedModels[reducedPatternIndex]);
|
||||
// pReducedPattern->copy(*reducedModels[2]);
|
||||
//pReducedPattern->copy(*reducedModels[0]);
|
||||
patternPairs.push_back(std::make_pair(pFullPattern, pReducedPattern));
|
||||
}
|
||||
}
|
||||
|
|
@ -94,8 +95,12 @@ int main(int argc, char *argv[]) {
|
|||
settings_optimization.numberOfFunctionCalls = 10;
|
||||
const std::string optimizationSettingsString =
|
||||
settings_optimization.toString();
|
||||
std::string optimiziationResultsDirectory = "../OptimizationResults";
|
||||
// if (argc == 1) {
|
||||
// optimiziationResultsDirectory = argv[0];
|
||||
//}
|
||||
std::filesystem::path thisOptimizationDirectory(
|
||||
std::filesystem::path("../OptimizationResults")
|
||||
std::filesystem::path(optimiziationResultsDirectory)
|
||||
.append(optimizationSettingsString));
|
||||
std::filesystem::create_directories(thisOptimizationDirectory);
|
||||
std::cout << optimizationSettingsString << std::endl;
|
||||
|
|
@ -111,7 +116,7 @@ int main(int argc, char *argv[]) {
|
|||
patternPairs.size());
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
//#pragma omp parallel for
|
||||
#pragma omp parallel for
|
||||
for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
||||
patternPairIndex++) {
|
||||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
|
|
@ -138,8 +143,8 @@ int main(int argc, char *argv[]) {
|
|||
patternPairs[patternPairIndex].second->getLabel()));
|
||||
std::filesystem::create_directories(std::filesystem::path(saveToPath));
|
||||
|
||||
optimizationResults_testSet[patternPairIndex].save(saveToPath);
|
||||
// optimizationResults_testSet[patternPairIndex].draw();
|
||||
optimizationResults_testSet[patternPairIndex].save(saveToPath.string());
|
||||
optimizationResults_testSet[patternPairIndex].draw();
|
||||
}
|
||||
csvFile statistics(std::filesystem::path(thisOptimizationDirectory)
|
||||
.append("statistics.csv")
|
||||
|
|
|
|||
|
|
@ -351,11 +351,10 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
|||
global.minY = error;
|
||||
global.minX.assign(x, x + n);
|
||||
}
|
||||
global.numberOfFunctionCalls++;
|
||||
// if (++global.numberOfFunctionCalls % 50 == 0) {
|
||||
if (++global.numberOfFunctionCalls % 100 == 0) {
|
||||
std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
||||
<< std::endl;
|
||||
//}
|
||||
}
|
||||
|
||||
// compute error and return it
|
||||
global.gObjectiveValueHistory.push_back(error);
|
||||
|
|
@ -688,8 +687,7 @@ void ReducedModelOptimizer::computeDesiredReducedModelDisplacements(
|
|||
}
|
||||
|
||||
ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
||||
const Settings &settings,
|
||||
double (*pObjectiveFunction)(long, const double *)) {
|
||||
const Settings &settings) {
|
||||
auto &global = tls[omp_get_thread_num()];
|
||||
|
||||
global.gObjectiveValueHistory.clear();
|
||||
|
|
@ -740,7 +738,6 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
|||
xMax(i) = settings.xRanges[i].max;
|
||||
}
|
||||
|
||||
global.numberOfFunctionCalls = 0;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
dlib::function_evaluation result;
|
||||
if (global.optimizeInnerHexagonSize) {
|
||||
|
|
@ -1130,6 +1127,7 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::optimize(
|
|||
global.g_firstRoundIterationIndex = 0;
|
||||
global.minY = std::numeric_limits<double>::max();
|
||||
global.numOfSimulationCrashes = 0;
|
||||
global.numberOfFunctionCalls = 0;
|
||||
// polyscope::removeAllStructures();
|
||||
|
||||
FormFinder::Settings settings;
|
||||
|
|
@ -1152,7 +1150,7 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::optimize(
|
|||
global.reducedPatternSimulationJobs[simulationScenarioIndex] =
|
||||
std::make_shared<SimulationJob>(reducedPatternSimulationJob);
|
||||
}
|
||||
Results optResults = runOptimization(xRanges, &objective);
|
||||
Results optResults = runOptimization(xRanges);
|
||||
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||
optResults.fullPatternSimulationJobs.push_back(
|
||||
simulationJobs[simulationScenarioIndex]);
|
||||
|
|
|
|||
|
|
@ -160,9 +160,7 @@ private:
|
|||
const SimulationResults &fullModelResults,
|
||||
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
||||
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
||||
static Results runOptimization(const Settings &settings,
|
||||
double (*pObjectiveFunction)(long,
|
||||
const double *));
|
||||
static Results runOptimization(const Settings &settings);
|
||||
std::vector<std::shared_ptr<SimulationJob>>
|
||||
createScenarios(const std::shared_ptr<SimulationMesh> &pMesh);
|
||||
void computeMaps(FlatPattern &fullModel, FlatPattern &reducedPattern,
|
||||
|
|
@ -243,15 +241,17 @@ struct ReducedModelOptimizer::Results {
|
|||
.append(pFullPatternSimulationJob->label));
|
||||
std::filesystem::create_directory(simulationJobFolderPath);
|
||||
const auto fullPatternDirectoryPath =
|
||||
std::filesystem::path(simulationJobFolderPath).append("FullPattern");
|
||||
std::filesystem::path(simulationJobFolderPath).append("Full");
|
||||
std::filesystem::create_directory(fullPatternDirectoryPath);
|
||||
pFullPatternSimulationJob->save(fullPatternDirectoryPath.string());
|
||||
const std::shared_ptr<SimulationJob> &pReducedPatternSimulationJob =
|
||||
reducedPatternSimulationJobs[simulationJobIndex];
|
||||
const auto reducedPatternDirectoryPath =
|
||||
std::filesystem::path(simulationJobFolderPath)
|
||||
.append("ReducedPattern");
|
||||
std::filesystem::create_directory(reducedPatternDirectoryPath);
|
||||
.append("Reduced");
|
||||
if (!std::filesystem::exists(reducedPatternDirectoryPath)) {
|
||||
std::filesystem::create_directory(reducedPatternDirectoryPath);
|
||||
}
|
||||
pReducedPatternSimulationJob->save(reducedPatternDirectoryPath.string());
|
||||
}
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ struct ReducedModelOptimizer::Results {
|
|||
// Load reduced pattern files
|
||||
for (const auto &fileEntry : filesystem::directory_iterator(
|
||||
std::filesystem::path(simulationScenarioPath)
|
||||
.append("FullPattern"))) {
|
||||
.append("Full"))) {
|
||||
const auto filepath = fileEntry.path();
|
||||
if (filepath.extension() == ".json") {
|
||||
SimulationJob job;
|
||||
|
|
@ -277,7 +277,7 @@ struct ReducedModelOptimizer::Results {
|
|||
// Load full pattern files
|
||||
for (const auto &fileEntry : filesystem::directory_iterator(
|
||||
std::filesystem::path(simulationScenarioPath)
|
||||
.append("ReducedPattern"))) {
|
||||
.append("Reduced"))) {
|
||||
const auto filepath = fileEntry.path();
|
||||
if (filepath.extension() == ".json") {
|
||||
SimulationJob job;
|
||||
|
|
|
|||
Loading…
Reference in New Issue