-
Notifications
You must be signed in to change notification settings - Fork 109
Support GPU lazy field arithmetic operators #3385
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
Changes from all commits
dc932cc
b83d2b5
9708709
e20da9d
096f576
34cba4d
7d75b9d
b8e7e97
d830f8d
c5f9fd6
4d64ad2
5dfa66a
026645a
338920e
6e88181
25d1272
56a8678
3e3a0ea
56fe675
b75103d
40974a9
ba5eabf
c079bb6
932f156
b6c738c
11ebfcd
cf5a882
9f42dcb
35e6f42
dc2117b
f38dbd1
98b9e55
b0fd981
bb5b495
a06e450
8018906
6cab892
1caebb6
4e19f8e
d676726
0b9dbf6
9350715
36c06ec
09aaee6
94cf70f
d3236d9
f48cd51
ac1836b
b9de118
0fdeedb
504fe6e
250a566
512e853
7cb424f
b0ff0c6
404e063
c88908b
ca94ba5
43c5050
50839f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1008,7 +1008,8 @@ class ELMpb : public PhysicsModel { | |||||
| vacuum_trans *= pnorm; | ||||||
|
|
||||||
| // Transitions from 0 in core to 1 in vacuum | ||||||
| vac_mask = (1.0 - tanh((P0 - vacuum_pressure) / vacuum_trans)) / 2.0; | ||||||
| Field2D tanh_res = tanh((P0 - vacuum_pressure) / vacuum_trans); | ||||||
| vac_mask = (1.0 - tanh_res) / 2.0; | ||||||
|
|
||||||
| if (spitzer_resist) { | ||||||
| // Use Spitzer resistivity | ||||||
|
|
@@ -1169,7 +1170,7 @@ class ELMpb : public PhysicsModel { | |||||
| // Only if not restarting: Check initial perturbation | ||||||
|
|
||||||
| // Set U to zero where P0 < vacuum_pressure | ||||||
| U = where(P0 - vacuum_pressure, U, 0.0); | ||||||
| U = where(Field2D{P0 - vacuum_pressure}, U, 0.0); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "where" is directly included [misc-include-cleaner] examples/elm-pb-outerloop/elm_pb_outerloop.cxx:13: - #define DISABLE_RAJA 0 // Turn off RAJA in this file?
+ #include "bout/where.hxx"
+ #define DISABLE_RAJA 0 // Turn off RAJA in this file? |
||||||
|
|
||||||
| if (constn0) { | ||||||
| ubyn = U; | ||||||
|
|
@@ -1796,7 +1797,8 @@ class ELMpb : public PhysicsModel { | |||||
| ddt(U) -= 0.5 * Upara2 * bracket(Pi0, Dperp2Phi, bm_exb) / B0; | ||||||
| Field3D B0phi = B0 * phi; | ||||||
| mesh->communicate(B0phi); | ||||||
| Field3D B0phi0 = B0 * phi0; | ||||||
| Field2D res = B0 * phi0; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'res' of type 'Field2D' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
| Field3D B0phi0 = res; | ||||||
| mesh->communicate(B0phi0); | ||||||
| ddt(U) += 0.5 * Upara2 * bracket(B0phi, Dperp2Pi0, bm_exb) / B0; | ||||||
| ddt(U) += 0.5 * Upara2 * bracket(B0phi0, Dperp2Pi, bm_exb) / B0; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,16 +6,22 @@ | |
| *******************************************************************************/ | ||
|
|
||
| #include <bout/bout.hxx> | ||
| #include <bout/bout_types.hxx> | ||
| #include <bout/boutexception.hxx> | ||
| #include <bout/constants.hxx> | ||
| #include <bout/coordinates.hxx> | ||
| #include <bout/derivs.hxx> | ||
| #include <bout/difops.hxx> | ||
| #include <bout/field2d.hxx> | ||
| #include <bout/field3d.hxx> | ||
| #include <bout/field_factory.hxx> | ||
| #include <bout/fv_ops.hxx> | ||
| #include <bout/initialprofiles.hxx> | ||
| #include <bout/interpolation.hxx> | ||
| #include <bout/invert/laplacexy.hxx> | ||
| #include <bout/invert_laplace.hxx> | ||
| #include <bout/invert_parderiv.hxx> | ||
| #include <bout/output.hxx> | ||
| #include <bout/sourcex.hxx> | ||
| #include <bout/tokamak_coordinates.hxx> | ||
| #include <bout/utils.hxx> | ||
|
|
@@ -246,8 +252,8 @@ class ELMpb : public PhysicsModel { | |
| std::unique_ptr<Laplacian> phiSolver{nullptr}; | ||
| std::unique_ptr<Laplacian> aparSolver{nullptr}; | ||
|
|
||
| const Field2D N0tanh(BoutReal n0_height, BoutReal n0_ave, BoutReal n0_width, | ||
| BoutReal n0_center, BoutReal n0_bottom_x) { | ||
| Field2D N0tanh(BoutReal n0_height, BoutReal n0_ave, BoutReal n0_width, | ||
| BoutReal n0_center, BoutReal n0_bottom_x) { | ||
| Field2D result; | ||
| result.allocate(); | ||
|
|
||
|
|
@@ -1138,7 +1144,7 @@ class ELMpb : public PhysicsModel { | |
| // Only if not restarting: Check initial perturbation | ||
|
|
||
| // Set U to zero where P0 < vacuum_pressure | ||
| U = where(P0 - vacuum_pressure, U, 0.0); | ||
| U = where(Field2D{P0 - vacuum_pressure}, U, 0.0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "where" is directly included [misc-include-cleaner] examples/elm-pb/elm_pb.cxx:7: - #include <bout/bout.hxx>
+ #include "bout/where.hxx"
+ #include <bout/bout.hxx> |
||
|
|
||
| if (constn0) { | ||
| ubyn = U; | ||
|
|
@@ -1202,7 +1208,7 @@ class ELMpb : public PhysicsModel { | |
| // Perform communications | ||
| mesh->communicate(comms); | ||
|
|
||
| Coordinates* metric = mesh->getCoordinates(); | ||
| const Coordinates* metric = mesh->getCoordinates(); | ||
|
|
||
| //////////////////////////////////////////// | ||
| // Transitions from 0 in core to 1 in vacuum | ||
|
|
@@ -1698,10 +1704,10 @@ class ELMpb : public PhysicsModel { | |
| // Vacuum solution | ||
| if (relax_j_vac) { | ||
| // Calculate the J and Psi profile we're aiming for | ||
| Field3D Jtarget = Jpar * (1.0 - vac_mask); // Zero in vacuum | ||
| const Field3D Jtarget = Jpar * (1.0 - vac_mask); // Zero in vacuum | ||
|
|
||
| // Invert laplacian for Psi | ||
| Field3D Psitarget = aparSolver->solve(Jtarget); | ||
| const Field3D Psitarget = aparSolver->solve(Jtarget); | ||
|
|
||
| // Add a relaxation term in the vacuum | ||
| ddt(Psi) = | ||
|
|
@@ -1832,7 +1838,7 @@ class ELMpb : public PhysicsModel { | |
| ddt(U) -= 0.5 * Upara2 * bracket(Pi0, Dperp2Phi, bm_exb) / B0; | ||
| Field3D B0phi = B0 * phi; | ||
| mesh->communicate(B0phi); | ||
| Field3D B0phi0 = B0 * phi0; | ||
| Field2D B0phi0 = B0 * phi0; | ||
| mesh->communicate(B0phi0); | ||
| ddt(U) += 0.5 * Upara2 * bracket(B0phi, Dperp2Pi0, bm_exb) / B0; | ||
| ddt(U) += 0.5 * Upara2 * bracket(B0phi0, Dperp2Pi, bm_exb) / B0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,8 @@ | ||||||
| /************************************************************************** | ||||||
| * Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu | ||||||
| * Copyright 2010 - 2026 BOUT++ contributors | ||||||
| * | ||||||
| * Contact Ben Dudson, dudson2@llnl.gov | ||||||
| * | ||||||
| * Contact Ben Dudson, bd512@york.ac.uk | ||||||
| * | ||||||
| * This file is part of BOUT++. | ||||||
| * | ||||||
| * BOUT++ is free software: you can redistribute it and/or modify | ||||||
|
|
@@ -22,6 +22,8 @@ | |||||
| #ifndef BOUT_TYPES_H | ||||||
| #define BOUT_TYPES_H | ||||||
|
|
||||||
| #include "bout/build_config.hxx" | ||||||
|
|
||||||
| #include <limits> | ||||||
| #include <string> | ||||||
|
|
||||||
|
|
@@ -140,4 +142,15 @@ struct enumWrapper { | |||||
| /// Boundary condition function | ||||||
| using FuncPtr = BoutReal (*)(BoutReal t, BoutReal x, BoutReal y, BoutReal z); | ||||||
|
|
||||||
| template <typename T> | ||||||
| struct Constant { | ||||||
| T val; | ||||||
| struct View { | ||||||
| T v; | ||||||
| View(T v) : v(v) {} | ||||||
| BOUT_HOST_DEVICE T operator()(int) const { return v; } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: all parameters should be named in a function [readability-named-parameter]
Suggested change
|
||||||
| }; | ||||||
| operator View() const { return {val}; } | ||||||
| }; | ||||||
|
|
||||||
| #endif // BOUT_TYPES_H | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ | |
| /// -> If Coordinates data is changed, the cache should be cleared | ||
| /// by calling CoordinatesAccessor::clear() | ||
| struct CoordinatesAccessor { | ||
| CoordinatesAccessor() = delete; | ||
| CoordinatesAccessor() {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: constructor does not initialize these fields: data, mesh_nz [cppcoreguidelines-pro-type-member-init] include/bout/coordinates_accessor.hxx:87: - BoutReal* data;
- int mesh_nz; ///< For converting from 3D to 2D index
+ BoutReal* data{};
+ int mesh_nz{}; ///< For converting from 3D to 2D index |
||
|
|
||
| /// Constructor from Coordinates | ||
| /// Copies data from coords, doesn't modify it | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'tanh_res' of type 'Field2D' can be declared 'const' [misc-const-correctness]