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

Geometric Multigrid #911

Merged
merged 196 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
fd7bb10
Add information to mesh required for GMG, build mesh levels
lroberts36 Jul 19, 2023
0e3f9a7
Add loop facilities over GMG boundaries
lroberts36 Jul 19, 2023
e0a7592
format and lint
lroberts36 Jul 19, 2023
93ab994
Fix bug when setting neighbor ranks
lroberts36 Jul 19, 2023
3d4d706
untested inclusion of gmg MeshData
lroberts36 Jul 19, 2023
b55408c
fix bug
lroberts36 Jul 19, 2023
b2ac5e8
Add GMG Boundary buffer building and only communicate interior when t…
lroberts36 Jul 19, 2023
df670c9
Format and lint
lroberts36 Jul 19, 2023
65e5cf9
Add same level neighbor finding
lroberts36 Jul 24, 2023
5ca17d7
Fix periodicity bugs
lroberts36 Jul 24, 2023
9efb42b
Clean up neighbor finding
lroberts36 Jul 24, 2023
388f3c4
Use newly found neighbors
lroberts36 Jul 24, 2023
c27568a
Format and lint
lroberts36 Jul 25, 2023
1414b8a
Remove extra print statement
lroberts36 Jul 25, 2023
ac9e08e
Clean up and refactor logical location
lroberts36 Jul 25, 2023
e9c35d6
Attempt to optimize logical location
lroberts36 Jul 25, 2023
562ae8c
update tests too
lroberts36 Jul 25, 2023
acddb7b
format and lint
lroberts36 Jul 25, 2023
1eedb84
Deal with multiple neighbor connections
lroberts36 Jul 25, 2023
55cd2ba
Remove debugging printf
lroberts36 Jul 25, 2023
8677a08
Remove unused code
lroberts36 Jul 25, 2023
9ece056
Build buffers for multigrid levels
lroberts36 Jul 25, 2023
dd38295
Build all level communication buffers and use right restriction
lroberts36 Jul 26, 2023
744c9f2
Separate gmg implementation into its own file
lroberts36 Jul 26, 2023
5beea19
actually add new file
lroberts36 Jul 26, 2023
0f78a6f
Use GMG hierarchy building method
lroberts36 Jul 26, 2023
8004d42
Add start on testing GMG
lroberts36 Jul 26, 2023
e9834d0
Format and lint
lroberts36 Jul 26, 2023
9d8d5d0
Add string for diagnosing index ranges
lroberts36 Jul 26, 2023
7595ba8
Add place holders for restriction data
lroberts36 Jul 26, 2023
c08568d
Add multigrid flag
lroberts36 Jul 26, 2023
678d19c
Fix bug in mesh data creation
lroberts36 Jul 26, 2023
7e68442
Small fixes
lroberts36 Jul 26, 2023
abdc2fa
Deal with locations above the root grid more carefully
lroberts36 Jul 27, 2023
20e4c91
Make coarse blocks a vector to account for no coarse neighbor
lroberts36 Jul 27, 2023
d978e91
Appropriately build buffers
lroberts36 Jul 27, 2023
93fa806
Format and lint
lroberts36 Jul 27, 2023
1042d7a
Add multigrid flag and buildboundaries for the base mesh so tests run
lroberts36 Jul 27, 2023
e2db850
Send ghost data when going from coarse to fine
lroberts36 Jul 27, 2023
2395d3d
format and lint
lroberts36 Jul 27, 2023
2f6abee
Fix the coordinates object above the root level
lroberts36 Jul 28, 2023
21d479a
Test going up and down the mesh hierarchy
lroberts36 Jul 28, 2023
ec8821d
Format and lint
lroberts36 Jul 28, 2023
902ca50
Working nodal prolongation and restriction with sparse packs
lroberts36 Jul 31, 2023
2fb10c6
Make GetBounds interface generic in meshblock_data
lroberts36 Aug 3, 2023
7f29eb6
Make GetBounds interface generic in mesh data
lroberts36 Aug 3, 2023
466e51b
Add linear shared prolongation operator
lroberts36 Aug 3, 2023
02234b1
Rewrite task list
lroberts36 Aug 3, 2023
b8f3766
Register zero boundary conditions
lroberts36 Aug 3, 2023
ea32197
Use tophat rhs
lroberts36 Aug 3, 2023
b428b26
Many changes to get Jacobi working
lroberts36 Aug 3, 2023
184b12e
format and lint
lroberts36 Aug 3, 2023
cb65d39
Fix printf warnings
lroberts36 Aug 3, 2023
aed517b
Change so things work on GPU
lroberts36 Aug 3, 2023
d5de6d8
Update changelog
lroberts36 Aug 3, 2023
cdddecc
Update copyrights
lroberts36 Aug 3, 2023
07a956e
Only build grid hierarchy when a flag is set
lroberts36 Aug 3, 2023
fad4d6e
Remove unused variables
lroberts36 Aug 3, 2023
3f43524
Switch location of gmg checks
lroberts36 Aug 3, 2023
eb3d188
switch location of gmg checks
lroberts36 Aug 3, 2023
68869c1
same
lroberts36 Aug 3, 2023
b06016a
maybe unused
lroberts36 Aug 3, 2023
974c9a9
Fix multi-d bug
lroberts36 Aug 3, 2023
83ec9da
Add simple prolongation/restriction task list
lroberts36 Aug 9, 2023
73d0831
Update output for 2D
lroberts36 Aug 9, 2023
f81a202
Initialize with res_err with linear function
lroberts36 Aug 9, 2023
89d8fa9
Generalize logical location to negative levels
lroberts36 Aug 9, 2023
54adfa1
work on building further coarsened grids
lroberts36 Aug 9, 2023
c12b0f3
Merge branch 'lroberts36/refactor-region-size' into lroberts36/add-mu…
lroberts36 Aug 10, 2023
e14d8de
Update to new interface
lroberts36 Aug 10, 2023
30defbd
Loop over directions
lroberts36 Aug 10, 2023
87d144e
Format and lint
lroberts36 Aug 10, 2023
b5ac2c0
Merge branch 'lroberts36/add-noncell-amr' into lroberts36/add-multi-grid
lroberts36 Aug 10, 2023
f53978c
Merge branch 'lroberts36/add-multi-grid' into lroberts36/add-negative…
lroberts36 Aug 10, 2023
8888665
Fixes for compiling and making tests work
lroberts36 Aug 10, 2023
38b451c
typo
lroberts36 Aug 15, 2023
e5fc879
Move enums to basic_types
lroberts36 Aug 15, 2023
dc24831
Add LogicalLocation Coordinate functionality
lroberts36 Aug 15, 2023
515b90f
Refactor SetBlockSizeAndBoundaries
lroberts36 Aug 15, 2023
ba80ed3
refactor static refinement
lroberts36 Aug 16, 2023
ceea3c2
exorcise mesh generators from the code
lroberts36 Aug 16, 2023
e86fc57
Format and lint
lroberts36 Aug 16, 2023
94d0264
fix bugs
lroberts36 Aug 16, 2023
fac206b
Include block size info in neighbor block
lroberts36 Aug 16, 2023
27f8b5c
Add topological element listings
lroberts36 Aug 17, 2023
ef23b61
Make indexing work for differing block sizes
lroberts36 Aug 17, 2023
22ebf08
Get index ranges on device from packs
lroberts36 Aug 17, 2023
91dc79d
Messing around with oddly shaped grids
lroberts36 Aug 17, 2023
fe79651
Format and lint
lroberts36 Aug 17, 2023
0fb79fe
compile w/o warnings on GPU
lroberts36 Aug 17, 2023
c1f85ee
fixes to make gpu tests run
lroberts36 Aug 17, 2023
8540819
Merge branch 'lroberts36/add-noncell-amr' into lroberts36/add-multi-grid
lroberts36 Aug 17, 2023
0871103
Merge branch 'lroberts36/add-multi-grid' into lroberts36/add-negative…
lroberts36 Aug 17, 2023
470df8a
Add CoordinateDirection back
lroberts36 Aug 17, 2023
e64ed3f
Include possible locations that are partially within root grid
lroberts36 Aug 17, 2023
f2c4284
Cleanup debug output
lroberts36 Aug 17, 2023
6475500
Format and lint
lroberts36 Aug 17, 2023
b72de6c
Start looking at multi-d poisson
lroberts36 Aug 17, 2023
5947062
Fix initialization bug
lroberts36 Aug 24, 2023
68ab593
Add constructor for NeighborBlock that automatically sets the index r…
lroberts36 Aug 24, 2023
80d6769
testing...
lroberts36 Aug 24, 2023
2b16bee
Allow for building boundary buffers twice
lroberts36 Aug 24, 2023
cdf9f9e
format
lroberts36 Aug 24, 2023
55a9190
Deal with periodicity below the root grid
lroberts36 Aug 25, 2023
bd0005a
Add sinusoidal setup
lroberts36 Aug 28, 2023
45c8f45
More work to test Poisson
lroberts36 Aug 28, 2023
5a8fa9a
problem for comparing to athena++
lroberts36 Aug 29, 2023
85d9d4e
Remove print statements
lroberts36 Aug 29, 2023
9d390ab
Update to work with damping
lroberts36 Aug 29, 2023
e85c3e5
Add a fixe value on the face boundary condition
lroberts36 Aug 29, 2023
616f8ad
Prevent segfault
lroberts36 Aug 29, 2023
efeecfc
Fix boundary conditions
lroberts36 Aug 29, 2023
8e46cdf
Format and lint
lroberts36 Aug 29, 2023
497e54c
Implement preconditioned CG
lroberts36 Aug 30, 2023
fa82dbc
Switch to flux based matrix calculations
lroberts36 Aug 30, 2023
fc1db71
Add in flux corrections
lroberts36 Aug 31, 2023
3f7ecae
Switch to other rhs
lroberts36 Aug 31, 2023
f5ffd91
fix symmetry related bug
lroberts36 Aug 31, 2023
5ba8f80
Split to multiple different task collections
lroberts36 Sep 5, 2023
a62504b
add different task collections to header
lroberts36 Sep 5, 2023
c1abe4d
MG working for 1D problem
lroberts36 Sep 5, 2023
9ead572
Debugging AMR MG
lroberts36 Sep 7, 2023
66afc9c
Distinguish between GMG restriction and prolongation
lroberts36 Sep 11, 2023
501a5d0
FAS working
lroberts36 Sep 12, 2023
8d55dc8
fix bugs causing tests to fail
lroberts36 Sep 12, 2023
782786c
Moving towards AMR MG
lroberts36 Sep 13, 2023
b9535dd
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Sep 13, 2023
53a7107
fix bug preventing compilation
lroberts36 Sep 13, 2023
ab633cb
Merge branch 'lroberts36/add-multi-grid' into lroberts36/add-negative…
lroberts36 Sep 13, 2023
ea86d18
Rename index range types and prolongate into ghosts for interior comm…
lroberts36 Sep 13, 2023
a1cb027
working code
lroberts36 Sep 13, 2023
c0647bc
cleanup print outs
lroberts36 Sep 14, 2023
987aeaa
Format and lint
lroberts36 Sep 14, 2023
8f4fbe1
Remove connectivity print out
lroberts36 Sep 14, 2023
e3edd3c
Add preconditioned BiCGSTAB
lroberts36 Sep 14, 2023
076ada0
Fix parameter bug
lroberts36 Sep 19, 2023
66cbdc4
Add some regional dependencies to be careful
lroberts36 Sep 19, 2023
43dd558
Add variable number of vcycles and calculate true residual
lroberts36 Sep 20, 2023
d5e80a1
Add variable diffusion coefficients and GS
lroberts36 Sep 20, 2023
2fc452e
Move things to bit_hacks utilities header
lroberts36 Sep 22, 2023
a8734a7
debugging AMR MGBiCGStab
lroberts36 Sep 22, 2023
42c69e0
code cleanup
lroberts36 Sep 22, 2023
802c9c9
Update parthenon input for poisson_gmg
lroberts36 Sep 22, 2023
43c57bd
Alter kernels to take option to only work on finest blocks in two-lev…
lroberts36 Sep 25, 2023
b0463a9
Add information about the grid that is represented by a particular me…
lroberts36 Sep 25, 2023
8b8550c
Specify the grid type of MeshData in a data collection
lroberts36 Sep 25, 2023
dbe43aa
Build two-level composite grids and search for subset of neighbors there
lroberts36 Sep 25, 2023
a364e61
cleanup and fix task list
lroberts36 Sep 25, 2023
fcba3dd
Format and lint
lroberts36 Sep 25, 2023
a267959
cleanup and remove extra communication
lroberts36 Sep 25, 2023
1cdde27
cleanup
lroberts36 Sep 25, 2023
1393d49
small
lroberts36 Sep 25, 2023
bc827db
Updated parameter input
lroberts36 Sep 25, 2023
4dfb6b2
Format and lint
lroberts36 Sep 25, 2023
1d8e2ed
Merge pull request #924 from parthenon-hpc-lab/lroberts36/add-negativ…
lroberts36 Sep 25, 2023
04e5620
Add documentation
lroberts36 Sep 26, 2023
27d2ac0
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Sep 26, 2023
948a723
Add raw GMG regression test
lroberts36 Sep 26, 2023
93cd2d3
format and lint
lroberts36 Sep 26, 2023
8be264a
Reintroduce comments
lroberts36 Sep 26, 2023
371dcd8
remove old comments
lroberts36 Sep 26, 2023
58c33a4
Update example/poisson_gmg/parthenon_app_inputs.cpp
lroberts36 Oct 5, 2023
e3556b9
Update example/poisson_gmg/parthenon_app_inputs.cpp
lroberts36 Oct 5, 2023
a49ee34
Update doc/sphinx/src/mesh/mesh.rst
lroberts36 Oct 5, 2023
e2a712c
Update doc/sphinx/src/mesh/mesh.rst
lroberts36 Oct 5, 2023
21bc763
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Oct 5, 2023
13135b3
format
lroberts36 Oct 5, 2023
b8d0ddb
lint
lroberts36 Oct 5, 2023
5bbbf98
comment
lroberts36 Oct 5, 2023
c1aefef
comment
lroberts36 Oct 5, 2023
7f7a13c
Finish respond to Jonah's comments
lroberts36 Oct 5, 2023
a925229
Update example/poisson_gmg/poisson_package.hpp
lroberts36 Oct 10, 2023
bae269f
Update example/poisson_gmg/parthenon_app_inputs.cpp
lroberts36 Oct 13, 2023
65454c3
Update example/poisson_gmg/parthinput.poisson
lroberts36 Oct 13, 2023
7086c04
Update example/poisson_gmg/parthinput.poisson
lroberts36 Oct 13, 2023
fc0467b
Update src/mesh/logical_location.hpp
lroberts36 Oct 13, 2023
e1a88fd
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Oct 13, 2023
1755cc6
format and lint
lroberts36 Oct 13, 2023
0fa5efa
comment
lroberts36 Oct 13, 2023
3844857
switch to default inner loop pattern
lroberts36 Oct 13, 2023
15ac1e5
remove unused
lroberts36 Oct 13, 2023
a2ac091
brief comment
lroberts36 Oct 13, 2023
14c452d
Remove prolongate2 and format
lroberts36 Oct 13, 2023
c779ddf
Revert loop pattern
lroberts36 Oct 13, 2023
c7918c1
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Oct 18, 2023
76a56a9
Allow for empty mesh data
lroberts36 Oct 20, 2023
8b2966f
small to compile
lroberts36 Oct 20, 2023
6475436
Add communicators for GMG fields
lroberts36 Oct 20, 2023
c013217
introduce task list dependency
lroberts36 Oct 23, 2023
b22e830
format and small
lroberts36 Oct 23, 2023
9fa1626
remove unused
lroberts36 Oct 23, 2023
94740ef
fix compile bug
lroberts36 Oct 23, 2023
6c1a833
Merge branch 'develop' into lroberts36/add-multi-grid
lroberts36 Oct 24, 2023
176d7c3
Fix comment
lroberts36 Oct 31, 2023
b099405
Merge branch 'develop' into lroberts36/add-multi-grid
bprather Nov 7, 2023
45a6b27
Merge pull request #966 from parthenon-hpc-lab/lroberts36/fix-multigr…
lroberts36 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR 911]](https://github.com/parthenon-hpc-lab/parthenon/pull/911) Add infrastructure for geometric multi-grid
- [[PR 932]](https://github.com/parthenon-hpc-lab/parthenon/pull/932) Add GetOrAddFlag to metadata
- [[PR 931]](https://github.com/parthenon-hpc-lab/parthenon/pull/931) Allow SparsePacks with subsets of blocks
- [[PR 921]](https://github.com/parthenon-hpc-lab/parthenon/pull/921) Add more flexible ways of adding and using MeshData/MeshBlockData objects to DataCollections
Expand Down
54 changes: 51 additions & 3 deletions doc/sphinx/src/boundary_communication.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _boundary_communication:

Boundary communication-in-one concepts
======================================

Expand All @@ -22,20 +24,60 @@ array of all the kinds of caches needed for the various kinds of
boundary operations performed.

We note that this infrastructure is more general than just ghost halos.
The same machinery could, for example, be used to prolongate or restrict
an entire meshblock.
The same machinery is used for communicating the interiors of meshblocks
that are restricted and/or prolongated between geometric multi-grid levels.
Additionally, with the ownership model for non-face fields, the basic
communication infrastructure could deal with flux correction as well
(although currently flux correction uses a somewhat separate code path).

Buffer subsets
--------------

Sometimes it is desirable, for example for custom prolongation and
restriction, to loop over a subset of the ghost sub-halos, rather than
restriction or to communicate on a single geometric multi-grid level,
to loop over a subset of the ghost sub-halos, rather than
all halos at once. This is enabled by the ``buffer_subsets`` and
``buffer_subsets_h`` arrays, which are contained in ``BvarsSubCache_t``.
The ``buffer_subsets`` array is a matrix, where the rows index the
subset, and the columns point to the indices in the ``bnd_info`` array
containing the subset of sub-halos you wish to operate on.

To communicate across a particular boundary type, the templated
boundary communication routines (see :boundary_comm_tasks:`boundary_comm_tasks`.)
should be instantiated with the desired ``BoundaryType``, i.e.
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved

.. code:: cpp
SendBoundBufs<BoundaryType::gmg_restrict_send>(md);
The different ``BoundaryType``s are:
- ``any``: Communications are performed between all leaf blocks (i.e. the
standard Parthenon grid that does not include multi-grid related blocks).
- ``local``: Communications are performed between all leaf blocks that
are on the current rank. *Currently, this option should not be used
because there are possibly associated bugs. This and nonlocal would
only be used as a potential performance enhancement, calling both
should result in the same communication as just calling
BoundaryType::any.*
- ``nonlocal``: Communications are performed between all leaf blocks that
are on different ranks than the current rank. *Currently, this option
should not be used because there are possibly associated bugs.*
- ``flxcor_send`` and ``flxcor_recv``: Used only for flux correction
routines, currently cannot be passed to regular boundary communication
routines.
- ``gmg_same``: Communicates ghost halos between blocks in the
same geometric multi-grid level.
- ``gmg_restrict_send`` and ``gmg_restrict_recv``: For restricting
block interiors between geometric multi-grid levels, i.e. inter-grid
communication. *It is probably not necessary to have separate
communicators for sending and receiving, but for now this is the way
if was written*
- ``gmg_prolongate_send`` and ``gmg_prolongate_recv``: For prolongating
block interiors between geometric multi-grid levels, i.e. inter-grid
communication. *It is probably not necessary to have separate
communicators for sending and receiving, but for now this is the way
if was written*

.. _sparse boundary comm:

Sparse boundary communication
Expand Down Expand Up @@ -327,6 +369,8 @@ generalizes to more realistic problems not being run with all ranks on
the same node. See ``InitializeBufferCache(...)`` for how to choose the
ordering.*

.. _boundary_comm_tasks:

Boundary Communication Tasks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -426,3 +470,7 @@ cacheing if desired.
- ``LoadAndSendFluxCorrections(std::shared_ptr<MeshData<Real>>&)``
- ``ReceiveFluxCorrections(std::shared_ptr<MeshData<Real>>&)``
- ``SetFluxCorrections(std::shared_ptr<MeshData<Real>>&)``

*Now that non-cell-centered fields are implemented in Parthenon, the
flux correction tasks can be unified with the boundary communication
above.*
61 changes: 61 additions & 0 deletions doc/sphinx/src/mesh/mesh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,64 @@ member.
time-integration advance. The default behavior calls to each package's
(StateDesrcriptor's) ``PreStepDiagnostics`` method which, in turn,
delegates to a ``std::function`` member that defaults to a no-op.

Multi-grid Grids Stored in ``Mesh``
-----------------------------------

If the parameter ``parthenon/mesh/multigrid`` is set to ``true``, the ``Mesh``
constructor and AMR routines populate both
``std::vector<LogicalLocMap_t> Mesh::gmg_grid_locs`` and
``std::vector<BlockList_t> gmg_block_lists``, where each entry into the vectors
describes one level of the of the geometric multi-grid (GMG) mesh. For refined
meshes, each GMG level only includes blocks that are at a given logical level
(starting from the finest logical level on the grid and including both internal
and leaf nodes in the refinement tree) as well as leaf blocks on the next coarser
level that are neighbors to finer blocks, which implies that below the root grid
level the blocks may not cover the entire mesh. For levels above the root grid,
blocks may change shape so that they only cover the domain of the root grid. Note
that leaf blocks may be contained in multiple blocklists, and the lists all point
to the same block (not a separate copy).
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved

*GMG Implementation Note:*
The reason for including two levels in the GMG block lists is for dealing with
accurately setting the boundary values of the fine blocks. Convergence can be poor
or non-exististent if the fine-coarse boundaries of a given level are not
self-consistently updated (since the boundary prolongation from the coarse grid to
the fine grid also depends on interior values of the fine grid that are being updated
by a smoothing operation). This means that each smoothing step, boundary communication
must occur between all blocks corresponding to all internal and leaf nodes at a given
level in the tree and with all leaf nodes at the next coarser level which abut blocks
at the current level. Therefore, the GMG block lists contain blocks at two levels, but
smoothing operations etc. should usually only occur on the subset of those blocks that
are at the fine level.
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved

To work with these GMG levels, ``MeshData`` objects containing these blocks can
be recovered from a ``Mesh`` pointer using

.. code:: c++
auto &md = pmesh->gmg_mesh_data[level].GetOrAdd(level, "base", i);
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved

This ``MeshData`` will include blocks at the current level and possibly some
blocks at the next coarser level. Often, one will only want to operate on blocks
on the finer level (the coarser blocks are required mainly for boundary
communication). To make packs containing only a subset of blocks from a
GMG ``MeshData`` pointer ``md``, one would use

.. code:: c++
int nblocks = md->NumBlocks();
std::vector<bool> include_block(nblocks, true);
for (int b = 0; b < nblocks; ++b)
include_block[b] =
(md->grid.logical_level == md->GetBlockData(b)->GetBlockPointer()->loc.level());
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved

auto desc = parthenon::MakePackDescriptor<in, out>(md.get());
auto pack = desc.GetPack(md.get(), include_block);

In addition to creating the ``LogicalLocation`` and block lists for the GMG levels,
``Mesh`` fills neigbor arrays in ``MeshBlock`` for intra- and inter-GMG block list
communication (i.e. boundary communication and internal prolongation/restriction,
respectively). Communication within and between GMG levels can be done by calling
boundary communication routines with the boundary tags ``gmg_same``,
``gmg_restrict_send``, ``gmg_restrict_recv``, ``gmg_prolongate_send``,
``gmg_prolongate_recv`` (see :boundary_communication:`boundary_communication`).

17 changes: 14 additions & 3 deletions doc/sphinx/src/solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
Solvers
=======

Parthenon does not yet provide an exhaustive set of solvers. Currently,
a few basic building blocks are provided and we hope to develop more
capability in the future.
Parthenon does not yet provide an exhaustive set of plug and play solvers.
Nevertheless, the building blocks required for implementing Krylov subspace
methods (i.e. global reductions for vector dot products) like CG, BiCGStab,
and GMRES are available. An example of a Parthenon based implementation of
BiCGStab can be found in ``examples/poisson_gmg``. Additionally, the
infrastructure required for implementing multigrid solvers is also
included in Parthenon. The requisite hierarchy of grids is produced if
``parthenon/mesh/multigrid=true`` is set in the parameter input. An example
of a multi-grid based linear solver in Parthenon is also given in
``examples/poisson_gmg`` (and also an example of using multi-grid as a
preconditioner for BiCGStab). We plan to build wrappers that simplify the
use of these methods in down stream codes in the future. Note that the
example code does not currently rely on the Stencil and SparseMatrixAccessor
code described below.

Stencil
-------
Expand Down
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ add_subdirectory(particles)
add_subdirectory(particle_leapfrog)
add_subdirectory(particle_tracers)
add_subdirectory(poisson)
add_subdirectory(poisson_gmg)
add_subdirectory(sparse_advection)
27 changes: 27 additions & 0 deletions example/poisson_gmg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#=========================================================================================
# (C) (or copyright) 2023. Triad National Security, LLC. All rights reserved.
#
# This program was produced under U.S. Government contract 89233218CNA000001 for Los
# Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
# for the U.S. Department of Energy/National Nuclear Security Administration. All rights
# in the program are reserved by Triad National Security, LLC, and the U.S. Department
# of Energy/National Nuclear Security Administration. The Government is granted for
# itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide
# license in this material to reproduce, prepare derivative works, distribute copies to
# the public, perform publicly and display publicly, and to permit others to do so.
#=========================================================================================

get_property(DRIVER_LIST GLOBAL PROPERTY DRIVERS_USED_IN_TESTS)
if( "poisson-gmg-example" IN_LIST DRIVER_LIST OR NOT PARTHENON_DISABLE_EXAMPLES)
add_executable(
poisson-gmg-example
poisson_driver.cpp
poisson_driver.hpp
poisson_package.cpp
poisson_package.hpp
main.cpp
parthenon_app_inputs.cpp
)
target_link_libraries(poisson-gmg-example PRIVATE Parthenon::parthenon)
lint_target(poisson-gmg-example)
endif()
86 changes: 86 additions & 0 deletions example/poisson_gmg/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//========================================================================================
// (C) (or copyright) 2023. Triad National Security, LLC. All rights reserved.
//
// This program was produced under U.S. Government contract 89233218CNA000001 for Los
// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
// for the U.S. Department of Energy/National Nuclear Security Administration. All rights
// in the program are reserved by Triad National Security, LLC, and the U.S. Department
// of Energy/National Nuclear Security Administration. The Government is granted for
// itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide
// license in this material to reproduce, prepare derivative works, distribute copies to
// the public, perform publicly and display publicly, and to permit others to do so.
//========================================================================================

#include "bvals/boundary_conditions_generic.hpp"
#include "parthenon_manager.hpp"

#include "poisson_driver.hpp"

using namespace parthenon;
using namespace parthenon::BoundaryFunction;
template <CoordinateDirection DIR, BCSide SIDE>
auto GetBoundaryCondition() {
return [](std::shared_ptr<MeshBlockData<Real>> &rc, bool coarse) -> void {
using namespace parthenon;
using namespace parthenon::BoundaryFunction;
GenericBC<DIR, SIDE, BCType::FixedFace, variable_names::any>(rc, coarse, 0.0);
};
}
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved

int main(int argc, char *argv[]) {
using parthenon::ParthenonManager;
using parthenon::ParthenonStatus;
ParthenonManager pman;

// Redefine parthenon defaults
pman.app_input->ProcessPackages = poisson_example::ProcessPackages;
pman.app_input->MeshProblemGenerator = poisson_example::ProblemGenerator;

// call ParthenonInit to initialize MPI and Kokkos, parse the input deck, and set up
auto manager_status = pman.ParthenonInitEnv(argc, argv);
if (manager_status == ParthenonStatus::complete) {
pman.ParthenonFinalize();
return 0;
}
if (manager_status == ParthenonStatus::error) {
pman.ParthenonFinalize();
return 1;
}
// Now that ParthenonInit has been called and setup succeeded, the code can now
// make use of MPI and Kokkos

// Set boundary conditions
pman.app_input->boundary_conditions[parthenon::BoundaryFace::inner_x1] =
pdmullen marked this conversation as resolved.
Show resolved Hide resolved
GetBoundaryCondition<X1DIR, BCSide::Inner>();
pman.app_input->boundary_conditions[parthenon::BoundaryFace::inner_x2] =
GetBoundaryCondition<X2DIR, BCSide::Inner>();
pman.app_input->boundary_conditions[parthenon::BoundaryFace::inner_x3] =
GetBoundaryCondition<X3DIR, BCSide::Inner>();
pman.app_input->boundary_conditions[parthenon::BoundaryFace::outer_x1] =
GetBoundaryCondition<X1DIR, BCSide::Outer>();
pman.app_input->boundary_conditions[parthenon::BoundaryFace::outer_x2] =
GetBoundaryCondition<X2DIR, BCSide::Outer>();
pman.app_input->boundary_conditions[parthenon::BoundaryFace::outer_x3] =
GetBoundaryCondition<X3DIR, BCSide::Outer>();
pman.ParthenonInitPackagesAndMesh();

// This needs to be scoped so that the driver object is destructed before Finalize
bool success = true;
{
// Initialize the driver
poisson_example::PoissonDriver driver(pman.pinput.get(), pman.app_input.get(),
pman.pmesh.get());

// This line actually runs the simulation
auto driver_status = driver.Execute();
if (driver_status != parthenon::DriverStatus::complete ||
driver.final_rms_residual > 1.e-10 || driver.final_rms_error > 1.e-12)
success = false;
}
// call MPI_Finalize and Kokkos::finalize if necessary
pman.ParthenonFinalize();
printf("success: %i\n", success);

// MPI and Kokkos can no longer be used
return static_cast<int>(!success);
}
Loading