MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
tdclw.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/tdclw.cc,v 1.24 2017/01/12 14:46:44 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 /* Cerniera deformabile */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include <typeinfo>
37 #include "dataman.h"
38 #include "tdclw.h"
39 
40 /* TDConstitutiveLawWrapper - begin */
41 
42 template <class T, class Tder>
44 : public ConstitutiveLaw<T, Tder> {
45 private:
49 
50 public:
52  const doublereal& dl,
53  const doublereal& dsd,
54  const doublereal& dsf,
55  const doublereal& dInitialWork,
57  virtual ~TDConstitutiveLawWrapper(void);
58 
60 
61  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const;
62  virtual std::ostream& Restart(std::ostream& out) const;
63 
64  virtual void Update(const T& Eps, const T& EpsPrime = mb_zero<T>());
65 
66  virtual void AfterConvergence(const T& Eps, const T& EpsPrime = mb_zero<T>());
67  virtual std::ostream& OutputAppend(std::ostream& out) const;
68 };
69 
70 template <class T, class Tder>
72  const doublereal& df,
73  const doublereal& dl,
74  const doublereal& dsd,
75  const doublereal& dsf,
76  const doublereal& dInitialWork,
78 : dF(df), dW(dl), dScaleEpsilon(dsd), dScaleForce(dsf),
79 dWCurr(dInitialWork), EpsPrev(mb_zero<T>()), FPrev(mb_zero<T>()), pCL(pcl)
80 {
81  NO_OP;
82 }
83 
84 template <class T, class Tder>
86 {
87  if (pCL) {
88  delete pCL;
89  }
90 }
91 
92 template <class T, class Tder>
95 {
96  return pCL->GetConstLawType();
97 }
98 
99 template <class T, class Tder>
102 {
103  ConstitutiveLaw<T, Tder>* pcl = NULL;
104 
105  typedef TDConstitutiveLawWrapper cl;
106  SAFENEWWITHCONSTRUCTOR(pcl, cl,
107  cl(dF, dW, dScaleEpsilon, dScaleForce, dWCurr, pCL->pCopy()));
108  return pcl;
109 }
110 
111 template <class T, class Tder>
112 std::ostream&
114 {
115  out
116  << "tdclw, " << dF
117  << ", " << dW
118  << ", scale deformation, " << dScaleEpsilon
119  << ", scale force, " << dScaleForce
120  << ", ";
121  return pCL->Restart(out);
122 }
123 
124 template <class T, class Tder>
125 void
126 TDConstitutiveLawWrapper<T, Tder>::Update(const T& Eps, const T& EpsPrime)
127 {
128 #if 0
129  // not needed
131 #endif
132 
133  pCL->Update(Eps*dScaleEpsilon, EpsPrime*dScaleEpsilon);
134 
135  // don't use dWCurr if > 0.
136  doublereal d = dScaleForce*(1. + dF*exp(-std::min(0., dWCurr)/dW));
137 
139  if (GetConstLawType() & ConstLawType::ELASTIC) {
141  }
142  if (GetConstLawType() & ConstLawType::VISCOUS) {
144  }
145 }
146 
147 template <class T, class Tder>
148 void
150 {
151  T EpsCurr = Eps*dScaleEpsilon;
152  pCL->AfterConvergence(EpsCurr, EpsPrime*dScaleEpsilon);
153 
154  // average force * (old - new epsilon), to avoid unary - operator
155  const T& FCurr = ConstitutiveLaw<T, Tder>::GetF();
156  dWCurr += ((FCurr + FPrev)*(EpsPrev - EpsCurr))/2.;
157 
158  FPrev = FCurr;
159  EpsPrev = EpsCurr;
160 }
161 
162 template <class T, class Tder>
163 std::ostream&
165 {
166  return pCL->OutputAppend(out) << " " << dWCurr;
167 }
168 
169 /* TDConstitutiveLawWrapper - end */
170 
171 
172 /* TDCLWR - begin */
173 
174 template <class T, class Tder>
175 struct TDCLWR : public ConstitutiveLawRead<T, Tder> {
176  virtual ConstitutiveLaw<T, Tder> *
177  Read(const DataManager* pDM, MBDynParser& HP, ConstLawType::Type& CLType);
178 };
179 
180 template <class T, class Tder>
183 {
184  ConstitutiveLaw<T, Tder>* pCL = 0;
185 
186  doublereal dF = HP.GetReal();
187 
188  doublereal dScaleEpsilon = 1.;
189  if (HP.IsKeyWord("scale" "deformation")) {
190  dScaleEpsilon = HP.GetReal();
191  }
192 
193  doublereal dScaleForce = 1.;
194  if (HP.IsKeyWord("scale" "force")) {
195  dScaleForce = HP.GetReal();
196  }
197 
198  doublereal dW = HP.GetReal();
199  if (dW >= 0.) {
200  silent_cerr("Invalid positive or null reference work in TDCLW "
201  "at line " << HP.GetLineData() << std::endl);
203  }
204 
205  doublereal dInitialWork = 0.;
206  if (HP.IsKeyWord("initial" "work")) {
207  dInitialWork = HP.GetReal();
208  if (dInitialWork > 0.) {
209  silent_cerr("Invalid positive initial work in TDCLW "
210  "at line " << HP.GetLineData() << std::endl);
212  }
213  }
214 
216  if (typeid(T) == typeid(doublereal)) {
217  pCL2 = dynamic_cast<ConstitutiveLaw<T, Tder> *>(HP.GetConstLaw1D(CLType));
218  } else if (typeid(T) == typeid(Vec3)) {
219  pCL2 = dynamic_cast<ConstitutiveLaw<T, Tder> *>(HP.GetConstLaw3D(CLType));
220  } else if (typeid(T) == typeid(Vec6)) {
221  pCL2 = dynamic_cast<ConstitutiveLaw<T, Tder> *>(HP.GetConstLaw6D(CLType));
222  } else {
224  }
225 
227  SAFENEWWITHCONSTRUCTOR(pCL, L,
228  L(dF, dW, dScaleEpsilon, dScaleForce, dInitialWork, pCL2));
229 
230  return pCL;
231 }
232 
233 /* TDCLWR - end */
234 
235 void
237 {
239  SetCL3D("tdclw", new TDCLWR<Vec3, Mat3x3>);
240  SetCL6D("tdclw", new TDCLWR<Vec6, Mat6x6>);
241 }
GradientExpression< UnaryExpr< FuncExp, Expr > > exp(const GradientExpression< Expr > &u)
Definition: gradient.h:2975
doublereal dWCurr
Definition: tdclw.cc:46
virtual const T & GetF(void) const
Definition: constltp.h:125
virtual std::ostream & Restart(std::ostream &out) const
Definition: tdclw.cc:113
Definition: tdclw.cc:175
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TDConstitutiveLawWrapper(const doublereal &df, const doublereal &dl, const doublereal &dsd, const doublereal &dsf, const doublereal &dInitialWork, ConstitutiveLaw< T, Tder > *pcl)
Definition: tdclw.cc:71
Definition: matvec3.h:98
void TDCLW_init(void)
Definition: tdclw.cc:236
ConstitutiveLaw< T, Tder > * pCL
Definition: tdclw.cc:48
virtual const Tder & GetFDE(void) const
Definition: constltp.h:129
virtual std::ostream & OutputAppend(std::ostream &out) const
Definition: tdclw.cc:164
#define NO_OP
Definition: myassert.h:74
ConstLawType::Type GetConstLawType(void) const
Definition: tdclw.cc:94
doublereal dScaleForce
Definition: tdclw.cc:46
virtual void Update(const T &Eps, const T &EpsPrime=mb_zero< T >())
Definition: tdclw.cc:126
Definition: matvec6.h:37
const T & mb_zero(void)
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
ConstitutiveLaw6D * GetConstLaw6D(ConstLawType::Type &clt)
Definition: mbpar.cc:1995
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
doublereal dScaleEpsilon
Definition: tdclw.cc:46
virtual void AfterConvergence(const T &Eps, const T &EpsPrime=mb_zero< T >())
Definition: tdclw.cc:149
virtual ~TDConstitutiveLawWrapper(void)
Definition: tdclw.cc:85
virtual const Tder & GetFDEPrime(void) const
Definition: constltp.h:133
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
Definition: tdclw.cc:101
virtual void Update(const T &Eps, const T &EpsPrime=mb_zero< T >())=0
double doublereal
Definition: colamd.c:52
ConstitutiveLaw3D * GetConstLaw3D(ConstLawType::Type &clt)
Definition: mbpar.cc:1968
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
virtual ConstitutiveLaw< T, Tder > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
Definition: tdclw.cc:182
ConstitutiveLaw1D * GetConstLaw1D(ConstLawType::Type &clt)
Definition: mbpar.cc:1941
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056