shape function gradient at arbitrary points in the element

42 views
Skip to first unread message

Simon

unread,
Jul 5, 2022, 9:56:31 AM7/5/22
to deal.II User Group
Dear all:

I have to compute the gradient with respect to real space co-ordinates of the shape functions belonging to a FE_Q element at arbitrary points in the element, that is, not only at quadrature points.

What is the way to do this in dealii?
FEValues provides shape function values, gradients,... only at quadrature points.

Thank you,
Simon

Martin Kronbichler

unread,
Jul 5, 2022, 11:16:18 AM7/5/22
to dea...@googlegroups.com

Dear Simon,

We have the class FEPointEvalation, https://dealii.org/developer/doxygen/deal.II/classFEPointEvaluation.html , which implements the operation of evaluating a solution at arbitrary points (as handed in as an array to points in unit coordinates). To do this for positions in real coordinates, you typically need to invert the mapping, Mapping::transform_real_to_unit_cell or Mapping::transform_points_real_to_unit_cell, see https://dealii.org/developer/doxygen/deal.II/classMapping.html , always assuming that you have located the correct points. Most tasks can be reduced to this setup.

If your intent is not just the solution interpolation but the value of shape functions, e.g. because you want to assemble a local matrix, FEPointEvaluation is not directly providing that info, so in that case the recommendation would be to use FEValues, despite that being terribly inefficient. We could possibly integrate such functionality into FEPointEvaluation if you have interest in that direction, so let us know what your needs are.

Best,
Martin

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/16afc8fa-bcfe-4a81-9ade-040c18f85596n%40googlegroups.com.

Simon Wiesheier

unread,
Jul 5, 2022, 11:29:25 AM7/5/22
to dea...@googlegroups.com
Dear Martin,

thanks for pointing out to the FEPointEvaluation class.
However, my intent is to compute the gradients of shape functions in real coordinates.

" so in that case the recommendation would be to use FEValues, despite that being terribly inefficient."

What is the approach to achieve this?
My only idea is to create a new FEValues object for each quadrature point and pass an appropriate Quadrature object. But seems to be very inefficient.
Is there an alternative way in combination with FEValues?

Best,
Simon


Wolfgang Bangerth

unread,
Jul 6, 2022, 9:45:01 PM7/6/22
to dea...@googlegroups.com
On 7/5/22 09:28, Simon Wiesheier wrote:
>
> What is the approach to achieve this?
> My only idea is to create a new FEValues object for each quadrature point and
> pass an appropriate Quadrature object. But seems to be very inefficient.

This is basically what the VectorTools::point_value() and
VectorTools::point_gradient() functions do. You might want to read through
their implementations to see how this is done.

The only other approach is with classes like FEPointEvaluation. If you read
through their implementation, you might be able to understand how they can
also be used to evaluate just a single shape function. In the end, the values
and gradients of a single shape function correspond to the values and
gradients of a finite element field that corresponds to a solution vector with
one 1.0 and the rest of the elements set to zero.

Best
W.


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

Simon Wiesheier

unread,
Jul 7, 2022, 4:35:07 AM7/7/22
to dea...@googlegroups.com
Just to make sure that I chose a reasonable approach:

//create FEValues object whenever I need it, that is, 'number_of_cells*number_of_qps_per_cell' times
FEValues<2> fe_values(dof_handler.get_fe(),
                                       Quadrature<2>(my_point_in_ref_coords),
                                       update_gradients);
fe_values.reinit(cell);

//evaluate, say, the gradient of the second shape function in real coords at "my_point_in_ref_coords"
Tensor<1,2> shape_gradient_real_second = fe_values.shape_grad(1, 0);

Without measuring the time but based on your intuition - the approach using FEPointEvaluation would not be much faster, would it?

Best
Simon



--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.

Wolfgang Bangerth

unread,
Jul 7, 2022, 9:36:22 AM7/7/22
to dea...@googlegroups.com
On 7/7/22 02:34, Simon Wiesheier wrote:
> Just to make sure that I chose a reasonable approach:
>
> //create FEValues object whenever I need it, that is,
> 'number_of_cells*number_of_qps_per_cell' times
> FEValues<2> fe_values(dof_handler.get_fe(),
>                                        Quadrature<2>(my_point_in_ref_coords),
>                                        update_gradients);
> fe_values.reinit(cell);
>
> //evaluate, say, the gradient of the second shape function in real coords at
> "my_point_in_ref_coords"
> Tensor<1,2> shape_gradient_real_second = fe_values.shape_grad(1, 0);

Yes, this looks reasonable.


> Without measuring the time but based on your intuition - the approach using
> FEPointEvaluation would not be much faster, would it?

Even good programmers cannot say which versions of code perform better or
worse without actually benchmarking. You'll have to try it out. I suspect that
the overall cost is dominated by computing the reference coordinates of an
arbitrary point, but I don't know for sure.
Reply all
Reply to author
Forward
0 new messages