Skip to content

Commit 65ba289

Browse files
Merge pull request #54 from epochpic/drop-boundaries
ignore boundary variables when loading
2 parents 5216859 + 0fa8392 commit 65ba289

File tree

8 files changed

+179
-6
lines changed

8 files changed

+179
-6
lines changed

docs/getting_started.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ Usage
2525
-----
2626

2727
``sdf-xarray`` is a backend for xarray, and so is usable directly from
28-
`xarray`.
28+
`xarray`. There are several ways to load SDF files:
29+
30+
- To load a single file, use :func:`xarray.open_dataset`.
31+
- To load multiple files, use :func:`xarray.open_mfdataset` or :func:`sdf_xarray.open_mfdataset`.
32+
- To access the raw contents of a single SDF file, use :func:`sdf_xarray.sdf_interface.SDFFile`.
33+
34+
.. note::
35+
When loading ``*.sdf`` files, variables related to ``boundaries``, ``cpu`` and ``output file`` are excluded as they are problematic.
2936

3037
Single file loading
3138
~~~~~~~~~~~~~~~~~~~

docs/key_functionality.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ Key Functionality
1313
1414
Loading SDF Files
1515
-----------------
16-
There are several ways to load in SDF files using ``sdf-xarray``.
17-
You can load in a single file using :func:`xarray.open_dataset`,
18-
load in multiple files using :func:`xarray.open_mfdataset` or
19-
:func:`sdf_xarray.open_mfdataset`, or load in a single raw SDF file
20-
using :func:`sdf_xarray.sdf_interface.SDFFile`.
16+
There are several ways to load SDF files:
17+
18+
- To load a single file, use :func:`xarray.open_dataset`.
19+
- To load multiple files, use :func:`xarray.open_mfdataset` or :func:`sdf_xarray.open_mfdataset`.
20+
- To access the raw contents of a single SDF file, use :func:`sdf_xarray.sdf_interface.SDFFile`.
21+
22+
.. note::
23+
When loading ``*.sdf`` files, variables related to ``boundaries``, ``cpu`` and ``output file`` are excluded as they are problematic.
2124

2225
Loading a Single SDF File
2326
~~~~~~~~~~~~~~~~~~~~~~~~~

src/sdf_xarray/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ def _process_grid_name(grid_name: str, transform_func) -> str:
310310
# Had some problems with these variables, so just ignore them for now
311311
if "cpu" in key.lower():
312312
continue
313+
if "boundary" in key.lower():
314+
continue
313315
if "output file" in key.lower():
314316
continue
315317

tests/example_dist_fn/0000.sdf

59.8 KB
Binary file not shown.

tests/example_dist_fn/0001.sdf

59.8 KB
Binary file not shown.

tests/example_dist_fn/0002.sdf

8.08 KB
Binary file not shown.

tests/example_dist_fn/input.deck

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
begin:control
2+
3+
# global number of gridpoints
4+
# Divide nx and ny by 2 from 40 to 20
5+
nx = 16 # in x
6+
ny = 8
7+
nparticles = nx * ny * 4
8+
9+
# maximum number of iterations
10+
# set to -1 to run until finished
11+
nsteps = -1
12+
13+
# final time of simulation
14+
t_end = 200e-15
15+
16+
# size of domain
17+
x_min = 0e-6
18+
x_max = 40e-6
19+
y_min = -10e-6
20+
y_max = -y_min
21+
22+
dt_multiplier = 0.8
23+
dlb_threshold = 0.8
24+
25+
end:control
26+
27+
begin:laser
28+
29+
boundary = x_min
30+
intensity_w_cm2 = 1.0e23
31+
lambda = 1e-6
32+
phase = 0.0
33+
t_profile = gauss(time, 40.0e-15, 30.0e-15) # This profile means your laser pulse has a maximum intensity at t=40 fs, and the intensity will smoothly decrease as time moves away from this point, with a width parameter of 30 fs.
34+
t_start = 0.0
35+
t_end = end
36+
end:laser
37+
38+
begin:collisions
39+
40+
use_collisions = T
41+
coulomb_log = auto
42+
collide = all
43+
44+
end:collisions
45+
46+
47+
begin:boundaries
48+
49+
bc_x_min = simple_laser
50+
bc_x_max = open
51+
bc_y_min = periodic
52+
bc_y_max = periodic
53+
54+
end:boundaries
55+
56+
57+
begin:species
58+
59+
# electrons
60+
name = Electron
61+
fraction = 0.5
62+
dump = T
63+
64+
temperature = 0
65+
number_density = if ((x gt 10e-6) and (x lt 30e-6), 1e22, 0)
66+
number_density_min = 1
67+
68+
identify:electron
69+
70+
end:species
71+
72+
73+
begin:output_global
74+
75+
force_final_to_be_restartable = F
76+
77+
end:output_global
78+
79+
80+
begin:output
81+
82+
name = normal
83+
84+
# If use_offset_grid is true then the code dumps a grid which displays
85+
# positions relative to the left hand edge of the window
86+
use_offset_grid = F
87+
88+
# number of timesteps between output dumps
89+
dt_snapshot = 100.0e-15 # 100.0e-15 / 100.0
90+
91+
# Properties at particle positions
92+
particles = never
93+
px = never
94+
py = never
95+
pz = never
96+
vx = never
97+
vy = never
98+
vz = never
99+
charge = never
100+
mass = never
101+
particle_weight = never
102+
species_id = never
103+
104+
# Properties on grid
105+
grid = always
106+
ex = never
107+
ey = always
108+
ez = never
109+
bx = never
110+
by = never
111+
bz = never
112+
jx = never
113+
jy = never
114+
jz = never
115+
poynt_flux = always
116+
average_particle_energy = never
117+
mass_density = never
118+
charge_density = never
119+
number_density = never
120+
temperature = never
121+
122+
# extended io
123+
distribution_functions = always
124+
particle_probes = never
125+
absorption = never
126+
total_energy_sum = never
127+
128+
end:output
129+
130+
131+
begin:dist_fn
132+
133+
name = x_px_py
134+
ndims = 3
135+
dumpmask = always
136+
137+
direction1 = dir_x
138+
direction2 = dir_px
139+
direction3 = dir_py
140+
141+
# range is ignored for spatial coordinates
142+
range1 = (1, 1)
143+
range2 = (1.6e-20, 1.6e-19)
144+
range3 = (1.6e-20, 1.6e-19)
145+
146+
# resolution is ignored for spatial coordinates
147+
resolution1 = 1
148+
resolution2 = 20
149+
resolution3 = 20
150+
151+
#include_species:Photon
152+
include_species:Electron
153+
154+
end:dist_fn

tests/test_basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
pathlib.Path(__file__).parent / "example_mismatched_files"
1111
)
1212
EXAMPLE_ARRAYS_DIR = pathlib.Path(__file__).parent / "example_array_no_grids"
13+
EXAMPLE_3D_DIST_FN = pathlib.Path(__file__).parent / "example_dist_fn"
1314

1415

1516
def test_basic():
@@ -178,3 +179,9 @@ def test_arrays_with_no_grids_multifile():
178179
random_states = "Random_States"
179180
assert random_states in df
180181
assert df[random_states].shape == (2, 8)
182+
183+
184+
def test_3d_distribution_function():
185+
with xr.open_dataset(EXAMPLE_3D_DIST_FN / "0000.sdf") as df:
186+
distribution_function = "dist_fn_x_px_py_Electron"
187+
assert df[distribution_function].shape == (16, 20, 20)

0 commit comments

Comments
 (0)