deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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\}}\)
Loading...
Searching...
No Matches
symengine_math.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_differentiation_sd_symengine_math_h
14#define dealii_differentiation_sd_symengine_math_h
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_SYMENGINE
19
21
22# include <type_traits>
23
24#endif // DEAL_II_WITH_SYMENGINE
25
27
28#ifdef DEAL_II_WITH_SYMENGINE
29namespace 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
58 Expression
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>>>
73 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
705#endif // DEAL_II_WITH_SYMENGINE
706
707// Close the dealii namespace, but do not close the export{} block yet if we
708// are building C++20 modules:
709DEAL_II_NAMESPACE_CLOSE // Do not convert for module purposes
710
711
712#ifdef DEAL_II_WITH_SYMENGINE
713
714# ifndef DOXYGEN
715
716 // Import math operations into standard namespace.
717 // This gives us the ability to use them within the Tensor class.
718 namespace std
719{
724# define DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(func) \
725 using ::Differentiation::SD::func;
726
727# define DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(func) \
728 using ::Differentiation::SD::func;
729
730 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(pow)
731 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(max)
732 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(min)
733 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(copysign)
734
735 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(exp)
736 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log10)
737 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sqrt)
738 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cbrt)
739 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erf)
740 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(erfc)
741 // Note: Both unary and binary versions
742 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(log)
743
744 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(abs)
745 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(fabs)
746 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sign)
747 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(floor)
748 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(ceil)
749
750 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sin)
751 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cos)
752 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tan)
753 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csc)
754 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sec)
755 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cot)
756
757 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asin)
758 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acos)
759 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atan)
760 DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION(atan2)
761 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsc)
762 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asec)
763 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acot)
764
765 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sinh)
766 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(cosh)
767 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(tanh)
768 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(csch)
769 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(sech)
770 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(coth)
771
772 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asinh)
773 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acosh)
774 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(atanh)
775 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acsch)
776 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(asech)
777 DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION(acoth)
778
779# undef DEAL_II_EXPOSE_SYMENGINE_BINARY_MATH_FUNCTION
780# undef DEAL_II_EXPOSE_SYMENGINE_UNARY_MATH_FUNCTION
781
782} // namespace std
783
784# endif // DOXYGEN
785
786#endif // DEAL_II_WITH_SYMENGINE
787
788// Re-open and then close the namespace, and this time also close the
789// export{} block if we are building C++20 modules:
790DEAL_II_NAMESPACE_OPEN // Do not convert for module purposes
792
793#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
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)