Dear all, I would like to check the convergence of my solution as I refine the mesh. Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake? Thank you, Tomasz
Hi Tomasz, On 25/10/16 11:25, Tomasz Salwa [RPG] wrote:
Dear all,
I would like to check the convergence of my solution as I refine the mesh.
Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake?
A few questions: How did you get the exact solution that you're checking convergence against? If it's analytic, can you just interpolate that expression on the different meshes? How did you get the refined mesh? Did you make it with a MeshHierarchy? In which case prolong and inject respectively transfer solution variables from coarse to fine and fine to coarse. If neither of those is true, you can interpolate the coordinates into a vector valued space of the same type as you solution field on the coarse mesh, get the data values, and evaluate your solution on the fine mesh at those points. You can then put these values back in a coarse function. Something like this, untested: mesh_coarse = ... mesh_fine = ... V = FunctionSpace(mesh_coarse, "CG", 2) Vf = FunctionSpace(mesh_fine, "CG", 2) coarse_points = Function(VectorFunctionSpace(mesh_coarse, "CG", 2)) coarse_points.interpolate(SpatialCoordinate(mesh_coarse)) fine_exact = Function(Vf) # Construct solution somehow. coarse_data = fine_exact.at(coarse_points.dat.data_ro) coarse_exact = Function(V) coarse_exact.dat.data[:] = coarse_data[:] # Now coarse_exact has the fine_exact solution interpolated on the coarse mesh. Cheers, Lawrence
Dear Tomasz, I would like to check the convergence of my solution as I refine the mesh. Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake? You can do this through the multigrid tools. # make an empty coarse function (Here, Vc is the coarse FS) f_coarse_ = Function(Vc) # project fine onto coarse inject(f_fine, f_coarse_) # check error norm(assemble(f_coarse - f_coarse_)) Many Thanks, Alastair Gregory ------------------------------------------------------------------- Research Assistant (Maths Foresees Grant) Imperial College London Office 759 Huxley Building, South Kensington (Tel: 07794 243913) | (Email: a.gregory14@imperial.ac.uk) ------------------------------------------------------------------------------------ ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Tomasz Salwa [RPG] <mmtjs@leeds.ac.uk> Sent: 25 October 2016 11:25:45 To: firedrake Subject: [firedrake] mapping between two meshes Dear all, I would like to check the convergence of my solution as I refine the mesh. Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake? Thank you, Tomasz
Dear Lawrence (thank you also Alastair for the suggestion), I think your last crude way is what I need, as I'd like to extrapolate results from 3 meshes to get the estimate of the exact solution. I also refine mesh externally in gmsh. Therefore I need results from a few runs with different meshes. I'd like to save the solution and open it in a different file for further study. I tried to use DumbCheckpoint. Firedrake seems to complain when I store the solution held in a certain object structure and then try to load it without the same structure (even in the same file). Details below. I don't run MPI. Thank you, Tomasz ... import firedrake as fd ... # store solution dumb_file = fd.DumbCheckpoint("results_crude/phi", mode=fd.FILE_CREATE) dumb_file.store(CS.W.phi) # some object structure ... # this works (in the same file, same object structure): #dumb_file = fd.DumbCheckpoint("results_crude/phi", mode=fd.FILE_READ) #dumb_file.load(CS.W.phi) # this doesn't work (same mesh and function space, no object structure): mesh = fd.Mesh("cylinder_coarse.msh") V = fd.FunctionSpace(mesh, "CG", 1) phi = fd.Function(V) dumb_file = fd.DumbCheckpoint("results_crude/phi", mode=fd.FILE_READ) dumb_file.load(phi) Error listing: Traceback (most recent call last): File "main.py", line 15, in <module> fn.time_evolution() File "/home/tommy/work/programs/lin_coupled_3d/lib/functions.py", line 96, in time_evolution dumb_file.load(phi) File "/home/tommy/programs/firedrake/local/lib/python2.7/site-packages/firedrake/checkpointing.py", line 235, in load v.load(self.vwr) File "PETSc/Vec.pyx", line 447, in petsc4py.PETSc.Vec.load (src/petsc4py.PETSc.c:96066) petsc4py.PETSc.Error: error code 76 [0] VecLoad() line 975 in /tmp/pip-qTWKue-build/src/vec/vec/interface/vector.c [0] VecLoad_Default() line 409 in /tmp/pip-qTWKue-build/src/vec/vec/utils/vecio.c [0] VecLoad_HDF5() line 267 in /tmp/pip-qTWKue-build/src/vec/vec/utils/vecio.c [0] Error in external library [0] Error in HDF5 call H5Dopen2() Status -1 Exception RuntimeError: RuntimeError("Can't decrement id ref count (Can't close file, there are objects still open)",) in 'h5py._objects.ObjectID.__dealloc__' ignored *** The MPI_File_close() function was called after MPI_FINALIZE was invoked. *** This is disallowed by the MPI standard. *** Your MPI job will now abort. [tommy-comp:19947] Local abort after MPI_FINALIZE completed successfully; not able to aggregate error messages, and not able to guarantee that all other processes were killed! ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Gregory, Alastair C A <a.gregory14@imperial.ac.uk> Sent: 25 October 2016 11:37:24 To: firedrake Subject: Re: [firedrake] mapping between two meshes Dear Tomasz, I would like to check the convergence of my solution as I refine the mesh. Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake? You can do this through the multigrid tools. # make an empty coarse function (Here, Vc is the coarse FS) f_coarse_ = Function(Vc) # project fine onto coarse inject(f_fine, f_coarse_) # check error norm(assemble(f_coarse - f_coarse_)) Many Thanks, Alastair Gregory ------------------------------------------------------------------- Research Assistant (Maths Foresees Grant) Imperial College London Office 759 Huxley Building, South Kensington (Tel: 07794 243913) | (Email: a.gregory14@imperial.ac.uk) ------------------------------------------------------------------------------------ ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Tomasz Salwa [RPG] <mmtjs@leeds.ac.uk> Sent: 25 October 2016 11:25:45 To: firedrake Subject: [firedrake] mapping between two meshes Dear all, I would like to check the convergence of my solution as I refine the mesh. Say, I have two solutions in CG1 space, f_coarse on mesh_coarse and f_fine on mesh_fine, which is a refined mesh_coarse. Can I map/interpolate/project f_fine onto mesh_coarse in Firedrake? Thank you, Tomasz
On 26/10/16 14:12, Tomasz Salwa [RPG] wrote:
Dear Lawrence (thank you also Alastair for the suggestion),
I think your last crude way is what I need, as I'd like to extrapolate results from 3 meshes to get the estimate of the exact solution. I also refine mesh externally in gmsh. Therefore I need results from a few runs with different meshes. I'd like to save the solution and open it in a different file for further study.
I tried to use DumbCheckpoint. Firedrake seems to complain when I store the solution held in a certain object structure and then try to load it without the same structure (even in the same file). Details below. I don't run MPI.
The function names have to be the same (by default they may not be, specify with "name"). There error message could be more helpful though... Lawrence
Ok, it was the name indeed. Thank you! ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> Sent: 26 October 2016 14:29:26 To: firedrake@imperial.ac.uk Subject: Re: [firedrake] mapping between two meshes On 26/10/16 14:12, Tomasz Salwa [RPG] wrote:
Dear Lawrence (thank you also Alastair for the suggestion),
I think your last crude way is what I need, as I'd like to extrapolate results from 3 meshes to get the estimate of the exact solution. I also refine mesh externally in gmsh. Therefore I need results from a few runs with different meshes. I'd like to save the solution and open it in a different file for further study.
I tried to use DumbCheckpoint. Firedrake seems to complain when I store the solution held in a certain object structure and then try to load it without the same structure (even in the same file). Details below. I don't run MPI.
The function names have to be the same (by default they may not be, specify with "name"). There error message could be more helpful though... Lawrence
participants (3)
- 
                
                Gregory, Alastair C A
- 
                
                Lawrence Mitchell
- 
                
                Tomasz Salwa [RPG]