I'm a grad student with some Python experience looking to learn FEniCS for waveguide simulation. I've gone through the tutorial, looked through some examples, and searched around on the internet for help with my problem. I have a good understanding of boundary conditions in the context of electromagnetic waves, but I'm struggling to figure out what FEniCS is doing.
Here's an example I found online:
import sys
from dolfin import *
## Problem data
E0 = Constant(0.0)
n = Constant(1.0)
k = Constant(50.0)
## Formulation
mesh = UnitSquareMesh(500,500)
V = FunctionSpace(mesh, "Lagrange", 1)
E = TrialFunction(V)
v = TestFunction(V)
# Boundary conditions
point = Point(0.5, 0.5)
f = PointSource(V, point)
def E0_boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, E0, E0_boundary)
# Equation
a = ((k**2 / n**2) * inner(E, v) - inner(nabla_grad(E), nabla_grad(v))) * dx
L = Constant(0.0) * v * dx
# Assemble system
A, rhs = assemble_system(a, L, bc)
f.apply(rhs)
# Solve system
E = Function(V)
E_vec = E.vector()
solve(A, E_vec, rhs)
# Plot and export solution
plot(E)
interactive()
I'm used to normal Python, where things like on_boundary
that aren't defined have no meaning and throw up errors. If I hop into iPython and enter the import statements and check to see if it was defined from those, Python tells me on_boundary
still isn't defined. I looked through some C++ files to see if something was referenced in some way that made sense, but I didn't come away from it with any useful conclusions. Could someone explain what's going on here?
Cheers,