proteus  1.8.1
C/C++/Fortran libraries
ChBodyAddedMass.cpp
Go to the documentation of this file.
1 #include "ChBodyAddedMass.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 
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 ChVector<>& 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 ChVector<>& 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.Get_ndof());
60  assert(Mfullmass_in.cols() == variables.Get_ndof());
61  variables.SetMfullmass(Mfullmass_in);
62  }
63 
64  // void ChBodyAddedMass::SetInvMfullmass(ChMatrixDynamic<> inv_Mfullmass_in) {
65  // assert(inv_Mfullmass_in.GetRows() == variables.Get_ndof());
66  // assert(inv_Mfullmass_in.GetColumns() == variables.Get_ndof());
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.Get_qb() = v.segment(off_v, 6);
85  this->variables.Get_fb() = 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.Get_qb();
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.Get_fb().setZero();
104 }
105 
107  // add applied forces to 'fb' vector
108  this->variables.Get_fb().segment(0, 3) += factor * Xforce.eigen();
109 
110  // add applied torques to 'fb' vector, including gyroscopic torque
111  if (this->GetNoGyroTorque())
112  this->variables.Get_fb().segment(3, 3) += factor * Xtorque.eigen();
113  else
114  this->variables.Get_fb().segment(3, 3) += factor * (Xtorque - gyro).eigen();
115 }
116 
118  this->variables.Compute_inc_Mb_v(this->variables.Get_fb(), this->variables.Get_qb());
119 }
120 
122  // set current speed in 'qb', it can be used by the solver when working in incremental mode
123  this->variables.Get_qb().segment(0, 3) = GetCoord_dt().pos.eigen();
124  this->variables.Get_qb().segment(3, 3) = GetWvel_loc().eigen();
125 }
126 
128  ChCoordsys<> old_coord_dt = this->GetCoord_dt();
129 
130  // from 'qb' vector, sets body speed, and updates auxiliary data
131  this->SetPos_dt(this->variables.Get_qb().segment(0, 3));
132  this->SetWvel_loc(this->variables.Get_qb().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->SetPos_dtdt((this->GetCoord_dt().pos - old_coord_dt.pos) / step);
143  this->SetRot_dtdt((this->GetCoord_dt().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  // 'qb' vector: pos' = pos + dt * speed , like in an Eulero step.
153 
154  ChVector<> newspeed(variables.Get_qb().segment(0, 3));
155  ChVector<> newwel(variables.Get_qb().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  ChVector<> newwel_abs = Amatrix * newwel;
164  double mangle = newwel_abs.Length() * dt_step;
165  newwel_abs.Normalize();
166  mdeltarot.Q_from_AngAxis(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 'fb' vector
177  R.segment(off, 3) += c * Xforce.eigen();
178 
179  // add applied torques to 'fb' vector, including gyroscopic torque
180  if (this->GetNoGyroTorque())
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 
200 {
201  return new chrono::ChBodyAddedMass();
202 };
chrono::ChBodyAddedMass::InjectVariables
virtual void InjectVariables(ChSystemDescriptor &mdescriptor) override
Definition: ChBodyAddedMass.cpp:97
chrono::ChBodyAddedMass::SetMass
void SetMass(double newmass)
Definition: ChBodyAddedMass.cpp:13
chrono::ChBodyAddedMass::VariablesFbReset
virtual void VariablesFbReset() override
Sets the 'fb' part of the encapsulated ChVariablesBodyOwnMass to zero.
Definition: ChBodyAddedMass.cpp:102
chrono::ChVariablesBodyAddedMass::SetMfullmass
void SetMfullmass(ChMatrixDynamic<> &Mfullmass_in)
Set the inertia matrix.
Definition: ChVariablesBodyAddedMass.cpp:48
w
#define w(x)
Definition: jf.h:22
chrono::ChBodyAddedMass::variables
ChVariablesBodyAddedMass variables
Definition: ChBodyAddedMass.h:10
chrono::ChBodyAddedMass::VariablesQbSetSpeed
virtual void VariablesQbSetSpeed(double step=0) override
Definition: ChBodyAddedMass.cpp:127
L
Double L
Definition: Headers.h:72
chrono::ChBodyAddedMass::SetMfullmass
void SetMfullmass(ChMatrixDynamic<> Mfullmass_in)
Definition: ChBodyAddedMass.cpp:58
chrono::ChVariablesBodyAddedMass::Compute_inc_Mb_v
virtual void Compute_inc_Mb_v(ChVectorRef result, const ChVectorConstRef vect) const override
Definition: ChVariablesBodyAddedMass.cpp:119
R
Double R
Definition: Headers.h:82
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::VariablesFbIncrementMq
virtual void VariablesFbIncrementMq() override
Definition: ChBodyAddedMass.cpp:117
v
Double v
Definition: Headers.h:95
chrono::ChBodyAddedMass::VariablesFbLoadForces
virtual void VariablesFbLoadForces(double factor=1) override
Definition: ChBodyAddedMass.cpp:106
c
Double c
Definition: Headers.h:54
ChBodyAddedMass.h
chrono::ChVariablesBodyAddedMass::GetMfullmass
ChMatrixDynamic & GetMfullmass()
Access the inertia matrix.
Definition: ChVariablesBodyAddedMass.h:57
chrono::ChBodyAddedMass::SetInertiaXY
void SetInertiaXY(const ChVector<> &iner)
Definition: ChBodyAddedMass.cpp:31
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
ChVariablesBodyAddedMass.h
chrono
Definition: ChBodyAddedMass.cpp:4
chrono::ChBodyAddedMass::VariablesQbLoadSpeed
virtual void VariablesQbLoadSpeed() override
Definition: ChBodyAddedMass.cpp:121
chrono::ChBodyAddedMass::VariablesQbIncrementPosition
virtual void VariablesQbIncrementPosition(double step) override
Definition: ChBodyAddedMass.cpp:147
newChBodyAddedMass
chrono::ChBodyAddedMass * newChBodyAddedMass()
Definition: ChBodyAddedMass.cpp:199
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::IntLoadResidual_F
virtual void IntLoadResidual_F(const unsigned int off, ChVectorDynamic<> &R, const double c) override
Definition: ChBodyAddedMass.cpp:171
pos
double pos(double a)
Definition: testFMMandFSW.cpp:8
chrono::ChBodyAddedMass::SetInertiaXX
void SetInertiaXX(const ChVector<> &iner)
Definition: ChBodyAddedMass.cpp:23
chrono::ChBodyAddedMass
Definition: ChBodyAddedMass.h:8
chrono::ChBodyAddedMass::SetInertia
void SetInertia(const ChMatrix33<> &iner)
Definition: ChBodyAddedMass.cpp:18