Program listing for file kernel/src/simulationTools/OneStepIntegrator.hpp

Program listing for file kernel/src/simulationTools/OneStepIntegrator.hpp#

  1#ifndef ONESTEPINTEGRATOR_H
  2#define ONESTEPINTEGRATOR_H
  3
  4#include "SiconosVisitor.hpp"
  5#include "SiconosException.hpp"
  6#include "SimulationTypeDef.hpp"
  7#include "OneStepIntegratorTypes.hpp"
  8#include "SimulationGraphs.hpp"
  9#include "Simulation.hpp"
 10
 11
 12class OneStepIntegrator :public std::enable_shared_from_this<OneStepIntegrator>
 13{
 14
 15protected:
 16
 17  ACCEPT_SERIALIZATION(OneStepIntegrator);
 18
 19
 20  OSI::TYPES _integratorType;
 21
 22
 23  SP::DynamicalSystemsGraph _dynamicalSystemsGraph;
 24
 25
 26  unsigned int _sizeMem;
 27
 28
 29  unsigned int _steps;
 30
 31
 32  unsigned int _levelMinForOutput;
 33
 34
 35  unsigned int _levelMaxForOutput;
 36
 37
 38  unsigned int _levelMinForInput;
 39
 40
 41  unsigned int _levelMaxForInput;
 42
 43  bool _isInitialized;
 44
 45
 46
 47  bool _explicitJacobiansOfRelation;
 48
 49
 50
 51
 52  SP::Simulation _simulation;
 53
 54
 55  OneStepIntegrator(const OSI::TYPES& type)
 56    : _integratorType(type), _sizeMem(1), _steps(0),
 57      _levelMinForOutput(0), _levelMaxForOutput(0),
 58      _levelMinForInput(0), _levelMaxForInput(0),
 59      _isInitialized(false), _explicitJacobiansOfRelation(false) {};
 60
 61
 62  SP::ExtraAdditionalTerms _extraAdditionalTerms;
 63
 64
 65  void _check_and_update_interaction_levels(Interaction& inter);
 66
 67
 68  SP::VectorOfVectors _initializeDSWorkVectors(SP::DynamicalSystem ds);
 69
 70
 71  OneStepIntegrator() {};
 72
 73private:
 74
 75
 76  OneStepIntegrator(const OneStepIntegrator&);
 77
 78
 79  OneStepIntegrator& operator=(const OneStepIntegrator& OSI);
 80
 81
 82public:
 83
 84
 85  virtual ~OneStepIntegrator() {};
 86
 87
 88  inline OSI::TYPES getType() const
 89  {
 90    return _integratorType;
 91  }
 92
 93
 94  inline SP::DynamicalSystemsGraph dynamicalSystemsGraph() const
 95  {
 96    return _dynamicalSystemsGraph;
 97  };
 98
 99
100  inline void setDynamicalSystemsGraph(SP::DynamicalSystemsGraph dsg)
101  {
102    _dynamicalSystemsGraph = dsg;
103  };
104
105
106  inline unsigned int getSizeMem() const
107  {
108    return _sizeMem;
109  };
110
111
112  inline SP::Simulation simulation() const
113  {
114    return _simulation;
115  }
116
117
118  inline void setSimulationPtr(SP::Simulation newS)
119  {
120    _simulation = newS;
121  }
122
123
124  virtual unsigned int levelMinForOutput()
125  {
126    return _levelMinForOutput;
127  }
128
129
130  virtual unsigned int levelMaxForOutput()
131  {
132    return _levelMaxForOutput;
133  }
134
135
136  virtual unsigned int levelMinForInput()
137  {
138    return _levelMinForInput;
139  }
140
141
142  virtual unsigned int levelMaxForInput()
143  {
144    return _levelMaxForInput;
145  }
146
147
148  virtual unsigned int numberOfIndexSets() const = 0;
149
150  inline bool isInitialized(){return _isInitialized;};
151
152  inline void setIsInitialized( bool value) {_isInitialized = value;};
153
154  bool explicitJacobiansOfRelation()
155  {
156  return  _explicitJacobiansOfRelation;
157  }
158
159  void setExplicitJacobiansOfRelation(bool newval)
160  {
161    _explicitJacobiansOfRelation = newval;
162  };
163
164
165  virtual void initialize();
166
167
168  virtual void initialize_nonsmooth_problems(){};
169
170
171  virtual void initializeWorkVectorsForDS(double t, SP::DynamicalSystem ds) = 0 ;
172
173
174  virtual void initializeWorkVectorsForInteraction(Interaction &inter,
175                             InteractionProperties& interProp,
176                             DynamicalSystemsGraph & DSG) = 0 ;
177
178
179
180  void UpdateAndSwapAllOutput(double time);
181
182
183  void UpdateAndSwapAllOutput(Interaction& inter, double time);
184
185
186  virtual void computeInitialNewtonState(){
187
188  }
189
190
191  virtual double computeResidu(){
192
193    THROW_EXCEPTION("OneStepIntegrator::computeResidu not implemented for integrator of type " + std::to_string(_integratorType));
194    return 0.0;
195  }
196
197
198  virtual void computeFreeState()
199  {
200
201    THROW_EXCEPTION("OneStepIntegrator::computeFreeState not implemented for integrator of type " + std::to_string(_integratorType));
202  }
203
204
205  virtual void computeFreeOutput(InteractionsGraph::VDescriptor& vertex_inter, OneStepNSProblem* osnsp)
206  {
207
208    THROW_EXCEPTION("OneStepIntegrator::computeFreeOutput not implemented for integrator of type " + std::to_string(_integratorType));
209  }
210
211
212  virtual double computeResiduOutput(double time, SP::InteractionsGraph indexSet);
213
214  virtual double computeResiduInput(double time, SP::InteractionsGraph indexSet);
215
216
217  virtual void integrate(double& tinit, double& tend, double& tout, int& idid) = 0;
218
219
220  void resetAllNonSmoothParts();
221
222
223  void resetNonSmoothPart(unsigned int level);
224
225
226  virtual void updateState(const unsigned int level) = 0;
227
228
229  void updateState() { updateState(0); }
230
231
232  virtual void updateOutput(double time);
233
234
235  virtual void updateInput(double time);
236
237
238  virtual void updateOutput(double time, unsigned int level);
239
240
241  virtual void updateInput(double time, unsigned int level);
242
243  virtual void prepareNewtonIteration(double time) = 0;
244
245
246  virtual void display() = 0;
247
248
249  virtual bool addInteractionInIndexSet(SP::Interaction inter, unsigned int i)
250  {
251    THROW_EXCEPTION("OneStepIntegrator::addInteractionInIndexSet - Should be called at this level");
252    return 0;
253  }
254  ;
255
256
257  virtual bool removeInteractionFromIndexSet(SP::Interaction inter, unsigned int i)
258  {
259    THROW_EXCEPTION("OneStepIntegrator::removeInteractionFromIndexSet - Should not be called at this level");
260    return 0;
261  };
262
263
264  inline SP::ExtraAdditionalTerms extraAdditionalTerms()
265  {
266    return _extraAdditionalTerms;
267  }
268
269
270  inline void setExtraAdditionalTerms(SP::ExtraAdditionalTerms eat)
271  {
272    _extraAdditionalTerms = eat;
273  }
274
275  inline bool checkOSI(DynamicalSystemsGraph::VIterator dsi)
276  {
277    return  (_dynamicalSystemsGraph->properties(*dsi).osi.get()) == this;
278  };
279
280
281  inline bool checkOSI(DynamicalSystemsGraph::VDescriptor dsgv)
282  {
283    return  (_dynamicalSystemsGraph->properties(dsgv).osi.get()) == this;
284  };
285
286
287  inline bool checkInteractionOSI(InteractionsGraph & indexSet0, InteractionsGraph::VIterator ui)
288  {
289    return  (indexSet0.properties(*ui).osi1.get()) == this;
290  };
291
292  virtual SiconosVector& osnsp_rhs(InteractionsGraph::VDescriptor& vertex_inter,  InteractionsGraph& indexSet) = 0;
293
294
295  VIRTUAL_ACCEPT_VISITORS(OneStepIntegrator);
296
297};
298
299#endif