AGXDynamics  2.35.0.3
FrictionModel.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_FRICTIONMODEL_H
18 #define AGX_FRICTIONMODEL_H
19 
20 #include <agx/Referenced.h>
21 #include <agx/Range.h>
22 #include <agx/Vec3.h>
23 #include <agxStream/Serializable.h>
25 
26 #if defined(_MSC_VER)
27 #pragma warning( push )
28 #pragma warning( disable : 4589 ) // Disable: 4589: Constructor of abstract class 'agx::FrictionModel' ignores initializer for virtual base class 'agxStream::Serializable'
29 #endif
30 
31 
32 // Forward declarations
33 namespace agxCollide
34 {
35  class Geometry;
36  class GeometryContact;
37 }
38 
39 namespace agxSDK
40 {
41  class Simulation;
42 }
43 
44 namespace agx
45 {
51  {
52  public:
53  // NOTE: Used to index in arrays.
54  // Think carefully before changing order and/or adding before DIRECT_AND_ITERATIVE.
55  enum SolveType
56  {
60  SPLIT,
62  DIRECT_AND_ITERATIVE
63  };
64 
66  {
67  NONE = 0,
68  INITIALIZE = 1 << 0,
69  SCALE_BOUNDS = 1 << 1,
70  ITERATIVE_PROJECTION = 1 << 2,
71  HAS_CUSTOM_CONTACT_IMPLEMENTATION = 1 << 3,
74  };
75 
76  public:
85  void setSolveType( SolveType solveType );
86 
90  SolveType getSolveType() const;
91 
95  int getCallbackMask() const;
96 
107  virtual void calculateTangentPlane( const agxCollide::Geometry* geometry1,
108  const agxCollide::Geometry* geometry2,
109  const agx::Vec3& point,
110  const agx::Vec3& normal,
111  const agx::Real depth,
112  agx::Vec3& ret_u,
113  agx::Vec3& ret_v ) const;
114 
123  virtual void initialize( const Physics::GeometryContactPtr geometryContact,
124  size_t pointIndex,
125  agx::Real dt,
126  agx::RangeReal& ret_boundU,
127  agx::RangeReal& ret_boundV ) const = 0;
128 
134  bool needsNlmcpCallbacks() const;
135 
141  bool hasCustomContactImplementation() const;
142 
148  virtual void matchForCustomContactImplementation( agxCollide::GeometryContact* geometryContact,
149  agxSDK::Simulation* simulation );
150 
152 
153  protected:
159  FrictionModel( int callbackMask, SolveType preferredSolveType );
160 
164  virtual ~FrictionModel();
165 
170  void restore( agxStream::InputArchive& in ) override;
171 
176  void store( agxStream::OutputArchive& out ) const override;
177 
178  private:
179  SolveType m_solveType;
180  int m_callbackMask;
181  };
182 
183 
184 
186 
196  {
197  public:
202 
211  virtual void initialize( const Physics::GeometryContactPtr geometryContact, size_t pointIndex, agx::Real dt, agx::RangeReal& ret_boundU, agx::RangeReal& ret_boundV ) const override;
212 
216  virtual agx::Real calculateNormalForce( const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2, const agx::Vec3& point, const agx::Vec3& normal, const agx::Real depth, const agx::Real dt, const size_t numPoints ) const;
217 
219 
220  protected:
221  virtual ~BoxFrictionModel() {}
222  };
223 
224 
226 
236  {
237  public:
242 
246  virtual void initialize( const Physics::GeometryContactPtr geometryContact, size_t pointIndex, Real dt, RangeReal& ret_boundU, RangeReal& ret_boundV ) const override;
247 
249 
250  protected:
251  ScaleBoxFrictionModel( int callbackMask, SolveType preferredSolveType ) : FrictionModel( callbackMask, preferredSolveType ) {}
253  };
254 
255 
257 
270  {
271  public:
281 
283 
284  protected:
286  };
287 
289  {
290  return m_solveType;
291  }
292 
294  {
295  return m_callbackMask;
296  }
297 
299  {
300  return (m_callbackMask & SCALE_BOUNDS) != 0 && (m_solveType == DIRECT || m_solveType == DIRECT_AND_ITERATIVE);
301  }
302 
304  {
305  return ( m_callbackMask & HAS_CUSTOM_CONTACT_IMPLEMENTATION ) != 0;
306  }
307 
309  agxSDK::Simulation* /*simulation*/ )
310  {
311  }
312 }
313 
314 #if defined(_MSC_VER)
315 #pragma warning( pop )
316 #endif
317 
318 #endif
agx::FrictionModel::NOT_DEFINED
@ NOT_DEFINED
Definition: FrictionModel.h:57
agx::FrictionModel::needsNlmcpCallbacks
bool needsNlmcpCallbacks() const
Definition: FrictionModel.h:298
agx::BoxFrictionModel::~BoxFrictionModel
virtual ~BoxFrictionModel()
Definition: FrictionModel.h:221
Referenced.h
agx::IterativeProjectedConeFriction::~IterativeProjectedConeFriction
virtual ~IterativeProjectedConeFriction()
Definition: FrictionModel.h:285
agx::Real
double Real
Definition: Real.h:42
agxStream::out
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Definition: OutputArchive.h:412
GeometryContactEntity.h
agx::FrictionModel::matchForCustomContactImplementation
virtual void matchForCustomContactImplementation(agxCollide::GeometryContact *geometryContact, agxSDK::Simulation *simulation)
Definition: FrictionModel.h:308
agx::IterativeProjectedConeFriction
Iterative Projected Cone Friction (IPC friction) model.
Definition: FrictionModel.h:269
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
agx::FrictionModel::DIRECT_AND_ITERATIVE
@ DIRECT_AND_ITERATIVE
Normal and friction equation calculated both in the ITERATIVE and the DIRECT solver.
Definition: FrictionModel.h:62
agx::FrictionModel::DIRECT
@ DIRECT
Normal and friction equation calculated only in the DIRECT solver.
Definition: FrictionModel.h:58
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
agx::ScaleBoxFrictionModel::ScaleBoxFrictionModel
ScaleBoxFrictionModel(int callbackMask, SolveType preferredSolveType)
Definition: FrictionModel.h:251
agx::FrictionModel
Base class for all friction models with interface and some utility/necessary methods implemented.
Definition: FrictionModel.h:50
agx::ScaleBoxFrictionModel::~ScaleBoxFrictionModel
virtual ~ScaleBoxFrictionModel()
Definition: FrictionModel.h:252
agx::FrictionModel::getCallbackMask
int getCallbackMask() const
Definition: FrictionModel.h:293
AGXSTREAM_DECLARE_SERIALIZABLE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::FrictionModel::SolveType
SolveType
Definition: FrictionModel.h:55
agxStream::in
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
agx::FrictionModel::FrictionCallbackType
FrictionCallbackType
Definition: FrictionModel.h:65
Vec3.h
agx::ScaleBoxFrictionModel
Scale box friction.
Definition: FrictionModel.h:235
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agx::Physics::GeometryContactPtr
A geometry contact hold contact information between two geometries.
Definition: GeometryContactEntity.h:224
agx::FrictionModel::SCALE_BOUNDS
@ SCALE_BOUNDS
Scaled bounds, if direct, callbacks from CP-solver.
Definition: FrictionModel.h:69
agx::FrictionModel::hasCustomContactImplementation
bool hasCustomContactImplementation() const
Definition: FrictionModel.h:303
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Range.h
agx::FrictionModel::HAS_CUSTOM_CONTACT_IMPLEMENTATION
@ HAS_CUSTOM_CONTACT_IMPLEMENTATION
Custom implementation of the contact constraints associated to this friction model with this state.
Definition: FrictionModel.h:71
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Serializable.h
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:269
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::Range< Real >
agx::Vec3T< Real >
agx::BoxFrictionModel
Box friction.
Definition: FrictionModel.h:195
agx::FrictionModel::SPLIT
@ SPLIT
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Definition: FrictionModel.h:60
agx::FrictionModel::ITERATIVE
@ ITERATIVE
Normal and friction equation calculated only in the ITERATIVE solver.
Definition: FrictionModel.h:59
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::FrictionModel::getSolveType
SolveType getSolveType() const
Definition: FrictionModel.h:288