AGX Dynamics  2.37.3.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 }
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...
bool Bool
Definition: Integer.h:48
AGXCORE_EXPORT const Real RealEpsilon
const agx::AddedMassInteraction::Matrix6x6 & getBlock() const
Base class for a strong interaction concept where there interaction is defined in the mass matrix par...
6x6 matrix class with blockwise interface to get or set 3x3 matrices: [ M(0, 0) M(0, 1) ] [ M(1, 0) M(1, 1) ]
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
const agx::Real & at(size_t i, size_t j) const
Pointer to a entity instance of type Physics.RigidBody.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void set(size_t i, size_t j, agx::Real value)
Interface to write added mass matrices for one or two rigid bodies.
agx::Real operator()(size_t i, size_t j) const
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
void reset()
Resets all values to zero.
#define agxAssert(expr)
Definition: debug.h:143
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
#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
Class containing a rigid body and the 6x6 matrix to be written in the diagonal of the system matrix...
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
double Real
Definition: Real.h:42
const agx::Real * operator[](size_t i) const
const agx::AddedMassInteraction::Matrix6x6 & getOffDiagonalBlock() const
Off diagonal block (6x6 matrix).