Finalized the simulation scenarios. Left out the torsion scenario.
This commit is contained in:
parent
4d4aa346b5
commit
b0ba64d499
145
src/main.cpp
145
src/main.cpp
|
|
@ -49,56 +49,61 @@ int main(int argc, char *argv[]) {
|
||||||
singleBarReducedModelEdges);
|
singleBarReducedModelEdges);
|
||||||
singleBarReducedModel.setLabel("Single bar reduced model");
|
singleBarReducedModel.setLabel("Single bar reduced model");
|
||||||
|
|
||||||
// std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
std::vector<vcg::Point2i> CCWreducedModelEdges{vcg::Point2i(1, 5),
|
||||||
// vcg::Point2i(3, 5)};
|
vcg::Point2i(3, 5)};
|
||||||
// FlatPattern CWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
FlatPattern CWReducedModel(numberOfNodesPerSlot, CCWreducedModelEdges);
|
||||||
// CWReducedModel.setLabel("CW reduced model");
|
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 CCWReducedModel(numberOfNodesPerSlot, CWreducedModelEdges);
|
||||||
// CCWReducedModel.setLabel("CCW reduced model");
|
CCWReducedModel.setLabel("CCW reduced model");
|
||||||
|
|
||||||
// std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
std::vector<FlatPattern *> reducedModels{&singleBarReducedModel,
|
||||||
// &CWReducedModel,
|
&CWReducedModel, &CCWReducedModel};
|
||||||
// &CCWReducedModel};
|
|
||||||
|
|
||||||
// ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
ReducedModelOptimizer optimizer(numberOfNodesPerSlot);
|
||||||
// std::string fullPatternsTestSetDirectory =
|
std::string fullPatternsTestSetDirectory =
|
||||||
// "/home/iason/Models/TestSet_validPatterns";
|
"/home/iason/Models/TestSet_validPatterns";
|
||||||
// for (const auto &entry :
|
for (const auto &entry :
|
||||||
// filesystem::directory_iterator(fullPatternsTestSetDirectory)) {
|
filesystem::directory_iterator(fullPatternsTestSetDirectory)) {
|
||||||
// const auto filepath =
|
const auto filepath =
|
||||||
// std::filesystem::path("/home/iason/Models/valid_6777.ply");
|
// std::filesystem::path("/home/iason/Models/valid_6777.ply");
|
||||||
// // std::filesystem::path(
|
// std::filesystem::path(
|
||||||
// // "/home/iason/Documents/PhD/Research/Pattern_enumerator/Results/"
|
// "/home/iason/Documents/PhD/Research/Pattern_enumerator/Results/"
|
||||||
// // "1v_0v_2e_1e_1c_6fan/3/Valid/431.ply");
|
// "1v_0v_2e_1e_1c_6fan/3/Valid/222.ply");
|
||||||
// // std::filesystem::path(
|
// std::filesystem::path(
|
||||||
// // "/home/iason/Models/TestSet_validPatterns/865.ply");
|
// "/home/iason/Documents/PhD/Research/Pattern_enumerator/Results/"
|
||||||
// // entry.path();
|
// "1v_0v_2e_1e_1c_6fan/2/Valid/33.ply");
|
||||||
// const auto filepathString = filepath.string();
|
std::filesystem::path(
|
||||||
// // Use only the base triangle version
|
"/home/iason/Documents/PhD/Research/Pattern_enumerator/Results/"
|
||||||
// const std::string tiledSuffix = "_tiled.ply";
|
"1v_0v_2e_1e_1c_6fan/3/Valid/431.ply");
|
||||||
// if (filepathString.compare(filepathString.size() - tiledSuffix.size(),
|
// std::filesystem::path(
|
||||||
// tiledSuffix.size(), tiledSuffix) == 0) {
|
// "/home/iason/Models/TestSet_validPatterns/865.ply");
|
||||||
// continue;
|
entry.path();
|
||||||
// }
|
const auto filepathString = filepath.string();
|
||||||
// FlatPattern pattern(filepathString);
|
// Use only the base triangle version
|
||||||
// pattern.setLabel(filepath.stem().string());
|
const std::string tiledSuffix = "_tiled.ply";
|
||||||
// std::cout << "Testing Pattern:" << filepathString << std::endl;
|
if (filepathString.compare(filepathString.size() - tiledSuffix.size(),
|
||||||
// for (FlatPattern *pReducedModel : reducedModels) {
|
tiledSuffix.size(), tiledSuffix) == 0) {
|
||||||
// // pReducedModel = reducedModels[1];
|
continue;
|
||||||
// std::unordered_set<size_t> optimizationExcludedEi;
|
}
|
||||||
// if (pReducedModel !=
|
FlatPattern pattern(filepathString);
|
||||||
// reducedModels[0]) { // assumes that the singleBar reduced model is
|
pattern.setLabel(filepath.stem().string());
|
||||||
// // the
|
std::cout << "Testing Pattern:" << filepathString << std::endl;
|
||||||
// // first in the reducedModels vector
|
for (FlatPattern *pReducedModel : reducedModels) {
|
||||||
// optimizationExcludedEi.insert(0);
|
// pReducedModel = reducedModels[1];
|
||||||
// }
|
std::unordered_set<size_t> optimizationExcludedEi;
|
||||||
// optimizer.initialize(pattern, *pReducedModel, optimizationExcludedEi);
|
if (pReducedModel !=
|
||||||
// Eigen::VectorXd optimalParameters = optimizer.optimize();
|
reducedModels[0]) { // assumes that the singleBar reduced model is
|
||||||
// }
|
// the
|
||||||
// }
|
// first in the reducedModels vector
|
||||||
|
optimizationExcludedEi.insert(0);
|
||||||
|
}
|
||||||
|
optimizer.initialize(pattern, *pReducedModel, optimizationExcludedEi);
|
||||||
|
Eigen::VectorXd optimalParameters = optimizer.optimize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// // Full model simulation
|
// // Full model simulation
|
||||||
// std::unordered_map<VertexIndex, std::unordered_set<DoFType>>
|
// std::unordered_map<VertexIndex, std::unordered_set<DoFType>>
|
||||||
|
|
@ -166,28 +171,56 @@ int main(int argc, char *argv[]) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Beam
|
// Beam
|
||||||
|
// registerWorldAxes();
|
||||||
VCGEdgeMesh mesh;
|
VCGEdgeMesh mesh;
|
||||||
mesh.loadFromPly("/home/iason/Models/simple_beam_model_10elem_1m.ply");
|
// mesh.loadFromPly("/home/iason/Models/simple_beam_model_10elem_1m.ply");
|
||||||
|
mesh.loadFromPly("/home/iason/Coding/Projects/Approximating shapes with flat "
|
||||||
|
"patterns/RodModelOptimizationForPatterns/build/Debug/"
|
||||||
|
"Fanned_Single bar reduced model.ply");
|
||||||
|
// vcg::Matrix44d R;
|
||||||
|
// R.SetRotateDeg(45, {0, 0, 1});
|
||||||
|
// vcg::tri::UpdatePosition<VCGEdgeMesh>::Matrix(mesh, R);
|
||||||
|
// mesh.updateEigenEdgeAndVertices();
|
||||||
FormFinder formFinder;
|
FormFinder formFinder;
|
||||||
|
formFinder.runUnitTests();
|
||||||
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
||||||
fixedVertices[0] = std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
fixedVertices[1] = std::unordered_set<DoFType>{2};
|
||||||
std::unordered_map<VertexIndex, Vector6d> nodalForces{
|
fixedVertices[2] = std::unordered_set<DoFType>{2};
|
||||||
{10, Vector6d({0, 0, 0, 0.00001, 0, 0})}};
|
fixedVertices[3] = std::unordered_set<DoFType>{1, 2};
|
||||||
|
fixedVertices[4] = std::unordered_set<DoFType>{2};
|
||||||
|
fixedVertices[5] = std::unordered_set<DoFType>{2};
|
||||||
|
fixedVertices[6] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
// Forced displacements
|
// Forced displacements
|
||||||
std::unordered_map<size_t, Eigen::Vector3d> nodalForcedDisplacements;
|
std::unordered_map<size_t, Eigen::Vector3d> nodalForcedDisplacements;
|
||||||
|
// nodalForcedDisplacements[10] = Eigen::Vector3d(0, 0.1, 0.1);
|
||||||
std::unordered_map<size_t, VectorType> nodalForcedNormal;
|
std::unordered_map<size_t, VectorType> nodalForcedNormal;
|
||||||
|
|
||||||
// CoordType v = (mesh.vert[10].cP() - mesh.vert[0].cP()).Normalize();
|
CoordType v14 = (mesh.vert[4].cP() - mesh.vert[0].cP()).Normalize();
|
||||||
|
CoordType v25 = (mesh.vert[5].cP() - mesh.vert[0].cP()).Normalize();
|
||||||
|
CoordType v36 = (mesh.vert[6].cP() - mesh.vert[0].cP()).Normalize();
|
||||||
|
const double forceMagnitude = 0.4;
|
||||||
|
std::unordered_map<VertexIndex, Vector6d> nodalForces{
|
||||||
|
// {4, Vector6d({0, 0, 0, v14[0], v14[1], 0}) * forceMagnitude},
|
||||||
|
// {1, Vector6d({0, 0, 0, -v14[0], -v14[1], 0}) * forceMagnitude},
|
||||||
|
// {5, Vector6d({0, 0, 0, v25[0], v25[1], 0}) * forceMagnitude},
|
||||||
|
// {2, Vector6d({0, 0, 0, -v25[0], -v25[1], 0}) * forceMagnitude},
|
||||||
|
// {6, Vector6d({0, 0, 0, v36[0], v36[1], 0}) * forceMagnitude},
|
||||||
|
{3, Vector6d({0, 0, 0, -v36[0], -v36[1], 0}) * forceMagnitude}};
|
||||||
// nodalForcedNormal[10] = v;
|
// nodalForcedNormal[10] = v;
|
||||||
fixedVertices[10] = {0, 1, 2};
|
// nodalForcedNormal[0] = -v;
|
||||||
|
// fixedVertices[10] = {0, 1};
|
||||||
|
|
||||||
SimulationJob beamSimulationJob{std::make_shared<SimulationMesh>(mesh),
|
SimulationJob beamSimulationJob{std::make_shared<SimulationMesh>(mesh),
|
||||||
fixedVertices, nodalForces,
|
fixedVertices,
|
||||||
nodalForcedDisplacements, nodalForcedNormal};
|
nodalForces,
|
||||||
|
{},
|
||||||
|
{}};
|
||||||
beamSimulationJob.mesh->setBeamMaterial(0.3, 1);
|
beamSimulationJob.mesh->setBeamMaterial(0.3, 1);
|
||||||
beamSimulationJob.mesh->setBeamCrossSection(
|
beamSimulationJob.mesh->setBeamCrossSection(
|
||||||
RectangularBeamDimensions{0.002, 0.002});
|
RectangularBeamDimensions{0.002, 0.002});
|
||||||
// registerWorldAxes();
|
beamSimulationJob.registerForDrawing();
|
||||||
|
registerWorldAxes();
|
||||||
|
polyscope::show();
|
||||||
SimulationResults beamSimulationResults =
|
SimulationResults beamSimulationResults =
|
||||||
formFinder.executeSimulation(beamSimulationJob, true, true);
|
formFinder.executeSimulation(beamSimulationJob, true, true);
|
||||||
beamSimulationResults.simulationLabel = "Beam";
|
beamSimulationResults.simulationLabel = "Beam";
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const bool gShouldDraw = true;
|
||||||
FormFinder simulator;
|
FormFinder simulator;
|
||||||
Eigen::MatrixX3d g_optimalReducedModelDisplacements;
|
Eigen::MatrixX3d g_optimalReducedModelDisplacements;
|
||||||
SimulationJob g_reducedPatternSimulationJob;
|
SimulationJob g_reducedPatternSimulationJob;
|
||||||
std::unordered_map<ReducedModelVertexIndex, FullModelVertexIndex>
|
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||||
g_reducedToFullInterfaceViMap;
|
g_reducedToFullInterfaceViMap;
|
||||||
matplot::line_handle gPlotHandle;
|
matplot::line_handle gPlotHandle;
|
||||||
std::vector<double> gObjectiveValueHistory;
|
std::vector<double> gObjectiveValueHistory;
|
||||||
|
|
@ -145,10 +145,10 @@ double ReducedModelOptimizer::objective(long n, const double *x) {
|
||||||
error += errorVector.norm();
|
error += errorVector.norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
gObjectiveValueHistory.push_back(error);
|
// gObjectiveValueHistory.push_back(error);
|
||||||
auto xPlot = matplot::linspace(0, gObjectiveValueHistory.size(),
|
// auto xPlot = matplot::linspace(0, gObjectiveValueHistory.size(),
|
||||||
gObjectiveValueHistory.size());
|
// gObjectiveValueHistory.size());
|
||||||
gPlotHandle = matplot::scatter(xPlot, gObjectiveValueHistory);
|
// gPlotHandle = matplot::scatter(xPlot, gObjectiveValueHistory);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
@ -278,13 +278,15 @@ void ReducedModelOptimizer::computeMaps(
|
||||||
|
|
||||||
void ReducedModelOptimizer::createSimulationMeshes(FlatPattern &fullModel,
|
void ReducedModelOptimizer::createSimulationMeshes(FlatPattern &fullModel,
|
||||||
FlatPattern &reducedModel) {
|
FlatPattern &reducedModel) {
|
||||||
pReducedModelElementalMesh = std::make_shared<SimulationMesh>(reducedModel);
|
m_pReducedPatternElementalMesh =
|
||||||
pReducedModelElementalMesh->setBeamCrossSection(
|
std::make_shared<SimulationMesh>(reducedModel);
|
||||||
|
m_pReducedPatternElementalMesh->setBeamCrossSection(
|
||||||
CrossSectionType{0.002, 0.002});
|
CrossSectionType{0.002, 0.002});
|
||||||
pReducedModelElementalMesh->setBeamMaterial(0.3, 1);
|
m_pReducedPatternElementalMesh->setBeamMaterial(0.3, 1);
|
||||||
pFullModelElementalMesh = std::make_shared<SimulationMesh>(fullModel);
|
m_pFullModelElementalMesh = std::make_shared<SimulationMesh>(fullModel);
|
||||||
pFullModelElementalMesh->setBeamCrossSection(CrossSectionType{0.002, 0.002});
|
m_pFullModelElementalMesh->setBeamCrossSection(
|
||||||
pFullModelElementalMesh->setBeamMaterial(0.3, 1);
|
CrossSectionType{0.002, 0.002});
|
||||||
|
m_pFullModelElementalMesh->setBeamMaterial(0.3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReducedModelOptimizer::ReducedModelOptimizer(
|
ReducedModelOptimizer::ReducedModelOptimizer(
|
||||||
|
|
@ -297,7 +299,7 @@ void ReducedModelOptimizer::initialize(
|
||||||
FlatPattern &fullPattern, FlatPattern &reducedPattern,
|
FlatPattern &fullPattern, FlatPattern &reducedPattern,
|
||||||
const std::unordered_set<size_t> &reducedModelExcludedEdges) {
|
const std::unordered_set<size_t> &reducedModelExcludedEdges) {
|
||||||
assert(fullPattern.VN() == reducedPattern.VN() &&
|
assert(fullPattern.VN() == reducedPattern.VN() &&
|
||||||
fullPattern.EN() > reducedPattern.EN());
|
fullPattern.EN() >= reducedPattern.EN());
|
||||||
polyscope::removeAllStructures();
|
polyscope::removeAllStructures();
|
||||||
// Create copies of the input models
|
// Create copies of the input models
|
||||||
FlatPattern copyFullPattern;
|
FlatPattern copyFullPattern;
|
||||||
|
|
@ -307,9 +309,6 @@ void ReducedModelOptimizer::initialize(
|
||||||
computeMaps(copyFullPattern, copyReducedPattern, reducedModelExcludedEdges);
|
computeMaps(copyFullPattern, copyReducedPattern, reducedModelExcludedEdges);
|
||||||
createSimulationMeshes(copyFullPattern, copyReducedPattern);
|
createSimulationMeshes(copyFullPattern, copyReducedPattern);
|
||||||
initializeStiffnesses();
|
initializeStiffnesses();
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReducedModelOptimizer::initializeStiffnesses() {
|
void ReducedModelOptimizer::initializeStiffnesses() {
|
||||||
|
|
@ -324,7 +323,8 @@ void ReducedModelOptimizer::initializeStiffnesses() {
|
||||||
// e.firstBendingConstFactor *= stiffnessFactor;
|
// e.firstBendingConstFactor *= stiffnessFactor;
|
||||||
// e.secondBendingConstFactor *= stiffnessFactor;
|
// e.secondBendingConstFactor *= stiffnessFactor;
|
||||||
// }
|
// }
|
||||||
g_initialParameters = pReducedModelElementalMesh->elements[0].properties.E;
|
g_initialParameters =
|
||||||
|
m_pReducedPatternElementalMesh->elements[0].properties.E;
|
||||||
// g_initialParameters(1) =
|
// g_initialParameters(1) =
|
||||||
// pReducedModelElementalMesh->elements[0].properties.G;
|
// pReducedModelElementalMesh->elements[0].properties.G;
|
||||||
// g_initialParameters(0, 0) =
|
// g_initialParameters(0, 0) =
|
||||||
|
|
@ -363,7 +363,7 @@ void ReducedModelOptimizer::computeReducedModelSimulationJob(
|
||||||
fullModelNodalForcedRotation.second;
|
fullModelNodalForcedRotation.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
simulationJobOfReducedModel = SimulationJob{pReducedModelElementalMesh,
|
simulationJobOfReducedModel = SimulationJob{m_pReducedPatternElementalMesh,
|
||||||
reducedModelFixedVertices,
|
reducedModelFixedVertices,
|
||||||
reducedModelNodalForces,
|
reducedModelNodalForces,
|
||||||
{},
|
{},
|
||||||
|
|
@ -383,8 +383,8 @@ void ReducedModelOptimizer::computeDesiredReducedModelDisplacements(
|
||||||
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel) {
|
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel) {
|
||||||
|
|
||||||
optimalDisplacementsOfReducedModel.resize(0, 3);
|
optimalDisplacementsOfReducedModel.resize(0, 3);
|
||||||
optimalDisplacementsOfReducedModel.resize(pReducedModelElementalMesh->VN(),
|
optimalDisplacementsOfReducedModel.resize(
|
||||||
3);
|
m_pReducedPatternElementalMesh->VN(), 3);
|
||||||
optimalDisplacementsOfReducedModel.setZero(
|
optimalDisplacementsOfReducedModel.setZero(
|
||||||
optimalDisplacementsOfReducedModel.rows(),
|
optimalDisplacementsOfReducedModel.rows(),
|
||||||
optimalDisplacementsOfReducedModel.cols());
|
optimalDisplacementsOfReducedModel.cols());
|
||||||
|
|
@ -403,20 +403,21 @@ void ReducedModelOptimizer::computeDesiredReducedModelDisplacements(
|
||||||
Eigen::VectorXd ReducedModelOptimizer::optimizeForSimulationJob(
|
Eigen::VectorXd ReducedModelOptimizer::optimizeForSimulationJob(
|
||||||
const SimulationJob &fullPatternSimulationJob) {
|
const SimulationJob &fullPatternSimulationJob) {
|
||||||
|
|
||||||
gObjectiveValueHistory.clear();
|
|
||||||
// fullPatternSimulationJob.registerForDrawing();
|
// fullPatternSimulationJob.registerForDrawing();
|
||||||
// polyscope::show();
|
// polyscope::show();
|
||||||
|
gObjectiveValueHistory.clear();
|
||||||
fullPatternSimulationJob.mesh->savePly(
|
fullPatternSimulationJob.mesh->savePly(
|
||||||
"Fanned_" + pFullModelElementalMesh->getLabel() + ".ply");
|
"Fanned_" + m_pFullModelElementalMesh->getLabel() + ".ply");
|
||||||
SimulationResults fullModelResults =
|
SimulationResults fullModelResults =
|
||||||
simulator.executeSimulation(fullPatternSimulationJob, false, true);
|
simulator.executeSimulation(fullPatternSimulationJob, false, true);
|
||||||
fullModelResults.simulationLabel = "fullModel";
|
fullModelResults.simulationLabel = "fullModel";
|
||||||
|
fullModelResults.registerForDrawing(fullPatternSimulationJob);
|
||||||
|
registerWorldAxes();
|
||||||
|
polyscope::show();
|
||||||
computeDesiredReducedModelDisplacements(fullModelResults,
|
computeDesiredReducedModelDisplacements(fullModelResults,
|
||||||
g_optimalReducedModelDisplacements);
|
g_optimalReducedModelDisplacements);
|
||||||
computeReducedModelSimulationJob(fullPatternSimulationJob,
|
computeReducedModelSimulationJob(fullPatternSimulationJob,
|
||||||
g_reducedPatternSimulationJob);
|
g_reducedPatternSimulationJob);
|
||||||
// fullModelSimulationJob.registerForDrawing();
|
|
||||||
// polyscope::show();
|
|
||||||
// gReducedPatternSimulationJob.registerForDrawing();
|
// gReducedPatternSimulationJob.registerForDrawing();
|
||||||
// polyscope::show();
|
// polyscope::show();
|
||||||
fullModelResults.registerForDrawing(fullPatternSimulationJob);
|
fullModelResults.registerForDrawing(fullPatternSimulationJob);
|
||||||
|
|
@ -490,12 +491,31 @@ std::vector<SimulationJob> ReducedModelOptimizer::createScenarios(
|
||||||
std::vector<SimulationJob> scenarios;
|
std::vector<SimulationJob> scenarios;
|
||||||
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
||||||
std::unordered_map<VertexIndex, Vector6d> nodalForces;
|
std::unordered_map<VertexIndex, Vector6d> nodalForces;
|
||||||
std::unordered_map<VertexIndex, VectorType> nodalForcedNormals;
|
|
||||||
const double forceMagnitude = 1;
|
const double forceMagnitude = 1;
|
||||||
// Assuming the patterns lays on the x-y plane
|
// Assuming the patterns lays on the x-y plane
|
||||||
const CoordType patternPlaneNormal(0, 0, 1);
|
const CoordType patternPlaneNormal(0, 0, 1);
|
||||||
|
// Make the first interface node lay on the x axis
|
||||||
|
const size_t fullPatternFirstInterfaceNodeIndex =
|
||||||
|
m_fullPatternOppositeInterfaceViMap.begin()->second;
|
||||||
|
CoordType fullPatternFirstInterfaceNodePosition =
|
||||||
|
m_pFullModelElementalMesh->vert[fullPatternFirstInterfaceNodeIndex].cP();
|
||||||
|
const vcg::Matrix33d R = vcg::RotationMatrix(
|
||||||
|
fullPatternFirstInterfaceNodePosition,
|
||||||
|
CoordType(fullPatternFirstInterfaceNodePosition.Norm(), 0, 0), false);
|
||||||
|
std::for_each(m_pFullModelElementalMesh->vert.begin(),
|
||||||
|
m_pFullModelElementalMesh->vert.end(), [&](auto &v) {
|
||||||
|
v.P() = R * v.P();
|
||||||
|
v.N() = R * v.N();
|
||||||
|
});
|
||||||
|
std::for_each(m_pReducedPatternElementalMesh->vert.begin(),
|
||||||
|
m_pReducedPatternElementalMesh->vert.end(), [&](auto &v) {
|
||||||
|
v.P() = R * v.P();
|
||||||
|
v.N() = R * v.N();
|
||||||
|
});
|
||||||
|
m_pFullModelElementalMesh->updateEigenEdgeAndVertices();
|
||||||
|
m_pReducedPatternElementalMesh->updateEigenEdgeAndVertices();
|
||||||
|
|
||||||
// // Axial
|
// //// Axial
|
||||||
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
||||||
// CoordType forceDirection =
|
// CoordType forceDirection =
|
||||||
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
|
|
@ -509,7 +529,7 @@ std::vector<SimulationJob> ReducedModelOptimizer::createScenarios(
|
||||||
// }
|
// }
|
||||||
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
||||||
|
|
||||||
// // In-plane Bending
|
// //// In-plane Bending
|
||||||
// fixedVertices.clear();
|
// fixedVertices.clear();
|
||||||
// nodalForces.clear();
|
// nodalForces.clear();
|
||||||
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
||||||
|
|
@ -526,7 +546,7 @@ std::vector<SimulationJob> ReducedModelOptimizer::createScenarios(
|
||||||
// }
|
// }
|
||||||
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
||||||
|
|
||||||
// // Torsion
|
// //// Torsion
|
||||||
// fixedVertices.clear();
|
// fixedVertices.clear();
|
||||||
// nodalForces.clear();
|
// nodalForces.clear();
|
||||||
// for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
// for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
||||||
|
|
@ -537,125 +557,83 @@ std::vector<SimulationJob> ReducedModelOptimizer::createScenarios(
|
||||||
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
// .Normalize();
|
// .Normalize();
|
||||||
// CoordType normalVDerivativeDir = (v ^ patternPlaneNormal).Normalize();
|
// CoordType normalVDerivativeDir = (v ^ patternPlaneNormal).Normalize();
|
||||||
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
// nodalForces[viPair.first] = Vector6d{
|
||||||
// nodalForcedNormals[viPair.first] = normalVDerivativeDir;
|
// 0, 0, 0, normalVDerivativeDir[0], normalVDerivativeDir[1], 0};
|
||||||
// } else {
|
// fixedVertices[viPair.second] =
|
||||||
// fixedVertices[viPair.first] =
|
|
||||||
// std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
// std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
||||||
|
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
|
// } else {
|
||||||
|
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
|
// fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
// }
|
// }
|
||||||
// fixedVertices[viPair.second] =
|
|
||||||
// std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
|
||||||
// }
|
// }
|
||||||
// scenarios.push_back(
|
// scenarios.push_back({pMesh, fixedVertices, nodalForces});
|
||||||
// {pMesh, fixedVertices, nodalForces, {}, nodalForcedNormals});
|
|
||||||
|
|
||||||
// // Out - of - plane bending.Pull towards Z
|
// // Out - of - plane bending.Pull towards Z
|
||||||
// fixedVertices.clear();
|
// fixedVertices.clear();
|
||||||
// nodalForces.clear();
|
// nodalForces.clear();
|
||||||
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
||||||
// nodalForces[viPair.first] = Vector6d({0, 0, forceMagnitude, 0, 0, 0}) *
|
// nodalForces[viPair.first] = Vector6d({0, 0, forceMagnitude, 0, 0, 0}) *
|
||||||
// 2; fixedVertices[viPair.second] =
|
// 1; fixedVertices[viPair.second] =
|
||||||
// std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
// std::unordered_set<DoFType>{0, 1, 2, 3, 4, 5};
|
||||||
// }
|
// }
|
||||||
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
||||||
|
|
||||||
// Double
|
// //// Double using moments
|
||||||
// fixedVertices.clear();
|
|
||||||
// nodalForces.clear();
|
|
||||||
// nodalForcedNormals.clear();
|
|
||||||
// int counter = 0;
|
|
||||||
// for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
|
||||||
// CoordType v =
|
|
||||||
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
|
||||||
// .Normalize();
|
|
||||||
// nodalForcedNormals[viPair.first] = -v;
|
|
||||||
// if (counter++ == 1) {
|
|
||||||
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0};
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
|
||||||
// }
|
|
||||||
// fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
|
||||||
// }
|
|
||||||
// scenarios.push_back(
|
|
||||||
// {pMesh, fixedVertices, nodalForces, {}, nodalForcedNormals});
|
|
||||||
|
|
||||||
// Double
|
|
||||||
fixedVertices.clear();
|
|
||||||
nodalForces.clear();
|
|
||||||
for (const auto &viPair : m_fullPatternOppositeInterfaceViMap) {
|
|
||||||
CoordType v =
|
|
||||||
(pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
|
||||||
.Normalize();
|
|
||||||
CoordType momentDirection = patternPlaneNormal ^ v;
|
|
||||||
nodalForces[viPair.first] =
|
|
||||||
Vector6d({0, 0, 0, momentDirection[1], momentDirection[0], 0}) *
|
|
||||||
forceMagnitude;
|
|
||||||
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
|
||||||
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
|
||||||
}
|
|
||||||
scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
|
||||||
|
|
||||||
//// Saddle using moments
|
|
||||||
// fixedVertices.clear();
|
// fixedVertices.clear();
|
||||||
// nodalForces.clear();
|
// nodalForces.clear();
|
||||||
// for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
// for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
||||||
// viPairIt != m_fullPatternOppositeInterfaceViMap.end(); viPairIt++) {
|
// viPairIt != m_fullPatternOppositeInterfaceViMap.end(); viPairIt++) {
|
||||||
// const auto &viPair = *viPairIt;
|
// const auto viPair = *viPairIt;
|
||||||
|
// if (viPairIt == m_fullPatternOppositeInterfaceViMap.begin()) {
|
||||||
|
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
|
// fixedVertices[viPair.second] = std::unordered_set<DoFType>{1, 2};
|
||||||
|
// } else {
|
||||||
|
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
||||||
|
// fixedVertices[viPair.second] = std::unordered_set<DoFType>{2};
|
||||||
|
// }
|
||||||
// CoordType v =
|
// CoordType v =
|
||||||
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
// (pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
// .Normalize();
|
// .Normalize();
|
||||||
// // CoordType momentDirection = (patternPlane ^ v).Normalize();
|
// nodalForces[viPair.first] =
|
||||||
// if (viPairIt == m_fullPatternOppositeInterfaceViMap.begin()) {
|
// Vector6d({0, 0, 0, v[0], v[1], 0}) * forceMagnitude * 0.1;
|
||||||
// nodalForces[viPair.first] =
|
// nodalForces[viPair.second] =
|
||||||
// Vector6d({0, 0, 0, v[0], v[1], 0}) * 5 * forceMagnitude;
|
// Vector6d({0, 0, 0, -v[0], -v[1], 0}) * forceMagnitude * 0.1;
|
||||||
// nodalForces[viPair.second] =
|
|
||||||
// Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 5 * forceMagnitude;
|
|
||||||
// } else {
|
|
||||||
// fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
|
||||||
// // nodalForces[viPair.first] =
|
|
||||||
// // Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 2 * forceMagnitude;
|
|
||||||
// fixedVertices[viPair.second] = std::unordered_set<DoFType>{2};
|
|
||||||
|
|
||||||
// nodalForces[viPair.first] =
|
|
||||||
// Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 2 * forceMagnitude;
|
|
||||||
// nodalForces[viPair.second] =
|
|
||||||
// Vector6d({0, 0, 0, v[0], v[1], 0}) * 2 * forceMagnitude;
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
// scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
||||||
|
|
||||||
//// Saddle using forced normals
|
//// Saddle
|
||||||
fixedVertices.clear();
|
fixedVertices.clear();
|
||||||
nodalForces.clear();
|
nodalForces.clear();
|
||||||
nodalForcedNormals.clear();
|
|
||||||
for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
for (auto viPairIt = m_fullPatternOppositeInterfaceViMap.begin();
|
||||||
viPairIt != m_fullPatternOppositeInterfaceViMap.end(); viPairIt++) {
|
viPairIt != m_fullPatternOppositeInterfaceViMap.end(); viPairIt++) {
|
||||||
const auto &viPair = *viPairIt;
|
const auto &viPair = *viPairIt;
|
||||||
CoordType v =
|
CoordType v =
|
||||||
(pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
(pMesh->vert[viPair.first].cP() - pMesh->vert[viPair.second].cP())
|
||||||
.Normalize();
|
.Normalize();
|
||||||
// CoordType momentDirection = (patternPlane ^ v).Normalize();
|
|
||||||
if (viPairIt == m_fullPatternOppositeInterfaceViMap.begin()) {
|
if (viPairIt == m_fullPatternOppositeInterfaceViMap.begin()) {
|
||||||
nodalForcedNormals[viPair.first] = v;
|
nodalForces[viPair.first] =
|
||||||
nodalForcedNormals[viPair.second] = -v;
|
Vector6d({0, 0, 0, v[0], v[1], 0}) * 0.02 * forceMagnitude;
|
||||||
|
nodalForces[viPair.second] =
|
||||||
|
Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 0.02 * forceMagnitude;
|
||||||
} else {
|
} else {
|
||||||
|
fixedVertices[viPair.first] = std::unordered_set<DoFType>{2};
|
||||||
|
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
||||||
|
|
||||||
nodalForcedNormals[viPair.first] = -v;
|
nodalForces[viPair.first] =
|
||||||
nodalForcedNormals[viPair.second] = v;
|
Vector6d({0, 0, 0, -v[0], -v[1], 0}) * 0.01 * forceMagnitude;
|
||||||
|
nodalForces[viPair.second] =
|
||||||
|
Vector6d({0, 0, 0, v[0], v[1], 0}) * 0.01 * forceMagnitude;
|
||||||
}
|
}
|
||||||
fixedVertices[viPair.first] = std::unordered_set<DoFType>{0, 1, 2};
|
|
||||||
fixedVertices[viPair.second] = std::unordered_set<DoFType>{0, 1, 2};
|
|
||||||
}
|
}
|
||||||
scenarios.push_back(
|
scenarios.push_back({pMesh, fixedVertices, nodalForces, {}});
|
||||||
{pMesh, fixedVertices, nodalForces, {}, nodalForcedNormals});
|
|
||||||
|
|
||||||
return scenarios;
|
return scenarios;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::VectorXd ReducedModelOptimizer::optimize() {
|
Eigen::VectorXd ReducedModelOptimizer::optimize() {
|
||||||
std::vector<SimulationJob> simulationJobs =
|
std::vector<SimulationJob> simulationJobs =
|
||||||
createScenarios(pFullModelElementalMesh);
|
createScenarios(m_pFullModelElementalMesh);
|
||||||
std::vector<Eigen::VectorXd> results;
|
std::vector<Eigen::VectorXd> results;
|
||||||
for (const SimulationJob &job : simulationJobs) {
|
for (const SimulationJob &job : simulationJobs) {
|
||||||
polyscope::removeAllStructures();
|
polyscope::removeAllStructures();
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@
|
||||||
#include "matplot/matplot.h"
|
#include "matplot/matplot.h"
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
|
|
||||||
using FullModelVertexIndex = VertexIndex;
|
using FullPatternVertexIndex = VertexIndex;
|
||||||
using ReducedModelVertexIndex = VertexIndex;
|
using ReducedPatternVertexIndex = VertexIndex;
|
||||||
|
|
||||||
class ReducedModelOptimizer {
|
class ReducedModelOptimizer {
|
||||||
std::shared_ptr<SimulationMesh> pReducedModelElementalMesh;
|
std::shared_ptr<SimulationMesh> m_pReducedPatternElementalMesh;
|
||||||
std::shared_ptr<SimulationMesh> pFullModelElementalMesh;
|
std::shared_ptr<SimulationMesh> m_pFullModelElementalMesh;
|
||||||
std::unordered_map<FullModelVertexIndex, ReducedModelVertexIndex>
|
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
||||||
m_fullToReducedInterfaceViMap;
|
m_fullToReducedInterfaceViMap;
|
||||||
std::unordered_map<ReducedModelVertexIndex, ReducedModelVertexIndex>
|
std::unordered_map<FullPatternVertexIndex, FullPatternVertexIndex>
|
||||||
m_fullPatternOppositeInterfaceViMap;
|
m_fullPatternOppositeInterfaceViMap;
|
||||||
std::unordered_map<size_t, size_t> nodeToSlot;
|
std::unordered_map<size_t, size_t> nodeToSlot;
|
||||||
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue