@@ -82,14 +82,42 @@ def tearDown(self):
8282 del self .__particle_series
8383 del self .__series
8484
85+ # This function exhibits a bug in the old use of refcounting.
86+ def refcountingCreateData (self ):
87+ series = io .Series (
88+ "../samples/refcounting.json" ,
89+ io .Access .create_linear ,
90+ )
91+
92+ for i in range (10 ):
93+ current_iteration = series .snapshots ()[i ]
94+
95+ # First, write an E mesh.
96+ E = current_iteration .meshes ["E" ]
97+ E .axis_labels = ["x" , "y" ]
98+ for dim in ["x" , "y" ]:
99+ component = E [dim ]
100+ component .reset_dataset (io .Dataset (np .dtype ("float" ), [10 , 10 ]))
101+ component [:, :] = np .reshape (
102+ np .arange (i * 100 , (i + 1 ) * 100 , dtype = np .dtype ("float" )),
103+ [10 , 10 ],
104+ )
105+
106+ # Now, write some e particles.
107+ e = current_iteration .particles ["e" ]
108+ for dim in ["x" , "y" ]:
109+ # Do not bother with a positionOffset
110+ position_offset = e ["positionOffset" ][dim ]
111+ position_offset .make_constant (0 )
112+
113+ position = e ["position" ][dim ]
114+ position .reset_dataset (io .Dataset (np .dtype ("float" ), [100 ]))
115+ position [:] = np .arange (
116+ i * 100 , (i + 1 ) * 100 , dtype = np .dtype ("float" )
117+ )
118+
85119 def testRefCounting (self ):
86- write = io .Series (
87- "../samples/refcounting.json" , io .Access .create_linear )
88- iteration = write .snapshots ()[0 ]
89- pos_x = iteration .particles ["e" ]["position" ]["x" ]
90- pos_x .reset_dataset (io .Dataset (np .dtype ("float" ), [100 ]))
91- pos_x [:] = np .arange (0 , 100 , dtype = np .dtype ("float" ))
92- write .close ()
120+ self .refcountingCreateData ()
93121
94122 read = io .Series ("../samples/refcounting.json" , io .Access .read_linear )
95123 iteration = read .snapshots ()[0 ]
0 commit comments