Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
symengine_math.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 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 
23 # include <deal.II/differentiation/sd/symengine_number_types.h>
24 
25 # include <type_traits>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 namespace Differentiation
30 {
31  namespace SD
32  {
51 
60  pow(const Expression &base, const Expression &exponent);
61 
71  template <typename NumberType,
72  typename = typename std::enable_if<
73  !std::is_same<NumberType, Expression>::value>::type>
75  pow(const Expression &base, const NumberType &exponent)
76  {
77  // Call other implementation
78  return pow(base, Expression(exponent));
79  }
80 
90  template <typename NumberType,
91  typename = typename std::enable_if<
92  !std::is_same<NumberType, Expression>::value>::type>
93  Expression
94  pow(const NumberType &base, const Expression &exponent)
95  {
96  // Call other implementation
97  return pow(Expression(base), exponent);
98  }
99 
106  Expression
107  sqrt(const Expression &x);
108 
115  Expression
116  cbrt(const Expression &x);
117 
125  Expression
126  exp(const Expression &exponent);
127 
134  Expression
135  log(const Expression &x);
136 
144  Expression
145  log(const Expression &x, const Expression &base);
146 
156  template <typename NumberType,
157  typename = typename std::enable_if<
158  !std::is_same<NumberType, Expression>::value>::type>
159  Expression
160  log(const Expression &x, const NumberType &base)
161  {
162  // Call other implementation
163  return log(x, Expression(base));
164  }
165 
175  template <typename NumberType,
176  typename = typename std::enable_if<
177  !std::is_same<NumberType, Expression>::value>::type>
178  Expression
179  log(const NumberType &x, const Expression &base)
180  {
181  // Call other implementation
182  return log(Expression(x), base);
183  }
184 
191  Expression
192  log10(const Expression &x);
193 
195 
200 
208  Expression
209  sin(const Expression &x);
210 
218  Expression
219  cos(const Expression &x);
220 
228  Expression
229  tan(const Expression &x);
230 
238  Expression
239  csc(const Expression &x);
240 
248  Expression
249  sec(const Expression &x);
250 
258  Expression
259  cot(const Expression &x);
260 
269  Expression
270  asin(const Expression &x);
271 
280  Expression
281  acos(const Expression &x);
282 
291  Expression
292  atan(const Expression &x);
293 
302  Expression
303  atan2(const Expression &y, const Expression &x);
304 
315  template <typename NumberType,
316  typename = typename std::enable_if<
317  !std::is_same<NumberType, Expression>::value>::type>
318  Expression
319  atan2(const NumberType &y, const Expression &x)
320  {
321  // Call other implementation
322  return atan2(Expression(y), x);
323  }
324 
335  template <typename NumberType,
336  typename = typename std::enable_if<
337  !std::is_same<NumberType, Expression>::value>::type>
338  Expression
339  atan2(const Expression &y, const NumberType &x)
340  {
341  // Call other implementation
342  return atan2(y, Expression(x));
343  }
344 
353  Expression
354  acsc(const Expression &x);
355 
364  Expression
365  asec(const Expression &x);
366 
375  Expression
376  acot(const Expression &x);
377 
379 
384 
393  Expression
394  sinh(const Expression &x);
395 
404  Expression
405  cosh(const Expression &x);
406 
415  Expression
416  tanh(const Expression &x);
417 
426  Expression
427  csch(const Expression &x);
428 
437  Expression
438  sech(const Expression &x);
439 
448  Expression
449  coth(const Expression &x);
450 
459  Expression
460  asinh(const Expression &x);
461 
470  Expression
471  acosh(const Expression &x);
472 
481  Expression
482  atanh(const Expression &x);
483 
492  Expression
493  acsch(const Expression &x);
494 
503  Expression
504  asech(const Expression &x);
505 
514  Expression
515  acoth(const Expression &x);
516 
518 
523 
530  Expression
531  abs(const Expression &x);
532 
533 
540  Expression
541  fabs(const Expression &x);
542 
543 
551  Expression
552  sign(const Expression &x);
553 
554 
562  Expression
563  copysign(const Expression &value, const Expression &sign);
564 
565 
572  Expression
573  floor(const Expression &x);
574 
575 
582  Expression
583  ceil(const Expression &x);
584 
592  Expression
593  max(const Expression &a, const Expression &b);
594 
604  template <typename NumberType,
605  typename = typename std::enable_if<
606  !std::is_same<NumberType, Expression>::value>::type>
607  Expression
608  max(const Expression &a, const NumberType &b)
609  {
610  // Call other implementation
611  return max(a, Expression(b));
612  }
613 
623  template <typename NumberType,
624  typename = typename std::enable_if<
625  !std::is_same<NumberType, Expression>::value>::type>
626  Expression
627  max(const NumberType &a, const Expression &b)
628  {
629  // Call other implementation
630  return max(Expression(a), b);
631  }
632 
640  Expression
641  min(const Expression &a, const Expression &b);
642 
652  template <typename NumberType,
653  typename = typename std::enable_if<
654  !std::is_same<NumberType, Expression>::value>::type>
655  Expression
656  min(const Expression &a, const NumberType &b)
657  {
658  // Call other implementation
659  return min(a, Expression(b));
660  }
661 
671  template <typename NumberType,
672  typename = typename std::enable_if<
673  !std::is_same<NumberType, Expression>::value>::type>
674  Expression
675  min(const NumberType &a, const Expression &b)
676  {
677  // Call other implementation
678  return min(Expression(a), b);
679  }
680 
688  Expression
689  erf(const Expression &x);
690 
698  Expression
699  erfc(const Expression &x);
700 
702 
703  } // namespace SD
704 } // namespace Differentiation
705 
706 DEAL_II_NAMESPACE_CLOSE
707 
708 
709 # ifndef DOXYGEN
710 
711 // Import math operations into standard namespace.
712 // This gives us the ability to use them within the Tensor class.
713 namespace std
714 {
719 # define DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(func) \
720  using ::Differentiation::SD::func;
721 
722 # define DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(func) \
723  using ::Differentiation::SD::func;
724 
725  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(pow)
726  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(max)
727  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(min)
728  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(copysign)
729 
730  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(exp)
731  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log10)
732  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sqrt)
733  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cbrt)
734  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erf)
735  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erfc)
736  // Note: Both unary and binary versions
737  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log)
738 
739  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(abs)
740  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(fabs)
741  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sign)
742  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(floor)
743  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(ceil)
744 
745  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sin)
746  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cos)
747  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tan)
748  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csc)
749  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sec)
750  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cot)
751 
752  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asin)
753  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acos)
754  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atan)
755  DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(atan2)
756  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsc)
757  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asec)
758  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acot)
759 
760  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sinh)
761  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cosh)
762  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tanh)
763  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csch)
764  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sech)
765  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(coth)
766 
767  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asinh)
768  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acosh)
769  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atanh)
770  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsch)
771  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asech)
772  DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acoth)
773 
774 # undef DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION
775 # undef DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION
776 
777 } // namespace std
778 
779 # endif // DOXYGEN
780 
781 #endif // DEAL_II_WITH_SYMENGINE
782 
783 #endif
Expression copysign(const Expression &value, const Expression &sign)
Expression sign(const Expression &x)
Expression asinh(const Expression &x)
Expression cosh(const Expression &x)
Expression acoth(const Expression &x)
Expression pow(const Expression &base, const Expression &exponent)
Expression log10(const Expression &x)
Expression sinh(const Expression &x)
Expression asec(const Expression &x)
Expression atan2(const Expression &y, const Expression &x)
Expression cot(const Expression &x)
Expression max(const Expression &a, const Expression &b)
Expression csc(const Expression &x)
STL namespace.
Expression atanh(const Expression &x)
Expression asech(const Expression &x)
Expression cbrt(const Expression &x)
Expression tanh(const Expression &x)
Expression ceil(const Expression &x)
Expression sqrt(const Expression &x)
Expression acos(const Expression &x)
Expression coth(const Expression &x)
Expression exp(const Expression &exponent)
Expression sech(const Expression &x)
Expression log(const Expression &x)
Expression fabs(const Expression &x)
Expression cos(const Expression &x)
Expression sin(const Expression &x)
Expression erfc(const Expression &x)
Expression asin(const Expression &x)
Expression tan(const Expression &x)
Expression erf(const Expression &x)
Expression abs(const Expression &x)
Expression acsc(const Expression &x)
Expression min(const Expression &a, const Expression &b)
Expression acsch(const Expression &x)
Expression acosh(const Expression &x)
Expression csch(const Expression &x)
Expression acot(const Expression &x)
Expression atan(const Expression &x)
Expression sec(const Expression &x)
Expression floor(const Expression &x)