Skip to content

Commit

Permalink
Implementation of Bessel functions of second kind (yn) (AMReX-Codes#4234
Browse files Browse the repository at this point in the history
)

## Summary
This merge request adds support for the Bessel function of the second
kind (Yn) to the AMReX parser. The implementation allows users to
evaluate the Yn(x) function directly in runtime expressions, enhancing
the mathematical capabilities of AMReX.

## Additional background
The Bessel function of the second kind is widely used in solving partial
differential equations, particularly in problems involving cylindrical
or spherical symmetry. Adding this function expands the parser's
usability in scientific and engineering applications where such
functions are essential. The implementation leverages standard
mathematical libraries for accurate computation.
  • Loading branch information
aliciaroblesp authored Nov 18, 2024
1 parent 456c93c commit 4210fe0
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Docs/sphinx_documentation/source/Basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ numbers can be computed with ``min`` and ``max``, respectively. It supports
the Heaviside step function, ``heaviside(x1,x2)`` that gives ``0``, ``x2``,
``1``, for ``x1 < 0``, ``x1 = 0`` and ``x1 > 0``, respectively.
It supports the Bessel function of the first kind of order ``n``
``jn(n,x)``. Complete elliptic integrals of the first and second kind, ``comp_ellint_1(k)`` and ``comp_ellint_2(k)``,
``jn(n,x)``, and the Bessel function of the second kind of order ``n`` ``yn(n,x)``. Complete elliptic integrals of the first and second kind, ``comp_ellint_1(k)`` and ``comp_ellint_2(k)``,
are supported.
There is ``if(a,b,c)`` that gives ``b`` or ``c`` depending on the value of
``a``. A number of comparison operators are supported, including ``<``,
Expand Down
19 changes: 19 additions & 0 deletions Src/Base/Parser/AMReX_Parser_Y.H
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum parser_f2_t { // Built-in functions with two arguments
PARSER_OR,
PARSER_HEAVISIDE,
PARSER_JN,
PARSER_YN,
PARSER_MIN,
PARSER_MAX,
PARSER_FMOD
Expand All @@ -116,6 +117,7 @@ std::string_view parser_f2_s[] =
"or",
"heaviside",
"jn",
"yn",
"min",
"max",
"fmod"
Expand Down Expand Up @@ -400,6 +402,21 @@ T parser_math_jn (int a, T b)
#endif
}

template <typename T>
AMREX_GPU_HOST_DEVICE AMREX_NO_INLINE
T parser_math_yn (int a, T b)
{
#if defined AMREX_USE_SYCL || defined __MINGW32__
amrex::ignore_unused(a,b);
// neither yn(f) nor std::cyl_bessel_y work yet
// https://github.com/oneapi-src/oneAPI-spec/issues/308
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(false, "parser: yn in SYCL not supported yet");
return 0.0;
#else
return yn(a, b);
#endif
}

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double
parser_call_f1 (enum parser_f1_t type, double a)
{
Expand Down Expand Up @@ -460,6 +477,8 @@ parser_call_f2 (enum parser_f2_t type, double a, double b)
return (a < 0.0) ? 0.0 : ((a > 0.0) ? 1.0 : b);
case PARSER_JN:
return parser_math_jn<double>(int(a),b);
case PARSER_YN:
return parser_math_yn<double>(int(a),b);
case PARSER_MIN:
return (a < b) ? a : b;
case PARSER_MAX:
Expand Down
1 change: 1 addition & 0 deletions Src/Base/Parser/amrex_parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ EXP ([Ee][-+]?[0-9]+)
"pow" { amrex_parserlval.f2 = amrex::PARSER_POW; return F2; }
"heaviside" { amrex_parserlval.f2 = amrex::PARSER_HEAVISIDE; return F2; }
"jn" { amrex_parserlval.f2 = amrex::PARSER_JN; return F2; }
"yn" { amrex_parserlval.f2 = amrex::PARSER_YN; return F2; }
"min" { amrex_parserlval.f2 = amrex::PARSER_MIN; return F2; }
"max" { amrex_parserlval.f2 = amrex::PARSER_MAX; return F2; }
"fmod" { amrex_parserlval.f2 = amrex::PARSER_FMOD; return F2; }
Expand Down
Loading

0 comments on commit 4210fe0

Please sign in to comment.