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 real_t vmin{ -REAL_MAX };
54 real_t vmax{ +REAL_MAX };
55 void inline update( const real_t &s )
56 {
57 x[ 2 ] = x[ 1 ];
58 x[ 1 ] = s;
59 }
62 public:
63 virtual ~nState() = default;
64
71 nState( const real_t x0 = 0.0_re,
72 const real_t sn_1 = 0.0_re,
73 const real_t sn_2 = 0.0_re ) noexcept
74 {
75 init( x0, sn_1, sn_2 );
76 }
77
84 void init( const real_t x0 = 0.0_re,
85 const real_t sn_1 = 0.0_re,
86 const real_t sn_2 = 0.0_re ) noexcept;
87
96 real_t integrate( const real_t s,
97 const real_t dt,
98 const bool bUpdate = true ) noexcept;
99
108 real_t derive( const real_t s,
109 const real_t dt,
110 const bool bUpdate = true ) noexcept;
111
130 inline void setIntegrationMethod( integrationMethod m ) noexcept
131 {
132 iMethod = m;
133 }
134
153 inline void setDerivationMethod( derivationMethod m ) noexcept
154 {
155 dMethod = m;
156 }
157
166 bool setSaturation( const real_t minV,
167 const real_t maxV ) noexcept;
168
173 real_t operator()( void ) const noexcept
174 {
175 return x[ 0 ];
176 }
177
179 real_t operator*( real_t rValue) const noexcept
180 {
181 return x[ 0 ]*rValue;
182 }
183 real_t operator/( real_t rValue) const noexcept
184 {
185 return x[ 0 ]/rValue;
186 }
187 real_t operator+( real_t rValue) const noexcept
188 {
189 return x[ 0 ] + rValue;
190 }
191 real_t operator-( real_t rValue) const noexcept
192 {
193 return x[ 0 ] - rValue;
194 }
195 friend real_t operator*( real_t rValue,
196 const nState& s ) noexcept;
197 friend real_t operator/( real_t rValue,
198 const nState& s ) noexcept;
199 friend real_t operator+( real_t rValue,
200 const nState& s ) noexcept;
201 friend real_t operator-( real_t rValue,
202 const nState& s ) noexcept;
204 };
205
207 inline real_t operator*( real_t rValue,
208 const nState& s ) noexcept
209 {
210 return rValue*s.x[ 0 ];
211 }
212 inline real_t operator/( real_t rValue,
213 const nState& s ) noexcept
214 {
215 return rValue/s.x[ 0 ];
216 }
217 inline real_t operator+( real_t rValue,
218 const nState& s ) noexcept
219 {
220 return rValue + s.x[ 0 ];
221 }
222 inline real_t operator-( real_t rValue,
223 const nState& s ) noexcept
224 {
225 return rValue - s.x[ 0 ];
226 }
228
235 class integrator : public nState, private nonCopyable {
236 private:
237 real_t dt;
238 public:
239 virtual ~integrator() = default;
240
251 integrator( const real_t timeStep,
252 const real_t initialCondition = 0.0_re );
253
254
262 real_t operator()( const real_t xDot );
263
268 real_t operator()() const;
269 };
270
277 class derivative : public nState, private nonCopyable {
278 private:
279 real_t dt;
280 public:
281 virtual ~derivative() = default;
282
292 derivative( const real_t timeStep,
293 const real_t initialCondition = 0.0_re );
294
303 real_t operator()( const real_t xt );
304 };
305
307}
308
309#endif /*QLIBS_NUMA*/
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:119
virtual ~derivative()=default
real_t operator()() const
Retrieve the current value of the integration.
Definition numa.cpp:114
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:103
virtual ~integrator()=default
A numerical state object.
Definition numa.hpp:50
bool setSaturation(const real_t minV, const real_t maxV) noexcept
Sets the saturation limits for the integrator output.
Definition numa.cpp:90
void setDerivationMethod(derivationMethod m) noexcept
Sets the numerical derivation method.
Definition numa.hpp:153
virtual ~nState()=default
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:53
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:130
real_t operator()(void) const noexcept
Get the value of the state.
Definition numa.hpp:173
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:71
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