BOUT-dev icon indicating copy to clipboard operation
BOUT-dev copied to clipboard

Add conservative flux divergence operator (FV::ConservativeFluxDiv)

Open pressatojump opened this issue 6 months ago • 2 comments

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);
}

pressatojump avatar Jun 13 '25 00:06 pressatojump

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

ZedThree avatar Jun 13 '25 13:06 ZedThree

Done @ZedThree :)

pressatojump avatar Jun 20 '25 05:06 pressatojump