AGXDynamics  2.35.0.3
AddedMassInteraction.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 #pragma once
17 
18 
19 #include <agx/StrongInteraction.h>
20 #include <agx/agx_valarray_types.h>
21 
22 namespace agx
23 {
25 
40  {
41  public:
48  {
49  public:
53  Matrix6x6();
54 
58  Matrix6x6( const Matrix6x6& other );
59 
64  Matrix6x6& operator=( const Matrix6x6& other );
65 
72  const agx::Real* operator[]( size_t i ) const;
73 
80  agx::Real* operator[]( size_t i );
81 
87  const agx::Real& at( size_t i, size_t j ) const;
88 
95  void set( size_t i, size_t j, agx::Real value );
96 
97 
103  agx::Real& at( size_t i, size_t j );
104 
108  Matrix6x6 transposed() const;
109 
116  agx::Matrix3x3 block( size_t i, size_t j ) const;
117 
124  void block( size_t i, size_t j, const agx::Matrix3x3& matrix );
125 
134  Matrix6x6 transform( const agx::Matrix3x3& left, const agx::Matrix3x3& right ) const;
135 
140  void multiply( const agx::Vec3 v1, const agx::Vec3 v2, agx::Real* result ) const;
141 
145  void reset();
146 
147  public:
151  void store( agxStream::OutputArchive& out ) const;
152 
156  void restore( agxStream::InputArchive& in );
157 
158  private:
159  agx::Real m_data[ 6 ][ 6 ];
160  };
161 
168  {
169  public:
178 
182  agx::RigidBody* getRigidBody() const;
183 
187  agx::Physics::RigidBodyPtr getRigidBodyEntity() const;
188 
193  agx::Bool getValid() const;
194 
198  const agx::AddedMassInteraction::Matrix6x6& getBlock() const;
199 
204 
205  public:
209  void store( agxStream::OutputArchive& out ) const;
210 
214  void restore( agxStream::InputArchive& in );
215 
216  private:
218  agx::Bool m_hadValidRb;
220  };
221 
222  public:
228  AddedMassInteraction( agx::RigidBody* rb1, agx::RigidBody* rb2 = nullptr );
229 
234  const agx::AddedMassInteraction::RigidBodyStorage* getRigidBody1Storage() const;
235 
240  agx::AddedMassInteraction::RigidBodyStorage* getRigidBody1Storage();
241 
246  const agx::AddedMassInteraction::RigidBodyStorage* getRigidBody2Storage() const;
247 
252  agx::AddedMassInteraction::RigidBodyStorage* getRigidBody2Storage();
253 
259  const agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock() const;
260 
266  agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock();
267 
271  void translateWorldDiagonalBlock( const agx::Vec3 cmOffset,
272  agx::AddedMassInteraction::Matrix6x6& matrix ) const;
273 
274  void translateWorldDiagonalBlock( const agx::Vec3 cmOffsetRb1,
275  const agx::Vec3 cmOffsetRb2,
276  agx::AddedMassInteraction::Matrix6x6& matrix ) const;
277 
278  public:
282  virtual agx::RigidBody* getRigidBody1() const override;
283 
287  virtual agx::RigidBody* getRigidBody2() const override;
288 
290 
291  protected:
292 
297 
301  virtual ~AddedMassInteraction();
302 
306  virtual void prepare() override;
307 
317  virtual void writeMatrixData( agx::StrongInteraction::MatrixData rb1DiagonalBlock,
318  agx::StrongInteraction::MatrixData rb2DiagonalBlock,
319  agx::StrongInteraction::MatrixData offDiagonalBlock ) override;
320 
324  virtual void writeRhs( agx::Physics::RigidBodyPtr rb1,
325  agx::Real* rb1Rhs,
327  agx::Real* rb2Rhs,
328  agx::Bool isRestingSolve ) override;
329 
330  private:
331  struct Transformed
332  {
333  AddedMassInteraction::Matrix6x6 rb1DiagonalBlock;
334  AddedMassInteraction::Matrix6x6 rb2DiagonalBlock;
335  AddedMassInteraction::Matrix6x6 offDiagonalBlock;
336 
337  void reset()
338  {
339  rb1DiagonalBlock.reset();
340  rb2DiagonalBlock.reset();
341  offDiagonalBlock.reset();
342  }
343  };
344 
345  private:
348  agx::AddedMassInteraction::Matrix6x6 m_offDiagonalBlock;
349  Transformed m_transformed;
350  };
351 
354 
356  {
357  agxAssert( i < 6 );
358  return m_data[ i ];
359  }
360 
362  {
363  agxAssert( i < 6 );
364  return m_data[ i ];
365  }
366 
368  {
369  agxAssert( j < 6 );
370  return (*this)[ i ][ j ];
371  }
372 
374  {
375  agxAssert( i < 6 );
376  agxAssert( j < 6 );
377  (*this)[ i ][ j ] = value;
378  }
379 
380 
382  {
383  agxAssert( j < 6 );
384  return (*this)[ i ][ j ];
385  }
386 
388  {
389  return m_block;
390  }
391 
393  {
394  return m_block;
395  }
396 
398  {
399  return m_offDiagonalBlock;
400  }
401 
403  {
404  return m_offDiagonalBlock;
405  }
406 }
agx::AddedMassInteraction::RigidBodyStorage
Class containing a rigid body and the 6x6 matrix to be written in the diagonal of the system matrix.
Definition: AddedMassInteraction.h:167
agx::RealEpsilon
const AGXCORE_EXPORT Real RealEpsilon
agx::Real
double Real
Definition: Real.h:42
agx::equivalent
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
agxData::transform
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
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
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
StrongInteraction.h
agx::StrongInteraction
Base class for a strong interaction concept where there interaction is defined in the mass matrix par...
Definition: StrongInteraction.h:42
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agx::AddedMassInteraction::Matrix6x6
6x6 matrix class with blockwise interface to get or set 3x3 matrices: [ M(0, 0) M(0,...
Definition: AddedMassInteraction.h:47
agx_valarray_types.h
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::Physics::RigidBodyPtr
Pointer to a entity instance of type Physics.RigidBody.
Definition: RigidBodyEntity.h:371
agx::observer_ptr< RigidBody >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
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::equalsZero
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
agx::AddedMassInteraction::Matrix6x6::operator[]
const agx::Real * operator[](size_t i) const
Definition: AddedMassInteraction.h:355
agx::AddedMassInteraction
Interface to write added mass matrices for one or two rigid bodies.
Definition: AddedMassInteraction.h:39
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agx::StrongInteraction::MatrixData
Definition: StrongInteraction.h:47
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::Bool
bool Bool
Definition: Integer.h:48
agx::AddedMassInteraction::getOffDiagonalBlock
const agx::AddedMassInteraction::Matrix6x6 & getOffDiagonalBlock() const
Off diagonal block (6x6 matrix).
Definition: AddedMassInteraction.h:397
agx::AddedMassInteraction::RigidBodyStorage::getBlock
const agx::AddedMassInteraction::Matrix6x6 & getBlock() const
Definition: AddedMassInteraction.h:387
agx::Vec3T< Real >
agx::AddedMassInteraction::Matrix6x6::set
void set(size_t i, size_t j, agx::Real value)
Definition: AddedMassInteraction.h:373
agx::Matrix3x3T< Real >
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::AddedMassInteraction::Matrix6x6::at
const agx::Real & at(size_t i, size_t j) const
Definition: AddedMassInteraction.h:367
agx::AddedMassInteraction::Matrix6x6::reset
void reset()
Resets all values to zero.