Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

How to calculate the error on the skeleton of mesh

More
4 years 5 months ago #2131 by Yongbin
#mesh
from netgen.geom2d import SplineGeometry
geo = SplineGeometry()
geo.AddRectangle( (0, 0), (1, 1))
mesh = Mesh( geo.GenerateMesh(maxh=1/16))
#
velocity = CoefficientFunction(UN.components[0:2])
err_u = sqrt (Integrate ( (velocity-exact_u)*(velocity-exact_u), mesh))
#
Now,I want to calculate the error on the skeleton of mesh, namely ,the L^2 error of mass flux jump [v_h] \cdot n
#tex
[tex] \sum_{F \in \mathcal{F}_{h}} \frac{1}{h_{F}}\left\| \llbracket {v}_{h} \rrbracket \cdot {n}_{F}\|_{L^{2}(F)}^{2}[/tex]
#\mathcal{F}_{h} stand for all facets of mesh
More
4 years 5 months ago #2132 by schruste
Hi Yongbin,

The simplest way to compute this quantity is by defining a bilinear form a so that a(u,u) coincides with your (sum of) integral(s). Then you Apply the bilinear form to your discrete solution u and take the inner product of the result with u again.

Best,
Christoph
The following user(s) said Thank You: Yongbin
More
4 years 5 months ago #2133 by Yongbin
Hi,Christoph,

Thank you very much for your reply. Sorry,I may not fully understand what you mean. This is my code for Stokes . I don't know how to calculate in my code. In addition,I also wonder, is there other way to calculate?

Thank you again!

Yongbin
More
4 years 5 months ago #2134 by schruste
Hi Yongbin,

Here is the code fitting your script. I use hybrid dg jumps here as you use a hybrid DG formulation:
Code:
a_jumps = BilinearForm(X) a_jumps += (ubar-uu)*(vbar-vv) * dx(element_boundary = True) AUNvec = UN.vec.CreateVector() a_jumps.Apply(UN.vec,AUNvec) jump_norm = sqrt(InnerProduct(AUNvec,UN.vec)) print(jump_norm)
Alternatively, if you are interested in the standard DG jumps the code looks as follows:
Code:
uuOther = CoefficientFunction((ux.Other(), uy.Other())) vvOther = CoefficientFunction((vx.Other(), vy.Other())) a_jumps = BilinearForm(X) a_jumps += (uuOther-uu)*(vvOther-vv) * dx(skeleton = True) AUNvec = UN.vec.CreateVector() a_jumps.Apply(UN.vec,AUNvec) jump_norm = sqrt(InnerProduct(AUNvec,UN.vec)) print(jump_norm)
Alternatives? I think this is the most straight-forward way to do it. As of now there is no "Integrate" equivalent that would allow you to integrate the skeleton-terms directly. However, I think the above approach is also very natural.

Best,
Christoph
The following user(s) said Thank You: Yongbin
More
4 years 5 months ago #2135 by Yongbin
I have successfully solved this problem according to your reply, thank you very much for your reply!



Yongbin Han
More
4 years 5 months ago #2136 by joachim
Hi Yongbin,

often one needs these terms in residual-type error estimators. Then you need them element by element.

This is now also supported:
Code:
h = specialcf.mesh_size n = specialcf.normal(mesh.dim) elerr = Integrate ( h*(n*(lam*grad(gfu)-(lam*grad(gfu)).Other()))**2*dx(element_boundary=True), mesh, element_wise=True)
full example is attached.

You can integrate elementwise, on every element boundary, and use also values from the neighbouring elements.

This is a quite new feature and needs some more testing. Faces at the domain boundary are skipped, at the moment.

Joachim
Attachments:
The following user(s) said Thank You: Yongbin
Time to create page: 0.165 seconds