Periodic boundary condition between specific vertices
Dear all,
I would like to apply a periodic boundary condition between specific nodes on a mesh. For instance, in the included example (based off a script in the demo directory), I would like to apply a PBC to x1=[0,0.5] and x2=[1,0.5] (along the surface). All other surface vertices are assigned a dirichlet condition. I’m able to find the vertices using the ‘inside()’ functions I’ve defined, but I don’t know how to tell the declare the mapping between x1 and x2 using ‘map()’ in the PBC function.
I’m sure there are simpler ways of doing this for a grid with aligned surface vertices, but I’d like a general solution since my meshes are very unlikely to unaligned. In practice, I might want to select a small region of vertices near x1 and x2 for this condition.
I appreciate any help on this problem!
Best,
Pete
from dolfin import *
# Periodic BCs don't work with Epetra
if parameters[
print "Sorry, this demo does not work with the Epetra backend"
import sys
sys.exit(0)
# Create mesh and finite element
mesh = UnitSquare(2,2)
for i,c in enumerate( mesh.coordinates() ):
print c
import numpy as np
coord1 = np.array([0.0,0.5])
coord2 = np.array([1.0,0.5])
Vv = FunctionSpace(mesh, "CG", 1)
# Source term
class Source(Expression):
def eval(self, values, x):
dx = x[0] - 0.5
dy = x[1] - 0.5
values[0] = x[0]*sin(
# Sub domain for Dirichlet boundary condition
# x free
class DirichletBounda
def inside(self, x, on_boundary):
return bool( \
# Sub domain for Periodic boundary condition
class PeriodicBoundar
def inside(self, x, on_boundary):
result = bool( \
print result
return result
# field component 1
def map(self, x, y):
#print "x y"
print x
y[0] = x[0] - 1.0
y[1] = x[1]
# Create Dirichlet boundary condition
u0 = Constant(1.0)
dbc0 = DirichletBounda
bc0 = DirichletBC(Vv, u0, dbc0)
pbc0 = PeriodicBoundary0()
bc1 = PeriodicBC(Vv, pbc0)
bcs = [bc0, bc1]
# Define variational problem
u = TrialFunction(Vv)
v = TestFunction(Vv)
f = Source()
a = dot(grad(u), grad(v))*dx
L = f*v*ds
# Compute solution
u = Function(Vv)
solve(a == L, u, bcs)
# Save solution to file
file = File("periodic.
file << u
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Peter Kekenes-Huskey for more information if necessary.