Refactoring
This commit is contained in:
parent
b764d7db2c
commit
513529f0a4
|
|
@ -1235,7 +1235,24 @@ void DRMSimulationModel::updateNodalMasses()
|
||||||
pMesh->nodes[v].mass_6d[DoF::Nx] = pMesh->nodes[v].mass.rotationalJ;
|
pMesh->nodes[v].mass_6d[DoF::Nx] = pMesh->nodes[v].mass.rotationalJ;
|
||||||
pMesh->nodes[v].mass_6d[DoF::Ny] = pMesh->nodes[v].mass.rotationalI3;
|
pMesh->nodes[v].mass_6d[DoF::Ny] = pMesh->nodes[v].mass.rotationalI3;
|
||||||
pMesh->nodes[v].mass_6d[DoF::Nr] = pMesh->nodes[v].mass.rotationalI2;
|
pMesh->nodes[v].mass_6d[DoF::Nr] = pMesh->nodes[v].mass.rotationalI2;
|
||||||
|
if (mSettings.useViscousDamping) {
|
||||||
|
//fill 6d damping vector
|
||||||
|
const double translationalDampingFactor
|
||||||
|
= 2 * std::sqrt(translationalSumSk * pMesh->nodes[v].mass.translational);
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Ux] = translationalDampingFactor;
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Uy] = translationalDampingFactor;
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Uz] = translationalDampingFactor;
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Nx] = 2
|
||||||
|
* std::sqrt(rotationalSumSk_J
|
||||||
|
* pMesh->nodes[v].mass_6d[DoF::Nx]);
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Ny] = 2
|
||||||
|
* std::sqrt(rotationalSumSk_I3
|
||||||
|
* pMesh->nodes[v].mass_6d[DoF::Ny]);
|
||||||
|
pMesh->nodes[v].damping_6d[DoF::Nr] = 2
|
||||||
|
* std::sqrt(rotationalSumSk_I2
|
||||||
|
* pMesh->nodes[v].mass_6d[DoF::Nr]);
|
||||||
|
pMesh->nodes[v].damping_6d = pMesh->nodes[v].damping_6d * 1e-2;
|
||||||
|
}
|
||||||
assert(std::pow(mSettings.Dtini, 2.0) * translationalSumSk
|
assert(std::pow(mSettings.Dtini, 2.0) * translationalSumSk
|
||||||
/ pMesh->nodes[v].mass.translational
|
/ pMesh->nodes[v].mass.translational
|
||||||
< 2);
|
< 2);
|
||||||
|
|
@ -1277,21 +1294,23 @@ void DRMSimulationModel::updateNodalVelocities()
|
||||||
for (VertexType &v : pMesh->vert) {
|
for (VertexType &v : pMesh->vert) {
|
||||||
const VertexIndex vi = pMesh->getIndex(v);
|
const VertexIndex vi = pMesh->getIndex(v);
|
||||||
Node &node = pMesh->nodes[v];
|
Node &node = pMesh->nodes[v];
|
||||||
#ifdef POLYSCOPE_DEFINED
|
|
||||||
if (std::isnan(node.velocity.norm())) {
|
|
||||||
std::cout << "Velocity " << vi << ":" << node.velocity.toString() << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (mSettings.useViscousDamping) {
|
if (mSettings.useViscousDamping) {
|
||||||
const Vector6d massOverDt = node.mass_6d / Dt;
|
const Vector6d massOverDt = node.mass_6d / Dt;
|
||||||
const Vector6d denominator = massOverDt + Vector6d(viscuousDampingConstant / 2);
|
const Vector6d visciousDampingFactor(viscuousDampingConstant / 2);
|
||||||
const Vector6d firstTermNominator = massOverDt - Vector6d(viscuousDampingConstant / 2);
|
// const Vector6d &visciousDampingFactor = node.damping_6d;
|
||||||
|
const Vector6d denominator = massOverDt + visciousDampingFactor / 2;
|
||||||
|
const Vector6d firstTermNominator = massOverDt - visciousDampingFactor / 2;
|
||||||
const Vector6d firstTerm = node.velocity * firstTermNominator / denominator;
|
const Vector6d firstTerm = node.velocity * firstTermNominator / denominator;
|
||||||
const Vector6d secondTerm = node.force.residual / denominator;
|
const Vector6d secondTerm = node.force.residual / denominator;
|
||||||
node.velocity = firstTerm + secondTerm;
|
node.velocity = firstTerm + secondTerm;
|
||||||
} else {
|
} else {
|
||||||
node.velocity = node.velocity + node.acceleration * Dt;
|
node.velocity = node.velocity + node.acceleration * Dt;
|
||||||
}
|
}
|
||||||
|
#ifdef POLYSCOPE_DEFINED
|
||||||
|
if (std::isnan(node.velocity.norm())) {
|
||||||
|
std::cout << "Velocity " << vi << ":" << node.velocity.toString() << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
updateKineticEnergy();
|
updateKineticEnergy();
|
||||||
}
|
}
|
||||||
|
|
@ -2266,19 +2285,19 @@ SimulationResults DRMSimulationModel::executeSimulation(const std::shared_ptr<Si
|
||||||
// SimulationResultsReporter::createPlot("Number of Steps",
|
// SimulationResultsReporter::createPlot("Number of Steps",
|
||||||
// "Residual Forces mov aver deriv",
|
// "Residual Forces mov aver deriv",
|
||||||
// movingAveragesDerivatives_norm);
|
// movingAveragesDerivatives_norm);
|
||||||
SimulationResultsReporter::createPlot("Number of Steps",
|
// SimulationResultsReporter::createPlot("Number of Steps",
|
||||||
"Residual Forces mov aver",
|
// "Residual Forces mov aver",
|
||||||
history.residualForcesMovingAverage);
|
// history.residualForcesMovingAverage);
|
||||||
// SimulationResultsReporter::createPlot("Number of Steps",
|
// SimulationResultsReporter::createPlot("Number of Steps",
|
||||||
// "Log of Residual Forces",
|
// "Log of Residual Forces",
|
||||||
// history.logResidualForces,
|
// history.logResidualForces,
|
||||||
// {},
|
// {},
|
||||||
// history.redMarks);
|
// history.redMarks);
|
||||||
// SimulationResultsReporter::createPlot("Number of Steps",
|
SimulationResultsReporter::createPlot("Number of Steps",
|
||||||
// "Log of Kinetic energy",
|
"Log of Kinetic energy",
|
||||||
// history.kineticEnergy,
|
history.kineticEnergy,
|
||||||
// {},
|
{},
|
||||||
// history.redMarks);
|
history.redMarks);
|
||||||
// SimulationResultsReporter reporter;
|
// SimulationResultsReporter reporter;
|
||||||
// reporter.reportHistory(history, "IntermediateResults", pJob->pMesh->getLabel());
|
// reporter.reportHistory(history, "IntermediateResults", pJob->pMesh->getLabel());
|
||||||
// SimulationResultsReporter::createPlot("Number of Iterations",
|
// SimulationResultsReporter::createPlot("Number of Iterations",
|
||||||
|
|
@ -2330,10 +2349,18 @@ currentSimulationStep > maxDRMIterations*/
|
||||||
= mSettings.useAverage
|
= mSettings.useAverage
|
||||||
&& (pMesh->totalResidualForcesNorm / pMesh->VN()) / totalExternalForcesNorm
|
&& (pMesh->totalResidualForcesNorm / pMesh->VN()) / totalExternalForcesNorm
|
||||||
< mSettings.averageResidualForcesCriterionThreshold;
|
< mSettings.averageResidualForcesCriterionThreshold;
|
||||||
|
if (fullfillsResidualForcesNormTerminationCriterion
|
||||||
|
|| fullfillsResidualForcesNormTerminationCriterion) {
|
||||||
|
if (mSettings.beVerbose /*&& !mSettings.isDebugMode*/) {
|
||||||
|
std::cout << "Simulation converged." << std::endl;
|
||||||
|
printCurrentState();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Residual forces norm convergence
|
// Residual forces norm convergence
|
||||||
if (((pMesh->previousTotalKineticEnergy > pMesh->currentTotalKineticEnergy
|
if ((mSettings.useKineticDamping)
|
||||||
|| fullfillsAverageResidualForcesNormTerminationCriterion
|
&& (pMesh->previousTotalKineticEnergy > pMesh->currentTotalKineticEnergy
|
||||||
|| fullfillsResidualForcesNormTerminationCriterion)
|
|
||||||
// && mCurrentSimulationStep > movingAverageSampleSize
|
// && mCurrentSimulationStep > movingAverageSampleSize
|
||||||
&& (pJob->nodalForcedDisplacements.empty()
|
&& (pJob->nodalForcedDisplacements.empty()
|
||||||
|| mCurrentSimulationStep > mSettings.gradualForcedDisplacementSteps))
|
|| mCurrentSimulationStep > mSettings.gradualForcedDisplacementSteps))
|
||||||
|
|
@ -2405,6 +2432,7 @@ mesh->currentTotalPotentialEnergykN*/
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mSettings.useViscousDamping) {
|
||||||
const bool shouldCapDisplacements = mSettings.displacementCap.has_value();
|
const bool shouldCapDisplacements = mSettings.displacementCap.has_value();
|
||||||
for (VertexType &v : pMesh->vert) {
|
for (VertexType &v : pMesh->vert) {
|
||||||
Node &node = pMesh->nodes[v];
|
Node &node = pMesh->nodes[v];
|
||||||
|
|
@ -2424,6 +2452,7 @@ mesh->currentTotalPotentialEnergykN*/
|
||||||
pJob->nodalForcedDisplacements);
|
pJob->nodalForcedDisplacements);
|
||||||
}
|
}
|
||||||
updateElementalLengths();
|
updateElementalLengths();
|
||||||
|
}
|
||||||
|
|
||||||
// const double triggerPercentage = 0.01;
|
// const double triggerPercentage = 0.01;
|
||||||
// const double xi_min = 0.55;
|
// const double xi_min = 0.55;
|
||||||
|
|
@ -2436,7 +2465,9 @@ mesh->currentTotalPotentialEnergykN*/
|
||||||
// + xi_init - triggerPercentage * xi_min)
|
// + xi_init - triggerPercentage * xi_min)
|
||||||
// / (1 - triggerPercentage);
|
// / (1 - triggerPercentage);
|
||||||
// }
|
// }
|
||||||
|
if (mSettings.useKineticDamping) {
|
||||||
resetVelocities();
|
resetVelocities();
|
||||||
|
}
|
||||||
Dt *= mSettings.xi;
|
Dt *= mSettings.xi;
|
||||||
// if (mSettings.isDebugMode) {
|
// if (mSettings.isDebugMode) {
|
||||||
// std::cout << Dt << std::endl;
|
// std::cout << Dt << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ public:
|
||||||
double averageResidualForcesCriterionThreshold{1e-5};
|
double averageResidualForcesCriterionThreshold{1e-5};
|
||||||
Settings() {}
|
Settings() {}
|
||||||
bool useViscousDamping{false};
|
bool useViscousDamping{false};
|
||||||
|
bool useKineticDamping{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -62,7 +63,7 @@ private:
|
||||||
std::vector<double> plotYValues;
|
std::vector<double> plotYValues;
|
||||||
size_t numOfDampings{0};
|
size_t numOfDampings{0};
|
||||||
int externalLoadStep{1};
|
int externalLoadStep{1};
|
||||||
const double viscuousDampingConstant{0.01};
|
const double viscuousDampingConstant{100};
|
||||||
std::vector<bool> isVertexConstrained;
|
std::vector<bool> isVertexConstrained;
|
||||||
std::vector<bool> isRigidSupport;
|
std::vector<bool> isRigidSupport;
|
||||||
double minTotalResidualForcesNorm{std::numeric_limits<double>::max()};
|
double minTotalResidualForcesNorm{std::numeric_limits<double>::max()};
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ struct Node {
|
||||||
|
|
||||||
Mass mass;
|
Mass mass;
|
||||||
Vector6d mass_6d;
|
Vector6d mass_6d;
|
||||||
|
Vector6d damping_6d;
|
||||||
VertexIndex vi;
|
VertexIndex vi;
|
||||||
CoordType initialLocation;
|
CoordType initialLocation;
|
||||||
CoordType initialNormal;
|
CoordType initialNormal;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue