mbsim 4.0.0 MBSim Kernel

time_stepping_ssc_integrator.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 * Contact: martin.o.foerg@googlemail.com
18 */
19
20 #ifndef _TIME_STEPPING_SSC_INTEGRATOR_H_
21 #define _TIME_STEPPING_SSC_INTEGRATOR_H_
22
23 #include "integrator.h"
24 #include "mbsim/utils/stopwatch.h"
25
26 namespace MBSim {
27 class Link;
28 }
29
30 namespace MBSim {
31
66 class TimeSteppingSSCIntegrator : public Integrator {
67
68 public:
69 enum Method {
70 extrapolation=0,
71 embedded,
72 embeddedHigherOrder,
73 unknownMethod
74 };
75
76 enum GapControl {
77 noGapControl=0,
78 biggestRoot,
79 scoring,
80 gapTolerance,
81 smallestRoot,
82 unknownGapControl
83 };
84
85 enum ErrorTest {
86 all=0,
87 scale=2,
88 exclude=3,
89 unknownErrorTest
90 };
91
92 protected:
93 void resize(MBSim::DynamicSystemSolver *system);
94
95 MBSim::DynamicSystemSolver* sysT1{NULL};
96 MBSim::DynamicSystemSolver* sysT2{NULL};
97 MBSim::DynamicSystemSolver* sysT3{NULL};
98
99 double dt{1e-6}, dtOld{1e-6}, dte{1e-6};
100 double dtMin{0}, dtMax{1e-3};
101 double dt_SSC_vorGapControl{0};
102 bool driftCompensation{false};
103 double t{0}, tPlot{0};
104 int qSize{0}, xSize{0}, uSize{0}, zSize{0};
105 fmatvec::Vec ze, zi, z1d, z2d, z2dRE, z3d, z4d, z6d, z2b, z3b, z4b, z6b, zStern;
106 fmatvec::VecInt LS, LSe, LStmp_T1, LStmp_T2, LStmp_T3, LSA, LSB1, LSB2, LSC1, LSC2, LSC3, LSC4, LSD1, LSD2, LSD3, LSD4, LSD5, LSD6;
107 fmatvec::Vec la, lae, la1d, la2b;
108 fmatvec::VecInt laSizes, laeSizes, la1dSizes, la2bSizes;
109 fmatvec::Vec gInActive, gdInActive;
110 std::vector<MBSim::Link*> SetValuedLinkListT1;
111 std::vector<MBSim::Link*> SetValuedLinkListT2;
112 std::vector<MBSim::Link*> SetValuedLinkListT3;
113
114 int StepsWithUnchangedConstraints{-1};
115
117 int FlagErrorTest{2};
119 bool FlagErrorTestAlwaysValid{true};
121 fmatvec::Vec aTol;
123 fmatvec::Vec rTol;
125 bool FlagSSC{true};
129 int maxOrder{1};
134 Method method{extrapolation};
135 /* Flag for Gap Control */
136 bool FlagGapControl{false};
138 double gapTol{1e-6};
140 double maxGainSSC{2.2};
142 double safetyFactorSSC{0.7};
144 bool FlagOutputOnlyAtTPlot{false};
146 bool FlagPlotEveryStep{false};
148 bool outputInterpolation{false};
150 double safetyFactorGapControl{-1};
158 GapControl GapControlStrategy{biggestRoot};
160 int numThreads{1};
162 double time{0};
164 MBSim::StopWatch Timer;
165 int iter{0}, iterA{0}, iterB1{0}, iterB2{0}, iterC1{0}, iterC2{0}, iterC3{0}, iterC4{0}, iterB2RE{0}, maxIterUsed{0}, maxIter{0}, sumIter{0};
166 int integrationSteps{0}, integrationStepswithChange{0}, refusedSteps{0}, refusedStepsWithImpact{0};
167 int wrongAlertGapControl{0}, stepsOkAfterGapControl{0}, stepsRefusedAfterGapControl{0}, statusGapControl{0};
168 int singleStepsT1{0}, singleStepsT2{0}, singleStepsT3{0};
169 double dtRelGapControl{1}, qUncertaintyByExtrapolation{0};
170 int indexLSException{-1};
171 fmatvec::Vec gUniActive;
172 double Penetration{0}, PenetrationCounter{0}, PenetrationLog{0}, PenetrationMin{0}, PenetrationMax{0};
173 double maxdtUsed{0}, mindtUsed{0};
174 bool ChangeByGapControl{false};
175 bool calcBlock2{0};
176 bool IterConvergence{0};
177 bool ConstraintsChanged{0}, ConstraintsChangedBlock1{0}, ConstraintsChangedBlock2{0};
178 int integrationStepsOrder1{0};
179 int integrationStepsOrder2{0};
180 int order{1};
181 int StepTrials{0};
182 int AnzahlAktiverKontakte{0};
183 double gNDurchschnittprostep{0};
184
185 fmatvec::Vec bi;
186
187 public:
189 ~TimeSteppingSSCIntegrator() override;
191 void setInitialStepSize(double dt_) { dt = dt_; }
193 void setMaximumStepSize(double dtMax_) { dtMax = dtMax_; }
195 void setMinimumStepSize(double dtMin_) { dtMin = dtMin_; }
197 void setMaximumGain(double maxGain) { maxGainSSC = maxGain; }
199 void setSafetyFactor(double sfactor) { safetyFactorSSC=sfactor; }
200 void setSafetyFactorForGapControl(double s) { safetyFactorGapControl = s; }
202 void setOutputInterpolation(bool flag) { outputInterpolation = flag; }
204 void setFlagOutputOnlyAtTPlot(bool flag) { FlagOutputOnlyAtTPlot = flag; }
214 void setGapControl(GapControl gapControl) { GapControlStrategy = gapControl; }
216 void setDriftCompensation(bool dc) { driftCompensation = dc; }
220 void setMaximumOrder(int maxOrder_) { maxOrder = maxOrder_; }
225 void setMethod(Method method_) { method = method_; }
226 /* deactivate step size control */
227 void setStepSizeControl(bool flag) { FlagSSC = flag; }
230 void setErrorTest(ErrorTest errorTest) { FlagErrorTest = errorTest; }
234 void setAlwaysValid(bool alwaysValid) { FlagErrorTestAlwaysValid = alwaysValid; }
235
237 using Integrator::integrate;
238 void integrate() override;
240 void integrate(MBSim::DynamicSystemSolver& systemT1_, MBSim::DynamicSystemSolver& systemT2_, MBSim::DynamicSystemSolver& systemT3_, int Threads=0);
241
242 void setAbsoluteTolerance(const fmatvec::Vec &aTol_) { aTol <<= aTol_; }
243 void setAbsoluteTolerance(double aTol_) { aTol.resize(1,fmatvec::INIT,aTol_); }
244 void setRelativeTolerance(const fmatvec::Vec &rTol_) { rTol <<= rTol_; }
245 void setRelativeTolerance(double rTol_) { rTol.resize(1,fmatvec::INIT,rTol_); }
246 void setgapTolerance(double gTol) { gapTol = gTol; }
247
250 void preIntegrate() override;
251 void subIntegrate(double tStop) override;
252 void postIntegrate() override;
253 void preIntegrate(MBSim::DynamicSystemSolver& systemT1_, MBSim::DynamicSystemSolver& systemT2_, MBSim::DynamicSystemSolver& systemT3_);
254
256 void getDataForGapControl();
257 bool testTolerances();
258 bool GapControl(double qUnsafe, bool SSCTestOK);
259 bool changedLinkStatus(const fmatvec::VecInt &L1, const fmatvec::VecInt &L2, int ex);
260 double calculatedtNewRel(const fmatvec::Vec &ErrorLocal, double H);
261 void plot();
262
263 virtual void initializeUsingXML(xercesc::DOMElement *element) override;
264
265 void updatebi();
266 void updatela();
267 void updatezd();
268 };
269
270 }
271
272 #endif
MBSim::TimeSteppingSSCIntegrator::FlagSSC
bool FlagSSC
Definition: time_stepping_ssc_integrator.h:125
MBSim::TimeSteppingSSCIntegrator::aTol
fmatvec::Vec aTol
Definition: time_stepping_ssc_integrator.h:121
MBSim::TimeSteppingSSCIntegrator::setDriftCompensation
void setDriftCompensation(bool dc)
Definition: time_stepping_ssc_integrator.h:216
MBSim::TimeSteppingSSCIntegrator::numThreads
int numThreads
Definition: time_stepping_ssc_integrator.h:160
MBSim::TimeSteppingSSCIntegrator::safetyFactorGapControl
double safetyFactorGapControl
Definition: time_stepping_ssc_integrator.h:150
MBSim::TimeSteppingSSCIntegrator::setOutputInterpolation
void setOutputInterpolation(bool flag)
Definition: time_stepping_ssc_integrator.h:202
MBSim::DynamicSystemSolver
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:61
MBSim::TimeSteppingSSCIntegrator::initializeUsingXML
virtual void initializeUsingXML(xercesc::DOMElement *element) override
initialize integrator
Definition: time_stepping_ssc_integrator.cc:1414
MBSim::TimeSteppingSSCIntegrator::~TimeSteppingSSCIntegrator
~TimeSteppingSSCIntegrator() override
Definition: time_stepping_ssc_integrator.cc:45
MBSim::TimeSteppingSSCIntegrator::setSafetyFactor
void setSafetyFactor(double sfactor)
Definition: time_stepping_ssc_integrator.h:199
MBSim::Integrator
integrator-interface for dynamic systems
Definition: integrator.h:37
MBSim::TimeSteppingSSCIntegrator::preIntegrate
void preIntegrate() override
Definition: time_stepping_ssc_integrator.cc:62
MBSim::TimeSteppingSSCIntegrator::setGapControl
void setGapControl(GapControl gapControl)
Definition: time_stepping_ssc_integrator.h:214
MBSim::TimeSteppingSSCIntegrator::setErrorTest
void setErrorTest(ErrorTest errorTest)
Definition: time_stepping_ssc_integrator.h:230
MBSim::TimeSteppingSSCIntegrator::rTol
fmatvec::Vec rTol
Definition: time_stepping_ssc_integrator.h:123
MBSim::Solver::system
MBSim::DynamicSystemSolver * system
dynamic system
Definition: solver.h:79
MBSim::Integrator::integrate
virtual void integrate()=0
start the integration of the system set by setSystem. Each class implemeting this function should cal...
MBSim::TimeSteppingSSCIntegrator::setAlwaysValid
void setAlwaysValid(bool alwaysValid)
Definition: time_stepping_ssc_integrator.h:234
MBSim::TimeSteppingSSCIntegrator
Half-explicit time-stepping integrator of first or higer order with StepSize Control (SSC) important ...
Definition: time_stepping_ssc_integrator.h:66
MBSim::StopWatch
Definition: stopwatch.h:35
MBSim::TimeSteppingSSCIntegrator::setMaximumOrder
void setMaximumOrder(int maxOrder_)
Definition: time_stepping_ssc_integrator.h:220
MBSim::TimeSteppingSSCIntegrator::setMaximumStepSize
void setMaximumStepSize(double dtMax_)
Definition: time_stepping_ssc_integrator.h:193
MBSim::TimeSteppingSSCIntegrator::FlagErrorTest
int FlagErrorTest
Definition: time_stepping_ssc_integrator.h:117
MBSim::TimeSteppingSSCIntegrator::gapTol
double gapTol
Definition: time_stepping_ssc_integrator.h:138
MBSim::TimeSteppingSSCIntegrator::setMethod
void setMethod(Method method_)
Definition: time_stepping_ssc_integrator.h:225
MBSim::TimeSteppingSSCIntegrator::maxGainSSC
double maxGainSSC
Definition: time_stepping_ssc_integrator.h:140
MBSim::TimeSteppingSSCIntegrator::outputInterpolation
bool outputInterpolation
Definition: time_stepping_ssc_integrator.h:148
MBSim::TimeSteppingSSCIntegrator::method
Method method
Definition: time_stepping_ssc_integrator.h:134
MBSim::TimeSteppingSSCIntegrator::setMinimumStepSize
void setMinimumStepSize(double dtMin_)
Definition: time_stepping_ssc_integrator.h:195
MBSim::TimeSteppingSSCIntegrator::FlagOutputOnlyAtTPlot
bool FlagOutputOnlyAtTPlot
Definition: time_stepping_ssc_integrator.h:144
MBSim::TimeSteppingSSCIntegrator::GapControlStrategy
GapControl GapControlStrategy
Definition: time_stepping_ssc_integrator.h:158
MBSim::TimeSteppingSSCIntegrator::time
double time
Definition: time_stepping_ssc_integrator.h:162
MBSim::TimeSteppingSSCIntegrator::safetyFactorSSC
double safetyFactorSSC
Definition: time_stepping_ssc_integrator.h:142
MBSim::TimeSteppingSSCIntegrator::maxOrder
int maxOrder
Definition: time_stepping_ssc_integrator.h:129
MBSim::TimeSteppingSSCIntegrator::setInitialStepSize
void setInitialStepSize(double dt_)
Definition: time_stepping_ssc_integrator.h:191
MBSim::TimeSteppingSSCIntegrator::FlagErrorTestAlwaysValid
bool FlagErrorTestAlwaysValid
Definition: time_stepping_ssc_integrator.h:119
MBSim::TimeSteppingSSCIntegrator::integrate
void integrate() override
start the integration of the system set by setSystem. Each class implemeting this function should cal...
Definition: time_stepping_ssc_integrator.cc:51
MBSim::TimeSteppingSSCIntegrator::Timer
MBSim::StopWatch Timer
Definition: time_stepping_ssc_integrator.h:164
MBSim::TimeSteppingSSCIntegrator::getDataForGapControl
void getDataForGapControl()
Definition: time_stepping_ssc_integrator.cc:1387
MBSim::TimeSteppingSSCIntegrator::FlagPlotEveryStep
bool FlagPlotEveryStep
Definition: time_stepping_ssc_integrator.h:146
MBSim::TimeSteppingSSCIntegrator::setMaximumGain
void setMaximumGain(double maxGain)
Definition: time_stepping_ssc_integrator.h:197
MBSim::TimeSteppingSSCIntegrator::setFlagOutputOnlyAtTPlot
void setFlagOutputOnlyAtTPlot(bool flag)
Definition: time_stepping_ssc_integrator.h:204
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30