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

  1#ifndef TimeStepping_H
  2#define TimeStepping_H
  3
  4#include "Simulation.hpp"
  5
  6
  7typedef void (*CheckSolverFPtr)(int, Simulation *);
  8
  9
 10
 11#define SICONOS_TS_LINEAR 1
 12#define SICONOS_TS_LINEAR_IMPLICIT 2
 13#define SICONOS_TS_NONLINEAR 3
 14#define SICONOS_TS_NONLINEAR_FULL 4
 15
 16class TimeStepping : public Simulation {
 17protected:
 18  ACCEPT_SERIALIZATION(TimeStepping);
 19
 20
 21  double _newtonTolerance;
 22
 23
 24  unsigned int _newtonMaxIteration;
 25
 26
 27  unsigned int _newtonNbIterations;
 28
 29
 30  unsigned int _newtonCumulativeNbIterations;
 31
 32
 33  unsigned int _newtonOptions;
 34
 35
 36  double _newtonResiduDSMax;
 37
 38
 39  double _newtonResiduYMax;
 40
 41
 42  double _newtonResiduRMax;
 43
 44
 45  bool _computeResiduY;
 46
 47
 48  bool _computeResiduR;
 49
 50
 51  bool _isNewtonConverge;
 52
 53
 54  bool _newtonUpdateInteractionsPerIteration;
 55
 56
 57  bool _displayNewtonConvergence;
 58
 59
 60  bool _newtonWarningOnNonConvergence;
 61
 62
 63  bool _warningNonsmoothSolver;
 64
 65
 66  bool _resetAllLambda;
 67
 68
 69  bool _skip_last_updateOutput;
 70
 71
 72  bool _skip_last_updateInput;
 73
 74
 75  bool _skip_resetLambdas;
 76
 77
 78  TimeStepping()
 79      : _computeResiduY(false), _computeResiduR(false),
 80        _isNewtonConverge(false){};
 81
 82
 83  virtual void newtonSolve(double criterion, unsigned int maxStep);
 84
 85public:
 86
 87  void initOSNS() override;
 88
 89
 90  TimeStepping(SP::NonSmoothDynamicalSystem nsds, SP::TimeDiscretisation td,
 91               SP::OneStepIntegrator osi, SP::OneStepNSProblem osnspb);
 92
 93
 94  TimeStepping(SP::NonSmoothDynamicalSystem nsds, SP::TimeDiscretisation td,
 95               int nb = 0);
 96
 97
 98  void insertIntegrator(SP::OneStepIntegrator osi) override;
 99
100
101  virtual ~TimeStepping() noexcept = default;
102
103
104  void updateIndexSet(unsigned int i) override;
105
106
107
108
109
110
111
112
113
114
115
116
117  virtual void nextStep();
118
119
120  void computeFreeState();
121
122
123  void resetLambdas();
124
125
126  void advanceToEvent() override;
127
128
129  void computeOneStep();
130
131
132  unsigned int getNewtonNbIterations() { return _newtonNbIterations; }
133
134
135  unsigned int getNewtonCumulativeNbIterations()
136  {
137    return _newtonCumulativeNbIterations;
138  }
139
140
141  void initializeNewtonSolve();
142  void computeInitialStateOfTheStep() override;
143  void prepareNewtonIteration();
144
145
146  bool newtonCheckConvergence(double criterion);
147
148
149  void run() override;
150
151
152  void DefaultCheckSolverOutput(int info);
153
154
155  void setCheckSolverFunction(CheckSolverFPtr newF);
156
157  bool isNewtonConverge() { return _isNewtonConverge; };
158
159  bool displayNewtonConvergence() { return _displayNewtonConvergence; };
160  void setDisplayNewtonConvergence(bool newval)
161  {
162    _displayNewtonConvergence = newval;
163  };
164
165  void setNewtonWarningOnNonConvergence(bool newval) { _newtonWarningOnNonConvergence = newval; };
166  bool newtonWarningOnNonConvergence() { return _newtonWarningOnNonConvergence; };
167
168  void setWarningNonsmoothSolver(bool newval) {  _warningNonsmoothSolver=newval;};
169  bool warningNonsmoothSolver() {  return _warningNonsmoothSolver;};
170
171
172
173
174  void displayNewtonConvergenceAtTheEnd(int info, unsigned int maxStep);
175  void displayNewtonConvergenceInTheLoop();
176
177  void setResetAllLambda(bool newval) { _resetAllLambda = newval; };
178
179  void setSkipLastUpdateOutput(bool newval)
180  {
181    _skip_last_updateOutput = newval;
182  };
183  bool skipLastUpdateOutput() { return _skip_last_updateOutput; };
184  void setSkipLastUpdateInput(bool newval) { _skip_last_updateInput = newval; };
185  bool skipLastUpdateInput() { return _skip_last_updateInput; };
186  void setSkipResetLambdas(bool newval) { _skip_resetLambdas = newval; };
187  bool skipResetLambdas() { return _skip_resetLambdas; };
188
189
190  void setComputeResiduY(bool v) { _computeResiduY = v; };
191
192
193  bool computeResiduY() override { return _computeResiduY; };
194
195
196  void setComputeResiduR(bool v) { _computeResiduR = v; };
197
198
199  bool computeResiduR() override { return _computeResiduR; };
200
201
202  void setNewtonTolerance(double tol) { _newtonTolerance = tol; };
203
204
205  double newtonTolerance() { return _newtonTolerance; };
206
207
208  void setNewtonMaxIteration(unsigned int maxStep)
209  {
210    _newtonMaxIteration = maxStep;
211  };
212
213
214  unsigned int newtonMaxIteration() { return _newtonMaxIteration; };
215
216
217  void setNewtonOptions(unsigned int v) { _newtonOptions = v; };
218
219
220  unsigned int newtonOptions() { return _newtonOptions; };
221
222
223  double newtonResiduDSMax() { return _newtonResiduDSMax; };
224
225
226  double newtonResiduYMax() { return _newtonResiduYMax; };
227
228
229  double newtonResiduRMax() { return _newtonResiduRMax; };
230
231  ACCEPT_STD_VISITORS();
232};
233
234#endif