MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
constltp_nlsf.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/constltp_nlsf.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("NLSFViscoElasticConstitutiveLaw: 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'*eps + f'(eps) + f0''*epsPrime + f''(epsPrime)
149  *
150  * so the Jacobian matrix contributions are
151  *
152  * f/eps = f0' + f'/eps
153  * f/epsPrime = f0'' + f''/epsPrime
154  */
155 
156  doublereal f = 0.;
157 
158  if ((CLType & ConstLawType::ELASTIC) && FDEsc[i]) {
159  doublereal dEps = E(i + 1);
160  f += (*FDEsc[i])(dEps);
161  doublereal df1DE = FDEsc[i]->ComputeDiff(dEps);
162  ConstitutiveLaw<T, Tder>::FDE(i + 1, i + 1) += df1DE;
163  }
164 
165  if ((CLType & ConstLawType::ELASTIC) && FDEPrimesc[i]) {
166  doublereal dEpsPrime = EpsPrime(i + 1);
167  f += (*FDEPrimesc[i])(dEpsPrime);
168  doublereal df2DEPrime = FDEPrimesc[i]->ComputeDiff(dEpsPrime);
169  ConstitutiveLaw<T, Tder>::FDEPrime(i + 1, i + 1) += df2DEPrime;
170  }
171 
172  ConstitutiveLaw<T, Tder>::F(i + 1) += f;
173  }
174  };
175 };
176 
177 template <>
179 : public ElasticConstitutiveLaw<doublereal, doublereal> {
180 private:
184  std::vector<const DifferentiableScalarFunction *> FDEsc;
185  std::vector<const DifferentiableScalarFunction *> FDEPrimesc;
186 
187 public:
189  const doublereal& PStress,
190  const ConstLawType::Type& cltype,
191  const doublereal& fde0,
192  const std::vector<const DifferentiableScalarFunction *>& fdesc,
193  const doublereal& fdeprime0,
194  const std::vector<const DifferentiableScalarFunction *>& fdeprimesc)
195  : ElasticConstitutiveLaw<doublereal, doublereal>(pDC, PStress),
196  CLType(cltype),
197  FDE0(fde0), FDEPrime0(fdeprime0),
198  FDEsc(fdesc), FDEPrimesc(fdeprimesc)
199  {
202  };
203 
205  NO_OP;
206  };
207 
209  return CLType;
210  };
211 
214 
216  SAFENEWWITHCONSTRUCTOR(pCL, cl,
220  return pCL;
221  };
222 
223  virtual std::ostream& Restart(std::ostream& out) const {
224  silent_cerr("NLSFViscoElasticConstitutiveLaw: Restart not implemented"
225  << std::endl);
227 
228 #if 0 /* ScalarFunction restart not implemented yet */
229  out << "nlp viscoelastic, ",
230  FDE0.Write(out, ", ");
231 
232  for (unsigned i = 0; i < FDEsc.size(); i++) {
233  out << ", ";
234  if (FDEsc[i]) {
235  FDEsc[i]->Restart(out);
236 
237  } else {
238  out << "null";
239  }
240  }
241 
242  out << ", ", FDEPrime0.Write(out, ", ");
243 
244  for (unsigned i = 0; i < FDEPrimesc.size(); i++) {
245  out << ", ";
246  if (FDEsc[i]) {
247  FDEPrimesc[i]->Restart(out);
248 
249  } else {
250  out << "null";
251  }
252  }
253 
255 #endif
256  };
257 
258  virtual void Update(const doublereal& Eps, const doublereal& EpsPrime = 0.) {
261 
264  doublereal dEpsPrime = EpsPrime;
265 
270  }
274  }
275 
276  /*
277  * each diagonal coefficient is:
278  *
279  * f = (f0' + f'(eps))*eps + (f0'' + f''(eps))*epsPrime
280  *
281  * so the Jacobian matrix contributions are
282  *
283  * f/eps = f0' + f' + f'/eps * eps + f''/eps * epsPrime
284  * f/epsPrime = f''
285  */
286 
287  doublereal f = 0.;
288 
289  if ((CLType & ConstLawType::ELASTIC) && FDEsc[0]) {
290  f += (*FDEsc[0])(dEps);
291  doublereal df1DE = FDEsc[0]->ComputeDiff(dEps);
293  }
294 
295  if ((CLType & ConstLawType::VISCOUS) && FDEPrimesc[0]) {
296  f += (*FDEPrimesc[0])(dEpsPrime);
297  doublereal df2DEPrime = FDEPrimesc[0]->ComputeDiff(dEpsPrime);
299  }
300 
302  };
303 };
304 
308 
309 /* specific functional object(s) */
310 template <class T, class Tder, ConstLawType::Type Typ>
311 struct NLSFViscoElasticCLR : public ConstitutiveLawRead<T, Tder> {
312  virtual ConstitutiveLaw<T, Tder> *
313  Read(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType)
314  {
315  ConstitutiveLaw<T, Tder>* pCL = 0;
316 
317  unsigned dim;
318  if (typeid(T) == typeid(doublereal)) {
319  dim = 1;
320 
321  } else if (typeid(T) == typeid(Vec3)) {
322  dim = 3;
323 
324  } else if (typeid(T) == typeid(Vec6)) {
325  dim = 6;
326 
327  } else {
328  silent_cerr("Invalid dimensionality "
329  "for NLSF viscoelastic constitutive law "
330  "at line " << HP.GetLineData()
331  << std::endl);
333  }
334 
335  /* stiffness */
336  Tder FDE0(mb_zero<Tder>());
337  bool bElastic(false);
338  std::vector<const DifferentiableScalarFunction *> FDEsc(dim);
339  for (unsigned i = 0; i < dim; i++) {
340  FDEsc[i] = 0;
341  }
342 
343  if (Typ & ConstLawType::ELASTIC) {
344  FDE0 = HP.Get(FDE0);
345 
346  bElastic = !IsNull<Tder>(FDE0);
347  for (unsigned i = 0; i < dim; i++) {
348  if (!HP.IsKeyWord("null")) {
349  const BasicScalarFunction *const sc
350  = ParseScalarFunction(HP, (DataManager *const)pDM);
351  FDEsc[i] = dynamic_cast<const DifferentiableScalarFunction *>(sc);
352  if (FDEsc[i] == 0) {
353  silent_cerr("NLSFViscoElasticCLR: "
354  "stiffness scalar function #" << i << " "
355  "at line " << HP.GetLineData() << " "
356  "must be differentiable" << std::endl);
358  }
359  bElastic = true;
360  }
361  }
362  }
363 
364  /* damping */
365  Tder FDEPrime0(mb_zero<Tder>());
366  bool bViscous(false);
367  std::vector<const DifferentiableScalarFunction *> FDEPrimesc(dim);
368  for (unsigned i = 0; i < dim; i++) {
369  FDEPrimesc[i] = 0;
370  }
371 
372  if (Typ & ConstLawType::VISCOUS) {
373  if ((Typ & ConstLawType::ELASTIC) && HP.IsKeyWord("proportional")) {
374  FDEPrime0 = FDE0*HP.GetReal();
375  } else {
376  FDEPrime0 = HP.Get(FDEPrime0);
377  }
378 
379  bViscous = !IsNull<Tder>(FDEPrime0);
380  for (unsigned i = 0; i < dim; i++) {
381  if (!HP.IsKeyWord("null")) {
382  const BasicScalarFunction *const sc
383  = ParseScalarFunction(HP, (DataManager *const)pDM);
384  FDEPrimesc[i] = dynamic_cast<const DifferentiableScalarFunction *>(sc);
385  if (FDEPrimesc[i] == 0) {
386  silent_cerr("NLSFViscoElasticCLR: "
387  "damping scalar function #" << i << " "
388  "at line " << HP.GetLineData() << " "
389  "must be differentiable" << std::endl);
391  }
392  bViscous = true;
393  }
394  }
395  }
396 
397  /* Prestress and prestrain */
398  T PreStress(mb_zero<T>());
399  GetPreStress(HP, PreStress);
400  TplDriveCaller<T>* pTplDC = GetPreStrain<T>(pDM, HP);
401 
402  if (bElastic && bViscous) {
404  } else if (bElastic) {
405  CLType = ConstLawType::ELASTIC;
406  } else if (bViscous) {
407  CLType = ConstLawType::VISCOUS;
408  } else {
409  /* needs to be at least elastic... */
410  CLType = ConstLawType::ELASTIC;
411  }
412 
414  SAFENEWWITHCONSTRUCTOR(pCL, L,
415  L(pTplDC, PreStress,
416  CLType,
417  FDE0, FDEsc,
418  FDEPrime0, FDEPrimesc));
419 
420  return pCL;
421  };
422 };
423 
424 int
426 {
427  // 1D viscoelastic
430  if (!SetCL1D("nlsf" "viscoelastic", rf1D)) {
431  delete rf1D;
432 
433  silent_cerr("NLSFViscoElasticConstitutiveLaw1D: "
434  "init failed" << std::endl);
435 
436  return -1;
437  }
438 
439  // 1D elastic
441  if (!SetCL1D("nlsf" "elastic", rf1D)) {
442  delete rf1D;
443 
444  silent_cerr("NLSFElasticConstitutiveLaw1D: "
445  "init failed" << std::endl);
446 
447  return -1;
448  }
449 
450  // 1D viscous
452  if (!SetCL1D("nlsf" "viscous", rf1D)) {
453  delete rf1D;
454 
455  silent_cerr("NLSFViscousConstitutiveLaw1D: "
456  "init failed" << std::endl);
457 
458  return -1;
459  }
460 
461  // 3D viscoelastic
464  if (!SetCL3D("nlsf" "viscoelastic", rf3D)) {
465  delete rf3D;
466 
467  silent_cerr("NLSFViscoElasticConstitutiveLaw3D: "
468  "init failed" << std::endl);
469 
470  return -1;
471  }
472 
473  // 3D elastic
475  if (!SetCL3D("nlsf" "elastic", rf3D)) {
476  delete rf3D;
477 
478  silent_cerr("NLSFElasticConstitutiveLaw3D: "
479  "init failed" << std::endl);
480 
481  return -1;
482  }
483 
484  // 3D viscous
486  if (!SetCL3D("nlsf" "viscous", rf3D)) {
487  delete rf3D;
488 
489  silent_cerr("NLSFViscousConstitutiveLaw3D: "
490  "init failed" << std::endl);
491 
492  return -1;
493  }
494 
495  // 6D viscoelastic
498  if (!SetCL6D("nlsf" "viscoelastic", rf6D)) {
499  delete rf6D;
500 
501  silent_cerr("NLSFViscoElasticConstitutiveLaw6D: "
502  "init failed" << std::endl);
503 
504  return -1;
505  }
506 
507  // 6D elastic
509  if (!SetCL6D("nlsf" "elastic", rf6D)) {
510  delete rf6D;
511 
512  silent_cerr("NLSFElasticConstitutiveLaw6D: "
513  "init failed" << std::endl);
514 
515  return -1;
516  }
517 
518  // 6D viscous
520  if (!SetCL6D("nlsf" "viscous", rf6D)) {
521  delete rf6D;
522 
523  silent_cerr("NLSFViscousConstitutiveLaw6D: "
524  "init failed" << std::endl);
525 
526  return -1;
527  }
528 
529  return 0;
530 }
531 
NLSFViscoElasticConstitutiveLaw< doublereal, doublereal > NLSFViscoElasticConstitutiveLaw1D
virtual ConstitutiveLaw< doublereal, doublereal > * pCopy(void) const
virtual std::ostream & Restart(std::ostream &out) const
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
NLSFViscoElasticConstitutiveLaw(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)
std::vector< const DifferentiableScalarFunction * > FDEsc
NLSFViscoElasticConstitutiveLaw(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)
std::vector< const DifferentiableScalarFunction * > FDEsc
virtual void Update(const T &Eps, const T &EpsPrime=0.)
std::vector< const DifferentiableScalarFunction * > FDEPrimesc
#define NO_OP
Definition: myassert.h:74
virtual ~NLSFViscoElasticConstitutiveLaw(void)
virtual std::ostream & Restart_int(std::ostream &out) const
NLSFViscoElasticConstitutiveLaw< Vec3, Mat3x3 > NLSFViscoElasticConstitutiveLaw3D
int NLSF_init(void)
Definition: matvec6.h:37
virtual void Update(const doublereal &Eps, const doublereal &EpsPrime=0.)
virtual std::ostream & Restart(std::ostream &out) const
std::vector< const DifferentiableScalarFunction * > FDEPrimesc
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
void GetPreStress(MBDynParser &HP, T &PreStress)
ConstLawType::Type GetConstLawType(void) const
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
NLSFViscoElasticConstitutiveLaw< Vec6, Mat6x6 > NLSFViscoElasticConstitutiveLaw6D
virtual ConstitutiveLaw< T, Tder > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
virtual doublereal Get(const doublereal &d)
Definition: mbpar.cc:2213
double doublereal
Definition: colamd.c:52
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