MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ginaccltp.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/ginaccltp.h,v 1.36 2017/04/28 17:59:45 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 /* GiNaC constitutive law */
33 
34 #ifndef GINACCLTP_H
35 #define GINACCLTP_H
36 
37 #include <typeinfo>
38 
39 #include <ginac/ginac.h>
40 
41 #include "symcltp.h"
42 
43 /* GiNaCElasticConstitutiveLaw - begin */
44 
45 template <class T, class Tder>
47 : public SymbolicElasticConstitutiveLaw<T, Tder> {
48 private:
49  unsigned dim;
50 
51  std::vector<GiNaC::symbol *> gEps; /* parameter symbols */
52 
53  std::vector<GiNaC::ex> gExpr; /* expressions */
54  std::vector<std::vector<GiNaC::ex> > gExprDEps; /* derivatives */
55 
56 public:
58  const TplDriveCaller<T>* pDC,
59  const T& PStress,
60  std::vector<std::string>& epsilon,
61  std::vector<std::string>& expression);
62  virtual ~GiNaCElasticConstitutiveLaw(void);
63  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const;
64  virtual std::ostream& Restart(std::ostream& out) const;
65  virtual void Update(const T& Eps, const T& /* EpsPrime */ = 0.);
66 };
67 
74 
75 template <class T, class Tder>
77  const TplDriveCaller<T>* pDC,
78  const T& PStress,
79  std::vector<std::string>& epsilon,
80  std::vector<std::string>& expression)
81 : SymbolicElasticConstitutiveLaw<T, Tder>(pDC, PStress, epsilon, expression)
82 {
83  if (typeid(T) == typeid(Vec3)) {
84  dim = 3;
85 
86  } else if (typeid(T) == typeid(Vec6)) {
87  dim = 6;
88 
89  } else {
91  }
92 
93  gEps.resize(dim);
94  gExpr.resize(dim);
95 
96  gExprDEps.resize(dim);
97  for (unsigned row = 0; row < dim; row++) {
98  gExprDEps[row].resize(dim);
99  }
100 
101  ConstitutiveLaw<T, Tder>::FDE = mb_zero<Tder>();
102 
103  GiNaC::lst l;
104 
105  for (unsigned row = 0; row < dim; row++) {
106  gEps[row] = new GiNaC::symbol(epsilon[row]);
107  l.append(*gEps[row]);
108  }
109 
110  for (unsigned row = 0; row < dim; row++) {
111  try {
112  gExpr[row] = GiNaC::ex(expression[row], l);
113 
114  } catch (std::exception& e) {
115  silent_cerr("GiNaCElasticConstitutiveLaw<T, Tder>: expression #" << row << " parsing "
116  "failed: " << e.what() << std::endl);
117  throw e;
118  }
119 
120  for (unsigned col = 0; col < dim; col++) {
121  try {
122  gExprDEps[row][col] = gExpr[row].diff(*gEps[col]);
123 
124  } catch (std::exception& e) {
125  silent_cerr("GiNaCElasticConstitutiveLaw<T, Tder>: expression #" << row << " differentiation "
126  "wrt/ Eps #" << col << "failed: "
127  << e.what() << std::endl);
128  throw e;
129  }
130  }
131  }
132 
133  silent_cout("\tGiNaCElasticConstitutiveLaw:" << std::endl);
134  for (unsigned row = 0; row < dim; row++) {
135  silent_cout("\t\tEps[" << row << "]: \"" << *gEps[row] << "\"" << std::endl);
136  }
137  for (unsigned row = 0; row < dim; row++) {
138  silent_cout("\t\tConstitutive law[" << row << "]: \"" << gExpr[row] << "\"" << std::endl);
139  }
140  for (unsigned row = 0; row < dim; row++) {
141  for (unsigned col = 0; col < dim; col++) {
142  silent_cout("\t\tDer[" << row << "]/Eps[" << row << "][" << col << "]: \"" << gExprDEps[row][col] << "\"" << std::endl);
143  }
144  }
145 
146  // try and evaluate the constitutive law
147  try {
149  }
150  catch (std::exception& e) {
151  silent_cerr("GiNaCElasticConstitutiveLaw<T, Tder>::GiNaCElasticConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
152  throw e;
153  }
154 }
155 
156 template <class T, class Tder>
158 {
159  for (unsigned row = 0; row < dim; row++) {
160  delete gEps[row];
161  }
162 };
163 
164 template <class T, class Tder> ConstitutiveLaw<T, Tder>*
166 {
167  ConstitutiveLaw<T, Tder>* pCL = 0;
168 
169  std::vector<std::string> epsilon(dim);
170  std::vector<std::string> expression(dim);
171 
172  for (unsigned row = 0; row < dim; row++) {
173  std::ostringstream eps;
174  std::ostringstream expr;
175 
176  eps << *gEps[row];
177  expr << gExpr[row];
178 
179  epsilon[row] = eps.str();
180  expression[row] = expr.str();
181  }
182 
185  cl,
188  epsilon, expression));
189 
190  return pCL;
191 }
192 
193 template <class T, class Tder> std::ostream&
195 {
196  out << "symbolic elastic, epsilon";
197  for (unsigned row = 0; row < dim; row++) {
198  out << ", \"" << *gEps[row] << "\"";
199  }
200  out << "\", expression";
201  for (unsigned row = 0; row < dim; row++) {
202  out << ", \"" << gExpr[row] << "\"";
203  }
204 
206 }
207 
208 template <class T, class Tder> void
210  const T& /* EpsPrime */ )
211 {
212  GiNaC::lst l;
213 
215 
217 
218  for (unsigned row = 0; row < dim; row++) {
219  l.append(*gEps[row] == e(row + 1));
220  }
221 
223 
224  for (unsigned row = 0; row < dim; row++) {
225  GiNaC::ex f_expr = gExpr[row].subs(l);
226 
228  += GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
229 
230  for (unsigned col = 0; col < dim; col++) {
231  GiNaC::ex f_derEps = gExprDEps[row][col].subs(l);
232 
233  ConstitutiveLaw<T, Tder>::FDE(row + 1, col + 1)
234  = GiNaC::ex_to<GiNaC::numeric>(f_derEps).to_double();
235  }
236  }
237 }
238 
239 /* specialize for scalar constitutive law */
240 
241 template <>
243 : public SymbolicElasticConstitutiveLaw<doublereal, doublereal> {
244 private:
245  GiNaC::symbol gEps; /* parameter symbol */
246 
247  GiNaC::ex gExpr; /* expression */
248  GiNaC::ex gExprDEps; /* derivative */
249 
250 public:
252  const TplDriveCaller<doublereal>* pDC,
253  const doublereal& PStress,
254  std::vector<std::string>& epsilon,
255  std::vector<std::string>& expression);
256  virtual ~GiNaCElasticConstitutiveLaw(void);
257  virtual ConstitutiveLaw<doublereal, doublereal>* pCopy(void) const;
258  virtual std::ostream& Restart(std::ostream& out) const;
259  virtual void Update(const doublereal& Eps, const doublereal& /* EpsPrime */ = 0.);
260 };
261 
263  const TplDriveCaller<doublereal>* pDC,
264  const doublereal& PStress,
265  std::vector<std::string>& epsilon,
266  std::vector<std::string>& expression)
267 : SymbolicElasticConstitutiveLaw<doublereal, doublereal>(pDC, PStress, epsilon, expression),
268 gEps(epsilon[0])
269 {
271 
272  GiNaC::lst l;
273 
274  l.append(gEps);
275 
276  try {
277  gExpr = GiNaC::ex(expression[0], l);
278 
279  } catch (std::exception& e) {
280  silent_cerr("GiNaCElasticConstitutiveLaw<doublereal, doublereal>: expression parsing failed: " << e.what() << std::endl);
281  throw e;
282  }
283 
284  try {
285  gExprDEps = gExpr.diff(gEps);
286 
287  } catch (std::exception& e) {
288  silent_cerr("GiNaCElasticConstitutiveLaw<doublereal, doublereal>: expression differentiation wrt/ Eps failed: " << e.what() << std::endl);
289  throw e;
290  }
291 
292  silent_cout("\tGiNaCElasticConstitutiveLaw:" << std::endl
293  << "\t\tEps: \"" << gEps << "\"" << std::endl
294  << "\t\tConstitutive law: \"" << gExpr << "\"" << std::endl
295  << "\t\tDer/Eps: \"" << gExprDEps << "\"" << std::endl);
296 
297  // try and evaluate the constitutive law
298  try {
300  }
301  catch (std::exception& e) {
302  silent_cerr("GiNaCElasticConstitutiveLaw<doublereal, doublereal>::GiNaCElasticConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
303  throw e;
304  }
305 }
306 
308 {
309  NO_OP;
310 };
311 
314 {
316 
317  std::ostringstream eps;
318  std::ostringstream expr;
319 
320  eps << gEps;
321  expr << gExpr;
322 
323  std::vector<std::string> epsilon;
324  std::vector<std::string> expression;
325 
326  epsilon.push_back(eps.str());
327  expression.push_back(expr.str());
328 
331  cl,
334  epsilon, expression));
335 
336  return pCL;
337 }
338 
339 std::ostream&
341 {
342  out << "symbolic elastic isotropic, epsilon, \"" << gEps
343  << "\", expression, \"" << gExpr << "\"";
344 
345  return Restart_int(out);
346 }
347 
348 void
350  const doublereal& /* EpsPrime */ )
351 {
352  GiNaC::lst l;
353 
355 
357 
358  l.append(gEps == e);
359 
360  GiNaC::ex f_expr = gExpr.subs(l);
363  + GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
364 
365  GiNaC::ex f_derEps = gExprDEps.subs(l);
366  ConstitutiveLaw<doublereal, doublereal>::FDE = GiNaC::ex_to<GiNaC::numeric>(f_derEps).to_double();
367 }
368 
369 /* GiNaCElasticConstitutiveLaw - end */
370 
371 /* GiNaCViscousConstitutiveLaw - begin */
372 
373 template <class T, class Tder>
375 : public SymbolicViscousConstitutiveLaw<T, Tder> {
376 private:
377  unsigned dim;
378 
379  std::vector<GiNaC::symbol *> gEpsPrime; /* parameter symbols */
380 
381  std::vector<GiNaC::ex> gExpr; /* expressions */
382  std::vector<std::vector<GiNaC::ex> > gExprDEpsPrime; /* derivatives */
383 
384 public:
386  const T& PStress,
387  std::vector<std::string>& epsilon,
388  std::vector<std::string>& expression);
389  virtual ~GiNaCViscousConstitutiveLaw(void);
390  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const;
391  virtual std::ostream& Restart(std::ostream& out) const;
392  virtual void Update(const T& Eps, const T& /* EpsPrime */ = 0.);
393 };
394 
401 
402 template <class T, class Tder>
404  const T& PStress,
405  std::vector<std::string>& epsilonPrime,
406  std::vector<std::string>& expression)
407 : SymbolicViscousConstitutiveLaw<T, Tder>(PStress, epsilonPrime, expression)
408 {
409  if (typeid(T) == typeid(Vec3)) {
410  dim = 3;
411 
412  } else if (typeid(T) == typeid(Vec6)) {
413  dim = 6;
414 
415  } else {
417  }
418 
419  gEpsPrime.resize(dim);
420  gExpr.resize(dim);
421 
422  gExprDEpsPrime.resize(dim);
423  for (unsigned row = 0; row < dim; row++) {
424  gExprDEpsPrime[row].resize(dim);
425  }
426 
427  ConstitutiveLaw<T, Tder>::FDE = mb_zero<Tder>();
428  ConstitutiveLaw<T, Tder>::FDEPrime = mb_zero<Tder>();
429 
430  GiNaC::lst l;
431 
432  for (unsigned row = 0; row < dim; row++) {
433  gEpsPrime[row] = new GiNaC::symbol(epsilonPrime[row]);
434  l.append(*gEpsPrime[row]);
435  }
436 
437  for (unsigned row = 0; row < dim; row++) {
438  try {
439  gExpr[row] = GiNaC::ex(expression[row], l);
440 
441  } catch (std::exception& e) {
442  silent_cerr("GiNaCViscousConstitutiveLaw<T, Tder>: expression #" << row << " parsing "
443  "failed: " << e.what() << std::endl);
444  throw e;
445  }
446 
447  for (unsigned col = 0; col < dim; col++) {
448  try {
449  gExprDEpsPrime[row][col] = gExpr[row].diff(*gEpsPrime[col]);
450 
451  } catch (std::exception& e) {
452  silent_cerr("GiNaCViscousConstitutiveLaw<T, Tder>: expression #" << row << " differentiation "
453  "wrt/ EpsPrime #" << col << " failed: " << e.what()
454  << std::endl);
455  throw e;
456  }
457  }
458  }
459 
460  silent_cout("\tGiNaCViscousConstitutiveLaw:" << std::endl);
461  for (unsigned row = 0; row < dim; row++) {
462  silent_cout("\t\tEpsPrime[" << row << "]: \"" << *gEpsPrime[row] << "\"" << std::endl);
463  }
464  for (unsigned row = 0; row < dim; row++) {
465  silent_cout("\t\tConstitutive law[" << row << "]: \"" << gExpr[row] << "\"" << std::endl);
466  }
467  for (unsigned row = 0; row < dim; row++) {
468  for (unsigned col = 0; col < dim; col++) {
469  silent_cout("\t\tDer[" << row << "]/EpsPrime[" << row << "][" << col << "]: \"" << gExprDEpsPrime[row][col] << "\"" << std::endl);
470  }
471  }
472 
473  // try and evaluate the constitutive law
474  try {
476  }
477  catch (std::exception& e) {
478  silent_cerr("GiNaCViscousConstitutiveLaw<T, Tder>::GiNaCViscousConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
479  throw e;
480  }
481 };
482 
483 template <class T, class Tder>
485 {
486  for (unsigned row = 0; row < dim; row++) {
487  delete gEpsPrime[row];
488  }
489 }
490 
491 template <class T, class Tder> ConstitutiveLaw<T, Tder>*
493 {
494  ConstitutiveLaw<T, Tder>* pCL = 0;
495 
496  std::vector<std::string> epsilonPrime(dim);
497  std::vector<std::string> expression(dim);
498 
499  for (unsigned row = 0; row < dim; row++) {
500  std::ostringstream epsPrime;
501  std::ostringstream expr;
502 
503  epsPrime << *gEpsPrime[row];
504  expr << gExpr[row];
505 
506  epsilonPrime[row] = epsPrime.str();
507  expression[row] = expr.str();
508  }
509 
512  cl,
514  epsilonPrime, expression));
515 
516  return pCL;
517 }
518 
519 template <class T, class Tder> std::ostream&
521 {
522  out << "symbolic viscous, epsilonPrime";
523  for (unsigned row = 0; row < dim; row++) {
524  out << ", \"" << *gEpsPrime[row] << "\"";
525  }
526  out << "\", expression";
527  for (unsigned row = 0; row < dim; row++) {
528  out << ", \"" << gExpr[row] << "\"";
529  }
530 
532 }
533 
534 template <class T, class Tder> void
536  const T& EpsPrime)
537 {
538  GiNaC::lst l;
539 
541 
542  for (unsigned row = 0; row < dim; row++) {
543  l.append(*gEpsPrime[row] == EpsPrime(row + 1));
544  }
545 
546  for (unsigned row = 0; row < dim; row++) {
547  GiNaC::ex f_expr = gExpr[row].subs(l);
548 
550  = GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
551 
552  for (unsigned col = 0; col < dim; col++) {
553  GiNaC::ex f_derEpsPrime = gExprDEpsPrime[row][col].subs(l);
554 
555  ConstitutiveLaw<T, Tder>::FDEPrime(row + 1, col + 1)
556  = GiNaC::ex_to<GiNaC::numeric>(f_derEpsPrime).to_double();
557  }
558  }
559 }
560 
561 /* specialize for scalar constitutive law */
562 
563 template <>
565 : public SymbolicViscousConstitutiveLaw<doublereal, doublereal> {
566 private:
567  GiNaC::symbol gEpsPrime; /* parameter derivative symbol */
568 
569  GiNaC::ex gExpr; /* expression */
570  GiNaC::ex gExprDEpsPrime; /* derivative */
571 
572 public:
574  const doublereal& PStress,
575  std::vector<std::string>& epsilonPrime,
576  std::vector<std::string>& expression);
577  virtual ~GiNaCViscousConstitutiveLaw(void);
578  virtual ConstitutiveLaw<doublereal, doublereal>* pCopy(void) const;
579  virtual std::ostream& Restart(std::ostream& out) const;
580  virtual void Update(const doublereal& Eps, const doublereal& EpsPrime = 0.);
581 };
582 
584  const doublereal& PStress,
585  std::vector<std::string>& epsilonPrime,
586  std::vector<std::string>& expression)
587 : SymbolicViscousConstitutiveLaw<doublereal, doublereal>(PStress, epsilonPrime, expression),
588 gEpsPrime(epsilonPrime[0])
589 {
591 
592  GiNaC::lst l;
593 
594  l.append(gEpsPrime);
595 
596  try {
597  gExpr = GiNaC::ex(expression[0], l);
598  } catch (std::exception& e) {
599  silent_cerr("GiNaCViscousConstitutiveLaw<doublereal, doublereal>: expression parsing failed: " << e.what() << std::endl);
600  throw e;
601  }
602 
603  try {
605  } catch (std::exception& e) {
606  silent_cerr("GiNaCViscousConstitutiveLaw<doublereal, doublereal>: expression differentiation wrt/ EpsPrime failed: " << e.what() << std::endl);
607  throw e;
608  }
609 
610  silent_cout("\tGiNaCViscousConstitutiveLaw:" << std::endl
611  << "\t\tEpsPrime: \"" << gEpsPrime << "\"" << std::endl
612  << "\t\tConstitutive law: \"" << gExpr << "\"" << std::endl
613  << "\t\tDer/EpsPrime: \"" << gExprDEpsPrime << "\"" << std::endl);
614 
615  // try and evaluate the constitutive law
616  try {
618  }
619  catch (std::exception& e) {
620  silent_cerr("GiNaCViscousConstitutiveLaw<doublereal, doublereal>::GiNaCViscousConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
621  throw e;
622  }
623 }
624 
626 {
627  NO_OP;
628 };
629 
632 {
634 
635  std::ostringstream epsPrime;
636  std::ostringstream expr;
637 
638  epsPrime << gEpsPrime;
639  expr << gExpr;
640 
641  std::vector<std::string> epsilonPrime;
642  std::vector<std::string> expression;
643 
644  epsilonPrime.push_back(epsPrime.str());
645  expression.push_back(expr.str());
646 
649  cl,
651  epsilonPrime, expression));
652 
653  return pCL;
654 }
655 
656 std::ostream&
658 {
659  out << "symbolic viscous isotropic, "
660  << "epsilon prime, \"" << gEpsPrime
661  << "\", expression, \"" << gExpr << "\"";
662 
663  return Restart_int(out);
664 }
665 
666 void
668  const doublereal& /* Eps */ ,
669  const doublereal& EpsPrime)
670 {
671  GiNaC::lst l;
672 
674 
675  l.append(gEpsPrime == EpsPrime);
676 
677  GiNaC::ex f_expr = gExpr.subs(l);
680  + GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
681 
682  GiNaC::ex f_derEpsPrime = gExprDEpsPrime.subs(l);
683  ConstitutiveLaw<doublereal, doublereal>::FDEPrime = GiNaC::ex_to<GiNaC::numeric>(f_derEpsPrime).to_double();
684 }
685 
686 /* GiNaCViscousConstitutiveLaw - end */
687 
688 /* GiNaCViscoElasticConstitutiveLaw - begin */
689 
690 template <class T, class Tder>
692 : public SymbolicViscoElasticConstitutiveLaw<T, Tder> {
693 private:
694  unsigned dim;
695 
696  std::vector<GiNaC::symbol *> gEps; /* parameter symbols */
697  std::vector<GiNaC::symbol *> gEpsPrime; /* parameter symbols */
698 
699  std::vector<GiNaC::ex> gExpr; /* expressions */
700  std::vector<std::vector<GiNaC::ex> > gExprDEps; /* derivatives */
701  std::vector<std::vector<GiNaC::ex> > gExprDEpsPrime; /* derivatives */
702 
703 public:
705  const TplDriveCaller<T>* pDC,
706  const T& PStress,
707  std::vector<std::string>& epsilon,
708  std::vector<std::string>& epsilonPrime,
709  std::vector<std::string>& expression);
710  virtual ~GiNaCViscoElasticConstitutiveLaw(void);
711  virtual ConstitutiveLaw<T, Tder>* pCopy(void) const;
712  virtual std::ostream& Restart(std::ostream& out) const;
713  virtual void Update(const T& Eps, const T& /* EpsPrime */ = mb_zero<T>());
714 };
715 
722 
723 template <class T, class Tder>
725  const TplDriveCaller<T>* pDC,
726  const T& PStress,
727  std::vector<std::string>& epsilon,
728  std::vector<std::string>& epsilonPrime,
729  std::vector<std::string>& expression)
730 : SymbolicViscoElasticConstitutiveLaw<T, Tder>(pDC, PStress, epsilon, epsilonPrime, expression)
731 {
732  if (typeid(T) == typeid(Vec3)) {
733  dim = 3;
734 
735  } else if (typeid(T) == typeid(Vec6)) {
736  dim = 6;
737 
738  } else {
740  }
741 
742  gEps.resize(dim);
743  gEpsPrime.resize(dim);
744  gExpr.resize(dim);
745 
746  gExprDEps.resize(dim);
747  gExprDEpsPrime.resize(dim);
748  for (unsigned row = 0; row < dim; row++) {
749  gExprDEps[row].resize(dim);
750  gExprDEpsPrime[row].resize(dim);
751  }
752 
753  ConstitutiveLaw<T, Tder>::FDE = mb_zero<Tder>();
754  ConstitutiveLaw<T, Tder>::FDEPrime = mb_zero<Tder>();
755 
756  GiNaC::lst l;
757 
758  for (unsigned row = 0; row < dim; row++) {
759  gEps[row] = new GiNaC::symbol(epsilon[row]);
760  l.append(*gEps[row]);
761  gEpsPrime[row] = new GiNaC::symbol(epsilonPrime[row]);
762  l.append(*gEpsPrime[row]);
763  }
764 
765  for (unsigned row = 0; row < dim; row++) {
766  try {
767  gExpr[row] = GiNaC::ex(expression[row], l);
768 
769  } catch (std::exception& e) {
770  silent_cerr("GiNaCViscoElasticConstitutiveLaw<T, Tder>: expression #" << row << " parsing "
771  "failed: " << e.what() << std::endl);
772  throw e;
773  }
774 
775  for (unsigned col = 0; col < dim; col++) {
776  try {
777  gExprDEps[row][col] = gExpr[row].diff(*gEps[col]);
778 
779  } catch (std::exception& e) {
780  silent_cerr("GiNaCViscoElasticConstitutiveLaw<T, Tder>: expression #" << row << " differentiation "
781  "wrt/ Eps #" << col << "failed: "
782  << e.what() << std::endl);
783  throw e;
784  }
785 
786  try {
787  gExprDEpsPrime[row][col] = gExpr[row].diff(*gEpsPrime[col]);
788 
789  } catch (std::exception& e) {
790  silent_cerr("GiNaCViscoElasticConstitutiveLaw<T, Tder>: expression #" << row << " differentiation "
791  "wrt/ EpsPrime #" << col << "failed: "
792  << e.what() << std::endl);
793  throw e;
794  }
795  }
796  }
797 
798  silent_cout("\tGiNaCViscoElasticConstitutiveLaw:" << std::endl);
799  for (unsigned row = 0; row < dim; row++) {
800  silent_cout("\t\tEps[" << row << "]: \"" << *gEps[row] << "\"" << std::endl);
801  }
802  for (unsigned row = 0; row < dim; row++) {
803  silent_cout("\t\tEpsPrime[" << row << "]: \"" << *gEpsPrime[row] << "\"" << std::endl);
804  }
805  for (unsigned row = 0; row < dim; row++) {
806  silent_cout("\t\tConstitutive law[" << row << "]: \"" << gExpr[row] << "\"" << std::endl);
807  }
808  for (unsigned row = 0; row < dim; row++) {
809  for (unsigned col = 0; col < dim; col++) {
810  silent_cout("\t\tDer[" << row << "]/Eps[" << row << "][" << col << "]: \"" << gExprDEps[row][col] << "\"" << std::endl);
811  }
812  }
813  for (unsigned row = 0; row < dim; row++) {
814  for (unsigned col = 0; col < dim; col++) {
815  silent_cout("\t\tDer[" << row << "]/EpsPrime[" << row << "][" << col << "]: \"" << gExprDEpsPrime[row][col] << "\"" << std::endl);
816  }
817  }
818 
819  // try and evaluate the constitutive law
820  try {
822  }
823  catch (std::exception& e) {
824  silent_cerr("GiNaCViscoElasticConstitutiveLaw<T, Tder>::GiNaCViscoElasticConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
825  throw e;
826  }
827 }
828 
829 template <class T, class Tder>
831 {
832  for (unsigned row = 0; row < dim; row++) {
833  delete gEps[row];
834  delete gEpsPrime[row];
835  }
836 };
837 
838 template <class T, class Tder> ConstitutiveLaw<T, Tder>*
840 {
841  ConstitutiveLaw<T, Tder>* pCL = 0;
842 
843  std::vector<std::string> epsilon(dim);
844  std::vector<std::string> epsilonPrime(dim);
845  std::vector<std::string> expression(dim);
846 
847  for (unsigned row = 0; row < dim; row++) {
848  std::ostringstream eps;
849  std::ostringstream epsPrime;
850  std::ostringstream expr;
851 
852  eps << *gEps[row];
853  epsPrime << *gEpsPrime[row];
854  expr << gExpr[row];
855 
856  epsilon[row] = eps.str();
857  epsilonPrime[row] = epsPrime.str();
858  expression[row] = expr.str();
859  }
860 
863  cl,
866  epsilon, epsilonPrime, expression));
867 
868  return pCL;
869 }
870 
871 template <class T, class Tder> std::ostream&
873 {
874  out << "symbolic viscoelastic, epsilon";
875  for (unsigned row = 0; row < dim; row++) {
876  out << ", \"" << *gEps[row] << "\"";
877  }
878  out << "\", epsilon prime";
879  for (unsigned row = 0; row < dim; row++) {
880  out << ", \"" << *gEpsPrime[row] << "\"";
881  }
882  out << "\", expression";
883  for (unsigned row = 0; row < dim; row++) {
884  out << ", \"" << gExpr[row] << "\"";
885  }
886 
888 }
889 
890 template <class T, class Tder> void
892  const T& EpsPrime)
893 {
894  GiNaC::lst l;
895 
898 
900 
901  for (unsigned row = 0; row < dim; row++) {
902  l.append(*gEps[row] == e(row + 1));
903  l.append(*gEpsPrime[row] == EpsPrime(row + 1));
904  }
905 
907 
908  for (unsigned row = 0; row < dim; row++) {
909  GiNaC::ex f_expr = gExpr[row].subs(l);
910 
912  += GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
913 
914  for (unsigned col = 0; col < dim; col++) {
915  GiNaC::ex f_derEps = gExprDEps[row][col].subs(l);
916 
917  ConstitutiveLaw<T, Tder>::FDE(row + 1, col + 1)
918  = GiNaC::ex_to<GiNaC::numeric>(f_derEps).to_double();
919 
920  GiNaC::ex f_derEpsPrime = gExprDEpsPrime[row][col].subs(l);
921 
922  ConstitutiveLaw<T, Tder>::FDEPrime(row + 1, col + 1)
923  = GiNaC::ex_to<GiNaC::numeric>(f_derEpsPrime).to_double();
924  }
925  }
926 }
927 
928 /* specialize for scalar constitutive law */
929 
930 template <>
932 : public SymbolicViscoElasticConstitutiveLaw<doublereal, doublereal> {
933 private:
934  GiNaC::symbol gEps; /* parameter symbol */
935  GiNaC::symbol gEpsPrime; /* parameter derivative symbol */
936 
937  GiNaC::ex gExpr; /* expression */
938  GiNaC::ex gExprDEps; /* derivative */
939  GiNaC::ex gExprDEpsPrime; /* derivative */
940 
941 public:
943  const TplDriveCaller<doublereal>* pDC,
944  const doublereal& PStress,
945  std::vector<std::string>& epsilon,
946  std::vector<std::string>& epsilonPrime,
947  std::vector<std::string>& expression);
948  virtual ~GiNaCViscoElasticConstitutiveLaw(void);
949  virtual ConstitutiveLaw<doublereal, doublereal>* pCopy(void) const;
950  virtual std::ostream& Restart(std::ostream& out) const;
951  virtual void Update(const doublereal& Eps, const doublereal& EpsPrime = 0.);
952 };
953 
955  const TplDriveCaller<doublereal>* pDC,
956  const doublereal& PStress,
957  std::vector<std::string>& epsilon,
958  std::vector<std::string>& epsilonPrime,
959  std::vector<std::string>& expression)
960 : SymbolicViscoElasticConstitutiveLaw<doublereal, doublereal>(pDC, PStress, epsilon, epsilonPrime, expression),
961 gEps(epsilon[0]), gEpsPrime(epsilonPrime[0])
962 {
965 
966  GiNaC::lst l;
967 
968  l.append(gEps);
969  l.append(gEpsPrime);
970 
971  try {
972  gExpr = GiNaC::ex(expression[0], l);
973  } catch (std::exception& e) {
974  silent_cerr("GiNaCViscoElasticConstitutiveLaw<doublereal, doublereal>: expression parsing failed: " << e.what() << std::endl);
975  throw e;
976  }
977 
978  try {
979  gExprDEps = gExpr.diff(gEps);
980  } catch (std::exception& e) {
981  silent_cerr("GiNaCViscoElasticConstitutiveLaw<doublereal, doublereal>: expression differentiation wrt/ Eps failed: " << e.what() << std::endl);
982  throw e;
983  }
984 
985  try {
987  } catch (std::exception& e) {
988  silent_cerr("GiNaCViscoElasticConstitutiveLaw<doublereal, doublereal>: expression differentiation wrt/ EpsPrime failed: " << e.what() << std::endl);
989  throw e;
990  }
991 
992  silent_cout("\tGiNaCViscoElasticConstitutiveLaw:" << std::endl
993  << "\t\tEps: \"" << gEps << "\"" << std::endl
994  << "\t\tEpsPrime: \"" << gEpsPrime << "\"" << std::endl
995  << "\t\tConstitutive law: \"" << gExpr << "\"" << std::endl
996  << "\t\tDer/Eps: \"" << gExprDEps << "\"" << std::endl
997  << "\t\tDer/EpsPrime: \"" << gExprDEpsPrime << "\"" << std::endl);
998 
999  // try and evaluate the constitutive law
1000  try {
1002  }
1003  catch (std::exception& e) {
1004  silent_cerr("GiNaCViscoElasticConstitutiveLaw<doublereal, doublereal>::GiNaCViscoElasticConstitutiveLaw: Update() failed (" << e.what() << ")" << std::endl);
1005  throw e;
1006  }
1007 }
1008 
1010 {
1011  NO_OP;
1012 };
1013 
1016 {
1018 
1019  std::ostringstream eps;
1020  std::ostringstream epsPrime;
1021  std::ostringstream expr;
1022 
1023  eps << gEps;
1024  epsPrime << gEpsPrime;
1025  expr << gExpr;
1026 
1027  std::vector<std::string> epsilon;
1028  std::vector<std::string> epsilonPrime;
1029  std::vector<std::string> expression;
1030 
1031  epsilon.push_back(eps.str());
1032  epsilonPrime.push_back(epsPrime.str());
1033  expression.push_back(expr.str());
1034 
1037  cl,
1040  epsilon, epsilonPrime, expression));
1041 
1042  return pCL;
1043 }
1044 
1045 std::ostream&
1047 {
1048  out << "symbolic elastic isotropic, "
1049  << "epsilon, \"" << gEps
1050  << "epsilon prime, \"" << gEpsPrime
1051  << "\", expression, \"" << gExpr << "\"";
1052 
1053  return Restart_int(out);
1054 }
1055 
1056 void
1058  const doublereal& Eps,
1059  const doublereal& EpsPrime)
1060 {
1061  GiNaC::lst l;
1062 
1064 
1066 
1067  l.append(gEps == e);
1068 
1070 
1071  l.append(gEpsPrime == EpsPrime);
1072 
1073  GiNaC::ex f_expr = gExpr.subs(l);
1076  + GiNaC::ex_to<GiNaC::numeric>(f_expr).to_double();
1077 
1078  GiNaC::ex f_derEps = gExprDEps.subs(l);
1079  ConstitutiveLaw<doublereal, doublereal>::FDE = GiNaC::ex_to<GiNaC::numeric>(f_derEps).to_double();
1080 
1081  GiNaC::ex f_derEpsPrime = gExprDEpsPrime.subs(l);
1082  ConstitutiveLaw<doublereal, doublereal>::FDEPrime = GiNaC::ex_to<GiNaC::numeric>(f_derEpsPrime).to_double();
1083 }
1084 
1085 /* GiNaCViscoElasticConstitutiveLaw - end */
1086 
1087 #endif /* GINACCLTP_H */
1088 
virtual std::ostream & Restart(std::ostream &out) const
Definition: ginaccltp.h:520
GiNaCElasticConstitutiveLaw< Vec6, Mat6x6 > GiNaCElasticConstitutiveLaw6D
Definition: ginaccltp.h:73
std::vector< GiNaC::ex > gExpr
Definition: ginaccltp.h:699
std::vector< GiNaC::symbol * > gEps
Definition: ginaccltp.h:51
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
GiNaCViscoElasticConstitutiveLaw< Vec6, Mat6x6 > GiNaCViscoElasticConstitutiveLaw6D
Definition: ginaccltp.h:721
virtual void Update(const T &Eps, const T &=mb_zero< T >())
Definition: ginaccltp.h:891
std::vector< GiNaC::symbol * > gEpsPrime
Definition: ginaccltp.h:697
virtual ~GiNaCViscoElasticConstitutiveLaw(void)
Definition: ginaccltp.h:830
#define NO_OP
Definition: myassert.h:74
GiNaCElasticConstitutiveLaw< Vec3, Mat3x3 > GiNaCElasticConstitutiveLaw3D
Definition: ginaccltp.h:71
std::vector< GiNaC::ex > gExpr
Definition: ginaccltp.h:381
virtual std::ostream & Restart(std::ostream &out) const
Definition: ginaccltp.h:872
std::vector< GiNaC::ex > gExpr
Definition: ginaccltp.h:53
virtual std::ostream & Restart_int(std::ostream &out) const
virtual std::ostream & Restart(std::ostream &out) const
Definition: ginaccltp.h:194
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
Definition: ginaccltp.h:839
GiNaCElasticConstitutiveLaw(const TplDriveCaller< T > *pDC, const T &PStress, std::vector< std::string > &epsilon, std::vector< std::string > &expression)
Definition: ginaccltp.h:76
std::vector< std::vector< GiNaC::ex > > gExprDEpsPrime
Definition: ginaccltp.h:701
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
Definition: ginaccltp.h:492
Definition: matvec6.h:37
virtual ~GiNaCElasticConstitutiveLaw(void)
Definition: ginaccltp.h:157
GiNaCViscousConstitutiveLaw< Vec6, Mat6x6 > GiNaCViscousConstitutiveLaw6D
Definition: ginaccltp.h:400
GiNaCViscousConstitutiveLaw< Vec3, Mat3x3 > GiNaCViscousConstitutiveLaw3D
Definition: ginaccltp.h:398
virtual void Update(const T &Eps, const T &=0.)
Definition: ginaccltp.h:209
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
Definition: ginaccltp.h:165
GiNaCViscoElasticConstitutiveLaw(const TplDriveCaller< T > *pDC, const T &PStress, std::vector< std::string > &epsilon, std::vector< std::string > &epsilonPrime, std::vector< std::string > &expression)
Definition: ginaccltp.h:724
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
GiNaCViscousConstitutiveLaw(const T &PStress, std::vector< std::string > &epsilon, std::vector< std::string > &expression)
Definition: ginaccltp.h:403
std::vector< std::vector< GiNaC::ex > > gExprDEps
Definition: ginaccltp.h:700
std::vector< std::vector< GiNaC::ex > > gExprDEpsPrime
Definition: ginaccltp.h:382
GiNaCViscoElasticConstitutiveLaw< doublereal, doublereal > GiNaCViscoElasticConstitutiveLaw1D
Definition: ginaccltp.h:717
double doublereal
Definition: colamd.c:52
GiNaCElasticConstitutiveLaw< doublereal, doublereal > GiNaCElasticConstitutiveLaw1D
Definition: ginaccltp.h:69
std::vector< GiNaC::symbol * > gEpsPrime
Definition: ginaccltp.h:379
virtual void Update(const T &Eps, const T &=0.)
Definition: ginaccltp.h:535
GiNaCViscoElasticConstitutiveLaw< Vec3, Mat3x3 > GiNaCViscoElasticConstitutiveLaw3D
Definition: ginaccltp.h:719
T Get(void) const
Definition: tpldrive.h:113
std::vector< GiNaC::symbol * > gEps
Definition: ginaccltp.h:696
std::vector< std::vector< GiNaC::ex > > gExprDEps
Definition: ginaccltp.h:54
virtual ~GiNaCViscousConstitutiveLaw(void)
Definition: ginaccltp.h:484
GiNaCViscousConstitutiveLaw< doublereal, doublereal > GiNaCViscousConstitutiveLaw1D
Definition: ginaccltp.h:396