Skip to content

Commit 4596c26

Browse files
authored
Adding python bindings and a helper setter/getter object in python to… (#5876)
… expose the density floor and substep parameters that can be adjusted at runtime. --------- Signed-off-by: S. Eric Clark <[email protected]>
1 parent 1c10835 commit 4596c26

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Python/pywarpx/HybridPICModel.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
1-
# Copyright 2023 The WarpX Community
1+
# Copyright 2023-2025 The WarpX Community
22
#
33
# This file is part of WarpX.
44
#
55
# Authors: Roelof Groenewald (TAE Technologies)
6+
# S. Eric Clark (Helion Energy)
67
#
78
# License: BSD-3-Clause-LBNL
89

10+
from ._libwarpx import libwarpx
911
from .Bucket import Bucket
1012

1113
hybridpicmodel = Bucket("hybrid_pic_model")
1214
external_vector_potential = Bucket("external_vector_potential")
15+
16+
17+
class HybridPICModel(object):
18+
"""HybridPICModel
19+
20+
Description: This is an accessor object to be able to vary parameters
21+
in the WarpX HybridPICModel class. This can be useful for adjusting parameters
22+
like the density floor or number of substeps taken dynamically. This will be implemented
23+
as a selection of parameters that can be adjusted at runtime in installed callbacks.
24+
"""
25+
26+
def __init__(self):
27+
# Nothing to be done since this is a wrapper object
28+
pass
29+
30+
@property
31+
def substeps(self):
32+
warpx = libwarpx.libwarpx_so.get_instance()
33+
return warpx.get_hybrid_pic_substeps()
34+
35+
@substeps.setter
36+
def substeps(self, substeps):
37+
warpx = libwarpx.libwarpx_so.get_instance()
38+
return warpx.set_hybrid_pic_substeps(substeps)
39+
40+
@property
41+
def density_floor(self):
42+
warpx = libwarpx.libwarpx_so.get_instance()
43+
return warpx.get_hybrid_pic_density_floor()
44+
45+
@density_floor.setter
46+
def density_floor(self, n_floor):
47+
warpx = libwarpx.libwarpx_so.get_instance()
48+
return warpx.set_hybrid_pic_density_floor(n_floor)

Source/Python/WarpX.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,33 @@ The physical fields in WarpX have the following naming:
278278
[] (WarpX& wx) { wx.SynchronizeVelocityWithPosition(); },
279279
"Synchronize particle velocities and positions."
280280
)
281+
// Add some accessor bindings for the Hybrid Ohm's Law Solver
282+
.def("set_hybrid_pic_substeps",
283+
[](WarpX& wx, int substeps) {
284+
wx.get_pointer_HybridPICModel()->m_substeps = substeps;
285+
},
286+
py::arg("substeps"),
287+
"Sets the number of substeps to take in the hybrid solver."
288+
)
289+
.def("get_hybrid_pic_substeps",
290+
[](WarpX& wx) {
291+
return wx.get_pointer_HybridPICModel()->m_substeps;
292+
},
293+
"Gets the number of substeps taken in the hybrid solver."
294+
)
295+
.def("set_hybrid_pic_density_floor",
296+
[](WarpX& wx, amrex::Real n_floor) {
297+
wx.get_pointer_HybridPICModel()->m_n_floor = n_floor;
298+
},
299+
py::arg("n_floor"),
300+
"Sets the density floor to use in the hybrid solver."
301+
)
302+
.def("get_hybrid_pic_density_floor",
303+
[](WarpX& wx) {
304+
return wx.get_pointer_HybridPICModel()->m_n_floor;
305+
},
306+
"Gets the number of substeps to take in the hybrid solver."
307+
)
281308
;
282309

283310
py::class_<warpx::Config>(m, "Config")

0 commit comments

Comments
 (0)