plugged
November 26, 2019, 12:49pm
2
Maybe take a look at these, and try to implement your code in C++, this will make it much faster than using a UserExpression, that uses python to do the computations
Thanks Kamensky!
Just to add: Using the Eigen::Ref<> template instead of py::array_t<> , pybind11 casts numpy arrays directly and also gives access to the Eigen library methods.
i.e Change npArray definition to
typedef Eigen::Ref<Eigen::VectorXd> npArray;
arr declaration to npArray arr;
and the constructor method to
test_exp(npArray a) : dolfin::Expression(), arr(a) {}
This can help in using Eigen Methods e.g arr.sum() in the eval method.
My goal is to speed up the evaluation of the SubDomain Gamma
from dolfin import *
mesh = UnitSquareMesh(50,50, 'left/right')
PHI = FunctionSpace(mesh, 'CG', 1)
phi_expr = Expression('2.0*(1.0 - x[0])*x[0] + 0.2 - x[1]', degree=2)
phi = interpolate(phi_expr , PHI)
File("phi_initial.pvd") << phi
class Gamma(SubDomain):
def inside(self, x, on_boundary):
return phi(x) > 0.5
with a C++ expression as follows
omega_out_code = """
#include <pybin…
1 Like