MBSim

Project Page
time_stepping_ssc_integrator.h
00001 /* Copyright (C) 2004-2009  MBSim Development Team
00002 
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact:
00018  *   rhuber@users.berlios.de
00019  */
00020 
00021 #ifndef _TIME_STEPPING_SSC_INTEGRATOR_H_ 
00022 #define _TIME_STEPPING_SSC_INTEGRATOR_H_
00023 
00024 #include "integrator.h"
00025 #include "mbsim/utils/stopwatch.h"
00026 
00027 namespace MBSim {
00028   
00029   class Link;
00030 
00065   class TimeSteppingSSCIntegrator : public Integrator { 
00066 
00067     protected:
00068       DynamicSystemSolver* sysT1;
00069       DynamicSystemSolver* sysT2;
00070       DynamicSystemSolver* sysT3;
00071 
00072       double dt, dtOld, dte;
00073       double dtMin, dtMax;
00074       double dt_SSC_vorGapControl;
00075       bool driftCompensation;
00076       double t, tPlot;
00077       int qSize, xSize, uSize, zSize;
00078       fmatvec::Vec ze, zi, zT1, zT2, zT3, z1d, z2d, z2dRE, z3d, z4d, z6d, z2b, z3b, z4b, z6b, zStern;
00079       fmatvec::VecInt LS, LSe, LStmp_T1, LStmp_T2, LStmp_T3, LSA, LSB1, LSB2, LSC1, LSC2, LSC3, LSC4, LSD1, LSD2, LSD3, LSD4, LSD5, LSD6;
00080       fmatvec::Vec la, lae, la1d, la2b;
00081       fmatvec::VecInt laSizes, laeSizes, la1dSizes, la2bSizes;
00082       fmatvec::Vec qT1, qT2, qT3;
00083       fmatvec::Vec uT1, uT2, uT3;
00084       fmatvec::Vec xT1, xT2, xT3;
00085       fmatvec::Vec gInActive, gdInActive;
00086       std::vector<MBSim::Link*> SetValuedLinkListT1;
00087       std::vector<MBSim::Link*> SetValuedLinkListT2;
00088       std::vector<MBSim::Link*> SetValuedLinkListT3;
00089 
00090       int StepsWithUnchangedConstraints;
00091 
00093       int FlagErrorTest;
00095       bool FlagErrorTestAlwaysValid;
00097       fmatvec::Vec aTol;
00099       fmatvec::Vec rTol;
00101       bool FlagSSC;
00105       int maxOrder;
00110       int method;
00111       /* Flag for Gap Control */
00112       bool FlagGapControl;
00114       double gapTol;
00116       double maxGainSSC;
00118       double safetyFactorSSC; 
00120       std::ofstream integPlot;
00122       bool FlagPlotIntegrator;
00124       bool FlagPlotIntegrationSum;
00126       bool FlagCoutInfo;
00128       bool FlagOutputOnlyAtTPlot;
00130       bool FlagPlotEveryStep;
00132       bool outputInterpolation;
00134       double safetyFactorGapControl;
00142       int GapControlStrategy;
00144       int numThreads;
00146       double time;
00148       StopWatch Timer;
00149       int iter, iterA, iterB1, iterB2, iterC1, iterC2, iterC3, iterC4, iterB2RE, maxIterUsed, maxIter, sumIter;
00150       int integrationSteps, integrationStepswithChange, refusedSteps, refusedStepsWithImpact;
00151       int wrongAlertGapControl, stepsOkAfterGapControl, stepsRefusedAfterGapControl, statusGapControl;
00152       int singleStepsT1, singleStepsT2, singleStepsT3;
00153       double dtRelGapControl, qUncertaintyByExtrapolation;
00154       int indexLSException;
00155       fmatvec::Vec gUniActive;
00156       double Penetration, PenetrationCounter, PenetrationLog, PenetrationMin, PenetrationMax;
00157       double maxdtUsed, mindtUsed;
00158       bool ChangeByGapControl;      
00159       bool calcBlock2;
00160       bool IterConvergence;
00161       bool ConstraintsChanged, ConstraintsChangedBlock1, ConstraintsChangedBlock2;
00162       int integrationStepsOrder1;
00163       int integrationStepsOrder2;
00164       int order;
00165       int StepTrials;
00166       int AnzahlAktiverKontakte;
00167       double gNDurchschnittprostep;
00168 
00169     public:
00171       TimeSteppingSSCIntegrator();
00173       ~TimeSteppingSSCIntegrator();
00175       void setInitialStepSize(double dt_) {dt = dt_;}
00177       void setStepSizeMax(double dtMax_) {dtMax = dtMax_;}
00179       void setStepSizeMin(double dtMin_) {dtMin = dtMin_;}
00181       void setmaxGainSSC(double maxGain) {maxGainSSC = maxGain;}
00183       void setSafetyFactorSSC(double sfactor) {safetyFactorSSC=sfactor;}
00184       void setSafetyFactorGapControl(double s){safetyFactorGapControl=s;}
00186       void setOutputInterpolation(bool flag=true) {outputInterpolation = flag;}
00188       void setFlagPlotIntegrator(bool flag=true) {FlagPlotIntegrator = flag;}
00190       void setFlagOutputOnlyAtTPlot(bool flag=true) {FlagOutputOnlyAtTPlot = flag;}
00200       void setGapControl(int strategy=1) {FlagGapControl=(strategy>=0); GapControlStrategy=(strategy<0)?0:strategy; }
00202       void setDriftCompensation(bool dc) {driftCompensation = dc;}
00207       void setMaxOrder(int order_, int method_=0);
00208       /* deactivate step size control */
00209       void deactivateSSC(bool flag=false) {FlagSSC=flag;}
00214       void setFlagErrorTest(int Flag, bool alwaysValid=true);
00215 
00217       void integrate(DynamicSystemSolver& system_);
00219       void integrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_, int Threads=0);
00220 
00221       void setAbsoluteTolerance(const fmatvec::Vec &aTol_) {aTol = aTol_;}
00222       void setAbsoluteTolerance(double aTol_) {aTol = fmatvec::Vec(1,fmatvec::INIT,aTol_);}
00223       void setRelativeTolerance(const fmatvec::Vec &rTol_) {rTol = rTol_;}
00224       void setRelativeTolerance(double rTol_) {rTol = fmatvec::Vec(1,fmatvec::INIT,rTol_);}
00225       void setgapTolerance(double gTol) {gapTol = gTol;}
00226 
00229       void preIntegrate(DynamicSystemSolver& system);
00230       void subIntegrate(DynamicSystemSolver& system, double tStop);
00231       void postIntegrate(DynamicSystemSolver& system);
00232       void preIntegrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_);
00233        
00235       void getAllSetValuedla(fmatvec::Vec& la_,fmatvec::VecInt& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
00236       void setAllSetValuedla(const fmatvec::Vec& la_,const fmatvec::VecInt& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
00237       void getDataForGapControl();
00238       bool testTolerances();
00239       bool GapControl(double qUnsafe, bool SSCTestOK); 
00240       bool changedLinkStatus(const fmatvec::VecInt &L1, const fmatvec::VecInt &L2, int ex);
00241       double calculatedtNewRel(const fmatvec::Vec &ErrorLocal, double H);
00242       void plot();
00243 
00244       virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00245   };
00246 
00247 }
00248 
00249 #endif