Moby
TimeSteppingSimulator.h
1 /****************************************************************************
2  * Copyright 2015 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _TS_SIMULATOR_H
8 #define _TS_SIMULATOR_H
9 
10 #include <map>
11 #include <Ravelin/sorted_pair>
12 #include <Moby/ConstraintSimulator.h>
13 #include <Moby/ImpactConstraintHandler.h>
14 #include <Moby/PenaltyConstraintHandler.h>
15 #include <Moby/SustainedUnilateralConstraintHandler.h>
16 #include <Moby/PairwiseDistInfo.h>
17 #include <Moby/CCD.h>
18 #include <Moby/UnilateralConstraint.h>
19 
20 namespace Moby {
21 
22 class ContactParameters;
23 class CollisionDetection;
24 class CollisionGeometry;
25 
28 {
29  friend class CollisionDetection;
30 
31  public:
33  virtual ~TimeSteppingSimulator() {}
34  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
35  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
36  virtual double step(double dt);
37  boost::shared_ptr<ContactParameters> get_contact_parameters(CollisionGeometryPtr geom1, CollisionGeometryPtr geom2) const;
38 
39  // the minimum step that the simulator should take (default = 1e-8)
40  double min_step_size;
41 
43  std::set<Ravelin::sorted_pair<CollisionGeometryPtr> > unchecked_pairs;
44 
46  std::vector<std::pair<ControlledBodyPtr, Ravelin::VectorNd> > _x0, _x1;
47 
49  boost::shared_ptr<TimeSteppingSimulator> get_this() { return boost::dynamic_pointer_cast<TimeSteppingSimulator>(shared_from_this()); }
50 
51  protected:
52  bool constraints_met(const std::vector<PairwiseDistInfo>& current_pairwise_distances);
53  std::set<Ravelin::sorted_pair<CollisionGeometryPtr> > get_current_contact_geoms() const;
54  double do_mini_step(double dt);
55  void step_si_Euler(double dt);
56  double calc_next_CA_Euler_step() const;
57 }; // end class
58 
59 } // end namespace
60 
61 #endif
62 
63 
Defines an abstract collision detection mechanism.
Definition: CollisionDetection.h:38
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml()
Definition: TimeSteppingSimulator.cpp:480
double calc_next_CA_Euler_step() const
Finds the next event time assuming constant velocity.
Definition: TimeSteppingSimulator.cpp:276
double do_mini_step(double dt)
Does a full integration cycle (but not necessarily a full step)
Definition: TimeSteppingSimulator.cpp:114
bool constraints_met(const std::vector< PairwiseDistInfo > &current_pairwise_distances)
Checks to see whether all constraints are met.
Definition: TimeSteppingSimulator.cpp:229
An virtual class for simulation with constraints.
Definition: ConstraintSimulator.h:29
std::vector< std::pair< ControlledBodyPtr, Ravelin::VectorNd > > _x0
Vectors set and passed to collision detection.
Definition: TimeSteppingSimulator.h:46
virtual double step(double dt)
Steps the simulator forward by the given step size.
Definition: TimeSteppingSimulator.cpp:52
An event-driven simulator.
Definition: TimeSteppingSimulator.h:27
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
std::set< Ravelin::sorted_pair< CollisionGeometryPtr > > unchecked_pairs
Determines whether two geometries are not checked.
Definition: TimeSteppingSimulator.h:43
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
std::set< Ravelin::sorted_pair< CollisionGeometryPtr > > get_current_contact_geoms() const
Gets the current set of contact geometries.
Definition: TimeSteppingSimulator.cpp:255
void step_si_Euler(double dt)
Does a semi-implicit step.
Definition: TimeSteppingSimulator.cpp:437
boost::shared_ptr< TimeSteppingSimulator > get_this()
Gets the shared pointer for this.
Definition: TimeSteppingSimulator.h:49
TimeSteppingSimulator()
Default constructor.
Definition: TimeSteppingSimulator.cpp:46
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Implements Base::load_from_xml()
Definition: TimeSteppingSimulator.cpp:462