MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-damper-hydraulic.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-damper-hydraulic/module-damper-hydraulic.cc,v 1.7 2017/01/12 14:50:12 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 <cmath>
35 #include <cfloat>
36 
37 #include "dataman.h"
38 #include "constltp.h"
39 
41 : public ConstitutiveLaw<doublereal, doublereal> {
42 private:
46 
47 public:
49  : m_sigma(sigma), m_dotz_L(dotz_L), m_d(d) {
51  };
52 
53  virtual ~HydraulicDamperCL(void) {
54  NO_OP;
55  };
56 
58  return ConstLawType::VISCOUS;
59  };
60 
63 
64  typedef HydraulicDamperCL cl;
66  return pCL;
67  };
68 
69  virtual std::ostream& Restart(std::ostream& out) const {
70  return out << "hydraulic damper, " << m_sigma << ", " << m_dotz_L << ", " << m_d;
71  };
72 
73  virtual void Update(const doublereal& /* Eps */ , const doublereal& dotz) {
75 
76  doublereal abs_dotz = std::abs(dotz);
77  if (abs_dotz < m_dotz_L) {
80 
81  } else {
83  copysign(m_d*(abs_dotz - m_dotz_L) + m_sigma*m_dotz_L*m_dotz_L, dotz);
85  }
86  };
87 };
88 
89 /* specific functional object(s) */
90 struct HydraulicDamperCLR : public ConstitutiveLawRead<doublereal, doublereal> {
92  Read(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType) {
94 
95  if (HP.IsKeyWord("help")) {
96  silent_cerr("HydraulicDamperCL:\n"
97  " hydraulic damper , <sigma> , <dotz_L> , <d>\n"
98  "# according to the formula\n"
99  "# f = sigma*|dotz|*dotz for |dotz| <= dotz_L\n"
100  "# f = sign(dotz)*(d*(|dotz| - dotz_L) + sigma*dotz_L^2) for |dotz| > dotz_L\n"
101  << std::endl);
102 
103  if (!HP.IsArg()) {
104  throw NoErr(MBDYN_EXCEPT_ARGS);
105  }
106  }
107 
108  CLType = ConstLawType::VISCOUS;
109 
110  doublereal sigma = HP.GetReal();
111  if (sigma <= 0.) {
112  silent_cerr("warning, null or negative parabolic slope "
113  "at line " << HP.GetLineData() << std::endl);
114  }
115 
116  doublereal dotz_L = HP.GetReal();
117  if (dotz_L <= 0.) {
118  silent_cerr("warning, null or negative limit velocity "
119  "at line " << HP.GetLineData() << std::endl);
120  }
121 
122  doublereal d = HP.GetReal();
123  if (d < 0.) {
124  silent_cerr("warning, negative slope "
125  "at line " << HP.GetLineData() << std::endl);
126  }
127 
128  typedef HydraulicDamperCL L;
129  SAFENEWWITHCONSTRUCTOR(pCL, L, L(sigma, dotz_L, d));
130 
131  return pCL;
132  };
133 };
134 
135 extern "C" int
136 module_init(const char *module_name, void *pdm, void *php)
137 {
138 #if 0
139  DataManager *pDM = (DataManager *)pdm;
140  MBDynParser *pHP = (MBDynParser *)php;
141 #endif
142 
144  = new HydraulicDamperCLR;
145  if (!SetCL1D("hydraulic" "damper", rf1D)) {
146  delete rf1D;
147 
148  silent_cerr("HydraulicDamperCL1D: "
149  "module_init(" << module_name << ") "
150  "failed" << std::endl);
151 
152  return -1;
153  }
154 
155  return 0;
156 }
157 
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
ConstLawType::Type GetConstLawType(void) const
#define NO_OP
Definition: myassert.h:74
virtual ConstitutiveLaw< doublereal, doublereal > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
virtual void Update(const doublereal &, const doublereal &dotz)
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
doublereal copysign(doublereal x, doublereal y)
Definition: gradient.h:97
virtual ~HydraulicDamperCL(void)
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
Definition: except.h:79
virtual bool IsArg(void)
Definition: parser.cc:807
virtual ConstitutiveLaw< doublereal, doublereal > * pCopy(void) const
double doublereal
Definition: colamd.c:52
HydraulicDamperCL(doublereal sigma, doublereal dotz_L, doublereal d)
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
static std::stack< const HighParser * > pHP
Definition: parser.cc:598
virtual std::ostream & Restart(std::ostream &out) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056