Dirichlet condition which is a function #2565
-
I am trying to solve Poisson's equationwith non trivial boun dary conditions but it does not work . I need help how to code the conditions and this is my attempt. from firedrake import *
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
a = (inner(grad(u), grad(v)) + inner(u, v)) * dx
L = Constant(0)*v*dx
x =SpatialCoordinate(mesh)
g = Function(V)
g.interpolate(min(4*x[0],4-4*x[0]))
bc1=DirichletBC(V, g ,1)
boundary_ids={2, 3, 4}
bc2=DirichletBC(V,0, boundary_ids)
u = Function(V)
solve(a == L, u,bcs=[bc1,bc2], solver_parameters={'ksp_type': 'cg', 'pc_type': 'none'}) Thank you in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Thanks for the question. I notice a couple of things immediately:
You haven't specified what you mean by "it does not work". Could you please detail what the observed output is and what you expect. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I mean a to be I get the error I expect an answer of approximately 0.325 when I ask for the solution at the center. |
Beta Was this translation helpful? Give feedback.
-
I think you want |
Beta Was this translation helpful? Give feedback.
-
Thank you. It is solved but without the use of the index 0. g.interpolate(conditional(4y > 4-4y, 4-4y, 4y)) |
Beta Was this translation helpful? Give feedback.
I think you want
g.interpolate(conditional(4*x[0] > 4-4*x[0], 4-4*x[0], 4*x[0]))
instead ofg.interpolate(min(4*x[0],4-4*x[0]))
.