Skip to content

Commit

Permalink
Change ChExternalDynamicsODE to an abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
rserban committed Oct 24, 2024
1 parent c9731e1 commit b3f4ec0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/chrono/physics/ChExternalDynamicsODE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ void ChExternalDynamicsODE::Initialize() {
}
}

ChExternalDynamicsODE* ChExternalDynamicsODE::Clone() const {
return new ChExternalDynamicsODE(*this);
}

ChVectorDynamic<> ChExternalDynamicsODE::GetInitialStates() {
ChVectorDynamic<> y0(m_nstates);
SetInitialConditions(y0);
Expand Down
20 changes: 11 additions & 9 deletions src/chrono/physics/ChExternalDynamicsODE.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@

namespace chrono {

/// Physics element that carries its own dynamics, described as a system of ODEs.
/// The internal states are integrated simultaneously with the containing system and they can be accessed and used coupled
/// Physics element that carries its own dynamics, described as an ODE IVP of the form:
/// <pre>
/// y' = f(t,y)
/// y(t0) = y0
/// </pre>
/// The internal states are integrated simultaneously with the containing system and they can be accessed and coupled
/// with other physics elements.
class ChApi ChExternalDynamicsODE : public ChPhysicsItem {
public:
virtual ~ChExternalDynamicsODE();

/// "Virtual" copy constructor (covariant return type).
virtual ChExternalDynamicsODE* Clone() const override;

/// Initialize the physics item.
virtual void Initialize();

Expand All @@ -43,7 +44,7 @@ class ChApi ChExternalDynamicsODE : public ChPhysicsItem {
virtual bool IsStiff() const { return false; }

/// Get number of states (dimension of y).
virtual unsigned int GetNumStates() const { return 0; }
virtual unsigned int GetNumStates() const = 0;

/// Get the initial values (state at initial time).
ChVectorDynamic<> GetInitialStates();
Expand All @@ -59,14 +60,14 @@ class ChApi ChExternalDynamicsODE : public ChPhysicsItem {

/// Set initial conditions.
/// Must load y0 = y(0).
virtual void SetInitialConditions(ChVectorDynamic<>& y0) {}
virtual void SetInitialConditions(ChVectorDynamic<>& y0) = 0;

/// Calculate and return the ODE right-hand side at the provided time and states.
/// Must load rhs = f(t,y).
virtual void CalculateRHS(double time, ///< current time
const ChVectorDynamic<>& y, ///< current ODE states
ChVectorDynamic<>& rhs ///< output ODE right-hand side vector
) {}
) = 0;

/// Calculate the Jacobian of the ODE right-hand side with respect to the ODE states.
/// Must load J = df/dy.
Expand All @@ -81,6 +82,7 @@ class ChApi ChExternalDynamicsODE : public ChPhysicsItem {
return false;
}

protected:
virtual void Update(double time, bool update_assets = true) override;

virtual unsigned int GetNumCoordsPosLevel() override { return m_nstates; }
Expand Down Expand Up @@ -135,10 +137,10 @@ class ChApi ChExternalDynamicsODE : public ChPhysicsItem {
virtual void VariablesQbIncrementPosition(double step) override;
virtual void ConstraintsFbLoadForces(double factor = 1) override;

private:
/// Compute the Jacobian at the current time and state.
void ComputeJac(double time);

private:
int m_nstates; ///< number of internal ODE states
ChVectorDynamic<> m_states; ///< vector of internal ODE states
ChVariablesGenericDiagonalMass* m_variables; ///< carrier for internal dynamics states
Expand Down
2 changes: 1 addition & 1 deletion src/chrono_fmi/ChExternalFmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ChApiFMI ChExternalFmu : public ChExternalDynamicsODE {
void SetRealInputFunction(const std::string& name, std::function<double(double)> function);

/// Initialize this physics item.
/// This function initializes the underlying FMU as well as this physcis item.
/// This function initializes the underlying FMU as well as this physics item.
virtual void Initialize() override;

/// Print the list of FMU variables.
Expand Down
2 changes: 2 additions & 0 deletions src/demos/mbs/demo_MBS_external_ODE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class VanDerPolODE : public ChExternalDynamicsODE {
public:
VanDerPolODE(double mu) : m_mu(mu) {}

virtual VanDerPolODE* Clone() const override { return new VanDerPolODE(*this); }

virtual unsigned int GetNumStates() const override { return 2; }

virtual bool IsStiff() const override { return m_mu > 10; }
Expand Down

0 comments on commit b3f4ec0

Please sign in to comment.