Output relative errors

Hi all,

I am wondering for benchmark problems, is there a straight forward way to output relative errors? I understand dealii doesn’t have the method for that in the VectorTools namespace, so I am quite curious if there is any template to follow.

Thanks,
Regards,
Ray

The function in VectorTools exists alright.

I think you should take a look at how the error is computed for some of the
other benchmarks in the benchmarks/ folders.

Best
W.

Hi Wolfgang,

Thanks, but are you referring to VectorTools::L1_norm/L2_norm? Cause I thought those are just absolute error norm instead of relative ones with respect to exact solutions.

Regards,
Ray

Right. They give you the enumerator of the ratio. You just need the
denominator in that case, which I would choose as the maximum of the solution.
Or how exactly do you define “relative error”?

Best
W.

For the denominator, I am thinking of the exact solution at each cell. (i.e. || u - u_e || / || u_e || )

Ray

For the denominator, I am thinking of the exact solution at each cell. (i.e.

u - u_e || / || u_e || )

The usual way to do this would actually be to divide by

u_e ||
which is something that you can easily get by writing it as

0 - u_e ||
which in turn you can get by calling VectorTools::integrate_difference() where
instead of the exact solution you pass Functions::ZeroFunction instead.

Best
W.

Somehow I produced an error that “expected primary expression before ‘)’ token”

My code for VectorTools::Integrate_difference is like the following,

 VectorTools::integrate_difference (this->get_mapping(),
				 this->get_dof_handler(),
				 this->get_solution(),
				 Functions::ZeroFunction<dim>(),
				 cellwise_errors_uhl2,
				 quadrature_formula,
				 VectorTools::L2_norm,
				 &comp_uh);

I was trying to follow the syntax in the dealii tutorial step-64, but I am wondering if I have to fill in some additional expressions.

Thanks in advance,
Ray

I was trying to follow the syntax in the dealii tutorial step-64, but I am
wondering if I have to fill in some additional expressions.

You’ll have to show us more of the code and what line the error message
corresponds. It’s possible that &comp_uh causes the problem that you’re
seeing, but I don’t know what comp_uh actually is.

Once it compiles, you will get a run-time error because
Functions::ZeroFunction()
creates a scalar function object, but you need one that has as many vector
components as the solution vector has components. That number should go into
the parentheses.

Best
W.

Hi Wolfgang,

Sorry for not making this clear, but I believe I have figured out the problem.

First for “comp_uh”, this is just a variable for the “ComponentSelectFunction” in this case, but it may not be necessary as normal “comp_u” (or comp_p for pressure) also works.

Second, indeed I need to fill the number of components in the parentheses, but it still produces the error of “error: reference to ‘ZeroFunction’ is ambiguous”, so instead of using Functions:ZeroFunction(), I just called ZeroFunction(), which somehow resolved the issue.

Again much appreciated of your help, thanks a lot.
Ray