proteus
1.9.0
C/C++/Fortran libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
work
cekees
proteus
proteus
mbd
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, Chris Kees
13
// =============================================================================
14
15
#include "
ChVariablesBodyAddedMass.h
"
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
22
ChVariablesBodyAddedMass
::
ChVariablesBodyAddedMass
() : ndof(6) {
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
33
ChVariablesBodyAddedMass
&
ChVariablesBodyAddedMass::operator=
(
const
ChVariablesBodyAddedMass
& other) {
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() == GetDOF());
50
assert(Mfullmass_in.cols() == GetDOF());
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() == GetDOF());
95
// assert(Maddedmass_in.GetColums() == GetDOF());
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::ComputeMassInverseTimesVector
(ChVectorRef result, ChVectorConstRef vect)
const
{
104
assert(vect.size() == GetDOF());
105
assert(result.size() == GetDOF());
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, ChVectorConstRef vect)
const
{
112
assert(vect.size() == GetDOF());
113
assert(result.size() == GetDOF());
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::AddMassTimesVector
(ChVectorRef result,
const
ChVectorConstRef vect)
const
{
120
assert(vect.size() == GetDOF());
121
assert(result.size() == GetDOF());
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.
131
void
ChVariablesBodyAddedMass::AddMassTimesVectorInto
(ChVectorRef result,
132
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::AddMassDiagonalInto
(ChVectorRef result,
const
double
c_a)
const
{
143
assert(result.size() >= this->offset + GetDOF());
144
for
(
int
i = 0; i < GetDOF(); 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::PasteMassInto
(ChSparseMatrix& storage,
unsigned
int
insrow,
unsigned
int
inscol,
const
double
c_a)
const
{
154
for
(
int
row = 0; row < GetDOF(); ++row)
155
for
(
int
col = 0; col < GetDOF(); ++col)
156
storage.SetElement(insrow + row, inscol + col, c_a * Mfullmass(row, col));
157
}
158
159
}
// end namespace chrono
ChVariablesBodyAddedMass.h
chrono::ChVariablesBodyAddedMass
Definition
ChVariablesBodyAddedMass.h:28
chrono::ChVariablesBodyAddedMass::ChVariablesBodyAddedMass
ChVariablesBodyAddedMass()
Definition
ChVariablesBodyAddedMass.cpp:22
chrono::ChVariablesBodyAddedMass::GetInvMfullmass
ChMatrixDynamic & GetInvMfullmass()
Access the inverted inertia matrix.
Definition
ChVariablesBodyAddedMass.h:60
chrono::ChVariablesBodyAddedMass::SetMfullmass
void SetMfullmass(ChMatrixDynamic<> &Mfullmass_in)
Set the inertia matrix.
Definition
ChVariablesBodyAddedMass.cpp:48
chrono::ChVariablesBodyAddedMass::GetMfullmass
ChMatrixDynamic & GetMfullmass()
Access the inertia matrix.
Definition
ChVariablesBodyAddedMass.h:57
chrono::ChVariablesBodyAddedMass::operator=
ChVariablesBodyAddedMass & operator=(const ChVariablesBodyAddedMass &other)
Assignment operator: copy from other object.
Definition
ChVariablesBodyAddedMass.cpp:33
chrono::ChVariablesBodyAddedMass::PasteMassInto
virtual void PasteMassInto(ChSparseMatrix &mat, unsigned int insrow, unsigned int inscol, const double c_a) const override
Definition
ChVariablesBodyAddedMass.cpp:153
chrono::ChVariablesBodyAddedMass::Compute_inc_invMb_v
virtual void Compute_inc_invMb_v(ChVectorRef result, ChVectorConstRef vect) const
Definition
ChVariablesBodyAddedMass.cpp:111
chrono::ChVariablesBodyAddedMass::AddMassTimesVectorInto
virtual void AddMassTimesVectorInto(ChVectorRef result, ChVectorConstRef vect, const double ca) const override
Definition
ChVariablesBodyAddedMass.cpp:131
chrono::ChVariablesBodyAddedMass::AddMassDiagonalInto
virtual void AddMassDiagonalInto(ChVectorRef result, const double c_a) const override
Definition
ChVariablesBodyAddedMass.cpp:142
chrono::ChVariablesBodyAddedMass::ComputeMassInverseTimesVector
virtual void ComputeMassInverseTimesVector(ChVectorRef result, ChVectorConstRef vect) const override
Definition
ChVariablesBodyAddedMass.cpp:103
chrono::ChVariablesBodyAddedMass::AddMassTimesVector
virtual void AddMassTimesVector(ChVectorRef results, ChVectorConstRef vect) const override
Definition
ChVariablesBodyAddedMass.cpp:119
chrono
Definition
ChBodyAddedMass.cpp:4
Generated on
for proteus by
1.18.0