state_sim.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef STATE_SIM_H
34 #define STATE_SIM_H
35 
36 #include <float.h>
37 #include <memory>
38 #include <vector>
39 
45 
46 namespace tuw
47 {
53 class StateSim;
54 using StateSimSPtr = std::shared_ptr<StateSim>;
55 using StateSimConstSPtr = std::shared_ptr<StateSim const>;
56 using StateSimUPtr = std::unique_ptr<StateSim>;
57 using StateSimConstUPtr = std::unique_ptr<StateSim const>;
58 class StateSim : public State
59 {
60  // special class member functions
61 public:
62  StateSim() = default;
63 
64 public:
65  virtual ~StateSim() = default;
66 
67 public:
68  StateSim(const StateSim&) = default;
69 
70 public:
71  StateSim& operator=(const StateSim&) = default;
72 
73 public:
74  StateSim(StateSim&&) = delete;
75 
76 public:
77  StateSim& operator=(StateSim&&) = delete;
78 
79  // pure virtual functions
81 public:
82  virtual StateSimUPtr cloneStateSim() const = 0;
84 public:
85  virtual void setDiscrType(const RungeKutta::DiscretizationType& _discrType) = 0;
87 public:
88  virtual void advance(double _arc) = 0;
89 
90  // public : virtual void advanceODEInt ( double _arc ) = 0;
91 
94 public:
95  virtual void toState0() = 0;
97 public:
98  virtual State& state0() = 0;
100 public:
101  virtual State& stateNm() = 0;
103 public:
104  virtual State& stateCf() = 0;
106 public:
107  virtual double stateArc() const = 0;
109 public:
110  virtual double stateDist() const = 0;
111 
112 public:
113  virtual void advanceSet0(const double& _tEnd, const double& _dt)
114  {
115  toState0();
116  double tSim = 0;
117  while (tSim + _dt <= _tEnd)
118  {
119  tSim += _dt;
120  advance(tSim);
121  }
122  advance(_tEnd);
123  for (size_t i = 0; i < valueSize(); ++i)
124  {
125  state0().value(i) = value(i);
126  }
127  // toState0();
128  }
129 
131 public:
132  virtual ParamFuncs* paramFuncs() = 0;
135 public:
136  virtual ParamFuncsDist* paramFuncsDist() = 0;
137 
140 public:
141  virtual void setState(StateSPtr& _otherState) = 0;
143 public:
144  virtual void
145  setStateCf(const double& _arc,
147 
148 public:
149  virtual void
150  setStateCfNmStep(const double& _arc,
152  {
153  setStateCf(_arc, _evalArcGuarantee);
154  }
157 private:
158  virtual State& stateNmDot() = 0;
161 private:
162  virtual State& stateNmDelta(const double& _dArc) = 0;
163 
164  template <std::size_t StateSize, std::size_t RKOrder, typename... RKCoeff>
165  friend void RungeKutta::discretize(StateSim& _stateSim, const double& _arc);
166  template <std::size_t StateSize, std::size_t StateNmSize>
167  friend class StateSimTemplate;
168 };
169 }
170 
171 #endif // STATE_SIM_H
void discretize(StateSim &_stateSim, const double &_arc)
Templetized generic discretization function.
virtual ParamFuncsDist * paramFuncsDist()=0
Returns (if applicable) reference of the parametric functions distance-extended structure. Otherwise returns nullptr.
virtual State & stateCf()=0
Reference to the actual closed-form state.
std::shared_ptr< StateSim const > StateSimConstSPtr
Definition: state_sim.h:55
std::shared_ptr< State > StateSPtr
Definition: state.h:129
virtual void advanceSet0(const double &_tEnd, const double &_dt)
Definition: state_sim.h:113
previous evaluation arc <= this evaluation arc
virtual ~StateSim()=default
virtual State & stateNm()=0
Reference to the actual numerical-computed state.
virtual double & value(const std::size_t &_i)=0
Access state variable based on index _i.
std::unique_ptr< StateSim > StateSimUPtr
Definition: state_sim.h:56
virtual StateSimUPtr cloneStateSim() const =0
Clone-to-base-class-ptr function.
std::unique_ptr< StateSim const > StateSimConstUPtr
Definition: state_sim.h:57
virtual ParamFuncs * paramFuncs()=0
Returns (if applicable) reference of the parametric functions structure. Otherwise returns nullptr...
virtual State & state0()=0
Reference to the initial state.
virtual void setState(StateSPtr &_otherState)=0
Sets the state variables to the values of _otherState. It also sets the control structure evaluation ...
virtual void setStateCfNmStep(const double &_arc, const ParamFuncs::EvalArcGuarantee &_evalArcGuarantee=ParamFuncs::EvalArcGuarantee::AFTER_LAST)
Definition: state_sim.h:150
DiscretizationType
Several discretization modes.
virtual void setDiscrType(const RungeKutta::DiscretizationType &_discrType)=0
Set discretization type used in the simulation.
Templated partial implementation of StateSim.
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
Definition: param_func.h:80
virtual size_t valueSize() const =0
Size of the state variables.
Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like...
Definition: state.h:135
virtual void advance(double _arc)=0
Performs one simulation step to parametrized arc length _arc.
virtual State & stateNmDot()=0
Computes numerical continuous arc state transition (return) based on internal closed-form state (stat...
std::shared_ptr< StateSim > StateSimSPtr
Definition: state_sim.h:54
Extends manipulation of parametric functions collection with closed-form arc length (distance) comput...
StateSim()=default
virtual void setStateCf(const double &_arc, const ParamFuncs::EvalArcGuarantee &_evalArcGuarantee=ParamFuncs::EvalArcGuarantee::AFTER_LAST)=0
Sets closed-form state at arc _arc.
virtual void toState0()=0
Resets entire state to state0. It also sets the control structure evaluation point at most at the new...
StateSim & operator=(const StateSim &)=default
Interface for a state simulator structure that performs numerical integration of not-closed-form stat...
Definition: state_sim.h:58
virtual double stateDist() const =0
Value of the current traveled distance of the state.
virtual State & stateNmDelta(const double &_dArc)=0
Computes numerical discrete state transition (return) based on internal closed-form state (stateCf ) ...
virtual double stateArc() const =0
Value of the current arc parametrization of the state.
Storage and manipulation of parametric functions collection.
Definition: param_func.h:57


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:22