This page was generated from unit-2.12-periodicity/periodicity.ipynb.

2.12 Periodic Spaces

To define spaces with periodic constraints, we have to create meshes where the nodes on one side are identified with the nodes on the opposite side.

[1]:
from ngsolve import *
from ngsolve.webgui import Draw
from netgen.occ import *

We identify the top edge with the bottom edge, and the right edge with the left edge of the unit square. The mesh generator copies the mesh from one edge to the other one:

[2]:
shape = Rectangle(1,1).Face()

shape.edges.Max(X).name = "right"
shape.edges.Min(X).name = "left"
shape.edges.Max(Y).name = "top"
shape.edges.Min(Y).name = "bot"

shape.edges.Max(Y).Identify(shape.edges.Min(Y), "bt")
shape.edges.Max(X).Identify(shape.edges.Min(X), "lr")

mesh = shape.GenerateMesh(dim=2, maxh=0.1)

The mesh stores the pairs of identified points:

[3]:
plist = []
for pair in mesh.ngmesh.GetIdentifications():
    plist += list(mesh.ngmesh[pair[0]].p)
    plist += list(mesh.ngmesh[pair[1]].p)
Draw(mesh, objects=[{"type" : "lines", "position" : plist, "name": "identification", "color": "purple"}]);

The Periodic wrapper identifies the degrees of freedom of a space according to the identifications of the mesh:

[4]:
fes = Periodic(H1(mesh,order=3))
u,v = fes.TnT()

source = exp(-100*( (x-0.8)**2+(y-0.8)**2))
gfu = Solve(grad(u)*grad(v)*dx+u*v*dx == source*v*dx)

Draw (gfu);

A piece of cake

The identification can be given by a general transformation. Here the two cut faces of a piece of cake are identified by a rotation:

[5]:
f = WorkPlane(Axes((0,0,0), Y,X)).MoveTo(0.3,0).Rectangle(3,1).Face()
ax = Axis ((0,0,0), Z)
cake = f.Revolve(ax, 30)
cake.faces.Min(Y).name="f1"
cake.faces.Max(Y-0.5*X).name="f2"
cake.faces.Min(Z).name="bot"

cake.faces["f1"][0].Identify(cake.faces["f2"][0], "id",
                            trafo=Rotation(ax, 30))
Draw (cake);

NGSolve does not support elements having dofs on the primary and on the secondary side. To avoid them we refine the mesh once:

[6]:
mesh = cake.GenerateMesh(maxh=0.5) # .Curve(3)
mesh.ngmesh.Refine()

plist = []
for pair in mesh.ngmesh.GetIdentifications():
    plist += list(mesh.ngmesh[pair[0]].p)
    plist += list(mesh.ngmesh[pair[1]].p)
Draw(mesh, objects=[{"type" : "lines", "position" : plist, "name": "identification", "color": "purple"}]);
[7]:
fes = Periodic(H1(mesh, order=2))
u,v = fes.TnT()

source = 100*exp(-9*( (x-2.5)**2+y**2+(z-0.5)**2))
gfu = Solve(grad(u)*grad(v)*dx == source*v*dx, u[BND("bot")] == 0)

Draw (gfu);

Application: computing band diagrams

Computing band diagrams