Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: Bessel Function (J_n) #1854

Merged
merged 4 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Parser/wp_parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ EXP ([Ee][-+]?[0-9]+)
"or" { wxparserlval.f2 = WP_OR; return OR;}
"pow" { wxparserlval.f2 = WP_POW; return F2; }
"heaviside" { wxparserlval.f2 = WP_HEAVISIDE; return F2; }
"jn" { wxparserlval.f2 = WP_JN; return F2; }
"min" { wxparserlval.f2 = WP_MIN; return F2; }
"max" { wxparserlval.f2 = WP_MAX; return F2; }

Expand Down
210 changes: 107 additions & 103 deletions Source/Parser/wp_parser.lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,29 +611,29 @@ static void yynoreturn yy_fatal_error ( const char* msg );
(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 47
#define YY_END_OF_BUFFER 48
#define YY_NUM_RULES 48
#define YY_END_OF_BUFFER 49
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
{
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static const flex_int16_t yy_accept[104] =
static const flex_int16_t yy_accept[106] =
{ 0,
0, 0, 48, 46, 43, 45, 46, 10, 11, 3,
1, 7, 2, 46, 4, 41, 8, 5, 9, 39,
46, 28, 39, 39, 39, 39, 39, 39, 39, 39,
39, 39, 39, 6, 32, 27, 41, 42, 40, 41,
0, 30, 31, 29, 39, 44, 39, 39, 39, 39,
39, 39, 39, 39, 39, 39, 39, 39, 34, 39,
39, 39, 39, 42, 40, 0, 0, 41, 25, 39,
33, 39, 39, 17, 13, 39, 39, 14, 38, 37,
35, 16, 39, 18, 0, 40, 20, 19, 21, 23,
26, 39, 39, 22, 12, 24, 39, 15, 39, 39,

39, 36, 0
0, 0, 49, 47, 44, 46, 47, 10, 11, 3,
1, 7, 2, 47, 4, 42, 8, 5, 9, 40,
47, 28, 40, 40, 40, 40, 40, 40, 40, 40,
40, 40, 40, 40, 6, 32, 27, 42, 43, 41,
42, 0, 30, 31, 29, 40, 45, 40, 40, 40,
40, 40, 40, 40, 40, 40, 37, 40, 40, 40,
34, 40, 40, 40, 40, 43, 41, 0, 0, 42,
25, 40, 33, 40, 40, 17, 13, 40, 40, 14,
39, 38, 35, 16, 40, 18, 0, 41, 20, 19,
21, 23, 26, 40, 40, 22, 12, 24, 40, 15,

40, 40, 40, 36, 0
} ;

static const YY_CHAR yy_ec[256] =
Expand All @@ -649,9 +649,9 @@ static const YY_CHAR yy_ec[256] =
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
1, 21, 1, 22, 19, 1, 23, 24, 25, 26,

27, 28, 29, 30, 31, 19, 19, 32, 33, 34,
35, 36, 37, 38, 39, 40, 19, 41, 42, 43,
19, 19, 1, 44, 1, 1, 1, 1, 1, 1,
27, 28, 29, 30, 31, 32, 19, 33, 34, 35,
36, 37, 38, 39, 40, 41, 19, 42, 43, 44,
19, 19, 1, 45, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Expand All @@ -668,99 +668,99 @@ static const YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;

static const YY_CHAR yy_meta[45] =
static const YY_CHAR yy_meta[46] =
{ 0,
1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 3, 3, 3, 1, 1, 1, 3, 3,
1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 1
3, 3, 3, 3, 1
} ;

static const flex_int16_t yy_base[106] =
static const flex_int16_t yy_base[108] =
{ 0,
0, 0, 156, 157, 157, 157, 138, 157, 157, 147,
157, 157, 157, 32, 141, 37, 135, 134, 133, 0,
146, 157, 29, 113, 104, 123, 118, 109, 35, 105,
107, 18, 118, 157, 157, 157, 47, 0, 57, 65,
73, 157, 157, 157, 0, 157, 101, 104, 112, 106,
113, 96, 98, 109, 109, 102, 87, 95, 0, 86,
93, 88, 91, 0, 76, 85, 91, 94, 0, 85,
0, 89, 88, 91, 0, 81, 78, 103, 0, 0,
0, 72, 61, 67, 97, 100, 0, 0, 0, 0,
0, 63, 69, 0, 0, 0, 36, 0, 42, 39,

32, 0, 157, 53, 115
0, 0, 158, 159, 159, 159, 140, 159, 159, 149,
159, 159, 159, 33, 143, 38, 137, 136, 135, 0,
148, 159, 31, 114, 105, 125, 120, 111, 109, 31,
105, 107, 19, 119, 159, 159, 159, 54, 0, 62,
72, 80, 159, 159, 159, 0, 159, 101, 104, 113,
107, 114, 96, 98, 110, 110, 0, 103, 87, 95,
0, 86, 93, 88, 91, 0, 83, 92, 46, 65,
0, 85, 0, 89, 88, 92, 0, 81, 78, 104,
0, 0, 0, 79, 67, 74, 98, 101, 0, 0,
0, 0, 0, 70, 78, 0, 0, 0, 44, 0,

42, 44, 37, 0, 159, 60, 116
} ;

static const flex_int16_t yy_def[106] =
static const flex_int16_t yy_def[108] =
{ 0,
103, 1, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 104,
103, 103, 104, 104, 104, 104, 104, 104, 104, 104,
104, 104, 104, 103, 103, 103, 103, 105, 103, 103,
103, 103, 103, 103, 104, 103, 104, 104, 104, 104,
104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
104, 104, 104, 105, 103, 103, 103, 103, 104, 104,
104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
104, 104, 104, 104, 103, 103, 104, 104, 104, 104,
104, 104, 104, 104, 104, 104, 104, 104, 104, 104,

104, 104, 0, 103, 103
105, 1, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 106,
105, 105, 106, 106, 106, 106, 106, 106, 106, 106,
106, 106, 106, 106, 105, 105, 105, 105, 107, 105,
105, 105, 105, 105, 105, 106, 105, 106, 106, 106,
106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
106, 106, 106, 106, 106, 107, 105, 105, 105, 105,
106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
106, 106, 106, 106, 106, 106, 105, 105, 106, 106,
106, 106, 106, 106, 106, 106, 106, 106, 106, 106,

106, 106, 106, 106, 0, 105, 105
} ;

static const flex_int16_t yy_nxt[202] =
static const flex_int16_t yy_nxt[205] =
{ 0,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 16, 16, 17, 18, 19, 20, 20,
21, 22, 23, 20, 24, 20, 25, 26, 20, 27,
20, 28, 29, 20, 30, 31, 20, 20, 32, 33,
20, 20, 20, 34, 37, 37, 37, 39, 61, 40,
40, 40, 47, 48, 62, 45, 41, 57, 102, 37,
37, 37, 49, 41, 101, 58, 41, 50, 51, 65,
65, 65, 100, 41, 99, 39, 66, 40, 40, 40,
67, 98, 67, 66, 41, 68, 68, 68, 65, 65,
65, 41, 85, 97, 85, 66, 96, 86, 86, 86,

95, 94, 66, 68, 68, 68, 68, 68, 68, 86,
86, 86, 86, 86, 86, 64, 93, 64, 92, 91,
90, 89, 88, 87, 84, 83, 82, 81, 80, 79,
78, 77, 76, 75, 74, 73, 72, 71, 70, 69,
63, 60, 59, 56, 55, 54, 53, 52, 46, 44,
43, 42, 38, 36, 35, 103, 3, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,

103
20, 28, 29, 30, 20, 31, 32, 20, 20, 33,
34, 20, 20, 20, 35, 38, 38, 38, 40, 63,
41, 41, 41, 59, 48, 49, 64, 42, 70, 70,
70, 60, 46, 104, 42, 50, 38, 38, 38, 103,
51, 52, 102, 42, 67, 67, 67, 70, 70, 70,
42, 68, 40, 101, 41, 41, 41, 69, 68, 69,
100, 42, 70, 70, 70, 67, 67, 67, 42, 87,

99, 87, 68, 98, 88, 88, 88, 97, 96, 68,
88, 88, 88, 88, 88, 88, 66, 95, 66, 94,
93, 92, 91, 90, 89, 86, 85, 84, 83, 82,
81, 80, 79, 78, 77, 76, 75, 74, 73, 72,
71, 65, 62, 61, 58, 57, 56, 55, 54, 53,
47, 45, 44, 43, 39, 37, 36, 105, 3, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,

105, 105, 105, 105
} ;

static const flex_int16_t yy_chk[202] =
static const flex_int16_t yy_chk[205] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 14, 14, 14, 16, 32, 16,
16, 16, 23, 23, 32, 104, 16, 29, 101, 37,
37, 37, 23, 16, 100, 29, 37, 23, 23, 39,
39, 39, 99, 37, 97, 40, 39, 40, 40, 40,
41, 93, 41, 39, 40, 41, 41, 41, 65, 65,
65, 40, 66, 92, 66, 65, 84, 66, 66, 66,

83, 82, 65, 67, 67, 67, 68, 68, 68, 85,
85, 85, 86, 86, 86, 105, 78, 105, 77, 76,
74, 73, 72, 70, 63, 62, 61, 60, 58, 57,
56, 55, 54, 53, 52, 51, 50, 49, 48, 47,
33, 31, 30, 28, 27, 26, 25, 24, 21, 19,
18, 17, 15, 10, 7, 3, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,

103
1, 1, 1, 1, 1, 14, 14, 14, 16, 33,
16, 16, 16, 30, 23, 23, 33, 16, 69, 69,
69, 30, 106, 103, 16, 23, 38, 38, 38, 102,
23, 23, 101, 38, 40, 40, 40, 70, 70, 70,
38, 40, 41, 99, 41, 41, 41, 42, 40, 42,
95, 41, 42, 42, 42, 67, 67, 67, 41, 68,

94, 68, 67, 86, 68, 68, 68, 85, 84, 67,
87, 87, 87, 88, 88, 88, 107, 80, 107, 79,
78, 76, 75, 74, 72, 65, 64, 63, 62, 60,
59, 58, 56, 55, 54, 53, 52, 51, 50, 49,
48, 34, 32, 31, 29, 28, 27, 26, 25, 24,
21, 19, 18, 17, 15, 10, 7, 3, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105,

105, 105, 105, 105
} ;

static yy_state_type yy_last_accepting_state;
Expand Down Expand Up @@ -1022,13 +1022,13 @@ YY_DECL
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 104 )
if ( yy_current_state >= 106 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_current_state != 103 );
while ( yy_current_state != 105 );
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);

Expand Down Expand Up @@ -1166,48 +1166,52 @@ YY_RULE_SETUP
YY_BREAK
case 37:
YY_RULE_SETUP
{ wxparserlval.f2 = WP_MIN; return F2; }
{ wxparserlval.f2 = WP_JN; return F2; }
YY_BREAK
case 38:
YY_RULE_SETUP
{ wxparserlval.f2 = WP_MIN; return F2; }
YY_BREAK
case 39:
YY_RULE_SETUP
{ wxparserlval.f2 = WP_MAX; return F2; }
YY_BREAK
/* We use SYMBOL to hold variables and constants */
case 39:
case 40:
YY_RULE_SETUP
{ wxparserlval.s = wp_makesymbol(wxparsertext); return SYMBOL; }
YY_BREAK
/* Number */
case 40:
case 41:
case 42:
YY_RULE_SETUP
{ wxparserlval.d = atof(wxparsertext); return NUMBER; }
YY_BREAK
/* Special characters */
case 42:
case 43:
YY_RULE_SETUP

YY_BREAK
case 43:
case 44:
YY_RULE_SETUP
/* ignore white space */
YY_BREAK
case 44:
/* rule 44 can match eol */
case 45:
/* rule 45 can match eol */
YY_RULE_SETUP
/* ignore line continuation */
YY_BREAK
case 45:
/* rule 45 can match eol */
case 46:
/* rule 46 can match eol */
YY_RULE_SETUP
{ return EOL; }
YY_BREAK
/* everything else */
case 46:
case 47:
YY_RULE_SETUP
{ wxparsererror("Unknown character %c\n", *wxparsertext); }
YY_BREAK
case 47:
case 48:
YY_RULE_SETUP
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
Expand Down Expand Up @@ -1508,7 +1512,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 104 )
if ( yy_current_state >= 106 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
Expand Down Expand Up @@ -1536,11 +1540,11 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 104 )
if ( yy_current_state >= 106 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 103);
yy_is_jam = (yy_current_state == 105);

return yy_is_jam ? 0 : yy_current_state;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Parser/wp_parser_y.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ wp_ast_print_f2 (struct wp_f2* f2)
case WP_HEAVISIDE:
std::printf("HEAVISIDE\n");
break;
case WP_JN:
std::printf("JN\n");
break;
case WP_MIN:
std::printf("MIN\n");
break;
Expand Down
18 changes: 17 additions & 1 deletion Source/Parser/wp_parser_y.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include <AMReX_Math.H>
#include <AMReX_Print.H>

#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <type_traits>

enum wp_f1_t { // Bulit-in functions with one argument
enum wp_f1_t { // Built-in functions with one argument
WP_SQRT = 1,
WP_EXP,
WP_LOG,
Expand Down Expand Up @@ -47,6 +48,7 @@ enum wp_f2_t { // Built-in functions with two arguments
WP_AND,
WP_OR,
WP_HEAVISIDE,
WP_JN,
WP_MIN,
WP_MAX
};
Expand Down Expand Up @@ -237,6 +239,20 @@ wp_call_f2 (enum wp_f2_t type, T a, T b)
return ((a != T(0)) || (b != T(0))) ? 1.0 : 0.0;
case WP_HEAVISIDE:
return (a < 0.0) ? amrex::Real(0.0) : ((a > 0.0) ? amrex::Real(1.0) : b);
case WP_JN:
#ifdef AMREX_USE_DPCPP
// neither jn(f) nor std::cyl_bessel_j work yet
// https://github.com/oneapi-src/oneAPI-spec/issues/308
AMREX_DEVICE_PRINTF("wp_call_f2: Parser does not implement jn (%d) for SYCL/DPC++ yet\n", type);
amrex::Abort();
return 0.0;
#else
# if defined(AMREX_USE_FLOAT) && !defined(__APPLE__)
return jnf(a, b);
# else
return jn(a, b);
ax3l marked this conversation as resolved.
Show resolved Hide resolved
# endif
#endif
case WP_MIN:
return (a < b) ? a : b;
case WP_MAX:
Expand Down