Hello everyone,
The code below defines a periodic boundary condition class, which maps (links) the nodes in x and z directions.
I would like to get the linked dof numbers in pairs.
If you have any suggestions, I would appreciate.
Fenics version: 2019.2.0.dev0
from fenics import *
from ufl import j
import numpy as np
xmin, xmax, ymin, ymax, zmin, zmax = 0, 1, 0, 1, 0, 1
TOL = 1E-10
class PeriodicBoundary(SubDomain):
def inside(self, x, on_boundary):
return bool( on_boundary and
(
( near(x[0], xmin, TOL) and not ( near(x[2], zmax, TOL) and near(x[0], xmin, TOL) ) )
or ( near(x[2], zmin, TOL) and not ( near(x[2], zmin, TOL) and near(x[0], xmax, TOL) ) )
)
)
def map(self, x, y):
if near(x[2], zmax, TOL) and near(x[0], xmax, TOL):
y[0] = x[0] - (xmax-xmin)
y[1] = x[1]
y[2] = x[2] - (zmax-zmin)
elif near(x[0], xmax, TOL):
y[0] = x[0] - (xmax-xmin)
y[1] = x[1]
y[2] = x[2]
else:
y[0] = x[0]
y[1] = x[1]
y[2] = x[2] - (zmax-zmin)
mesh = BoxMesh(Point(0,0,0), Point(1, 1, 1), 2, 2, 2)
Ve = VectorElement("CG", mesh.ufl_cell(), 1)
Space = FunctionSpace(mesh, Ve, constrained_domain=PeriodicBoundary())
delta_u = TestFunction(Space)
u = TrialFunction(Space)
M = PETScMatrix()
assemble(delta_u[j]*u[j]*dx , tensor = M)