assign different values on subdomains
Hi all, I would like to assign different values of some function u on subdomains of a 2-D domain. More precisely, I want to have u equal to 1 for y > x and equal to 0 otherwise. For that reason I guess one needs to be able to define subdomains. Besides the Issue on https://github.com/firedrakeproject/firedrake/issues/723 I didn't find any helpful information online. Can someone help out please? I attached the fenics version of what I want, hoping that might help! All the best, Tobias
On 18/10/16 18:00, Schwedes, Tobias wrote:
Hi all,
I would like to assign different values of some function u on subdomains of a 2-D domain. More precisely, I want to have u equal to 1 for y > x and equal to 0 otherwise. For that reason I guess one needs to be able to define subdomains. Besides the Issue on
Here are two ways: x, y = SpatialCoordinate(mesh) subdomain = SubDomainData(y > x) u = Function(V) u.interpolate(as_ufl(1), subset=subdomain) This will create a subset that marks all cells as "active" if their coordinate, evaluated at the cell center, has y > x. This is, I think, equivalent to your dolfin code. Alternately, if you want the expression to be evaluated quad-point-wise: x, y = SpatialCoordinate(mesh) u = conditional(y > x, 1, 0) Now use u as normal in your expressions. If you need to visualise this field you will obviously have to interpolate it into some space. Cheers, Lawrence
Hi Lawrence, works perfectly, thanks! All the best, Tobias ________________________________ Von: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> im Auftrag von Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Gesendet: Dienstag, 18. Oktober 2016 18:12 An: firedrake Betreff: Re: [firedrake] assign different values on subdomains On 18/10/16 18:00, Schwedes, Tobias wrote:
Hi all,
I would like to assign different values of some function u on subdomains of a 2-D domain. More precisely, I want to have u equal to 1 for y > x and equal to 0 otherwise. For that reason I guess one needs to be able to define subdomains. Besides the Issue on
Here are two ways: x, y = SpatialCoordinate(mesh) subdomain = SubDomainData(y > x) u = Function(V) u.interpolate(as_ufl(1), subset=subdomain) This will create a subset that marks all cells as "active" if their coordinate, evaluated at the cell center, has y > x. This is, I think, equivalent to your dolfin code. Alternately, if you want the expression to be evaluated quad-point-wise: x, y = SpatialCoordinate(mesh) u = conditional(y > x, 1, 0) Now use u as normal in your expressions. If you need to visualise this field you will obviously have to interpolate it into some space. Cheers, Lawrence
Another way to do this (which may be more convenient if the internal border doesn't have such a simple analytic expression) is to define the subdomains in Gmsh as 'Physical Surfaces'. These can then be accessed using the cell_subset method of the Mesh and passed to the subset keyword-argument of interpolate. I attach a minimal example which seems to do the same thing as the FEniCS piecewise.py. I gleaned this technique from https://github.com/firedrakeproject/firedrake/pull/791/files .
participants (3)
- 
                
                G. D. McBain
- 
                
                Lawrence Mitchell
- 
                
                Schwedes, Tobias