Projecting function to finer mesh
Dear All, I have a function w: mesh = UnitSquareMesh(size, size, quadrilateral = True) V0 = FunctionSpace(mesh, "DG", 0) w = Function(V0) ... w was calculated during my program run. Now, I want to project it to finer mesh, something like: mesh2 = UnitSquareMesh(2*size, 2*size, quadrilateral = True) V2_0 = FunctionSpace(mesh, "DG", 0) w2 = Function(V2_0) project(w, w2) but I'm getting errors about mesh being quadrilateral or something like RuntimeError: Can't project between mismatching meshes. What is the correct way to project function from one mesh to another? Sincerely, George
Hi George, Sorry about the Easter delay in getting back to you. You can only project 'w' to other Function Spaces that are on the same original mesh. Here, you are after the ability to prolong / inject between a hierarchy of meshes. For this you can use: MeshHierarchy(coarsest_mesh,number_of_levels) So, given your original mesh, mesh=UnitSquareMesh(size,size,quadrilateral=True) You can make a Mesh Hierarchy, mesh_hierarchy=MeshHierarchy(mesh,L) That will give you a LIST type of L+1 elements. In the i'th element, there will be a mesh V_F, that satisfies, mesh /subset V_F, and has new size: size*(2^i). Thus, the first element i=0 of mesh_hierarchy will be the coarsest mesh, size: size. You can then create a FunctionSpaceHierarchy using, V_hierarchy=FunctionSpaceHierarchy(mesh_hierarchy,'DG',0) And two corresponding FunctionHierarchy using, W_hierarchy=FunctionHierarchy(V_hierarchy) W2_hierarchy=FunctionHierarchy(V_hierarchy) These are both LIST types with the i'th element corresponding to a function on the i'th mesh in mesh_hierarchy. Then, you can use prolong and inject commands to 'project' between different meshes within the same hierarchy. Finally, one can 'project' between any two 'levels' of the hierarchy, by using prolong (projecting up levels) and inject (projecting down levels). Example: - Do some operations to W_hierarchy[0], I.e. The function on the coarsest mesh. - Then, one can project it to the next finest mesh in the hierarchy by, prolong(W_hierarchy[0] , W2_hierarchy[1]) Remember, it's important to have pre allocated the 'output' Function in the above command -> in this case, W2_hierarchy. Two notes on this: 1). W2_hierarchy has to be a FunctionHierarchy in the same FunctionSpace as W_hierarchy (there are ways however to get around it if they aren't) and 2). You can't prolong / inject up / down more than one level at a time; this can be easily solved be creating an iterative function. Hope this solves your problems. Many Thanks, Alastair Gregory Sent from my iPad
On 28 Mar 2016, at 14:24, George Ovchinnikov <lives9@gmail.com> wrote:
Dear All,
I have a function w:
mesh = UnitSquareMesh(size, size, quadrilateral = True) V0 = FunctionSpace(mesh, "DG", 0) w = Function(V0)
...
w was calculated during my program run.
Now, I want to project it to finer mesh, something like:
mesh2 = UnitSquareMesh(2*size, 2*size, quadrilateral = True) V2_0 = FunctionSpace(mesh, "DG", 0) w2 = Function(V2_0)
project(w, w2)
but I'm getting errors about mesh being quadrilateral or something like RuntimeError: Can't project between mismatching meshes.
What is the correct way to project function from one mesh to another?
Sincerely, George
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Le 29 mars 2016 19:31, "Gregory, Alastair" <a.gregory14@imperial.ac.uk> a écrit :
Hi George,
Sorry about the Easter delay in getting back to you.
You can only project 'w' to other Function Spaces that are on the same
original mesh. Here, you are after the ability to prolong / inject between a hierarchy of meshes.
For this you can use: MeshHierarchy(coarsest_mesh,number_of_levels)
So, given your original mesh,
mesh=UnitSquareMesh(size,size,quadrilateral=True)
You can make a Mesh Hierarchy, mesh_hierarchy=MeshHierarchy(mesh,L)
That won't work on a quadrilateral mesh, will it? Only meshes of intervals or triangles? There's a test at the start of the constructor.
Hi Gregory, Happy Easter and thank you for clarification. I guess I'm out of luck with quadrilateral=True, though... Sincerely, George On 29.03.2016 11:31, Gregory, Alastair wrote:
Hi George,
Sorry about the Easter delay in getting back to you.
You can only project 'w' to other Function Spaces that are on the same original mesh. Here, you are after the ability to prolong / inject between a hierarchy of meshes.
For this you can use: MeshHierarchy(coarsest_mesh,number_of_levels)
So, given your original mesh,
mesh=UnitSquareMesh(size,size,quadrilateral=True)
You can make a Mesh Hierarchy,
mesh_hierarchy=MeshHierarchy(mesh,L)
That will give you a LIST type of L+1 elements. In the i'th element, there will be a mesh V_F, that satisfies, mesh /subset V_F, and has new size: size*(2^i). Thus, the first element i=0 of mesh_hierarchy will be the coarsest mesh, size: size.
You can then create a FunctionSpaceHierarchy using,
V_hierarchy=FunctionSpaceHierarchy(mesh_hierarchy,'DG',0)
And two corresponding FunctionHierarchy using,
W_hierarchy=FunctionHierarchy(V_hierarchy) W2_hierarchy=FunctionHierarchy(V_hierarchy)
These are both LIST types with the i'th element corresponding to a function on the i'th mesh in mesh_hierarchy.
Then, you can use prolong and inject commands to 'project' between different meshes within the same hierarchy.
Finally, one can 'project' between any two 'levels' of the hierarchy, by using prolong (projecting up levels) and inject (projecting down levels).
Example:
- Do some operations to W_hierarchy[0], I.e. The function on the coarsest mesh. - Then, one can project it to the next finest mesh in the hierarchy by,
prolong(W_hierarchy[0] , W2_hierarchy[1])
Remember, it's important to have pre allocated the 'output' Function in the above command -> in this case, W2_hierarchy. Two notes on this: 1). W2_hierarchy has to be a FunctionHierarchy in the same FunctionSpace as W_hierarchy (there are ways however to get around it if they aren't) and 2). You can't prolong / inject up / down more than one level at a time; this can be easily solved be creating an iterative function.
Hope this solves your problems.
Many Thanks, Alastair Gregory
Sent from my iPad
On 28 Mar 2016, at 14:24, George Ovchinnikov <lives9@gmail.com> wrote:
Dear All,
I have a function w:
mesh = UnitSquareMesh(size, size, quadrilateral = True) V0 = FunctionSpace(mesh, "DG", 0) w = Function(V0)
...
w was calculated during my program run.
Now, I want to project it to finer mesh, something like:
mesh2 = UnitSquareMesh(2*size, 2*size, quadrilateral = True) V2_0 = FunctionSpace(mesh, "DG", 0) w2 = Function(V2_0)
project(w, w2)
but I'm getting errors about mesh being quadrilateral or something like RuntimeError: Can't project between mismatching meshes.
What is the correct way to project function from one mesh to another?
Sincerely, George
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (3)
- 
                
                Geordie McBain
- 
                
                George Ovchinnikov
- 
                
                Gregory, Alastair