← Back to team overview

dolfin team mailing list archive

Re: [Question #127050]: Axisymmetric magnetostatic problem ?

 

Question #127050 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/127050

    Status: Answered => Open

Clemens Weninger is still having a problem:
Thanks for the tip. I think I have the weak form of the problem (simple 
axisymmetric coil). But I have a problem getting the resulting B field from the 
Vector potential A in cylinder coordinates.

Here is the code:

from dolfin import *
import math
import matplotlib.pyplot as plt

# Create mesh and define function space
mesh = UnitSquare(100, 100)
V = FunctionSpace(mesh, "Lagrange", 2)

# Define Dirichlet boundary (x = 0 or x = 1)
def boundary(x):
    return x[0] > 1.0 - DOLFIN_EPS or x[1] < DOLFIN_EPS or x[1] > 1.0 - 
DOLFIN_EPS

# Define boundary condition
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

# current souce
class CurrentSource(Expression):
    def eval(self, values, x):
        if x[0] < 0.5 and x[0] > 0.45 and x[1] < 0.7 and x[1] > 0.3:
            values[0] = 10
        else:
            values[0] = 0.0

I = CurrentSource()
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)

# ((u/r + du/dr) * (v/r + dv/dr) + du/dz * dv/dz) *2*pi*r *dx*dz
a = (inner(u.dx(0) + u/x[0], v.dx(0) + v/x[0]) + inner(u.dx(1), 
v.dx(1)))*2.0*math.pi*x[0]*dx
L = I*v*2.0*math.pi*x[0]*dx

# Compute solution
problem = VariationalProblem(a, L, bc)
problem.parameters['linear_solver'] = 'iterative'
problem.parameters['symmetric'] = True
A = problem.solve()

# calculate magnetic field with derivatives of shapefunctions
# br = - du/dz * A
# bz = (u/r + u/dr) * A
br = -u.dx(1)*A
bz = (u/x[0] + u.dx(0))*A

# Plot solution
#plt.quiver(br, bz)
#plt.show()

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.