- 3.0.2 core module.
Masspoint.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <ct/core/core.h> // as usual, include CT
13 
14 // create a class that derives from ct::core::System
15 class Masspoint : public ct::core::System<2>
16 {
17 public:
18  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
19 
20  static const size_t STATE_DIM = 2;
21 
22  // constructor
23  Masspoint(double mass, double d) : mass_(mass), d_(d) {}
24 
25  // copy constructor
26  Masspoint(const Masspoint& other) : mass_(other.mass_), d_(other.d_) {}
27 
28  // destructor
29  ~Masspoint() = default;
30 
31  // clone method for deep copying
32  Masspoint* clone() const override
33  {
34  return new Masspoint(*this); // calls copy constructor
35  }
36 
37  // The system dynamics. We override this method which gets called by e.g. the Integrator
39  const ct::core::Time& t,
40  ct::core::StateVector<STATE_DIM>& derivative) override
41  {
42  // first part of state derivative is the velocity
43  derivative(0) = x(1);
44 
45  // second part is the acceleration which is caused by damper forces
46  derivative(1) = -d_ / mass_ * x(1);
47  }
48 
49 private:
50  double mass_;
51  double d_;
52 };
~Masspoint()=default
Masspoint * clone() const override
deep copy
Definition: Masspoint.h:32
Masspoint(const Masspoint &other)
Definition: Masspoint.h:26
Definition: Masspoint.h:15
Masspoint(double mass, double d)
Definition: Masspoint.h:23
Interface class for a general system described by an ordinary differential equation (ODE) ...
Definition: System.h:38
void computeDynamics(const ct::core::StateVector< STATE_DIM > &x, const ct::core::Time &t, ct::core::StateVector< STATE_DIM > &derivative) override
Definition: Masspoint.h:38
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t STATE_DIM
Definition: Masspoint.h:20
double Time
Definition: Time.h:11