CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

linear vs quadratic triangle and divergence theorem

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By praveen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 9, 2020, 06:38
Default linear vs quadratic triangle and divergence theorem
  #1
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Dear all,

In a classic 2D unstructured finite volume code with linear triangles, I always get using mid-point quadrature rule \int_{\partial\Omega}\vec{n}dS\approx \sum_{f\in faces} \vec{n_{f}}S_f=0 up to machine precision, where \vec{n_f} is unit normal and S_f edge length.

Now, let's say I have a triangle with two straight edges f_{s_1},f_{s_2} and one "quadratic" edge f_{c_3}, e.g. a curved edge defined with three points: \int_{\partial\Omega}\vec{n}dS\approx \sum_{f_{s_1},f_{s_2}} \vec{n_{f}}S_f+\int_{f_{c_3}}\vec{n}dS.

With 3 points defining my curved edge, I understand I can build a unique 2nd degree polynomial using Lagrange basis. Then I can approximate \int_{f_{c_3}}\vec{n}dS with a 3 points quadrature rule (Simpson if quadratic point is located at mid-distance).

Problem is that numerical test gives me an integral which is not machine 0.

With straight triangle edges, I understand mid-point rule is exact because the integrand is constant over the edge. In the same way, I expected Simpson's quadrature exact for 2nd degree polynomial and as such get 0 up to machine precision as well.

Am I missing something or I possibly made a mistake in my numerical tests ?
naffrancois is offline   Reply With Quote

Old   October 9, 2020, 08:08
Default
  #2
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
In what space is your curve defined. Perhaps you are confusing different reference spaces y(x), s(t). If your curve is a polynomial (quadratic) in x and y it might not be in s and t.

Note that the Jacobian determinante is defined as:

| \frac{ \partial (s,t) }{ \partial ( \xi, \eta)} |=  \frac{ \partial s}{ \partial \xi}  \frac{ \partial t}{ \partial \eta} -  \frac{ \partial s}{ \partial \eta}  \frac{ \partial t}{ \partial \xi},

or

| \frac{ \partial (x,y) }{ \partial ( \xi, \eta)} |=  \frac{ \partial x}{ \partial \xi}  \frac{ \partial y}{ \partial \eta} -  \frac{ \partial x}{ \partial \eta}  \frac{ \partial y}{ \partial \xi},

or

| \frac{ \partial (s,t) }{ \partial ( x, y)} |=  \frac{ \partial s}{ \partial x}  \frac{ \partial t}{ \partial y} -  \frac{ \partial s}{ \partial y}  \frac{ \partial t}{ \partial x}.

Regards


Edit: I doubt that it is possible to integrate 2-D curved elements (quadratic) with a simple Simpson rule. The 2-D case is different to the 1-D case.
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.
Eifoehn4 is offline   Reply With Quote

Old   October 9, 2020, 08:47
Default
  #3
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Thank you for your reply !

You are certainly right, I am confusing something for sure.

Let's say I have a straight triangle. I manually set 3 extra points somewhere in each edge bisector.

This way, my "curved edges" are circle arcs and my "quadratic points" are at equal distance to the vertices of the triangle.

Now I apply the quadrature along the three circle arcs. For each curved edges, I have three unit normals poiting outwards along the line joining the center to each nodes, the circle arc length and 1/6-4/6-1/6 weights. If I sum up these for the three edges, result is not 0.
Attached Images
File Type: png 2nd_order_elements.png (23.0 KB, 8 views)

Last edited by naffrancois; October 9, 2020 at 08:57. Reason: image
naffrancois is offline   Reply With Quote

Old   October 9, 2020, 09:02
Default
  #4
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
Are the normal vectors taken from the exact circle?

For a consistent integration you should take the normals given by the quadratic approximation. They are not identical. This might result in an integration error and therefore in geometric aliasing.
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.
Eifoehn4 is offline   Reply With Quote

Old   October 9, 2020, 09:27
Default
  #5
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
The normal vectors are indeed taken from the exact circle arcs.

For each edge, I simply compute from the 3 points (let's say index 1 and 2 are vertices and 3 the extra point) the center and radius of the circle arc passing through the points.

Then the normals are just \vec{n_{f_i}}=\frac{\vec{x_i}-\vec{x_c}}{||\vec{x_i}-\vec{x_c}||}.

Length of circle arc is obtained from radius, center and vertices coordinates as dl=r\cos^{-1}\left(\frac{(\vec{x_1}-\vec{x_c}).(\vec{x_2}-\vec{x_c})}{r^2}\right)

For each edge, I simply apply: dl\left( \frac{\vec{n_{f_1}}}{6}+\frac{4\vec{n_{f_3}}}{6} +\frac{\vec{n_{f_2}}}{6}\right)

Well... in fact neither dl nor r are polynomials in x and y, is it in line with what you suggested in your first post ? May I conclude that the error I get on the integration is due to this fact ?
naffrancois is offline   Reply With Quote

Old   October 9, 2020, 09:43
Default
  #6
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
The first step would be to calculate all lengths and derivatives (normals and tangentials) from your polynomial quadratic approximation. Because these are the correct metrics if you consider three points for each curve.

I am quite sure with this it should work. The only problem is, that you mix different metrics.

Simply be aware that you do not integrate the exact circle with three points. Otherwise you would have to use a number of infinity collocation points.
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.
Eifoehn4 is offline   Reply With Quote

Old   October 9, 2020, 10:06
Default
  #7
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Quote:
Originally Posted by Eifoehn4 View Post
The first step would be to calculate all lengths and derivatives (normals and tangentials) from your polynomial quadratic approximation. Because these are the correct metrics if you consider three points for each curve.

I am quite sure with this it should work. The only problem is, that you mix different metrics.

Simply be aware that you do not integrate the exact circle with three points. Otherwise you would have to use a number of infinity collocation points.
I think I understand now but am not sure I can state it clearly. What I am doing with this simple example is wrong because I apply a quadrature rule on an exact representation (circle arcs), then I would need many more quadrature points to eventually converge the error to zero.

On the other hand, let's say now I exclusively work with a polynomial representation of my curved edges, from which I extract lengths and derivatives to compute the normals. Then if this polynomial can be integrated exactly by the quadrature rule, then I would recover sum nds=0.

Many thanks for your help !
naffrancois is offline   Reply With Quote

Old   October 9, 2020, 10:23
Default
  #8
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
Yes! If you are considering nodal basis functions (Lagrange kernels) the only possibility is to increase the number of points respectively the uniquely linked quadrature rule.

You may also consider other basis functions, e.g. modal ones. With them you easily can integrate the circle exact with only one mode. However, in practice you are not able to describe arbitrary geometry shapes with algebraic functions.

Regards
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.
Eifoehn4 is offline   Reply With Quote

Old   October 9, 2020, 11:09
Default
  #9
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Many thanks for your answers, now I can go on
naffrancois is offline   Reply With Quote

Old   October 9, 2020, 13:39
Default
  #10
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,882
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I read only the original question, not the replies so I can be quite junk in my answer.

I want to stress an issue... The Simpson rule is exact for a 1D homogeneous distribution of nodes and a quadratic function, that is something like
Int[a,b] x^2 dx should be exactly computed by Simpson.
That means you have to transform you curved edge in a computational plane where it is a straight edge and you apply Simpson. But when you go back to the physical plane you have the metric.
Is that the problem you are discussing?
FMDenaro is offline   Reply With Quote

Old   October 9, 2020, 18:46
Default
  #11
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Thank you FMDenaro for your input. After the intervention of Eifoehn4 I thought I conceptually moved forward in the understanding but I am confused again. I feel I miss some concepts of calculus.

I will restate the problem. I have a 2D unstructured mesh composed of quadratic triangles, e.g. 6 nodes triangles. I use a finite volume code so I need area of element as well as length of edges and normals. I want to apply a high order flux integration over the edges so I need the normals at different locations on the edges. Obviously if edges are straight, no problem. Let's imagine a general quadratic triangle where "mid points" does not lie on the segments formed by the vertices.

What I have are x,y coordinates of the 6 triangle nodes, given by gmsh. At first I thought of a naive approach: constructing circle arcs for each edge passing through the 3 nodes. This way I could easily compute length of curved edges, area of element and normals. Problem occured when trying to apply 3 points quadrature integration per edge to compute \int\vec{n}dS. I do not get 0. As explained by Eifoehn4, if I understood correctly, this is because I am trying to integrate a circle arc which cannot be written as a 2nd order polynomial in an explicit form as y=f(x). If I increase the number of nodes in the quadrature the approximation of \int\vec{n}dS tends to 0, which makes sense.

So now I follow a different approach by constructing for each edge a quadratic polynomial \bold{x}(t)=\bold{a_0}+\bold{a_1}t+\bold{a_2}t^2 passing by the 3 nodes. But to compute curved edge length I think I need to evaluate the integral \int_0^1\sqrt{\bold{x'}(t).\bold{x'}(t)}dt. This integral seems to have a rather complicated analytic expression, then I guess I would have to integrate it numerically as well using a pretty high quadrature rule. Next, with the curved edges lengths in hand I thought of simply applying 3 points quadrature rule (assuming third node is located at mid distance on the curve this is Simpson, otherwise I have to calculate different weights) to compute \int\vec{n}dS.

Do you think this is the way to go or would you have some references to read ?

Many thanks for your help and advice !
naffrancois is offline   Reply With Quote

Old   October 12, 2020, 05:33
Default
  #12
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
Are you familiar with the creation of interpolation and differentiation matrices on triangles for arbitrary polynomial degrees?
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.
Eifoehn4 is offline   Reply With Quote

Old   October 12, 2020, 05:47
Default
  #13
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,882
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by naffrancois View Post
Thank you FMDenaro for your input. After the intervention of Eifoehn4 I thought I conceptually moved forward in the understanding but I am confused again. I feel I miss some concepts of calculus.

I will restate the problem. I have a 2D unstructured mesh composed of quadratic triangles, e.g. 6 nodes triangles. I use a finite volume code so I need area of element as well as length of edges and normals. I want to apply a high order flux integration over the edges so I need the normals at different locations on the edges. Obviously if edges are straight, no problem. Let's imagine a general quadratic triangle where "mid points" does not lie on the segments formed by the vertices.

What I have are x,y coordinates of the 6 triangle nodes, given by gmsh. At first I thought of a naive approach: constructing circle arcs for each edge passing through the 3 nodes. This way I could easily compute length of curved edges, area of element and normals. Problem occured when trying to apply 3 points quadrature integration per edge to compute \int\vec{n}dS. I do not get 0. As explained by Eifoehn4, if I understood correctly, this is because I am trying to integrate a circle arc which cannot be written as a 2nd order polynomial in an explicit form as y=f(x). If I increase the number of nodes in the quadrature the approximation of \int\vec{n}dS tends to 0, which makes sense.

So now I follow a different approach by constructing for each edge a quadratic polynomial \bold{x}(t)=\bold{a_0}+\bold{a_1}t+\bold{a_2}t^2 passing by the 3 nodes. But to compute curved edge length I think I need to evaluate the integral \int_0^1\sqrt{\bold{x'}(t).\bold{x'}(t)}dt. This integral seems to have a rather complicated analytic expression, then I guess I would have to integrate it numerically as well using a pretty high quadrature rule. Next, with the curved edges lengths in hand I thought of simply applying 3 points quadrature rule (assuming third node is located at mid distance on the curve this is Simpson, otherwise I have to calculate different weights) to compute \int\vec{n}dS.

Do you think this is the way to go or would you have some references to read ?

Many thanks for your help and advice !


Maybe you can find some suggestions here

https://www.researchgate.net/publica...mulation_codes

https://www.researchgate.net/publica...ructured_grids
FMDenaro is offline   Reply With Quote

Old   October 12, 2020, 05:49
Default
  #14
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Hello Eifoehn4,

Long time ago when I worked with structured boundary fitted grids I had to deal with grid metrics, mapping from physical->computational plane with chain rule and Jacobian. This is the furthest I went and I barely remember anything. Is this somehow related with your question ?
naffrancois is offline   Reply With Quote

Old   October 12, 2020, 05:50
Default
  #15
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
Hello FMDenaro,

Thank you for the suggestions, I will have a look.
naffrancois is offline   Reply With Quote

Old   October 12, 2020, 06:59
Default
  #16
Senior Member
 
Eifoehn4's Avatar
 
-
Join Date: Jul 2012
Location: Germany
Posts: 184
Rep Power: 14
Eifoehn4 is on a distinguished road
Quote:
Originally Posted by naffrancois View Post
Hello Eifoehn4,

Long time ago when I worked with structured boundary fitted grids I had to deal with grid metrics, mapping from physical->computational plane with chain rule and Jacobian. This is the furthest I went and I barely remember anything. Is this somehow related with your question ?
Yes, an easy way to calculate the curved metrics (normal, lengths, area) ist based on the application on these matrices. If i have some more time i will write something down. It's a little bit lengthy.
__________________
Check out my side project:

A multiphysics discontinuous Galerkin framework: Youtube, Gitlab.

Last edited by Eifoehn4; October 12, 2020 at 10:12.
Eifoehn4 is offline   Reply With Quote

Old   October 14, 2020, 17:09
Thumbs up
  #17
Senior Member
 
Join Date: Oct 2011
Posts: 242
Rep Power: 17
naffrancois is on a distinguished road
Many thanks Eifoehn4 and FMDenaro for your help.

Thanks to your hints I could get it working for a single general quadratic triangle. I used one set of 2nd degree shape functions for the triangle in order to get the area.

I used 3 sets of quadratic shape functions for the 3 curved segments to get edge integrals and normals.

It turns out that triangle area, edges lengths and normals have all analytic expression using a 2nd degree Lagrange representation (edge length expression is a bit lengthy though). I checked that using a formal calculus software.

I finally get \int\vec{n}dl=0 to machine precision using 3 points 1/6-4/6-1/6 quadrature on the mapped space.


edit: after reconsideration and following your comments I was doubtful about the exactness of simpson's rule, but under the 2nd degree mapping I get: \int_{\partial\Omega}\vec{n}dl=\sum_{f\in{1,3}}\left(\int_0^1\vec{n}_f(\xi)\sqrt{\left(\frac{\partial x_f}{\partial\xi}\right)^2+\left(\frac{\partial y_f}{\partial\xi}\right)^2}d\xi\right)=\sum_{f\in{1,3}}\left(\int_0^1\left[\frac{\partial y_f}{\partial\xi},-\frac{\partial x_f}{\partial\xi}\right]d\xi\right). The integrand is linear so the 3 points rule is exact

Last edited by naffrancois; October 15, 2020 at 06:42.
naffrancois is offline   Reply With Quote

Old   October 17, 2020, 01:35
Default
  #18
Super Moderator
 
Praveen. C
Join Date: Mar 2009
Location: Bangalore
Posts: 343
Blog Entries: 6
Rep Power: 18
praveen is on a distinguished road
Quote:
Originally Posted by naffrancois View Post
Many thanks Eifoehn4 and FMDenaro for your help.

Thanks to your hints I could get it working for a single general quadratic triangle. I used one set of 2nd degree shape functions for the triangle in order to get the area.

I used 3 sets of quadratic shape functions for the 3 curved segments to get edge integrals and normals.

It turns out that triangle area, edges lengths and normals have all analytic expression using a 2nd degree Lagrange representation (edge length expression is a bit lengthy though). I checked that using a formal calculus software.

I finally get \int\vec{n}dl=0 to machine precision using 3 points 1/6-4/6-1/6 quadrature on the mapped space.


edit: after reconsideration and following your comments I was doubtful about the exactness of simpson's rule, but under the 2nd degree mapping I get: \int_{\partial\Omega}\vec{n}dl=\sum_{f\in{1,3}}\left(\int_0^1\vec{n}_f(\xi)\sqrt{\left(\frac{\partial x_f}{\partial\xi}\right)^2+\left(\frac{\partial y_f}{\partial\xi}\right)^2}d\xi\right)=\sum_{f\in{1,3}}\left(\int_0^1\left[\frac{\partial y_f}{\partial\xi},-\frac{\partial x_f}{\partial\xi}\right]d\xi\right). The integrand is linear so the 3 points rule is exact
This is the right way. As you observed, the integrand is actually a linear function, so even a midpoint rule wrt \xi would be exact !!!
naffrancois likes this.
praveen is offline   Reply With Quote

Old   October 26, 2020, 07:27
Default
  #19
New Member
 
Join Date: Oct 2020
Posts: 2
Rep Power: 0
blancot is on a distinguished road
Thank you for your reply !


192.168.100.1 192.168.1.1 jpg to pdf

Last edited by blancot; October 27, 2020 at 14:09.
blancot is offline   Reply With Quote

Old   September 30, 2021, 10:29
Default
  #20
New Member
 
gail jacob
Join Date: Sep 2021
Posts: 1
Rep Power: 0
gail1jacob is on a distinguished road
Bear in mind that, for a given number of elements, quadratic elements allow better representation of a curved boundary.



paperwritingservice
gail1jacob is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 23:50.