proteus  1.8.1
C/C++/Fortran libraries
ChVariablesBodyAddedMass.cpp
Go to the documentation of this file.
1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Tristan de Lataillade
13 // =============================================================================
14 
16 
17 namespace chrono {
18 
19 // Register into the object factory, to enable run-time dynamic creation and persistence
20 CH_FACTORY_REGISTER(ChVariablesBodyAddedMass)
21 
23  Maddedmass = ChMatrixDynamic<>(ndof, ndof);
24  Maddedmass.setIdentity();
25  Mmass = ChMatrixDynamic<>(ndof, ndof);
26  Mmass.setIdentity();
27  Mfullmass = ChMatrixDynamic<>(ndof, ndof);
28  Mfullmass.setIdentity();
29  inv_Mfullmass = ChMatrixDynamic<>(ndof, ndof);
30  inv_Mfullmass.setIdentity();
31 }
32 
34  if (&other == this)
35  return *this;
36 
37  // copy parent class data
38  ChVariablesBodyOwnMass::operator=(other);
39 
40  // copy class data
41  Mmass = other.Mmass;
42  Maddedmass = other.Maddedmass;
43  Mfullmass = other.Mfullmass;
44  inv_Mfullmass = other.inv_Mfullmass;
45  return *this;
46 }
47 
48 void ChVariablesBodyAddedMass::SetMfullmass(ChMatrixDynamic<>& Mfullmass_in) {
49  assert(Mfullmass_in.rows() == Get_ndof());
50  assert(Mfullmass_in.cols() == Get_ndof());
51  GetMfullmass() = Mfullmass_in;
52  GetInvMfullmass() = Mfullmass_in.inverse();
53 }
54 
55  // Set the inertia matrix
56  // void ChVariablesBodyAddedMass::SetBodyInertia(const ChMatrix33<>& minertia) {
57  // ChVariablesBodyOwnMass::SetBodyInertia(minertia);
58  // GetLog() << "JUST SET " << ChVariablesBodyOwnMass::GetBodyInertia();
59  // GetLog() << "JUST SET 2 " << GetBodyInertia();
60  // }
61 
62  // // Set the mass associated with translation of body
63  // void ChVariablesBodyAddedMass::SetBodyMass(const double mmass) {
64  // ChVariablesBodyOwnMass::SetBodyMass(mmass);
65  // }
66 // /// Set the inertia matrix
67 // void ChVariablesBodyAddedMass::SetBodyInertia(const ChMatrix33<>& minertia) {
68 // ChVariablesBodyOwnMass::SetBodyInertia(minertia);
69 // /// Add inertia to mass matrix
70 // ChMatrix33<>& bodyinertia = ChVariablesBodyOwnMass::GetBodyInertia();
71 // for (int i = 0; i < 3; i++) {
72 // for (int j = 0; j < 3; j++) {
73 // Mmass(3 + i, 3 + j) = bodyinertia(i, j);
74 // }
75 // }
76 // Mfullmass = Mmass + Maddedmass;
77 // }
78 
79 
80 // /// Set the mass associated with translation of body
81 // void ChVariablesBodyAddedMass::SetBodyMass(const double mmass) {
82 // /// Value of mass as double
83 // ChVariablesBodyOwnMass::SetBodyMass(mmass);
84 // /// Value of mass in mass matrix
85 // Mmass(0, 0) = mmass;
86 // Mmass(1, 1) = mmass;
87 // Mmass(2, 2) = mmass;
88 // /// rebuild full mass matrix
89 // Mfullmass = Mmass + Maddedmass;
90 // }
91 
92 // /// Set the added mass matrix of the body (6x6)
93 // void ChVariablesBodyAddedMass::SetBodyAddedMass(ChMatrixDynamic<>& Maddedmass_in) {
94 // assert(Maddedmass_in.GetRows() == Get_ndof());
95 // assert(Maddedmass_in.GetColums() == Get_ndof());
96 // Maddedmass.CopyFromMatrix(Maddedmass_in);
97 // /// rebuild full mass matrix
98 // Mfullmass = Mmass + Maddedmass;
99 // }
100 
101 // Computes the product of the inverse mass matrix by a
102 // vector, and set in result: result = [invMb]*vect
103 void ChVariablesBodyAddedMass::Compute_invMb_v(ChVectorRef result, const ChVectorConstRef vect) const {
104  assert(vect.size() == Get_ndof());
105  assert(result.size() == Get_ndof());
106  result = inv_Mfullmass * vect;
107 }
108 
109 // Computes the product of the inverse mass matrix by a
110 // vector, and increment result: result += [invMb]*vect
111 void ChVariablesBodyAddedMass::Compute_inc_invMb_v(ChVectorRef result, const ChVectorConstRef vect) const {
112  assert(vect.size() == Get_ndof());
113  assert(result.size() == Get_ndof());
114  result += inv_Mfullmass * vect;
115 }
116 
117 // Computes the product of the mass matrix by a
118 // vector, and set in result: result = [Mb]*vect
119 void ChVariablesBodyAddedMass::Compute_inc_Mb_v(ChVectorRef result, const ChVectorConstRef vect) const {
120  assert(vect.size() == Get_ndof());
121  assert(result.size() == Get_ndof());
122  result += Mfullmass * vect;
123 }
124 
125 // Computes the product of the corresponding block in the
126 // system matrix (ie. the mass matrix) by 'vect', scale by c_a, and add to 'result'.
127 // NOTE: the 'vect' and 'result' vectors must already have
128 // the size of the total variables&constraints in the system; the procedure
129 // will use the ChVariable offsets (that must be already updated) to know the
130 // indexes in result and vect.
132  const ChVectorConstRef vect,
133  const double c_a) const {
134  int off = this->offset;
135  result.segment(off, 6) += Mfullmass*vect.segment(off, 6)*c_a;
136 }
137 
138 // Add the diagonal of the mass matrix scaled by c_a to 'result'.
139 // NOTE: the 'result' vector must already have the size of system unknowns, ie
140 // the size of the total variables&constraints in the system; the procedure
141 // will use the ChVariable offset (that must be already updated) as index.
142 void ChVariablesBodyAddedMass::DiagonalAdd(ChVectorRef result, const double c_a) const {
143  assert(result.size() >= this->offset + Get_ndof());
144  for (int i = 0; i < Get_ndof(); i++) {
145  result(this->offset + i) += c_a * Mfullmass(i, i);
146  }
147 }
148 
149 // Build the mass matrix (for these variables) scaled by c_a, storing
150 // it in 'storage' sparse matrix, at given column/row offset.
151 // Note, most iterative solvers don't need to know mass matrix explicitly.
152 // Optimized: doesn't fill unneeded elements except mass and 3x3 inertia.
153 void ChVariablesBodyAddedMass::Build_M(ChSparseMatrix& storage, int insrow, int inscol, const double c_a) {
154  for (int row = 0; row < Get_ndof(); ++row)
155  for (int col = 0; col < Get_ndof(); ++col)
156  storage.SetElement(insrow + row, inscol + col, c_a * Mfullmass(row, col));
157 }
158 
159 } // end namespace chrono
chrono::ChVariablesBodyAddedMass::SetMfullmass
void SetMfullmass(ChMatrixDynamic<> &Mfullmass_in)
Set the inertia matrix.
Definition: ChVariablesBodyAddedMass.cpp:48
chrono::ChVariablesBodyAddedMass::Compute_inc_invMb_v
virtual void Compute_inc_invMb_v(ChVectorRef result, const ChVectorConstRef vect) const override
Definition: ChVariablesBodyAddedMass.cpp:111
chrono::ChVariablesBodyAddedMass::MultiplyAndAdd
virtual void MultiplyAndAdd(ChVectorRef result, const ChVectorConstRef vect, const double c_a) const override
Definition: ChVariablesBodyAddedMass.cpp:131
chrono::ChVariablesBodyAddedMass::DiagonalAdd
virtual void DiagonalAdd(ChVectorRef result, const double c_a) const override
Definition: ChVariablesBodyAddedMass.cpp:142
chrono::ChVariablesBodyAddedMass::Compute_inc_Mb_v
virtual void Compute_inc_Mb_v(ChVectorRef result, const ChVectorConstRef vect) const override
Definition: ChVariablesBodyAddedMass.cpp:119
chrono::ChVariablesBodyAddedMass
Definition: ChVariablesBodyAddedMass.h:28
chrono::ChVariablesBodyAddedMass::GetMfullmass
ChMatrixDynamic & GetMfullmass()
Access the inertia matrix.
Definition: ChVariablesBodyAddedMass.h:57
ChVariablesBodyAddedMass.h
chrono::ChVariablesBodyAddedMass::operator=
ChVariablesBodyAddedMass & operator=(const ChVariablesBodyAddedMass &other)
Assignment operator: copy from other object.
Definition: ChVariablesBodyAddedMass.cpp:33
chrono::ChVariablesBodyAddedMass::Compute_invMb_v
virtual void Compute_invMb_v(ChVectorRef result, const ChVectorConstRef vect) const override
Definition: ChVariablesBodyAddedMass.cpp:103
chrono
Definition: ChBodyAddedMass.cpp:4
chrono::ChVariablesBodyAddedMass::Build_M
virtual void Build_M(ChSparseMatrix &storage, int insrow, int inscol, const double c_a) override
Definition: ChVariablesBodyAddedMass.cpp:153
chrono::ChVariablesBodyAddedMass::GetInvMfullmass
ChMatrixDynamic & GetInvMfullmass()
Access the inverted inertia matrix.
Definition: ChVariablesBodyAddedMass.h:60