00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _AUTO_TIME_STEPPING_SSC_INTEGRATOR_H_
00023 #define _AUTO_TIME_STEPPING_SSC_INTEGRATOR_H_
00024
00025 #include "integrator.h"
00026 #include "mbsim/utils/stopwatch.h"
00027
00028 namespace MBSim {
00029
00030 class Link;
00031
00091 class AutoTimeSteppingSSCIntegrator : public Integrator {
00092
00093 protected:
00094 DynamicSystemSolver* sysT1;
00095 DynamicSystemSolver* sysT2;
00096 DynamicSystemSolver* sysT3;
00097 DynamicSystemSolver* sysTP;
00098
00099 double dt, dtOld, dte;
00100 double dtMin, dtMax;
00101 double dt_SSC_vorGapControl;
00102 bool driftCompensation;
00103 double t, tPlot, tPlotP;
00104 int qSize, xSize, uSize, zSize;
00105 fmatvec::Vec ze, zeP, zi, ziP, zT1, zT2, zT3, zTP, z1d, z2d, z2dRE, z3d, z4d, z6d, z2b, z3b, z4b, z6b, zStern;
00106
00107 fmatvec::VecInt LS, LSe, LSA, LSB1, LSB2, LSC1, LSC2, LSC3, LSC4, LSD1, LSD2, LSD3, LSD4, LSD5, LSD6;
00108 fmatvec::VecInt LS_Reg, LSe_Reg, LSA_Reg, LSB1_Reg, LSB2_Reg, LSC1_Reg, LSC2_Reg, LSC3_Reg, LSC4_Reg, LSD1_Reg, LSD2_Reg, LSD3_Reg, LSD4_Reg, LSD5_Reg, LSD6_Reg;
00109 fmatvec::VecInt LS_Reg_T1, LS_Reg_T2, LS_Reg_T3;
00110 fmatvec::VecInt LS_Reg_z2b, S_Reg_z1d, LS_Reg_z4b, LS_Reg_z6b, LS_Reg_z1d, LS_Reg_z3b, LSB1_2_Reg;
00111 fmatvec::VecInt LS_tmp;
00112
00113 fmatvec::Vec la, laP, lae, laeP, la1d, la2b;
00114 fmatvec::VecInt laSizes, laSizesP, laeSizes, laeSizesP, la1dSizes, la2bSizes;
00115 fmatvec::Vec qT1, qT2, qT3, qTP;
00116 fmatvec::Vec uT1, uT2, uT3, uTP;
00117 fmatvec::Vec xT1, xT2, xT3, xTP;
00118 fmatvec::Vec gInActive, gdInActive;
00119 std::vector<MBSim::Link*> SetValuedLinkListT1;
00120 std::vector<MBSim::Link*> SetValuedLinkListT2;
00121 std::vector<MBSim::Link*> SetValuedLinkListT3;
00122 std::vector<MBSim::Link*> SetValuedLinkListTP;
00123
00124 int StepsWithUnchangedConstraints;
00125
00127 int FlagErrorTest;
00128
00130 bool FlagErrorTestAlwaysValid;
00131
00133 fmatvec::Vec aTol;
00134
00136 fmatvec::Vec rTol;
00137
00139 bool FlagSSC;
00140
00144 int maxOrder;
00145
00150 int method;
00151
00152
00153 bool FlagGapControl;
00154
00156 double gapTol;
00157
00159 double maxGainSSC;
00160
00162 double safetyFactorSSC;
00163
00165 std::ofstream integPlot;
00166
00168 bool FlagPlotIntegrator;
00169
00171 bool FlagPlotIntegrationSum;
00172
00174 bool FlagCoutInfo;
00175
00177 bool FlagPlotEveryStep;
00178
00180 bool outputInterpolation;
00181
00183 double safetyFactorGapControl;
00184
00192 int GapControlStrategy;
00193
00195 int numThreads, numThreadsB1;
00196
00198 double time, dhdztime, timeB1, timeB2, timePlot, timePlotPar;
00199
00201 StopWatch Timer, dhdzTimer, TimerB1, TimerB2, TimerPlot, TimerPlotPar;
00202
00204 int iter, iterA, iterB1, iterB2, iterC1, iterC2, iterC3, iterC4, iterB2RE, maxIterUsed, maxIter, sumIter;
00205
00207 int integrationSteps, integrationStepswithChange, refusedSteps, refusedStepsWithImpact;
00208
00210 int JacUpdateT1, JacUpdateT2, JacUpdateT3;
00211
00213 int wrongAlertGapControl, stepsOkAfterGapControl, stepsRefusedAfterGapControl, statusGapControl;
00214
00216 int singleStepsT1, singleStepsT2, singleStepsT3;
00217
00219 double dtRelGapControl, qUncertaintyByExtrapolation;
00220 int indexLSException;
00221 fmatvec::Vec gUniActive;
00222 double Penetration, PenetrationCounter, PenetrationLog, PenetrationMin, PenetrationMax;
00223 double maxdtUsed, mindtUsed;
00224 bool ChangeByGapControl;
00225 bool calcBlock2;
00226 bool IterConvergence;
00227 bool ConstraintsChanged, ConstraintsChangedBlock1, ConstraintsChangedBlock2, ConstraintsChanged_B1_A;
00228 int integrationStepsOrder1, integrationStepsOrder2;
00229 int order;
00230 int StepTrials;
00231 int AnzahlAktiverKontakte;
00232 double gNDurchschnittprostep;
00233
00235 int iter_T1, iter_T2, iter_T3, step;
00236
00237 fmatvec::Index Iq, Iu, Ix;
00238
00240 bool expInt;
00241
00243 int it_T1, it_T2, it_T3;
00244
00246 bool gAC_T1, gAC_T2, gAC_T3, gAC_reg_T1, gAC_reg_T2, gAC_reg_T3;
00247
00249 bool upgedated_T1, upgedated_T2, upgedated_T3;
00250
00252 bool JacUpdate_B1_T1, JacUpdate_B2_T1, JacUpdate_B1_T2, JacUpdate_B2_T2, JacUpdate_T1, JacUpdate_T2;
00253
00255 int itMax;
00256
00258 double itTol;
00259
00261 fmatvec::Mat dhdq_n_T1, dhdu_n_T1, dhdq_n_T2, dhdu_n_T2, dhdq_n_T3, dhdu_n_T3, dhdq_T1, dhdu_T1, dhdq_T2, dhdu_T2, dhdq_T3, dhdu_T3;
00262 fmatvec::Mat dhdq_z1d, dhdu_z1d, dhdq_z2b, dhdq_z3b, dhdq_z4b, dhdq_z6b, dhdu_z2b, dhdu_z3b, dhdu_z4b, dhdu_z6b, dhdq_end, dhdu_end, dhdq_z2d, dhdu_z2d, dhdq_z2dRE, dhdu_z2dRE, dhdq_z3d, dhdu_z3d, dhdq_z4d, dhdu_z4d, dhdq_z6d, dhdu_z6d;
00263
00265 double theta;
00266
00267 bool parJac;
00268 bool parInt;
00269
00270 std::vector<DynamicSystemSolver*> *psystems;
00271
00273 bool inexactJac;
00274
00275 int maxImpIter;
00276 int JacConstSteps;
00277
00279 bool SetValuedForceLawsExplicit;
00280
00282 bool debugOutput;
00283
00285 bool plotParallel;
00286
00287
00288 fmatvec::Mat JacVgl, JacVgl2, JacVgl3;
00289
00291 int JacCounter;
00292
00293 public:
00294
00296 AutoTimeSteppingSSCIntegrator();
00297
00299 ~AutoTimeSteppingSSCIntegrator();
00300
00302 void setInitialStepSize(double dt_) {dt = dt_;}
00303
00305 void setStepSizeMax(double dtMax_) {dtMax = dtMax_;}
00306
00308 void setStepSizeMin(double dtMin_) {dtMin = dtMin_;}
00309
00311 void setmaxGainSSC(double maxGain) {maxGainSSC = maxGain;}
00312
00314 void setSafetyFactorSSC(double sfactor) {safetyFactorSSC=sfactor;}
00315 void setSafetyFactorGapControl(double s){safetyFactorGapControl=s;}
00316
00318 void setOutputInterpolation(bool flag=true) {outputInterpolation = flag;}
00319
00321 void setFlagPlotIntegrator(bool flag=true) {FlagPlotIntegrator = flag;}
00322
00332 void setGapControl(int strategy=1) {FlagGapControl=(strategy>=0); GapControlStrategy=(strategy<0)?0:strategy; }
00333
00335 void setDriftCompensation(bool dc) {driftCompensation = dc;}
00336
00341 void setMaxOrder(int order_, int method_=0);
00342
00343
00344 void deactivateSSC(bool flag=false) {FlagSSC=flag;}
00345
00350 void setFlagErrorTest(int Flag, bool alwaysValid=true);
00351
00353 void integrate(DynamicSystemSolver& system_);
00354 void integrate(DynamicSystemSolver& system_, std::vector<DynamicSystemSolver*> systems);
00355
00356 void integrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_, DynamicSystemSolver& systemTP_, int Threads=0);
00357 void integrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_, DynamicSystemSolver& systemTP_, std::vector<DynamicSystemSolver*> systems, int Threads=0);
00358
00360 void setAbsoluteTolerance(const fmatvec::Vec &aTol_) {aTol.resize() = aTol_;}
00361 void setAbsoluteTolerance(double aTol_) {aTol.resize() = fmatvec::Vec(1,fmatvec::INIT,aTol_);}
00362 void setRelativeTolerance(const fmatvec::Vec &rTol_) {rTol.resize() = rTol_;}
00363 void setRelativeTolerance(double rTol_) {rTol.resize() = fmatvec::Vec(1,fmatvec::INIT,rTol_);}
00364 void setgapTolerance(double gTol) {gapTol = gTol;}
00365
00367 void preIntegrate(DynamicSystemSolver& system);
00368 void subIntegrate(DynamicSystemSolver& system, double tStop);
00369 void postIntegrate(DynamicSystemSolver& system);
00370 void preIntegrate(DynamicSystemSolver& systemT1_, DynamicSystemSolver& systemT2_, DynamicSystemSolver& systemT3_, DynamicSystemSolver& systemTP_);
00371
00373 void getAllSetValuedla(fmatvec::Vec& la_,fmatvec::VecInt& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
00374 void setAllSetValuedla(const fmatvec::Vec& la_,const fmatvec::VecInt& la_Sizes,std::vector<MBSim::Link*> &SetValuedLinkList);
00375 void getDataForGapControl();
00376 bool testTolerances();
00377 bool GapControl(double qUnsafe, bool SSCTestOK);
00378 bool changedLinkStatus(const fmatvec::VecInt &L1, const fmatvec::VecInt &L2, int ex);
00379 double calculatedtNewRel(const fmatvec::Vec &ErrorLocal, double H);
00380 void plot();
00381 void plotPar();
00382 void doIntegPlot();
00383
00384 virtual void initializeUsingXML(xercesc::DOMElement *element);
00385
00393 void update(DynamicSystemSolver& system, const fmatvec::Vec& z, double t, int nrSys_=1);
00394
00395 void doStep(DynamicSystemSolver& system_, fmatvec::Vec& z_, int nrSys_, double t_, double dt_, bool exp_);
00396
00405 void doExpStep(DynamicSystemSolver& system_, fmatvec::Vec& z_, int nrSys_, double t_, double dt_);
00406
00415 void doImpStep(DynamicSystemSolver& system_, fmatvec::Vec& z_, int nrSys_, double t_, double dt_);
00416
00425 void doLinImpStep(DynamicSystemSolver& system_, fmatvec::Vec& z_, int nrSys_, double t_, double dt_);
00426
00428 void setTheta(double theta_ ) { theta = theta_; }
00429
00431 void getdhdqdhdu(fmatvec::Mat& dhdq_, fmatvec::Mat& dhdu_, const fmatvec::Vec z_, const double t_, const int nsys_);
00432
00434 void setItMax(int itMax_) {itMax = itMax_;}
00435
00437 void setInexactJac(bool inexactJac_) {inexactJac = inexactJac_;}
00438
00440 void setItTol(double itTol_) {itTol = itTol_;}
00441
00443 void setSetValuedForceLawsExplicit(bool SetValuedForceLawsExplicit_) {SetValuedForceLawsExplicit = SetValuedForceLawsExplicit_;}
00444
00446 void setDebugOutput(bool debugOutput_) {debugOutput = debugOutput_;}
00447
00449 void setPlotParallel(bool plotParallel_) {plotParallel = plotParallel_;}
00450 };
00451
00452 }
00453
00454 #endif