Refactoring
This commit is contained in:
parent
06e95b0e02
commit
f598d6a46e
|
@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 2.8)
|
||||||
project(ReducedModelOptimization)
|
project(ReducedModelOptimization)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER}")
|
message(STATUS "The compiler ${CMAKE_CXX_COMPILER}")
|
||||||
|
|
||||||
|
SET(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
|
||||||
#Add the project cmake scripts to the module path
|
#Add the project cmake scripts to the module path
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
@ -42,7 +44,7 @@ download_project(PROJ POLYSCOPE
|
||||||
add_subdirectory(${POLYSCOPE_SOURCE_DIR} ${POLYSCOPE_BINARY_DIR})
|
add_subdirectory(${POLYSCOPE_SOURCE_DIR} ${POLYSCOPE_BINARY_DIR})
|
||||||
add_compile_definitions(POLYSCOPE_DEFINED)
|
add_compile_definitions(POLYSCOPE_DEFINED)
|
||||||
endif()
|
endif()
|
||||||
|
set(MYSOURCES_STATIC_LINK NOT ${USE_POLYSCOPE})
|
||||||
|
|
||||||
set(MYSOURCES_SOURCE_DIR "/home/iason/Coding/Libraries/MySources")
|
set(MYSOURCES_SOURCE_DIR "/home/iason/Coding/Libraries/MySources")
|
||||||
if (EXISTS ${MYSOURCES_SOURCE_DIR})
|
if (EXISTS ${MYSOURCES_SOURCE_DIR})
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -48,20 +48,20 @@ int main(int argc, char *argv[]) {
|
||||||
ReducedPatternOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0};
|
ReducedPatternOptimization::xRange innerHexagonAngle{"HexAngle", -30.0, 30.0};
|
||||||
ReducedPatternOptimization::Settings settings_optimization;
|
ReducedPatternOptimization::Settings settings_optimization;
|
||||||
settings_optimization.xRanges
|
settings_optimization.xRanges
|
||||||
= {beamE, beamA, beamI2, beamI3, beamJ, innerHexagonSize, innerHexagonAngle};
|
= {/*beamE,*/ beamA, beamI2, beamI3, beamJ, innerHexagonSize, innerHexagonAngle};
|
||||||
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
const bool input_numberOfFunctionCallsDefined = argc >= 4;
|
||||||
settings_optimization.numberOfFunctionCalls = input_numberOfFunctionCallsDefined
|
settings_optimization.numberOfFunctionCalls = input_numberOfFunctionCallsDefined
|
||||||
? std::atoi(argv[3])
|
? std::atoi(argv[3])
|
||||||
: 100;
|
: 100;
|
||||||
settings_optimization.normalizationStrategy
|
settings_optimization.normalizationStrategy
|
||||||
= ReducedPatternOptimization::Settings::NormalizationStrategy::Epsilon;
|
= ReducedPatternOptimization::Settings::NormalizationStrategy::Epsilon;
|
||||||
|
settings_optimization.splitGeometryMaterialOptimization = false;
|
||||||
settings_optimization.translationNormalizationParameter = 1e-3;
|
settings_optimization.translationNormalizationParameter = 1e-3;
|
||||||
settings_optimization.rotationNormalizationParameter = vcg::math::ToRad(3.0);
|
settings_optimization.rotationNormalizationParameter = vcg::math::ToRad(3.0);
|
||||||
// settings_optimization.translationNormalizationParameter = 1e-15;
|
// settings_optimization.translationNormalizationParameter = 1e-15;
|
||||||
// settings_optimization.rotationNormalizationParameter = vcg::math::ToRad(1e-15);
|
// settings_optimization.rotationNormalizationParameter = vcg::math::ToRad(1e-15);
|
||||||
// settings_optimization.solverAccuracy = 1e-3;
|
// settings_optimization.solverAccuracy = 1e-3;
|
||||||
settings_optimization.solverAccuracy = 1e-3;
|
settings_optimization.solverAccuracy = 1e-1;
|
||||||
settings_optimization.objectiveWeights.translational = std::atof(argv[4]);
|
settings_optimization.objectiveWeights.translational = std::atof(argv[4]);
|
||||||
settings_optimization.objectiveWeights.rotational = 2 - std::atof(argv[4]);
|
settings_optimization.objectiveWeights.rotational = 2 - std::atof(argv[4]);
|
||||||
|
|
||||||
|
@ -129,7 +129,6 @@ int main(int argc, char *argv[]) {
|
||||||
if (optimizationResults.wasSuccessful) {
|
if (optimizationResults.wasSuccessful) {
|
||||||
resultsOutputDir = convergedJobsDirPath.string();
|
resultsOutputDir = convergedJobsDirPath.string();
|
||||||
csvFile csv_results({}, false);
|
csvFile csv_results({}, false);
|
||||||
// csvFile csv_results(std::filesystem::path(resultsOutputDir).append("optimizationDistances.csv"), false);
|
|
||||||
csv_results << "Name";
|
csv_results << "Name";
|
||||||
optimizationResults.writeHeaderTo(csv_results);
|
optimizationResults.writeHeaderTo(csv_results);
|
||||||
settings_optimization.writeHeaderTo(csv_results);
|
settings_optimization.writeHeaderTo(csv_results);
|
||||||
|
@ -146,11 +145,6 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
// optimizationResults.saveMeshFiles();
|
// optimizationResults.saveMeshFiles();
|
||||||
std::cout << "E:"
|
|
||||||
<< optimizationResults.reducedPatternSimulationJobs[0]
|
|
||||||
->pMesh->elements[0]
|
|
||||||
.material.youngsModulus
|
|
||||||
<< std::endl;
|
|
||||||
optimizationResults.draw();
|
optimizationResults.draw();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,9 @@ struct GlobalOptimizationVariables {
|
||||||
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||||
fullPatternInterfaceViPairs;
|
fullPatternInterfaceViPairs;
|
||||||
matplot::line_handle gPlotHandle;
|
matplot::line_handle gPlotHandle;
|
||||||
std::vector<double> objectiveValueHistoryY;
|
std::vector<size_t> objectiveValueHistory_iteration;
|
||||||
std::vector<double> objectiveValueHistoryX;
|
std::vector<double> objectiveValueHistory;
|
||||||
std::vector<double> plotColors;
|
std::vector<double> plotColors;
|
||||||
size_t iterationOfMinima{0};
|
|
||||||
Eigen::VectorXd initialParameters;
|
Eigen::VectorXd initialParameters;
|
||||||
std::vector<int> simulationScenarioIndices;
|
std::vector<int> simulationScenarioIndices;
|
||||||
double minY{DBL_MAX};
|
double minY{DBL_MAX};
|
||||||
|
@ -259,7 +258,8 @@ double ReducedModelOptimizer::objective(const dlib::matrix<double, 0, 1> &x)
|
||||||
++global.numberOfFunctionCalls;
|
++global.numberOfFunctionCalls;
|
||||||
if (totalError < global.minY) {
|
if (totalError < global.minY) {
|
||||||
global.minY = totalError;
|
global.minY = totalError;
|
||||||
global.iterationOfMinima = global.numberOfFunctionCalls;
|
global.objectiveValueHistory.push_back(totalError);
|
||||||
|
global.objectiveValueHistory_iteration.push_back(global.numberOfFunctionCalls);
|
||||||
// std::cout << "New best:" << totalError << std::endl;
|
// std::cout << "New best:" << totalError << std::endl;
|
||||||
// // global.minX.assign(x.begin(), x.begin() + n);
|
// // global.minX.assign(x.begin(), x.begin() + n);
|
||||||
// std::cout.precision(17);
|
// std::cout.precision(17);
|
||||||
|
@ -961,7 +961,8 @@ void ReducedModelOptimizer::getResults(const dlib::function_evaluation &optimiza
|
||||||
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->registerForDrawing();
|
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->registerForDrawing();
|
||||||
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->setLabel(temp);
|
// global.reducedPatternSimulationJobs[simulationScenarioIndex]->pMesh->setLabel(temp);
|
||||||
}
|
}
|
||||||
results.iterationOfMinima = global.iterationOfMinima;
|
results.objectiveValueHistory = global.objectiveValueHistory;
|
||||||
|
results.objectiveValueHistory_iteration = global.objectiveValueHistory_iteration;
|
||||||
// results.draw();
|
// results.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1029,16 +1030,17 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
||||||
void ReducedModelOptimizer::runOptimization(const Settings &settings,
|
void ReducedModelOptimizer::runOptimization(const Settings &settings,
|
||||||
ReducedPatternOptimization::Results &results)
|
ReducedPatternOptimization::Results &results)
|
||||||
{
|
{
|
||||||
|
global.objectiveValueHistory.clear();
|
||||||
|
global.objectiveValueHistory_iteration.clear();
|
||||||
|
global.objectiveValueHistory.reserve(settings.numberOfFunctionCalls / 100);
|
||||||
|
global.objectiveValueHistory_iteration.reserve(settings.numberOfFunctionCalls / 100);
|
||||||
|
|
||||||
#if POLYSCOPE_DEFINED
|
#if POLYSCOPE_DEFINED
|
||||||
global.objectiveValueHistoryY.clear();
|
|
||||||
global.objectiveValueHistoryY.reserve(settings.numberOfFunctionCalls);
|
|
||||||
global.objectiveValueHistoryX.reserve(settings.numberOfFunctionCalls);
|
|
||||||
global.plotColors.reserve(settings.numberOfFunctionCalls);
|
global.plotColors.reserve(settings.numberOfFunctionCalls);
|
||||||
#endif
|
#endif
|
||||||
double (*objF)(const dlib::matrix<double, 0, 1> &) = &objective;
|
double (*objF)(const dlib::matrix<double, 0, 1> &) = &objective;
|
||||||
|
|
||||||
dlib::function_evaluation optimalResult;
|
dlib::function_evaluation optimalResult;
|
||||||
constexpr bool shouldJointlyOptimizeGeometryAndMaterial = false;
|
|
||||||
const auto hexAngleParameterIt = std::find_if(settings.xRanges.begin(),
|
const auto hexAngleParameterIt = std::find_if(settings.xRanges.begin(),
|
||||||
settings.xRanges.end(),
|
settings.xRanges.end(),
|
||||||
[](const xRange &x) {
|
[](const xRange &x) {
|
||||||
|
@ -1058,7 +1060,7 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings,
|
||||||
- numberOfGeometryOptimizationParameters;
|
- numberOfGeometryOptimizationParameters;
|
||||||
const bool hasGeometryAndMaterialParameters = hasBothGeometricalParameters
|
const bool hasGeometryAndMaterialParameters = hasBothGeometricalParameters
|
||||||
&& numberOfMaterialOptimizationParameters != 0;
|
&& numberOfMaterialOptimizationParameters != 0;
|
||||||
if (!shouldJointlyOptimizeGeometryAndMaterial && hasGeometryAndMaterialParameters) {
|
if (settings.splitGeometryMaterialOptimization && hasGeometryAndMaterialParameters) {
|
||||||
//Geometry optimization of the reduced pattern
|
//Geometry optimization of the reduced pattern
|
||||||
dlib::matrix<double, 0, 1> xGeometryMin(numberOfGeometryOptimizationParameters);
|
dlib::matrix<double, 0, 1> xGeometryMin(numberOfGeometryOptimizationParameters);
|
||||||
dlib::matrix<double, 0, 1> xGeometryMax(numberOfGeometryOptimizationParameters);
|
dlib::matrix<double, 0, 1> xGeometryMax(numberOfGeometryOptimizationParameters);
|
||||||
|
@ -1145,11 +1147,11 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings,
|
||||||
std::copy(result_dlib_geometry.x.begin(),
|
std::copy(result_dlib_geometry.x.begin(),
|
||||||
result_dlib_geometry.x.end(),
|
result_dlib_geometry.x.end(),
|
||||||
optimalResult.x.begin() + numberOfMaterialOptimizationParameters);
|
optimalResult.x.begin() + numberOfMaterialOptimizationParameters);
|
||||||
std::cout << "opt x:";
|
// std::cout << "opt x:";
|
||||||
for (const auto optx : optimalResult.x) {
|
// for (const auto optx : optimalResult.x) {
|
||||||
std::cout << optx << " ";
|
// std::cout << optx << " ";
|
||||||
}
|
// }
|
||||||
std::cout << std::endl;
|
// std::cout << std::endl;
|
||||||
function_updateReducedPattern =
|
function_updateReducedPattern =
|
||||||
[&](const dlib::matrix<double, 0, 1> &x,
|
[&](const dlib::matrix<double, 0, 1> &x,
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh) {
|
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh) {
|
||||||
|
|
Loading…
Reference in New Issue