Optimization using the second reduced model.
This commit is contained in:
parent
cfdbe60f37
commit
97893cd618
|
|
@ -48,7 +48,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: "
|
||||
|
|
@ -87,7 +87,8 @@ int main(int argc, char *argv[]) {
|
|||
beamDimensionsRatio.toString() + " " +
|
||||
beamE.toString();
|
||||
std::cout << xRangesString << std::endl;
|
||||
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE,innerHexagonSize};
|
||||
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE,
|
||||
innerHexagonSize};
|
||||
// std::filesystem::path thisOptimizationDirectory(
|
||||
// std::filesystem::path("../OptimizationResults").append(xRangesString));
|
||||
// std::filesystem::create_directories(thisOptimizationDirectory);
|
||||
|
|
@ -103,7 +104,7 @@ int main(int argc, char *argv[]) {
|
|||
resultsPerPattern(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 auto filepathString = filepath.string();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ struct GlobalOptimizationVariables {
|
|||
std::vector<std::vector<double>> failedSimulationsXRatio;
|
||||
int numOfSimulationCrashes{false};
|
||||
int numberOfFunctionCalls{0};
|
||||
int numberOfOptimizationParameters{ 3 };
|
||||
int numberOfOptimizationParameters{3};
|
||||
};
|
||||
|
||||
// static GlobalOptimizationVariables global;
|
||||
|
|
@ -155,8 +155,7 @@ double ReducedModelOptimizer::computeError(
|
|||
void updateMesh(long n, const double *x) {
|
||||
auto &global = tls[omp_get_thread_num()];
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh =
|
||||
global
|
||||
.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
||||
global.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
||||
->pMesh;
|
||||
// const Element &elem = g_reducedPatternSimulationJob[0]->mesh->elements[0];
|
||||
// std::cout << elem.axialConstFactor << " " << elem.torsionConstFactor << "
|
||||
|
|
@ -222,7 +221,7 @@ double ReducedModelOptimizer::objective(double b, double h, double E) {
|
|||
|
||||
double ReducedModelOptimizer::objective(double b, double h, double E,
|
||||
double innerHexagonSize) {
|
||||
std::vector<double> x{b, h, E,innerHexagonSize};
|
||||
std::vector<double> x{b, h, E, innerHexagonSize};
|
||||
return ReducedModelOptimizer::objective(x.size(), x.data());
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +249,7 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
|||
double error = 0;
|
||||
FormFinder simulator;
|
||||
FormFinder::Settings simulationSettings;
|
||||
simulationSettings.shouldDraw = true;
|
||||
// simulationSettings.shouldDraw = true;
|
||||
for (const int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||
SimulationResults reducedModelResults = simulator.executeSimulation(
|
||||
global.g_reducedPatternSimulationJob[simulationScenarioIndex],
|
||||
|
|
@ -296,8 +295,7 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
|||
std::ofstream out(filename, std::ios_base::app);
|
||||
auto pMesh =
|
||||
global
|
||||
.g_reducedPatternSimulationJob[global
|
||||
.simulationScenarioIndices[0]]
|
||||
.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
||||
->pMesh;
|
||||
|
||||
for (size_t parameterIndex = 0; parameterIndex < n; parameterIndex++) {
|
||||
|
|
@ -321,9 +319,9 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
|||
global.minX.assign(x, x + n);
|
||||
}
|
||||
global.numberOfFunctionCalls++;
|
||||
//if (++global.numberOfFunctionCalls % 50 == 0) {
|
||||
std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
||||
<< std::endl;
|
||||
// if (++global.numberOfFunctionCalls % 50 == 0) {
|
||||
std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
||||
<< std::endl;
|
||||
//}
|
||||
|
||||
// compute error and return it
|
||||
|
|
@ -497,8 +495,8 @@ ReducedModelOptimizer::ReducedModelOptimizer(
|
|||
void ReducedModelOptimizer::initializePatterns(
|
||||
FlatPattern &fullPattern, FlatPattern &reducedPattern,
|
||||
const std::unordered_set<size_t> &reducedModelExcludedEdges) {
|
||||
//fullPattern.setLabel("full_pattern_" + fullPattern.getLabel());
|
||||
//reducedPattern.setLabel("reduced_pattern_" + reducedPattern.getLabel());
|
||||
// fullPattern.setLabel("full_pattern_" + fullPattern.getLabel());
|
||||
// reducedPattern.setLabel("reduced_pattern_" + reducedPattern.getLabel());
|
||||
assert(fullPattern.VN() == reducedPattern.VN() &&
|
||||
fullPattern.EN() >= reducedPattern.EN());
|
||||
polyscope::removeAllStructures();
|
||||
|
|
@ -540,9 +538,9 @@ void ReducedModelOptimizer::initializeOptimizationParameters(
|
|||
const std::shared_ptr<SimulationMesh> &mesh) {
|
||||
auto &global = tls[omp_get_thread_num()];
|
||||
global.numberOfOptimizationParameters = 3;
|
||||
global.g_initialParameters.resize(global.optimizeInnerHexagonSize
|
||||
? ++global.numberOfOptimizationParameters
|
||||
: global.numberOfOptimizationParameters);
|
||||
global.g_initialParameters.resize(
|
||||
global.optimizeInnerHexagonSize ? ++global.numberOfOptimizationParameters
|
||||
: global.numberOfOptimizationParameters);
|
||||
// Save save the beam stiffnesses
|
||||
// for (size_t ei = 0; ei < pReducedModelElementalMesh->EN(); ei++) {
|
||||
// Element &e = pReducedModelElementalMesh->elements[ei];
|
||||
|
|
@ -560,7 +558,7 @@ void ReducedModelOptimizer::initializeOptimizationParameters(
|
|||
global.g_initialParameters(1) = initialRatio;
|
||||
global.g_initialParameters(2) = mesh->elements[0].material.youngsModulus;
|
||||
if (global.optimizeInnerHexagonSize) {
|
||||
global.g_initialParameters(3) =global.g_innerHexagonInitialPos;
|
||||
global.g_initialParameters(3) = global.g_innerHexagonInitialPos;
|
||||
}
|
||||
// g_initialParameters =
|
||||
// m_pReducedPatternSimulationMesh->elements[0].properties.E;
|
||||
|
|
@ -648,9 +646,9 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
|||
// "conditions is not recommended.");
|
||||
// Set initial guess of solution
|
||||
|
||||
//const size_t initialGuess = 1;
|
||||
//std::vector<double> x(n, initialGuess);
|
||||
//if (global.optimizeInnerHexagonSize) {
|
||||
// const size_t initialGuess = 1;
|
||||
// std::vector<double> x(n, initialGuess);
|
||||
// if (global.optimizeInnerHexagonSize) {
|
||||
// x[n - 1] = global.g_innerHexagonInitialPos;
|
||||
//}
|
||||
/*if (!initialGuess.empty()) {
|
||||
|
|
@ -690,16 +688,15 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
|||
auto start = std::chrono::system_clock::now();
|
||||
dlib::function_evaluation result;
|
||||
if (global.optimizeInnerHexagonSize) {
|
||||
double (*objF)(double, double, double,double) = &objective;
|
||||
result = dlib::find_min_global(
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||
}
|
||||
else {
|
||||
double (*objF)(double, double, double) = &objective;
|
||||
result = dlib::find_min_global(
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||
double (*objF)(double, double, double, double) = &objective;
|
||||
result = dlib::find_min_global(
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||
} else {
|
||||
double (*objF)(double, double, double) = &objective;
|
||||
result = dlib::find_min_global(
|
||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||
}
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||||
|
|
@ -1084,6 +1081,6 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::optimize(
|
|||
}
|
||||
Results optResults = runOptimization(xRanges, &objective);
|
||||
updateMesh(optResults.x.size(), optResults.x.data());
|
||||
visualizeResults(simulationJobs, global.simulationScenarioIndices);
|
||||
visualizeResults(simulationJobs, global.simulationScenarioIndices);
|
||||
return optResults;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue