Reference documentation for deal.II version 9.6.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\}}\)
Loading...
Searching...
No Matches
symengine_math.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_differentiation_sd_symengine_math_h
16#define dealii_differentiation_sd_symengine_math_h
17
18#include <deal.II/base/config.h>
19
20#ifdef DEAL_II_WITH_SYMENGINE
21
23
24# include <type_traits>
25
27
28namespace Differentiation
29{
30 namespace SD
31 {
32 // Mathematical functions:
33 //
34 // It is necessary that all computed inputs to SymEngine functions are
35 // of type SymEngine::RCP<SymEngine::Basic>. So we instead simply offer a
36 // unified interface to Expression types and with other permutations of
37 // numbers we convert between them.
38 //
39 // For a full list of functions that we (ultimately) expect to support, see
40 // http://www.cplusplus.com/reference/cmath/. Those that are currently
41 // supported are extracted from symengine/{functions,pow}.h;
42 // symengine/type_codes.inc.
43
44
57 Expression
58 pow(const Expression &base, const Expression &exponent);
59
69 template <
70 typename NumberType,
71 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
72 Expression
73 pow(const Expression &base, const NumberType &exponent)
74 {
75 // Call other implementation
76 return pow(base, Expression(exponent));
77 }
78
88 template <
89 typename NumberType,
90 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
91 Expression
92 pow(const NumberType &base, const Expression &exponent)
93 {
94 // Call other implementation
95 return pow(Expression(base), exponent);
96 }
97
104 Expression
105 sqrt(const Expression &x);
106
113 Expression
114 cbrt(const Expression &x);
115
123 Expression
124 exp(const Expression &exponent);
125
132 Expression
133 log(const Expression &x);
134
142 Expression
143 log(const Expression &x, const Expression &base);
144
154 template <
155 typename NumberType,
156 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
157 Expression
158 log(const Expression &x, const NumberType &base)
159 {
160 // Call other implementation
161 return log(x, Expression(base));
162 }
163
173 template <
174 typename NumberType,
175 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
176 Expression
177 log(const NumberType &x, const Expression &base)
178 {
179 // Call other implementation
180 return log(Expression(x), base);
181 }
182
189 Expression
190 log10(const Expression &x);
191
206 Expression
207 sin(const Expression &x);
208
216 Expression
217 cos(const Expression &x);
218
226 Expression
227 tan(const Expression &x);
228
236 Expression
237 csc(const Expression &x);
238
246 Expression
247 sec(const Expression &x);
248
256 Expression
257 cot(const Expression &x);
258
267 Expression
268 asin(const Expression &x);
269
278 Expression
279 acos(const Expression &x);
280
289 Expression
290 atan(const Expression &x);
291
300 Expression
301 atan2(const Expression &y, const Expression &x);
302
313 template <
314 typename NumberType,
315 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
316 Expression
317 atan2(const NumberType &y, const Expression &x)
318 {
319 // Call other implementation
320 return atan2(Expression(y), x);
321 }
322
333 template <
334 typename NumberType,
335 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
336 Expression
337 atan2(const Expression &y, const NumberType &x)
338 {
339 // Call other implementation
340 return atan2(y, Expression(x));
341 }
342
351 Expression
352 acsc(const Expression &x);
353
362 Expression
363 asec(const Expression &x);
364
373 Expression
374 acot(const Expression &x);
375
391 Expression
392 sinh(const Expression &x);
393
402 Expression
403 cosh(const Expression &x);
404
413 Expression
414 tanh(const Expression &x);
415
424 Expression
425 csch(const Expression &x);
426
435 Expression
436 sech(const Expression &x);
437
446 Expression
447 coth(const Expression &x);
448
457 Expression
458 asinh(const Expression &x);
459
468 Expression
469 acosh(const Expression &x);
470
479 Expression
480 atanh(const Expression &x);
481
490 Expression
491 acsch(const Expression &x);
492
501 Expression
502 asech(const Expression &x);
503
512 Expression
513 acoth(const Expression &x);
514
528 Expression
529 abs(const Expression &x);
530
531
538 Expression
539 fabs(const Expression &x);
540
541
549 Expression
550 sign(const Expression &x);
551
552
560 Expression
561 copysign(const Expression &value, const Expression &sign);
562
563
570 Expression
571 floor(const Expression &x);
572
573
580 Expression
581 ceil(const Expression &x);
582
590 Expression
591 max(const Expression &a, const Expression &b);
592
602 template <
603 typename NumberType,
604 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
605 Expression
606 max(const Expression &a, const NumberType &b)
607 {
608 // Call other implementation
609 return max(a, Expression(b));
610 }
611
621 template <
622 typename NumberType,
623 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
624 Expression
625 max(const NumberType &a, const Expression &b)
626 {
627 // Call other implementation
628 return max(Expression(a), b);
629 }
630
638 Expression
639 min(const Expression &a, const Expression &b);
640
650 template <
651 typename NumberType,
652 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
653 Expression
654 min(const Expression &a, const NumberType &b)
655 {
656 // Call other implementation
657 return min(a, Expression(b));
658 }
659
669 template <
670 typename NumberType,
671 typename = std::enable_if_t<!std::is_same_v<NumberType, Expression>>>
672 Expression
673 min(const NumberType &a, const Expression &b)
674 {
675 // Call other implementation
676 return min(Expression(a), b);
677 }
678
686 Expression
687 erf(const Expression &x);
688
696 Expression
697 erfc(const Expression &x);
698
701 } // namespace SD
702} // namespace Differentiation
703
705
706
707# ifndef DOXYGEN
708
709// Import math operations into standard namespace.
710// This gives us the ability to use them within the Tensor class.
711namespace std
712{
717# define DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(func) \
718 using ::Differentiation::SD::func;
719
720# define DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(func) \
721 using ::Differentiation::SD::func;
722
723 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(pow)
724 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(max)
725 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(min)
726 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(copysign)
727
728 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(exp)
729 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log10)
730 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sqrt)
731 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cbrt)
732 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erf)
733 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erfc)
734 // Note: Both unary and binary versions
735 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log)
736
737 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(abs)
738 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(fabs)
739 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sign)
740 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(floor)
741 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(ceil)
742
743 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sin)
744 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cos)
745 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tan)
746 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csc)
747 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sec)
748 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cot)
749
750 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asin)
751 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acos)
752 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atan)
753 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(atan2)
754 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsc)
755 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asec)
756 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acot)
757
758 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sinh)
759 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cosh)
760 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tanh)
761 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csch)
762 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sech)
763 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(coth)
764
765 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asinh)
766 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acosh)
767 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atanh)
768 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsch)
769 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asech)
770 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acoth)
771
772# undef DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION
773# undef DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION
774
775} // namespace std
776
777# endif // DOXYGEN
778
779#endif // DEAL_II_WITH_SYMENGINE
780
781#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
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 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 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)
STL namespace.
inline ::VectorizedArray< Number, width > acosh(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > exp(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > tan(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > asinh(const ::VectorizedArray< Number, width > &x)
inline ::VectorizedArray< Number, width > tanh(const ::VectorizedArray< Number, width > &x)
inline ::VectorizedArray< Number, width > sinh(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > cosh(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
inline ::VectorizedArray< Number, width > atanh(const ::VectorizedArray< Number, width > &x)
inline ::VectorizedArray< Number, width > atan(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > acos(const ::VectorizedArray< Number, width > &x)
inline ::VectorizedArray< Number, width > asin(const ::VectorizedArray< Number, width > &x)