MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
constltp.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/constltp.h,v 1.51 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 /* Legami costitutivi */
33 
34 #ifndef CONSTLTP_H
35 #define CONSTLTP_H
36 
37 #include "withlab.h"
38 #include "simentity.h"
39 #include "tpldrive.h"
40 
41 #ifdef USE_AUTODIFF
42 #include "matvec.h"
43 #endif
44 
45 /* Tipi di cerniere deformabili */
46 class ConstLawType {
47 public:
48  enum Type {
49  UNKNOWN = 0x0,
50 
51  ELASTIC = 0x1,
52  VISCOUS = 0x2,
54 
56  };
57 };
58 
59 /* ConstitutiveLaw - begin */
60 template <class T, class Tder>
61 class ConstitutiveLaw : public WithLabel, public SimulationEntity {
62 public:
63  class ErrNotAvailable : public MBDynErrBase {
64  public:
67  {
68  silent_cerr("Constitutive law not available "
69  "for this dimensionality"
70  << std::endl);
71  };
74  {
75  out << "Constitutive law not available "
76  "for this dimensionality"
77  << what()
78  << std::endl;
79  };
80  };
81 
83 
84 protected:
85  T Epsilon; /* strain */
86  T EpsilonPrime; /* strain rate */
87 
88  T F; /* force */
89  Tder FDE; /* force strain derivative */
90  Tder FDEPrime; /* force strain rate derivative */
91 
92 public:
94  : WithLabel(0),
95  Epsilon(mb_zero<T>()), EpsilonPrime(mb_zero<T>()),
96  F(mb_zero<T>()), FDE(mb_zero<Tder>()), FDEPrime(mb_zero<Tder>()) {
97  NO_OP;
98  };
99 
100  virtual ~ConstitutiveLaw(void) {
101  NO_OP;
102  };
103 
104  virtual ConstLawType::Type GetConstLawType(void) const = 0;
105 
106  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const = 0;
107  virtual std::ostream& Restart(std::ostream& out) const {
108  return out;
109  };
110 
111  virtual void Update(const T& Eps, const T& EpsPrime = mb_zero<T>()) = 0;
112 
113  virtual void AfterConvergence(const T& Eps, const T& EpsPrime = mb_zero<T>()) {
114  NO_OP;
115  };
116 
117  virtual const T& GetEpsilon(void) const {
118  return Epsilon;
119  };
120 
121  virtual const T& GetEpsilonPrime(void) const {
122  return EpsilonPrime;
123  };
124 
125  virtual const T& GetF(void) const {
126  return F;
127  };
128 
129  virtual const Tder& GetFDE(void) const {
130  return FDE;
131  };
132 
133  virtual const Tder& GetFDEPrime(void) const {
134  return FDEPrime;
135  };
136 
137  /* simentity */
138  virtual unsigned int iGetNumDof(void) const {
139  return 0;
140  };
141 
142  virtual std::ostream& DescribeDof(std::ostream& out,
143  const char *prefix = "",
144  bool bInitial = false) const
145  {
146  return out;
147  };
148  virtual void DescribeDof(std::vector<std::string>& desc,
149  bool bInitial = false, int i = -1) const
150  {
151  ASSERT(i <= 0);
152  desc.resize(0);
153  };
154 
155  virtual std::ostream& DescribeEq(std::ostream& out,
156  const char *prefix = "",
157  bool bInitial = false) const
158  {
159  return out;
160  };
161 
162  virtual void DescribeEq(std::vector<std::string>& desc,
163  bool bInitial = false, int i = -1) const
164  {
165  ASSERT(i <= 0);
166  desc.resize(0);
167  };
168 
169  virtual DofOrder::Order GetDofType(unsigned int i) const {
171  };
172 
173 protected:
174 #ifdef USE_AUTODIFF
175  template <typename ConstLaw>
176  static inline void UpdateViscoelastic(ConstLaw* pCl, const T& Eps, const T& EpsPrime);
177 
178  template <typename ConstLaw>
179  static inline void UpdateElastic(ConstLaw* pCl, const T& Eps);
180 #endif
181 };
182 
186 
187 #ifdef USE_AUTODIFF
188 template <class T, class Tder>
189 template <typename ConstLaw>
190 inline void ConstitutiveLaw<T, Tder>::UpdateViscoelastic(ConstLaw* pCl, const T& Eps, const T& EpsPrime)
191 {
192 
193 
194  using namespace grad;
195  const index_type N = VectorSize<T>::N;
196  Vector<Gradient<2 * N>, N> gEps, gEpsPrime, gF;
197 
198  pCl->Epsilon = Eps;
199  pCl->EpsilonPrime = EpsPrime;
200 
201  for (int i = 0; i < N; ++i)
202  {
203  gEps(i + 1).SetValuePreserve(Eps(i + 1));
204  gEps(i + 1).DerivativeResizeReset(0, i, MapVectorBase::LOCAL, 1.);
205  gEpsPrime(i + 1).SetValuePreserve(EpsPrime(i + 1));
206  gEpsPrime(i + 1).DerivativeResizeReset(0, i + N, MapVectorBase::LOCAL, 1.);
207  }
208 
209  pCl->UpdateViscoelasticTpl(gEps, gEpsPrime, gF);
210 
211  for (int i = 1; i <= N; ++i)
212  {
213  pCl->F(i) = gF(i).dGetValue();
214 
215  for (int j = 0; j < N; ++j)
216  {
217  pCl->FDE(i, j + 1) = gF(i).dGetDerivativeLocal(j);
218  pCl->FDEPrime(i, j + 1) = gF(i).dGetDerivativeLocal(j + N);
219  }
220  }
221 }
222 
223 template <class T, class Tder>
224 template <typename ConstLaw>
225 inline void ConstitutiveLaw<T, Tder>::UpdateElastic(ConstLaw* pCl, const T& Eps)
226 {
227 
228 
229  using namespace grad;
230  const index_type N = VectorSize<T>::N;
231  Vector<Gradient<N>, N> gEps, gF;
232 
233  pCl->Epsilon = Eps;
234 
235  for (int i = 0; i < N; ++i)
236  {
237  gEps(i + 1).SetValuePreserve(Eps(i + 1));
238  gEps(i + 1).DerivativeResizeReset(0, i, MapVectorBase::LOCAL, 1.);
239  }
240 
241  pCl->UpdateElasticTpl(gEps, gF);
242 
243  for (int i = 1; i <= N; ++i)
244  {
245  pCl->F(i) = gF(i).dGetValue();
246 
247  for (int j = 0; j < N; ++j)
248  {
249  pCl->FDE(i, j + 1) = gF(i).dGetDerivativeLocal(j);
250  }
251  }
252 }
253 #endif
254 
255 /* ConstitutiveLaw - end */
256 
257 
258 /* ConstitutiveLawOwner - begin */
259 
260 template <class T, class Tder>
262 protected:
264 
265 public:
267  : pConstLaw(const_cast<ConstitutiveLaw<T, Tder> *>(pCL)) {
268  ASSERT(pCL != NULL);
269  };
270 
271  virtual ~ConstitutiveLawOwner(void) {
272  ASSERT(pConstLaw != NULL);
273  if (pConstLaw != NULL) {
274  SAFEDELETE(pConstLaw);
275  }
276  };
277 
279  ASSERT(pConstLaw != NULL);
280  return pConstLaw;
281  };
282 
283  inline void Update(const T& Eps, const T& EpsPrime = mb_zero<T>()) {
284  ASSERT(pConstLaw != NULL);
285  pConstLaw->Update(Eps, EpsPrime);
286  };
287 
288  inline void AfterConvergence(const T& Eps, const T& EpsPrime = mb_zero<T>()) {
289  ASSERT(pConstLaw != NULL);
290  pConstLaw->AfterConvergence(Eps, EpsPrime);
291  };
292 
293  inline const T& GetF(void) const {
294  ASSERT(pConstLaw != NULL);
295  return pConstLaw->GetF();
296  };
297 
298  inline const Tder& GetFDE(void) const {
299  ASSERT(pConstLaw != NULL);
300  return pConstLaw->GetFDE();
301  };
302 
303  inline const Tder& GetFDEPrime(void) const {
304  ASSERT(pConstLaw != NULL);
305  return pConstLaw->GetFDEPrime();
306  };
307 
308  /* simentity */
309  virtual unsigned int iGetNumDof(void) const {
310  ASSERT(pConstLaw != NULL);
311  return pConstLaw->iGetNumDof();
312  };
313 
314  virtual std::ostream& DescribeDof(std::ostream& out,
315  const char *prefix = "",
316  bool bInitial = false) const
317  {
318  return out;
319  };
320 
321  virtual void DescribeDof(std::vector<std::string>& desc,
322  bool bInitial = false, int i = -1) const
323  {
324  ASSERT(i <= 0);
325  desc.resize(0);
326  };
327 
328  virtual std::ostream& DescribeEq(std::ostream& out,
329  const char *prefix = "",
330  bool bInitial = false) const
331  {
332  return out;
333  };
334 
335  virtual void DescribeEq(std::vector<std::string>& desc,
336  bool bInitial = false, int i = -1) const
337  {
338  ASSERT(i <= 0);
339  desc.resize(0);
340  };
341 
342  virtual DofOrder::Order GetDofType(unsigned int i) const {
343  ASSERT(pConstLaw != NULL);
344  return pConstLaw->GetDofType(i);
345  };
346 
347  /*
348  * Metodi per l'estrazione di dati "privati".
349  * Si suppone che l'estrattore li sappia interpretare.
350  * Come default non ci sono dati privati estraibili
351  */
352  virtual unsigned int iGetNumPrivData(void) const {
353  return pConstLaw->iGetNumPrivData();
354  };
355 
356  /*
357  * Maps a string (possibly with substrings) to a private data;
358  * returns a valid index ( > 0 && <= iGetNumPrivData()) or 0
359  * in case of unrecognized data; error must be handled by caller
360  */
361  virtual unsigned int iGetPrivDataIdx(const char *s) const {
362  return pConstLaw->iGetPrivDataIdx(s);
363  };
364 
365  /*
366  * Returns the current value of a private data
367  * with 0 < i <= iGetNumPrivData()
368  */
369  virtual doublereal dGetPrivData(unsigned int i) const {
370  return pConstLaw->dGetPrivData(i);
371  };
372 
373  virtual std::ostream& OutputAppend(std::ostream& out) const {
374  return pConstLaw->OutputAppend(out);
375  };
376 };
377 
381 
382 /* ConstitutiveLawOwner - end */
383 
384 /* functions that read a constitutive law */
386 ReadCL1D(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType);
388 ReadCL3D(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType);
390 ReadCL6D(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType);
391 
392 /* prototype of the template functional object: reads a constitutive law */
393 template <class T, class Tder>
395  virtual ~ConstitutiveLawRead<T, Tder>( void ) { NO_OP; };
396  virtual ConstitutiveLaw<T, Tder> *
397  Read(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType) = 0;
398 };
399 
400 /* constitutive law registration functions: call to register one */
401 extern bool
403 extern bool
404 SetCL3D(const char *name, ConstitutiveLawRead<Vec3, Mat3x3> *rf);
405 extern bool
406 SetCL6D(const char *name, ConstitutiveLawRead<Vec6, Mat6x6> *rf);
407 
408 /* create/destroy */
409 extern void InitCL(void);
410 extern void DestroyCL(void);
411 
412 #endif /* CONSTLTP_H */
413 
virtual const T & GetF(void) const
Definition: constltp.h:125
virtual const T & GetEpsilon(void) const
Definition: constltp.h:117
void InitCL(void)
ErrNotAvailable(std::ostream &out, MBDYN_EXCEPT_ARGS_DECL)
Definition: constltp.h:72
virtual DofOrder::Order GetDofType(unsigned int i) const
Definition: constltp.h:169
void DestroyCL(void)
ConstitutiveLaw< T, Tder > * pGetConstLaw(void) const
Definition: constltp.h:278
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
ConstitutiveLaw(void)
Definition: constltp.h:93
ErrNotAvailable(MBDYN_EXCEPT_ARGS_DECL)
Definition: constltp.h:65
#define MBDYN_EXCEPT_ARGS_PASSTHRU
Definition: except.h:55
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: constltp.h:361
ConstitutiveLawOwner< Vec6, Mat6x6 > ConstitutiveLaw6DOwner
Definition: constltp.h:380
virtual unsigned int iGetNumDof(void) const
Definition: constltp.h:309
virtual void DescribeEq(std::vector< std::string > &desc, bool bInitial=false, int i=-1) const
Definition: constltp.h:335
ConstitutiveLawOwner< Vec3, Mat3x3 > ConstitutiveLaw3DOwner
Definition: constltp.h:379
virtual const Tder & GetFDE(void) const
Definition: constltp.h:129
ConstitutiveLaw< Vec3, Mat3x3 > * ReadCL3D(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
const Tder & GetFDE(void) const
Definition: constltp.h:298
ConstitutiveLaw< T, Tder > * pConstLaw
Definition: constltp.h:263
#define MBDYN_EXCEPT_ARGS_DECL
Definition: except.h:43
integer index_type
Definition: gradient.h:104
virtual unsigned int iGetNumPrivData(void) const
Definition: constltp.h:352
ConstitutiveLawOwner(const ConstitutiveLaw< T, Tder > *pCL)
Definition: constltp.h:266
ConstitutiveLaw< Vec6, Mat6x6 > * ReadCL6D(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
#define NO_OP
Definition: myassert.h:74
virtual void DescribeDof(std::vector< std::string > &desc, bool bInitial=false, int i=-1) const
Definition: constltp.h:148
ConstitutiveLaw< doublereal, doublereal > ConstitutiveLaw1D
Definition: constltp.h:183
virtual ~ConstitutiveLaw(void)
Definition: constltp.h:100
virtual std::ostream & Restart(std::ostream &out) const
Definition: constltp.h:107
virtual void DescribeEq(std::vector< std::string > &desc, bool bInitial=false, int i=-1) const
Definition: constltp.h:162
ConstitutiveLaw< Vec3, Mat3x3 > ConstitutiveLaw3D
Definition: constltp.h:184
ConstitutiveLawOwner< doublereal, doublereal > ConstitutiveLaw1DOwner
Definition: constltp.h:378
const T & mb_zero(void)
virtual std::ostream & OutputAppend(std::ostream &out) const
Definition: constltp.h:373
virtual std::ostream & DescribeDof(std::ostream &out, const char *prefix="", bool bInitial=false) const
Definition: constltp.h:314
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
virtual const T & GetEpsilonPrime(void) const
Definition: constltp.h:121
virtual ~ConstitutiveLawOwner(void)
Definition: constltp.h:271
void AfterConvergence(const T &Eps, const T &EpsPrime=mb_zero< T >())
Definition: constltp.h:288
#define ASSERT(expression)
Definition: colamd.c:977
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
ConstitutiveLaw< Vec6, Mat6x6 > ConstitutiveLaw6D
Definition: constltp.h:185
virtual void AfterConvergence(const T &Eps, const T &EpsPrime=mb_zero< T >())
Definition: constltp.h:113
ConstitutiveLaw< T, Tder >::ErrNotAvailable Err
Definition: constltp.h:82
virtual doublereal dGetPrivData(unsigned int i) const
Definition: constltp.h:369
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
virtual unsigned int iGetNumDof(void) const
Definition: constltp.h:138
const T & GetF(void) const
Definition: constltp.h:293
ConstitutiveLaw< doublereal, doublereal > * ReadCL1D(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
virtual const Tder & GetFDEPrime(void) const
Definition: constltp.h:133
virtual std::ostream & DescribeDof(std::ostream &out, const char *prefix="", bool bInitial=false) const
Definition: constltp.h:142
virtual std::ostream & DescribeEq(std::ostream &out, const char *prefix="", bool bInitial=false) const
Definition: constltp.h:328
virtual void DescribeDof(std::vector< std::string > &desc, bool bInitial=false, int i=-1) const
Definition: constltp.h:321
const Tder & GetFDEPrime(void) const
Definition: constltp.h:303
void Update(const T &Eps, const T &EpsPrime=mb_zero< T >())
Definition: constltp.h:283
virtual std::ostream & DescribeEq(std::ostream &out, const char *prefix="", bool bInitial=false) const
Definition: constltp.h:155
virtual DofOrder::Order GetDofType(unsigned int i) const
Definition: constltp.h:342
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710