AGX Dynamics  2.38.0.2
AddedMassInteraction.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 #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 
94  agx::Real operator()(size_t i, size_t j) const;
95 
101  agx::Real& operator()(size_t i, size_t j);
102 
103 
110  void set( size_t i, size_t j, agx::Real value );
111 
112 
118  agx::Real& at( size_t i, size_t j );
119 
123  Matrix6x6 transposed() const;
124 
131  agx::Matrix3x3 block( size_t i, size_t j ) const;
132 
139  void block( size_t i, size_t j, const agx::Matrix3x3& matrix );
140 
149  Matrix6x6 transform( const agx::Matrix3x3& left, const agx::Matrix3x3& right ) const;
150 
155  void multiply( const agx::Vec3 v1, const agx::Vec3 v2, agx::Real* result ) const;
156 
160  void reset();
161 
162  public:
166  void store( agxStream::OutputArchive& out ) const;
167 
171  void restore( agxStream::InputArchive& in );
172 
173  private:
174  agx::Real m_data[ 6 ][ 6 ];
175  };
176 
177 
178 
179 
186  {
187  public:
196 
200  agx::RigidBody* getRigidBody() const;
201 
205  agx::Physics::RigidBodyPtr getRigidBodyEntity() const;
206 
211  agx::Bool getValid() const;
212 
216  const agx::AddedMassInteraction::Matrix6x6& getBlock() const;
217 
222 
223  public:
227  void store( agxStream::OutputArchive& out ) const;
228 
232  void restore( agxStream::InputArchive& in );
233 
234  private:
236  agx::Bool m_hadValidRb;
238  };
239 
240  public:
246  AddedMassInteraction( agx::RigidBody* rb1, agx::RigidBody* rb2 = nullptr );
247 
252  const agx::AddedMassInteraction::RigidBodyStorage* getRigidBody1Storage() const;
253 
258  agx::AddedMassInteraction::RigidBodyStorage* getRigidBody1Storage();
259 
264  const agx::AddedMassInteraction::RigidBodyStorage* getRigidBody2Storage() const;
265 
270  agx::AddedMassInteraction::RigidBodyStorage* getRigidBody2Storage();
271 
277  const agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock() const;
278 
284  agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock();
285 
289  void translateWorldDiagonalBlock( const agx::Vec3 cmOffset,
290  agx::AddedMassInteraction::Matrix6x6& matrix ) const;
291 
292  void translateWorldDiagonalBlock( const agx::Vec3 cmOffsetRb1,
293  const agx::Vec3 cmOffsetRb2,
294  agx::AddedMassInteraction::Matrix6x6& matrix ) const;
295 
296  public:
300  virtual agx::RigidBody* getRigidBody1() const override;
301 
305  virtual agx::RigidBody* getRigidBody2() const override;
306 
308 
309  protected:
310 
315 
319  virtual ~AddedMassInteraction();
320 
324  virtual void prepare() override;
325 
335  virtual void writeMatrixData( agx::StrongInteraction::MatrixData rb1DiagonalBlock,
336  agx::StrongInteraction::MatrixData rb2DiagonalBlock,
337  agx::StrongInteraction::MatrixData offDiagonalBlock ) override;
338 
342  virtual void writeRhs( agx::Physics::RigidBodyPtr rb1,
343  agx::Real* rb1Rhs,
345  agx::Real* rb2Rhs,
346  agx::Bool isRestingSolve ) override;
347 
348  private:
349  struct Transformed
350  {
351  AddedMassInteraction::Matrix6x6 rb1DiagonalBlock;
352  AddedMassInteraction::Matrix6x6 rb2DiagonalBlock;
353  AddedMassInteraction::Matrix6x6 offDiagonalBlock;
354 
355  void reset()
356  {
357  rb1DiagonalBlock.reset();
358  rb2DiagonalBlock.reset();
359  offDiagonalBlock.reset();
360  }
361  };
362 
363  private:
366  agx::AddedMassInteraction::Matrix6x6 m_offDiagonalBlock;
367  Transformed m_transformed;
368  };
369 
370 
371 
372 
373 
376 
378  {
379  agxAssert( i < 6 );
380  return m_data[ i ];
381  }
382 
384  {
385  agxAssert( i < 6 );
386  return m_data[ i ];
387  }
388 
390  {
391  agxAssert(j < 6);
392  return (*this)[i][j];
393  }
394 
396  {
397  agxAssert(j < 6);
398  return (*this)[i][j];
399  }
400 
402  {
403  agxAssert( j < 6 );
404  return (*this)[ i ][ j ];
405  }
406 
408  {
409  agxAssert( i < 6 );
410  agxAssert( j < 6 );
411  (*this)[ i ][ j ] = value;
412  }
413 
414 
416  {
417  agxAssert( j < 6 );
418  return (*this)[ i ][ j ];
419  }
420 
422  {
423  return m_block;
424  }
425 
427  {
428  return m_block;
429  }
430 
432  {
433  return m_offDiagonalBlock;
434  }
435 
437  {
438  return m_offDiagonalBlock;
439  }
440 
441  inline std::ostream& operator<< (std::ostream& os, const agx::AddedMassInteraction::Matrix6x6& m)
442  {
443  os << "{" << std::endl;
444  for (size_t row = 0; row < 6; ++row) {
445  os << "\t";
446  for (size_t col = 0; col < 6; ++col)
447  os << m(row, col) << " ";
448  os << std::endl;
449  }
450  os << "}" << std::endl;
451  return os;
452  }
453 
454 }
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:185
agx::operator<<
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
Definition: AddedMassInteraction.h:441
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:51
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
agx::AddedMassInteraction::Matrix6x6::operator()
agx::Real operator()(size_t i, size_t j) const
Definition: AddedMassInteraction.h:389
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:399
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:377
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:50
agx::StrongInteraction::MatrixData
Definition: StrongInteraction.h:47
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Bool
bool Bool
Definition: Integer.h:40
agx::AddedMassInteraction::getOffDiagonalBlock
const agx::AddedMassInteraction::Matrix6x6 & getOffDiagonalBlock() const
Off diagonal block (6x6 matrix).
Definition: AddedMassInteraction.h:431
agx::AddedMassInteraction::RigidBodyStorage::getBlock
const agx::AddedMassInteraction::Matrix6x6 & getBlock() const
Definition: AddedMassInteraction.h:421
agx::Vec3T< Real >
agx::AddedMassInteraction::Matrix6x6::set
void set(size_t i, size_t j, agx::Real value)
Definition: AddedMassInteraction.h:407
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:401
agx::AddedMassInteraction::Matrix6x6::reset
void reset()
Resets all values to zero.