Skip to content

Commit

Permalink
Use _integrate_over_unit_sphere() to perform trapeze integration and …
Browse files Browse the repository at this point in the history
…estimate the surface of the sphere
  • Loading branch information
DorianDepriester committed Jan 14, 2025
1 parent 1a08cae commit 1828b88
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Elasticipy/SphericalFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,8 @@ def fun(theta, phi):
elif method == 'trapezoid':
angles, evals = self.evaluate_on_spherical_grid(n_evals)
phi, theta = angles
sine = np.sin(theta)
return integrate.trapezoid(
integrate.trapezoid(evals * sine, axis=0, x=phi[:,0]),
x=theta[0,:]) / dom_size
dom_size = _integrate_over_unit_sphere(phi, theta)
return _integrate_over_unit_sphere(phi, theta, values=evals) / dom_size
else:
u = uniform_spherical_distribution(n_evals, seed=seed)
return np.mean(self.eval(u))
Expand Down Expand Up @@ -436,10 +434,8 @@ def fun(theta, phi):
mean = self.mean(method="trapezoid")
angles, evals = self.evaluate_on_spherical_grid(n_evals)
phi, theta = angles
sine = np.sin(theta)
return integrate.trapezoid(
integrate.trapezoid((evals - mean)**2 * sine, axis=0, x=phi[:,0]),
x=theta[0,:]) / dom_size
dom_size = _integrate_over_unit_sphere(phi, theta)
return _integrate_over_unit_sphere(phi, theta, values=(evals - mean)**2) / dom_size
else:
u = uniform_spherical_distribution(n_evals, seed=seed)
return np.var(self.eval(u))
Expand Down

0 comments on commit 1828b88

Please sign in to comment.