MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
resforces.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/resforces.cc,v 1.26 2017/01/12 14:46:10 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 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 #include "resforces.h"
35 #include "dataman.h"
36 
37 /* ResForces - begin */
38 
40 : F(Zero3), C(Zero3)
41 {
42  NO_OP;
43 }
44 
46 {
47  NO_OP;
48 }
49 
50 void
52 {
53  F = Zero3;
54  C = Zero3;
55 }
56 
57 void
59 {
60  F += f;
61 }
62 
63 void
65 {
66  F += f;
67  C += (x-Pole()).Cross(f);
68 }
69 
70 void
72 {
73  C += c;
74 }
75 
76 void
77 ResForces::AddForces(const Vec3& f, const Vec3& c, const Vec3& x)
78 {
79  F += f;
80  C += c + (x-Pole()).Cross(f);
81 }
82 
83 void
85 {
86  F = f;
87 }
88 
89 void
91 {
92  C = c;
93 }
94 
95 void
96 ResForces::PutForces(const Vec3& f, const Vec3& c)
97 {
98  F = f;
99  C = c;
100 }
101 
102 const Vec3&
103 ResForces::Force(void) const
104 {
105  return F;
106 }
107 
108 const Vec3&
109 ResForces::Moment(void) const
110 {
111  return C;
112 }
113 
115 : X(Zero3)
116 {
117  NO_OP;
118 }
119 
121 {
122  NO_OP;
123 }
124 
125 void
127 {
129 }
130 
131 void
133 {
134  X = x;
136 }
137 
138 void
140 {
141  X = x;
142 }
143 
144 const Vec3&
146 {
147  return X;
148 }
149 
151 : pNode(n)
152 {
153  NO_OP;
154 }
155 
157 {
158  NO_OP;
159 }
160 
161 const Vec3&
163 {
164  ASSERT(pNode);
165  return pNode->GetXCurr();
166 }
167 
169 : NodeResForces(n)
170 {
171  NO_OP;
172 }
173 
175 {
176  NO_OP;
177 }
178 
179 const Vec3&
181 {
182  return (Fr = pNode->GetRCurr().Transpose()*F);
183 }
184 
185 const Vec3&
187 {
188  return (Cr = pNode->GetRCurr().Transpose()*C);
189 }
190 
191 ResForceSet::ResForceSet(unsigned int uLabel, ResForces *p)
192 : WithLabel(uLabel), pRes(p)
193 {
194  ASSERT(pRes);
195 }
196 
198 {
199  SAFEDELETE(pRes);
200 }
201 
202 bool
203 ResForceSet::is_in(unsigned int uL)
204 {
205  return labelSet.find(uL) != labelSet.end();
206 }
207 
208 ResForceSet *
209 ReadResSet(DataManager* pDM, MBDynParser& HP, unsigned int uL)
210 {
211  ResForceSet *pset = NULL;
212  ResForces *pres = NULL;
213 
214  if (HP.IsKeyWord("external")) {
215  SAFENEW(pres, ExternResForces);
216 
217  } else if (HP.IsKeyWord("node")) {
218  const StructNode *pNode = pDM->ReadNode<const StructNode, Node::STRUCTURAL>(HP);
219 
220  if (HP.IsKeyWord("local")) {
222  LocalNodeResForces(pNode));
223 
224  } else {
226  NodeResForces(pNode));
227  }
228 
229  } else {
230  silent_cerr("unknown force set type at line "
231  << HP.GetLineData() << std::endl);
233  }
234 
235  unsigned int nItems = HP.GetInt();
236  if (nItems < 1) {
237  silent_cerr("illegal number of items " << nItems
238  << " in set at line " << HP.GetLineData() << std::endl);
239  SAFEDELETE(pres);
241  }
242 
244 
245  for (unsigned int i = 0; i < nItems; i++) {
246  unsigned int uLabel = HP.GetInt();
247  std::pair<std::set<unsigned int>::iterator, bool> rc =
248  pset->labelSet.insert(uLabel);
249 
250  if (!rc.second) {
251  silent_cerr("unable to insert item " << uLabel
252  << " in set at line " << HP.GetLineData()
253  << std::endl);
254  SAFEDELETE(pset);
256  }
257  }
258 
259  return pset;
260 }
261 
262 ResForceSet **
264 {
265  ResForceSet **ppres = NULL;
266 
267  if (HP.IsKeyWord("set")) {
268  int nSets = HP.GetInt();
269 
270  if (nSets < 1) {
271  silent_cerr("Illegal number of sets (" << nSets
272  << ") at line " << HP.GetLineData()
273  << std::endl);
275  }
276 
277  SAFENEWARR(ppres, ResForceSet*, nSets+1);
278  for (unsigned int i = 0; i <= (unsigned int)nSets; i++) {
279  ppres[i] = NULL;
280  }
281 
282  try {
283  for (unsigned int i = 0; i < (unsigned int)nSets; i++) {
284  ppres[i] = ReadResSet(pDM, HP, i+1);
285  }
286 
287  } catch (...) {
288  for (unsigned int i = 0; ppres[i]; i++) {
289  SAFEDELETE(ppres[i]);
290  }
291  SAFEDELETEARR(ppres);
292  }
293  }
294 
295  return ppres;
296 }
297 
298 /* ResForces - end */
void PutForces(const Vec3 &f, const Vec3 &c)
Definition: resforces.cc:96
ResForces * pRes
Definition: resforces.h:106
const Vec3 Zero3(0., 0., 0.)
void PutMoment(const Vec3 &c)
Definition: resforces.cc:90
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const Vec3 & Force(void) const
Definition: resforces.cc:180
Definition: matvec3.h:98
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
virtual ~ResForceSet(void)
Definition: resforces.cc:197
void Reset(void)
Definition: resforces.cc:126
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
ResForceSet * ReadResSet(DataManager *pDM, MBDynParser &HP, unsigned int uL)
Definition: resforces.cc:209
NodeResForces(const StructNode *n=0)
Definition: resforces.cc:150
virtual const Vec3 & Force(void) const
Definition: resforces.cc:103
ResForces(void)
Definition: resforces.cc:39
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
const Vec3 & Pole(void) const
Definition: resforces.cc:145
#define NO_OP
Definition: myassert.h:74
virtual const Vec3 & Moment(void) const
Definition: resforces.cc:109
const Vec3 & Pole(void) const
Definition: resforces.cc:162
bool is_in(unsigned int uL)
Definition: resforces.cc:203
LocalNodeResForces(const StructNode *n=0)
Definition: resforces.cc:168
std::set< unsigned int > labelSet
Definition: resforces.h:107
void AddForces(const Vec3 &f, const Vec3 &c, const Vec3 &x)
Definition: resforces.cc:77
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
virtual const Vec3 & Pole(void) const =0
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
const Vec3 & Moment(void) const
Definition: resforces.cc:186
ResForceSet(unsigned int uLabel, ResForces *p)
Definition: resforces.cc:191
void PutPole(const Vec3 &x)
Definition: resforces.cc:139
#define ASSERT(expression)
Definition: colamd.c:977
VectorExpression< VectorCrossExpr< VectorLhsExpr, VectorRhsExpr >, 3 > Cross(const VectorExpression< VectorLhsExpr, 3 > &u, const VectorExpression< VectorRhsExpr, 3 > &v)
Definition: matvec.h:3248
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310
ResForceSet ** ReadResSets(DataManager *pDM, MBDynParser &HP)
Definition: resforces.cc:263
virtual ~LocalNodeResForces(void)
Definition: resforces.cc:174
Vec3 C
Definition: resforces.h:46
virtual ~ResForces(void)
Definition: resforces.cc:45
static std::stack< cleanup * > c
Definition: cleanup.cc:59
Mat3x3 Transpose(void) const
Definition: matvec3.h:816
Vec3 F
Definition: resforces.h:45
void AddForce(const Vec3 &f)
Definition: resforces.cc:58
virtual ~ExternResForces(void)
Definition: resforces.cc:120
ExternResForces(void)
Definition: resforces.cc:114
void PutForce(const Vec3 &f)
Definition: resforces.cc:84
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
const StructNode * pNode
Definition: resforces.h:83
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
virtual ~NodeResForces(void)
Definition: resforces.cc:156
Node * ReadNode(MBDynParser &HP, Node::Type type) const
Definition: dataman3.cc:2309
virtual void Reset(void)
Definition: resforces.cc:51
void AddMoment(const Vec3 &c)
Definition: resforces.cc:71
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710