6 #include <AMReX_GpuQualifiers.H> 7 #include <AMReX_GpuPrint.H> 8 #include <AMReX_Extension.H> 9 #include <AMReX_REAL.H> 10 #include <AMReX_Print.H> 16 #include <type_traits> 22 template <
int Depth, std::enable_if_t<(Depth<WARPX_PARSER_DEPTH),
int> = 0>
23 AMREX_GPU_DEVICE AMREX_NO_INLINE
24 void wp_ast_update_device_ptr (struct wp_node* node,
char* droot,
char* hroot)
33 p->name = droot + (p->name - hroot);
41 node->l = (
wp_node*)(droot + ((
char*)node->l - hroot));
42 node->r = (
wp_node*)(droot + ((
char*)node->r - hroot));
43 wp_ast_update_device_ptr<Depth+1>(node->l, droot, hroot);
44 wp_ast_update_device_ptr<Depth+1>(node->r, droot, hroot);
49 node->l = (
wp_node*)(droot + ((
char*)node->l - hroot));
50 wp_ast_update_device_ptr<Depth+1>(node->l, droot, hroot);
55 auto p = (
struct wp_f1*)node;
56 p->l = (
wp_node*)(droot + ((
char*)p->l - hroot));
57 wp_ast_update_device_ptr<Depth+1>(p->l, droot, hroot);
62 auto p = (
struct wp_f2*)node;
63 p->l = (
wp_node*)(droot + ((
char*)p->l - hroot));
64 p->r = (
wp_node*)(droot + ((
char*)p->r - hroot));
65 wp_ast_update_device_ptr<Depth+1>(p->l, droot, hroot);
66 wp_ast_update_device_ptr<Depth+1>(p->r, droot, hroot);
85 #if AMREX_DEVICE_COMPILE 86 AMREX_DEVICE_PRINTF(
"wp_ast_update_device_ptr: unknown node type %d\n",
87 static_cast<int>(node->type));
94 template <
int Depth, std::enable_if_t<Depth == WARPX_PARSER_DEPTH,
int> = 0>
95 AMREX_GPU_DEVICE AMREX_NO_INLINE
96 void wp_ast_update_device_ptr (
struct wp_node*,
char*,
char*)
98 #if AMREX_DEVICE_COMPILE 99 AMREX_DEVICE_PRINTF(
"wp_ast_update_device_ptr: WARPX_PARSER_DEPTH %d not big enough\n",
107 template <
int Depth, std::enable_if_t<(Depth<WARPX_PARSER_DEPTH),
int> = 0>
108 AMREX_GPU_HOST_DEVICE
113 wp_ast_eval (struct wp_node* node, amrex::Real const* x)
115 amrex::Real result = 0.0;
121 result = ((
struct wp_number*)node)->value;
126 #if AMREX_DEVICE_COMPILE 130 result = *(((
struct wp_symbol*)node)->ip.p);
136 result = wp_ast_eval<Depth+1>(node->l,
x) + wp_ast_eval<Depth+1>(node->r,
x);
141 result = wp_ast_eval<Depth+1>(node->l,
x) - wp_ast_eval<Depth+1>(node->r,
x);
146 result = wp_ast_eval<Depth+1>(node->l,
x) * wp_ast_eval<Depth+1>(node->r,
x);
151 result = wp_ast_eval<Depth+1>(node->l,
x) / wp_ast_eval<Depth+1>(node->r,
x);
156 result = -wp_ast_eval<Depth+1>(node->l,
x);
162 wp_ast_eval<Depth+1>(((
struct wp_f1*)node)->l,
x));
168 wp_ast_eval<Depth+1>(((
struct wp_f2*)node)->l,
x),
169 wp_ast_eval<Depth+1>(((
struct wp_f2*)node)->r,
x));
174 #if AMREX_DEVICE_COMPILE 176 result = node->lvp.v +
x[
i];
178 result = node->lvp.v + *(node->rip.p);
184 #if AMREX_DEVICE_COMPILE 185 int i = node->lvp.ip.i;
187 result =
x[
i] +
x[j];
189 result = *(node->lvp.ip.p) + *(node->rip.p);
195 #if AMREX_DEVICE_COMPILE 197 result = node->lvp.v -
x[
i];
199 result = node->lvp.v - *(node->rip.p);
205 #if AMREX_DEVICE_COMPILE 206 int i = node->lvp.ip.i;
208 result =
x[
i] -
x[j];
210 result = *(node->lvp.ip.p) - *(node->rip.p);
216 #if AMREX_DEVICE_COMPILE 218 result = node->lvp.v *
x[
i];
220 result = node->lvp.v * *(node->rip.p);
226 #if AMREX_DEVICE_COMPILE 227 int i = node->lvp.ip.i;
229 result =
x[
i] *
x[j];
231 result = *(node->lvp.ip.p) * *(node->rip.p);
237 #if AMREX_DEVICE_COMPILE 239 result = node->lvp.v /
x[
i];
241 result = node->lvp.v / *(node->rip.p);
247 #if AMREX_DEVICE_COMPILE 248 int i = node->lvp.ip.i;
250 result =
x[
i] /
x[j];
252 result = *(node->lvp.ip.p) / *(node->rip.p);
258 #if AMREX_DEVICE_COMPILE 262 result = -*(node->lvp.ip.p);
268 #if AMREX_DEVICE_COMPILE 269 AMREX_DEVICE_PRINTF(
"wp_ast_eval: unknown node type %d\n", node->type);
271 amrex::AllPrint() <<
"wp_ast_eval: unknown node type " << node->type <<
"\n";
279 template <
int Depth, std::enable_if_t<Depth == WARPX_PARSER_DEPTH,
int> = 0>
280 AMREX_GPU_HOST_DEVICE
287 #if AMREX_DEVICE_COMPILE 288 AMREX_DEVICE_PRINTF(
"wp_ast_eval: WARPX_PARSER_DEPTH %d not big enough\n",
291 amrex::AllPrint() <<
"wp_ast_eval: WARPX_PARSER_DEPTH" << WARPX_PARSER_DEPTH
292 <<
"not big enough\n";
294 amrex::ignore_unused(node, x);
338 amrex::AllPrint() <<
"wp_ast_get_symbols: unknown node type " << node->
type <<
"\n";
Definition: wp_parser_y.h:69
Definition: wp_parser_y.h:71
Definition: wp_parser_y.h:72
Definition: wp_parser_y.h:58
struct wp_parser * wp_c_parser_new(char const *function_body)
Definition: wp_parser_c.cpp:6
Definition: wp_parser_y.h:60
Definition: wp_parser_y.h:65
void wp_ast_get_symbols(struct wp_node *node, std::set< std::string > &symbols)
Definition: wp_parser_c.h:300
def x
Definition: read_lab_particles.py:25
Definition: wp_parser_y.h:67
Definition: wp_parser_y.h:68
Definition: wp_parser_y.h:55
Definition: wp_parser_y.h:70
Definition: wp_parser_y.h:145
Definition: wp_parser_y.h:104
Definition: wp_parser_y.h:56
AMREX_GPU_HOST_DEVICE T wp_call_f2(enum wp_f2_t type, T a, T b)
Definition: wp_parser_y.h:217
AMREX_GPU_HOST_DEVICE amrex::Real wp_ast_eval(struct wp_node *node, amrex::Real const *x)
Definition: wp_parser_c.h:113
enum wp_node_t type
Definition: wp_parser_y.h:117
i
Definition: check_interp_points_and_weights.py:171
Definition: wp_parser_y.h:61
Definition: wp_parser_y.h:66
Definition: wp_parser_y.h:91
Definition: wp_parser_y.h:59
type
Definition: run_alltests_1node.py:67
Definition: wp_parser_y.h:62
struct wp_node * r
Definition: wp_parser_y.h:119
name
Definition: run_automated.py:204
AMREX_GPU_HOST_DEVICE T wp_call_f1(enum wp_f1_t type, T a)
Definition: wp_parser_y.h:177
Definition: wp_parser_y.h:64
enum wp_node_t type
Definition: wp_parser_y.h:92
Definition: wp_parser_y.h:116
Definition: wp_parser_y.h:57
Definition: wp_parser_y.h:63
Definition: wp_parser_y.h:99
Definition: wp_parser_y.h:110