MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
shape.cc File Reference
#include "mbconfig.h"
#include "mbpar.h"
#include "dataman.h"
#include "shape_impl.h"
Include dependency graph for shape.cc:

Go to the source code of this file.

Functions

ShapeReadShape (MBDynParser &HP)
 

Function Documentation

Shape* ReadShape ( MBDynParser HP)

Definition at line 298 of file shape.cc.

References ASSERT, ASSERTMSG, DEBUGCOUTFNAME, DEBUGLCOUT, HighParser::GetInt(), IncludeParser::GetLineData(), HighParser::GetReal(), HighParser::IsKeyWord(), LASTKEYWORD, MBDYN_EXCEPT_ARGS, MYDEBUG_INPUT, SAFEDELETEARR, SAFENEWARR, and SAFENEWWITHCONSTRUCTOR.

Referenced by ReadAeroData().

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 */
#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
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
#define ASSERTMSG(expr, msg)
Definition: myassert.h:219
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define ASSERT(expression)
Definition: colamd.c:977
KeyWords
Definition: dataman4.cc:94
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
double doublereal
Definition: colamd.c:52
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
#define DEBUGLCOUT(level, msg)
Definition: myassert.h:244
Definition: shape.h:50
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056

Here is the call graph for this function: