Reference documentation for deal.II version GIT edc7d5c3ce 2023-09-25 07:10:03+00:00
\(\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 - 2022 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 
59  pow(const Expression &base, const Expression &exponent);
60 
70  template <
71  typename NumberType,
72  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
74  pow(const Expression &base, const NumberType &exponent)
75  {
76  // Call other implementation
77  return pow(base, Expression(exponent));
78  }
79 
89  template <
90  typename NumberType,
91  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
156  typename NumberType,
157  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
175  typename NumberType,
176  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 
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 <
315  typename NumberType,
316  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
335  typename NumberType,
336  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 
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 
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 <
604  typename NumberType,
605  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
623  typename NumberType,
624  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
652  typename NumberType,
653  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 <
671  typename NumberType,
672  typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
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 
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
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
Expression cbrt(const Expression &x)
Expression atanh(const Expression &x)
Expression atan2(const Expression &y, const Expression &x)
Expression asin(const Expression &x)
Expression asinh(const Expression &x)
Expression cosh(const Expression &x)
Expression csc(const Expression &x)
Expression min(const NumberType &a, const Expression &b)
Expression log(const NumberType &x, const Expression &base)
Expression max(const NumberType &a, const Expression &b)
Expression atan2(const Expression &y, const NumberType &x)
Expression acsch(const Expression &x)
Expression abs(const Expression &x)
Expression fabs(const Expression &x)
Expression ceil(const Expression &x)
Expression coth(const Expression &x)
Expression sinh(const Expression &x)
Expression sec(const Expression &x)
Expression atan(const Expression &x)
Expression floor(const Expression &x)
Expression tanh(const Expression &x)
Expression acsc(const Expression &x)
Expression sin(const Expression &x)
Expression max(const Expression &a, const Expression &b)
Expression erfc(const Expression &x)
Expression exp(const Expression &exponent)
Expression asech(const Expression &x)
Expression pow(const Expression &base, const Expression &exponent)
Expression sign(const Expression &x)
Expression sech(const Expression &x)
Expression acos(const Expression &x)
Expression csch(const Expression &x)
Expression tan(const Expression &x)
Expression acosh(const Expression &x)
Expression pow(const NumberType &base, const Expression &exponent)
Expression min(const Expression &a, const Expression &b)
Expression asec(const Expression &x)
Expression cot(const Expression &x)
Expression cos(const Expression &x)
Expression erf(const Expression &x)
Expression acoth(const Expression &x)
Expression acot(const Expression &x)
Expression log(const Expression &x)
Expression sqrt(const Expression &x)
Expression log10(const Expression &x)
Expression copysign(const Expression &value, const Expression &sign)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)