Hello,
I am trying to solve the pde \nabla^2 \phi = -\nabla^2 \psi for the potential \phi in a 3D domain, which is insulated except at one point where it is earthed. The function \psi is known on the 3D mesh and consists of a solid region of 1’s with the remainder being 0. My variational formulation is as follows:
def boundary_fixed_point(x,on_boundary):
tol=1E-10
return (abs(x[0]-3.0) < tol) and (abs(x[1]-0.0)<tol) and (abs(x[2])<tol)
V = FunctionSpace(mesh,'CG',1)
phi = TrialFunction(V)
psi = TrialFunction(V)
v = TestFunction(V)
psi = Function(V)
# I read in the pointwise definition of psi from a file. psi is defined at the nodes of the mesh
V_g = VectorFunctionSpace(mesh,"CG",1)
grad_psi = project(grad(psi),V_g)
dbc = DirichletBC(V,Constant(0.0),boundary_fixed_point,
method='pointwise')
a = inner(grad(phi),grad(v))*dx
L = inner(Constant(-1.0)*grad_psi,grad(v))*dx
phi = Function(V)
solve(a == L,phi,dbc)
While this code code does run, it produces incorrect answers. The answers produced do not agree with another code using the same mesh and input conditions, nor the physics of the problem in really simple problems. I assume that I must have either the variational formulation incorrect or there is some problem with the calculation of grad_psi.
If someone could provide some insight that would be great. I can expand on my explanation of the problem or the code if necessary.
Thank you,
Peter.