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

fespace update fails for h derefinement after p adaption #4230

Closed
tradeqvest opened this issue Apr 4, 2024 · 1 comment
Closed

fespace update fails for h derefinement after p adaption #4230

tradeqvest opened this issue Apr 4, 2024 · 1 comment
Assignees

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 fespace update for the 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()
# 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)
fespace.Update()

The code above uses PyMFEM, yet the issue stems from mfem. In this code, I create a simple mesh, h refine it once, then reset the element order of element 3 to 1 as a p refinement with no effect, h refine and then h derefine. When commenting out the p refinement part, the derefinement works as intended. Otherwise, I get the following error during the fespace.Update():

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? Is there a potential workaround for this?

Thank you in advance for your time and effort!

@dylan-copeland
Copy link
Member

Hello @tradeqvest, thanks for your interest in hp-(de)refinement. In the current state of the MFEM master branch, hp-refinement should work for H1 spaces in serial (the parallel extension is a work in progress, see PR 4038). As far as I know, derefinement is not supported with variable-order spaces, even in serial. I think it works for h-derefinement (constant order), but even that is not tested in any example, miniapp, or unit test.

The error you posted is a failed verification that the last mesh operation was an h-refinement. My guess is that the last operation was NONE, in the case of p-refinement. In other words, this error says that derefinement is not supported when the last mesh operation was not an h-refinement.

Supporting derefinement in variable-order spaces may require significant development effort in the MFEM library, so there is likely no workaround or easy solution. We should add this capability in MFEM in the future (no definite plans currently).

@tzanio tzanio closed this as completed May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants