Hello Fenics-pros,
I am trying to run a simple example to simulate magnetic field around a current.
The current is supposedly running on a straight line (say, a piece of wire) in the middle of the domain. One would expect that the magnetic field would form around the wire solenoidally.
I used the curl-curl-example here
When I try and put my own current into the variable dbdt (actually i am imposing a current, but the equation to solve should stay the same) that is the current in the wire, I get total crap as solution. How could I fix that?
For comparison in the line dbdt delete "my_j" and uncomment what is there behind my_j.
from dolfin import *
from numpy import zeros
mesh=UnitCubeMesh(16,16,16)
class MyJ(Expression):
def eval(self, values, x):
if x[0]<= 0.6 and x[0]>=0.4 and x[1]>=0.1 and x[1]<=0.9 and x[2]<= 0.6 and x[2]>=0.4 :
values[0] = 0.0
values[1] = 1.0
values[2] = 0.0
else :
values[0]=0.0
values[1]=0
values[2] = 0.0
def value_shape(self):
return (3, )
# Define function spaces
P1 = VectorFunctionSpace(mesh, "CG", 1)
PN = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 1)
my_j = interpolate(MyJ(), P1)
plot(my_j)
# Define test and trial functions
v0 = TestFunction(PN)
u0 = TrialFunction(PN)
v1 = TestFunction(P1)
u1 = TrialFunction(P1)
# Define functions
dbdt = my_j#Expression(("0.0", "0.0", "1.0"), degree=1)
zero = Expression(("0.0", "0.0", "0.0"), degree=1)
T = Function(PN)
J = Function(P1)
# Dirichlet boundary
class DirichletBoundary(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
# Boundary condition
bc = DirichletBC(PN, zero, DirichletBoundary())
# Solve currents equation (using potential T)
solve(inner(curl(u0), curl(v0))*dx == inner(dbdt, v0)*dx, T, bc)
# Solve density equation
solve(inner(v1, u1)*dx == dot(v1, curl(T))*dx, J)
# Plot solution
plot(curl(T))
file=File("current_density.pvd")
file << J
# Hold plot
interactive()