Skip to content
Snippets Groups Projects
Commit 7de2579f authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Add option to have 'fixed' and 'real-time' time stepping schemes

parent a2be3e4b
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,15 @@ enum class DynamicalModelType
none
};
///
/// \brief Type of the update of the state of the body
///
enum class TimeSteppingType
{
realTime,
fixed
};
///
/// \class DynamicalModel
///
......@@ -63,6 +72,7 @@ public:
none
};
public:
///
/// \brief Constructor
......@@ -119,11 +129,27 @@ public:
///
virtual void updatePhysicsGeometry(){};
///
/// \brief Set the time step size
///
virtual void setTimeStep(const double timeStep) = 0;
///
/// \brief Returns the time step size
///
virtual double getTimeStep() const = 0;
///
/// \brief Initialize the dynamical model
///
virtual bool initialize() = 0;
///
/// \brief Set the type of approach used to update the time step size after every frame
///
virtual void setTimeStepSizeType(const TimeSteppingType type){ m_timeStepSizeType = type; }
TimeSteppingType getTimeStepSizeType(){ return m_timeStepSizeType; }
protected:
DynamicalModelType m_type; ///> Mathematical model type
......@@ -134,6 +160,8 @@ protected:
std::shared_ptr<StateType> m_previousState; ///> Previous state
std::size_t m_numDOF; ///> Total number of degree of freedom
TimeSteppingType m_timeStepSizeType = TimeSteppingType::fixed;
};
} // imstk
......
......@@ -673,4 +673,11 @@ FEMDeformableBodyModel::getContactForce()
{
return m_Fcontact;
}
void
FEMDeformableBodyModel::setFixedSizeTimeStepping()
{
m_timeStepSizeType = TimeSteppingType::fixed;
m_timeIntegrator->setTimestepSizeToDefault();
}
} // imstk
\ No newline at end of file
......@@ -233,6 +233,21 @@ public:
///
std::vector<std::size_t>& getFixNodeIds() { return m_fixedNodeIds; }
///
/// \brief Set the time step size
///
virtual void setTimeStep(const double timeStep) { m_timeIntegrator->setTimestepSize(timeStep); };
///
/// \brief Returns the time step size
///
virtual double getTimeStep() const { return m_timeIntegrator->getTimestepSize(); };
///
/// \brief Set the time step size to fixed size
///
void setFixedSizeTimeStepping();
protected:
std::shared_ptr<InternalForceModel> m_internalForceModel; ///> Mathematical model for intenal forces
std::shared_ptr<TimeIntegrator> m_timeIntegrator; ///> Time integrator
......
......@@ -69,6 +69,7 @@ PbdModel::configure(const int nCons, ...)
this->setGravity(g);
this->setTimeStep(va_arg(args, double));
this->setDefaultTimeStep(m_dt);
char *s = va_arg(args, char*);
if (strlen(s) > 0)
......@@ -611,6 +612,16 @@ PbdModel::updatePbdStateFromPhysicsGeometry()
m_currentState->setPositions(m_mesh->getVertexPositions());
}
void
PbdModel::setTimeStepSizeType(const TimeSteppingType type)
{
m_timeStepSizeType = type;
if (type == TimeSteppingType::fixed)
{
m_dt = m_DefaultDt;
}
}
void
PbdModel::setViscousDamping(const double damping)
{
......
......@@ -167,11 +167,18 @@ public:
/// \brief Set the time step size
///
void setTimeStep(const double timeStep) { m_dt = timeStep; };
void setDefaultTimeStep(const double timeStep) { m_DefaultDt = timeStep; };
///
/// \brief Set the time step size to fixed size
///
void setTimeStepSizeType(const TimeSteppingType type) override;
///
/// \brief Returns the time step size
///
double getTimeStep() const { return m_dt; };
double getDefaultTimeStep() const { return m_DefaultDt; };
///
/// \brief Set the gravity
......@@ -250,6 +257,7 @@ protected:
double m_proximity; ///> Proximity for collisions
double m_dt; ///> Time step size
double m_DefaultDt; ///> Default Time step size
};
} // imstk
......
......@@ -145,6 +145,36 @@ SceneManager::runModule()
{
controller->setTrackerToOutOfDate();
}
<<<<<<< HEAD
=======
auto timeElapsed = wwt.getTimeElapsed(StopWatch::TimeUnitType::seconds);
// Update time step size of the dynamic objects
for (auto obj : m_scene->getSceneObjects())
{
if (obj->getType() == SceneObject::Type::Pbd)
{
if (auto dynaObj = std::dynamic_pointer_cast<PbdObject>(obj))
{
if (dynaObj->getDynamicalModel()->getTimeStepSizeType() == TimeSteppingType::realTime)
{
dynaObj->getDynamicalModel()->setTimeStep(timeElapsed);
}
}
}
else if (obj->getType() == SceneObject::Type::FEMDeformable)
{
if (auto dynaObj = std::dynamic_pointer_cast<DeformableObject>(obj))
{
if (dynaObj->getDynamicalModel()->getTimeStepSizeType() == TimeSteppingType::realTime)
{
dynaObj->getDynamicalModel()->setTimeStep(timeElapsed);
}
}
}
}
>>>>>>> 2decf6e... initial
}
void
......
......@@ -56,7 +56,7 @@ public:
///
/// \brief Constructor
///
TimeIntegrator(Type type, double dT) : m_type(type), m_dT(dT){}
TimeIntegrator(Type type, double dT) : m_type(type), m_dT(dT), m_defaultDt(dT){}
///
/// \brief Destructor
......@@ -73,6 +73,13 @@ public:
///
void setTimestepSize(const double dT){ m_dT = dT; }
double getTimestepSize() const { return m_dT; }
void setTimestepSizeToDefault(){ m_dT = m_defaultDt; }
///
/// \brief Set/Get the time step size
///
void setDefaultTimestepSize(const double dT){ m_defaultDt = dT; }
double getDefaultTimestepSize() const { return m_defaultDt; }
///
/// \brief Update states given the updates in different forms
......@@ -85,6 +92,7 @@ public:
protected:
Type m_type; ///> Type of the time integrator
double m_dT; ///> Delta T
double m_defaultDt;
};
} // imstk
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment