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

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

  1#ifndef SIMULATION_H
  2#define SIMULATION_H
  3
  4#include <fstream>
  5
  6#include "InteractionManager.hpp"
  7#include "NonSmoothDynamicalSystem.hpp"
  8#include "SiconosConst.hpp"
  9#include "SiconosFwd.hpp"
 10#include "SimulationTypeDef.hpp"
 11
 12
 13
 14class Simulation : public std::enable_shared_from_this<Simulation> {
 15 protected:
 16  ACCEPT_SERIALIZATION(Simulation);
 17
 18
 19  std::string _name;
 20
 21
 22  SP::EventsManager _eventsManager;
 23
 24
 25  double _tinit;
 26
 27
 28  double _tend;
 29
 30
 31  double _tout;
 32
 33  double _T;
 34
 35
 36  SP::OSISet _allOSI;
 37
 38
 39  SP::OneStepNSProblems _allNSProblems;
 40
 41
 42  SP::NonSmoothDynamicalSystem _nsds;
 43
 44
 45  SP::InteractionManager _interman;
 46
 47
 48  unsigned int _numberOfIndexSets;
 49
 50
 51  double _tolerance;
 52
 53
 54  bool _printStat;
 55
 56
 57  bool _staticLevels;
 58
 59
 60  std::ofstream statOut;
 61
 62
 63  bool _useRelativeConvergenceCriterion;
 64
 65  bool _relativeConvergenceCriterionHeld;
 66
 67  double _relativeConvergenceTol;
 68
 69  bool _isInitialized;
 70
 71
 72  NonSmoothDynamicalSystem::ChangeLogIter _nsdsChangeLogPosition;
 73
 74
 75  std::map<SP::OneStepIntegrator, std::list<SP::DynamicalSystem> > _OSIDSmap;
 76
 77 private:
 78
 79  Simulation(const Simulation&);
 80
 81
 82  Simulation& operator=(const Simulation&);
 83
 84 public:
 85
 86  Simulation(){};
 87
 88
 89  Simulation(SP::NonSmoothDynamicalSystem nsds, SP::TimeDiscretisation td);
 90
 91
 92  Simulation(SP::TimeDiscretisation td);
 93
 94
 95  virtual ~Simulation();
 96
 97
 98  void clear();
 99
100
101
102
103  inline const std::string name() const { return _name; }
104
105
106  inline void setName(const std::string& newName) { _name = newName; }
107
108
109  double getTk() const;
110
111
112  double getTkp1() const;
113
114
115  double getTkp2() const;
116
117
118  double currentTimeStep() const;
119
120
121  inline SP::EventsManager eventsManager() const { return _eventsManager; };
122
123
124  double startingTime() const;
125
126
127  double nextTime() const;
128
129
130  inline double timeStep() const { return (nextTime() - startingTime()); };
131
132
133  bool hasNextEvent() const;
134
135
136  inline const SP::OSISet oneStepIntegrators() const { return _allOSI; };
137
138
139  inline size_t numberOfOSI() const { return _allOSI->size(); }
140
141
142  virtual void insertIntegrator(SP::OneStepIntegrator osi);
143
144
145  void associate(SP::OneStepIntegrator osi, SP::DynamicalSystem ds);
146
147
148  SP::InteractionsGraph indexSet(unsigned int i);
149
150
151  inline const SP::OneStepNSProblems oneStepNSProblems() const { return _allNSProblems; };
152
153
154  inline size_t numberOfOSNSProblems() const { return _allNSProblems->size(); }
155
156
157  SP::OneStepNSProblem oneStepNSProblem(int id);
158
159
160  virtual void insertNonSmoothProblem(SP::OneStepNSProblem osns,
161                                      int Id = SICONOS_OSNSP_DEFAULT);
162
163
164  inline SP::NonSmoothDynamicalSystem nonSmoothDynamicalSystem() const { return _nsds; }
165
166  void setNonSmoothDynamicalSystemPtr(SP::NonSmoothDynamicalSystem newPtr) {
167    _nsdsChangeLogPosition = _nsds->changeLogBegin();
168    _nsds = newPtr;
169  }
170
171
172  double tolerance() const { return _tolerance; };
173
174
175  void setTolerance(double inputVal) { _tolerance = inputVal; };
176
177
178  inline void setPrintStat(const bool& newVal) { _printStat = newVal; };
179
180
181  inline bool getPrintStat() const { return _printStat; };
182  virtual void computeInitialStateOfTheStep(){};
183
184
185  void updateIndexSets();
186
187
188  virtual void updateIndexSet(unsigned int level) = 0;
189
190
191  virtual void initialize();
192
193
194  virtual void initializeInteraction(double time, SP::Interaction inter);
195
196
197  void insertInteractionManager(SP::InteractionManager manager) { _interman = manager; }
198
199
200  void computeResidu();
201
202
203  int computeOneStepNSProblem(int nb);
204
205
206  virtual void updateDSPlugins(double time);
207
208
209  virtual void updateInput(unsigned int level);
210
211
212  virtual void updateAllInput();
213
214  virtual void updateState(unsigned int level = 0);
215
216
217  virtual void updateOutput(unsigned int level = 0);
218
219
220  void update(unsigned int level = 0) {
221    updateInput(level);
222    updateState(level);
223    updateOutput(level);
224  }
225
226
227  virtual void run();
228
229
230  virtual void initializeOneStepNSProblem() = 0;
231
232
233  virtual void advanceToEvent() = 0;
234
235
236  void clearNSDSChangeLog();
237
238
239  inline void setUseRelativeConvergenceCriteron(bool use) {
240    _useRelativeConvergenceCriterion = use;
241  };
242
243  inline bool useRelativeConvergenceCriteron() { return _useRelativeConvergenceCriterion; };
244
245
246  inline void setRelativeConvergenceTol(double v) { _relativeConvergenceTol = v; };
247
248
249  inline double relativeConvergenceTol() { return _relativeConvergenceTol; };
250
251
252  inline void setRelativeConvergenceCriterionHeld(bool newVal) {
253    _relativeConvergenceCriterionHeld = newVal;
254  };
255
256  inline bool relativeConvergenceCriterionHeld() { return _relativeConvergenceCriterionHeld; };
257
258
259  SP::SiconosVector lambda(unsigned int level = 0, unsigned int coor = 0);
260
261
262  SP::SiconosVector y(unsigned int level = 0, unsigned int coor = 0);
263
264
265  void processEvents();
266
267
268  void setStaticLevels(bool b) { _staticLevels = b; }
269
270
271  void updateT(double T);
272
273  virtual bool computeResiduY() { return false; };
274
275  virtual bool computeResiduR() { return false; };
276
277
278  void link(SP::Interaction inter, SP::DynamicalSystem ds1,
279            SP::DynamicalSystem ds2 = SP::DynamicalSystem());
280
281
282  void unlink(SP::Interaction inter);
283
284
285  void updateInteractions();
286
287
288  virtual void updateWorldFromDS() { ; };
289
290
291  void initializeOSIAssociations();
292
293
294  void initializeNSDSChangelog();
295
296  void applyNSDSChangelogForDS();
297
298
299  void initializeIndexSets();
300
301
302  virtual void firstInitialize();
303
304  VIRTUAL_ACCEPT_VISITORS(Simulation);
305};
306
307#endif