Hi, consider
#include <dolfin.h>
#include "potential.h"
/* potential.ufl
cell = tetrahedron
S = FiniteElement('Lagrange', cell, 1)
V = VectorElement('Lagrange', cell, 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Coefficient(S)
# Solve u = -nabla_grad(f)
a = inner(u, v)*dx
L = inner(-nabla_grad(f), v)*dx
*/
using namespace dolfin;
class Source : public Expression
{
void eval(Array<double>& values, const Array<double>& x) const
{
values[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2];
}
};
int main()
{
BoxMesh mesh(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 4, 4, 4);
potential::FunctionSpace V(mesh);
potential::CoefficientSpace_f S(mesh);
Source f_exp;
Function f(S);
f.interpolate(f_exp);
potential::BilinearForm a(V, V);
potential::LinearForm L(V);
L.f = f;
Function u(V);
solve(a == L, u);
plot(f);
plot(u);
interactive();
return 0;
}