Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
numa.hpp
1
9#ifndef QLIBS_NUMA
10#define QLIBS_NUMA
11
12#include <include/qlibs_types.hpp>
13
17namespace qlibs {
18
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
70 nState( const real_t x0 = 0.0_re,
71 const real_t sn_1 = 0.0_re,
72 const real_t sn_2 = 0.0_re ) noexcept
73 {
74 init( x0, sn_1, sn_2 );
75 }
76
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
95 real_t integrate( const real_t s,
96 const real_t dt,
97 const bool bUpdate = true ) noexcept;
98
106 real_t derive( const real_t s,
107 const real_t dt,
108 const bool bUpdate = true ) noexcept;
109
124 inline void setIntegrationMethod( integrationMethod m ) noexcept
125 {
126 iMethod = m;
127 }
128
141 inline void setDerivationMethod( derivationMethod m ) noexcept
142 {
143 dMethod = m;
144 }
145
150 real_t operator()( void ) const noexcept
151 {
152 return x[ 0 ];
153 }
154
156 real_t operator*( real_t rValue) const noexcept
157 {
158 return x[ 0 ]*rValue;
159 }
160 real_t operator/( real_t rValue) const noexcept
161 {
162 return x[ 0 ]/rValue;
163 }
164 real_t operator+( real_t rValue) const noexcept
165 {
166 return x[ 0 ] + rValue;
167 }
168 real_t operator-( real_t rValue) const noexcept
169 {
170 return x[ 0 ] - rValue;
171 }
172 friend real_t operator*( real_t rValue,
173 const nState& s ) noexcept;
174 friend real_t operator/( real_t rValue,
175 const nState& s ) noexcept;
176 friend real_t operator+( real_t rValue,
177 const nState& s ) noexcept;
178 friend real_t operator-( real_t rValue,
179 const nState& s ) noexcept;
181 };
182
184 inline real_t operator*( real_t rValue,
185 const nState& s ) noexcept
186 {
187 return rValue*s.x[ 0 ];
188 }
189 inline real_t operator/( real_t rValue,
190 const nState& s ) noexcept
191 {
192 return rValue/s.x[ 0 ];
193 }
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 }
207}
208
209#endif /*QLIBS_NUMA*/
A numerical state object.
Definition numa.hpp:50
virtual ~nState()
Definition numa.hpp:61
void setDerivationMethod(derivationMethod m) noexcept
Set derivation method.
Definition numa.hpp:141
real_t derive(const real_t s, const real_t dt, const bool bUpdate=true) noexcept
Perform a numerical derivation step by using the delta rule.
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.
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
Set integration method .
Definition numa.hpp:124
real_t operator()(void) const noexcept
Get the value of the state.
Definition numa.hpp:150
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:70
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 fp16.cpp:4
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43