Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
numa.hpp
1
8
9#ifndef QLIBS_NUMA
10#define QLIBS_NUMA
11
12#include <include/qlibs_types.hpp>
13
17namespace qlibs {
18
24
34
43
50 class nState {
51 private:
52 real_t x[ 3 ] = { 0.0_re, 0.0_re, 0.0_re };
53 void inline update( const real_t &s )
54 {
55 x[ 2 ] = x[ 1 ];
56 x[ 1 ] = s;
57 }
60 public:
61 virtual ~nState() {}
62
69 nState( const real_t x0 = 0.0_re,
70 const real_t sn_1 = 0.0_re,
71 const real_t sn_2 = 0.0_re ) noexcept
72 {
73 init( x0, sn_1, sn_2 );
74 }
75
82 void init( const real_t x0 = 0.0_re,
83 const real_t sn_1 = 0.0_re,
84 const real_t sn_2 = 0.0_re ) noexcept;
85
94 real_t integrate( const real_t s,
95 const real_t dt,
96 const bool bUpdate = true ) noexcept;
97
106 real_t derive( const real_t s,
107 const real_t dt,
108 const bool bUpdate = true ) noexcept;
109
128 inline void setIntegrationMethod( integrationMethod m ) noexcept
129 {
130 iMethod = m;
131 }
132
151 inline void setDerivationMethod( derivationMethod m ) noexcept
152 {
153 dMethod = m;
154 }
155
160 real_t operator()( void ) const noexcept
161 {
162 return x[ 0 ];
163 }
164
166 real_t operator*( real_t rValue) const noexcept
167 {
168 return x[ 0 ]*rValue;
169 }
170 real_t operator/( real_t rValue) const noexcept
171 {
172 return x[ 0 ]/rValue;
173 }
174 real_t operator+( real_t rValue) const noexcept
175 {
176 return x[ 0 ] + rValue;
177 }
178 real_t operator-( real_t rValue) const noexcept
179 {
180 return x[ 0 ] - rValue;
181 }
182 friend real_t operator*( real_t rValue,
183 const nState& s ) noexcept;
184 friend real_t operator/( real_t rValue,
185 const nState& s ) noexcept;
186 friend real_t operator+( real_t rValue,
187 const nState& s ) noexcept;
188 friend real_t operator-( real_t rValue,
189 const nState& s ) noexcept;
191 };
192
194 inline real_t operator*( real_t rValue,
195 const nState& s ) noexcept
196 {
197 return rValue*s.x[ 0 ];
198 }
199 inline real_t operator/( real_t rValue,
200 const nState& s ) noexcept
201 {
202 return rValue/s.x[ 0 ];
203 }
204 inline real_t operator+( real_t rValue,
205 const nState& s ) noexcept
206 {
207 return rValue + s.x[ 0 ];
208 }
209 inline real_t operator-( real_t rValue,
210 const nState& s ) noexcept
211 {
212 return rValue - s.x[ 0 ];
213 }
215
222 class integrator : public nState, private nonCopyable {
223 private:
224 real_t dt;
225 real_t min{ -REAL_MAX };
226 real_t max{ +REAL_MAX };
227 public:
228 virtual ~integrator() {}
229
240 integrator( const real_t timeStep,
241 const real_t initialCondition = 0.0_re );
242
251 bool setSaturation( const real_t minV, const real_t maxV ) noexcept;
252
260 real_t operator()( const real_t xDot );
261 };
262
269 class derivative : public nState, private nonCopyable {
270 private:
271 real_t dt;
272 public:
273 virtual ~derivative() {}
274
284 derivative( const real_t timeStep,
285 const real_t initialCondition = 0.0_re );
286
295 real_t operator()( const real_t xt );
296 };
297
299}
300
301#endif /*QLIBS_NUMA*/
virtual ~derivative()
Definition numa.hpp:273
derivative(const real_t timeStep, const real_t initialCondition=0.0_re)
Constructs a derivative block with a given timeStep and optional initial condition.
Definition numa.cpp:104
bool setSaturation(const real_t minV, const real_t maxV) noexcept
Sets the saturation limits for the integrator output.
Definition numa.cpp:74
virtual ~integrator()
Definition numa.hpp:228
integrator(const real_t timeStep, const real_t initialCondition=0.0_re)
Constructs an integrator block with a given timeStep time and optional initial condition.
Definition numa.cpp:68
A numerical state object.
Definition numa.hpp:50
virtual ~nState()
Definition numa.hpp:61
void setDerivationMethod(derivationMethod m) noexcept
Sets the numerical derivation method.
Definition numa.hpp:151
real_t derive(const real_t s, const real_t dt, const bool bUpdate=true) noexcept
Perform a numerical derivation step by using the specified derivation method.
Definition numa.cpp:42
real_t integrate(const real_t s, const real_t dt, const bool bUpdate=true) noexcept
Perform a numerical integration step by using the specified integration method.
Definition numa.cpp:15
void init(const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
Initialize the state object.
Definition numa.cpp:6
void setIntegrationMethod(integrationMethod m) noexcept
Sets the numerical integration method.
Definition numa.hpp:128
real_t operator()(void) const noexcept
Get the value of the state.
Definition numa.hpp:160
nState(const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
Constructor for the state object.
Definition numa.hpp:69
derivationMethod
An enum with all the available derivation methods.
Definition numa.hpp:38
integrationMethod
An enum with all the available integration methods.
Definition numa.hpp:28
@ DERIVATION_FORWARD
Definition numa.hpp:41
@ DERIVATION_BACKWARD
Definition numa.hpp:40
@ DERIVATION_2POINTS
Definition numa.hpp:39
@ INTEGRATION_QUADRATIC
Definition numa.hpp:32
@ INTEGRATION_SIMPSON
Definition numa.hpp:31
@ INTEGRATION_TRAPEZOIDAL
Definition numa.hpp:30
@ INTEGRATION_RECTANGULAR
Definition numa.hpp:29
The qLibs++ library namespace.
Definition mat.hpp:18
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43