AGX Dynamics  2.37.3.2
Material.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #pragma once
18 
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agxStream/Serializable.h>
22 #include <agx/FrictionModel.h>
28 #include <agx/macros.h>
29 #include <agx/SetVector.h>
30 
31 
32 #ifdef _MSC_VER
33 # pragma warning(push)
34 # pragma warning(disable: 4251) // warning C4251: class X needs to have dll-interface to be used by clients of class Y
35 #endif
36 
37 namespace agxSDK
38 {
39  class MaterialManager;
40 }
41 namespace agxIO
42 {
43  class SceneExporter;
44 }
45 namespace agxCollide
46 {
47  class GeometryContact;
48 }
49 namespace agxData
50 {
51  class EntityStorage;
52 }
53 
54 namespace agx
55 {
63 
64 
69  {
70  public:
71 
73  BulkMaterial();
74 
82  void setDensity(Real density);
83 
88  Real getDensity() const;
89 
93  void setYoungsModulus(Real value);
94 
98  Real getYoungsModulus() const;
99 
104  Real getDamping() const;
105 
111  void setDamping( Real damping );
112 
126  bool setMinMaxElasticRestLength(Real minElasticRestLength, Real maxElasticRestLength);
127 
134  Real getMinElasticRestLength() const;
135 
142  Real getMaxElasticRestLength() const;
143 
145  void copy( const BulkMaterial* source );
146 
151  void setViscosity( Real viscosity );
152 
156  Real getViscosity() const;
157 
161  bool isDirty() const;
162 
164 
165 
167 
170 
172  const Physics::BulkMaterialPtr& getEntity() const;
173 
174  protected:
175 
176  friend class Material;
177 
178  AGX_FORCE_INLINE void setDirty( bool flag ) const;
180 
181 
182  virtual ~BulkMaterial();
183 
184 
185 
186  private:
187  mutable Physics::BulkMaterialRef m_entity;
188  };
189 
190 
195  {
196  public:
197 
199  SurfaceMaterial();
200 
205  void setRoughness( Real roughness );
206 
211  Real getRoughness() const;
212 
222  void setAdhesion( Real adhesion, Real adhesiveOverlap );
223 
227  Real getAdhesion() const;
228 
232  Real getAdhesiveOverlap() const;
233 
239  void setViscosity( Real viscosity );
240 
244  Real getViscosity() const;
245 
250  bool getFrictionEnabled() const;
251 
257  void setFrictionEnabled( bool flag );
258 
260  bool isDirty() const;
261 
263 
265 
266 
270  void copy( const SurfaceMaterial* source );
271 
273 
274  const Physics::SurfaceMaterialPtr& getEntity() const;
275 
276  protected:
277 
278  friend class Material;
279  void setDirty( bool flag ) const;
280 
282 
283 
284  virtual ~SurfaceMaterial();
285 
286  private:
287  mutable Physics::SurfaceMaterialRef m_entity;
288  };
289 
290 
295  {
296  public:
297 
299  WireMaterial();
300 
304  Real getYoungsModulusStretch() const;
305 
309  Real getDampingStretch() const;
310 
314  Real getYoungsModulusBend() const;
315 
319  Real getDampingBend() const;
320 
325  void setYoungsModulusStretch( Real youngsStretch );
326 
331  void setDampingStretch( Real dampingStretch );
332 
337  void setYoungsModulusBend( Real youngsBend );
338 
343  void setDampingBend( Real dampingBend );
344 
346 
347 
349 
350  bool isDirty() const;
351  void setDirty(bool flag) const;
352 
354  void copy( const WireMaterial* source );
355 
357 
358  const Physics::WireMaterialPtr& getEntity() const;
359 
360  protected:
361 
362  friend class Material;
364 
365 
366  virtual ~WireMaterial();
367 
368  private:
369  mutable Physics::WireMaterialRef m_entity;
370  };
371 
372 
373 
376  {
377  public:
378 
384  Material( const agx::Name& name, const Material* parent = nullptr );
385 
393  Material( const agx::Name& name, Real restitution, Real friction );
394 
398  Material( const Material& material );
399 
403  SurfaceMaterial* getSurfaceMaterial();
404 
408  const SurfaceMaterial* getSurfaceMaterial() const;
409 
413  BulkMaterial* getBulkMaterial();
414 
418  const BulkMaterial* getBulkMaterial() const;
419 
423  WireMaterial* getWireMaterial();
424 
428  const WireMaterial* getWireMaterial() const;
429 
433  const agx::Name& getName() const;
434 
438  void setName( const agx::Name& name ) {
439  m_entity.name() = name;
440  }
441 
443  static Material* getDefaultMaterial();
444 
446 
447 
450  bool isDirty() const;
451 
452 
458  bool loadLibraryMaterial( agx::String name );
459 
460 
464  static agx::StringVector getAvailableLibraryMaterials();
465 
466 
471  bool isLibraryMaterial() const;
472 
474 
475 
477 
478  const Physics::MaterialPtr& getEntity() const;
479 
481  void copy(const Material* other);
482 
484 
485 
486  protected:
487 
489  Material();
490 
492  virtual ~Material();
493 
494  private:
496  void setDirty( bool flag ) const;
497 
499  void init(const Name& name);
500 
501  private:
502  BulkMaterialRef m_bulkMaterial;
503  SurfaceMaterialRef m_surfaceMaterial;
504  WireMaterialRef m_wireMaterial;
505 
506  mutable Physics::MaterialRef m_entity;
507  };
508 
509 
516  {
517  public:
522  BOTH_PRIMARY_AND_SECONDARY
523  };
524 
529  REDUCE_ALL
530  };
531 
532  public:
533 
540  ContactMaterial( const Material* m1, const Material* m2, bool implicit=false );
541 
547  ContactMaterial( const ContactMaterial* other, bool implicit );
548 
554  void setRestitution( Real restitution );
555 
563  void setTangentialRestitution( Real restitution, FrictionDirection direction = BOTH_PRIMARY_AND_SECONDARY );
564 
571  void setFrictionCoefficient( Real friction, FrictionDirection direction = BOTH_PRIMARY_AND_SECONDARY );
572 
579  void setSurfaceViscosity( Real viscosity, FrictionDirection direction = BOTH_PRIMARY_AND_SECONDARY );
580 
590  void setAdhesion( Real adhesion, Real adhesiveOverlap );
591 
595  Real getAdhesion() const;
596 
600  Real getAdhesiveOverlap() const;
601 
605  Real getRestitution() const;
606 
610  Real getTangentialRestitution( FrictionDirection direction = PRIMARY_DIRECTION ) const;
611 
615  Real getFrictionCoefficient( FrictionDirection direction = PRIMARY_DIRECTION ) const;
616 
620  Real getSurfaceViscosity( FrictionDirection direction = PRIMARY_DIRECTION ) const;
621 
625  bool getSurfaceFrictionEnabled() const;
626 
630  void setEnableSurfaceFriction( bool flag );
631 
633  void setYoungsModulus( Real youngsModulus );
634 
636  Real getYoungsModulus() const ;
637 
643  void setDamping( Real damping );
644 
658  bool setMinMaxElasticRestLength(Real minElasticRestLength, Real maxElasticRestLength);
659 
666  Real getMinElasticRestLength() const;
667 
674  Real getMaxElasticRestLength() const;
675 
680  Real getDamping() const ;
681 
685  FrictionModel* getFrictionModel() const;
686 
690  void setFrictionModel( FrictionModel* frictionModel );
691 
695  const Material* getMaterial1() const;
696 
700  const Material* getMaterial2() const;
701 
705  bool isExplicit() const;
706 
711  void setContactReductionMode( ContactReductionMode mode );
712 
717  ContactReductionMode getContactReductionMode( ) const;
718 
726  void setContactReductionBinResolution( agx::UInt8 binResolution );
727 
731  agx::UInt8 getContactReductionBinResolution() const;
732 
738  void setUseContactAreaApproach( bool useContactAreaApproach );
739 
745  bool getUseContactAreaApproach() const;
746 
753  void setRollingResistanceCoefficient(agx::Real rollingCoefficient);
754 
761  void setTwistingResistanceCoefficient(agx::Real twistingCoefficient);
762 
766  agx::Real getRollingResistanceCoefficient() const;
767 
771  agx::Real getTwistingResistanceCoefficient() const;
772 
779  void setRollingResistanceCompliance(agx::Real compliance);
780 
787  void setTwistingResistanceCompliance(agx::Real compliance);
788 
792  agx::Real getRollingResistanceCompliance() const;
793 
797  agx::Real getTwistingResistanceCompliance() const;
798 
804  void setImpactCompliance(agx::Real impactCompliance);
805 
809  agx::Real getImpactCompliance() const;
810 
819  void setWireFrictionCoefficient( Real friction, FrictionDirection direction = BOTH_PRIMARY_AND_SECONDARY );
820 
824  Real getWireFrictionCoefficient( FrictionDirection direction = PRIMARY_DIRECTION ) const;
825 
827 
828 
837  agx::ContactMaterial* clone( const agx::Material* material1, const agx::Material* material2 ) const;
838 
839 
843  void copyInto( ContactMaterial& target ) const;
844 
845  void transfer( agxData::EntityStorage* storage );
846 
847 
849 
850  Physics::ContactMaterialPtr& getEntity();
851 
852  const Physics::ContactMaterialPtr& getEntity() const;
853 
859  enum class RestitutionCoefficient
860  {
861  NORMAL,
862  TANGENTIAL_PRIMARY,
863  TANGENTIAL_SECONDARY
864  };
865 
867 
868  protected:
869  ContactMaterial();
870  virtual ~ContactMaterial();
871 
872  private:
873 
874  ContactMaterial( const ContactMaterial& m );
875 
876  ContactMaterial& operator = ( const ContactMaterial& );
877 
878  void setDefaultParameters();
879 
880  friend class agxSDK::MaterialManager;
881  friend class agxCollide::GeometryContact;
882  friend class agxIO::SceneExporter;
883  void setIsExplicit( bool is_explicit );
884 
885 
886  private:
887  ref_ptr<const Material> m_material1;
888  ref_ptr<const Material> m_material2;
889  FrictionModelRef m_frictionModel;
890 
891  mutable Physics::ContactMaterialRef m_entity;
892  };
893 
894 
895  /* Implementation */
896 
897 
898  // SurfaceMaterial AGX_FORCE_INLINE implementation
899  AGX_FORCE_INLINE bool SurfaceMaterial::getFrictionEnabled() const
900  {
901  return m_entity.frictionEnabled();
902  }
903 
904  AGX_FORCE_INLINE Real SurfaceMaterial::getRoughness() const
905  {
906  return m_entity.roughness();
907  }
908 
909  AGX_FORCE_INLINE Real SurfaceMaterial::getAdhesion() const
910  {
911  return m_entity.adhesion();
912  }
913 
914  AGX_FORCE_INLINE Real SurfaceMaterial::getAdhesiveOverlap() const
915  {
916  return m_entity.adhesiveOverlap();
917  }
918 
919  AGX_FORCE_INLINE Real SurfaceMaterial::getViscosity() const
920  {
921  return m_entity.viscosity();
922  }
923 
925  AGX_FORCE_INLINE bool SurfaceMaterial::isDirty() const
926  {
927  return m_entity.dirty();
928  }
929 
930  AGX_FORCE_INLINE void SurfaceMaterial::setDirty( bool flag ) const
931  {
932  m_entity.dirty() = flag;
933  }
935 
937  AGX_FORCE_INLINE bool WireMaterial::isDirty() const
938  {
939  return m_entity.dirty();
940  }
941 
942  AGX_FORCE_INLINE void WireMaterial::setDirty( bool flag ) const
943  {
944  m_entity.dirty() = flag;
945  }
947 
948  AGX_FORCE_INLINE Real WireMaterial::getYoungsModulusStretch() const
949  {
950  return m_entity.youngsModulusStretch();
951  }
952 
953  AGX_FORCE_INLINE Real WireMaterial::getDampingStretch() const
954  {
955  return m_entity.dampingStretch();
956  }
957 
958  AGX_FORCE_INLINE Real WireMaterial::getYoungsModulusBend() const
959  {
960  return m_entity.youngsModulusBend();
961  }
962 
963  AGX_FORCE_INLINE Real WireMaterial::getDampingBend() const
964  {
965  return m_entity.dampingBend();
966  }
967 
968  AGX_FORCE_INLINE void WireMaterial::setYoungsModulusStretch( Real youngsStretch )
969  {
970  setDirty( true );
971  m_entity.youngsModulusStretch() = youngsStretch;
972  }
973 
974  AGX_FORCE_INLINE void WireMaterial::setDampingStretch( Real dampingStretch )
975  {
976  setDirty( true );
977  m_entity.dampingStretch() = dampingStretch;
978  }
979 
980  AGX_FORCE_INLINE void WireMaterial::setYoungsModulusBend( Real youngsBend )
981  {
982  setDirty( true );
983  m_entity.youngsModulusBend() = youngsBend;
984  }
985 
986  AGX_FORCE_INLINE void WireMaterial::setDampingBend( Real dampingBend )
987  {
988  setDirty( true );
989  m_entity.dampingBend() = dampingBend;
990  }
991 
992  // BulkMaterial AGX_FORCE_INLINE implementation
993  AGX_FORCE_INLINE Real BulkMaterial::getViscosity() const
994  {
995  return m_entity.viscosity();
996  }
997 
998  AGX_FORCE_INLINE Real BulkMaterial::getDamping() const
999  {
1000  return m_entity.damping();
1001  }
1002 
1003  AGX_FORCE_INLINE Real BulkMaterial::getYoungsModulus() const
1004  {
1005  return m_entity.youngsModulus();
1006  }
1007 
1008  AGX_FORCE_INLINE Real BulkMaterial::getDensity() const
1009  {
1010  return m_entity.density();
1011  }
1012 
1013  AGX_FORCE_INLINE bool BulkMaterial::isDirty() const
1014  {
1015  return m_entity.dirty();
1016  }
1017 
1019  AGX_FORCE_INLINE void BulkMaterial::setDirty( bool flag ) const
1020  {
1021  m_entity.dirty() = flag;
1022  }
1024 
1025  // Material AGX_FORCE_INLINE implementation
1027  {
1028  return m_surfaceMaterial;
1029  }
1030 
1031  AGX_FORCE_INLINE const SurfaceMaterial* Material::getSurfaceMaterial() const
1032  {
1033  return m_surfaceMaterial;
1034  }
1035 
1036  AGX_FORCE_INLINE BulkMaterial* Material::getBulkMaterial()
1037  {
1038  return m_bulkMaterial;
1039  }
1040 
1041  AGX_FORCE_INLINE const BulkMaterial* Material::getBulkMaterial() const
1042  {
1043  return m_bulkMaterial;
1044  }
1045 
1046  AGX_FORCE_INLINE WireMaterial* Material::getWireMaterial()
1047  {
1048  return m_wireMaterial;
1049  }
1050 
1051  AGX_FORCE_INLINE const WireMaterial* Material::getWireMaterial() const
1052  {
1053  return m_wireMaterial;
1054  }
1055 
1057  AGX_FORCE_INLINE bool Material::isDirty() const
1058  {
1059  return m_surfaceMaterial->isDirty() || m_bulkMaterial->isDirty() || m_wireMaterial->isDirty();
1060  }
1061 
1062  AGX_FORCE_INLINE void Material::setDirty( bool flag ) const
1063  {
1064  m_surfaceMaterial->setDirty(flag);
1065  m_bulkMaterial->setDirty(flag);
1066  m_wireMaterial->setDirty(flag);
1067  }
1069 
1070 
1071  AGX_FORCE_INLINE const agx::Name& Material::getName() const
1072  {
1073  return m_entity.name();
1074  }
1075 
1076  // ContactMaterial AGX_FORCE_INLINE implementation
1077  AGX_FORCE_INLINE Real ContactMaterial::getRestitution() const
1078  {
1079  return m_entity.restitution()[ (int)RestitutionCoefficient::NORMAL ];
1080  }
1081 
1082  AGX_FORCE_INLINE Real ContactMaterial::getFrictionCoefficient(FrictionDirection direction) const
1083  {
1084  return m_entity.friction()[ agx::clamp< int >( direction, 0, 1 ) ];
1085  }
1086 
1087  AGX_FORCE_INLINE Real ContactMaterial::getSurfaceViscosity( FrictionDirection direction /* = PRIMARY_DIRECTION */ ) const
1088  {
1089  return m_entity.viscosity()[ agx::clamp< int >( direction, 0, 1 ) ];
1090  }
1091 
1092  AGX_FORCE_INLINE Real ContactMaterial::getAdhesion() const
1093  {
1094  return m_entity.adhesion();
1095  }
1096 
1097  AGX_FORCE_INLINE Real ContactMaterial::getAdhesiveOverlap() const
1098  {
1099  return m_entity.adhesiveOverlap();
1100  }
1101 
1102  AGX_FORCE_INLINE bool ContactMaterial::getSurfaceFrictionEnabled() const
1103  {
1104  return m_entity.surfaceFrictionEnabled();
1105  }
1106 
1107  AGX_FORCE_INLINE Real ContactMaterial::getYoungsModulus() const
1108  {
1109  return m_entity.youngsModulus();
1110  }
1111 
1112  AGX_FORCE_INLINE Real ContactMaterial::getDamping() const
1113  {
1114  return m_entity.damping();
1115  }
1116 
1117  AGX_FORCE_INLINE FrictionModel* ContactMaterial::getFrictionModel() const
1118  {
1119  return m_frictionModel;
1120  }
1121 
1122  AGX_FORCE_INLINE bool ContactMaterial::isExplicit() const
1123  {
1124  return m_entity.isExplicit();
1125  }
1126 
1127  AGX_FORCE_INLINE const Material* ContactMaterial::getMaterial1() const
1128  {
1129  return m_material1;
1130  }
1131 
1132  AGX_FORCE_INLINE const Material* ContactMaterial::getMaterial2() const
1133  {
1134  return m_material2;
1135  }
1136 
1137  AGX_FORCE_INLINE ContactMaterial::ContactReductionMode ContactMaterial::getContactReductionMode( ) const
1138  {
1139  return (ContactReductionMode)m_entity.contactReductionMode();
1140  }
1141 
1142  AGX_FORCE_INLINE agx::UInt8 ContactMaterial::getContactReductionBinResolution() const
1143  {
1144  return m_entity.contactReductionBinResolution();
1145  }
1146 
1148 
1150  {
1151  return m_entity;
1152  }
1154  {
1155  return m_entity;
1156  }
1157 
1159  {
1160  return m_entity;
1161  }
1162 
1164  {
1165  return m_entity;
1166  }
1167 
1168 
1170  {
1171  return m_entity;
1172  }
1173 
1175  {
1176  return m_entity;
1177  }
1178 
1179 
1181  {
1182  return m_entity;
1183  }
1184 
1186  {
1187  return m_entity;
1188  }
1189 
1190 
1192  {
1193  return m_entity;
1194  }
1195 
1197  {
1198  return m_entity;
1199  }
1201 
1202  AGX_FORCE_INLINE agx::Real ContactMaterial::getRollingResistanceCoefficient() const
1203  {
1204  return m_entity.rollingResistanceCoefficient();
1205  }
1206 
1207  AGX_FORCE_INLINE agx::Real ContactMaterial::getRollingResistanceCompliance() const
1208  {
1209  return m_entity.rollingResistanceCompliance();
1210  }
1211 
1212  AGX_FORCE_INLINE agx::Real ContactMaterial::getTwistingResistanceCompliance() const
1213  {
1214  return m_entity.twistingResistanceCompliance();
1215  }
1216 
1218  {
1219  return m_entity.impactCompliance();
1220  }
1221 
1223  {
1224  return m_entity.useContactAreaApproach();
1225  }
1226 
1227  AGX_FORCE_INLINE Real ContactMaterial::getWireFrictionCoefficient(FrictionDirection direction) const
1228  {
1229  return m_entity.wireFriction()[ agx::clamp< int >( direction, 0, 1 ) ];
1230  }
1231 } // namespace agx
1232 
1233 #ifdef _MSC_VER
1234 # pragma warning(pop)
1235 #endif
1236 
1237 
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
Physical properties for the bulk of geometries made up by a Material.
Definition: Material.h:68
The agxIO namespace contains classes for reading, writing and finding files.
Definition: Material.h:41
No contact reduction enabled.
Definition: Material.h:527
Base class for all friction models with interface and some utility/necessary methods implemented...
Definition: FrictionModel.h:50
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Pointer to a entity instance of type Physics.Material.
agx::Vector< agx::ref_ptr< agx::ContactMaterial > > ContactMaterialRefVector
Definition: Material.h:62
uint8_t UInt8
Definition: Integer.h:38
void setName(const agx::Name &name)
Set the name of the material.
Definition: Material.h:438
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
Physical properties for the contact between a Geometry and an agx::Wire.
Definition: Material.h:294
Base class providing referencing counted objects.
Definition: Referenced.h:119
Pointer to a entity instance of type Physics.WireMaterial.
Templated vector class.
Definition: Vector.h:52
agx::SetVector< agx::ref_ptr< agx::ContactMaterial > > ContactMaterialRefSetVector
Definition: Material.h:61
Pointer to a entity instance of type Physics.BulkMaterial.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Physical properties for the surface of a Material.
Definition: Material.h:194
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
agx::Real getImpactCompliance() const
Definition: Material.h:1217
ContactReductionMode
Specifies the mode for contact reduction.
Definition: Material.h:526
FrictionDirection
Specifies the direction of friction.
Definition: Material.h:519
AGXFMI_EXPORT InputVariable_Real * setDamping(agx::Constraint *constraint)
#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
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Simulation unique manager that handles logics around and parameters in contact materials given two ag...
bool getUseContactAreaApproach() const
Should contacts using this contact material use the new approach for computing contact area...
Definition: Material.h:1222
Default: Reduce contacts between geometries.
Definition: Material.h:528
double Real
Definition: Real.h:42
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
Pointer to a entity instance of type Physics.SurfaceMaterial.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
Pointer to a entity instance of type Physics.ContactMaterial.
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.