MBSim

Project Page
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:
18  * rhuber@users.berlios.de
19  */
20 
21 #ifndef _TIME_STEPPING_SSC_INTEGRATOR_H_
22 #define _TIME_STEPPING_SSC_INTEGRATOR_H_
23 
24 #include<fmatvec.h>
25 #include "integrator.h"
26 #include "mbsim/utils/stopwatch.h"
27 
28 namespace MBSim {
29 
30  class Link;
31 
67 
68  protected:
69  DynamicSystemSolver* sysT1;
70  DynamicSystemSolver* sysT2;
71  DynamicSystemSolver* sysT3;
72 
73  double dt, dtOld, dte;
74  double dtMin, dtMax;
75  double dt_SSC_vorGapControl;
76  bool driftCompensation;
77  double t, tPlot;
78  int qSize, xSize, uSize, zSize;
79  fmatvec::Vec ze, zi, zT1, zT2, zT3, z1d, z2d, z2dRE, z3d, z4d, z6d, z2b, z3b, z4b, z6b, zStern;
80  fmatvec::Vector<int> LS, LSe, LStmp_T1, LStmp_T2, LStmp_T3, LSA, LSB1, LSB2, LSC1, LSC2, LSC3, LSC4, LSD1, LSD2, LSD3, LSD4, LSD5, LSD6;
81  fmatvec::Vec la, lae, la1d, la2b;
82  fmatvec::Vector<int> laSizes, laeSizes, la1dSizes, la2bSizes;
83  fmatvec::Vec qT1, qT2, qT3;
84  fmatvec::Vec uT1, uT2, uT3;
85  fmatvec::Vec xT1, xT2, xT3;
86  fmatvec::Vec gInActive, gdInActive;
87  std::vector<MBSim::Link*> SetValuedLinkListT1;
88  std::vector<MBSim::Link*> SetValuedLinkListT2;
89  std::vector<MBSim::Link*> SetValuedLinkListT3;
90 
91  int StepsWithUnchangedConstraints;
92 
98  fmatvec::Vec aTol;
100  fmatvec::Vec rTol;
102  bool FlagSSC;
106  int maxOrder;
111  int method;
112  /* Flag for Gap Control */
113  bool FlagGapControl;
115  double gapTol;
117  double maxGainSSC;
121  std::ofstream integPlot;
145  double time;
148  int iter, iterA, iterB1, iterB2, iterC1, iterC2, iterC3, iterC4, iterB2RE, maxIterUsed, maxIter, sumIter;
149  int integrationSteps, integrationStepswithChange, refusedSteps, refusedStepsWithImpact;
150  int wrongAlertGapControl, stepsOkAfterGapControl, stepsRefusedAfterGapControl, statusGapControl;
151  int singleStepsT1, singleStepsT2, singleStepsT3;
152  double dtRelGapControl, qUncertaintyByExtrapolation;
153  int indexLSException;
154  fmatvec::Vec gUniActive;
155  double Penetration, PenetrationCounter, PenetrationLog, PenetrationMin, PenetrationMax;
156  double maxdtUsed, mindtUsed;
157  bool ChangeByGapControl;
158  bool calcBlock2;
159  bool IterConvergence;
160  bool ConstraintsChanged, ConstraintsChangedBlock1, ConstraintsChangedBlock2;
161  int integrationStepsOrder1;
162  int integrationStepsOrder2;
163  int order;
164  int StepTrials;
165  int AnzahlAktiverKontakte;
166  double gNDurchschnittprostep;
167 
168  public:
174  void setInitialStepSize(double dt_) {dt = dt_;}
176  void setStepSizeMax(double dtMax_) {dtMax = dtMax_;}
178  void setStepSizeMin(double dtMin_) {dtMin = dtMin_;}
180  void setmaxGainSSC(double maxGain) {maxGainSSC = maxGain;}
182  void setSafetyFactorSSC(double sfactor) {safetyFactorSSC=sfactor;}
183  void setSafetyFactorGapControl(double s){safetyFactorGapControl=s;}
185  void setOutputInterpolation(bool flag=true) {outputInterpolation = flag;}
187  void setFlagPlotIntegrator(bool flag=true) {FlagPlotIntegrator = flag;}
197  void setGapControl(int strategy=1) {FlagGapControl=(strategy>=0); GapControlStrategy=(strategy<0)?0:strategy; }
199  void setDriftCompensation(bool dc) {driftCompensation = dc;}
204  void setMaxOrder(int order_, int method_=0);
205  /* deactivate step size control */
206  void deactivateSSC(bool flag=false) {FlagSSC=flag;}
211  void setFlagErrorTest(int Flag, bool alwaysValid=true);
212 
214  void integrate(DynamicSystemSolver& system_);
216  void integrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_, int Threads=0);
217 
218  void setAbsoluteTolerance(const fmatvec::Vec &aTol_) {aTol.resize() = aTol_;}
219  void setAbsoluteTolerance(double aTol_) {aTol.resize() = fmatvec::Vec(1,fmatvec::INIT,aTol_);}
220  void setRelativeTolerance(const fmatvec::Vec &rTol_) {rTol.resize() = rTol_;}
221  void setRelativeTolerance(double rTol_) {rTol.resize() = fmatvec::Vec(1,fmatvec::INIT,rTol_);}
222  void setgapTolerance(double gTol) {gapTol = gTol;}
223 
226  void preIntegrate(DynamicSystemSolver& system);
227  void subIntegrate(DynamicSystemSolver& system, double tStop);
228  void postIntegrate(DynamicSystemSolver& system);
229  void preIntegrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_);
230 
232  void getAllSetValuedla(fmatvec::Vec& la_,fmatvec::Vector<int>& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
233  void setAllSetValuedla(const fmatvec::Vec& la_,const fmatvec::Vector<int>& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
234  void getDataForGapControl();
235  bool testTolerances();
236  bool GapControl(double qUnsafe, bool SSCTestOK);
237  bool changedLinkStatus(const fmatvec::Vector<int> &L1, const fmatvec::Vector<int> &L2, int ex);
238  double calculatedtNewRel(const fmatvec::Vec &ErrorLocal, double H);
239  void plot();
240 
241  virtual void initializeUsingXML(TiXmlElement *element);
242  };
243 
244 }
245 
246 #endif