Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h derefinement fails after p adaption #215

Open
tradeqvest opened this issue Mar 21, 2024 · 2 comments
Open

h derefinement fails after p adaption #215

tradeqvest opened this issue Mar 21, 2024 · 2 comments

Comments

@tradeqvest
Copy link

Hello,

I am currently working on combining hp (de-)refinement, however, during testing I noticed that when modifying the element order, a subsequent h derefinement was not possible anymore.

import mfem.ser as mfem
def init_mesh_and_fespace():
    # create simple mesh consisting of 1 triangle
    mesh = mfem.Mesh(2, 3, 1, 0, 2)
    mesh.AddVertex(mfem.Vector([0.0, 0.0]))
    mesh.AddVertex(mfem.Vector([1.0, 0.0]))
    mesh.AddVertex(mfem.Vector([0.0, 1.0]))
    mesh.AddTriangle([0, 1, 2], 1)
    mesh.FinalizeTriMesh(1, 1, True)

    # create finite element space
    fec = mfem.H1_FECollection(1, 2)
    fespace = mfem.FiniteElementSpace(mesh, fec)

    return mesh, fespace


mesh, fespace = init_mesh_and_fespace()

mesh.GeneralRefinement(mfem.intArray([0]), 1, 0) # h refine element 0
fespace.Update()
mesh.GeneralRefinement(mfem.intArray([0]), 1, 0)  # h refine element 0
fespace.Update()
# Start of p refinement
fespace.SetElementOrder(3, 1)
fespace.Update(False)
# End of p refinement
derefined = mesh.DerefineByError(mfem.Vector([0, 0, 0, 0, 1, 1, 1]), 0.5, 0, 1)
fespace.Update()

In this code, I create a simple mesh, h refine it twice, then reset the element order of element 3 to 1 as a p refinement with no effect and h derefine. When commenting out the p refinement part, the derefinement works as intended. Otherwise, I get the following error:

RuntimeError: PyMFEM error (mfem::ErrorException): Verification failed: (GetLastOperation() == Mesh::REFINE) is false:
 --> 
 ... in function: const CoarseFineTransformations &mfem::Mesh::GetRefinementTransforms()

Do you have any insights on this?

Thank you in advance for your time and effort!

@rw-anderson
Copy link
Member

I don't think you can currently mix the adaptations in sequence like that; an h coarsening must be preceded by an h refinement step. That's what that assertion is requiring.

I do not know if that check is there simply because it was the expected usage pattern at the time it was written (predating p adaptation), or if there is a more fundamental reason why the coarsening operations depend on that being the case.

@tradeqvest
Copy link
Author

Thank you for your answer, however inserting an h refinement before a subsequent derefinement still leads to the error iff there has been a p adaption before:

mesh, fespace = init_mesh_and_fespace()

mesh.GeneralRefinement(mfem.intArray([0]), 1, 0) # h refine element 0
fespace.Update()
# Start of p refinement
fespace.SetElementOrder(3, 1)
fespace.Update(False)
# End of p refinement
mesh.GeneralRefinement(mfem.intArray([0]), 1, 0)  # h refine element 0
fespace.Update()
derefined = mesh.DerefineByError(mfem.Vector([0, 0, 0, 0, 1, 1, 1]), 0.5, 0, 1)
print(derefined)
fespace.Update()

This code snippet also leads to the error. The error itself only occurs on the last line when updating the fespace, so the mesh has been derefined already. My current workaround is to create a new fespace, then derefine, then set the old element orders again, which is suboptimal and brings about many other issues. Would be glad if there was another way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants