Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
de09f57
supposedly make dot products work for non-cell centered fields
lroberts36 Mar 31, 2025
31a1c71
actually change things in dot product local
lroberts36 Mar 31, 2025
16b0dea
correctly mask the physical boundary of the domain
lroberts36 Mar 31, 2025
6a17d56
fix indexing bug
lroberts36 Apr 1, 2025
90d8d67
mostly working nodal poisson
lroberts36 Apr 1, 2025
6db71ca
format
lroberts36 Apr 1, 2025
11d5c50
lint and some small comments
lroberts36 Apr 2, 2025
987fdc8
remove unused script
lroberts36 Apr 2, 2025
41a8066
fix cacheing for packs and add selector
lroberts36 Apr 3, 2025
22f6e5a
create folder for pack source code
lroberts36 Apr 3, 2025
a4a62a0
Change guard names
lroberts36 Apr 3, 2025
e09d155
not sure why those stuck around
lroberts36 Apr 3, 2025
1cac045
move block selector to its own file
lroberts36 Apr 3, 2025
58009e9
required include
lroberts36 Apr 3, 2025
ea9ec92
format
lroberts36 Apr 3, 2025
b76d522
Add test
lroberts36 Apr 3, 2025
17752f5
format
lroberts36 Apr 3, 2025
039df05
revert poisson_gmg changes
lroberts36 Apr 3, 2025
a0229ce
Move messy implementation bits
lroberts36 Apr 3, 2025
4d33d28
make things a little more unified
lroberts36 Apr 3, 2025
93b040d
changelog
lroberts36 Apr 3, 2025
f1468b8
add to breaking changes
lroberts36 Apr 3, 2025
81eedce
Start on some documentation
lroberts36 Apr 7, 2025
1a6cbcc
split up files and remove unecessary dependencies
lroberts36 Apr 7, 2025
7505b36
format and lint
lroberts36 Apr 7, 2025
ce95797
explicitly add pack_descriptor.hpp to exports
lroberts36 Apr 7, 2025
e3d5957
remove unused includes
lroberts36 Apr 7, 2025
9e885e2
remove some more unecessary dependencies
lroberts36 Apr 7, 2025
88f4ad8
further reduce dependencies
lroberts36 Apr 7, 2025
02ccb65
Update src/mesh/meshblock.hpp
lroberts36 Apr 7, 2025
c056351
expand docs
lroberts36 Apr 7, 2025
04c3db5
changelog
lroberts36 Apr 7, 2025
887b225
hacked in cacheing
lroberts36 Apr 8, 2025
273cae3
more doc
lroberts36 Apr 8, 2025
9dbed00
small
lroberts36 Apr 8, 2025
881ddf1
fix warning
lroberts36 Apr 8, 2025
e164448
cache pack descriptors and make calls work for every type
lroberts36 Apr 8, 2025
3c5cc35
fix bug and remove dependencies
lroberts36 Apr 8, 2025
548c970
changelog
lroberts36 Apr 8, 2025
a7dde97
Update docs
lroberts36 Apr 8, 2025
d324bc2
include link to swarm packs
lroberts36 Apr 9, 2025
dcdc87e
clean up hash stuff, use c++17 features where possible, add some more…
lroberts36 Apr 9, 2025
db15f37
remove unecessary tuple_hashs
lroberts36 Apr 9, 2025
4af0d35
Add MetadataFlag hash
lroberts36 Apr 9, 2025
c9d224e
switch to non-string cacheing
lroberts36 Apr 9, 2025
29dd345
Make sure we cache everywhere
lroberts36 Apr 9, 2025
5154cca
fix docs?
lroberts36 Apr 9, 2025
369611e
doc fixes
lroberts36 Apr 9, 2025
e4891c0
remove hacked in boundary cacheing
lroberts36 Apr 9, 2025
7c9409f
fix bug
lroberts36 Apr 9, 2025
1f8610b
small
lroberts36 Apr 9, 2025
0cb113f
switch to a slightly different model
lroberts36 Apr 10, 2025
8d57137
small
lroberts36 Apr 10, 2025
8e3eff8
expose templated class
lroberts36 Apr 10, 2025
3d59015
move to state descriptor
lroberts36 Apr 10, 2025
8c9c71e
fix names
lroberts36 Apr 10, 2025
7c7f0c2
supposedly make dot products work for non-cell centered fields
lroberts36 Mar 31, 2025
1bc0b07
lint and some small comments
lroberts36 Apr 2, 2025
545036f
remove unused
lroberts36 Apr 2, 2025
65238f4
add another package
lroberts36 Apr 10, 2025
6ef6993
move stuff around
lroberts36 Apr 10, 2025
518a715
update guards
lroberts36 Apr 10, 2025
35374bf
Add cell centered poisson
lroberts36 Apr 10, 2025
765cf0d
update param input
lroberts36 Apr 10, 2025
c852670
more changes
lroberts36 Apr 10, 2025
c626f93
Move shit around, do some stuff
lroberts36 Apr 14, 2025
0593302
Merge branch 'lroberts36/cache-pack-descriptors' into lroberts36/solv…
lroberts36 Apr 14, 2025
12a297a
Add access to matrix multiplication
lroberts36 Apr 14, 2025
8fe984a
use matrix multiplication
lroberts36 Apr 14, 2025
627ffbc
remove unused macro
lroberts36 Apr 14, 2025
23ee7da
more cleanup, get solvers to work together
lroberts36 Apr 14, 2025
3950c73
add non-template overloads for coordinates
lroberts36 Apr 14, 2025
ef432fd
cell centered working
lroberts36 Apr 14, 2025
15cfead
closer...
lroberts36 Apr 15, 2025
1a5842e
Make most utilities work for arbitrary field types
lroberts36 Apr 15, 2025
805570f
try some other stuff
lroberts36 Apr 15, 2025
f51fab3
Merge branch 'lroberts36/cache-pack-descriptors' into lroberts36/solv…
lroberts36 Apr 15, 2025
ef9e11f
fix linting issue
lroberts36 Apr 15, 2025
cda2908
DRY
lroberts36 Apr 15, 2025
f1a812b
one more place
lroberts36 Apr 15, 2025
6aec108
Generalize looping over TEs and vars, fix possible dot product bug
lroberts36 Apr 16, 2025
6d37901
Fix jacobi to work with any set of topological types
lroberts36 Apr 16, 2025
fbe9026
messing around
lroberts36 Apr 16, 2025
22a4213
Make boundary indexing of non-cell centered types easier and introduc…
lroberts36 Apr 17, 2025
ccbe136
missing piece...
lroberts36 Apr 17, 2025
0ed3175
thread stuff through solvers
lroberts36 Apr 17, 2025
df81993
small fixes
lroberts36 Apr 17, 2025
d98772f
switch to an inner loop pattern that exists everywhere
lroberts36 Apr 17, 2025
25ba534
small
lroberts36 Apr 17, 2025
dd9b196
Merge branch 'develop' into lroberts36/solver-noncell-vars
lroberts36 Jul 7, 2025
5246ac7
Merge branch 'develop' into lroberts36/solver-noncell-vars
lroberts36 Jul 30, 2025
e03b62e
update tridiag solver
lroberts36 Jul 30, 2025
013a129
fix bugs
lroberts36 Aug 2, 2025
9517d4f
fix more bugs
lroberts36 Aug 2, 2025
dd8e7b5
Merge branch 'develop' into lroberts36/solver-noncell-vars
lroberts36 Sep 3, 2025
bfd1db3
name change
lroberts36 Sep 3, 2025
204bcc0
Allow for user overridable BCs
lroberts36 Sep 3, 2025
a76b1b6
changelog
lroberts36 Sep 3, 2025
d188e59
actually execute the task list...
lroberts36 Sep 3, 2025
5859c7e
format and lint
lroberts36 Sep 3, 2025
fc28887
Merge branch 'lroberts36/add-user-boundary-override' into lroberts36/…
lroberts36 Sep 4, 2025
b6f5319
Merge branch 'lroberts36/add-user-specifiable-BCs-to-solvers' into lr…
lroberts36 Sep 4, 2025
3ce0e47
remove unused code
lroberts36 Sep 4, 2025
e7e8d61
remove duplication
lroberts36 Sep 4, 2025
fb0ad78
tiny
lroberts36 Sep 4, 2025
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 example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ add_subdirectory(particle_leapfrog)
add_subdirectory(particle_tracers)
add_subdirectory(poisson)
add_subdirectory(poisson_gmg)
add_subdirectory(linear_solvers)
add_subdirectory(diffusion)
add_subdirectory(sparse_advection)
36 changes: 36 additions & 0 deletions example/linear_solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#=========================================================================================
# (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( "linear-solvers-example" IN_LIST DRIVER_LIST OR NOT PARTHENON_DISABLE_EXAMPLES)
add_executable(
linear-solvers-example
linear_solver_driver.cpp
linear_solver_driver.hpp
poisson_cell_equation.hpp
poisson_cell_package.cpp
poisson_cell_package.hpp
poisson_nodal_equation.hpp
poisson_nodal_package.cpp
poisson_nodal_package.hpp
helmholtz_equation.cpp
helmholtz_equation.hpp
helmholtz_package.cpp
helmholtz_package.hpp
main.cpp
parthenon_app_inputs.cpp
variable_type.hpp
)
target_link_libraries(linear-solvers-example PRIVATE Parthenon::parthenon)
lint_target(linear-solvers-example)
endif()
169 changes: 169 additions & 0 deletions example/linear_solvers/helmholtz_equation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
//========================================================================================
// (C) (or copyright) 2023-2024. 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 <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include <kokkos_abstraction.hpp>
#include <parthenon/package.hpp>

#include "helmholtz_equation.hpp"

namespace helmholtz_package {
using namespace parthenon::package::prelude;

parthenon::TaskStatus
HelmholtzEquation::AxImpl(std::shared_ptr<parthenon::MeshData<Real>> &md_in,
std::shared_ptr<parthenon::MeshData<Real>> &md_out) {
using namespace parthenon;
using TE = TopologicalElement;
auto pkg = md_in->GetMeshPointer()->packages.Get("helmholtz_package");
const auto alpha = pkg->Param<Real>("diagonal_alpha");

const int ndim = md_in->GetMeshPointer()->ndim;
IndexRange ib = md_in->GetBoundsI(IndexDomain::interior);
IndexRange jb = md_in->GetBoundsJ(IndexDomain::interior);
IndexRange kb = md_in->GetBoundsK(IndexDomain::interior);

auto desc = parthenon::MakePackDescriptorFromTypeList<IndependentVars>(md_in.get());
auto pack_in = desc.GetPack(md_in.get());
auto pack_out = desc.GetPack(md_out.get());

const int ioff = ndim > 0;
const int joff = ndim > 1;
const int koff = ndim > 2;
parthenon::par_for(
"HelmholtzEquation::Ax", 0, pack_in.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
const auto &coords = pack_in.GetCoordinates(b);
const Real dx1 = coords.template Dxc<X1DIR>(k, j, i);
const Real dx2 = coords.template Dxc<X2DIR>(k, j, i);
const Real dx3 = coords.template Dxc<X3DIR>(k, j, i);

Real Ax = -alpha * pack_in(b, TE::CC, vcc_t(), k, j, i);
Ax -= (pack_in(b, TE::F1, vfc_t(), k, j, i + ioff) -
pack_in(b, TE::F1, vfc_t(), k, j, i)) /
dx1;
Ax -= (pack_in(b, TE::F2, vfc_t(), k, j + joff, i) -
pack_in(b, TE::F2, vfc_t(), k, j, i)) /
dx2;
Ax -= (pack_in(b, TE::F3, vfc_t(), k + koff, j, i) -
pack_in(b, TE::F3, vfc_t(), k, j, i)) /
dx3;

pack_out(b, TE::CC, vcc_t(), k, j, i) = Ax;
});
std::vector<TE> tes{TE::F1};
if (ndim > 1) tes.push_back(TE::F2);
if (ndim > 2) tes.push_back(TE::F3);
for (auto &&te : tes) {
IndexRange ib = md_in->GetBoundsI(IndexDomain::interior, te);
IndexRange jb = md_in->GetBoundsJ(IndexDomain::interior, te);
IndexRange kb = md_in->GetBoundsK(IndexDomain::interior, te);
const int ioff = TopologicalOffsetI(te) * (ndim > 0);
const int joff = TopologicalOffsetJ(te) * (ndim > 1);
const int koff = TopologicalOffsetK(te) * (ndim > 2);
parthenon::par_for(
"HelmholtzEquation::Ax", 0, pack_in.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e,
ib.s, ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
const auto &coords = pack_in.GetCoordinates(b);
const Real dx1 = coords.template Dxc<X1DIR>(k, j, i);
const Real dx2 = coords.template Dxc<X2DIR>(k, j, i);
const Real dx3 = coords.template Dxc<X3DIR>(k, j, i);

Real Ax = alpha * pack_in(b, te, vfc_t(), k, j, i);
Ax += (pack_in(b, TE::CC, vcc_t(), k, j, i) -
pack_in(b, TE::CC, vcc_t(), k - koff, j - joff, i - ioff)) /
dx1;
pack_out(b, te, vfc_t(), k, j, i) = Ax;
});
}
return TaskStatus::complete;
}

parthenon::TaskStatus
HelmholtzEquation::SetBoundary(std::shared_ptr<parthenon::MeshData<Real>> &md,
bool coarse) {
using namespace parthenon;

using TE = TopologicalElement;
const int ndim = md->GetMeshPointer()->ndim;

CellLevel cl = coarse ? CellLevel::coarse : CellLevel::same;

std::set<PDOpt> opts{};
if (coarse) opts.emplace(PDOpt::Coarse);
auto desc = parthenon::MakePackDescriptor<vfc_t>(md.get(), {}, opts);
auto pack = desc.GetPack(md.get(), GetBlockSelector::OnPhysicalBoundary());

std::vector<TE> tes{TE::F1};
if (ndim > 1) tes.push_back(TE::F2);
if (ndim > 2) tes.push_back(TE::F3);
for (auto &&te : tes) {
IndexRange ib = md->GetBoundsI(cl, IndexDomain::interior, te);
IndexRange jb = md->GetBoundsJ(cl, IndexDomain::interior, te);
IndexRange kb = md->GetBoundsK(cl, IndexDomain::interior, te);

parthenon::par_for(
"PoissonNodal::SetBoundary", 0, pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e,
ib.s, ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
const int oi = TopologicalOffsetI(te) * ((ib.e == i) - (ib.s == i));
const int oj = TopologicalOffsetJ(te) * ((jb.e == j) - (jb.s == j));
const int ok = TopologicalOffsetK(te) * ((kb.e == k) - (kb.s == k));
if (pack.IsPhysicalBoundary(b, ok, oj, oi)) pack(b, te, vfc_t(), k, j, i) = 0.0;
});
}
return TaskStatus::complete;
}

parthenon::TaskStatus
HelmholtzEquation::SetDiagonal(std::shared_ptr<parthenon::MeshData<Real>> & /*md_mat*/,
std::shared_ptr<parthenon::MeshData<Real>> &md_diag) {
using namespace parthenon;
using TE = TopologicalElement;
auto pkg = md_diag->GetMeshPointer()->packages.Get("helmholtz_package");
const auto alpha = pkg->Param<Real>("diagonal_alpha");

const int ndim = md_diag->GetMeshPointer()->ndim;
IndexRange ib = md_diag->GetBoundsI(IndexDomain::interior);
IndexRange jb = md_diag->GetBoundsJ(IndexDomain::interior);
IndexRange kb = md_diag->GetBoundsK(IndexDomain::interior);

auto desc = parthenon::MakePackDescriptorFromTypeList<IndependentVars>(md_diag.get());
auto pack_diag = desc.GetPack(md_diag.get());

parthenon::par_for(
"HelmholtzEquation::Ax", 0, pack_diag.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e,
ib.s, ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
pack_diag(b, TE::CC, vcc_t(), k, j, i) = -alpha;
});

std::vector<TE> tes{TE::F1};
if (ndim > 1) tes.push_back(TE::F2);
if (ndim > 2) tes.push_back(TE::F3);
for (auto &&te : tes) {
IndexRange ib = md_diag->GetBoundsI(IndexDomain::interior, te);
IndexRange jb = md_diag->GetBoundsJ(IndexDomain::interior, te);
IndexRange kb = md_diag->GetBoundsK(IndexDomain::interior, te);
parthenon::par_for(
"HelmholtzEquation::Ax", 0, pack_diag.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e,
ib.s, ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
pack_diag(b, te, vfc_t(), k, j, i) = alpha;
});
}
return TaskStatus::complete;
}

} // namespace helmholtz_package
65 changes: 65 additions & 0 deletions example/linear_solvers/helmholtz_equation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//========================================================================================
// (C) (or copyright) 2023-2024. 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.
//========================================================================================
#ifndef EXAMPLE_LINEAR_SOLVERS_HELMHOLTZ_EQUATION_HPP_
#define EXAMPLE_LINEAR_SOLVERS_HELMHOLTZ_EQUATION_HPP_

#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include <kokkos_abstraction.hpp>
#include <parthenon/package.hpp>

#include "helmholtz_package.hpp"

namespace helmholtz_package {
using namespace parthenon::package::prelude;

// This class implement methods for calculating A.x = y and returning the diagonal of A,
// where A is the the matrix representing the discretized Poisson equation on the grid.
// Here we implement the Laplace operator in terms of a flux divergence to (potentially)
// consistently deal with coarse fine boundaries on the grid. Only the routines Ax and
// SetDiagonal need to be defined for interfacing this with solvers. The other methods
// are internal, but can't be marked private or protected because they launch kernels
// on device.
class HelmholtzEquation {
public:
using vcc_t = u;
using vfc_t = F;
using IndependentVars = parthenon::TypeList<vcc_t, vfc_t>;

HelmholtzEquation(parthenon::ParameterInput *pin, const std::string &label) {}

parthenon::TaskID Ax(parthenon::TaskList &tl, parthenon::TaskID depends_on,
std::shared_ptr<parthenon::MeshData<Real>> & /*md_mat*/,
std::shared_ptr<parthenon::MeshData<Real>> &md_in,
std::shared_ptr<parthenon::MeshData<Real>> &md_out) {
return tl.AddTask(depends_on, AxImpl, md_in, md_out);
}

static parthenon::TaskStatus AxImpl(std::shared_ptr<parthenon::MeshData<Real>> &md_in,
std::shared_ptr<parthenon::MeshData<Real>> &md_out);

static parthenon::TaskStatus SetBoundary(std::shared_ptr<parthenon::MeshData<Real>> &md,
bool coarse);

parthenon::TaskStatus
SetDiagonal(std::shared_ptr<parthenon::MeshData<Real>> & /*md_mat*/,
std::shared_ptr<parthenon::MeshData<Real>> &md_diag);
};

} // namespace helmholtz_package

#endif // EXAMPLE_LINEAR_SOLVERS_HELMHOLTZ_EQUATION_HPP_
Loading
Loading