Permalink
Browse files

testsuite: velocityprofile.

  • Loading branch information...
KaiSzuttor committed Jan 11, 2018
1 parent 2a275a3 commit aabcb3730a3cd73562c331fdf036a45c7855c188
Showing with 39 additions and 4 deletions.
  1. +39 −4 testsuite/observable_cylindrical.py
@@ -108,14 +108,15 @@ def set_particles(self):
def calculate_numpy_histogram(self):
pol_positions = self.pol_coords()
bin_volume = self.calculate_bin_volume()
np_hist, _ = np.histogramdd(pol_positions, bins=(self.params['n_r_bins'], self.params['n_phi_bins'], self.params['n_z_bins']),
range=[(self.params['min_r'], self.params['max_r']), (self.params['min_phi'], self.params['max_phi']),
(self.params['min_z'], self.params['max_z'])])
# Normalization
def normalize_with_bin_volume(self, histogram):
bin_volume = self.calculate_bin_volume()
for i in range(self.params['n_r_bins']):
np_hist[i, :, :] /= bin_volume[i]
return np_hist
histogram[i, :, :] /= bin_volume[i]
return histogram
def density_profile_test(self):
self.set_particles()
@@ -140,8 +141,41 @@ def density_profile_test(self):
self.params['n_phi_bins'],
self.params['n_z_bins'])
np_hist = self.calculate_numpy_histogram()
np_hist = self.normalize_with_bin_volume(np_hist)
np.testing.assert_array_almost_equal(np_hist, core_hist)
def velocity_profile_test(self):
self.set_particles()
# Set up the Observable.
obs = espressomd.observables.CylindricalVelocityProfile(
ids=range(
self.params['N']),
center=self.params['center'],
axis=self.params['axis'],
n_r_bins=self.params['n_r_bins'],
n_phi_bins=self.params['n_phi_bins'],
n_z_bins=self.params['n_z_bins'],
min_r=self.params['min_r'],
min_phi=self.params['min_phi'],
min_z=self.params['min_z'],
max_r=self.params['max_r'],
max_phi=self.params['max_phi'],
max_z=self.params['max_z'])
core_hist = np.array(
obs.calculate()).reshape(
self.params['n_r_bins'],
self.params['n_phi_bins'],
self.params['n_z_bins'],
3)
core_hist_v_r = core_hist[:, :, :, 0]
core_hist_v_phi = core_hist[:, :, :, 1]
core_hist_v_z = core_hist[:, :, :, 2]
np_hist = self.calculate_numpy_histogram()
np.testing.assert_array_almost_equal(np_hist * self.v_r, core_hist_v_r)
np.testing.assert_array_almost_equal(np_hist * self.v_phi, core_hist_v_phi)
np.testing.assert_array_almost_equal(np_hist * self.v_z, core_hist_v_z)
def flux_density_profile_test(self):
self.set_particles()
# Set up the Observable.
@@ -169,6 +203,7 @@ def flux_density_profile_test(self):
core_hist_v_phi = core_hist[:, :, :, 1]
core_hist_v_z = core_hist[:, :, :, 2]
np_hist = self.calculate_numpy_histogram()
np_hist = self.normalize_with_bin_volume(np_hist)
np.testing.assert_array_almost_equal(np_hist * self.v_r, core_hist_v_r)
np.testing.assert_array_almost_equal(np_hist * self.v_phi, core_hist_v_phi)
np.testing.assert_array_almost_equal(np_hist * self.v_z, core_hist_v_z)

0 comments on commit aabcb37

Please sign in to comment.