How to get the shape_value at the quadrature point in the reference cell?

56 views
Skip to first unread message

Michael Lee

unread,
Sep 10, 2021, 6:48:35 PM9/10/21
to deal.II User Group
Deal deal.ii comunity,

I want to require the value of a shape function at some quadrature point. But the following code throws an error saying finite_element_output is protected.
     double shape_value = fe_values.finite_element_output.shape_values(i, q_index);

For a 2D bilinear element, I expect the shape values  at the cell center(kesi=0, eta=0) are 0.25 for all the 4 shape functions.
              Screenshot 2021-09-10 164654.png
Is there other way to acquire this information?

Best,
Michael

Thang W Pham

unread,
Sep 11, 2021, 2:20:28 AM9/11/21
to deal.II User Group
Hi Michael,
I think you should have a look at FE_Q (Lagrange elements) at this link. In deal.II, the reference cell's domain is [0,1]^2 for 2d element. So, the point you are about to evaluate (to get the value of phi_i equal 0.25)  is (0.5, 0.5).
You can refer to this snippet:
/*
  const FE_Q<2> Q_2d_element(1);
  const Point<2> center(0.5, 0.5);
  for(int i=0; i<Q_2d_element.n_dofs_per_cell(); i++){
    std::cout << Q_2d_element.shape_value(i, center) << std::endl;
  }
*/
//output 0.25 0.25 0.25 0.25
Also  have a look at step-3 to understand how FE_Q works in real problem since the shape functions will be evaluated at real cell coordinates. Good luck.

Regards,
T.P

Vào lúc 07:48:35 UTC+9 ngày Thứ Bảy, 11 tháng 9, 2021, lian...@gmail.com đã viết:

Michael Li

unread,
Sep 11, 2021, 11:45:15 AM9/11/21
to dea...@googlegroups.com

Hi Dear Thang,

Thank you for you code snippet! It is simple and works well and is what I want. The link helps me understand the shape function in deal.ii.

 

Have a good weekend!

Michael

              

Is there other way to acquire this information?

 

Best,

Michael

--
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/b939b310-fd2b-46ee-83fa-59b46e6f9130n%40googlegroups.com.

 

Wolfgang Bangerth

unread,
Sep 12, 2021, 7:13:22 PM9/12/21
to dea...@googlegroups.com
On 9/10/21 4:48 PM, Michael Lee wrote:
>
> I want to require the value of a shape function at some quadrature point. But
> the following code throws an error saying finite_element_output is protected.
> double shape_value = fe_values.finite_element_output.shape_values(i, q_index);
>

You already solved the problem, but just for completeness: You get the error
because you try to access a 'protected' member variable called 'shape_values'
(plural). What you want is to use the 'public' member function 'shape_value'
(singular).

Best
W.

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

Michael Li

unread,
Sep 12, 2021, 8:15:44 PM9/12/21
to dea...@googlegroups.com

Dr. Bangerth,

 

Thank you for your hints. I tried using shape_value, but it seems  finite_element_output is a protected member. The error shows as follows:

 

error: ‘dealii::internal::FEValuesImplementation::FiniteElementRelatedData<2, 2> dealii::FEValuesBase<2, 2>::finite_element_output’ is protected within this context

   59 |           double shape_value = fe_values.finite_element_output.shape_value(i, q_index);

                                                                               ^~~~~~~~~~~~~~~~~~~~~

error: ‘class dealii::internal::FEValuesImplementation::FiniteElementRelatedData<2, 2>’ has no member named ‘shape_value’; did you mean ‘shape_values’?

 

 

By the way, I also want to get the shape_grad of the reference cell to compare with some other code implementation regarding shape function.

 

Based on Thong’s method, the following codes gives me the desired results for a Q1 element:

  const FE_Q<2> Q_2d_element(1);

  const Point<2> center(11);

  for(unsigned int i=0; i<Q_2d_element.n_dofs_per_cell(); i++)

  {

    std::cout << " shape value = " << Q_2d_element.shape_value(i, center);

    std::cout << " shape grad = "  << Q_2d_element.shape_grad(i, center) << std::endl;

  }

 

I wonder if there are other ways to access the shape_grad on the ref cell directly. Do I need to use fe_values.inverse_jacobian(q_index) to convert from shape_grad on the real cell to the reference cell?

 

 

Best,

Michael

--

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,
Sep 12, 2021, 10:58:23 PM9/12/21
to dea...@googlegroups.com
On 9/12/21 6:15 PM, Michael Li wrote:
> Thank you for your hints. I tried using *shape_value*, but it seems
> finite_element_output is a protected member. The error shows as follows:
>
> error*: ‘dealii::internal::FEValuesImplementation::FiniteElementRelatedData<2,
> 2> dealii::FEValuesBase<2, 2>::finite_element_output’* is protected within
> this context
>
>    59 |           double shape_value =
> fe_values.finite_element_output.shape_value(i, q_index);
>
> ^~~~~~~~~~~~~~~~~~~~~
>
> *error: ‘class
> dealii::internal::FEValuesImplementation::FiniteElementRelatedData<2, 2>’ has
> no member named ‘shape_value’; did you mean‘shape_values’?*

Where does the reference to finite_element_output come from? You just need
fe_values.shape_value(i,q_index);
Take a look at any of the tutorial programs -- they all use this syntax, and
they're usually quite a good illustration of how things are typically done
with deal.II :-)


> By the way, I also want to get the *shape_grad* of the reference cell to
> compare with some other code implementation regarding shape function.
>
> Based on Thong’s method, the following codes gives me the desired results for
> a Q1 element:
>
> const FE_Q<2> Q_2d_element(1);
>
> const Point<2> center(1, 1);

That's not the center of the cell :-)


> for(unsignedint i=0; i<Q_2d_element.n_dofs_per_cell(); i++)
>
>   {
>
>     std::cout << " shape value = "<< Q_2d_element.shape_value(i, center);
>
>     std::cout << " shape grad = " <<
> Q_2d_element.shape_grad(i, center) << std::endl;
>
>   }
>
> I wonder if there are other ways to access the shape_grad on the ref cell
> directly. Do I need to use *fe_values.inverse_jacobian(q_index) *to convert
> from *shape_grad* on the real cell to the reference cell?

If you ask the finite element object, you will get the values, gradients, ...
of the shape functions on the reference cell. If you ask the FEValues object,
you will get the values, gradients, ... of the shape functions on a concrete cell.
Reply all
Reply to author
Forward
0 new messages