mbsimphysics  4.0.0
MBSim Physics Module
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
universal_gravitation.h
1 /* Copyright (C) 2004-2018 MBSim Development Team
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * Contact: martin.o.foerg@googlemail.com
17  */
18 
19 #ifndef _UNIVERSAL_GRAVITATION_H
20 #define _UNIVERSAL_GRAVITATION_H
21 
22 #include "mbsim/links/mechanical_link.h"
23 
24 #include "mbsim/utils/boost_parameters.h"
25 #include "mbsim/utils/openmbv_utils.h"
26 
27 namespace MBSim {
28  class RigidBody;
29 }
30 
31 namespace MBSimPhysics {
32 
34  public:
35  UniversalGravitation(const std::string &name="");
36  void resetUpToDate() override;
37  void init(InitStage stage, const MBSim::InitConfigSet &config) override;
38  void initializeUsingXML(xercesc::DOMElement *element) override;
39 
40  void connect(MBSim::RigidBody *body0, MBSim::RigidBody* body1);
41 
42  void plot() override;
43 
44  void setGravitationalConstant(double ga_) { ga = ga_; }
45 
46  void updateGeneralizedPositions() override;
47  void updatePositions() override;
48  void updatelaF() override;
49  void updateForce() override;
50  void updateh(int i=0) override;
51 
52  const fmatvec::Vec3& evalGlobalRelativePosition() { if(updPos) updatePositions(); return WrP0P1; }
53 
54  bool isActive() const override { return true; }
55  bool gActiveChanged() override { return false; }
56  bool isSingleValued() const override { return true; }
57 
58  void updateWRef(fmatvec::Mat& ref, int i=0) override { }
59  void updateVRef(fmatvec::Mat& ref, int i=0) override { }
60  void updatehRef(fmatvec::Vec &hRef, int i=0) override;
61  virtual void updatedhdqRef(fmatvec::Mat& ref, int i=0);
62  virtual void updatedhduRef(fmatvec::SqrMat& ref, int i=0);
63  virtual void updatedhdtRef(fmatvec::Vec& ref, int i=0);
64  void updaterRef(fmatvec::Vec &ref, int i=0) override { }
65 
66  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, MBSim::tag, (optional (sideOfInteraction,(MBSim::OpenMBVInteractionArrow::SideOfInteraction),MBSim::OpenMBVInteractionArrow::action)(scaleLength,(double),1)(scaleSize,(double),1)(referencePoint,(MBSim::OpenMBVArrow::ReferencePoint),MBSim::OpenMBVArrow::toPoint)(colorRepresentation,(MBSim::OpenMBVArrow::ColorRepresentation),MBSim::OpenMBVArrow::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
67  ombvArrow = std::shared_ptr<MBSim::OpenMBVInteractionArrow>(new MBSim::OpenMBVInteractionArrow(sideOfInteraction,scaleLength,scaleSize,MBSim::OpenMBVArrow::toHead,referencePoint,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
68  }
69 
70  protected:
71  std::vector<MBSim::RigidBody*> body;
72  double ga{6.67408e-11};
73  fmatvec::Vec3 WrP0P1;
74  bool updPos;
75 
76  std::shared_ptr<MBSim::OpenMBVInteractionArrow> ombvArrow;
77  std::vector<std::shared_ptr<OpenMBV::Arrow>> openMBVForce;
78 
79  private:
80  std::string saved_ref1, saved_ref2;
81  };
82 
83 }
84 
85 #endif
Definition: universal_gravitation.h:33