MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
gravity.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/gravity.cc,v 1.31 2017/01/12 14:46:43 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /* Elemento accelerazione di gravita' */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include "dataman.h"
37 #include "gravity.h"
38 
39 /* Gravity - begin */
40 
42 : Elem(1, fOut)
43 {
44  NO_OP;
45 }
46 
48 {
49  NO_OP;
50 }
51 
52 /* assemblaggio jacobiano */
55  doublereal /* dCoef */ ,
56  const VectorHandler& /* XCurr */ ,
57  const VectorHandler& /* XPrimeCurr */ )
58 {
59  DEBUGCOUT("Entering Gravity::AssJac()" << std::endl);
60  WorkMat.SetNullMatrix();
61  return WorkMat;
62 }
63 
64 /* assemblaggio residuo */
67  doublereal /* dCoef */ ,
68  const VectorHandler& /* XCurr */ ,
69  const VectorHandler& /* XPrimeCurr */ )
70 {
71  DEBUGCOUT("Entering Gravity::AssRes()" << std::endl);
72  WorkVec.Resize(0);
73  return WorkVec;
74 }
75 
76 /* Gravity - end */
77 
78 
79 /* UniformGravity - begin */
80 
82 : Elem(1, fOut), Gravity(fOut), TplDriveOwner<Vec3>(pDC)
83 {
84  Acc = Get();
85 }
86 
88 {
89  NO_OP;
90 }
91 
92 /* Scrive il contributo dell'elemento al file di restart */
93 std::ostream&
94 UniformGravity::Restart(std::ostream& out) const
95 {
96  return out << " gravity: uniform, /* reference, global, */ ",
97  pGetDriveCaller()->Restart(out) << ";" << std::endl;
98 }
99 
100 /* assemblaggio residuo */
103  doublereal dCoef,
104  const VectorHandler& XCurr,
105  const VectorHandler& XPrimeCurr)
106 {
107  DEBUGCOUT("Entering UniformGravity::AssRes()" << std::endl);
108 
109  /* Approfitto del fatto che Gravity viene aggiornato prima
110  * degli altri elementi (vedi l'enum Elem::Type e la sequenza di
111  * assemblaggio) per fargli calcolare Acc una volta per tutte.
112  * Quindi, quando viene chiamata GetAcceleration(void),
113  * questa restituisce un reference all'accelerazione con il
114  * minimo overhead
115  */
116  Acc = Get();
117  return Gravity::AssRes(WorkVec, dCoef, XCurr, XPrimeCurr);
118 }
119 
120 void
122 {
123  if (bToBeOutput()) {
125  OH.Gravity() << std::setw(8) << GetLabel()
126  << " " << Acc << std::endl;
127  }
128  }
129 }
130 
131 /* UniformGravity - end */
132 
133 
134 /* CentralGravity - begin */
135 
137  doublereal dM, doublereal dG, flag fOut)
138 : Elem(1, fOut), Gravity(fOut), m_X0(X0), m_dM(dM), m_dG(dG)
139 {
140  NO_OP;
141 }
142 
144 {
145  NO_OP;
146 }
147 
148 /* Scrive il contributo dell'elemento al file di restart */
149 std::ostream&
150 CentralGravity::Restart(std::ostream& out) const
151 {
152  return out << " gravity: central, "
153  "origin, ", m_X0.Write(out, ", ") << ", "
154  "mass, " << m_dM << ", "
155  "G, " << m_dG << ";"
156  << std::endl;
157 }
158 
159 void
161 {
162 #if 0
163  // nothing to output...
164  if (bToBeOutput()) {
166  OH.Gravity() << std::setw(8) << GetLabel()
167  << std::endl;
168  }
169  }
170 #endif
171  NO_OP;
172 }
173 
174 Vec3
176 {
177  Vec3 D = m_X0 - X;
178  doublereal dD = D.Norm();
179  return D*(m_dM*m_dG/(dD*dD*dD));
180 }
181 
182 /* CentralGravity - end */
183 
184 
185 /* GravityOwner - begin */
186 
188 : pGravity(0)
189 {
190  NO_OP;
191 }
192 
193 
195 {
196  NO_OP;
197 }
198 
199 
200 void
202 {
203  ASSERT(pGravity == 0);
204  pGravity = const_cast<Gravity *>(pG);
205 }
206 
207 bool
208 GravityOwner::bGetGravity(const Vec3& X, Vec3& Acc) const
209 {
210  if (pGravity == 0) {
211  return false;
212  }
213 
214  Acc = pGravity->GetAcceleration(X);
215  return true;
216 }
217 
218 /* GravityOwner - end */
219 
220 
221 /* ElemGravityOwner - begin */
222 
224 : Elem(uL, fOut), GravityOwner()
225 {
226  NO_OP;
227 }
228 
230 {
231  NO_OP;
232 }
233 
234 /* ElemGravityOwner - end */
235 
236 Elem *
238 {
239  Elem *pE = 0;
240 
241  if (HP.IsKeyWord("central")) {
242  Vec3 X0 = ::Zero3;
243  if (HP.IsKeyWord("origin")) {
244  X0 = HP.GetPosAbs(::AbsRefFrame);
245  }
246 
247  if (!HP.IsKeyWord("mass")) {
248  silent_cerr("Gravity: \"mass\" keyword expected at line " << HP.GetLineData() << std::endl);
250  }
251  doublereal dM = HP.GetReal();
252  if (dM <= std::numeric_limits<doublereal>::epsilon()) {
253  silent_cerr("Gravity: mass " << dM << " is negative or too small at line " << HP.GetLineData() << std::endl);
255  }
256 
257  if (!HP.IsKeyWord("G")) {
258  silent_cerr("Gravity: \"G\" keyword expected at line " << HP.GetLineData() << std::endl);
260  }
261  // 6.673 84 x 10-11 m3 kg-1 s-2, http://physics.nist.gov/cuu/Constants/index.html
262  doublereal dG = 6.67384e-11;
263  if (!HP.IsKeyWord("si")) {
264  dG = HP.GetReal();
265  if (dG <= std::numeric_limits<doublereal>::epsilon()) {
266  silent_cerr("Gravity: gravity constant " << dG << " is negative or too small at line " << HP.GetLineData() << std::endl);
268  }
269  }
270 
272 
273  } else {
274  if (!HP.IsKeyWord("uniform")) {
275  silent_cerr("Gravity: "
276  "<type> expected "
277  "at line " << HP.GetLineData() << "; "
278  "assuming \"uniform\""
279  << std::endl);
280  }
281 
282  TplDriveCaller<Vec3>* pDC = ReadDC3D(pDM, HP);
283 
284  flag fOut = pDM->fReadOutput(HP, Elem::GRAVITY);
285 
287  }
288 
289  return pE;
290 }
291 
flag fReadOutput(MBDynParser &HP, const T &t) const
Definition: dataman.h:1064
Elem * ReadGravity(DataManager *pDM, MBDynParser &HP)
Definition: gravity.cc:237
doublereal m_dM
Definition: gravity.h:179
const Vec3 Zero3(0., 0., 0.)
std::ostream & Write(std::ostream &out, const char *sFill=" ") const
Definition: matvec3.cc:738
long int flag
Definition: mbdyn.h:43
virtual bool bToBeOutput(void) const
Definition: output.cc:890
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual ~Gravity(void)
Definition: gravity.cc:47
void PutGravity(const Gravity *pG)
Definition: gravity.cc:201
virtual void Output(OutputHandler &OH) const
Definition: gravity.cc:160
virtual ~CentralGravity(void)
Definition: gravity.cc:143
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal m_dG
Definition: gravity.h:180
virtual bool bGetGravity(const Vec3 &X, Vec3 &Acc) const
Definition: gravity.cc:208
ElemGravityOwner(unsigned int uL, flag fOut)
Definition: gravity.cc:223
#define NO_OP
Definition: myassert.h:74
std::ostream & Gravity(void) const
Definition: output.h:587
virtual VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: gravity.cc:54
virtual Vec3 GetAcceleration(const Vec3 &) const =0
Gravity(flag fOut)
Definition: gravity.cc:41
const ReferenceFrame AbsRefFrame(0, Vec3(0., 0., 0), Mat3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), Vec3(0., 0., 0), Vec3(0., 0., 0), EULER_123)
TplDriveCaller< Vec3 > * ReadDC3D(const DataManager *pDM, MBDynParser &HP)
TplDriveCaller< Vec3 > * pGetDriveCaller(void) const
Definition: tpldrive.h:105
virtual ~GravityOwner(void)
Definition: gravity.cc:194
virtual Vec3 GetAcceleration(const Vec3 &X) const
Definition: gravity.cc:175
void SetNullMatrix(void)
Definition: submat.h:1159
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define DEBUGCOUT(msg)
Definition: myassert.h:232
Vec3 GetPosAbs(const ReferenceFrame &rf)
Definition: mbpar.cc:1401
Gravity * pGravity
Definition: gravity.h:207
virtual std::ostream & Restart(std::ostream &out) const
Definition: gravity.cc:150
UniformGravity(const TplDriveCaller< Vec3 > *pDC, flag fOut)
Definition: gravity.cc:81
virtual std::ostream & Restart(std::ostream &out) const
Definition: gravity.cc:94
virtual void Output(OutputHandler &OH) const
Definition: gravity.cc:121
virtual std::ostream & Restart(std::ostream &out) const =0
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
GravityOwner(void)
Definition: gravity.cc:187
CentralGravity(const Vec3 &X0, doublereal dM, doublereal dG, flag fOut)
Definition: gravity.cc:136
virtual ~UniformGravity(void)
Definition: gravity.cc:87
virtual SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: gravity.cc:102
Definition: elem.h:75
virtual SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: gravity.cc:66
double doublereal
Definition: colamd.c:52
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
unsigned int GetLabel(void) const
Definition: withlab.cc:62
Vec3 Get(void) const
Definition: tpldrive.h:113
virtual ~ElemGravityOwner(void)
Definition: gravity.cc:229
virtual void Resize(integer iNewSize)=0
bool UseText(int out) const
Definition: output.cc:446
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056