Skip to content

Commit 5de95b3

Browse files
IlianCSax3l
authored andcommitted
replace extent in weighting and displacement
store extent value in n_particles
1 parent e31e4dd commit 5de95b3

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

examples/9_particle_write_serial.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if __name__ == "__main__":
1717
# open file for writing
1818
f = Series(
19-
"../samples/7_particle_write_serial_py.h5",
19+
"../samples/9_particle_write_serial_py.h5",
2020
Access.create
2121
)
2222

@@ -35,25 +35,29 @@
3535
"Electrons... the necessary evil for ion acceleration! ",
3636
"Just kidding.")
3737

38+
n_particles = 234
39+
3840
# let's set a weird user-defined record this time
3941
electrons["displacement"].unit_dimension = {Unit_Dimension.M: 1}
4042
electrons["displacement"][SCALAR].unit_SI = 1.e-6
41-
dset = Dataset(np.dtype("float64"), extent=[2])
43+
dset = Dataset(np.dtype("float64"), extent=[n_particles])
4244
electrons["displacement"][SCALAR].reset_dataset(dset)
4345
electrons["displacement"][SCALAR].make_constant(42.43)
4446
# don't like it anymore? remove it with:
4547
# del electrons["displacement"]
4648

47-
electrons["weighting"][SCALAR].make_constant(1.e-5)
49+
electrons["weighting"][SCALAR] \
50+
.reset_dataset(Dataset(np.dtype("float32"), extent=[n_particles])) \
51+
.make_constant(1.e-5)
4852

49-
particlePos_x = np.random.rand(234).astype(np.float32)
50-
particlePos_y = np.random.rand(234).astype(np.float32)
53+
particlePos_x = np.random.rand(n_particles).astype(np.float32)
54+
particlePos_y = np.random.rand(n_particles).astype(np.float32)
5155
d = Dataset(particlePos_x.dtype, extent=particlePos_x.shape)
5256
electrons["position"]["x"].reset_dataset(d)
5357
electrons["position"]["y"].reset_dataset(d)
5458

55-
particleOff_x = np.arange(234, dtype=np.uint)
56-
particleOff_y = np.arange(234, dtype=np.uint)
59+
particleOff_x = np.arange(n_particles, dtype=np.uint)
60+
particleOff_y = np.arange(n_particles, dtype=np.uint)
5761
d = Dataset(particleOff_x.dtype, particleOff_x.shape)
5862
electrons["positionOffset"]["x"].reset_dataset(d)
5963
electrons["positionOffset"]["y"].reset_dataset(d)

0 commit comments

Comments
 (0)