Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
symengine_math.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_differentiation_sd_symengine_math_h
17 #define dealii_differentiation_sd_symengine_math_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_SYMENGINE
22 
24 
25 # include <type_traits>
26 
28 
29 namespace Differentiation
30 {
31  namespace SD
32  {
33  // Mathematical functions:
34  //
35  // It is necessary that all computed inputs to SymEngine functions are
36  // of type SymEngine::RCP<SymEngine::Basic>. So we instead simply offer a
37  // unified interface to Expression types and with other permutations of
38  // numbers we convert between them.
39  //
40  // For a full list of functions that we (ultimately) expect to support, see
41  // http://www.cplusplus.com/reference/cmath/. Those that are currently
42  // supported are extracted from symengine/{functions,pow}.h;
43  // symengine/type_codes.inc.
44 
45 
50 
59  pow(const Expression &base, const Expression &exponent);
60 
70  template <typename NumberType,
71  typename = typename std::enable_if<
74  pow(const Expression &base, const NumberType &exponent)
75  {
76  // Call other implementation
77  return pow(base, Expression(exponent));
78  }
79 
89  template <typename NumberType,
90  typename = typename std::enable_if<
92  Expression
93  pow(const NumberType &base, const Expression &exponent)
94  {
95  // Call other implementation
96  return pow(Expression(base), exponent);
97  }
98 
105  Expression
106  sqrt(const Expression &x);
107 
114  Expression
115  cbrt(const Expression &x);
116 
124  Expression
125  exp(const Expression &exponent);
126 
133  Expression
134  log(const Expression &x);
135 
143  Expression
144  log(const Expression &x, const Expression &base);
145 
155  template <typename NumberType,
156  typename = typename std::enable_if<
158  Expression
159  log(const Expression &x, const NumberType &base)
160  {
161  // Call other implementation
162  return log(x, Expression(base));
163  }
164 
174  template <typename NumberType,
175  typename = typename std::enable_if<
177  Expression
178  log(const NumberType &x, const Expression &base)
179  {
180  // Call other implementation
181  return log(Expression(x), base);
182  }
183 
190  Expression
191  log10(const Expression &x);
192 
194 
199 
207  Expression
208  sin(const Expression &x);
209 
217  Expression
218  cos(const Expression &x);
219 
227  Expression
228  tan(const Expression &x);
229 
237  Expression
238  csc(const Expression &x);
239 
247  Expression
248  sec(const Expression &x);
249 
257  Expression
258  cot(const Expression &x);
259 
268  Expression
269  asin(const Expression &x);
270 
279  Expression
280  acos(const Expression &x);
281 
290  Expression
291  atan(const Expression &x);
292 
301  Expression
302  atan2(const Expression &y, const Expression &x);
303 
314  template <typename NumberType,
315  typename = typename std::enable_if<
317  Expression
318  atan2(const NumberType &y, const Expression &x)
319  {
320  // Call other implementation
321  return atan2(Expression(y), x);
322  }
323 
334  template <typename NumberType,
335  typename = typename std::enable_if<
337  Expression
338  atan2(const Expression &y, const NumberType &x)
339  {
340  // Call other implementation
341  return atan2(y, Expression(x));
342  }
343 
352  Expression
353  acsc(const Expression &x);
354 
363  Expression
364  asec(const Expression &x);
365 
374  Expression
375  acot(const Expression &x);
376 
378 
383 
392  Expression
393  sinh(const Expression &x);
394 
403  Expression
404  cosh(const Expression &x);
405 
414  Expression
415  tanh(const Expression &x);
416 
425  Expression
426  csch(const Expression &x);
427 
436  Expression
437  sech(const Expression &x);
438 
447  Expression
448  coth(const Expression &x);
449 
458  Expression
459  asinh(const Expression &x);
460 
469  Expression
470  acosh(const Expression &x);
471 
480  Expression
481  atanh(const Expression &x);
482 
491  Expression
492  acsch(const Expression &x);
493 
502  Expression
503  asech(const Expression &x);
504 
513  Expression
514  acoth(const Expression &x);
515 
517 
522 
529  Expression
530  abs(const Expression &x);
531 
532 
539  Expression
540  fabs(const Expression &x);
541 
542 
550  Expression
551  sign(const Expression &x);
552 
553 
561  Expression
562  copysign(const Expression &value, const Expression &sign);
563 
564 
571  Expression
572  floor(const Expression &x);
573 
574 
581  Expression
582  ceil(const Expression &x);
583 
591  Expression
592  max(const Expression &a, const Expression &b);
593 
603  template <typename NumberType,
604  typename = typename std::enable_if<
606  Expression
607  max(const Expression &a, const NumberType &b)
608  {
609  // Call other implementation
610  return max(a, Expression(b));
611  }
612 
622  template <typename NumberType,
623  typename = typename std::enable_if<
625  Expression
626  max(const NumberType &a, const Expression &b)
627  {
628  // Call other implementation
629  return max(Expression(a), b);
630  }
631 
639  Expression
640  min(const Expression &a, const Expression &b);
641 
651  template <typename NumberType,
652  typename = typename std::enable_if<
654  Expression
655  min(const Expression &a, const NumberType &b)
656  {
657  // Call other implementation
658  return min(a, Expression(b));
659  }
660 
670  template <typename NumberType,
671  typename = typename std::enable_if<
673  Expression
674  min(const NumberType &a, const Expression &b)
675  {
676  // Call other implementation
677  return min(Expression(a), b);
678  }
679 
687  Expression
688  erf(const Expression &x);
689 
697  Expression
698  erfc(const Expression &x);
699 
701 
702  } // namespace SD
703 } // namespace Differentiation
704 
706 
707 
708 # ifndef DOXYGEN
709 
710 // Import math operations into standard namespace.
711 // This gives us the ability to use them within the Tensor class.
712 namespace std
713 {
718 # define DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(func) \
719  using ::Differentiation::SD::func;
720 
721 # define DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(func) \
722  using ::Differentiation::SD::func;
723 
724  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(pow)
725  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(max)
726  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(min)
727  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(copysign)
728 
729  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(exp)
730  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log10)
731  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sqrt)
732  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cbrt)
733  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erf)
734  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erfc)
735  // Note: Both unary and binary versions
736  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log)
737 
738  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(abs)
739  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(fabs)
740  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sign)
741  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(floor)
742  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(ceil)
743 
744  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sin)
745  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cos)
746  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tan)
747  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csc)
748  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sec)
749  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cot)
750 
751  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asin)
752  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acos)
753  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atan)
754  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(atan2)
755  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsc)
756  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asec)
757  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acot)
758 
759  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sinh)
760  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cosh)
761  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tanh)
762  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csch)
763  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sech)
764  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(coth)
765 
766  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asinh)
767  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acosh)
768  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atanh)
769  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsch)
770  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asech)
771  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acoth)
772 
773 # undef DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION
774 # undef DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION
775 
776 } // namespace std
777 
778 # endif // DOXYGEN
779 
780 #endif // DEAL_II_WITH_SYMENGINE
781 
782 #endif
Differentiation::SD::floor
Expression floor(const Expression &x)
Definition: symengine_math.cc:294
Differentiation::SD::csch
Expression csch(const Expression &x)
Definition: symengine_math.cc:203
Differentiation::SD::atan2
Expression atan2(const Expression &y, const NumberType &x)
Definition: symengine_math.h:338
Differentiation::SD::copysign
Expression copysign(const Expression &value, const Expression &sign)
Definition: symengine_math.cc:287
Differentiation::SD::coth
Expression coth(const Expression &x)
Definition: symengine_math.cc:217
Differentiation::SD::atanh
Expression atanh(const Expression &x)
Definition: symengine_math.cc:238
Differentiation::SD::atan
Expression atan(const Expression &x)
Definition: symengine_math.cc:147
Differentiation::SD::erfc
Expression erfc(const Expression &x)
Definition: symengine_math.cc:329
Differentiation::SD::tanh
Expression tanh(const Expression &x)
Definition: symengine_math.cc:196
Differentiation::SD::erf
Expression erf(const Expression &x)
Definition: symengine_math.cc:322
Differentiation::SD::acoth
Expression acoth(const Expression &x)
Definition: symengine_math.cc:259
Differentiation::SD::sech
Expression sech(const Expression &x)
Definition: symengine_math.cc:210
Differentiation::SD::csc
Expression csc(const Expression &x)
Definition: symengine_math.cc:112
Differentiation::SD::asinh
Expression asinh(const Expression &x)
Definition: symengine_math.cc:224
Differentiation::SD::pow
Expression pow(const NumberType &base, const Expression &exponent)
Definition: symengine_math.h:93
Differentiation::SD::sinh
Expression sinh(const Expression &x)
Definition: symengine_math.cc:182
Differentiation::SD::cosh
Expression cosh(const Expression &x)
Definition: symengine_math.cc:189
symengine_number_types.h
Differentiation::SD::fabs
Expression fabs(const Expression &x)
Definition: symengine_math.cc:273
Differentiation::SD::max
Expression max(const Expression &a, const Expression &b)
Definition: symengine_math.cc:308
Differentiation::SD::log
Expression log(const NumberType &x, const Expression &base)
Definition: symengine_math.h:178
Differentiation::SD::atan2
Expression atan2(const Expression &y, const Expression &x)
Definition: symengine_math.cc:154
Differentiation::SD::min
Expression min(const Expression &a, const Expression &b)
Definition: symengine_math.cc:315
Differentiation::SD::asech
Expression asech(const Expression &x)
Definition: symengine_math.cc:252
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Differentiation
Definition: numbers.h:645
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Differentiation::SD::acot
Expression acot(const Expression &x)
Definition: symengine_math.cc:175
Differentiation::SD::abs
Expression abs(const Expression &x)
Definition: symengine_math.cc:266
Differentiation::SD::sin
Expression sin(const Expression &x)
Definition: symengine_math.cc:91
Differentiation::SD::max
Expression max(const NumberType &a, const Expression &b)
Definition: symengine_math.h:626
Differentiation::SD::cot
Expression cot(const Expression &x)
Definition: symengine_math.cc:126
Differentiation::SD::Expression
Definition: symengine_number_types.h:179
Differentiation::SD::ceil
Expression ceil(const Expression &x)
Definition: symengine_math.cc:301
Differentiation::SD::acosh
Expression acosh(const Expression &x)
Definition: symengine_math.cc:231
Differentiation::SD::sqrt
Expression sqrt(const Expression &x)
Definition: symengine_math.cc:49
value
static const bool value
Definition: dof_tools_constraints.cc:433
Differentiation::SD::pow
Expression pow(const Expression &base, const Expression &exponent)
Definition: symengine_math.cc:42
Differentiation::SD::asec
Expression asec(const Expression &x)
Definition: symengine_math.cc:168
Differentiation::SD::cbrt
Expression cbrt(const Expression &x)
Definition: symengine_math.cc:56
Differentiation::SD::min
Expression min(const NumberType &a, const Expression &b)
Definition: symengine_math.h:674
Differentiation::SD::log
Expression log(const Expression &x)
Definition: symengine_math.cc:70
config.h
Differentiation::SD::sign
Expression sign(const Expression &x)
Definition: symengine_math.cc:280
Differentiation::SD::acsc
Expression acsc(const Expression &x)
Definition: symengine_math.cc:161
Differentiation::SD::acos
Expression acos(const Expression &x)
Definition: symengine_math.cc:140
Differentiation::SD::cos
Expression cos(const Expression &x)
Definition: symengine_math.cc:98
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Differentiation::SD::log10
Expression log10(const Expression &x)
Definition: symengine_math.cc:84
Differentiation::SD::sec
Expression sec(const Expression &x)
Definition: symengine_math.cc:119
Differentiation::SD::tan
Expression tan(const Expression &x)
Definition: symengine_math.cc:105
Differentiation::SD::exp
Expression exp(const Expression &exponent)
Definition: symengine_math.cc:63
Differentiation::SD::asin
Expression asin(const Expression &x)
Definition: symengine_math.cc:133
Differentiation::SD::acsch
Expression acsch(const Expression &x)
Definition: symengine_math.cc:245