proteus 1.9.0
C/C++/Fortran libraries
Loading...
Searching...
No Matches
ChBodyAddedMass.cpp
Go to the documentation of this file.
1#include "ChBodyAddedMass.h"
3
4namespace chrono {
5
6 // Register into the object factory, to enable run-time dynamic creation and persistence
7 CH_FACTORY_REGISTER(ChBodyAddedMass)
8
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
103 this->variables.Force().setZero();
104 }
105
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
118 this->variables.AddMassTimesVector(this->variables.Force(), this->variables.State());
119 }
120
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
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
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
chrono::ChBodyAddedMass * newChBodyAddedMass()
Double L
Definition Headers.h:72
Double v
Definition Headers.h:95
Double R
Definition Headers.h:82
virtual void InjectVariables(ChSystemDescriptor &mdescriptor) override
virtual void IntFromDescriptor(const unsigned int off_v, ChStateDelta &v, const unsigned int off_L, ChVectorDynamic<> &L) override
void SetMass(double newmass)
virtual void VariablesFbLoadForces(double factor=1) override
void SetMfullmass(ChMatrixDynamic<> Mfullmass_in)
virtual void VariablesFbIncrementMq() override
virtual void IntLoadResidual_Mv(const unsigned int off, ChVectorDynamic<> &R, const ChVectorDynamic<> &w, const double c) override
void SetInertiaXY(const ChVector3d &iner)
virtual void VariablesQbSetSpeed(double step=0) override
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
virtual void VariablesQbLoadSpeed() override
virtual void VariablesFbReset() override
Sets the 'fb' part of the encapsulated ChVariablesBodyOwnMass to zero.
void SetInertia(const ChMatrix33<> &iner)
virtual void IntLoadResidual_F(const unsigned int off, ChVectorDynamic<> &R, const double c) override
virtual void VariablesQbIncrementPosition(double step) override
void SetInertiaXX(const ChVector3d &iner)
ChVariablesBodyAddedMass variables
void SetMfullmass(ChMatrixDynamic<> &Mfullmass_in)
Set the inertia matrix.
ChMatrixDynamic & GetMfullmass()
Access the inertia matrix.
virtual void AddMassTimesVector(ChVectorRef results, ChVectorConstRef vect) const override
#define c(i)
Definition jf.h:21
#define w(x)
Definition jf.h:22