Hi,
I need to evaluate an integral within an expression class (see below) but it is running extremely slow when using tplquad in scipy.
Do you guys have any suggestions to speed it up?
Would defining the expression in C++ and calling an integrator in C++ speed up the process?
Thanks!
class Integration(Expression):
def __init__(self, ulimit=0.001, mesh=mesh):
self.ulimit = ulimit
self.mesh = mesh
def diff_volume(self, p,t,r):
return r**2*sin(p)
def eval(self, value, x):
upper=project(self.ulimit,FunctionSpace(self.mesh, "CG", 1))
upper_array = upper.vector().array()
r1 = 0.
r2 = 1.
# limits for theta
t1 = 0
t2 = 2*pi
# limits for phi
p1 = 0
p2 = pi
results = []
for p in upper_array:
triple_Res = tplquad(self.diff_volume, r1, r2, lambda r: t1, lambda r: t2,
lambda r,t: p1, lambda r,t: p)[0]
results.append(triple_Res)
results = np.array(results)
S = FunctionSpace(mesh, 'CG', 1)
results_exp = Function(S)
results_exp.vector()[:] = results;
value[0] = results_exp(x[0], x[1], x[2]);