AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
AddedMassInteraction.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17
18
21
22namespace 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
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
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
172
173 private:
174 agx::Real m_data[ 6 ][ 6 ];
175 };
176
177
178
179
186 {
187 public:
196
201
206
212
216 const agx::AddedMassInteraction::Matrix6x6& getBlock() const;
217
222
223 public:
227 void store( agxStream::OutputArchive& out ) const;
228
233
234 private:
236 agx::Bool m_hadValidRb;
238 };
239
240 public:
247
253
259
265
271
277 const agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock() const;
278
284 agx::AddedMassInteraction::Matrix6x6& getOffDiagonalBlock();
285
291
292 void translateWorldDiagonalBlock( const agx::Vec3 cmOffsetRb1,
293 const agx::Vec3 cmOffsetRb2,
295
296 public:
300 virtual agx::RigidBody* getRigidBody1() const override;
301
305 virtual agx::RigidBody* getRigidBody2() const override;
306
308
309 protected:
310
315
320
324 virtual void prepare() override;
325
336 agx::StrongInteraction::MatrixData rb2DiagonalBlock,
337 agx::StrongInteraction::MatrixData offDiagonalBlock ) override;
338
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}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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:208
#define AGXPHYSICS_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
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
Matrix6x6 & operator=(const Matrix6x6 &other)
Assignment operator.
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()
Default constructor, sets all elements to 0.
void set(size_t i, size_t j, agx::Real value)
agx::Real operator()(size_t i, size_t j) const
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.
AddedMassInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2=nullptr)
Construct given either one or two rigid bodies.
agx::AddedMassInteraction::RigidBodyStorage * getRigidBody1Storage()
Storage of 'rb1' from construction containing the rigid body and a 6x6 matrix block.
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.
const agx::AddedMassInteraction::RigidBodyStorage * getRigidBody1Storage() const
Storage of 'rb1' from construction containing the rigid body and a 6x6 matrix block.
virtual agx::RigidBody * getRigidBody2() const override
const agx::AddedMassInteraction::RigidBodyStorage * getRigidBody2Storage() const
Storage of 'rb2' from construction containing the rigid body and a 6x6 matrix block.
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 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 agx::RigidBody * getRigidBody1() const override
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.
void translateWorldDiagonalBlock(const agx::Vec3 cmOffsetRb1, const agx::Vec3 cmOffsetRb2, agx::AddedMassInteraction::Matrix6x6 &matrix) const
virtual ~AddedMassInteraction()
Reference counted object, protected destructor.
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:52
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
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:40
AGXCORE_EXPORT const Real RealEpsilon
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
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)