I am overriding the value and the gradient member functions in the TensorFunction class then similar to step 7 I am using compute_global_error to compute the L2: and H1 norms. I have to convert my TensorFunction to a vector valued function in order to do this using VectorFunctionFromTensorFunction<dim>.
I am getting an exception thrown when I ask for the H1 norm saying that the gradient operator is not overridden.
Here is a sketch of the code:
class Exact : public TensorFunction<1, dim>
{
public:
Exact() : TensorFunction<1, dim>(dim)
{
}
virtual Tensor<1, dim> value(const Point<dim> &p) const override;
virtual Tensor<2, dim> gradient(const Point<dim> &p) const override;
};
Tensor<1, dim> Exact<dim>::value(const Point<dim> &p) const
{
return Tensor<1, dim>;
}
Tensor<2, dim> Exact<dim>::gradient(const Point<dim> &p) const
{
return Tensor<2, dim>;
}
int main()
{
//blablabla tri, dofs, fe..
// declate then convert tensor function
Exact<dim> exact_solution;
VectorFunctionFromTensorFunction<dim> exact_solution_vector_function(exact_solution, 0, dim);
//L2 works fine
VectorTools::integrate_difference(dof_handler,
solution,
exact_solution_vector_function,
difference_per_cell,
quadrature_formula,
VectorTools::L2_norm);
// THis throws exception
VectorTools::integrate_difference(dof_handler,
solution,
exact_solution_vector_function,
difference_per_cell,
quadrature_formula,
VectorTools::H1_seminorm);;
}
Doing something as simple as:
Point<dim> p1;
exact_solution_vector_function.value(p1);
exact_solution_vector_function.gradient(p1);
is raising the exception.
I attached the code with the cmake below too.