Hello,
I am working on an optimization problem, which finds the optimized material property while part of the material property is fixed. See following for an example code with poisson’s equation and some illustrations.
In the above drawing, kappa2
is meant to be an area with a constant value, while kappa1
takes the form of any function input. Note that using an expression with a conditional statement would not work properly in my optimization implementation.
One way I’m picturing the implementation be something like this: kappa = kappa1+kappa2
, where kappa1
only defines in the purple subdomain, and kappa2
only defines in the yellow subdomain.
I am struggling how to make this implementation work, any advice is appreciated.
from dolfin import *
from mshr import*
domain = Rectangle(Point(0., 0.), Point(1., 1.))
domain.set_subdomain(1, Rectangle(Point(0.6, 0.1), Point(0.8, 0.3)) )
mesh = generate_mesh(domain, 30)
mf = MeshFunction("size_t", mesh, 2, mesh.domains())
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(6.4*2,4.8*2),dpi=800)
plot(mesh, "2D mesh")
plot(mf, "Subdomains")
plt.show()
V = FunctionSpace(mesh, "Lagrange", 1)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2)
g = Expression("sin(5*x[0])", degree=2)
kappa = Function(V)
a = inner( kappa* grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
Forward = a-L