iMSTK
Interactive Medical Simulation Toolkit
imstkReducedStVKBodyModel.cpp
1 /*=========================================================================
2 
3  Library: iMSTK
4 
5  Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
6  & Imaging in Medicine, Rensselaer Polytechnic Institute.
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0.txt
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =========================================================================*/
21 
22 // std lib
23 #include <fstream>
24 #include <ios>
25 #include <iomanip>
26 
27 // imstk
28 #include "imstkMath.h"
29 #include "imstkNewtonSolver.h"
30 #include "imstkReducedStVKBodyModel.h"
31 #include "imstkTimeIntegrator.h"
32 #include "imstkVegaMeshIO.h"
33 #include "imstkVolumetricMesh.h"
34 #include "imstkTaskGraph.h"
35 #include "imstkNewtonSolver.h"
36 
37 // vega
38 #include "StVKReducedInternalForces.h"
39 #include "matrixIO.h"
40 #include "modalMatrix.h"
41 #include "reducedStVKForceModel.h"
42 
43 #pragma warning(push)
44 #pragma warning(disable : 4458)
45 #include "configFile.h"
46 #pragma warning(pop)
47 
48 namespace imstk
49 {
51 {
52  // m_fixedNodeIds.reserve(1000);
53 
54  m_validGeometryTypes = { "TetrahedralMesh", "HexahedralMesh" };
55 
56  m_solveNode = m_taskGraph->addFunction("FEMModel_Solve", [&]() { getSolver()->solve(); });
57 }
58 
60 {
61  // Get vega to destruct first (before the shared pointer to the vega mesh is cleaned up)
62  m_internalForceModel = nullptr;
63 }
64 
65 void
66 ReducedStVK::configure(const std::string& configFileName)
67 {
68  std::cerr << "not implemented yet" << std::endl;
69  // Configure the ReducedStVKConfig
70  m_config = std::make_shared<ReducedStVKConfig>();
71 
72  // char femMethod[256];
73  // char invertibleMaterial[256];
74  // char fixedDOFFilename[256];
75 
76  vega::ConfigFile vegaConfigFileOptions;
77 
78  // configure the options
79  vegaConfigFileOptions.addOptionOptional("dampingMassCoefficient",
80  &m_config->m_dampingMassCoefficient,
81  m_config->m_dampingMassCoefficient);
82  vegaConfigFileOptions.addOptionOptional("dampingStiffnessCoefficient",
83  &m_config->m_dampingStiffnessCoefficient,
84  m_config->m_dampingStiffnessCoefficient);
85  vegaConfigFileOptions.addOptionOptional("dampingLaplacianCoefficient",
86  &m_config->m_dampingLaplacianCoefficient,
87  m_config->m_dampingLaplacianCoefficient);
88  vegaConfigFileOptions.addOptionOptional("numberOfThreads",
89  &m_config->m_numberOfThreads,
90  m_config->m_numberOfThreads);
91  vegaConfigFileOptions.addOptionOptional("gravity", &m_config->m_gravity, m_config->m_gravity);
92 
93  // Parse the configuration file
94  CHECK(vegaConfigFileOptions.parseOptions(configFileName.data()) == 0)
95  << "ForceModelConfig::parseConfig - Unable to load the configuration file";
96 
97  // get the root directory of the boundary file name
98  // std::string rootDir;
99  // const size_t last_slash_idx = configFileName.rfind('/');
100  // if (std::string::npos != last_slash_idx)
101  // {
102  // rootDir = configFileName.substr(0, last_slash_idx);
103  // }
104 
105  // file names (remove from here?)
106  // m_config->m_fixedDOFFilename = rootDir + std::string("/") + std::string(fixedDOFFilename);
107 }
108 
109 void
110 ReducedStVK::configure(std::shared_ptr<ReducedStVKConfig> config)
111 {
112  m_config = config;
113 }
114 
115 void
116 ReducedStVK::setForceModelConfiguration(std::shared_ptr<ReducedStVKConfig> fmConfig)
117 {
118  m_config = fmConfig;
119 }
120 
121 std::shared_ptr<imstk::ReducedStVKConfig>
122 ReducedStVK::getForceModelConfiguration() const
123 {
124  return m_config;
125 }
126 
127 void
128 // ReducedStVK::setInternalForceModel(std::shared_ptr<InternalForceModel> fm)
129 ReducedStVK::setInternalForceModel(std::shared_ptr<vega::StVKReducedInternalForces> fm)
130 {
131  m_internalForceModel = fm;
132 }
133 
134 std::shared_ptr<imstk::InternalForceModel>
135 ReducedStVK::getInternalForceModel() const
136 {
137  // return m_internalForceModel;
138  LOG(FATAL) << "current implementation can not return an imstk::InternalForceModel.";
139  // todo: to implement this function, we have to
140  // 1) template InternalForceModel with SystemMatrix
141  // 2) define ReducedStVKForceModel by inherit from InternalForceModel
142  // 3) replace vega::StVKReducedInternalForces with ReducedStVKForceModel
143  return nullptr;
144 }
145 
146 void
147 ReducedStVK::setTimeIntegrator(std::shared_ptr<TimeIntegrator> timeIntegrator)
148 {
149  m_timeIntegrator = timeIntegrator;
150 }
151 
152 std::shared_ptr<imstk::TimeIntegrator>
153 ReducedStVK::getTimeIntegrator() const
154 {
155  return m_timeIntegrator;
156 }
157 
158 bool
160 {
161  // prerequisite of for successfully initializing
162  CHECK(m_geometry != nullptr && m_config != nullptr)
163  << "Physics mesh or force model configuration not set yet!";
164 
165  // Setup default solver if model wasn't assigned one
166  if (m_solver == nullptr)
167  {
168  // create a nonlinear system
169  auto nlSystem = std::make_shared<NonLinearSystem<Matrixd>>(getFunction(), getFunctionGradient());
170 
171  nlSystem->setUnknownVector(getUnknownVec());
172  nlSystem->setUpdateFunction(getUpdateFunction());
173  nlSystem->setUpdatePreviousStatesFunction(getUpdatePrevStateFunction());
174 
175  // create a non-linear solver and add to the scene
176  auto nlSolver = std::make_shared<NewtonSolver<Matrixd>>();
177  nlSolver->setToSemiImplicit();
178  // nlSolver->setLinearSolver(linSolver);
179  nlSolver->setMaxIterations(1);
180  nlSolver->setSystem(nlSystem);
181  setSolver(nlSolver);
182  }
183 
184  // This will specify \p m_numDOF and \p m_numDOFReduced
185  this->readModalMatrix(m_config->m_modesFileName);
186  this->loadInitialStates();
187 
188  auto physicsMesh = std::dynamic_pointer_cast<imstk::VolumetricMesh>(this->getModelGeometry());
189  m_vegaPhysicsMesh = VegaMeshIO::convertVolumetricMeshToVegaMesh(physicsMesh);
190  CHECK(m_numDOF == m_vegaPhysicsMesh->getNumVertices() * 3);
191 
192  if (!this->initializeForceModel() || !this->initializeMassMatrix()
195  {
196  return false;
197  }
198 
199  // reduced-space
200  m_Feff.resize(m_numDOFReduced);
202  m_Finternal.setConstant(0.0);
204  m_qSolReduced.setConstant(0.0);
206  m_FgravityReduced.resize(m_numDOFReduced);
208 
209  // full-space variable
210  m_Fcontact.resize(m_numDOF);
211  m_Fcontact.setConstant(0.0);
212  m_qSol.resize(m_numDOF);
213  m_qSol.setConstant(0.0);
214 
215  return true;
216 }
217 
218 void
219 ReducedStVK::readModalMatrix(const std::string& fname)
220 {
221  std::vector<float> Ufloat;
222  int m, n;
223  vega::ReadMatrixFromDisk_(fname.c_str(), m, n, Ufloat);
224  m_numDOF = m;
225  m_numDOFReduced = n;
226  std::vector<double> Udouble(Ufloat.size());
227 
228  for (size_t i = 0; i < Ufloat.size(); ++i)
229  {
230  Udouble[i] = Ufloat[i];
231  }
232 
233  m_modalMatrix =
234  std::make_shared<vega::ModalMatrix>(m_numDOF / 3, m_numDOFReduced, Udouble.data());
235  return;
236 }
237 
238 void
240 {
241  if (m_numDOF == 0 || m_numDOFReduced == 0)
242  {
243  LOG(WARNING) << "Num. of degree of freedom is zero!";
244  }
245 
246  // For now the initial states are set to zero
247  m_initialState = std::make_shared<kinematicState>(m_numDOF);
248  m_previousState = std::make_shared<kinematicState>(m_numDOF);
249  m_currentState = std::make_shared<kinematicState>(m_numDOF);
250 
251  m_initialStateReduced = std::make_shared<kinematicState>(m_numDOFReduced);
252  m_previousStateReduced = std::make_shared<kinematicState>(m_numDOFReduced);
253  m_currentStateReduced = std::make_shared<kinematicState>(m_numDOFReduced);
254 }
255 
256 bool
258 {
259  const double g = m_config->m_gravity;
260  const bool isGravityPresent = (g > 0) ? true : false;
261 
262  // m_numDOFReduced = m_config->r;
263  m_internalForceModel = std::make_shared<vega::StVKReducedInternalForces>(
264  m_config->m_cubicPolynomialFilename.c_str(),
266  m_forceModel = std::make_shared<vega::ReducedStVKForceModel>(m_internalForceModel.get());
267 
268  return true;
269 }
270 
271 bool
273 {
274  CHECK(m_geometry != nullptr)
275  << "Force model geometry not set!";
276  this->m_massMatrix.resize(m_numDOFReduced * m_numDOFReduced, 0.0);
277 
278  // set M to identity
279  for (size_t i = 0; i < m_numDOFReduced; ++i)
280  {
281  this->m_massMatrix[i * m_numDOFReduced + i] = 1.0;
282  }
283  this->m_M.resize(m_numDOFReduced, m_numDOFReduced);
285 
286  return true;
287 }
288 
289 bool
291 {
292  // \todo: only mass dampings are considered here.
293  this->m_dampingMatrix.resize(m_numDOFReduced * m_numDOFReduced, 0.0);
294  auto cM = m_config->m_dampingMassCoefficient;
295  auto cK = m_config->m_dampingStiffnessCoefficient;
296  for (size_t i = 0; i < m_dampingMatrix.size(); ++i)
297  {
298  m_dampingMatrix[i] = m_massMatrix[i] * cM + m_stiffnessMatrix[i] * cK;
299  }
300  this->m_C.resize(m_numDOFReduced, m_numDOFReduced);
302  m_damped = true;
303 
304  return true;
305 }
306 
307 bool
309 {
310  CHECK(m_forceModel != nullptr)
311  << "Tangent stiffness cannot be initialized without force model";
312 
314  m_forceModel->GetTangentStiffnessMatrix(m_initialStateReduced->getQ().data(),
315  m_stiffnessMatrix.data());
316  this->m_K.resize(m_numDOFReduced, m_numDOFReduced);
318  return true;
319 }
320 
321 bool
323 {
324  m_Fgravity.resize(m_numDOF);
325  const double gravity = m_config->m_gravity;
326 
327  m_vegaPhysicsMesh->computeGravity(m_Fgravity.data(), gravity);
328  m_FgravityReduced.resize(m_numDOFReduced);
329  this->project(m_Fgravity, m_FgravityReduced);
330 
331  return true;
332 }
333 
334 void
336  kinematicState& newState,
337  const StateUpdateType updateType)
338 {
339  const auto& uPrev = stateAtT.getQ();
340  const auto& vPrev = stateAtT.getQDot();
341  auto& u = newState.getQ();
342  const auto& v = newState.getQDot();
343 
344  // Do checks if there are uninitialized matrices
345  m_forceModel->GetTangentStiffnessMatrix(u.data(), m_stiffnessMatrix.data());
347 
348  const double dT = m_timeIntegrator->getTimestepSize();
349 
350  switch (updateType)
351  {
352  case StateUpdateType::DeltaVelocity:
353 
354  m_Feff = m_K * -(uPrev - u + v * dT);
355 
356  if (m_damped)
357  {
358  m_Feff -= m_C * v;
359  }
360 
361  m_forceModel->GetInternalForce(u.data(), m_Finternal.data());
362  m_Feff -= m_Finternal;
365  // the reduced gravity has alredy been initialized in initializeGravityForce
366  // this->project(m_Fgravity, m_FgravityReduced);
367  m_Feff += m_FgravityReduced;
370  m_Feff *= dT;
371  m_Feff += m_M * (vPrev - v);
372 
373  break;
374  default:
375  LOG(WARNING) << "Update type not supported";
376  }
377 }
378 
379 void
381  kinematicState& newState,
382  const StateUpdateType updateType)
383 {
384  // auto& uPrev = stateAtT.getQ();
385  const auto& vPrev = stateAtT.getQDot();
386  auto& u = newState.getQ();
387  // auto& v = newState.getQDot();
388 
389  // Do checks if there are uninitialized matrices
390  m_forceModel->GetTangentStiffnessMatrix(u.data(), m_stiffnessMatrix.data());
392 
393  const double dT = m_timeIntegrator->getTimestepSize();
394 
395  switch (updateType)
396  {
397  case StateUpdateType::DeltaVelocity:
398 
399  m_Feff = m_K * (vPrev * -dT);
400 
401  if (m_damped)
402  {
403  m_Feff -= m_C * vPrev;
404  }
405 
406  m_forceModel->GetInternalForce(u.data(), m_Finternal.data());
407  m_Feff -= m_Finternal;
410  this->project(m_Fgravity, m_FgravityReduced);
411  m_Feff += m_FgravityReduced;
414  m_Feff *= dT;
415 
416  break;
417 
418  default:
419  LOG(FATAL) << "Update type not supported";
420  }
421 }
422 
423 void
425  kinematicState& newState,
426  const StateUpdateType updateType)
427 {
428  const double dT = m_timeIntegrator->getTimestepSize();
429 
430  switch (updateType)
431  {
432  case StateUpdateType::DeltaVelocity:
433 
434  stateAtT; // supress warning (state is not used in this update type hence can be
435  // ignored)
436 
437  this->updateMassMatrix();
438  m_forceModel->GetTangentStiffnessMatrix(newState.getQ().data(),
439  m_stiffnessMatrix.data());
441  this->updateDampingMatrix();
442 
443  m_Keff = m_M;
444  if (m_damped)
445  {
446  m_Keff += dT * m_C;
447  }
448  m_Keff += (dT * dT) * m_K;
449 
450  break;
451 
452  default:
453  LOG(FATAL) << "Update type not supported";
454  }
455 }
456 
457 bool
459 {
460  m_FexplicitExternal.resize(m_numDOF);
461  m_FexplicitExternal.setZero();
463  m_FexplicitExternalReduced.setZero();
464 
465  return true;
466 }
467 
468 void
470 {
471  if (!m_damped)
472  {
473  return;
474  }
475 
476  const auto& dampingStiffnessCoefficient = m_config->m_dampingStiffnessCoefficient;
477  const auto& dampingMassCoefficient = m_config->m_dampingMassCoefficient;
478 
479  if (dampingMassCoefficient > 0)
480  {
481  m_C = dampingMassCoefficient * m_M;
482 
483  if (dampingStiffnessCoefficient > 0)
484  {
485  m_C += m_K * dampingStiffnessCoefficient;
486  }
487  }
488  else if (dampingStiffnessCoefficient > 0)
489  {
490  m_C = m_K * dampingStiffnessCoefficient;
491  }
492 }
493 
494 void
495 ReducedStVK::applyBoundaryConditions(Matrixd& M, const bool withCompliance) const
496 {
497  // I believe there is nothing to do here since the full space has already been constrained
498  // before the reduction.
499  return;
500 }
501 
502 void
503 ReducedStVK::applyBoundaryConditions(Vectord& x) const
504 {
505  LOG(WARNING) << "Boundary conditions are not not allowed to change";
506 }
507 
508 void
510 {
511  // Do nothing for now as topology changes are not supported yet!
512 }
513 
514 void
516 {
517  auto volMesh = std::static_pointer_cast<VolumetricMesh>(m_geometry);
518  auto& uReduced = m_currentStateReduced->getQ();
519  auto& uFull = m_currentState->getQ();
520  this->prolongate(uReduced, uFull);
521  volMesh->setVertexDisplacements(uFull);
522 }
523 
524 void
526 {
527  // full-space
528  m_previousStateReduced->setU(m_currentStateReduced->getQ());
529  m_previousStateReduced->setV(m_currentStateReduced->getQDot());
530  prolongate(*m_previousStateReduced, *m_previousState);
531 }
532 
533 void
534 ReducedStVK::updateBodyStates(const Vectord& solution, const StateUpdateType updateType)
535 {
536  this->updateBodyPreviousStates();
537  this->updateBodyIntermediateStates(solution, updateType);
538 }
539 
540 void
541 ReducedStVK::updateBodyIntermediateStates(const Vectord& solution, const StateUpdateType updateType)
542 {
543  const auto& uPrev = m_previousStateReduced->getQ();
544  // auto& u = m_currentState->getQ();
545  const auto& v = m_currentStateReduced->getQDot();
546  const double dT = m_timeIntegrator->getTimestepSize();
547 
548  switch (updateType)
549  {
550  case StateUpdateType::DeltaVelocity:
551  m_currentStateReduced->setV(v + solution);
552  m_currentStateReduced->setU(uPrev + dT * v);
553 
554  break;
555 
556  case StateUpdateType::Velocity:
557  m_currentStateReduced->setV(solution);
558  m_currentStateReduced->setU(uPrev + dT * v);
559 
560  break;
561 
562  default:
563  LOG(FATAL) << "Unknown state update type";
564  }
565  prolongate(*m_currentStateReduced, *m_currentState);
566  m_qSolReduced = m_currentStateReduced->getQ();
567 }
568 
569 NonLinearSystem<Matrixd>::VectorFunctionType
571 {
572 #pragma warning(push)
573 #pragma warning(disable : 4100)
574 
575  // Function to evaluate the nonlinear objective function given the current state
576  return [&, this](const Vectord& q, const bool semiImplicit) -> const Vectord& {
577  (semiImplicit) ? this->computeSemiImplicitSystemRHS(*m_previousStateReduced,
578  *m_currentStateReduced,
579  m_updateType)
580  : this->computeImplicitSystemRHS(*m_previousStateReduced,
581  *m_currentStateReduced,
582  m_updateType);
583  return m_Feff;
584  };
585 
586 #pragma warning(pop)
587 }
588 
589 NonLinearSystem<Matrixd>::MatrixFunctionType
591 {
592 #pragma warning(push)
593 #pragma warning(disable : 4100)
594  // Gradient of the nonlinear objective function given the current state
595  return [&, this](const Vectord& q) -> const Matrixd& {
596  this->computeImplicitSystemLHS(*m_previousStateReduced,
597  *m_currentStateReduced,
598  m_updateType);
599  return m_Keff;
600  };
601 
602 #pragma warning(pop)
603 }
604 
605 NonLinearSystem<Matrixd>::UpdateFunctionType
607 {
608  // Function to evaluate the nonlinear objective function given the current state
609  return [&, this](const Vectord& q, const bool fullyImplicit) -> void {
610  (fullyImplicit) ? this->updateBodyIntermediateStates(q, m_updateType)
611  : this->updateBodyStates(q, m_updateType);
612  };
613 }
614 
615 NonLinearSystem<Matrixd>::UpdatePrevStateFunctionType
616 ReducedStVK::getUpdatePrevStateFunction()
617 {
618  // Function to evaluate the nonlinear objective function given the current state
619  return [&, this]() -> void { this->updateBodyPreviousStates(); };
620 }
621 
622 void
623 ReducedStVK::initializeEigenMatrixFromStdVector(const std::vector<double>& A, Matrixd& eigenMatrix)
624 {
625  CHECK(eigenMatrix.rows() == eigenMatrix.cols());
626  CHECK(A.size() == eigenMatrix.rows() * eigenMatrix.cols());
627 
628  // A is column-major
629  for (size_t j = 0; j < eigenMatrix.cols(); ++j)
630  {
631  size_t offset = j * eigenMatrix.rows();
632  for (size_t i = 0; i < eigenMatrix.rows(); ++i)
633  {
634  eigenMatrix(i, j) = A[i + offset];
635  }
636  }
637 }
638 
639 Vectord&
641 {
642  return m_Fcontact;
643 }
644 
645 void
647 {
648  m_timeStepSizeType = TimeSteppingType::Fixed;
649  m_timeIntegrator->setTimestepSizeToDefault();
650 }
651 
652 void
653 ReducedStVK::setTimeStep(const double timeStep)
654 {
655  m_timeIntegrator->setTimestepSize(timeStep);
656 }
657 
658 double
660 {
661  return m_timeIntegrator->getTimestepSize();
662 };
663 
664 void
665 ReducedStVK::prolongate(const Vectord& uReduced, Vectord& u) const
666 {
667  //\todo: check sizes
668  m_modalMatrix->AssembleVector(const_cast<double*>(uReduced.data()), u.data());
669 }
670 
671 void
673 {
674  this->prolongate(uReduced.getQ(), u.getQ());
675  this->prolongate(uReduced.getQDot(), u.getQDot());
676 }
677 
678 void
679 ReducedStVK::project(const Vectord& u, Vectord& uReduced) const
680 {
681  m_modalMatrix->ProjectVector(const_cast<double*>(u.data()), uReduced.data());
682 }
683 
684 void
685 ReducedStVK::initGraphEdges(std::shared_ptr<TaskNode> source, std::shared_ptr<TaskNode> sink)
686 {
687  // Setup graph connectivity
688  m_taskGraph->addEdge(source, m_solveNode);
689  m_taskGraph->addEdge(m_solveNode, sink);
690 }
691 } // namespace imstk
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrixd
A dynamic size matrix of doubles.
Definition: imstkMath.h:97
void setFixedSizeTimeStepping()
Set the time step size to fixed size.
std::shared_ptr< FeDeformBodyState > m_initialState
Initial state.
Matrixd m_Keff
Tangent (derivative of internal force w.r.t displacements) stiffness matrix
Matrixd m_K
Damping coefficient matrix
std::shared_ptr< vega::ReducedStVKForceModel > m_forceModel
Mathematical model for intenal forces
void prolongate(const Vectord &uReduced, Vectord &u) const
prolongate reduced vector into full space, ie, u = U * uReduced
Vectord & getContactForce()
Get the contact force vector.
std::shared_ptr< Geometry > getModelGeometry() const
Gets the model geometry.
std::shared_ptr< vega::ModalMatrix > m_modalMatrix
Nonlinear system resulting from TI and force model
virtual ~ReducedStVK() override
Destructor.
void updateDampingMatrix()
Update damping Matrix.
Matrixd m_M
Matrices typical to a elastodynamics and 2nd order analogous systems.
Compound Geometry.
Vectord & getQ()
Get the state.
Vectord m_FexplicitExternal
Vector of gravity forces
Vectord m_qSol
Vector of explicitly defined external forces
void configure(const std::string &configFileName)
Configure the force model from external file.
void computeImplicitSystemRHS(kinematicState &prevState, kinematicState &newState, const StateUpdateType updateType)
Compute the RHS of the resulting linear system.
bool initializeGravityForce()
Initialize the gravity force.
DynamicalModelType
Type of the time dependent mathematical model.
std::shared_ptr< FeDeformBodyState > m_previousState
Previous state.
void applyBoundaryConditions(Matrixd &M, const bool withCompliance=false) const
Applies boundary conditions to matrix and a vector.
void updatePhysicsGeometry() override
Updates the Physics geometry.
std::vector< double > m_massMatrix
Mesh used for Physics
void setTimeIntegrator(std::shared_ptr< TimeIntegrator > timeIntegrator)
Set/Get time integrator.
static void initializeEigenMatrixFromStdVector(const std::vector< double > &v, Matrixd &eigenMatrix)
Initialize the Eigen matrix with data inside vega sparse matrix.
void project(const Vectord &u, Vectord &uReduced) const
project full-space vector into reduced space, uReduced = U^T u
This class stores the state of the unknown field variable in vectorized form.
Vectord & getUnknownVec()
Returns the unknown vectors.
void updateBodyStates(const Vectord &solution, const StateUpdateType updateType)
Update states.
void setInternalForceModel(std::shared_ptr< vega::StVKReducedInternalForces > fm)
Set/Get time integrator.
Vectord & getQDot()
Get the derivative of state w.r.t time.
bool initialize() override
Initialize the deformable body model.
Vectord m_qSolReduced
Vector of internal forces
bool initializeDampingMatrix()
Initialize the damping (combines structural and viscous damping) matrix.
void computeImplicitSystemLHS(const kinematicState &prevState, kinematicState &newState, const StateUpdateType updateType)
Compute the LHS of the resulting linear system.
virtual void setTimeStep(const double timeStep)
Set the time step size.
Vectord m_Feff
Vector to maintain solution at each iteration of nonlinear solver
bool initializeTangentStiffness()
Initialize the tangent stiffness matrix.
bool initializeExplicitExternalForces()
Initialize explicit external forces.
Vectord m_Finternal
Vector of effective forces
Vectord m_FexplicitExternalReduced
Vector of gravity forces
StateUpdateType m_updateType
Nodal IDs of the nodes that are fixed
std::vector< double > m_stiffnessMatrix
Vega mass matrix
bool m_damped
Update type of the model
std::set< std::string > m_validGeometryTypes
Valid geometry types of this model.
Vectord m_Fgravity
Vector of contact forces
bool initializeForceModel()
Initialize the force model.
StateUpdateType
Type of the update of the state of the body.
void computeSemiImplicitSystemRHS(kinematicState &stateAtT, kinematicState &newState, const StateUpdateType updateType)
Compute the RHS of the resulting linear system using semi-implicit scheme.
Vectord m_FcontactReduced
Vector to maintain solution at each iteration of nonlinear solver
void loadInitialStates()
Load the initial conditions of the deformable object.
virtual double getTimeStep() const
Returns the time step size.
std::vector< double > m_dampingMatrix
Vega Tangent stiffness matrix
Base class for mathematical model of the physics governing the dynamic object.
size_t m_numDOFReduced
Vector of explicitly defined external forces
std::shared_ptr< FeDeformBodyState > m_currentState
Current state.
void readModalMatrix(const std::string &fname)
Read in the basis file and create m_modalMatrix.
Base class for all volume mesh types.
NonLinearSystem< Matrixd >::UpdateFunctionType getUpdateFunction()
Get the function that updates the model given the solution.
void updateMassMatrix()
Update mass matrix Note: Not supported yet!
Vectord m_Fcontact
integrator)
bool initializeMassMatrix()
Initialize the mass matrix from the mesh.
NonLinearSystem< Matrixd >::VectorFunctionType getFunction()
Returns the "function" that evaluates the nonlinear function given the state vector.
std::shared_ptr< Geometry > m_geometry
Physics geometry of the model.
void updateBodyPreviousStates()
Update the previous states given the current state.
static std::shared_ptr< vega::VolumetricMesh > convertVolumetricMeshToVegaMesh(const std::shared_ptr< PointSet > volumeMesh)
Generate a vega volume mesh given volumetric mesh.
NonLinearSystem< Matrixd >::MatrixFunctionType getFunctionGradient()
Returns the "function" that evaluates the gradient of the nonlinear function given the state vector...
void setForceModelConfiguration(std::shared_ptr< ReducedStVKConfig > config)
Set/Get internal force model.
void initGraphEdges()
Initializes the edges of the graph.