Skip to content

[BUG] -AttributeError: 'NaturalBC' object has no attribute 'fn_F' when using add_natural_bc #25

Closed

Description

@Belay-129

Hi uw3 support team,
I encountered an error when applying a natural boundary condition to the Poisson solver in Underworld3, which prevents the solve from running successfully.

poisson.add_dirichlet_bc([17.0], "Top")
q_bottom = 0.065 # W/m2
poisson.add_natural_bc([q_bottom], "Bottom")

poisson.solve()

When applying a natural boundary condition to a Poisson solver, the following error occurs:

AttributeError Traceback (most recent call last)
Cell In[18], line 1
----> 1 poisson.solve()

File src/underworld3/cython/petsc_generic_snes_solvers.pyx:872, in underworld3.cython.generic_solvers.SNES_Scalar.solve()

File src/underworld3/cython/petsc_generic_snes_solvers.pyx:194, in underworld3.cython.generic_solvers.SolverBaseClass._build()

File src/underworld3/cython/petsc_generic_snes_solvers.pyx:744, in underworld3.cython.generic_solvers.SNES_Scalar._setup_pointwise_functions()

AttributeError: 'NaturalBC' object has no attribute 'fn_F'

Thanks for your time and help

Activity

  1. self-assigned this
    on Sep 22, 2025
  2. gthyagi commented on Sep 23, 2025

    @gthyagi
    Contributor

    Hi @Belay-129,

    Please attach the example script you are running so we can debug. It also looks like you’re using an older version of Underworld, please update to the latest release, as some of these issues are already fixed.

    Cheers,
    Thyagi

  3. Belay-129 commented on Sep 23, 2025

    @Belay-129
    Author
  4. Belay-129 commented on Sep 23, 2025

    @Belay-129
    Author

    '''
    mesh = uw.meshing.UnstructuredSimplexBox(
    minCoords=(423755, -10000),
    maxCoords=(496255, 0),
    cellSize=1000,
    regular=False,
    )
    '''

    '''
    k_scalar = uw.discretisation.MeshVariable("k", mesh, 1)
    '''

    '''
    T_soln = uw.discretisation.MeshVariable("T", mesh, 1)
    '''

    '''
    Set up the Poisson system
    poisson = uw.systems.Poisson(mesh, u_Field=T_soln)

    poisson.constitutive_model = uw.constitutive_models.DiffusionModel

    poisson.constitutive_model.Parameters.diffusivity = k_scalar.sym[0]

    poisson.f = 0
    '''

    BCs

    '''
    poisson.add_dirichlet_bc([17.0], "Top")
    q_bottom = 0.065 #W/m2
    poisson.add_natural_bc([q_bottom], "Bottom")
    '''

    solve
    poisson.solve()

  5. gthyagi commented on Sep 23, 2025

    @gthyagi
    Contributor

    Hi Thyagi,
    Thank you for your response. Could you please confirm the current version of Underworld? I checked on GitHub and found the version listed as:
    version = "0.99.0b"

    This matches the version I already have installed.
    Cheers,
    Belay
    …

    The version number may look the same, but we’ve recently pushed many important changes.

  6. jcgraciosa commented on Sep 23, 2025

    @jcgraciosa
    Contributor

    Hello @gthyagi and @Belay-129, I found the cause of the issue and I'm investigating a fix.
    I'll give you some updates soon.

    Cheers,
    JC

  7. Belay-129 commented on Sep 23, 2025

    @Belay-129
    Author
  8. added a commit that references this issue on Sep 23, 2025
  9. added a commit that references this issue on Oct 8, 2025
  10. lmoresi commented on Feb 26, 2026

    @lmoresi
    Member

    Status update — bug confirmed, tracked internally

    We've confirmed the root cause: the NaturalBC namedtuple defines fn_f (lowercase) but solver code references fn_F (uppercase). Additionally, the Poisson natural BC setup has a deeper issue causing PETSc error 73 ("Object in wrong state") — the test (test_1000_poissonNaturalBC.py) is currently skipped pending a fix.

    Note that the Stokes solver's natural BCs (traction conditions) work correctly — the issue is specific to the scalar Poisson solver path.

    This is tracked in our internal planning and will be addressed as part of the solver cleanup work. We'll update this issue when we have a fix.

    @Belay-129 — in the meantime, Dirichlet BCs work correctly for the Poisson solver. If your problem allows it, you may be able to reformulate using a Dirichlet condition on the dependent variable rather than a Neumann flux condition.

  11. added a commit that references this issue on Feb 28, 2026
    12075ef
  12. lmoresi commented on Feb 28, 2026

    @lmoresi
    Member

    Fixed in PR #60 (merged to development)

    The root cause was two bugs in the scalar Poisson solver (SNES_Scalar):

    1. Natural BCs were registered with per-boundary labels ("Bottom") instead of the consolidated "UW_Boundaries" label
    2. The compiled boundary residual/jacobian functions were never passed to PETSc's DS system — the code was completely missing from _setup_solver

    Both issues were present in the Scalar solver but not the Vector (Stokes) solver, which is why Stokes natural BCs (traction conditions) worked correctly.

    The fix mirrors the working Stokes pattern. Verified with an analytical solution (T = x²y with mixed Dirichlet/Neumann BCs) on simplex and quad meshes.

    @Belay-129 — this fix is now on the development branch. Your original code pattern should work:

    poisson.add_dirichlet_bc([17.0], "Top")
    poisson.add_natural_bc([0.065], "Bottom")
    poisson.solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions