use of BCs for interior nodes
Dear all, In the code attached, the objective is to copy the surface values of the 3D function phi_s, to the interior nodes of the 3D function phi_3s such that phi_3s is equal to the top values of phi_2s at each z. For this, I want to solve dzz(phi) = 0, with boundary conditions : phi_3s = phi_s(top) at the bottom z=0 and top z=H0. solving the equation: phi.dx(2)*v.dx(2) = 0 (where phi is the trial function and v the test function) did not work, so instead I solve: grad(phi).grad(v) = phi_3s.dx(0)v.dx(0) + phi_3s.dx(1) v.dx(1), with phi_s as boundary condition. I have two questions concerning this code: 1) First, when I change CG1 to CG2, then the value of phi_3s is not exactly the same as the one of phi_s at the surface. Where does this difference come from? 2) Is there a way to define a boundary condition at the bottom of the domain V (at z=0), using the value of a function at the top of this domain? Basically, I would like to use the top surface value of phi_s as a boundary condition both at the bottom z=0 and at the top z=h0 of the domain. Is that possible? Thanks and best regards, Floriane
I missed that last week in the code: the 2nd order equation dzz(phi) needs 2 conditions, chosen here to be the same at the top and bottom; also phi_s at later stages will be one of the unknowns! So how is it possible that the equation was solved at all with only one condition? Did it take Neumann condition at the bottom, as part of an automatic procedure in Firedrake? ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Floriane Gidel [RPG] <mmfg@leeds.ac.uk> Sent: Tuesday, April 19, 2016 3:56 PM To: firedrake@imperial.ac.uk Subject: [firedrake] use of BCs for interior nodes Dear all, In the code attached, the objective is to copy the surface values of the 3D function phi_s, to the interior nodes of the 3D function phi_3s such that phi_3s is equal to the top values of phi_2s at each z. For this, I want to solve dzz(phi) = 0, with boundary conditions : phi_3s = phi_s(top) at the bottom z=0 and top z=H0. solving the equation: phi.dx(2)*v.dx(2) = 0 (where phi is the trial function and v the test function) did not work, so instead I solve: grad(phi).grad(v) = phi_3s.dx(0)v.dx(0) + phi_3s.dx(1) v.dx(1), with phi_s as boundary condition. I have two questions concerning this code: 1) First, when I change CG1 to CG2, then the value of phi_3s is not exactly the same as the one of phi_s at the surface. Where does this difference come from? 2) Is there a way to define a boundary condition at the bottom of the domain V (at z=0), using the value of a function at the top of this domain? Basically, I would like to use the top surface value of phi_s as a boundary condition both at the bottom z=0 and at the top z=h0 of the domain. Is that possible? Thanks and best regards, Floriane
On 19 Apr 2016, at 16:35, Onno Bokhove <O.Bokhove@leeds.ac.uk> wrote:
I missed that last week in the code:
the 2nd order equation dzz(phi) needs 2 conditions, chosen here to be the same at the top and bottom; also phi_s at later stages will be one of the unknowns! So how is it possible that the equation was solved at all with only one condition? Did it take Neumann condition at the bottom, as part of an automatic procedure in Firedrake?
A neumann condition just kills one of your surface terms when integrating by parts, no? If you just completely left it out, that's equivalent to choosing u.n = 0 as a neumann condition on that side. Lawrence
Yes this was just a simple case where phi_s has the same value everywhere (while in our case it will be updated only at the top surface), so in the example, I use neuman boundary conditions (u.n = 0 everywhere), and two Dirichlet boundary conditions : the top value of phi_s at the top of the domain, and the bottom value of phi_s at the bottom of the domain (since in this example, they are equal). This is why I ask the second question about using the top boundary of phi_s as a boundary condition for the bottom of the domain (as well as for the top surface). I hope this is more clear. Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Envoyé : mardi 19 avril 2016 16:38 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes
On 19 Apr 2016, at 16:35, Onno Bokhove <O.Bokhove@leeds.ac.uk> wrote:
I missed that last week in the code:
the 2nd order equation dzz(phi) needs 2 conditions, chosen here to be the same at the top and bottom; also phi_s at later stages will be one of the unknowns! So how is it possible that the equation was solved at all with only one condition? Did it take Neumann condition at the bottom, as part of an automatic procedure in Firedrake?
A neumann condition just kills one of your surface terms when integrating by parts, no? If you just completely left it out, that's equivalent to choosing u.n = 0 as a neumann condition on that side. Lawrence
Dear all, Do you have any tips concerning the two questions below ? Thank you and best regards, Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Floriane Gidel [RPG] <mmfg@leeds.ac.uk> Envoyé : mardi 19 avril 2016 16:42:47 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes Yes this was just a simple case where phi_s has the same value everywhere (while in our case it will be updated only at the top surface), so in the example, I use neuman boundary conditions (u.n = 0 everywhere), and two Dirichlet boundary conditions : the top value of phi_s at the top of the domain, and the bottom value of phi_s at the bottom of the domain (since in this example, they are equal). This is why I ask the second question about using the top boundary of phi_s as a boundary condition for the bottom of the domain (as well as for the top surface). I hope this is more clear. Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Envoyé : mardi 19 avril 2016 16:38 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes
On 19 Apr 2016, at 16:35, Onno Bokhove <O.Bokhove@leeds.ac.uk> wrote:
I missed that last week in the code:
the 2nd order equation dzz(phi) needs 2 conditions, chosen here to be the same at the top and bottom; also phi_s at later stages will be one of the unknowns! So how is it possible that the equation was solved at all with only one condition? Did it take Neumann condition at the bottom, as part of an automatic procedure in Firedrake?
A neumann condition just kills one of your surface terms when integrating by parts, no? If you just completely left it out, that's equivalent to choosing u.n = 0 as a neumann condition on that side. Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Dear Floriane, On 25/04/16 10:15, Floriane Gidel [RPG] wrote:
Dear all,
Do you have any tips concerning the two questions below ? Thank you and best regards,
I don't have an idea as to why in the CG2 case you don't get identical values everywhere. Although I note that you are solving an equation so you can't expect to get a solution that is closer than the solver tolerance (by default 1e-8) in the general case. As to transferring values from the top surface to the bottom. You can do that like so: f = Function(V) # The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top] This will only work on extruded meshes (since there there is an easy identification of the "top" and "bottom" of the domain). Cheers, Lawrence
Dear Lawrence, Thank you for your answer. Do you think we can use this tip while solving an equation for f ? I mean, we solve an equation for f which updates only its top surface values, and we need the bottom values to be updated at the same time (with the same values as the top surface), because other equations must be solved simultaneously, using the top and bottom values of f. So basically my question is: if I use what you suggest: f = Function(V) # The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top] and then define boundary conditions: bc_top = DirichletBC(V ,f, 'top') bc_bottom = DirichletBC(V, f, 'bottom') to solve : solve(f_equation==0, f, bcs=[bc_top,bc_bottom]) will it update and apply the boundary conditions while f is updated, or will it use the previous values of f as boundary conditions? Best regards, Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Envoyé : lundi 25 avril 2016 10:26:31 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes Dear Floriane, On 25/04/16 10:15, Floriane Gidel [RPG] wrote:
Dear all,
Do you have any tips concerning the two questions below ? Thank you and best regards,
I don't have an idea as to why in the CG2 case you don't get identical values everywhere. Although I note that you are solving an equation so you can't expect to get a solution that is closer than the solver tolerance (by default 1e-8) in the general case. As to transferring values from the top surface to the bottom. You can do that like so: f = Function(V) # The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top] This will only work on extruded meshes (since there there is an easy identification of the "top" and "bottom" of the domain). Cheers, Lawrence
On 25/04/16 11:04, Floriane Gidel [RPG] wrote:
Dear Lawrence,
Thank you for your answer. Do you think we can use this tip while solving an equation for f ? I mean, we solve an equation for f which updates only its top surface values, and we need the bottom values to be updated at the same time (with the same values as the top surface), because other equations must be solved simultaneously, using the top and bottom values of f. So basically my question is: if I use what you suggest:
f = Function(V)
# The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top]
and then define boundary conditions:
bc_top = DirichletBC(V ,f, 'top') bc_bottom = DirichletBC(V, f, 'bottom')
to solve : solve(f_equation==0, f, bcs=[bc_top,bc_bottom])
will it update and apply the boundary conditions while f is updated, or will it use the previous values of f as boundary conditions?
It will use the previous boundary values. In fact, it's somewhat worse than this. The boundary lifting operator we use assumes that the boundary conditions are explicit to the equation you're solving. Here you have implicit boundary conditions and so we're mathematically doing the wrong thing, so I would not expect this to work at all! Cheers, Lawrence
Ok, thanks. So I assume there is no way to solve the equation with implicit BCs ? Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Envoyé : lundi 25 avril 2016 11:09:14 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes On 25/04/16 11:04, Floriane Gidel [RPG] wrote:
Dear Lawrence,
Thank you for your answer. Do you think we can use this tip while solving an equation for f ? I mean, we solve an equation for f which updates only its top surface values, and we need the bottom values to be updated at the same time (with the same values as the top surface), because other equations must be solved simultaneously, using the top and bottom values of f. So basically my question is: if I use what you suggest:
f = Function(V)
# The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top]
and then define boundary conditions:
bc_top = DirichletBC(V ,f, 'top') bc_bottom = DirichletBC(V, f, 'bottom')
to solve : solve(f_equation==0, f, bcs=[bc_top,bc_bottom])
will it update and apply the boundary conditions while f is updated, or will it use the previous values of f as boundary conditions?
It will use the previous boundary values. In fact, it's somewhat worse than this. The boundary lifting operator we use assumes that the boundary conditions are explicit to the equation you're solving. Here you have implicit boundary conditions and so we're mathematically doing the wrong thing, so I would not expect this to work at all! Cheers, Lawrence
Are these implicit bc's? they are unknowns but that is something else, isn't? the key issue is not solving these equations but extending a surface 2D function vertically. so if this does not work, then it goes back to the query I had a week or so ago for which you guys said that a hack could work;l i.e.: (i) iiint f(x,y) * h(x,y,z) dx dy dz = iint f(x,y) [int h(x,y,z) dz ] dx dy as that is the alternative. otherwise, we need f(x,y) as on the RHS of the above specified everywhere in the 3D domain. of course, the domain is extruded in the z-direction in regular fashion. (ii) the trick Floriane is now trying is solving d_zz f_3D(x,y,z) = 0 with f_3d is f(x,y) at the top and bottom as part of a larger system of water wave equations. Thanks! ________________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Floriane Gidel [RPG] <mmfg@leeds.ac.uk> Sent: Monday, April 25, 2016 11:21 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] use of BCs for interior nodes Ok, thanks. So I assume there is no way to solve the equation with implicit BCs ? Floriane ________________________________________ De : firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> de la part de Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Envoyé : lundi 25 avril 2016 11:09:14 À : firedrake@imperial.ac.uk Objet : Re: [firedrake] use of BCs for interior nodes On 25/04/16 11:04, Floriane Gidel [RPG] wrote:
Dear Lawrence,
Thank you for your answer. Do you think we can use this tip while solving an equation for f ? I mean, we solve an equation for f which updates only its top surface values, and we need the bottom values to be updated at the same time (with the same values as the top surface), because other equations must be solved simultaneously, using the top and bottom values of f. So basically my question is: if I use what you suggest:
f = Function(V)
# The nodes topologically at the bottom of the domain: bottom = V.bottom_nodes() # Sim at the top top = V.top_nodes() # Copy from top nodes into bottom nodes f.dat.data_with_halos[bottom] = f.dat.data_with_halos[top]
and then define boundary conditions:
bc_top = DirichletBC(V ,f, 'top') bc_bottom = DirichletBC(V, f, 'bottom')
to solve : solve(f_equation==0, f, bcs=[bc_top,bc_bottom])
will it update and apply the boundary conditions while f is updated, or will it use the previous values of f as boundary conditions?
It will use the previous boundary values. In fact, it's somewhat worse than this. The boundary lifting operator we use assumes that the boundary conditions are explicit to the equation you're solving. Here you have implicit boundary conditions and so we're mathematically doing the wrong thing, so I would not expect this to work at all! Cheers, Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 25/04/16 11:30, Onno Bokhove wrote:
Are these implicit bc's? they are unknowns but that is something else, isn't?
the key issue is not solving these equations but extending a surface 2D function vertically.
so if this does not work, then it goes back to the query I had a week or so ago for which you guys said that a hack could work;l i.e.: (i) iiint f(x,y) * h(x,y,z) dx dy dz = iint f(x,y) [int h(x,y,z) dz ] dx dy
as that is the alternative.
otherwise, we need f(x,y) as on the RHS of the above specified everywhere in the 3D domain.
of course, the domain is extruded in the z-direction in regular fashion.
(ii) the trick Floriane is now trying is solving
d_zz f_3D(x,y,z) = 0 with f_3d is f(x,y) at the top and bottom as part of a larger system of water wave equations.
So is the problem that you want to solve d_zz f_3D(x, y, z) = 0 with strong dirichlet conditions at top and bottom set by f(x, y). In which case, the previous suggestion of copying from top to bottom works. So if your process is something like: solve for f(x, y) construct f_3D Use f_3D in a system X. Then that's fine. Presumably solving X you might construct a new solution for f, but you're happy using the old value in f_3D (which enters through the right hand side)? Lawrence
thx. well f(x,y) is an unknown as well as f_3D but maybe an iteration would work if one is not using a direct solver? so maybe? any suggestions? ________________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Sent: Monday, April 25, 2016 11:53 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] use of BCs for interior nodes On 25/04/16 11:30, Onno Bokhove wrote:
Are these implicit bc's? they are unknowns but that is something else, isn't?
the key issue is not solving these equations but extending a surface 2D function vertically.
so if this does not work, then it goes back to the query I had a week or so ago for which you guys said that a hack could work;l i.e.: (i) iiint f(x,y) * h(x,y,z) dx dy dz = iint f(x,y) [int h(x,y,z) dz ] dx dy
as that is the alternative.
otherwise, we need f(x,y) as on the RHS of the above specified everywhere in the 3D domain.
of course, the domain is extruded in the z-direction in regular fashion.
(ii) the trick Floriane is now trying is solving
d_zz f_3D(x,y,z) = 0 with f_3d is f(x,y) at the top and bottom as part of a larger system of water wave equations.
So is the problem that you want to solve d_zz f_3D(x, y, z) = 0 with strong dirichlet conditions at top and bottom set by f(x, y). In which case, the previous suggestion of copying from top to bottom works. So if your process is something like: solve for f(x, y) construct f_3D Use f_3D in a system X. Then that's fine. Presumably solving X you might construct a new solution for f, but you're happy using the old value in f_3D (which enters through the right hand side)? Lawrence
On 25/04/16 11:56, Onno Bokhove wrote:
thx.
well f(x,y) is an unknown as well as f_3D but maybe an iteration would work if one is not using a direct solver?
so maybe? any suggestions?
I think we're talking at cross purposes. As I understand it f and f_3D are both unknowns. However, f enters the f_3D equation through strongly enforced boundary conditions. Now, if f is somehow a function of f_3D, then this makes the equation for f_3D implicit in the boundary conditions. Since we have: equation_for(f_3D) == 0 in the bulk and f_3D = f on the boundary But f = f(f_3D)! So you need to figure out some way to break this implicitness I think. But maybe I misunderstand what is going on. Cheers, Lawrence
participants (3)
-
Floriane Gidel [RPG]
-
Lawrence Mitchell
-
Onno Bokhove