Hello,
I would like to know if there is a way to extract/compute the lengths of equipotential lines (or areas of equipotential surfaces in 3D)?
I am solving Poisson’s equation with Dirichlet BC. The solution is then restricted to a conductor of arbitrary shape, and I would like to extract the length of the equipotential lines inside this conductor. A finite number of lines could be explicitly computed and the rest interpolated between the previously computed values.
(I know that in practice the conductivity should be accounted for in the PDE for conduction problems but let’s assume here that it is =1 everywhere).
Here is a minimal working example of the problem:
from dolfin import *
from dolfin_adjoint import *
from matplotlib import pyplot as plt
mesh = UnitSquareMesh(50,50)
U = FunctionSpace(mesh,'CG', 2)
class top_left(SubDomain):
def inside(self,x,on_boundary):
return (near(x[1], 1.0, DOLFIN_EPS) and (x[0]<=0.4+DOLFIN_EPS) and on_boundary)
class top_right(SubDomain):
def inside(self,x,on_boundary):
return (near(x[1], 1.0, DOLFIN_EPS) and (x[0]>=0.6+DOLFIN_EPS) and on_boundary)
bcs = []
bc1 = DirichletBC(U,2.0,top_left())
bc2 = DirichletBC(U,1.0,top_right())
bcs.append(bc1)
bcs.append(bc2)
# Poisson's equation
f = interpolate(Constant(1.0e-5), U) # the source term for the PDE for elec
u = Function(U, name="Potential")
v = TestFunction(U)
F = inner(grad(v),grad(u))*dx - f*v*dx
solve(F == 0, u, bcs, solver_parameters={"newton_solver": {"absolute_tolerance": 1.0e-7, "maximum_iterations": 20}})
# Conductor distribution (expression not known beforehand)
expr = Expression('(pow(x[0]-0.5,2) + pow(x[1]-1,2) > pow(0.25,2)) && (pow(x[0]-0.5,2) + pow(x[1]-1,2) <= pow(0.5,2)) ? 1.0 : 0.0',degree=3)
conductor = Function(U, name="Conductor")
conductor.assign(project(expr,U))
# Function of interest (compute the length of equipotential lines)
v_c = u*conductor
# Plots for visualization
pl, ax = plt.subplots();
fig = plt.gcf()
fig.set_size_inches(16, 4)
plt.subplot(1, 2, 1); p = plot(u, title='potential everywhere'); p.set_cmap("coolwarm"); cbar = plt.colorbar(p);
plt.subplot(1, 2, 2); p = plot(v_c, title='potential in conductor',mode='color',vmin=0.0); p.set_cmap("magma"); cbar = plt.colorbar(p);
Is there a way to compute these lengths/areas with a PDE or another operation?
(If this operation can easily be accounted for with dolfin_adjoint
to compute its gradient afterwards, this would be perfect!)
Thank you for your time