calculation of the L2-norm using "integrate_difference" - mismatch with own test case

49 views
Skip to first unread message

Simon

unread,
May 12, 2021, 10:47:42 AM5/12/21
to deal.II User Group

Dear all,

I want to compute the L2-norm for a large number of scalar history-variables. The solution vectors for all of them are stored in the following container: "std::vector<Vector<double>>(num_of_history_variables)".
So far I called integrate_difference " num_of_history_variables" times, which is quite time consuming. Thus, I´d like to compute the L2-norm by myself to get a second time measurement and may save in the first call some time reducing information which integrate_differnce doesn´t provide for subsequent calls.

In order to do so, I compared for a arbitrary history variable the vector of cell errors, calculated from integrate_differnce, with those cell errors of my own implementation. Unfortunately I don´t come up with the same cell error(s).

In the following is a snippet of my code, some remarks for a better understanding:
(I access my history variables via a CellDataStorage object. The Variable "comp_0" is the value at the QP of my current mesh, the variable "comp_0_ref" is the corresponding value of the reference solution on the same QP).
------------------------------------------------------------------------------------------------
Functions::FEFieldFunction<dim> fe_field(dof_handler_scalar_ar, reference_solution_n[0]);

cell=dof_handler_scalar.begin_active();
for(; cell!=endc; cell++)
{
fe_values.reinit(cell);

std::vector<std::shared_ptr<PointHistory<dim>>> lqph =          quadrature_point_history.get_data(cell);

double error_cell=0;
        
     for(unsigned int q=0; q<qf_cell.size(); q++)
     {
     const double JxW = fe_values.JxW(q);

     Vector<double> projection_variables = lqph[q]->create_vector_for_projection();
     double comp_0 = projection_variables(0);

     error_cell += ((comp_0 - comp_0_ref)*(comp_0 - comp_0_ref)*JxW);
     }
std::cout<<"Local cell error: "<<std::sqrt(error_cell)<<" , ";
}
------------------------------------------------------------------------------------------

I had a look in the implementation of the integrate_difference function with case == L2 as well.
However I could not identify any differences to my own implementation.

My question is if there is a mistake in my code snippet, i.e in the way how I calculate the integrals for the cell errors?
On each cell, I basically multiply the squared abs-value of the difference with the JxW-Value, sum those values up and finally take the square root.

Thanks in advance for helping!

Best
Simon

Simon

unread,
May 13, 2021, 2:19:42 PM5/13/21
to deal.II User Group
By the way, I forgot to mention how I acutally compute the variable "comp_0_ref", which is potentially the place where the difference may come from.
I do this by simply asking the initialized FE Field function:
double comp_0_ref = fe_field.value(fe_values.quadrature_point(q));

For my understanding of the L2-Norm this is acutally the value that I need, i.e. I need the value of the reference solution at the qps of my current solution, do I?

-Simon

Wolfgang Bangerth

unread,
May 14, 2021, 6:20:42 PM5/14/21
to dea...@googlegroups.com, Simon
Yes, this looks correct to me, but I don't know what the PointHistory class
does and what create_vector_for_projection() does or return.

To start figuring out where things go wrong, first determine whether comp_0 or
comp_0_ref are wrong. You could, for example, compute their L2 norms
separately and compare with what you have.

Best
W.


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Reply all
Reply to author
Forward
0 new messages