I’m solving a 3D static electric field in a box of 1000*1000*50 um^3. The boundary between two areas with different charge density somehow shifted.
How could I restate the formal problem to get a correct solution?
The problem is
in which
Python codes are below.
import fenics
import mshr
mesh = mshr.generate_mesh(mshr.Box(fenics.Point(0, 0, 0), fenics.Point(1000, 1000, 50)),32)
V = fenics.FunctionSpace(mesh, 'P', 1)
u_D = fenics.Expression('x[2]<tol ? p_1:p_2', degree=2, tol=1E-14, p_1=-2000, p_2=0)
def boundary(x, on_boundary):
return abs(x[2])<1E-14 or abs(x[2]-50)<1E-14
bc_l = fenics.DirichletBC(V, u_D, boundary)
e0 = 1.60217733e-19
perm_mat = 9.76
perm0 = 8.854187817e-12
f_1 = e0*4e5*1e6/perm0/perm_mat
f_2 = e0*10*1e6/perm0/perm_mat
u = fenics.TrialFunction(V)
v = fenics.TestFunction(V)
f = fenics.Expression('x[2] < 1 + tol ? f_1 : f_2',
degree=1,width=1,f_1=f_1,f_2=f_2, tol = 1E-14)
a = fenics.dot(fenics.grad(u), fenics.grad(v))*fenics.dx
L = f*v*fenics.dx
U = fenics.Function(V)
fenics.solve(a == L, U, bc_l, solver_parameters=dict(linear_solver='gmres', preconditioner='ilu'))
W = fenics.VectorFunctionSpace(mesh, 'P', 1)
E_field = fenics.project(fenics.as_vector((U.dx(0), U.dx(1), U.dx(2))),W)