Updated the base scenario max displacements
This commit is contained in:
parent
ace90996bb
commit
1e384c14a7
32
src/main.cpp
32
src/main.cpp
|
|
@ -24,18 +24,10 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
|
||||
// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)");
|
||||
// optResults.load("/home/iason/Coding/Projects/Approximating shapes with flat "
|
||||
// "patterns/ReducedModelOptimization/Results/OptimizationResults/"
|
||||
// "objectiveFunction/ConvergedJobs/testSet/7#12");
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
|
||||
// "singlePattern_dlib_23_12/12@single_reduced(100000_1.20)");
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
|
||||
// "singlePattern_ensmallen_AllVars_optParameters/7#12");
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/dlib_firstSubmission/"
|
||||
// "ConvergedJobs/72@single_reduced(100000_1.20)");
|
||||
// optResults.load("/home/iason/Desktop/selectionOfPatterns_0.2To1.6/selectionOfPatterns/1.2/"
|
||||
// "ConvergedJobs/12@single_reduced(100000_1.20)");
|
||||
// ReducedModelEvaluator::evaluateReducedModel(optResults);
|
||||
// return 0;
|
||||
#endif
|
||||
if (argc < 3) {
|
||||
std::cerr << "Wrong number of input parameters. Expects at least 4 input parameters."
|
||||
|
|
@ -43,8 +35,8 @@ int main(int argc, char *argv[])
|
|||
"1)full pattern file path\n"
|
||||
"2)reduced pattern file path\n"
|
||||
"3)Optimization results directory path\n"
|
||||
"4)[optional]Optimization settings json file path\n"
|
||||
"5)[optional]Intermediate results directory path\n"
|
||||
"4)[optional]Intermediate results directory path\n"
|
||||
"5)[optional]Optimization settings json file path\n"
|
||||
"Exiting.."
|
||||
<< std::endl;
|
||||
std::cerr << "Input arguments are:" << std::endl;
|
||||
|
|
@ -66,8 +58,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Set the optization settings
|
||||
ReducedModelOptimization::Settings settings_optimization;
|
||||
if (argc > 3) {
|
||||
const std::filesystem::path optimizationSettingsFilePath = argv[4];
|
||||
if (argc > 5) {
|
||||
const std::filesystem::path optimizationSettingsFilePath = argv[5];
|
||||
if (!std::filesystem::exists(optimizationSettingsFilePath)) {
|
||||
std::cerr << "Input optimization settings file does not exist:"
|
||||
<< optimizationSettingsFilePath << std::endl;
|
||||
|
|
@ -120,9 +112,9 @@ int main(int argc, char *argv[])
|
|||
const std::vector<size_t> numberOfNodesPerSlot{1, 0, 0, 2, 1, 2, 1};
|
||||
assert(interfaceNodeIndex == numberOfNodesPerSlot[0] + numberOfNodesPerSlot[3]);
|
||||
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||
const bool input_intermediateResultsDirectoryDefined = argc == 6;
|
||||
const bool input_intermediateResultsDirectoryDefined = argc == 5;
|
||||
if (input_intermediateResultsDirectoryDefined) {
|
||||
optimizer.setIntermediateResultsDirectoryPath(std::filesystem::path(argv[5]));
|
||||
optimizer.setIntermediateResultsDirectoryPath(std::filesystem::path(argv[4]));
|
||||
}
|
||||
optimizer.initializePatterns(fullPattern,
|
||||
reducedPattern,
|
||||
|
|
@ -161,7 +153,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
ReducedModelEvaluator::evaluateReducedModel(optimizationResults);
|
||||
|
||||
std::vector<std::string> scenarioLabels(
|
||||
optimizationResults.objectiveValue.perSimulationScenario_total.size());
|
||||
const double colorAxial = 1;
|
||||
|
|
@ -211,11 +202,8 @@ int main(int argc, char *argv[])
|
|||
.append("perScenarioObjectiveValues.png"));
|
||||
// optimizationResults.saveMeshFiles();
|
||||
std::cout << "Saved results to:" << resultsOutputDir << std::endl;
|
||||
// optimizationResults.draw();
|
||||
optimizationResults.draw();
|
||||
|
||||
// ReducedModelOptimization::Results optResults;
|
||||
// optResults.load("/home/iason/Desktop/dlib_ensmallen_comparison/TestSets/"
|
||||
// "singlePattern_dlib_firstSubmission/12@single_reduced(100000_1.20)");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,27 +140,27 @@ double ReducedModelOptimizer::computeError(
|
|||
const double &scenarioWeight,
|
||||
const Settings::ObjectiveWeights &objectiveWeights)
|
||||
{
|
||||
const double translationalError
|
||||
= computeDisplacementError(simulationResults_fullPattern.displacements,
|
||||
simulationResults_reducedPattern.displacements,
|
||||
reducedToFullInterfaceViMap,
|
||||
normalizationFactor_translationalDisplacement);
|
||||
// const double translationalError
|
||||
// = computeRawTranslationalError(simulationResults_fullPattern.displacements,
|
||||
// simulationResults_reducedPattern.displacements,
|
||||
// reducedToFullInterfaceViMap);
|
||||
// = computeDisplacementError(simulationResults_fullPattern.displacements,
|
||||
// simulationResults_reducedPattern.displacements,
|
||||
// reducedToFullInterfaceViMap,
|
||||
// normalizationFactor_translationalDisplacement);
|
||||
const double translationalError
|
||||
= computeRawTranslationalError(simulationResults_fullPattern.displacements,
|
||||
simulationResults_reducedPattern.displacements,
|
||||
reducedToFullInterfaceViMap);
|
||||
|
||||
// std::cout << "normalization factor:" << normalizationFactor_rotationalDisplacement << std::endl;
|
||||
// std::cout << "trans error:" << translationalError << std::endl;
|
||||
const double rotationalError
|
||||
= computeRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
reducedToFullInterfaceViMap,
|
||||
normalizationFactor_rotationalDisplacement);
|
||||
// const double rotationalError
|
||||
// = computeRawRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
// simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
// reducedToFullInterfaceViMap);
|
||||
// = computeRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
// simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
// reducedToFullInterfaceViMap,
|
||||
// normalizationFactor_rotationalDisplacement);
|
||||
const double rotationalError
|
||||
= computeRawRotationalError(simulationResults_fullPattern.rotationalDisplacementQuaternion,
|
||||
simulationResults_reducedPattern.rotationalDisplacementQuaternion,
|
||||
reducedToFullInterfaceViMap);
|
||||
// std::cout << "rot error:" << rotationalError<< std::endl;
|
||||
const double simulationError = objectiveWeights.translational * translationalError
|
||||
+ objectiveWeights.rotational * rotationalError;
|
||||
|
|
@ -186,16 +186,16 @@ struct EnsmallenOptimizationObjective
|
|||
//#ifdef POLYSCOPE_DEFINED
|
||||
// std::cout << "Out of range" << std::endl;
|
||||
//#endif
|
||||
// return std::numeric_limits<double>::max();
|
||||
// return 1000;
|
||||
x[xi] = global.xMax[xi];
|
||||
return std::numeric_limits<double>::max();
|
||||
// return 1e10;
|
||||
// x[xi] = global.xMax[xi];
|
||||
} else if (x[xi] < global.xMin[xi]) {
|
||||
//#ifdef POLYSCOPE_DEFINED
|
||||
// std::cout << "Out of range" << std::endl;
|
||||
//#endif
|
||||
// return std::numeric_limits<double>::max();
|
||||
// return 1000;
|
||||
x[xi] = global.xMin[xi];
|
||||
return std::numeric_limits<double>::max();
|
||||
// return 1e10;
|
||||
// x[xi] = global.xMin[xi];
|
||||
}
|
||||
}
|
||||
return ReducedModelOptimizer::objective(x);
|
||||
|
|
@ -247,7 +247,7 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
// FormFinder simulator;
|
||||
|
||||
std::for_each(
|
||||
// std::execution::par_unseq,
|
||||
std::execution::par_unseq,
|
||||
global.simulationScenarioIndices.begin(),
|
||||
global.simulationScenarioIndices.end(),
|
||||
[&](const int &simulationScenarioIndex) {
|
||||
|
|
@ -267,10 +267,10 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
std::cout << "Failed simulation" << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
const double simulationScenarioError_PE = std::abs(
|
||||
(reducedModelResults.internalPotentialEnergy
|
||||
- global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy)
|
||||
/ global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy);
|
||||
// const double simulationScenarioError_PE = std::abs(
|
||||
// (reducedModelResults.internalPotentialEnergy
|
||||
// - global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy)
|
||||
// / global.fullPatternResults[simulationScenarioIndex].internalPotentialEnergy);
|
||||
// else {
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#ifdef USE_SCENARIO_WEIGHTS
|
||||
|
|
@ -291,7 +291,7 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
global.objectiveWeights[simulationScenarioIndex]);
|
||||
|
||||
simulationErrorsPerScenario[simulationScenarioIndex]
|
||||
= simulationScenarioError_displacements + simulationScenarioError_PE;
|
||||
= simulationScenarioError_displacements /*+ simulationScenarioError_PE*/;
|
||||
// }
|
||||
// #ifdef POLYSCOPE_DEFINED
|
||||
// reducedJob->pMesh->registerForDrawing(Colors::reducedInitial);
|
||||
|
|
@ -309,9 +309,9 @@ double ReducedModelOptimizer::objective(const std::vector<double> &x)
|
|||
// double totalError = std::accumulate(simulationErrorsPerScenario.begin(),
|
||||
// simulationErrorsPerScenario.end(),
|
||||
// 0);
|
||||
double totalError = std::reduce(std::execution::par_unseq,
|
||||
simulationErrorsPerScenario.begin(),
|
||||
simulationErrorsPerScenario.end());
|
||||
const double totalError = std::reduce(std::execution::par_unseq,
|
||||
simulationErrorsPerScenario.begin(),
|
||||
simulationErrorsPerScenario.end());
|
||||
// std::cout << totalError << std::endl;
|
||||
// global.objectiveValueHistory.push_back(totalError);
|
||||
// global.plotColors.push_back(10);
|
||||
|
|
@ -975,7 +975,7 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
|||
.append(m_pFullPatternSimulationMesh->getLabel() + ".json"));
|
||||
const bool fullPatternScenarioMagnitudesExist = std::filesystem::exists(
|
||||
patternMaxForceMagnitudesFilePath);
|
||||
constexpr bool recomputeMagnitudes = false;
|
||||
constexpr bool recomputeMagnitudes = true;
|
||||
if (fullPatternScenarioMagnitudesExist && !recomputeMagnitudes) {
|
||||
nlohmann::json json;
|
||||
std::ifstream ifs(patternMaxForceMagnitudesFilePath.string());
|
||||
|
|
@ -996,6 +996,11 @@ ReducedModelOptimizer::getFullPatternMaxSimulationForces(
|
|||
std::ofstream jsonFile(patternMaxForceMagnitudesFilePath.string());
|
||||
jsonFile << json;
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
std::cout << "Saved base scenario max magnitudes to:" << patternMaxForceMagnitudesFilePath
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
//#endif
|
||||
assert(fullPatternSimulationScenarioMaxMagnitudes.size()
|
||||
== desiredBaseSimulationScenarioIndices.size());
|
||||
|
|
@ -1094,12 +1099,12 @@ void ReducedModelOptimizer::runOptimization(const Settings &settings,
|
|||
// ens::CNE optimizer;
|
||||
// ens::DE optimizer;
|
||||
// ens::SPSA optimizer;
|
||||
// arma::mat xMin_arma(global.xMin);
|
||||
// arma::mat xMax_arma(global.xMax);
|
||||
arma::mat xMin_arma(global.xMin);
|
||||
arma::mat xMax_arma(global.xMax);
|
||||
// ens::LBestPSO optimizer(64, xMin_arma, xMax_arma, 1000);
|
||||
ens::LBestPSO optimizer(64,
|
||||
1,
|
||||
1,
|
||||
ens::LBestPSO optimizer(200,
|
||||
xMin_arma,
|
||||
xMax_arma,
|
||||
settings.numberOfFunctionCalls,
|
||||
500,
|
||||
settings.solverAccuracy,
|
||||
|
|
@ -1322,14 +1327,14 @@ void ReducedModelOptimizer::constructDomeSimulationScenario(
|
|||
= Eigen::Vector3d(-interfaceVector[0],
|
||||
-interfaceVector[1],
|
||||
0)
|
||||
* 0.005
|
||||
* 0.001
|
||||
* std::abs(
|
||||
forceMagnitude); //NOTE:Should the forced displacement change relatively to the magnitude?
|
||||
// * std::abs(forceMagnitude / maxForceMagnitude_dome);
|
||||
job.nodalForcedDisplacements[viPair.second] = Eigen::Vector3d(interfaceVector[0],
|
||||
interfaceVector[1],
|
||||
0)
|
||||
* 0.005 * std::abs(forceMagnitude);
|
||||
* 0.001 * std::abs(forceMagnitude);
|
||||
// * std::abs(forceMagnitude / maxForceMagnitude_dome);
|
||||
// CoordType v = (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||
// ^ CoordType(0, 0, -1).Normalize();
|
||||
|
|
@ -1560,19 +1565,22 @@ double ReducedModelOptimizer::computeFullPatternMaxSimulationForce(
|
|||
global.desiredMaxDisplacementValue = 0.03 * baseTriangleHeight;
|
||||
break;
|
||||
case Shear:
|
||||
global.desiredMaxDisplacementValue = 0.03 * baseTriangleHeight;
|
||||
global.desiredMaxDisplacementValue = 0.04 * baseTriangleHeight;
|
||||
break;
|
||||
case Bending:
|
||||
global.interfaceViForComputingScenarioError = global.fullPatternInterfaceViPairs[0].first;
|
||||
global.desiredMaxDisplacementValue = 0.05 * baseTriangleHeight;
|
||||
break;
|
||||
case Dome:
|
||||
global.desiredMaxRotationAngle = vcg::math::ToRad(35.0);
|
||||
global.desiredMaxRotationAngle = vcg::math::ToRad(20.0);
|
||||
objectiveFunction = &fullPatternMaxSimulationForceRotationalObjective;
|
||||
forceMagnitudeEpsilon *= 1e-2;
|
||||
objectiveEpsilon = vcg::math::ToRad(3.0);
|
||||
objectiveEpsilon = vcg::math::ToRad(1.0);
|
||||
forceMagnitude = 0.6;
|
||||
break;
|
||||
case Saddle:
|
||||
global.interfaceViForComputingScenarioError = global.fullPatternInterfaceViPairs[0].first;
|
||||
global.desiredMaxDisplacementValue = 0.05 * baseTriangleHeight;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1907,6 +1915,7 @@ void ReducedModelOptimizer::optimize(
|
|||
for (int simulationScenarioIndex : global.simulationScenarioIndices) {
|
||||
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob
|
||||
= global.fullPatternSimulationJobs[simulationScenarioIndex];
|
||||
// std::cout << pFullPatternSimulationJob->getLabel() << std::endl;
|
||||
|
||||
std::filesystem::path jobResultsDirectoryPath(
|
||||
std::filesystem::path(intermediateResultsDirectoryPath)
|
||||
|
|
@ -1914,7 +1923,7 @@ void ReducedModelOptimizer::optimize(
|
|||
.append(m_pFullPatternSimulationMesh->getLabel())
|
||||
.append(pFullPatternSimulationJob->getLabel()));
|
||||
// .append(pFullPatternSimulationJob->getLabel() + ".json")
|
||||
constexpr bool recomputeFullPatternResults = true;
|
||||
constexpr bool recomputeFullPatternResults = false;
|
||||
SimulationResults fullPatternResults;
|
||||
if (!recomputeFullPatternResults && std::filesystem::exists(jobResultsDirectoryPath)) {
|
||||
fullPatternResults.load(std::filesystem::path(jobResultsDirectoryPath).append("Results"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue