-
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
Signed-off-by: Umberto Zerbinati <[email protected]>
- Loading branch information
Umberto Zerbinati
committed
Jan 10, 2024
1 parent
b89c8d5
commit 6df8e58
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from firedrake import * | ||
import pytest | ||
|
||
|
||
def test_netgen_mg_circle(): | ||
try: | ||
from netgen.geom2d import Circle, CSG2d | ||
except ImportError: | ||
pytest.skip(reason="Netgen unavailable, skipping Netgen test.") | ||
geo = CSG2d() | ||
|
||
circle = Circle(center=(0, 0), radius=1.0, mat="mat1", bc="circle") | ||
geo.Add(circle) | ||
|
||
ngmesh = geo.GenerateMesh(maxh=0.75) | ||
|
||
nh = MeshHierarchy(ngmesh, 2, order=3) | ||
mesh = nh[-1] | ||
|
||
V = FunctionSpace(mesh, "CG", 3) | ||
|
||
u = TrialFunction(V) | ||
v = TestFunction(V) | ||
|
||
a = dot(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) |