MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
constltp_nlp.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/constltp_nlp.cc,v 1.22 2017/01/12 14:46:09 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  * This family of constitutive laws was sponsored by Hutchinson CdR
34  */
35 
36 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
37 
38 #include <cmath>
39 #include <cfloat>
40 
41 #include "dataman.h"
42 #include "ScalarFunctionsImpl.h"
43 #include "constltp_impl.h"
44 
45 template <class T, class Tder>
47 : public ElasticConstitutiveLaw<T, Tder> {
48 private:
50  Tder FDE0;
51  Tder FDEPrime0;
52  std::vector<const DifferentiableScalarFunction *> FDEsc;
53  std::vector<const DifferentiableScalarFunction *> FDEPrimesc;
54 
55 public:
57  const T& PStress,
58  const ConstLawType::Type& cltype,
59  const Tder& fde0,
60  const std::vector<const DifferentiableScalarFunction *>& fdesc,
61  const Tder& fdeprime0,
62  const std::vector<const DifferentiableScalarFunction *>& fdeprimesc)
63  : ElasticConstitutiveLaw<T, Tder>(pDC, PStress),
64  CLType(cltype),
65  FDE0(fde0), FDEPrime0(fdeprime0),
66  FDEsc(fdesc), FDEPrimesc(fdeprimesc)
67  {
70  };
71 
73  NO_OP;
74  };
75 
77  return CLType;
78  };
79 
80  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const {
81  ConstitutiveLaw<T, Tder>* pCL = NULL;
82 
84  SAFENEWWITHCONSTRUCTOR(pCL, cl,
88  return pCL;
89  };
90 
91  virtual std::ostream& Restart(std::ostream& out) const {
92  silent_cerr("NLPViscoElasticConstitutiveLaw: Restart not implemented"
93  << std::endl);
95 
96 #if 0 /* ScalarFunction restart not implemented yet */
97  out << "nlp viscoelastic, ",
98  FDE0.Write(out, ", ");
99 
100  for (unsigned i = 0; i < FDEsc.size(); i++) {
101  out << ", ";
102  if (FDEsc[i]) {
103  FDEsc[i]->Restart(out);
104 
105  } else {
106  out << "null";
107  }
108  }
109 
110  out << ", ", FDEPrime0.Write(out, ", ");
111 
112  for (unsigned i = 0; i < FDEPrimesc.size(); i++) {
113  out << ", ";
114  if (FDEsc[i]) {
115  FDEPrimesc[i]->Restart(out);
116 
117  } else {
118  out << "null";
119  }
120  }
121 
123 #endif
124  };
125 
126  virtual void Update(const T& Eps, const T& EpsPrime = 0.) {
129 
132 
137  }
141  }
142 
143  for (unsigned i = 0; i < FDEsc.size(); i++) {
144 
145  /*
146  * each diagonal coefficient is:
147  *
148  * f = (f0' + f'(eps))*eps + (f0'' + f''(eps))*epsPrime
149  *
150  * so the Jacobian matrix contributions are
151  *
152  * f/eps = f0' + f' + f'/eps * eps + f''/eps * epsPrime
153  * f/epsPrime = f''
154  */
155 
156  doublereal dEps = E(i + 1);
157 
158  doublereal f = 0.;
159  doublereal fde = 0.;
160 
161  if ((CLType & ConstLawType::ELASTIC) && FDEsc[i]) {
162  doublereal df1 = (*FDEsc[i])(dEps);
163  doublereal df1DE = FDEsc[i]->ComputeDiff(dEps);
164  f += df1*dEps;
165  fde += df1 + df1DE*dEps;
166  }
167 
168  if ((CLType & ConstLawType::VISCOUS) && FDEPrimesc[i]) {
169  doublereal df2 = (*FDEPrimesc[i])(dEps);
170  doublereal df2DE = FDEPrimesc[i]->ComputeDiff(dEps);
171  doublereal dEpsPrime = EpsPrime(i + 1);
172  f += df2*dEpsPrime;
173  fde += df2DE*dEpsPrime;
174  ConstitutiveLaw<T, Tder>::FDEPrime(i + 1, i + 1) += df2;
175  }
176 
177  ConstitutiveLaw<T, Tder>::F(i + 1) += f;
178  ConstitutiveLaw<T, Tder>::FDE(i + 1, i + 1) += fde;
179  }
180  };
181 };
182 
183 template <>
185 : public ElasticConstitutiveLaw<doublereal, doublereal> {
186 private:
190  std::vector<const DifferentiableScalarFunction *> FDEsc;
191  std::vector<const DifferentiableScalarFunction *> FDEPrimesc;
192 
193 public:
195  const doublereal& PStress,
196  const ConstLawType::Type& cltype,
197  const doublereal& fde0,
198  const std::vector<const DifferentiableScalarFunction *>& fdesc,
199  const doublereal& fdeprime0,
200  const std::vector<const DifferentiableScalarFunction *>& fdeprimesc)
201  : ElasticConstitutiveLaw<doublereal, doublereal>(pDC, PStress),
202  CLType(cltype),
203  FDE0(fde0), FDEPrime0(fdeprime0),
204  FDEsc(fdesc), FDEPrimesc(fdeprimesc)
205  {
208  };
209 
211  NO_OP;
212  };
213 
215  return CLType;
216  };
217 
220 
222  SAFENEWWITHCONSTRUCTOR(pCL, cl,
226  return pCL;
227  };
228 
229  virtual std::ostream& Restart(std::ostream& out) const {
230  silent_cerr("NLPViscoElasticConstitutiveLaw: Restart not implemented"
231  << std::endl);
233 
234 #if 0 /* ScalarFunction restart not implemented yet */
235  out << "nlp viscoelastic, ",
236  FDE0.Write(out, ", ");
237 
238  for (unsigned i = 0; i < FDEsc.size(); i++) {
239  out << ", ";
240  if (FDEsc[i]) {
241  FDEsc[i]->Restart(out);
242 
243  } else {
244  out << "null";
245  }
246  }
247 
248  out << ", ", FDEPrime0.Write(out, ", ");
249 
250  for (unsigned i = 0; i < FDEPrimesc.size(); i++) {
251  out << ", ";
252  if (FDEsc[i]) {
253  FDEPrimesc[i]->Restart(out);
254 
255  } else {
256  out << "null";
257  }
258  }
259 
261 #endif
262  };
263 
264  virtual void Update(const doublereal& Eps, const doublereal& EpsPrime = 0.) {
267 
270  doublereal dEpsPrime = EpsPrime;
271 
276  }
280  }
281 
282  /*
283  * each diagonal coefficient is:
284  *
285  * f = (f0' + f'(eps))*eps + (f0'' + f''(eps))*epsPrime
286  *
287  * so the Jacobian matrix contributions are
288  *
289  * f/eps = f0' + f' + f'/eps * eps + f''/eps * epsPrime
290  * f/epsPrime = f''
291  */
292 
293  doublereal f = 0.;
294  doublereal fde = 0.;
295 
296  if ((CLType & ConstLawType::ELASTIC) && FDEsc[0]) {
297  doublereal df1 = (*FDEsc[0])(dEps);
298  doublereal df1DE = FDEsc[0]->ComputeDiff(dEps);
299  f += df1*dEps;
300  fde += df1 + df1DE*dEps;
301  }
302 
303  if ((CLType & ConstLawType::VISCOUS) && FDEPrimesc[0]) {
304  doublereal df2 = (*FDEPrimesc[0])(dEps);
305  doublereal df2DE = FDEPrimesc[0]->ComputeDiff(dEps);
306  f += df2*dEpsPrime;
307  fde += df2DE*dEpsPrime;
309  }
310 
313  };
314 };
315 
319 
320 /* specific functional object(s) */
321 template <class T, class Tder, ConstLawType::Type Typ>
322 struct NLPViscoElasticCLR : public ConstitutiveLawRead<T, Tder> {
323  virtual ConstitutiveLaw<T, Tder> *
324  Read(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType)
325  {
326  ConstitutiveLaw<T, Tder>* pCL = 0;
327 
328  unsigned dim;
329  if (typeid(T) == typeid(doublereal)) {
330  dim = 1;
331 
332  } else if (typeid(T) == typeid(Vec3)) {
333  dim = 3;
334 
335  } else if (typeid(T) == typeid(Vec6)) {
336  dim = 6;
337 
338  } else {
339  silent_cerr("Invalid dimensionality "
340  "for NLP viscoelastic constitutive law "
341  "at line " << HP.GetLineData()
342  << std::endl);
344  }
345 
346  /* stiffness */
347  Tder FDE0(mb_zero<Tder>());
348  bool bElastic(false);
349  std::vector<const DifferentiableScalarFunction *> FDEsc(dim);
350  for (unsigned i = 0; i < dim; i++) {
351  FDEsc[i] = 0;
352  }
353 
354 
355  if (Typ & ConstLawType::ELASTIC) {
356  FDE0 = HP.Get(FDE0);
357 
358  bElastic = !IsNull<Tder>(FDE0);
359  for (unsigned i = 0; i < dim; i++) {
360  if (!HP.IsKeyWord("null")) {
361  const BasicScalarFunction *const sc
362  = ParseScalarFunction(HP, (DataManager *const)pDM);
363  FDEsc[i] = dynamic_cast<const DifferentiableScalarFunction *>(sc);
364  if (FDEsc[i] == 0) {
365  silent_cerr("NLPViscoElasticCLR: "
366  "stiffness scalar function #" << i << " "
367  "at line " << HP.GetLineData() << " "
368  "must be differentiable" << std::endl);
370  }
371  bElastic = true;
372  }
373  }
374  }
375 
376  /* damping */
377  Tder FDEPrime0(mb_zero<Tder>());
378  bool bViscous(false);
379  std::vector<const DifferentiableScalarFunction *> FDEPrimesc(dim);
380  for (unsigned i = 0; i < dim; i++) {
381  FDEPrimesc[i] = 0;
382  }
383 
384  if (Typ & ConstLawType::VISCOUS) {
385  if ((Typ & ConstLawType::ELASTIC) && HP.IsKeyWord("proportional")) {
386  FDEPrime0 = FDE0*HP.GetReal();
387  } else {
388  FDEPrime0 = HP.Get(FDEPrime0);
389  }
390 
391 
392  bViscous = !IsNull<Tder>(FDEPrime0);
393  for (unsigned i = 0; i < dim; i++) {
394  if (!HP.IsKeyWord("null")) {
395  const BasicScalarFunction *const sc
396  = ParseScalarFunction(HP, (DataManager *const)pDM);
397  FDEPrimesc[i] = dynamic_cast<const DifferentiableScalarFunction *>(sc);
398  if (FDEPrimesc[i] == 0) {
399  silent_cerr("NLPViscoElasticCLR: "
400  "damping scalar function #" << i << " "
401  "at line " << HP.GetLineData() << " "
402  "must be differentiable" << std::endl);
404  }
405  bViscous = true;
406  }
407  }
408  }
409 
410  /* Prestress and prestrain */
411  T PreStress(mb_zero<T>());
412  GetPreStress(HP, PreStress);
413  TplDriveCaller<T>* pTplDC = GetPreStrain<T>(pDM, HP);
414 
415  if (bElastic && bViscous) {
417  } else if (bElastic) {
418  CLType = ConstLawType::ELASTIC;
419  } else if (bViscous) {
420  CLType = ConstLawType::VISCOUS;
421  } else {
422  /* needs to be at least elastic... */
423  CLType = ConstLawType::ELASTIC;
424  }
425 
427  SAFENEWWITHCONSTRUCTOR(pCL, L,
428  L(pTplDC, PreStress,
429  CLType,
430  FDE0, FDEsc,
431  FDEPrime0, FDEPrimesc));
432 
433  return pCL;
434  };
435 };
436 
437 int
438 NLP_init(void)
439 {
440  // 1D viscoelastic
443  if (!SetCL1D("nlp" "viscoelastic", rf1D)) {
444  delete rf1D;
445 
446  silent_cerr("NLPViscoElasticConstitutiveLaw1D: "
447  "init failed" << std::endl);
448 
449  return -1;
450  }
451 
452  // 1D elastic
454  if (!SetCL1D("nlp" "elastic", rf1D)) {
455  delete rf1D;
456 
457  silent_cerr("NLPElasticConstitutiveLaw1D: "
458  "init failed" << std::endl);
459 
460  return -1;
461  }
462 
463  // 1D viscous
465  if (!SetCL1D("nlp" "viscous", rf1D)) {
466  delete rf1D;
467 
468  silent_cerr("NLPViscousConstitutiveLaw1D: "
469  "init failed" << std::endl);
470 
471  return -1;
472  }
473 
474  // 3D viscoelastic
477  if (!SetCL3D("nlp" "viscoelastic", rf3D)) {
478  delete rf3D;
479 
480  silent_cerr("NLPViscoElasticConstitutiveLaw3D: "
481  "init failed" << std::endl);
482 
483  return -1;
484  }
485 
486  // 3D elastic
488  if (!SetCL3D("nlp" "elastic", rf3D)) {
489  delete rf3D;
490 
491  silent_cerr("NLPElasticConstitutiveLaw3D: "
492  "init failed" << std::endl);
493 
494  return -1;
495  }
496 
497  // 3D viscous
499  if (!SetCL3D("nlp" "viscous", rf3D)) {
500  delete rf3D;
501 
502  silent_cerr("NLPViscousConstitutiveLaw3D: "
503  "init failed" << std::endl);
504 
505  return -1;
506  }
507 
508  // 6D viscoelastic
511  if (!SetCL6D("nlp" "viscoelastic", rf6D)) {
512  delete rf6D;
513 
514  silent_cerr("NLPViscoElasticConstitutiveLaw6D: "
515  "init failed" << std::endl);
516 
517  return -1;
518  }
519 
520  // 6D elastic
522  if (!SetCL6D("nlp" "elastic", rf6D)) {
523  delete rf6D;
524 
525  silent_cerr("NLPElasticConstitutiveLaw6D: "
526  "init failed" << std::endl);
527 
528  return -1;
529  }
530 
531  // 6D viscous
533  if (!SetCL6D("nlp" "viscous", rf6D)) {
534  delete rf6D;
535 
536  silent_cerr("NLPViscousConstitutiveLaw6D: "
537  "init failed" << std::endl);
538 
539  return -1;
540  }
541 
542  return 0;
543 }
544 
virtual std::ostream & Restart(std::ostream &out) const
std::vector< const DifferentiableScalarFunction * > FDEPrimesc
Definition: constltp_nlp.cc:53
virtual void Update(const T &Eps, const T &EpsPrime=0.)
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
ConstLawType::Type GetConstLawType(void) const
Definition: constltp_nlp.cc:76
#define NO_OP
Definition: myassert.h:74
virtual std::ostream & Restart_int(std::ostream &out) const
Definition: matvec6.h:37
std::vector< const DifferentiableScalarFunction * > FDEPrimesc
NLPViscoElasticConstitutiveLaw(const TplDriveCaller< T > *pDC, const T &PStress, const ConstLawType::Type &cltype, const Tder &fde0, const std::vector< const DifferentiableScalarFunction * > &fdesc, const Tder &fdeprime0, const std::vector< const DifferentiableScalarFunction * > &fdeprimesc)
Definition: constltp_nlp.cc:56
NLPViscoElasticConstitutiveLaw< Vec6, Mat6x6 > NLPViscoElasticConstitutiveLaw6D
virtual void Update(const doublereal &Eps, const doublereal &EpsPrime=0.)
NLPViscoElasticConstitutiveLaw< doublereal, doublereal > NLPViscoElasticConstitutiveLaw1D
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
std::vector< const DifferentiableScalarFunction * > FDEsc
virtual ConstitutiveLaw< T, Tder > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
std::vector< const DifferentiableScalarFunction * > FDEsc
Definition: constltp_nlp.cc:52
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
int NLP_init(void)
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
Definition: constltp_nlp.cc:80
void GetPreStress(MBDynParser &HP, T &PreStress)
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
virtual ~NLPViscoElasticConstitutiveLaw(void)
Definition: constltp_nlp.cc:72
NLPViscoElasticConstitutiveLaw< Vec3, Mat3x3 > NLPViscoElasticConstitutiveLaw3D
virtual ConstitutiveLaw< doublereal, doublereal > * pCopy(void) const
NLPViscoElasticConstitutiveLaw(const TplDriveCaller< doublereal > *pDC, const doublereal &PStress, const ConstLawType::Type &cltype, const doublereal &fde0, const std::vector< const DifferentiableScalarFunction * > &fdesc, const doublereal &fdeprime0, const std::vector< const DifferentiableScalarFunction * > &fdeprimesc)
virtual doublereal Get(const doublereal &d)
Definition: mbpar.cc:2213
double doublereal
Definition: colamd.c:52
virtual std::ostream & Restart(std::ostream &out) const
Definition: constltp_nlp.cc:91
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
const BasicScalarFunction *const ParseScalarFunction(MBDynParser &HP, DataManager *const pDM)
T Get(void) const
Definition: tpldrive.h:113
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056