Dear all,
I have a question: I'm porting a python project to UFL/C++, but I am encountering errors. All the code I am posting here is inspired by the undocumented/dg-poisson/cpp/
demo.
The error is the following:
*** Error: Unable to assemble form.
*** Reason: Invalid value rank for coefficient 1 (got 0 but expecting 1). You might have forgotten to specify the value rank correctly in an Expression subclass.
*** Where: This error was encountered inside AssemblerBase.cpp.
The test is easy: a plate clamped at the bottom and pulled at the top, so one Dirichlet and one Neumann BCs. In my UFL I have (here only the relevant parts, no bulk forces):
cell = triangle
element = VectorElement("Lagrange", cell, 2)
u = TrialFunction(element)
v = TestFunction(element)
force_vector = Coefficient(element)
# Known term
L = inner(force_vector, v) * ds(1)
My C++ main file is this:
// Neumann BCs
EdgeForceExpression force;
// Boundary markers set by default to 0 (MAYBE!)
FacetFunction<std::size_t> boundary_markers(mesh, 0);
// Mark the edge with load as 1
top.mark(boundary_markers, 1);
// Set loads RHS
L.f = f_bulk;
// L.force_vector = f_surf;
L.force_vector = force;
L.ds = boundary_markers;
You can see that force_vector
is assigned a force
object, this is an instance of the following class:
// Force on an edge
class EdgeForceExpression : public Expression
{
void eval(Array<double>& values, const Array<double>& x) const
{
values[0] = 1.0e6;
values[1] = 0.0;
}
};
As you can see, in the main file there's a commented assignment for the force to f_surf
, defined as Constant f_surf(1.0e6, 0.0);
. If I use this, the program runs fine, and produces correct results.
Why can't I use the force as defined by eval
in the class? I cannot see how, but I'm a newbie in this...
Thanks!