Skip to content

Commit 80447f9

Browse files
committed
Add Bessel functions of second kind (yn)
Sync with AMReX-Codes/amrex#4234.
1 parent 07f9857 commit 80447f9

File tree

4 files changed

+147
-120
lines changed

4 files changed

+147
-120
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ in the form of string. It supports `+`, `-`, `*`, `/`, `**` (power), `^`
2020
can be computed with `min` and `max`, respectively. It supports the
2121
Heaviside step function, `heaviside(x1,x2)` that gives `0`, `x2`, `1`, for
2222
`x1 < 0`, `x1 = 0` and `x1 > 0`, respectively. It supports the Bessel
23-
function of the first kind of order `n` `jn(n,x)`. Complete elliptic
23+
function of the first kind of order `n` `jn(n,x)`, and the Bessel function
24+
of the second kind of order ``n`` ``yn(n,x)``. Complete elliptic
2425
integrals of the first and second kind, `comp_ellint_1(k)` and
2526
`comp_ellint_2(k)`, are supported. There is `if(a,b,c)` that gives `b` or
2627
`c` depending on the value of `a`. A number of comparison operators are

Src/amrexpr_Parser_Y.H

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ enum parser_f2_t { // Built-in functions with two arguments
9090
PARSER_OR,
9191
PARSER_HEAVISIDE,
9292
PARSER_JN,
93+
PARSER_YN,
9394
PARSER_MIN,
9495
PARSER_MAX,
9596
PARSER_FMOD
@@ -115,6 +116,7 @@ std::string_view parser_f2_s[] =
115116
"or",
116117
"heaviside",
117118
"jn",
119+
"yn",
118120
"min",
119121
"max",
120122
"fmod"
@@ -399,6 +401,21 @@ T parser_math_jn (int a, T b)
399401
#endif
400402
}
401403

404+
template <typename T>
405+
AMREXPR_GPU_HOST_DEVICE AMREXPR_NO_INLINE
406+
T parser_math_yn (int a, T b)
407+
{
408+
#if defined AMREXPR_USE_SYCL || defined __MINGW32__
409+
amrex::ignore_unused(a,b);
410+
// neither yn(f) nor std::cyl_bessel_y work yet
411+
// https://github.com/oneapi-src/oneAPI-spec/issues/308
412+
AMREXPR_ALWAYS_ASSERT_WITH_MESSAGE(false, "parser: yn in SYCL not supported yet");
413+
return 0.0;
414+
#else
415+
return yn(a, b);
416+
#endif
417+
}
418+
402419
AMREXPR_GPU_HOST_DEVICE AMREXPR_FORCE_INLINE double
403420
parser_call_f1 (enum parser_f1_t type, double a)
404421
{
@@ -459,6 +476,8 @@ parser_call_f2 (enum parser_f2_t type, double a, double b)
459476
return (a < 0.0) ? 0.0 : ((a > 0.0) ? 1.0 : b);
460477
case PARSER_JN:
461478
return parser_math_jn<double>(int(a),b);
479+
case PARSER_YN:
480+
return parser_math_yn<double>(int(a),b);
462481
case PARSER_MIN:
463482
return (a < b) ? a : b;
464483
case PARSER_MAX:

Src/amrexpr_parser.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ EXP ([Ee][-+]?[0-9]+)
7070
"pow" { amrexpr_parserlval.f2 = amrexpr::PARSER_POW; return F2; }
7171
"heaviside" { amrexpr_parserlval.f2 = amrexpr::PARSER_HEAVISIDE; return F2; }
7272
"jn" { amrexpr_parserlval.f2 = amrexpr::PARSER_JN; return F2; }
73+
"yn" { amrexpr_parserlval.f2 = amrexpr::PARSER_YN; return F2; }
7374
"min" { amrexpr_parserlval.f2 = amrexpr::PARSER_MIN; return F2; }
7475
"max" { amrexpr_parserlval.f2 = amrexpr::PARSER_MAX; return F2; }
7576
"fmod" { amrexpr_parserlval.f2 = amrexpr::PARSER_FMOD; return F2; }

0 commit comments

Comments
 (0)