AGX Dynamics  2.35.0.1
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:
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 
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:
152 
157 
158  private:
159  agx::Real m_data[ 6 ][ 6 ];
160  };
161 
168  {
169  public:
178 
183 
188 
194 
198  const agx::AddedMassInteraction::Matrix6x6& getBlock() const;
199 
204 
205  public:
210 
215 
216  private:
218  agx::Bool m_hadValidRb;
220  };
221 
222  public:
229 
235 
241 
247 
253 
259  const agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock() const;
260 
266  agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock();
267 
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 
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 
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 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
#define AGXPHYSICS_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:52
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
6x6 matrix class with blockwise interface to get or set 3x3 matrices: [ M(0, 0) M(0,...
void block(size_t i, size_t j, const agx::Matrix3x3 &matrix)
const agx::Real * operator[](size_t i) const
agx::Matrix3x3 block(size_t i, size_t j) const
Matrix6x6(const Matrix6x6 &other)
Copy constructor.
void restore(agxStream::InputArchive &in)
Internal.
Matrix6x6 transform(const agx::Matrix3x3 &left, const agx::Matrix3x3 &right) const
Returns a transformed version of this matrix: [ left M(0, 0) right left M(0, 1) right ] [ left M(1,...
void store(agxStream::OutputArchive &out) const
Internal.
void reset()
Resets all values to zero.
const agx::Real & at(size_t i, size_t j) const
void multiply(const agx::Vec3 v1, const agx::Vec3 v2, agx::Real *result) const
Performs result += M * [v1] [v2].
Matrix6x6 & operator=(const Matrix6x6 &other)
Assignment operator.
Matrix6x6()
Default constructor, sets all elements to 0.
void set(size_t i, size_t j, agx::Real value)
Class containing a rigid body and the 6x6 matrix to be written in the diagonal of the system matrix.
void store(agxStream::OutputArchive &out) const
Internal.
const agx::AddedMassInteraction::Matrix6x6 & getBlock() const
agx::Physics::RigidBodyPtr getRigidBodyEntity() const
RigidBodyStorage(agx::RigidBody *rb)
Construct given rigid body.
void restore(agxStream::InputArchive &in)
Internal.
Interface to write added mass matrices for one or two rigid bodies.
const agx::AddedMassInteraction::RigidBodyStorage * getRigidBody1Storage() const
Storage of 'rb1' from construction containing the rigid body and a 6x6 matrix block.
AddedMassInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2=nullptr)
Construct given either one or two rigid bodies.
void translateWorldDiagonalBlock(const agx::Vec3 cmOffset, agx::AddedMassInteraction::Matrix6x6 &matrix) const
Transform the mass matrix according to a translate of center of mass.
AddedMassInteraction()
Default constructor used by serialization.
agx::AddedMassInteraction::RigidBodyStorage * getRigidBody2Storage()
Storage of 'rb2' from construction containing the rigid body and a 6x6 matrix block.
const agx::AddedMassInteraction::Matrix6x6 & getOffDiagonalBlock() const
Off diagonal block (6x6 matrix).
virtual agx::RigidBody * getRigidBody1() const override
virtual agx::RigidBody * getRigidBody2() const override
virtual void writeMatrixData(agx::StrongInteraction::MatrixData rb1DiagonalBlock, agx::StrongInteraction::MatrixData rb2DiagonalBlock, agx::StrongInteraction::MatrixData offDiagonalBlock) override
Call from the direct solver with pointers where to write diagonal block(s) and the off diagonal block...
virtual void prepare() override
Checks if this interaction is valid for the solver.
virtual void writeRhs(agx::Physics::RigidBodyPtr rb1, agx::Real *rb1Rhs, agx::Physics::RigidBodyPtr rb2, agx::Real *rb2Rhs, agx::Bool isRestingSolve) override
Right hand side update.
agx::AddedMassInteraction::RigidBodyStorage * getRigidBody1Storage()
Storage of 'rb1' from construction containing the rigid body and a 6x6 matrix block.
void translateWorldDiagonalBlock(const agx::Vec3 cmOffsetRb1, const agx::Vec3 cmOffsetRb2, agx::AddedMassInteraction::Matrix6x6 &matrix) const
virtual ~AddedMassInteraction()
Reference counted object, protected destructor.
const agx::AddedMassInteraction::RigidBodyStorage * getRigidBody2Storage() const
Storage of 'rb2' from construction containing the rigid body and a 6x6 matrix block.
Pointer to a entity instance of type Physics.RigidBody.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Base class for a strong interaction concept where there interaction is defined in the mass matrix par...
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
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
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.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:48
AGXCORE_EXPORT const Real RealEpsilon
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
double Real
Definition: Real.h:42
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)