I am trying to convert the following python UserExpression class for inflow boundary condition to C++ to make it more efficient.
class Inflow(UserExpression):
def __init__(self, param, mesh, **kwargs):
super(Inflow, self).__init__(**kwargs)
self.param = param
self.mesh = mesh
def eval_cell(self, values, x, ufc_cell):
# Create DOLFIN Cell
cell = Cell(self.mesh, ufc_cell.index)
# Get normal for current facet
assert(ufc_cell.local_facet >= 0)
n = cell.normal(ufc_cell.local_facet)
# Compute boundary value
t = self.param["time"].t
period = self.param["period"]
nm = self.param["nm"].cycle
Area = self.param["Area"]
Vsc = self.param["Vsc"]
Tsc = self.param["Tsc"]
func = self.param["func"]
val = (splev(t*Tsc - nm*period*Tsc, func)/Area)/Vsc
values[0] = -n.x()*val
values[1] = -n.y()*val
values[2] = -n.z()*val
def value_shape(self):
return (3,)
Here is my C++ code for the same class:
def Inflow1(param, mesh, degree):
t = param["time"].t
period = param["period"]
nm = param["nm"].cycle
Area = param["Area"]
Vsc = param["Vsc"]
Tsc = param["Tsc"]
func = param["func"]
val = (splev(t*Tsc - nm*period*Tsc, func)/Area)/Vsc
code = '''
#include <dolfin/function/Expression.h>
using namespace dolfin;
class InflowX : public Expression
{
public:
double v;
InflowX() : Expression(3) {}
void eval(Array<double>& values, const Array<double>& x,
const ufc::cell& c) const
{
const Cell cell(*cell_data->mesh(), c.index);
assert(c.local_facet >= 0);
double n_x cell.normal(c.local_facet, 0);
double n_y cell.normal(c.local_facet, 1);
double n_z cell.normal(c.local_facet, 2);
values[0] = -1*n_x*v
values[1] = -1*n_y*v
values[2] = -1*n_z*v
}
};'''
f = Expression(code, domain = mesh, degree = degree)
f.v = val
return f
This seems to be producing the following error.
File “/usr/local/lib/python3.6/dist-packages/dolfin/jit/jit.py”, line 170, in compile_class
raise RuntimeError(“Unable to compile C++ code with dijitso”)
RuntimeError: Unable to compile C++ code with dijitso
Any help to resolve this error would be appreciated? Thanks in advance.