proteus
1.9.0
C/C++/Fortran libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
work
cekees
proteus
proteus
mbd
ChBodyAddedMass.cpp
Go to the documentation of this file.
1
#include "
ChBodyAddedMass.h
"
2
#include "
ChVariablesBodyAddedMass.h
"
3
4
namespace
chrono
{
5
6
// Register into the object factory, to enable run-time dynamic creation and persistence
7
CH_FACTORY_REGISTER(
ChBodyAddedMass
)
8
9
ChBodyAddedMass
::
ChBodyAddedMass
() {
10
ChBody::variables =
variables
;
11
}
12
13
void
ChBodyAddedMass::SetMass
(
double
newmass) {
14
variables
.SetBodyMass(newmass);
15
ChBody::variables.SetBodyMass(newmass);
16
}
17
18
void
ChBodyAddedMass::SetInertia
(
const
ChMatrix33<>& newXInertia) {
19
variables
.SetBodyInertia(newXInertia);
20
ChBody::variables.SetBodyInertia(newXInertia);
21
}
22
23
void
ChBodyAddedMass::SetInertiaXX
(
const
ChVector3d& iner) {
24
variables
.GetBodyInertia()(0, 0) = iner.x();
25
variables
.GetBodyInertia()(1, 1) = iner.y();
26
variables
.GetBodyInertia()(2, 2) = iner.z();
27
variables
.GetBodyInvInertia() =
variables
.GetBodyInertia().inverse();
28
ChBody::SetInertiaXX(iner);
29
}
30
31
void
ChBodyAddedMass::SetInertiaXY
(
const
ChVector3d& iner) {
32
variables
.GetBodyInertia()(0, 1) = iner.x();
33
variables
.GetBodyInertia()(0, 2) = iner.y();
34
variables
.GetBodyInertia()(1, 2) = iner.z();
35
variables
.GetBodyInertia()(1, 0) = iner.x();
36
variables
.GetBodyInertia()(2, 0) = iner.y();
37
variables
.GetBodyInertia()(2, 1) = iner.z();
38
variables
.GetBodyInvInertia() =
variables
.GetBodyInertia().inverse();
39
ChBody::SetInertiaXY(iner);
40
}
41
42
// ChVector<> ChBodyAddedMass::GetInertiaXX() {
43
// ChVector<> iner;
44
// iner.x() = variables.GetBodyInertia().GetElement(0, 0);
45
// iner.y() = variables.GetBodyInertia().GetElement(1, 1);
46
// iner.z() = variables.GetBodyInertia().GetElement(2, 2);
47
// return iner;
48
// }
49
50
// ChVector<> ChBodyAddedMass::GetInertiaXY() {
51
// ChVector<> iner;
52
// iner.x() = variables.GetBodyInertia().GetElement(0, 1);
53
// iner.y() = variables.GetBodyInertia().GetElement(0, 2);
54
// iner.z() = variables.GetBodyInertia().GetElement(1, 2);
55
// return iner;
56
// }
57
58
void
ChBodyAddedMass::SetMfullmass
(ChMatrixDynamic<> Mfullmass_in) {
59
assert(Mfullmass_in.rows() ==
variables
.GetDOF());
60
assert(Mfullmass_in.cols() ==
variables
.GetDOF());
61
variables
.
SetMfullmass
(Mfullmass_in);
62
}
63
64
// void ChBodyAddedMass::SetInvMfullmass(ChMatrixDynamic<> inv_Mfullmass_in) {
65
// assert(inv_Mfullmass_in.GetRows() == variables.GetDOF());
66
// assert(inv_Mfullmass_in.GetColumns() == variables.GetDOF());
67
// ChMatrixDynamic<>& Mm = variables.GetInvMfullmass();
68
// for (int i = 0; i < 6; i++) {
69
// for (int j = 0; j < 6; j++) {
70
// Mm(i, j) = inv_Mfullmass_in(i, j);
71
// }
72
// }
73
// }
75
76
77
78
void
ChBodyAddedMass::IntToDescriptor
(
const
unsigned
int
off_v,
// offset in v, R
79
const
ChStateDelta&
v
,
80
const
ChVectorDynamic<>&
R
,
81
const
unsigned
int
off_L,
// offset in L, Qc
82
const
ChVectorDynamic<>&
L
,
83
const
ChVectorDynamic<>& Qc) {
84
this->
variables
.State() =
v
.segment(off_v, 6);
85
this->
variables
.Force() =
R
.segment(off_v, 6);
86
}
87
88
void
ChBodyAddedMass::IntFromDescriptor
(
const
unsigned
int
off_v,
// offset in v
89
ChStateDelta&
v
,
90
const
unsigned
int
off_L,
// offset in L
91
ChVectorDynamic<>&
L
) {
92
v
.segment(off_v, 6) = this->
variables
.State();
93
}
94
96
97
void
ChBodyAddedMass::InjectVariables
(ChSystemDescriptor& mdescriptor) {
98
this->
variables
.SetDisabled(!this->IsActive());
99
mdescriptor.InsertVariables(&this->
variables
);
100
}
101
102
void
ChBodyAddedMass::VariablesFbReset
() {
103
this->
variables
.Force().setZero();
104
}
105
106
void
ChBodyAddedMass::VariablesFbLoadForces
(
double
factor) {
107
// add applied forces to Force vector
108
this->
variables
.Force().segment(0, 3) += factor * Xforce.eigen();
109
110
// add applied torques to Force vector, including gyroscopic torque
111
if
(this->IsUsingGyroTorque())
112
this->
variables
.Force().segment(3, 3) += factor * Xtorque.eigen();
113
else
114
this->
variables
.Force().segment(3, 3) += factor * (Xtorque - gyro).eigen();
115
}
116
117
void
ChBodyAddedMass::VariablesFbIncrementMq
() {
118
this->
variables
.
AddMassTimesVector
(this->
variables
.Force(), this->variables.State());
119
}
120
121
void
ChBodyAddedMass::VariablesQbLoadSpeed
() {
122
// set current speed in State, it can be used by the solver when working in incremental mode
123
this->
variables
.State().segment(0, 3) = GetCoordsysDt().pos.eigen();
124
this->
variables
.State().segment(3, 3) = GetAngVelLocal().eigen();
125
}
126
127
void
ChBodyAddedMass::VariablesQbSetSpeed
(
double
step) {
128
ChCoordsys<> old_coord_dt = this->GetCoordsysDt();
129
130
// from State vector, sets body speed, and updates auxiliary data
131
this->SetPosDt(this->
variables
.State().segment(0, 3));
132
this->SetAngVelLocal(this->
variables
.State().segment(3, 3));
133
134
// apply limits (if in speed clamping mode) to speeds.
135
ClampSpeed();
136
137
// compute auxiliary gyroscopic forces
138
ComputeGyro();
139
140
// Compute accel. by BDF (approximate by differentiation);
141
if
(step) {
142
this->SetPosDt2((this->GetCoordsysDt().pos - old_coord_dt.pos) / step);
143
this->SetRotDt2((this->GetCoordsysDt().rot - old_coord_dt.rot) / step);
144
}
145
}
146
147
void
ChBodyAddedMass::VariablesQbIncrementPosition
(
double
dt_step) {
148
if
(!this->IsActive())
149
return
;
150
151
// Updates position with incremental action of speed contained in the
152
// State vector: pos' = pos + dt * speed , like in an Eulero step.
153
154
ChVector3d newspeed(
variables
.State().segment(0, 3));
155
ChVector3d newwel(
variables
.State().segment(3, 3));
156
157
// ADVANCE POSITION: pos' = pos + dt * vel
158
this->SetPos(this->GetPos() + newspeed * dt_step);
159
160
// ADVANCE ROTATION: rot' = [dt*wwel]%rot (use quaternion for delta rotation)
161
ChQuaternion<> mdeltarot;
162
ChQuaternion<> moldrot = this->GetRot();
163
ChVector3d newwel_abs = this->GetRotMat() * newwel;
164
double
mangle = newwel_abs.Length() * dt_step;
165
newwel_abs.Normalize();
166
mdeltarot.SetFromAngleAxis(mangle, newwel_abs);
167
ChQuaternion<> mnewrot = mdeltarot * moldrot;
168
this->SetRot(mnewrot);
169
}
170
171
void
ChBodyAddedMass::IntLoadResidual_F
(
const
unsigned
int
off,
// offset in R residual
172
ChVectorDynamic<>&
R
,
// result: the R residual, R += c*F
173
const
double
c
// a scaling factor
174
) {
175
176
// add applied forces to Force vector
177
R
.segment(off, 3) +=
c
* Xforce.eigen();
178
179
// add applied torques to Force vector, including gyroscopic torque
180
if
(this->IsUsingGyroTorque())
181
R
.segment(off + 3, 3) +=
c
* Xtorque.eigen();
182
else
183
R
.segment(off + 3, 3) +=
c
* (Xtorque - gyro).eigen();
184
}
185
186
void
ChBodyAddedMass::IntLoadResidual_Mv
(
const
unsigned
int
off,
// offset in R residual
187
ChVectorDynamic<>&
R
,
// result: the R residual, R += c*M*v
188
const
ChVectorDynamic<>&
w
,
// the w vector
189
const
double
c
// a scaling factor
190
) {
191
ChMatrixDynamic<> ww = ChMatrixDynamic<>(6, 1);
192
for
(
int
i=0; i < 6; i++) {
193
ww(i, 0) =
w
(off+i);
194
}
195
R
.segment(off, 6) +=
variables
.
GetMfullmass
()*ww*
c
;
196
}
197
}
// end namespace chrono
198
199
chrono::ChBodyAddedMass
*
newChBodyAddedMass
()
200
{
201
return
new
chrono::ChBodyAddedMass
();
202
};
newChBodyAddedMass
chrono::ChBodyAddedMass * newChBodyAddedMass()
Definition
ChBodyAddedMass.cpp:199
ChBodyAddedMass.h
ChVariablesBodyAddedMass.h
L
Double L
Definition
Headers.h:72
v
Double v
Definition
Headers.h:95
R
Double R
Definition
Headers.h:82
chrono::ChBodyAddedMass
Definition
ChBodyAddedMass.h:8
chrono::ChBodyAddedMass::InjectVariables
virtual void InjectVariables(ChSystemDescriptor &mdescriptor) override
Definition
ChBodyAddedMass.cpp:97
chrono::ChBodyAddedMass::IntFromDescriptor
virtual void IntFromDescriptor(const unsigned int off_v, ChStateDelta &v, const unsigned int off_L, ChVectorDynamic<> &L) override
Definition
ChBodyAddedMass.cpp:88
chrono::ChBodyAddedMass::SetMass
void SetMass(double newmass)
Definition
ChBodyAddedMass.cpp:13
chrono::ChBodyAddedMass::VariablesFbLoadForces
virtual void VariablesFbLoadForces(double factor=1) override
Definition
ChBodyAddedMass.cpp:106
chrono::ChBodyAddedMass::SetMfullmass
void SetMfullmass(ChMatrixDynamic<> Mfullmass_in)
Definition
ChBodyAddedMass.cpp:58
chrono::ChBodyAddedMass::VariablesFbIncrementMq
virtual void VariablesFbIncrementMq() override
Definition
ChBodyAddedMass.cpp:117
chrono::ChBodyAddedMass::IntLoadResidual_Mv
virtual void IntLoadResidual_Mv(const unsigned int off, ChVectorDynamic<> &R, const ChVectorDynamic<> &w, const double c) override
Definition
ChBodyAddedMass.cpp:186
chrono::ChBodyAddedMass::SetInertiaXY
void SetInertiaXY(const ChVector3d &iner)
Definition
ChBodyAddedMass.cpp:31
chrono::ChBodyAddedMass::ChBodyAddedMass
ChBodyAddedMass()
Definition
ChBodyAddedMass.cpp:9
chrono::ChBodyAddedMass::VariablesQbSetSpeed
virtual void VariablesQbSetSpeed(double step=0) override
Definition
ChBodyAddedMass.cpp:127
chrono::ChBodyAddedMass::IntToDescriptor
virtual void IntToDescriptor(const unsigned int off_v, const ChStateDelta &v, const ChVectorDynamic<> &R, const unsigned int off_L, const ChVectorDynamic<> &L, const ChVectorDynamic<> &Qc) override
Definition
ChBodyAddedMass.cpp:78
chrono::ChBodyAddedMass::VariablesQbLoadSpeed
virtual void VariablesQbLoadSpeed() override
Definition
ChBodyAddedMass.cpp:121
chrono::ChBodyAddedMass::VariablesFbReset
virtual void VariablesFbReset() override
Sets the 'fb' part of the encapsulated ChVariablesBodyOwnMass to zero.
Definition
ChBodyAddedMass.cpp:102
chrono::ChBodyAddedMass::SetInertia
void SetInertia(const ChMatrix33<> &iner)
Definition
ChBodyAddedMass.cpp:18
chrono::ChBodyAddedMass::IntLoadResidual_F
virtual void IntLoadResidual_F(const unsigned int off, ChVectorDynamic<> &R, const double c) override
Definition
ChBodyAddedMass.cpp:171
chrono::ChBodyAddedMass::VariablesQbIncrementPosition
virtual void VariablesQbIncrementPosition(double step) override
Definition
ChBodyAddedMass.cpp:147
chrono::ChBodyAddedMass::SetInertiaXX
void SetInertiaXX(const ChVector3d &iner)
Definition
ChBodyAddedMass.cpp:23
chrono::ChBodyAddedMass::variables
ChVariablesBodyAddedMass variables
Definition
ChBodyAddedMass.h:10
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::AddMassTimesVector
virtual void AddMassTimesVector(ChVectorRef results, ChVectorConstRef vect) const override
Definition
ChVariablesBodyAddedMass.cpp:119
c
#define c(i)
Definition
jf.h:21
w
#define w(x)
Definition
jf.h:22
chrono
Definition
ChBodyAddedMass.cpp:4
Generated on
for proteus by
1.18.0