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

BUG: MeshHierarchy with ref_per_level=3 fails #3233

Open
APaganini opened this issue Nov 15, 2023 · 0 comments
Open

BUG: MeshHierarchy with ref_per_level=3 fails #3233

APaganini opened this issue Nov 15, 2023 · 0 comments
Labels

Comments

@APaganini
Copy link
Contributor

APaganini commented Nov 15, 2023

Describe the bug
In MeshHierarchy, users can specify how many refinement_levelsand how many refinements_per_level they want. If refinements_per_level is not 1, 2, or 4 (or probably any power of 2), then restrict and prolong raise a KeyError (it seems because there's a mismatch with the number of dofs).

Steps to Reproduce
This minimal example

from firedrake import *

mesh = UnitSquareMesh(2,2)

for n in range(1, 6): 
    print("\nrefinements_per_level = ", n)

    # refinement_levels=1, refinements_per_level=n
    mh = MeshHierarchy(mesh, 1, n)

    # Coarse space
    V_coarse = FunctionSpace(mh[0], "CG", 2)
    V_coarse_dual = V_coarse.dual()

    # Fine space
    element = V_coarse.ufl_element()
    V_fine = FunctionSpace(mh[-1], element)
    V_fine_dual = V_fine.dual()

    # restrict cofunction from V_fine_dual to V_coarse_dual
    F_fine = Cofunction(V_fine_dual)
    F_coarse = Cofunction(V_coarse_dual)
    try:
        restrict(F_fine, F_coarse)
        print("restrict works")
    except Exception as e:
        print("restrict does not work, the error is:")
        print(e)

    # prolong function from V_coarse into V_fine
    u_coarse = Function(V_coarse)
    u_fine = Function(V_fine)
    try:
        prolong(u_coarse, u_fine)
        print("prolong works")
    except Exception as e:
        print("prolong does not work, the error is:")
        print(e)

outputs

refinements_per_level =  1
restrict works
prolong works

refinements_per_level =  2
restrict works
prolong works

refinements_per_level =  3
restrict does not work, the error is:
Fraction(54043195528445951, 54043195528445952)
prolong does not work, the error is:
Fraction(6004799503160661, 18014398509481984)

refinements_per_level =  4
restrict works
prolong works

refinements_per_level =  5
restrict does not work, the error is:
Fraction(90071992547409921, 90071992547409920)
prolong does not work, the error is:
Fraction(3602879701896397, 18014398509481984)

Expected behavior
From the documentation, this should work with any integer value.

Error message
here is one of the backtraces:

Traceback (most recent call last):
  File "/Users/alberto/Documents/FIREDRAKE/firedrake/src/firedrake/firedrake/mg/kernels.py", line 224, in prolong_kernel
    return cache[key]
           ~~~~~^^^^^
KeyError: ('prolong', (0, (0,), (1,), (2,)), (1, (3,), (4,), (5,)), (2, ()), (0, (0,), (1,), (2,)), (1, (), (), ()), (2, ()))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alberto/Documents/FIREDRAKE/fireshape/examples/levelset/multigridfail.py", line 32, in <module>
    prolong(u_coarse, u_fine)
  File "petsc4py/PETSc/Log.pyx", line 188, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 189, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/Users/alberto/Documents/FIREDRAKE/firedrake/src/firedrake/firedrake/mg/interface.py", line 75, in prolong
    kernel = kernels.prolong_kernel(coarse)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alberto/Documents/FIREDRAKE/firedrake/src/firedrake/firedrake/mg/kernels.py", line 282, in prolong_kernel
    "ncandidate": hierarchy.fine_to_coarse_cells[levelf].shape[1],
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: Fraction(6004799503160661, 18014398509481984)

Environment:

  • Output of `firedrake-status
(firedrake) (ap/reenable_multidgridcontrolspace *)$ firedrake-status
/Users/alberto/Documents/FIREDRAKE/firedrake/bin/firedrake-status:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
 __import__('pkg_resources').require('firedrake==0.13.0+5908.g1692a70c7')
Firedrake Configuration:
   package_manager: True
   minimal_petsc: False
   mpicc: None
   mpicxx: None
   mpif90: None
   mpiexec: None
   disable_ssh: True
   honour_petsc_dir: False
   with_parmetis: False
   slepc: False
   packages: []
   honour_pythonpath: False
   opencascade: False
   tinyasm: False
   torch: False
   petsc_int_type: int32
   cache_dir: /Users/alberto/Documents/FIREDRAKE/firedrake/.cache
   complex: False
   remove_build_files: False
   with_blas: download
   netgen: False
Additions:
   None
Environment:
   PYTHONPATH: None
   PETSC_ARCH: None
   PETSC_DIR: None
Status of components:
---------------------------------------------------------------------------
|Package             |Branch                        |Revision  |Modified  |
---------------------------------------------------------------------------
|FInAT               |master                        |f493084   |False     |
|PyOP2               |master                        |d017d594  |False     |
|fiat                |master                        |e440a06   |False     |
|firedrake           |master                        |1692a70c7 |False     |
|h5py                |firedrake                     |6cc4c912  |False     |
|libspatialindex     |master                        |4768bf3   |True      |
|libsupermesh        |master                        |dbe226b   |False     |
|loopy               |main                          |8158afdb  |False     |
|petsc               |firedrake                     |98a9995288|False     |
|pyadjoint           |master                        |cefba3f   |False     |
|pytest-mpi          |main                          |a478bc8   |False     |
|tsfc                |master                        |47c1324   |False     |
|ufl                 |master                        |cf66c4b3  |False     |
---------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant