Added the size of the inner hexagon of the CW and CCW reduced models as an optimization parameter.
This commit is contained in:
parent
81ac6c20b8
commit
ea23a75ca8
18
src/main.cpp
18
src/main.cpp
|
|
@ -49,16 +49,19 @@ int main(int argc, char *argv[]) {
|
||||||
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
FlatPattern singleBarReducedModel(numberOfNodesPerSlot,
|
||||||
singleBarReducedModelEdges);
|
singleBarReducedModelEdges);
|
||||||
singleBarReducedModel.setLabel("Single bar reduced model");
|
singleBarReducedModel.setLabel("Single bar reduced model");
|
||||||
|
singleBarReducedModel.scale(0.03);
|
||||||
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
|
||||||
vcg::Point2i(3, 5)};
|
|
||||||
FlatPattern CWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
|
||||||
CWReducedModel.setLabel("CW reduced model");
|
|
||||||
|
|
||||||
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
std::vector<vcg::Point2i> CWreducedModelEdges{vcg::Point2i(1, 5),
|
||||||
vcg::Point2i(3, 1)};
|
vcg::Point2i(3, 1)};
|
||||||
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
FlatPattern CWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
||||||
|
CWReducedModel.setLabel("CW reduced model");
|
||||||
|
CWReducedModel.scale(0.03);
|
||||||
|
|
||||||
|
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
||||||
|
vcg::Point2i(3, 5)};
|
||||||
|
FlatPattern CCWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
||||||
CCWReducedModel.setLabel("CCW reduced model");
|
CCWReducedModel.setLabel("CCW reduced model");
|
||||||
|
CCWReducedModel.scale(0.03);
|
||||||
|
|
||||||
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
||||||
&CWReducedModel, &CCWReducedModel};
|
&CWReducedModel, &CCWReducedModel};
|
||||||
|
|
@ -101,6 +104,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
FlatPattern pattern(filepathString);
|
FlatPattern pattern(filepathString);
|
||||||
pattern.setLabel(filepath.stem().string());
|
pattern.setLabel(filepath.stem().string());
|
||||||
|
pattern.scale(0.03);
|
||||||
// for (int reducedPatternIndex = 0;
|
// for (int reducedPatternIndex = 0;
|
||||||
// reducedPatternIndex < reducedModels.size();
|
// reducedPatternIndex < reducedModels.size();
|
||||||
// reducedPatternIndex++) {
|
// reducedPatternIndex++) {
|
||||||
|
|
@ -115,7 +119,7 @@ int main(int argc, char *argv[]) {
|
||||||
// optimizationExcludedEi.insert(0);
|
// optimizationExcludedEi.insert(0);
|
||||||
// }
|
// }
|
||||||
std::cout << "Full pattern:" << filepathString << std::endl;
|
std::cout << "Full pattern:" << filepathString << std::endl;
|
||||||
optimizer.initializePatterns(*reducedModels[2], *reducedModels[0],
|
optimizer.initializePatterns(pattern, *reducedModels[1],
|
||||||
optimizationExcludedEi);
|
optimizationExcludedEi);
|
||||||
optimizer.optimize();
|
optimizer.optimize();
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ std::unordered_set<size_t> g_reducedPatternExludedEdges;
|
||||||
// double g_initialParameters;
|
// double g_initialParameters;
|
||||||
Eigen::VectorXd g_initialParameters;
|
Eigen::VectorXd g_initialParameters;
|
||||||
ReducedModelOptimizer::SimulationScenario g_chosenSimulationScenarioName;
|
ReducedModelOptimizer::SimulationScenario g_chosenSimulationScenarioName;
|
||||||
|
std::vector<VectorType> g_innerHexagonVectors{6, VectorType(0, 0, 0)};
|
||||||
|
double g_innerHexagonInitialPos = 0;
|
||||||
|
|
||||||
// struct OptimizationCallback {
|
// struct OptimizationCallback {
|
||||||
// double operator()(const size_t &iterations, const Eigen::VectorXd &x,
|
// double operator()(const size_t &iterations, const Eigen::VectorXd &x,
|
||||||
|
|
@ -144,6 +146,20 @@ void updateMesh(long n, const double *x) {
|
||||||
e.secondBendingConstFactor =
|
e.secondBendingConstFactor =
|
||||||
2 * e.properties.E * e.properties.I3 / e.initialLength;
|
2 * e.properties.E * e.properties.I3 / e.initialLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (n == 5) {
|
||||||
|
assert(pReducedPatternSimulationMesh->EN() == 12);
|
||||||
|
for (VertexIndex vi = 0; vi < pReducedPatternSimulationMesh->VN();
|
||||||
|
vi += 2) {
|
||||||
|
pReducedPatternSimulationMesh->vert[vi].P() =
|
||||||
|
g_innerHexagonVectors[vi / 2] * x[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
pReducedPatternSimulationMesh->updateEigenEdgeAndVertices();
|
||||||
|
pReducedPatternSimulationMesh->updateInitialPositions();
|
||||||
|
// pReducedPatternSimulationMesh->registerForDrawing("Optimized
|
||||||
|
// hexagon"); polyscope::show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double ReducedModelOptimizer::objectiveAllScenarios(long n, const double *x) {
|
double ReducedModelOptimizer::objectiveAllScenarios(long n, const double *x) {
|
||||||
|
|
@ -359,11 +375,31 @@ void ReducedModelOptimizer::initializePatterns(
|
||||||
FlatPattern copyReducedPattern;
|
FlatPattern copyReducedPattern;
|
||||||
copyFullPattern.copy(fullPattern);
|
copyFullPattern.copy(fullPattern);
|
||||||
copyReducedPattern.copy(reducedPattern);
|
copyReducedPattern.copy(reducedPattern);
|
||||||
|
if (copyReducedPattern.EN() == 2) {
|
||||||
|
const double h = copyReducedPattern.getBaseTriangleHeight();
|
||||||
|
double baseTriangle_bottomEdgeSize = 2 * h / tan(vcg::math::ToRad(60.0));
|
||||||
|
VectorType baseTriangle_leftBottomNode(-baseTriangle_bottomEdgeSize / 2, -h,
|
||||||
|
0);
|
||||||
|
|
||||||
|
const int fanSize = 6;
|
||||||
|
const CoordType rotationAxis(0, 0, 1);
|
||||||
|
for (int rotationCounter = 0; rotationCounter < fanSize;
|
||||||
|
rotationCounter++) {
|
||||||
|
VectorType rotatedVector =
|
||||||
|
vcg::RotationMatrix(rotationAxis,
|
||||||
|
vcg::math::ToRad(rotationCounter * 60.0)) *
|
||||||
|
baseTriangle_leftBottomNode;
|
||||||
|
g_innerHexagonVectors[rotationCounter] = rotatedVector;
|
||||||
|
}
|
||||||
|
}
|
||||||
computeMaps(copyFullPattern, copyReducedPattern, reducedModelExcludedEdges);
|
computeMaps(copyFullPattern, copyReducedPattern, reducedModelExcludedEdges);
|
||||||
|
const double innerHexagonInitialPos_x =
|
||||||
|
copyReducedPattern.vert[0].cP()[0] / g_innerHexagonVectors[0][0];
|
||||||
|
const double innerHexagonInitialPos_y =
|
||||||
|
copyReducedPattern.vert[0].cP()[1] / g_innerHexagonVectors[0][1];
|
||||||
|
g_innerHexagonInitialPos = innerHexagonInitialPos_x;
|
||||||
createSimulationMeshes(copyFullPattern, copyReducedPattern);
|
createSimulationMeshes(copyFullPattern, copyReducedPattern);
|
||||||
initializeStiffnesses();
|
initializeStiffnesses();
|
||||||
copyFullPattern.registerForDrawing();
|
|
||||||
polyscope::show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReducedModelOptimizer::initializeStiffnesses() {
|
void ReducedModelOptimizer::initializeStiffnesses() {
|
||||||
|
|
@ -463,8 +499,7 @@ Eigen::VectorXd ReducedModelOptimizer::runOptimization(
|
||||||
|
|
||||||
gObjectiveValueHistory.clear();
|
gObjectiveValueHistory.clear();
|
||||||
|
|
||||||
// const size_t n = m_pReducedPatternSimulationMesh->EN();
|
const size_t n = m_pReducedPatternSimulationMesh->EN() == 12 ? 5 : 4;
|
||||||
const size_t n = 4;
|
|
||||||
const size_t npt = 2 * n;
|
const size_t npt = 2 * n;
|
||||||
// ((n + 2) + ((n + 1) * (n + 2) / 2)) / 2;
|
// ((n + 2) + ((n + 1) * (n + 2) / 2)) / 2;
|
||||||
assert(npt <= (n + 1) * (n + 2) / 2 && npt >= n + 2);
|
assert(npt <= (n + 1) * (n + 2) / 2 && npt >= n + 2);
|
||||||
|
|
@ -473,6 +508,7 @@ Eigen::VectorXd ReducedModelOptimizer::runOptimization(
|
||||||
// Set initial guess of solution
|
// Set initial guess of solution
|
||||||
|
|
||||||
std::vector<double> x(n, 2);
|
std::vector<double> x(n, 2);
|
||||||
|
x[4] = g_innerHexagonInitialPos;
|
||||||
if (!initialGuess.empty()) {
|
if (!initialGuess.empty()) {
|
||||||
x = initialGuess;
|
x = initialGuess;
|
||||||
} // {0.10000000000000 001, 2, 1.9999999971613847, 6.9560343643347764};
|
} // {0.10000000000000 001, 2, 1.9999999971613847, 6.9560343643347764};
|
||||||
|
|
@ -487,10 +523,15 @@ Eigen::VectorXd ReducedModelOptimizer::runOptimization(
|
||||||
// }));
|
// }));
|
||||||
std::vector<double> xLow(x.size(), xMin);
|
std::vector<double> xLow(x.size(), xMin);
|
||||||
std::vector<double> xUpper(x.size(), xMax);
|
std::vector<double> xUpper(x.size(), xMax);
|
||||||
|
if (n == 5) {
|
||||||
|
xLow[4] = 0.1;
|
||||||
|
xUpper[4] = 1;
|
||||||
|
}
|
||||||
const double maxX = *std::max_element(
|
const double maxX = *std::max_element(
|
||||||
x.begin(), x.end(),
|
x.begin(), x.end(),
|
||||||
[](const double &a, const double &b) { return abs(a) < abs(b); });
|
[](const double &a, const double &b) { return abs(a) < abs(b); });
|
||||||
const double rhobeg = std::min(0.95, 0.2 * maxX);
|
// const double rhobeg = std::min(0.95, 0.2 * maxX);
|
||||||
|
const double rhobeg = 0.01;
|
||||||
// const double rhobeg = 10;
|
// const double rhobeg = 10;
|
||||||
const double rhoend = rhobeg * 1e-6;
|
const double rhoend = rhobeg * 1e-6;
|
||||||
const size_t wSize = (npt + 5) * (npt + n) + 3 * n * (n + 5) / 2;
|
const size_t wSize = (npt + 5) * (npt + n) + 3 * n * (n + 5) / 2;
|
||||||
|
|
@ -672,7 +713,7 @@ void ReducedModelOptimizer::optimize(const int &simulationScenario) {
|
||||||
createScenarios(m_pFullModelSimulationMesh);
|
createScenarios(m_pFullModelSimulationMesh);
|
||||||
g_optimalReducedModelDisplacements.resize(6);
|
g_optimalReducedModelDisplacements.resize(6);
|
||||||
g_reducedPatternSimulationJob.resize(6);
|
g_reducedPatternSimulationJob.resize(6);
|
||||||
polyscope::removeAllStructures();
|
// polyscope::removeAllStructures();
|
||||||
|
|
||||||
for (int simulationScenarioIndex = SimulationScenario::Axial;
|
for (int simulationScenarioIndex = SimulationScenario::Axial;
|
||||||
simulationScenarioIndex !=
|
simulationScenarioIndex !=
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue