-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mesh Hierarchy support when working with Netgen mesh 2D (#3314)
* Mesh Hierarchy support when working with Netgen mesh
- Loading branch information
1 parent
4ae22e7
commit e8c2a62
Showing
4 changed files
with
394 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from firedrake import * | ||
import pytest | ||
|
||
|
||
def create_netgen_mesh_circle(): | ||
from netgen.geom2d import Circle, CSG2d | ||
geo = CSG2d() | ||
|
||
circle = Circle(center=(0, 0), radius=1.0, mat="mat1", bc="circle") | ||
geo.Add(circle) | ||
|
||
ngmesh = geo.GenerateMesh(maxh=0.75) | ||
return ngmesh | ||
|
||
|
||
@pytest.mark.skipcomplex | ||
@pytest.mark.skipnetgen | ||
def test_netgen_mg_circle(): | ||
ngmesh = create_netgen_mesh_circle() | ||
mesh = Mesh(ngmesh) | ||
nh = MeshHierarchy(mesh, 2, netgen_flags={"degree": 3}) | ||
mesh = nh[-1] | ||
|
||
V = FunctionSpace(mesh, "CG", 3) | ||
|
||
u = TrialFunction(V) | ||
v = TestFunction(V) | ||
|
||
a = inner(grad(u), grad(v))*dx | ||
labels = [i+1 for i, name in enumerate(ngmesh.GetRegionNames(codim=1)) if name in ["circle"]] | ||
bcs = DirichletBC(V, zero(), labels) | ||
x, y = SpatialCoordinate(mesh) | ||
|
||
f = 4+0*x | ||
L = f*v*dx | ||
exact = (1-x**2-y**2) | ||
|
||
u = Function(V) | ||
solve(a == L, u, bcs=bcs, solver_parameters={"ksp_type": "cg", | ||
"pc_type": "mg"}) | ||
expect = Function(V).interpolate(exact) | ||
assert (norm(assemble(u - expect)) <= 1e-6) | ||
|
||
|
||
@pytest.mark.skipcomplex | ||
@pytest.mark.skipnetgeun | ||
def test_netgen_mg_circle_non_uniform_degree(): | ||
ngmesh = create_netgen_mesh_circle() | ||
mesh = Mesh(ngmesh) | ||
nh = MeshHierarchy(mesh, 2, netgen_flags={"degree": [1, 2, 3]}) | ||
mesh = nh[-1] | ||
|
||
V = FunctionSpace(mesh, "CG", 3) | ||
|
||
u = TrialFunction(V) | ||
v = TestFunction(V) | ||
|
||
a = inner(grad(u), grad(v))*dx | ||
labels = [i+1 for i, name in enumerate(ngmesh.GetRegionNames(codim=1)) if name in ["circle"]] | ||
bcs = DirichletBC(V, zero(), labels) | ||
x, y = SpatialCoordinate(mesh) | ||
|
||
f = 4+0*x | ||
L = f*v*dx | ||
exact = (1-x**2-y**2) | ||
|
||
u = Function(V) | ||
solve(a == L, u, bcs=bcs, solver_parameters={"ksp_type": "cg", | ||
"pc_type": "mg"}) | ||
expect = Function(V).interpolate(exact) | ||
assert (norm(assemble(u - expect)) <= 1e-6) | ||
|
||
|
||
@pytest.mark.skipcomplex | ||
@pytest.mark.parallel | ||
@pytest.mark.skipnetgen | ||
def test_netgen_mg_circle_parallel(): | ||
ngmesh = create_netgen_mesh_circle() | ||
mesh = Mesh(ngmesh) | ||
nh = MeshHierarchy(mesh, 2, netgen_flags={"degree": 3}) | ||
mesh = nh[-1] | ||
|
||
V = FunctionSpace(mesh, "CG", 3) | ||
|
||
u = TrialFunction(V) | ||
v = TestFunction(V) | ||
|
||
a = inner(grad(u), grad(v))*dx | ||
labels = [i+1 for i, name in enumerate(ngmesh.GetRegionNames(codim=1)) if name in ["circle"]] | ||
bcs = DirichletBC(V, zero(), labels) | ||
x, y = SpatialCoordinate(mesh) | ||
|
||
f = 4+0*x | ||
L = f*v*dx | ||
exact = (1-x**2-y**2) | ||
|
||
u = Function(V) | ||
solve(a == L, u, bcs=bcs, solver_parameters={"ksp_type": "cg", | ||
"pc_type": "mg"}) | ||
expect = Function(V).interpolate(exact) | ||
assert norm(assemble(u - expect)) <= 1e-6 |
Oops, something went wrong.