Skip to content

Buoyancy example on static multi-level MAC grid #4423

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

Draft
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

drb-tai
Copy link

@drb-tai drb-tai commented Apr 17, 2025

Summary

Add minimal working example of a buoyancy calculation on a MAC grid on a static multi-level mesh without subcycling-in-time. Detailed description in README.md.

Draft PR to get feedback on the following questions:

  • Would this work be useful as an example, a test, documentation, or something else? If so:
    • Where should it live, be named, etc?
    • Any correctness, best practices, or language/terminology issues?
    • Any suggestions for a more illustrative model setup?

Additional background

I built up this example while attempting to learn how to convert an existing single-level code to multi-level. It was intended to represent a single stage in a CFD code, and to expose and solve the unique requirements for a (static, non-subcycling-in-time) multi-level solve compared to a (uniform, distributed parallel) single-level solve. For this buoyancy algorithm, those unique requirements seem to be a) initialization of coarse/fine ghosts for temperature inputs, and b) an "average down" for the velocity outputs. I plan to do this again for a more complicated case (heat equation? Suggestions welcome) to tease out more of these requirements, and may be able to contribute that if it's useful.

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

drb-tai and others added 6 commits April 15, 2025 11:38
Summary:
  Create a place to put some new code.

  The example will implement a simple velocity update on a multi-level
  MAC grid, without subcycling-in-time.  It was created to explore what
  is necessary to convert a single-level code to multi-level, and it is
  being shared in an attempt to document what was learned.

main.cpp
* main()
  - Boilerplate for Initialize()/Finalize().
* MyMain()
  - Stub implementation.  Placeholder for the example/test.

CMakeLists.txt
GNUmakefile
Make.package
* Boilerplate for adding the example/test.  The initial implementation
  will only support 3D.
Summary:
  Example/test implementing a simple buoyancy calculation on a MAC grid
  on a multi-level mesh without subcycling-in-time.

  The intention in developing this code was to identify the requirements
  for converting a single-level code to multi-level, starting with a
  simple calculation.  This calculation requires a) an "interpolation
  from coarse" step to initialize the coarse/fine ghosts on one of the
  input data sets (temperature), and b) an "average down" step to
  overwrite the covered coarse results.

Tests/Amr/Buoyancy/main.cpp
* Add a big comment block documenting the system that is being
  implemented.
  - Note the buoyancy calculation itself is not particularly
    interesting.  Rather, it is a simple system which should allow for
    exactly reproducing an analytic solution if the composite mesh is
    handled correctly, and which will show a variance if ghosts are not
    handled correctly.
* MyMain()
  - Allocate the multi-level MultiFabs, initialize temperature and
    velocity data, call the buoyancy calculation subroutine, and test
    that the results match the analytic expectation.

Tests/Amr/Buoyancy/helpers.H
Tests/Amr/Buoyancy/helpers.cpp
* DefineGeometry()
  - Declare a 4x1x1 domain, refined twice.
* DefineBoxArrays()
  - Declare a single box/FAB at each level, covering only half of the
    next-coarser level.
* DefineDMs()
  - Default DistributionMappings should put all the FABs on the
    rank-zero process.
* DefineFABs()
  - Declare a cell-centered temperature MultiFab.
  - Declare a set of face-centered velocity MultiFabs (i.e. a MAC grid).
* CalculateBuoyancy()
  - Calculate the buoyant acceleration and update the velocities for the
    current time step.
  - Perform an "average down" to overwrite any covered coarse results
    with the solution from the fine grid.  For this test case, the
    results should be identical in the bulk, and should vary only at the
    domain boundary.
* CalculateVelocities()
  - Function meant to mock a non-subcycling-in-time velocity update
    calculation at the current time step.  This mock just sets the
    velocity at all levels to {0.0,0.0,0.0}.
* CalculateTemperatures()
  - Function meant to mock a non-subcycling-in-time temperature update
    calculation at the current time step.  This mock sets
      T(x,y,z) = 300.0+100.0*x
    on all the valid cells, and then updates all temperature ghosts.
* SetTemperatureProfile()
  - Helper to set the temperature field.
* UpdateTemperatureGhosts()
  - Helper to update the internal, external, and coarse/fine temperature
    ghosts.
* FillCoarseFineGhosts()
  - Helper to update the coarse/fine temperature ghosts.

Tests/Amr/Buoyancy/CMakeLists.txt
Tests/Amr/Buoyancy/Make.package
* Add the new source file.
Tests/Amr/Buoyancy/Amr/Buoyancy/main.cpp
* MyMain()
  - Skip the debug output printing.

Tests/Amr/Buoyancy/Amr/Buoyancy/helpers.H
Tests/Amr/Buoyancy/Amr/Buoyancy/helpers.cpp
* Delete the debug output functions.
* Remove ifdef'd out GTest assertion.
Tests/Amr/Buoyancy/Amr/Buoyancy/helpers.H
Tests/Amr/Buoyancy/Amr/Buoyancy/helpers.cpp
* Attempt to match project formatting standards.
Tests/Amr/Buoyancy/README.md
Tests/Amr/Buoyancy/main.cpp
* Move the documentation for this example from main.cpp into a new
  README.md, converting some formatting.
@WeiqunZhang
Copy link
Member

Sorry. I am not sure where this belongs to.

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.

2 participants