MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
shape.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/shape.cc,v 1.10 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 /* Classe di forme pluridimensionali */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include "mbpar.h"
37 #include "dataman.h"
38 #include "shape_impl.h"
39 
41 {
42  NO_OP;
43 }
44 
46 : pShape(pS)
47 {
48  ASSERT(pShape != NULL);
49 }
50 
52 {
53  ASSERT(pShape != NULL);
54  if(pShape != NULL) {
56  }
57 }
58 
61 {
62  return pShape->dGet(d);
63 }
64 
67 {
68  return pShape->dGet(d1, d2);
69 }
70 
71 const Shape *
73 {
74  return pShape;
75 }
76 
78 {
79  NO_OP;
80 }
81 
83 : dConst(d)
84 {
85  NO_OP;
86 }
87 
89 {
90  NO_OP;
91 }
92 
95 {
96  return dConst;
97 }
98 
99 std::ostream&
100 ConstShape1D::Restart(std::ostream& out) const
101 {
102  return out << "const, " << dConst;
103 }
104 
106  doublereal *x, doublereal *v)
107 : nPoints(n), pdX(x), pdV(v)
108 {
109  ASSERT(nPoints > 0);
110  ASSERT(pdX != NULL);
111  ASSERT(pdV != NULL);
112 }
113 
115 {
118 }
119 
122 {
123  if (d <= pdX[0]) {
124  return pdV[0];
125  }
126 
127  for (int i = 1; i < nPoints; i++) {
128  if (d < pdX[i]) {
129  return pdV[i - 1];
130  }
131  }
132 
133  return pdV[nPoints - 1];
134 }
135 
136 std::ostream&
137 PiecewiseConstShape1D::Restart(std::ostream& out) const
138 {
139  out << "piecewise const, " << nPoints;
140 
141  for (int i = 0; i < nPoints; i++) {
142  out << ", " << pdX[i] << ", " << pdV[i];
143  }
144 
145  return out;
146 }
147 
149 : dShift(d0), dSlope(d1)
150 {
151  NO_OP;
152 }
153 
155 {
156  NO_OP;
157 }
158 
161 {
162  return dShift + dSlope*d;
163 }
164 
165 std::ostream&
166 LinearShape1D::Restart(std::ostream& out) const
167 {
168  return out << "linear, " << dShift << ", " << dSlope;
169 }
170 
172  doublereal *x, doublereal *v)
173 : nPoints(n), pdX(x), pdV(v)
174 {
175  ASSERT(nPoints > 0);
176  ASSERT(pdX != NULL);
177  ASSERT(pdV != NULL);
178 }
179 
181 {
184 }
185 
188 {
189  if (d <= pdX[0]) {
190  return pdV[0];
191  }
192 
193  for (int i = 1; i < nPoints; i++) {
194  if (d <= pdX[i]) {
195  doublereal dl = pdX[i] - pdX[i-1];
196  doublereal dw1 = pdX[i] - d;
197  doublereal dw2 = d - pdX[i - 1];
198  return (pdV[i]*dw2 + pdV[i - 1]*dw1)/dl;
199  }
200  }
201 
202  return pdV[nPoints - 1];
203 }
204 
205 std::ostream&
206 PiecewiseLinearShape1D::Restart(std::ostream& out) const
207 {
208  out << "piecewise linear, " << nPoints;
209 
210  for (int i = 0; i < nPoints; i++) {
211  out << ", " << pdX[i] << ", " << pdV[i];
212  }
213 
214  return out;
215 }
216 
218 : da0(d0), da1(d1), da2(d2)
219 {
220  NO_OP;
221 }
222 
224 {
225  NO_OP;
226 }
227 
230 {
231  return da0 + (da1 + da2*d)*d;
232 }
233 
234 std::ostream&
235 ParabolicShape1D::Restart(std::ostream& out) const
236 {
237  return out << "parabolic, " << da0 << ", "
238  << da1 << ", " << da2;
239 }
240 
242 {
243  NO_OP;
244 }
245 
247 : dConst(d)
248 {
249  NO_OP;
250 }
251 
253 {
254  NO_OP;
255 }
256 
259 {
260  return dConst;
261 }
262 
263 std::ostream&
264 ConstShape2D::Restart(std::ostream& out) const
265 {
266  return out << "const, " << dConst;
267 }
268 
270  doublereal d1y, doublereal d1xy)
271 : da0(d0), da1x(d1x), da1y(d1y), da1xy(d1xy)
272 {
273  NO_OP;
274 }
275 
277 {
278  NO_OP;
279 }
280 
283 {
284  return da0 + da1x*dx + da1y*dy + da1xy*dx*dy;
285 }
286 
287 std::ostream&
288 BilinearShape2D::Restart(std::ostream& out) const
289 {
290  return out << "bilinear, " << da0 << ", "
291  << da1x << ", " << da1y << ", " << da1xy;
292 }
293 
294 /* Legge una shape1D;
295  * NOTA: il proprietario del puntatore alla Shape la deve distruggere */
296 
297 Shape*
299 {
300  DEBUGCOUTFNAME("ReadShape");
301 
302  const char* sKeyWords[] = {
303  "const",
304  "piecewise" "const",
305  "linear",
306  "piecewise" "linear",
307  "parabolic",
308  NULL
309  };
310 
311  /* enum delle parole chiave */
312  enum KeyWords {
313  UNKNOWN = -1,
314  SHAPECONST = 0,
315  PIECEWISECONST,
316  LINEAR,
317  PIECEWISELINEAR,
318  PARABOLIC,
320  };
321 
322  /* tabella delle parole chiave */
323  KeyTable K(HP, sKeyWords);
324 
325  /* lettura del tipo di drive */
326  KeyWords CurrKeyWord;
327  if ((CurrKeyWord = KeyWords(HP.IsKeyWord())) == UNKNOWN) {
328  CurrKeyWord = SHAPECONST;
329  }
330 
331 #ifdef DEBUG
332  if (CurrKeyWord >= 0) {
333  std::cout << "shape type: " << sKeyWords[CurrKeyWord] << std::endl;
334  }
335 #endif /* DEBUG */
336 
337  Shape* pS = NULL;
338 
339  switch (CurrKeyWord) {
340  /* forma costante */
341  case SHAPECONST: {
342  /* lettura dei dati specifici */
343  doublereal dConst = HP.GetReal();
344  DEBUGLCOUT(MYDEBUG_INPUT, "Const value: " << dConst << std::endl);
345 
346  /* allocazione e creazione */
348  ConstShape1D,
349  ConstShape1D(dConst));
350  } break;
351 
352  /* forma lineare */
353  case LINEAR: {
354  /* lettura dei dati specifici */
355  doublereal da0;
356  doublereal da1;
357  if (HP.IsKeyWord("coefficients")) {
358  da0 = HP.GetReal();
359  da1 = HP.GetReal();
360  } else {
361  doublereal dm = HP.GetReal();
362  doublereal dp = HP.GetReal();
363  da0 = (dp + dm)/2.;
364  da1 = (dp - dm)/2;
365  }
366 
367  DEBUGLCOUT(MYDEBUG_INPUT, "Coefficients: "
368  << da0 << ", " << da1 << std::endl);
369 
370  /* allocazione e creazione */
373  LinearShape1D(da0, da1));
374  } break;
375 
376  /* forma lineare a tratti (costante al di fuori del dominio definito) */
377  case PIECEWISECONST:
378  case PIECEWISELINEAR: {
379  const char *sType = 0;
380  switch (CurrKeyWord) {
381  case PIECEWISECONST:
382  sType = "piecewise const";
383  break;
384 
385  case PIECEWISELINEAR:
386  sType = "piecewise linear";
387  break;
388 
389  default:
390  ASSERT(0);
391  break;
392  }
393 
394  int np = HP.GetInt();
395  if (np <= 0) {
396  silent_cerr("Illegal number of points " << np
397  << " for " << sType << " shape at line "
398  << HP.GetLineData() << std::endl);
400  }
401 
402  doublereal *px = NULL;
403  doublereal *pv = NULL;
404 
405  SAFENEWARR(px, doublereal, np);
406  SAFENEWARR(pv, doublereal, np);
407 
408  px[0] = HP.GetReal();
409  if (px[0] < -1. || px[0] > 1.) {
410  silent_cerr("Illegal value " << px[0]
411  << " for first point abscissa (must be -1. < x < 1.) "
412  "in " << sType << " shape at line "
413  << HP.GetLineData() << std::endl);
414  SAFEDELETEARR(px);
415  SAFEDELETEARR(pv);
417  }
418  pv[0] = HP.GetReal();
419 
420  for (int i = 1; i < np; i++) {
421  px[i] = HP.GetReal();
422  if (px[i] <= px[i-1] || px[i] > 1.) {
423  silent_cerr("Illegal value " << px[i]
424  << " for point " << i + 1 << " abscissa "
425  "(must be " << px[i - 1] << " < x < 1.) "
426  "in " << sType << " shape at line "
427  << HP.GetLineData() << std::endl);
428  SAFEDELETEARR(px);
429  SAFEDELETEARR(pv);
431  }
432  pv[i] = HP.GetReal();
433  }
434 
435  /* allocazione e creazione */
436  switch (CurrKeyWord) {
437  case PIECEWISECONST:
440  PiecewiseConstShape1D(np, px, pv));
441  break;
442 
443  case PIECEWISELINEAR:
446  PiecewiseLinearShape1D(np, px, pv));
447  break;
448 
449  default:
450  ASSERT(0);
451  break;
452  }
453 
454  } break;
455 
456  /* forma lineare */
457  case PARABOLIC: {
458  /* lettura dei dati specifici */
459  doublereal dm = HP.GetReal();
460  doublereal da0 = HP.GetReal();
461  doublereal dp = HP.GetReal();
462  doublereal da1 = (dp - dm)/2.;
463  doublereal da2 = (dp + dm)/2. - da0;
464  DEBUGLCOUT(MYDEBUG_INPUT, "Coefficients: "
465  << da0 << ", " << da1 << ", " << da2 << std::endl);
466 
467  /* allocazione e creazione */
470  ParabolicShape1D(da0, da1, da2));
471  } break;
472 
473  /* Non c'e' default in quanto all'inizio il default e' stato messo
474  * pari a SHAPECONST */
475  default:
476  ASSERTMSG(0, "You shouldn't have reached this point");
478  }
479 
480  ASSERT(pS != NULL);
481  return pS;
482 } /* ReadShape */
483 
ConstShape1D(doublereal d)
Definition: shape.cc:82
PiecewiseLinearShape1D(int n, doublereal *x, doublereal *v)
Definition: shape.cc:171
~ParabolicShape1D(void)
Definition: shape.cc:223
doublereal dGet(doublereal d, doublereal=0.) const
Definition: shape.cc:229
doublereal * pdV
Definition: shape_impl.h:80
~PiecewiseConstShape1D(void)
Definition: shape.cc:114
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:206
doublereal dConst
Definition: shape.h:95
BilinearShape2D(doublereal d0, doublereal d1x, doublereal d1y, doublereal d1xy)
Definition: shape.cc:269
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define DEBUGCOUTFNAME(fname)
Definition: myassert.h:256
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
doublereal dConst
Definition: shape_impl.h:115
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:137
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
#define ASSERTMSG(expr, msg)
Definition: myassert.h:219
ParabolicShape1D(doublereal d0, doublereal d1, doublereal d2)
Definition: shape.cc:217
doublereal dGet(doublereal dx, doublereal dy) const
Definition: shape.cc:282
~BilinearShape2D(void)
Definition: shape.cc:276
#define NO_OP
Definition: myassert.h:74
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:264
doublereal dGet(doublereal d, doublereal=0.) const
Definition: shape.cc:121
virtual const Shape * pGetShape(void) const
Definition: shape.cc:72
doublereal da0
Definition: shape_impl.h:94
virtual ~Shape(void)
Definition: shape.cc:40
LinearShape1D(doublereal d0, doublereal d1)
Definition: shape.cc:148
doublereal dSlope
Definition: shape_impl.h:64
Shape * ReadShape(MBDynParser &HP)
Definition: shape.cc:298
doublereal da0
Definition: shape_impl.h:129
doublereal da1x
Definition: shape_impl.h:130
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:100
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:166
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
doublereal * pdX
Definition: shape_impl.h:48
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:235
PiecewiseConstShape1D(int n, doublereal *x, doublereal *v)
Definition: shape.cc:105
doublereal dGet(doublereal, doublereal=0.) const
Definition: shape.cc:258
~LinearShape1D(void)
Definition: shape.cc:154
virtual doublereal dGet(doublereal d) const
Definition: shape.cc:60
~ConstShape2D(void)
Definition: shape.cc:252
doublereal dGet(doublereal, doublereal=0.) const
Definition: shape.cc:94
#define ASSERT(expression)
Definition: colamd.c:977
KeyWords
Definition: dataman4.cc:94
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
doublereal dShift
Definition: shape_impl.h:63
const Shape * pShape
Definition: shape.h:68
doublereal dGet(doublereal d, doublereal=0.) const
Definition: shape.cc:160
ShapeOwner(const Shape *pS)
Definition: shape.cc:45
virtual doublereal dGet(doublereal d1, doublereal d2=0.) const =0
virtual ~Shape2D(void)
Definition: shape.cc:241
~PiecewiseLinearShape1D(void)
Definition: shape.cc:180
doublereal da1y
Definition: shape_impl.h:131
~ConstShape1D(void)
Definition: shape.cc:88
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
doublereal * pdV
Definition: shape_impl.h:49
doublereal dGet(doublereal d, doublereal=0.) const
Definition: shape.cc:187
double doublereal
Definition: colamd.c:52
virtual ~ShapeOwner(void)
Definition: shape.cc:51
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
ConstShape2D(doublereal d)
Definition: shape.cc:246
doublereal da1xy
Definition: shape_impl.h:132
doublereal da1
Definition: shape_impl.h:95
#define DEBUGLCOUT(level, msg)
Definition: myassert.h:244
std::ostream & Restart(std::ostream &out) const
Definition: shape.cc:288
doublereal da2
Definition: shape_impl.h:96
doublereal * pdX
Definition: shape_impl.h:79
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710
Definition: shape.h:50
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056
virtual ~Shape1D(void)
Definition: shape.cc:77