I'm a young user a FEniCS Project and I need help. This is my program who calculating a electromagnetic field in biological tissues and I need to add to them a time to see how the field strength varies with difriend time.
Please help my, My study graduaded depends on it. I don't have a time.
Ps. I'm very sorry for my English. I use FEniCS 1.3.0 on Ubuntu
Regards
Paul
from dolfin import *
if not has_cgal():
print "DOLFIN must be compiled with CGAL to run this demo."
exit(0) class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 5.0)
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.0)
class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 5.0)
class Lewo(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.25)
class Prawo(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 4.75)
class Dol(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.25)
class Gora(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 4.75)
class Obstacle(SubDomain):
def inside(self, x, on_boundary): return (between(x[1], (1.25, 3.75)) and between(x[0], (1.25, 3.75)))
# Initialize sub-domain instances
left = Left()
top = Top()
right = Right()
bottom = Bottom()
lewo = Left()
gora = Top()
prawo = Right()
dol = Bottom()
obstacle = Obstacle()
# Define 2D geometry
domain = Rectangle(0., 0., 5., 5.)
domain.set_subdomain(1, Rectangle(0.25, 0.25, 4.75, 4.75))
domain.set_subdomain(2, Rectangle(1.25, 1.25, 3.75, 3.75))
mesh2d = Mesh(domain, 45)
mf = MeshFunction("size_t", mesh2d, 2, mesh2d.domains())
domains = CellFunction("size_t", mesh2d)
domains.set_all(0) obstacle.mark(domains, 1)
# Initialize mesh function for boundary domains
boundaries = FacetFunction("size_t", mesh2d)
boundaries.set_all(0)
left.mark(boundaries, 1)
top.mark(boundaries, 2)
right.mark(boundaries, 3)
bottom.mark(boundaries, 4)
lewo.mark(boundaries, 5)
gora.mark(boundaries, 6)
prawo.mark(boundaries, 7)
dol.mark(boundaries, 8)
# Define input data
a0 = Constant(1.25E-1)
a1 = Constant(2.86E-1)
a2 = Constant(9.50E-2)
#g_L = Expression("- 10*exp(- pow(x[1] - 0.5, 2))")
#g_R = Constant("1.0") f = Constant(1.0)
# Define function space and basis functions
V = FunctionSpace(mesh2d, "CG", 2)
u = TrialFunction(V)
v = TestFunction(V)
# Define Dirichlet boundary conditions at top and bottom boundaries
bcs = [DirichletBC(V, 0.0, boundaries, 1),
DirichletBC(V, 0.0, boundaries, 2),
DirichletBC(V, 0.0, boundaries, 3),
DirichletBC(V, 0.0, boundaries, 4),
DirichletBC(V, 0.0, boundaries, 5),
DirichletBC(V, 0.0, boundaries, 6),
DirichletBC(V, 0.0, boundaries, 7),
DirichletBC(V, 0.0, boundaries, 8) ]
# Define new measures associated with the interior domains and
# exterior boundaries
dx = Measure("dx")[domains]
ds = Measure("ds")[boundaries]
# Define variational form
F = (inner(a0*grad(u), grad(v))*dx(0) + inner(a1*grad(u), grad(v))*dx(1) + inner(a2*grad(u), grad(v))*dx(2) - f*v*dx(1) - f*v*dx(2) - f*v*dx(3) - f*v*dx(4) - f*v*dx(5) - f*v*dx(6)
- f*v*dx(7) - f*v*dx(8))
# Separate left and right hand sides of equation
a, L = lhs(F), rhs(F)
# Solve problem
u = Function(V)
solve(a == L, u, bcs)
plot(u, title="u")
plot(mesh2d, "2D mesh")
#plot(mesh2d, "2D mesh")
# Convert subdomains to mesh function for plotting file = File("tkanka.pvd") file << u
#plot(mf, "Subdomains") interactive()