| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2017 - 2025 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_ad_adolc_math_h |
| 16 |
#define dealii_differentiation_ad_adolc_math_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#ifdef DEAL_II_WITH_ADOLC |
| 21 |
|
| 22 |
# include <adolc/adouble.h> // Taped double |
| 23 |
# include <adolc/adtl.h> // Tapeless double |
| 24 |
# include <adolc/internal/adolc_settings.h> |
| 25 |
# include <adolc/internal/adubfunc.h> // Taped double math functions |
| 26 |
|
| 27 |
# include <cmath> |
| 28 |
|
| 29 |
|
| 30 |
# ifndef DOXYGEN |
| 31 |
|
| 32 |
DEAL_II_NAMESPACE_OPEN |
| 33 |
/** |
| 34 |
* Implementation of the complementary error function for adol-c adouble |
| 35 |
* numbers. |
| 36 |
*/ |
| 37 |
# ifdef DEAL_II_ADOLC_WITH_ATRIG_ERF |
| 38 |
inline adouble |
| 39 |
erfc(const adouble &x) |
| 40 |
{ |
| 41 |
// Make things work with AD types |
| 42 |
using std::erf; |
| 43 |
return 1.0 - erf(x); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Implementation of the complementary error function for adol-c adtl::adouble |
| 48 |
* numbers. |
| 49 |
*/ |
| 50 |
inline adtl::adouble |
| 51 |
erfc(const adtl::adouble &x) |
| 52 |
{ |
| 53 |
// Make things work with AD types |
| 54 |
using std::erf; |
| 55 |
return 1.0 - erf(x); |
| 56 |
} |
| 57 |
# endif |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* For improved genericity, implement abs() in terms of fabs() for adouble. |
| 62 |
*/ |
| 63 |
inline adouble |
| 64 |
abs(const adouble &x) |
| 65 |
{ |
| 66 |
return fabs(static_cast<const badouble &>(x)); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Same idea: implement abs() in terms of adtl::fabs(). |
| 71 |
*/ |
| 72 |
inline adtl::adouble |
| 73 |
abs(const adtl::adouble &x) |
| 74 |
{ |
| 75 |
return adtl::fabs(x); |
| 76 |
} |
| 77 |
|
| 78 |
DEAL_II_NAMESPACE_CLOSE |
| 79 |
# endif // DOXYGEN |
| 80 |
|
| 81 |
#else |
| 82 |
|
| 83 |
// Make sure the scripts that create the C++20 module input files have |
| 84 |
// something to latch on if the preprocessor #ifdef above would |
| 85 |
// otherwise lead to an empty content of the file. |
| 86 |
DEAL_II_NAMESPACE_OPEN |
| 87 |
DEAL_II_NAMESPACE_CLOSE |
| 88 |
|
| 89 |
#endif // DEAL_II_WITH_ADOLC |
| 90 |
|
| 91 |
#endif |