You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I delete the plot code because WSL cannot use it.
"""FEniCS tutorial demo program: Magnetic field generated by a copperwire wound around an iron cylinder. The solution is computed bysolving the Poisson equation for the z-component of the magneticvector potential. -Laplace(A_z) = mu_0 * J_z"""from __future__ importprint_functionfromdolfinimport*frommshrimport*frommathimportsin, cos, pia=1.0# inner radius of iron cylinderb=1.2# outer radius of iron cylinderc_1=0.8# radius for inner circle of copper wiresc_2=1.4# radius for outer circle of copper wiresr=0.1# radius of copper wiresR=5.0# radius of domainn=10# number of windings# Define geometry for backgrounddomain=Circle(Point(0, 0), R)
# Define geometry for iron cylindercylinder=Circle(Point(0, 0), b) -Circle(Point(0, 0), a)
# Define geometry for wires (N = North (up), S = South (down))angles_N= [i*2*pi/nforiinrange(n)]
angles_S= [(i+0.5)*2*pi/nforiinrange(n)]
wires_N= [Circle(Point(c_1*cos(v), c_1*sin(v)), r) forvinangles_N]
wires_S= [Circle(Point(c_2*cos(v), c_2*sin(v)), r) forvinangles_S]
# Set subdomain for iron cylinderdomain.set_subdomain(1, cylinder)
# Set subdomains for wiresfor (i, wire) inenumerate(wires_N):
domain.set_subdomain(2+i, wire)
for (i, wire) inenumerate(wires_S):
domain.set_subdomain(2+n+i, wire)
# Create meshmesh=generate_mesh(domain, 128)
# Define function spaceV=FunctionSpace(mesh, 'P', 1)
# Define boundary conditionbc=DirichletBC(V, Constant(0), 'on_boundary')
# Define subdomain markers and integration measuremarkers=MeshFunction('size_t', mesh, 2, mesh.domains())
dx=Measure('dx', domain=mesh, subdomain_data=markers)
# Define current densitiesJ_N=Constant(1.0)
J_S=Constant(-1.0)
# Define magnetic permeability# class Permeability(Expression):# def __init__(self, markers, **kwargs):# self.markers = markers# def eval_cell(self, values, x, cell):# if self.markers[cell.index] == 0:# values[0] = 4*pi*1e-7 # vacuum# elif self.markers[cell.index] == 1:# values[0] = 1e-5 # iron (should really be 6.3e-3)# else:# values[0] = 1.26e-6 # copperclassPermeability(UserExpression): # UserExpression instead of Expressiondef__init__(self, markers, **kwargs):
super().__init__(**kwargs) # This part is new!self.markers=markersdefeval_cell(self, values, x, cell):
ifself.markers[cell.index] ==0:
values[0] =4*pi*1e-7# vacuumelifself.markers[cell.index] ==1:
values[0] =1e-5# iron (should really be 6.3e-3)else:
values[0] =1.26e-6# coppermu=Permeability(markers, degree=1)
# Define variational problemA_z=TrialFunction(V)
v=TestFunction(V)
a= (1/mu)*dot(grad(A_z), grad(v))*dxL_N=sum(J_N*v*dx(i) foriinrange(2, 2+n))
L_S=sum(J_S*v*dx(i) foriinrange(2+n, 2+2*n))
L=L_N+L_S# Solve variational problemA_z=Function(V)
solve(a==L, A_z, bc)
# Compute magnetic field (B = curl A)W=VectorFunctionSpace(mesh, 'P', 1)
B=project(as_vector((A_z.dx(1), -A_z.dx(0))), W)
# Plot solution# plot(A_z)# plot(B)# Save solution to filevtkfile_A_z=File('magnetostatics/potential.pvd')
vtkfile_B=File('magnetostatics/field.pvd')
vtkfile_A_z<<A_zvtkfile_B<<B# Hold plot# interactive()
The text was updated successfully, but these errors were encountered:
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I delete the plot code because WSL cannot use it.
The text was updated successfully, but these errors were encountered: