Approximate Derivative Tensor functionality

26 views
Skip to first unread message

Sumedh Yadav

unread,
Feb 15, 2017, 6:12:55 AM2/15/17
to deal.II User Group
Hey there!
For cell-wise error estimation calculations, I want to use the 'approximate_gradient', 'approximate_derivative_tensor' and similar functionality available in 'DerivativeApproximation' namespace (here). So I made the appropriate function calls and here is the code-snippet of it -

      Tensor<2,2> cell_hessian;
      Tensor<1,2> cell_grad;
      float magnitude = 0.;
    DoFHandler<2>::active_cell_iterator
    cell = dof_handler.begin_active(),
    endc = dof_handler.end();
    for (; cell!=endc; ++cell)
      {
        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, unsigned int);
        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, unsigned int);
        magnitude = DerivativeApproximation::derivative_norm(cell_grad);
     ...

I get compilation errors and couldn't find why?
The errors:
   solver1.cc:171:98: error: expected primary-expression before ‘unsigned’
   DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, unsigned int);
                                                                                                                                              ^
   solver1.cc:173:101: error: expected primary-expression before ‘unsigned’
   DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, unsigned int);
                                                                                                                                                  ^
   I do understand that the tensor argument is passed wrong, but can't figure out? I do have proper dof_handler, solution objects.
   Please point out the mistake, thank you in advance!

Jean-Paul Pelteret

unread,
Feb 15, 2017, 7:20:36 AM2/15/17
to deal.II User Group
Hi Sumedh,

The highlighted parts look suspicious:


        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, unsigned int);
        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, unsigned int);

You were probably wanting to send in a component value as this particular argument.

Regards,
Jean-Paul

Sumedh Yadav

unread,
Feb 15, 2017, 10:03:28 AM2/15/17
to deal.II User Group
Hey Jean,
Thank you for the reply.
I understood what you mean to imply, but I still get compilation errors.
The modified code-snippet:

        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, unsigned int a = 0);
        DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, const unsigned int a = 0);

 The error:
solver1.cc:172:102: error: expected primary-expression before ‘unsigned’
       DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, unsigned int a = 0);
                                                                                                                                                  ^
solver1.cc:174:105: error: expected primary-expression before ‘const’
       DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, const unsigned int a = 0);
                                                                                                                                                      ^
I comprehend that component argument passing should not be a problem since it is by default = 0 (and I have only 1 scalar field). The syntax error shall be coming from the tensors cell_grad and cell_hessian.

Bruno Turcksin

unread,
Feb 15, 2017, 10:36:20 AM2/15/17
to deal.II User Group
Sumedh,

use DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad) or DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad, 0)

Best,

Bruno

Jean-Paul Pelteret

unread,
Feb 15, 2017, 10:58:06 AM2/15/17
to deal.II User Group
Dear Sumedh,

What Bruno has said is exactly what I would have suggested.

Best,
Jean-Paul

Sumedh Yadav

unread,
Feb 15, 2017, 10:59:03 AM2/15/17
to deal.II User Group
Hey Bruno,
Thanks for the reply!
But either suggestions didn't work. The code-snippet:
            DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad);
            DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_hessian, 0);
Errors:
             solver1.cc:172:100: error: no matching function for call to ‘approximate_derivative_tensor(dealii::DoFHandler<2>&, dealii::Vector<double>&, dealii::DoFHandler<2>::active_cell_iterator&, dealii::Tensor<1, 2, double>&)’
       DerivativeApproximation::approximate_derivative_tensor(dof_handler, solution, cell, cell_grad);
                                                                                                                                    ^
 The same error for the second function call as well. It is kind of funny that the same logic to omit the last function argument (with a default value) works for the following function call:

        DerivativeApproximation::approximate_gradient(dof_handler, solution, check);

Here check is declared as -   Vector<float> check(triangulation.n_active_cells());
whereas cell matrices as   -   Tensor<2,2, float> cell_hessian;
                                       -    Tensor<1,2, float> cell_grad;



On Wednesday, 15 February 2017 16:42:55 UTC+5:30, Sumedh Yadav wrote:

Jean-Paul Pelteret

unread,
Feb 15, 2017, 11:38:12 AM2/15/17
to deal.II User Group
Dear Sumedh,

The following works for me with version 8.4.1. For some reason it is necessary to supply some template arguments to this function - this could probably be improved. I'll open an issue about this.

#include <deal.II/base/tensor.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/lac/vector.h>
#include <deal.II/numerics/derivative_approximation.h>

using namespace dealii;

int main ()
{
  Triangulation<2,2> triangulation;
  DoFHandler<2,2> dof_handler;
  Vector<double> solution;

  Tensor<1,2> cell_grad;
  Tensor<2,2> cell_hessian;

  DoFHandler<2>::active_cell_iterator
  cell = dof_handler.begin_active(),
  endc = dof_handler.end();
  for (; cell!=endc; ++cell)
  {
    DerivativeApproximation::approximate_derivative_tensor<DoFHandler<2>,2,2>(dof_handler, solution, cell, cell_grad);
    DerivativeApproximation::approximate_derivative_tensor<DoFHandler<2>,2,2>(dof_handler, solution, cell, cell_hessian);
  }

  return 0;
}



I hope that this helps fix your problem.

Best,
Jean-Paul

Sumedh Yadav

unread,
Feb 15, 2017, 10:27:27 PM2/15/17
to deal.II User Group
Hey Jean,
Thanks for the reply, it seems to work for me as well!
I just had a query, when supplying <DoFHandler<2>,2,2> these template arguments I suppose the highlighted 2 is for the rank of tensor? If yes then as I also need to call the function for cell_grad<1,2> I should then be supplying <DoFHandler<2>,1,2> as template arguments. But supplying 1 in place of 2 doesn't work!


On Wednesday, 15 February 2017 16:42:55 UTC+5:30, Sumedh Yadav wrote:

Wolfgang Bangerth

unread,
Feb 15, 2017, 11:43:34 PM2/15/17
to dea...@googlegroups.com
On 02/15/2017 08:27 PM, Sumedh Yadav wrote:
>
> I just had a query, when supplying <DoFHandler<2>,2,2> these template
> arguments I suppose the highlighted 2 is for the rank of tensor?

Not quite. The template list for the function looks like this:

template<typename DoFHandlerType ,
int dim,
int spacedim,
class InputVector ,
int order>

> If yes then
> as I also need to call the function for cell_grad<1,2> I should then be
> supplying <DoFHandler<2>,1,2> as template arguments. But supplying 1 in place
> of 2 doesn't work!

Because it refers to the dimension, not the order of the tensor. It turns out
that you can safely let the compiler determine the order itself, depending on
the argument you provide.

Best
W.

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

Reply all
Reply to author
Forward
0 new messages