MBSim

Project Page
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: martin.o.foerg@googlemail.com
00018  */
00019 
00020 #ifndef _INTEGRATOR_H_
00021 #define _INTEGRATOR_H_
00022 
00023 #define MBSIMINTNS_ "http://mbsim.berlios.de/MBSimIntegrator"
00024 #define MBSIMINTNS "{"MBSIMINTNS_"}"
00025 
00026 #include<fmatvec/fmatvec.h>
00027 #include"mbxmlutilstinyxml/tinyxml.h"
00028 #include<string>
00029 #include<iostream>
00030 
00031 namespace MBSim {
00032 
00033   class DynamicSystemSolver;
00034 
00040   class Integrator {
00041     public:
00045       Integrator();
00046       
00050       virtual ~Integrator() {};
00051       
00052       /* GETTER / SETTER */
00053       void setStartTime(double tStart_) { tStart=tStart_; }
00054       void setEndTime(double tEnd_) { tEnd = tEnd_; }
00055       void setPlotStepSize(double dtPlot_) { dtPlot = dtPlot_; }
00056       void setInitialState(const fmatvec::Vec &z0_) { z0 = z0_; }
00057       void setWarnLevel(int level) { warnLevel = level; }
00058       void setOutput(bool flag) { output = flag; }
00059       double getStartTime() const { return tStart; }
00060       double getEndTime() const { return tEnd; }
00061       double getPlotStepSize() const { return dtPlot; }
00062       const fmatvec::Vec& getInitialState() const { return z0; }
00063       int getWarnLevel() const { return warnLevel; }
00064       bool getOutput() const { return output; }
00065       /***************************************************/
00066       
00067       /* INTERFACE FOR DERIVED CLASSES */
00073       virtual void integrate(DynamicSystemSolver& system) = 0;
00074 
00080       void debugInit();
00081 
00082       virtual void preIntegrate(DynamicSystemSolver& system) { std::cerr<<"preIntegrate is not defined\n"<<std::endl; }
00083       virtual void subIntegrate(DynamicSystemSolver& system, double tStop) { std::cerr<<"subIntegrate is not defined\n"<<std::endl; }
00084       virtual void postIntegrate(DynamicSystemSolver& system) { std::cerr<<"postIntegrate is not defined\n"<<std::endl; }
00085 
00090       virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00091       virtual MBXMLUtils::TiXmlElement* writeXMLFile(MBXMLUtils::TiXmlNode *element);
00092 
00093       static Integrator* readXMLFile(const std::string &filename);
00094       void writeXMLFile(const std::string &name);
00095       void writeXMLFile() { writeXMLFile(getType()); }
00096 
00097       /***************************************************/
00098 
00102       virtual std::string getType() const { return "Integrator"; }
00103 
00104     protected:
00108       static DynamicSystemSolver* system;
00109 
00113       double tStart, tEnd, dtPlot;
00114 
00118       fmatvec::Vec z0;
00119 
00123       int warnLevel;
00124 
00128       bool output;
00129 
00133       std::string name;
00134 
00135   };
00136 
00137 }
00138 
00139 #endif /* _INTEGRATOR_H_ */
00140