how to calculate the total energy?

65 views
Skip to first unread message

Yiyang Zhang

unread,
Sep 15, 2017, 10:32:36 AM9/15/17
to deal.II User Group
For example, consider the sine-Gordon equation, which is in Step-25. 
With the help of the DataPostprocessor class, we can output a plot for the energy density.
But then, how could we calculate the total energy?

The best scenario would be computing the energy density and total energy at the same time...

Wolfgang Bangerth

unread,
Sep 15, 2017, 12:19:01 PM9/15/17
to dea...@googlegroups.com
Yiyang -- it's not easily possible to do it both at the same time
(because DataPostprocessor only creates output, but not do any kind of
integration -- so you are missing some information). But it's easy to do
by hand. For example, for the Laplace equation, you would do something
like this (pseudo-code):

double compute_energy ()
{
FEValues fe_values (...);
std::vector<Tensor<1,dim> > solution_gradients (n_q_points);

double energy = 0;

for (cell=...)
{
fe_values.reinit(cell);
fe_values.get_function_gradients (solution,
solution_gradients);

for (q=0...n_q_points)
energy += solution_gradients[q] * solution_gradients[q] *
fe_values.JxW(q);
}

return energy;
}

Best
W.

Yiyang Zhang

unread,
Sep 15, 2017, 4:10:44 PM9/15/17
to deal.II User Group
Thank you so much, Prof. Bangerth. 

llf m

unread,
Jun 3, 2019, 8:50:25 PM6/3/19
to deal.II User Group
Dear Wolfgang,
how to do this in distributed parallel mode( to sum up the energy in all processors)?
as the vector and matrix has the "compress(...::add)" function,
what about a scalar?

在 2017年9月16日星期六 UTC+8上午12:19:01,Wolfgang Bangerth写道:

llf m

unread,
Jun 3, 2019, 9:52:16 PM6/3/19
to deal.II User Group
Sorry, I misused the Utilities::MPI::sum() function and thought it might not work right at first.
Now I use the Utilities::MPI::sum() function to sum up the energy in all processors, is that right? 

在 2019年6月4日星期二 UTC+8上午8:50:25,llf m写道:

Wolfgang Bangerth

unread,
Jun 3, 2019, 11:15:27 PM6/3/19
to dea...@googlegroups.com
On 6/3/19 7:52 PM, llf m wrote:
> Sorry, I misused the Utilities::MPI::sum() function and thought it might not
> work right at first.
> Now I use the Utilities::MPI::sum() function to sum up the energy in all
> processors, is that right?

Yes -- each processor loops over its locally owned cells, and then you use the
function above to sum up over all processors.

Best
W.

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

Reply all
Reply to author
Forward
0 new messages