00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _ELEMENT_H_
00022 #define _ELEMENT_H_
00023
00024 #include "fmatvec/fmatvec.h"
00025 #include "fmatvec/atom.h"
00026 #include "mbsim/objectfactory.h"
00027 #include <string>
00028 #include <hdf5serie/vectorserie.h>
00029 #include <mbxmlutilshelper/dom.h>
00030
00031 #include "mbsim_event.h"
00032
00033 #ifdef HAVE_OPENMBVCPPINTERFACE
00034 namespace OpenMBV {
00035 class Group;
00036 }
00037 #endif
00038
00039 namespace H5 {
00040 class Group;
00041 }
00042
00046 namespace MBSim {
00047
00048 const MBXMLUtils::NamespaceURI MBSIM("http://mbsim.berlios.de/MBSim");
00049
00050 class DynamicSystemSolver;
00051
00058 class Element : virtual public fmatvec::Atom {
00059 public:
00061 enum PlotFeatureStatus {
00062 enabled,
00063 disabled,
00064 unset
00065 };
00066
00067
00068
00069
00070
00071
00072
00074 enum PlotFeature {
00075 plotRecursive=0,
00076 separateFilePerGroup,
00077 state,
00078 stateDerivative,
00079 notMinimalState,
00080 rightHandSide,
00081 globalPosition,
00082 globalVelocity,
00083 globalAcceleration,
00084 energy,
00085 openMBV,
00086 generalizedLinkForce,
00087 linkKinematics,
00088 stopVector,
00089 debug,
00090 LASTPLOTFEATURE
00091 };
00092
00097 enum InitStage {
00098 modelBuildup=0,
00099 resolveXMLPath,
00100 preInit,
00101 resize,
00102 relativeFrameContourLocation,
00103 worldFrameContourLocation,
00104 plotting,
00105 reorganizeHierarchy,
00106 unknownStage,
00107 calculateLocalInitialValues,
00108 LASTINITSTAGE
00109 };
00110
00114 Element(const std::string &name);
00115
00119 virtual ~Element();
00120
00121
00125 virtual void initDataInterfaceBase(DynamicSystemSolver *parentds) {};
00126
00130 virtual std::string getType() const { return "Element"; }
00131
00136 virtual void setDynamicSystemSolver(DynamicSystemSolver *sys) { ds = sys; }
00137
00143 virtual void plot(double t, double dt = 1);
00144
00150 virtual void plotAtSpecialEvent(double t, double dt = 1) {}
00151
00155 virtual void closePlot();
00156
00157
00161 const std::string& getName() const { return name; }
00162
00166 void setName(const std::string &str) { name = str; }
00167
00168
00169 void setPath(const std::string &str) { path=str; }
00170
00174 DynamicSystemSolver* getDynamicSystemSolver() { return ds; }
00175
00180 virtual void init(InitStage stage);
00181
00185 virtual void createPlotGroup();
00186
00190 H5::GroupBase *getPlotGroup() { return plotGroup; }
00191
00198 virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; }
00199
00205 void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value) { plotFeatureForChildren[pf]=value; }
00206
00212 void setPlotFeatureRecursive(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; plotFeatureForChildren[pf]=value; }
00213
00217 PlotFeatureStatus getPlotFeature(PlotFeature pf) { return plotFeature[pf]; }
00218
00222 PlotFeatureStatus getPlotFeatureForChildren(PlotFeature pf) { return plotFeatureForChildren[pf]; }
00223
00224 virtual void initializeUsingXML(xercesc::DOMElement *element);
00225 virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00226
00231 template<class T> T* getByPath(const std::string &path, bool initialCaller=true) const;
00232
00238 std::string getPath(const Element *relTo=NULL, std::string sep="/") const;
00239
00243 virtual Element* getChildByContainerAndName(const std::string &container, const std::string &name) const {
00244 THROW_MBSIMERROR("This element has no containers with childs.");
00245 }
00246
00247
00248 static double getDouble(xercesc::DOMElement *e);
00249 static int getInt(xercesc::DOMElement *e);
00250 static bool getBool(xercesc::DOMElement *e);
00251 static fmatvec::Vec3 getVec3(xercesc::DOMElement *e);
00252 static fmatvec::Vec getVec(xercesc::DOMElement *e, int rows=0);
00253 static fmatvec::Mat3xV getMat3xV(xercesc::DOMElement *e, int cols=0);
00254 static fmatvec::Mat getMat(xercesc::DOMElement *e, int rows=0, int cols=0);
00255 static fmatvec::SqrMat3 getSqrMat3(xercesc::DOMElement *e);
00256 static fmatvec::SqrMat getSqrMat(xercesc::DOMElement *e, int size=0);
00257 static fmatvec::SymMat3 getSymMat3(xercesc::DOMElement *e);
00258 static fmatvec::SymMat getSymMat(xercesc::DOMElement *e, int size=0);
00259
00260 #ifdef HAVE_OPENMBVCPPINTERFACE
00261 virtual OpenMBV::Group* getOpenMBVGrp() {return 0;}
00262 #endif
00263
00264 virtual Element* getParent() {return parent;}
00265 virtual const Element* getParent() const {return parent;}
00266 virtual void setParent(Element* parent_) {parent = parent_;}
00267
00268 protected:
00269 Element *parent;
00270
00274 std::string name;
00275
00281 std::string path;
00282
00286 DynamicSystemSolver *ds;
00287
00291 H5::VectorSerie<double> *plotVectorSerie;
00292
00296 std::vector<double> plotVector;
00297
00301 std::vector<std::string> plotColumns;
00302
00306 H5::GroupBase *plotGroup;
00307
00308 void updatePlotFeatures();
00309
00310 private:
00314 PlotFeatureStatus plotFeature[LASTPLOTFEATURE], plotFeatureForChildren[LASTPLOTFEATURE];
00315 };
00316
00317 template<class T>
00318 T* Element::getByPath(const std::string &path, bool initialCaller) const {
00319 try {
00320 if(path.substr(0, 1) == "/") {
00321 if(parent)
00322 return parent->getByPath<T>(path, false);
00323 else
00324 return getByPath<T>(path.substr(1), false);
00325 }
00326 else if (path.substr(0, 3) == "../")
00327 return parent->getByPath<T>(path.substr(3), false);
00328 else {
00329
00330 size_t idx=path.find('/');
00331 std::string first=path.substr(0, idx);
00332 std::string rest;
00333 if(idx!=std::string::npos)
00334 rest=path.substr(idx+1);
00335
00336 size_t pos0=first.find('[');
00337 if(pos0==std::string::npos)
00338 THROW_MBSIMERROR("Syntax error in subreference '"+first+"': no [ found.");
00339 std::string container=first.substr(0, pos0);
00340 if(first[first.size()-1]!=']')
00341 THROW_MBSIMERROR("Syntax error in subreference '"+first+"': not ending with ].");
00342 std::string name=first.substr(pos0+1, first.size()-pos0-2);
00343 Element *e=getChildByContainerAndName(container, name);
00344
00345 if(!rest.empty())
00346 return e->getByPath<T>(rest, false);
00347
00348 T *t=dynamic_cast<T*>(e);
00349 if(t)
00350 return t;
00351 else
00352 THROW_MBSIMERROR("Cannot cast this element to type "+container+".");
00353 }
00354 }
00355 catch(MBSimError &ex) {
00356 if(initialCaller)
00357 THROW_MBSIMERROR("Evaluation of refernece '"+path+"' failed: Message from "+
00358 ex.getPath()+": "+ex.getErrorMessage());
00359 else
00360 throw ex;
00361 }
00362 }
00363
00364
00365 }
00366
00367 #endif