23 #include "fmatvec/fmatvec.h" 24 #include "fmatvec/atom.h" 25 #include "mbsim/objectfactory.h" 26 #include "mbsim/utils/plotfeatureenum.h" 27 #include "mbsim/utils/initconfigenum.h" 28 #include "mbsim/namespace.h" 29 #include "mbsim/mbsim_event.h" 30 #include <hdf5serie/vectorserie.h> 45 extern int baseIndexForPlot;
47 extern const PlotFeatureEnum plotRecursive, openMBV, debug;
49 class DynamicSystemSolver;
58 class Element :
virtual public fmatvec::Atom {
85 void throwError(
const std::string &msg)
const {
120 void setPath(
const std::string &str) {
path=str; }
131 virtual void init(
InitStage stage,
const InitConfigSet &config);
142 virtual H5::GroupBase *getFramesPlotGroup() {
return nullptr; }
143 virtual H5::GroupBase *getContoursPlotGroup() {
return nullptr; }
144 virtual H5::GroupBase *getGroupsPlotGroup() {
return nullptr; }
145 virtual H5::GroupBase *getObjectsPlotGroup() {
return nullptr; }
146 virtual H5::GroupBase *getLinksPlotGroup() {
return nullptr; }
147 virtual H5::GroupBase *getConstraintsPlotGroup() {
return nullptr; }
148 virtual H5::GroupBase *getObserversPlotGroup() {
return nullptr; }
180 virtual void initializeUsingXML(xercesc::DOMElement *element);
186 template<
class T> T*
getByPath(
const std::string &
path,
bool initialCaller=
true)
const;
193 std::string
getPath(
const Element *relTo=
nullptr, std::string sep=
"/")
const;
199 throwError(
"This element has no containers with childs.");
202 virtual std::shared_ptr<OpenMBV::Group> getOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
203 virtual std::shared_ptr<OpenMBV::Group> getFramesOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
204 virtual std::shared_ptr<OpenMBV::Group> getContoursOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
205 virtual std::shared_ptr<OpenMBV::Group> getGroupsOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
206 virtual std::shared_ptr<OpenMBV::Group> getObjectsOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
207 virtual std::shared_ptr<OpenMBV::Group> getLinksOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
208 virtual std::shared_ptr<OpenMBV::Group> getConstraintsOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
209 virtual std::shared_ptr<OpenMBV::Group> getObserversOpenMBVGrp() {
return std::shared_ptr<OpenMBV::Group>(); }
211 virtual Element* getParent() {
return parent;}
212 virtual const Element* getParent()
const {
return parent;}
213 virtual void setParent(
Element* parent_) {parent = parent_;}
230 virtual void updatePositions(Frame *frame) { }
231 virtual void updateVelocities(Frame *frame) { }
232 virtual void updateAccelerations(Frame *frame) { }
233 virtual void updateJacobians(Frame *frame,
int j=0) { }
234 virtual void updateGyroscopicAccelerations(Frame *frame) { }
236 virtual void resetUpToDate() { }
238 const double& getTime()
const;
239 double getStepSize()
const;
290 void updatePlotFeatures();
302 int convertIndex(
int i) {
return baseIndexForPlot+i; }
304 void addToPlot(
const std::string &
name);
305 void addToPlot(
const std::string &
name,
int size);
306 void addToPlot(
const std::string &
name,
const std::vector<std::string> &iname);
308 template<
class AT>
void plot(
const AT &x) {
311 template<
class Type,
class AT>
void plot(
const fmatvec::Vector<Type,AT> &x) {
312 for(
int i=0; i<x.size(); i++)
320 if(
path.substr(0, 1) ==
"/") {
322 return parent->getByPath<T>(
path,
false);
324 return getByPath<T>(
path.substr(1),
false);
326 else if (
path.substr(0, 3) ==
"../") {
328 throwError(
"Reference to parent '"+
path+
"' requested but already at the root node.");
329 return parent->getByPath<T>(
path.substr(3),
false);
333 size_t idx=
path.find(
'/');
334 std::string first=
path.substr(0, idx);
336 if(idx!=std::string::npos)
337 rest=
path.substr(idx+1);
339 size_t pos0=first.find(
'[');
340 if(pos0==std::string::npos)
341 throwError(
"Syntax error in subreference '"+first+
"': no [ found.");
342 std::string container=first.substr(0, pos0);
343 if(first[first.size()-1]!=
']')
344 throwError(
"Syntax error in subreference '"+first+
"': not ending with ].");
345 std::string
name=first.substr(pos0+1, first.size()-pos0-2);
351 auto *t=dynamic_cast<T*>(e);
355 throwError(
"Cannot cast this element to type "+container+
".");
360 throwError(
"Evaluation of refernece '"+
path+
"' failed: Message from "+
361 ex.getPath()+
": "+ex.getErrorMessage());
virtual void createPlotGroup()
creates the plotGroup for H5-output
Definition: element.cc:115
std::vector< Element * > getDependencies() const
checks dependency on other elements.
Definition: element.h:219
virtual void plot()
plots time dependent data
Definition: element.cc:71
virtual void setPlotFeature(const PlotFeatureEnum &pf, bool value)
Set a plot feature.
Definition: element.cc:210
bool getPlotFeature(const PlotFeatureEnum &pf)
Definition: element.h:152
virtual void init(InitStage stage, const InitConfigSet &config)
plots time series header
Definition: element.cc:82
DynamicSystemSolver * getDynamicSystemSolver()
Definition: element.h:125
solver interface for modelling and simulation of dynamic systems
Definition: dynamic_system_solver.h:58
std::vector< Element * > dependency
vector containing all dependencies.
Definition: element.h:295
virtual void plotAtSpecialEvent()
plots time dependent data at special events
Definition: element.h:107
PlotFeatureMap plotFeature
plot feature
Definition: element.h:300
H5::VectorSerie< double > * plotVectorSerie
time series
Definition: element.h:273
void setPlotFeatureRecursive(const PlotFeatureEnum &pf, bool value)
Set a plot feature for this object and the children of this object.
Definition: element.h:178
basic class of MBSim mainly for plotting
Definition: element.h:58
std::string path
The path of this object. Is set during the init stage reorganizeHierarchy. Before this the path is ca...
Definition: element.h:258
DynamicSystemSolver * ds
dynamic system
Definition: element.h:268
H5::GroupBase * getPlotGroup()
Definition: element.h:141
void setPlotFeatureForChildren(const PlotFeatureEnum &pf, bool value)
Set a plot feature for the children of this object.
Definition: element.cc:214
std::vector< std::string > plotColumns
columns of time series
Definition: element.h:283
Definition: plotfeatureenum.h:29
std::string getPath(const Element *relTo=nullptr, std::string sep="/") const
Return the path of this object. If relativeTo is not NULL return a relative path to relativeTo....
Definition: element.cc:150
InitStage
The stages of the initialization.
Definition: element.h:64
virtual Element * getChildByContainerAndName(const std::string &container, const std::string &name) const
Get the Element named name in the container named container.
Definition: element.h:198
std::vector< double > plotVector
one entry of time series
Definition: element.h:278
const std::string & getName() const
Definition: element.h:112
~Element() override=default
destructor
std::string name
name of element
Definition: element.h:251
MBXMLUtils::DOMEvalException domEvalError
Special XML helper variable.
Definition: element.h:262
virtual void setDynamicSystemSolver(DynamicSystemSolver *sys)
sets the used dynamics system solver to the element
Definition: element.h:93
H5::GroupBase * plotGroup
associated plot group
Definition: element.h:288
void setName(const std::string &str)
Definition: element.h:117
basic error class for mbsim
Definition: mbsim_event.h:39
int computeLevel()
computes the length of the pathes in the graph that represents the dependencies between all elements.
Definition: element.cc:240
T * getByPath(const std::string &path, bool initialCaller=true) const
Get the object of type T represented by the path path. Do not set any argurment other than path!
Definition: element.h:318
Element(const std::string &name)
constructor
Definition: element.cc:68
namespace MBSim
Definition: bilateral_constraint.cc:29