1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/hydr/hfluid.cc,v 1.36 2017/01/12 14:46:32 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 /*
33 * Copyright 1999-2000 Lamberto Puggelli <puggelli@tiscalinet.it>
34 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
35 */
36
37 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
38
39 #include <cfloat>
40 #include <limits>
41
42 #include "dataman.h"
43 #include "hfluid.h"
44 #include "hfluid_.h"
45
46 /* HydraulicFluid - begin */
47
HydraulicFluid(unsigned int Label,const doublereal dPres0,const doublereal dTemp0)48 HydraulicFluid::HydraulicFluid(unsigned int Label,
49 const doublereal dPres0,
50 const doublereal dTemp0)
51 : WithLabel(Label), dPres0(dPres0), dTemp0(dTemp0)
52 {
53 NO_OP;
54 }
55
HydraulicFluid(const HydraulicFluid & HF)56 HydraulicFluid::HydraulicFluid(const HydraulicFluid& HF)
57 : WithLabel(HF.GetLabel()), dPres0(HF.dPres0), dTemp0(HF.dTemp0)
58 {
59 NO_OP;
60 }
61
~HydraulicFluid(void)62 HydraulicFluid::~HydraulicFluid(void)
63 {
64 NO_OP;
65 }
66
67 doublereal
dGetPres0(void) const68 HydraulicFluid::dGetPres0(void) const
69 {
70 ASSERT(dPres0 != -1.);
71 return dPres0;
72 }
73
74 doublereal
dGetTemp0(void) const75 HydraulicFluid::dGetTemp0(void) const
76 {
77 ASSERT(dTemp0 != -1.);
78 return dTemp0;
79 }
80
81 /* HydraulicFluid - end */
82
83
84 HydraulicFluid *
ReadHydraulicFluid(MBDynParser & HP,unsigned int uLabel)85 ReadHydraulicFluid(MBDynParser& HP, unsigned int uLabel)
86 {
87 /* tipi di fluidi */
88 const char* sKeyWords[] = {
89 "uncompressible", /* deprecated (typo) */
90 "incompressible",
91 "linear" "compressible",
92 "linear" "thermal" "compressible",
93 "super",
94 "exponential",
95
96 NULL
97 };
98
99 enum KeyWords {
100 UNKNOWN = -1,
101
102 UNCOMPRESSIBLE = 0, /* deprecated (typo) */
103 INCOMPRESSIBLE,
104 LINEARCOMPRESSIBLE,
105 LINEARTHERMALCOMPRESSIBLE,
106 SUPER,
107 EXPONENTIAL,
108
109 LASTKEYWORD
110 };
111
112 /* tabella delle parole chiave */
113 KeyTable K(HP, sKeyWords);
114
115 /* lettura del tipo di drive */
116 KeyWords CurrKeyWord = KeyWords(HP.IsKeyWord());
117 if (CurrKeyWord == UNKNOWN) {
118 CurrKeyWord = INCOMPRESSIBLE;
119 }
120
121 HydraulicFluid* pHF = 0;
122
123 switch (CurrKeyWord) {
124 case UNCOMPRESSIBLE: /* deprecated (typo) */
125 case INCOMPRESSIBLE: {
126 doublereal dDensity(0.);
127 if (HP.IsKeyWord("density")) {
128 dDensity = HP.GetReal();
129 }
130
131 if (dDensity < std::numeric_limits<doublereal>::epsilon()) {
132 silent_cerr("line " << HP.GetLineData()
133 << ": illegal density " << dDensity
134 << " for hydraulic fluid " << uLabel << std::endl);
135 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
136 }
137
138 doublereal dViscosity(0.);
139 if (HP.IsKeyWord("viscosity")) {
140 dViscosity = HP.GetReal();
141 }
142
143 if (dViscosity < std::numeric_limits<doublereal>::epsilon()) {
144 silent_cerr("line " << HP.GetLineData()
145 << ": illegal viscosity " << dViscosity
146 << std::endl);
147 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
148 }
149
150 doublereal dPres0(-1.);
151 if (HP.IsKeyWord("pressure")) {
152 dPres0 = HP.GetReal();
153 if (dPres0 < 0.) {
154 silent_cerr("line " << HP.GetLineData()
155 << ": illegal reference pressure " << dPres0
156 << " for hydraulic fluid " << uLabel << std::endl);
157 }
158 }
159
160 doublereal dTemp0(-1.);
161 if (HP.IsKeyWord("temperature")) {
162 dTemp0 = HP.GetReal();
163 if (dTemp0 < 0.) {
164 silent_cerr("line " << HP.GetLineData()
165 << ": illegal reference temperature " << dTemp0
166 << " for hydraulic fluid " << uLabel << std::endl);
167 }
168 }
169
170 SAFENEWWITHCONSTRUCTOR(pHF,
171 IncompressibleHydraulicFluid,
172 IncompressibleHydraulicFluid(uLabel,
173 dDensity,
174 dViscosity,
175 dPres0,
176 dTemp0));
177 } break;
178
179 case LINEARCOMPRESSIBLE:
180 case SUPER:
181 case EXPONENTIAL: {
182 doublereal dDensity(0.);
183 doublereal dBeta(0.);
184 doublereal dPres0(0.);
185 if (HP.IsKeyWord("density")) {
186 dDensity = HP.GetReal();
187
188 if (HP.IsKeyWord("sound" "celerity")) {
189 doublereal sound = HP.GetReal();
190 if (sound < std::numeric_limits<doublereal>::epsilon()) {
191 silent_cerr("line " << HP.GetLineData()
192 << ": illegal sound celerity " << sound
193 << std::endl);
194 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
195 }
196
197 dBeta = sound*sound*dDensity;
198 } else {
199 dBeta = HP.GetReal();
200 if (std::abs(dBeta) < std::numeric_limits<doublereal>::epsilon()) {
201 silent_cerr("line " << HP.GetLineData()
202 << ": illegal bulk modulus " << dBeta
203 << std::endl);
204 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
205 }
206 }
207
208 if (dDensity < std::numeric_limits<doublereal>::epsilon()) {
209 silent_cerr("line " << HP.GetLineData()
210 << ": illegal density " << dDensity
211 << " for hydraulic fluid " << uLabel << std::endl);
212 }
213
214 dPres0 = HP.GetReal();
215 if (dPres0 < 0.) {
216 silent_cerr("line " << HP.GetLineData()
217 << ": illegal reference pressure " << dPres0
218 << " for hydraulic fluid " << uLabel << std::endl);
219 }
220 }
221
222 doublereal dViscosity(0.);
223 if (HP.IsKeyWord("viscosity")) {
224 dViscosity = HP.GetReal();
225 }
226
227 if (dViscosity < std::numeric_limits<doublereal>::epsilon()) {
228 silent_cerr("line " << HP.GetLineData()
229 << ": illegal viscosity " << dViscosity
230 << std::endl);
231 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
232 }
233
234 doublereal dTemp0(-1.);
235 if (HP.IsKeyWord("temperature")) {
236 dTemp0 = HP.GetReal();
237 if (dTemp0 < 0.) {
238 silent_cerr("line " << HP.GetLineData()
239 << ": illegal reference temperature " << dTemp0
240 << " for hydraulic fluid " << uLabel << std::endl);
241 }
242 }
243
244 switch (CurrKeyWord) {
245 default:
246 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
247
248 case LINEARCOMPRESSIBLE:
249 SAFENEWWITHCONSTRUCTOR(pHF,
250 LinearCompressibleHydraulicFluid,
251 LinearCompressibleHydraulicFluid(uLabel,
252 dDensity,
253 dBeta,
254 dPres0,
255 dViscosity,
256 dTemp0));
257 break;
258
259 case SUPER:
260 SAFENEWWITHCONSTRUCTOR(pHF,
261 SuperHydraulicFluid,
262 SuperHydraulicFluid(uLabel,
263 dDensity,
264 dBeta,
265 dPres0,
266 dViscosity,
267 dTemp0));
268 break;
269
270 case EXPONENTIAL:
271 doublereal dPsat = HP.GetReal();
272
273 SAFENEWWITHCONSTRUCTOR(pHF,
274 ExpHydraulicFluid,
275 ExpHydraulicFluid(uLabel,
276 dDensity,
277 dBeta,
278 dPres0,
279 dPsat,
280 dViscosity,
281 dTemp0));
282 break;
283 }
284
285 } break;
286
287 case LINEARTHERMALCOMPRESSIBLE: {
288 doublereal dDensity(0.);
289 doublereal dBeta(0.);
290 doublereal dPres0(0.);
291 doublereal dAlpha(0.);
292 doublereal dTemp0(0.);
293 if (HP.IsKeyWord("density")) {
294 dDensity = HP.GetReal();
295
296 if (HP.IsKeyWord("sound" "celerity")) {
297 doublereal sound = HP.GetReal();
298 if (sound < std::numeric_limits<doublereal>::epsilon()) {
299 silent_cerr("line " << HP.GetLineData()
300 << ": illegal sound celerity " << sound
301 << " for hydraulic fluid " << uLabel << std::endl);
302 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
303 }
304
305 dBeta = sound*sound*dDensity;
306
307 } else {
308 dBeta = HP.GetReal();
309 if (std::abs(dBeta) < std::numeric_limits<doublereal>::epsilon()) {
310 silent_cerr("line " << HP.GetLineData()
311 << ": illegal bulk modulus " << dBeta
312 << " for hydraulic fluid " << uLabel << std::endl);
313 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
314 }
315 }
316
317 if (dDensity < std::numeric_limits<doublereal>::epsilon()) {
318 silent_cerr("line " << HP.GetLineData()
319 << ": illegal density " << dDensity
320 << " for hydraulic fluid " << uLabel << std::endl);
321 }
322
323 dPres0 = HP.GetReal();
324 if (dPres0 < 0.) {
325 silent_cerr("line " << HP.GetLineData()
326 << ": illegal reference pressure " << dPres0
327 << " for hydraulic fluid " << uLabel << std::endl);
328 }
329
330 dAlpha = HP.GetReal();
331
332 dTemp0 = HP.GetReal();
333 if (dTemp0 < 0.) {
334 silent_cerr("line " << HP.GetLineData()
335 << ": illegal reference temperature " << dTemp0
336 << " for hydraulic fluid " << uLabel << std::endl);
337 }
338 }
339
340 doublereal dViscosity(0.);
341 if (HP.IsKeyWord("viscosity")) {
342 dViscosity = HP.GetReal();
343 }
344
345 if (dViscosity < std::numeric_limits<doublereal>::epsilon()) {
346 silent_cerr("line " << HP.GetLineData()
347 << ": illegal viscosity " << dViscosity
348 << std::endl);
349 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
350 }
351
352 SAFENEWWITHCONSTRUCTOR(pHF,
353 LinearCompressibleTHydraulicFluid,
354 LinearCompressibleTHydraulicFluid(uLabel,
355 dDensity,
356 dBeta,
357 dPres0,
358 dAlpha,
359 dTemp0,
360 dViscosity));
361 } break;
362
363 default:
364 silent_cerr("line " << HP.GetLineData()
365 << ": unknown hydraulic fluid type" << std::endl);
366 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
367 }
368
369 return pHF;
370 }
371