Skip to content

Add conservative flux divergence operator (FV::ConservativeFluxDiv) #3122

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

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

pressatojump
Copy link

Summary

This PR adds a conservative flux divergence operator for finite-volume discretizations in BOUT++. The operator computes the divergence of face-centered fluxes stored in FaceField3D objects.

Motivation

The conservative flux divergence operator is essential for finite-volume methods that ensure exact conservation properties. This is particularly important for:

  • Transport equations where conservation is critical
  • Shock-capturing schemes
  • Coupled multi-physics simulations requiring consistent fluxes

Implementation Details

  • New functions: FV::ConservativeFluxDiv with two overloads:
    • Basic version with boolean flag for boundary flux from field
    • Extended version with explicit boundary flux pointers for each dimension
  • Finite-volume discretization: Properly accounts for metric factors (J, dx, dy, dz)
  • Boundary handling: Complete support for X, Y, and Z boundary fluxes
  • Parallel support: Includes ghost cell communication via mesh_facefield_comm

Changes

  • Added include/bout/conservative_flux_div.hxx - header with function declarations
  • Added src/mesh/conservative_flux_div.cxx - implementation
  • Fixed FaceField3D virtual method overrides for C++17 compatibility
  • Added unit tests (compile test + framework for functional tests)
  • Updated build system files

Testing

  • Compile test verifies the operator builds and links correctly
  • Functional tests are implemented but disabled due to FakeMeshFixture size constraints
  • All existing tests continue to pass

API Addition

namespace FV {
  // Basic version - uses field values at boundaries if bndry_flux=true
  Field3D ConservativeFluxDiv(const FaceField3D& F, bool bndry_flux = false);

  // Extended version - explicit boundary fluxes
  Field3D ConservativeFluxDiv(const FaceField3D& F,
                             const Field3D* bndry_flux_x,
                             const Field3D* bndry_flux_y,
                             const Field3D* bndry_flux_z);
}

Anonymous and others added 3 commits June 12, 2025 18:39
Implements FaceField3D<T> class to store field data on cell faces in all
three directions (X, Y, Z). This is the foundation for the conservative
flux divergence operator.

Key features:
- Templated class with default type BoutReal
- Three Field3D components with appropriate staggered locations
  - x component: CELL_XLOW
  - y component: CELL_YLOW
  - z component: CELL_ZLOW
- Inherits from FieldData for solver integration
- Complete arithmetic operators (component-wise)
- Unit tests for all operations
- CMake build system integration

This implementation follows the established BOUT++ patterns used in
Vector3D and integrates cleanly with the existing field infrastructure.

Part of conservative flux divergence feature implementation.
Reference: Plan 01-data-structures.md

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Implements halo exchange for face-centered fields leveraging BOUT++'s
existing staggered grid support. The implementation provides convenience
methods for communicating FaceField3D across processor boundaries.

Key features:
- Convenience methods communicate(FaceField3D&) and variants
- Leverages existing Field3D staggered location support
- Each component (x, y, z) communicated with correct location
- Works with existing MPI infrastructure
- Documentation explains reliance on StaggerGrids mechanism

Implementation notes:
- No core Mesh modifications needed
- BOUT++ already handles CELL_XLOW/YLOW/ZLOW locations
- Face ownership conventions maintained by existing code
- Ghost cells exchanged to preserve flux continuity

The approach is minimal and non-invasive, relying on BOUT++'s mature
staggered grid infrastructure rather than reimplementing communication.

Part of conservative flux divergence feature implementation.
Reference: Plan 02-communication.md

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Implements FV::ConservativeFluxDiv for finite-volume discretization of flux divergence.

  - Add ConservativeFluxDiv with two overloads for boundary flux handling
  - Implement complete boundary handling for X, Y, and Z dimensions
  - Add parallel communication support via mesh_facefield_comm
  - Fix FaceField3D compilation issues with virtual method overrides
  - Add unit tests (compile test + disabled functional tests due to mesh constraints)
  - Update CMakeLists.txt to include new source files

  The operator correctly handles:
  - Interior divergence calculation using finite-volume method
  - Optional boundary fluxes for all three dimensions
  - Ghost cell synchronization for parallel runs
  - Proper metric factors (J, dx, dy, dz) for curvilinear coordinates
@ZedThree
Copy link
Member

This looks like it's built off next but going into master -- you probably just need to switch the base branch of the PR :)

@pressatojump pressatojump changed the base branch from master to next June 20, 2025 05:55
@pressatojump
Copy link
Author

Done @ZedThree :)

Comment on lines +31 to +32
// These tests are disabled because they require a larger mesh than FakeMeshFixture provides
// The conservative flux div operator has been implemented and compiles correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, @tomc271 encountered this as well -- Tom, please could you pull out your FakeMeshFixture generalisation into its own PR so that it can be used here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here you are:
#3132

* Field3D& fz = flux.z();
* \endcode
*/
template <typename T = BoutReal>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that this could also be used with other types? I couldn't immediately see what T is actually being used for

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

Successfully merging this pull request may close these issues.

3 participants