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 beamE{"E", 0.1, 1.9};
|
||||||
ReducedModelOptimizer::xRange innerHexagonSize{"HexagonSize", 0.1, 0.9};
|
ReducedModelOptimizer::xRange innerHexagonSize{"HexagonSize", 0.1, 0.9};
|
||||||
// Test set of full patterns
|
// Test set of full patterns
|
||||||
std::string fullPatternsTestSetDirectory = "TestSet";
|
std::string fullPatternsTestSetDirectory = "../TestSet";
|
||||||
if (!std::filesystem::exists(
|
if (!std::filesystem::exists(
|
||||||
std::filesystem::path(fullPatternsTestSetDirectory))) {
|
std::filesystem::path(fullPatternsTestSetDirectory))) {
|
||||||
std::cerr << "Full pattern directory does not exist: "
|
std::cerr << "Full pattern directory does not exist: "
|
||||||
|
|
@ -87,7 +87,8 @@ int main(int argc, char *argv[]) {
|
||||||
beamDimensionsRatio.toString() + " " +
|
beamDimensionsRatio.toString() + " " +
|
||||||
beamE.toString();
|
beamE.toString();
|
||||||
std::cout << xRangesString << std::endl;
|
std::cout << xRangesString << std::endl;
|
||||||
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE,innerHexagonSize};
|
settings.xRanges = {beamWidth, beamDimensionsRatio, beamE,
|
||||||
|
innerHexagonSize};
|
||||||
// std::filesystem::path thisOptimizationDirectory(
|
// std::filesystem::path thisOptimizationDirectory(
|
||||||
// std::filesystem::path("../OptimizationResults").append(xRangesString));
|
// std::filesystem::path("../OptimizationResults").append(xRangesString));
|
||||||
// std::filesystem::create_directories(thisOptimizationDirectory);
|
// std::filesystem::create_directories(thisOptimizationDirectory);
|
||||||
|
|
@ -103,7 +104,7 @@ int main(int argc, char *argv[]) {
|
||||||
resultsPerPattern(patternPairs.size());
|
resultsPerPattern(patternPairs.size());
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
#pragma omp parallel for
|
//#pragma omp parallel for
|
||||||
for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
for (int patternPairIndex = 0; patternPairIndex < patternPairs.size();
|
||||||
patternPairIndex++) {
|
patternPairIndex++) {
|
||||||
// const auto filepathString = filepath.string();
|
// const auto filepathString = filepath.string();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ struct GlobalOptimizationVariables {
|
||||||
std::vector<std::vector<double>> failedSimulationsXRatio;
|
std::vector<std::vector<double>> failedSimulationsXRatio;
|
||||||
int numOfSimulationCrashes{false};
|
int numOfSimulationCrashes{false};
|
||||||
int numberOfFunctionCalls{0};
|
int numberOfFunctionCalls{0};
|
||||||
int numberOfOptimizationParameters{ 3 };
|
int numberOfOptimizationParameters{3};
|
||||||
};
|
};
|
||||||
|
|
||||||
// static GlobalOptimizationVariables global;
|
// static GlobalOptimizationVariables global;
|
||||||
|
|
@ -155,8 +155,7 @@ double ReducedModelOptimizer::computeError(
|
||||||
void updateMesh(long n, const double *x) {
|
void updateMesh(long n, const double *x) {
|
||||||
auto &global = tls[omp_get_thread_num()];
|
auto &global = tls[omp_get_thread_num()];
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh =
|
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh =
|
||||||
global
|
global.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
||||||
.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
|
||||||
->pMesh;
|
->pMesh;
|
||||||
// const Element &elem = g_reducedPatternSimulationJob[0]->mesh->elements[0];
|
// const Element &elem = g_reducedPatternSimulationJob[0]->mesh->elements[0];
|
||||||
// std::cout << elem.axialConstFactor << " " << elem.torsionConstFactor << "
|
// 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 ReducedModelOptimizer::objective(double b, double h, double E,
|
||||||
double innerHexagonSize) {
|
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());
|
return ReducedModelOptimizer::objective(x.size(), x.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,7 +249,7 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
||||||
double error = 0;
|
double error = 0;
|
||||||
FormFinder simulator;
|
FormFinder simulator;
|
||||||
FormFinder::Settings simulationSettings;
|
FormFinder::Settings simulationSettings;
|
||||||
simulationSettings.shouldDraw = true;
|
// simulationSettings.shouldDraw = true;
|
||||||
for (const int simulationScenarioIndex : global.simulationScenarioIndices) {
|
for (const int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||||
SimulationResults reducedModelResults = simulator.executeSimulation(
|
SimulationResults reducedModelResults = simulator.executeSimulation(
|
||||||
global.g_reducedPatternSimulationJob[simulationScenarioIndex],
|
global.g_reducedPatternSimulationJob[simulationScenarioIndex],
|
||||||
|
|
@ -296,8 +295,7 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
||||||
std::ofstream out(filename, std::ios_base::app);
|
std::ofstream out(filename, std::ios_base::app);
|
||||||
auto pMesh =
|
auto pMesh =
|
||||||
global
|
global
|
||||||
.g_reducedPatternSimulationJob[global
|
.g_reducedPatternSimulationJob[global.simulationScenarioIndices[0]]
|
||||||
.simulationScenarioIndices[0]]
|
|
||||||
->pMesh;
|
->pMesh;
|
||||||
|
|
||||||
for (size_t parameterIndex = 0; parameterIndex < n; parameterIndex++) {
|
for (size_t parameterIndex = 0; parameterIndex < n; parameterIndex++) {
|
||||||
|
|
@ -321,7 +319,7 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
||||||
global.minX.assign(x, x + n);
|
global.minX.assign(x, x + n);
|
||||||
}
|
}
|
||||||
global.numberOfFunctionCalls++;
|
global.numberOfFunctionCalls++;
|
||||||
//if (++global.numberOfFunctionCalls % 50 == 0) {
|
// if (++global.numberOfFunctionCalls % 50 == 0) {
|
||||||
std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
std::cout << "Number of function calls:" << global.numberOfFunctionCalls
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
//}
|
//}
|
||||||
|
|
@ -497,8 +495,8 @@ ReducedModelOptimizer::ReducedModelOptimizer(
|
||||||
void ReducedModelOptimizer::initializePatterns(
|
void ReducedModelOptimizer::initializePatterns(
|
||||||
FlatPattern &fullPattern, FlatPattern &reducedPattern,
|
FlatPattern &fullPattern, FlatPattern &reducedPattern,
|
||||||
const std::unordered_set<size_t> &reducedModelExcludedEdges) {
|
const std::unordered_set<size_t> &reducedModelExcludedEdges) {
|
||||||
//fullPattern.setLabel("full_pattern_" + fullPattern.getLabel());
|
// fullPattern.setLabel("full_pattern_" + fullPattern.getLabel());
|
||||||
//reducedPattern.setLabel("reduced_pattern_" + reducedPattern.getLabel());
|
// reducedPattern.setLabel("reduced_pattern_" + reducedPattern.getLabel());
|
||||||
assert(fullPattern.VN() == reducedPattern.VN() &&
|
assert(fullPattern.VN() == reducedPattern.VN() &&
|
||||||
fullPattern.EN() >= reducedPattern.EN());
|
fullPattern.EN() >= reducedPattern.EN());
|
||||||
polyscope::removeAllStructures();
|
polyscope::removeAllStructures();
|
||||||
|
|
@ -540,8 +538,8 @@ void ReducedModelOptimizer::initializeOptimizationParameters(
|
||||||
const std::shared_ptr<SimulationMesh> &mesh) {
|
const std::shared_ptr<SimulationMesh> &mesh) {
|
||||||
auto &global = tls[omp_get_thread_num()];
|
auto &global = tls[omp_get_thread_num()];
|
||||||
global.numberOfOptimizationParameters = 3;
|
global.numberOfOptimizationParameters = 3;
|
||||||
global.g_initialParameters.resize(global.optimizeInnerHexagonSize
|
global.g_initialParameters.resize(
|
||||||
? ++global.numberOfOptimizationParameters
|
global.optimizeInnerHexagonSize ? ++global.numberOfOptimizationParameters
|
||||||
: global.numberOfOptimizationParameters);
|
: global.numberOfOptimizationParameters);
|
||||||
// Save save the beam stiffnesses
|
// Save save the beam stiffnesses
|
||||||
// for (size_t ei = 0; ei < pReducedModelElementalMesh->EN(); ei++) {
|
// for (size_t ei = 0; ei < pReducedModelElementalMesh->EN(); ei++) {
|
||||||
|
|
@ -560,7 +558,7 @@ void ReducedModelOptimizer::initializeOptimizationParameters(
|
||||||
global.g_initialParameters(1) = initialRatio;
|
global.g_initialParameters(1) = initialRatio;
|
||||||
global.g_initialParameters(2) = mesh->elements[0].material.youngsModulus;
|
global.g_initialParameters(2) = mesh->elements[0].material.youngsModulus;
|
||||||
if (global.optimizeInnerHexagonSize) {
|
if (global.optimizeInnerHexagonSize) {
|
||||||
global.g_initialParameters(3) =global.g_innerHexagonInitialPos;
|
global.g_initialParameters(3) = global.g_innerHexagonInitialPos;
|
||||||
}
|
}
|
||||||
// g_initialParameters =
|
// g_initialParameters =
|
||||||
// m_pReducedPatternSimulationMesh->elements[0].properties.E;
|
// m_pReducedPatternSimulationMesh->elements[0].properties.E;
|
||||||
|
|
@ -648,9 +646,9 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
||||||
// "conditions is not recommended.");
|
// "conditions is not recommended.");
|
||||||
// Set initial guess of solution
|
// Set initial guess of solution
|
||||||
|
|
||||||
//const size_t initialGuess = 1;
|
// const size_t initialGuess = 1;
|
||||||
//std::vector<double> x(n, initialGuess);
|
// std::vector<double> x(n, initialGuess);
|
||||||
//if (global.optimizeInnerHexagonSize) {
|
// if (global.optimizeInnerHexagonSize) {
|
||||||
// x[n - 1] = global.g_innerHexagonInitialPos;
|
// x[n - 1] = global.g_innerHexagonInitialPos;
|
||||||
//}
|
//}
|
||||||
/*if (!initialGuess.empty()) {
|
/*if (!initialGuess.empty()) {
|
||||||
|
|
@ -690,12 +688,11 @@ ReducedModelOptimizer::Results ReducedModelOptimizer::runOptimization(
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
dlib::function_evaluation result;
|
dlib::function_evaluation result;
|
||||||
if (global.optimizeInnerHexagonSize) {
|
if (global.optimizeInnerHexagonSize) {
|
||||||
double (*objF)(double, double, double,double) = &objective;
|
double (*objF)(double, double, double, double) = &objective;
|
||||||
result = dlib::find_min_global(
|
result = dlib::find_min_global(
|
||||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||||
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
std::chrono::hours(24 * 365 * 290), settings.solutionAccuracy);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
double (*objF)(double, double, double) = &objective;
|
double (*objF)(double, double, double) = &objective;
|
||||||
result = dlib::find_min_global(
|
result = dlib::find_min_global(
|
||||||
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
objF, xMin, xMax, dlib::max_function_calls(settings.maxSimulations),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue