Skip to content

Commit 4789e0e

Browse files
committed
finish cleanup
1 parent 37500d2 commit 4789e0e

10 files changed

+68
-72
lines changed

example/poisson_gmg/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if( "poisson-gmg-example" IN_LIST DRIVER_LIST OR NOT PARTHENON_DISABLE_EXAMPLES)
1717
poisson-gmg-example
1818
poisson_driver.cpp
1919
poisson_driver.hpp
20-
poisson_equation_stages.hpp
20+
poisson_equation.hpp
2121
poisson_package.cpp
2222
poisson_package.hpp
2323
main.cpp

example/poisson_gmg/poisson_driver.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include "mesh/meshblock_pack.hpp"
2626
#include "parthenon/driver.hpp"
2727
#include "poisson_driver.hpp"
28-
#include "poisson_equation_stages.hpp"
28+
#include "poisson_equation.hpp"
2929
#include "poisson_package.hpp"
3030
#include "prolong_restrict/prolong_restrict.hpp"
31-
#include "solvers/bicgstab_solver_stages.hpp"
32-
#include "solvers/cg_solver_stages.hpp"
33-
#include "solvers/mg_solver_stages.hpp"
31+
#include "solvers/bicgstab_solver.hpp"
32+
#include "solvers/cg_solver.hpp"
33+
#include "solvers/mg_solver.hpp"
3434
#include "solvers/solver_utils.hpp"
3535

3636
using namespace parthenon::driver::prelude;
@@ -76,17 +76,18 @@ TaskCollection PoissonDriver::MakeTaskCollection(BlockList_t &blocks) {
7676

7777
// Move the rhs variable into the rhs stage for stage based solver
7878
auto copy_rhs = tl.AddTask(none, TF(solvers::utils::CopyData<rhs, u>), md);
79-
copy_rhs = tl.AddTask(
80-
copy_rhs, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md, md_rhs);
81-
79+
copy_rhs = tl.AddTask(copy_rhs, TF(solvers::utils::CopyData<parthenon::TypeList<u>>),
80+
md, md_rhs);
81+
8282
// Possibly set rhs <- A.u_exact for a given u_exact so that the exact solution is
8383
// known when we solve A.u = rhs
8484
if (use_exact_rhs) {
8585
auto copy_exact = tl.AddTask(copy_rhs, TF(solvers::utils::CopyData<exact, u>), md);
8686
copy_exact = tl.AddTask(
87-
copy_rhs, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md, md_u);
87+
copy_rhs, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md, md_u);
8888
auto comm = AddBoundaryExchangeTasks<BoundaryType::any>(copy_exact, tl, md_u, true);
89-
auto *eqs = pkg->MutableParam<poisson_package::PoissonEquation<u, D>>("poisson_equation");
89+
auto *eqs =
90+
pkg->MutableParam<poisson_package::PoissonEquation<u, D>>("poisson_equation");
9091
copy_rhs = eqs->Ax(tl, comm, md, md_u, md_rhs);
9192
}
9293

@@ -100,9 +101,9 @@ TaskCollection PoissonDriver::MakeTaskCollection(BlockList_t &blocks) {
100101
// solution to the exact solution
101102
if (use_exact_rhs) {
102103
auto copy_back = tl.AddTask(
103-
solve, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md_u, md);
104-
auto diff = tl.AddTask(copy_back, TF(solvers::utils::AddFieldsAndStore<exact, u, u>),
105-
md, 1.0, -1.0);
104+
solve, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md_u, md);
105+
auto diff = tl.AddTask(
106+
copy_back, TF(solvers::utils::AddFieldsAndStore<exact, u, u>), md, 1.0, -1.0);
106107
auto get_err = solvers::utils::DotProduct<u, u>(diff, tl, &err, md);
107108
tl.AddTask(
108109
get_err,

example/poisson_gmg/poisson_equation_stages.hpp renamed to example/poisson_gmg/poisson_equation.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// license in this material to reproduce, prepare derivative works, distribute copies to
1111
// the public, perform publicly and display publicly, and to permit others to do so.
1212
//========================================================================================
13-
#ifndef EXAMPLE_POISSON_GMG_POISSON_EQUATION_STAGES_HPP_
14-
#define EXAMPLE_POISSON_GMG_POISSON_EQUATION_STAGES_HPP_
13+
#ifndef EXAMPLE_POISSON_GMG_POISSON_EQUATION_HPP_
14+
#define EXAMPLE_POISSON_GMG_POISSON_EQUATION_HPP_
1515

1616
#include <memory>
1717
#include <set>
@@ -315,4 +315,4 @@ class PoissonEquation {
315315

316316
} // namespace poisson_package
317317

318-
#endif // EXAMPLE_POISSON_GMG_POISSON_EQUATION_STAGES_HPP_
318+
#endif // EXAMPLE_POISSON_GMG_POISSON_EQUATION_HPP_

example/poisson_gmg/poisson_package.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
#include <coordinates/coordinates.hpp>
2424
#include <parthenon/driver.hpp>
2525
#include <parthenon/package.hpp>
26-
#include <solvers/bicgstab_solver_stages.hpp>
27-
#include <solvers/cg_solver_stages.hpp>
26+
#include <solvers/bicgstab_solver.hpp>
27+
#include <solvers/cg_solver.hpp>
2828
#include <solvers/solver_utils.hpp>
2929

3030
#include "defs.hpp"
3131
#include "kokkos_abstraction.hpp"
32-
#include "poisson_equation_stages.hpp"
32+
#include "poisson_equation.hpp"
3333
#include "poisson_package.hpp"
3434

3535
using namespace parthenon::package::prelude;
@@ -94,20 +94,17 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
9494

9595
std::shared_ptr<parthenon::solvers::SolverBase> psolver;
9696
using prolongator_t = parthenon::solvers::ProlongationBlockInteriorDefault;
97-
using preconditioner_t =
98-
parthenon::solvers::MGSolver<PoissEq, prolongator_t>;
97+
using preconditioner_t = parthenon::solvers::MGSolver<PoissEq, prolongator_t>;
9998
if (solver == "MG") {
100-
psolver = std::make_shared<
101-
parthenon::solvers::MGSolver<PoissEq, prolongator_t>>(
99+
psolver = std::make_shared<parthenon::solvers::MGSolver<PoissEq, prolongator_t>>(
102100
"base", "u", "rhs", pin, "poisson/solver_params", PoissEq(pin, "poisson"));
103101
} else if (solver == "CG") {
104-
psolver = std::make_shared<
105-
parthenon::solvers::CGSolver<PoissEq, preconditioner_t>>(
102+
psolver = std::make_shared<parthenon::solvers::CGSolver<PoissEq, preconditioner_t>>(
106103
"base", "u", "rhs", pin, "poisson/solver_params", PoissEq(pin, "poisson"));
107104
} else if (solver == "BiCGSTAB") {
108-
psolver = std::make_shared<
109-
parthenon::solvers::BiCGSTABSolver<PoissEq, preconditioner_t>>(
110-
"base", "u", "rhs", pin, "poisson/solver_params", PoissEq(pin, "poisson"));
105+
psolver =
106+
std::make_shared<parthenon::solvers::BiCGSTABSolver<PoissEq, preconditioner_t>>(
107+
"base", "u", "rhs", pin, "poisson/solver_params", PoissEq(pin, "poisson"));
111108
} else {
112109
PARTHENON_FAIL("Unknown solver type.");
113110
}
@@ -122,8 +119,8 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
122119
// for the standard Poisson equation.
123120
pkg->AddField(D::name(), mD);
124121

125-
std::vector<MetadataFlag> flags{Metadata::Cell, Metadata::Independent,
126-
Metadata::FillGhost, Metadata::WithFluxes,
122+
std::vector<MetadataFlag> flags{Metadata::Cell, Metadata::Independent,
123+
Metadata::FillGhost, Metadata::WithFluxes,
127124
Metadata::GMGRestrict, Metadata::GMGProlongate};
128125
auto mflux_comm = Metadata(flags);
129126
if (prolong == "Linear") {

src/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ add_library(parthenon
229229
amr_criteria/refinement_package.cpp
230230
amr_criteria/refinement_package.hpp
231231

232-
solvers/bicgstab_solver_stages.hpp
233-
solvers/cg_solver_stages.hpp
232+
solvers/bicgstab_solver.hpp
233+
solvers/cg_solver.hpp
234234
solvers/internal_prolongation.hpp
235-
solvers/mg_solver_stages.hpp
235+
solvers/mg_solver.hpp
236236
solvers/solver_base.hpp
237237
solvers/solver_utils.hpp
238238

src/solvers/bicgstab_solver_stages.hpp renamed to src/solvers/bicgstab_solver.hpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// license in this material to reproduce, prepare derivative works, distribute copies to
1111
// the public, perform publicly and display publicly, and to permit others to do so.
1212
//========================================================================================
13-
#ifndef SOLVERS_BICGSTAB_SOLVER_STAGES_HPP_
14-
#define SOLVERS_BICGSTAB_SOLVER_STAGES_HPP_
13+
#ifndef SOLVERS_BICGSTAB_SOLVER_HPP_
14+
#define SOLVERS_BICGSTAB_SOLVER_HPP_
1515

1616
#include <cstdio>
1717
#include <memory>
@@ -23,7 +23,7 @@
2323
#include "interface/meshblock_data.hpp"
2424
#include "interface/state_descriptor.hpp"
2525
#include "kokkos_abstraction.hpp"
26-
#include "solvers/mg_solver_stages.hpp"
26+
#include "solvers/mg_solver.hpp"
2727
#include "solvers/solver_base.hpp"
2828
#include "solvers/solver_utils.hpp"
2929
#include "tasks/tasks.hpp"
@@ -87,12 +87,13 @@ class BiCGSTABSolver : public SolverBase {
8787
// Internal containers for solver which create deep copies of sol_fields
8888
std::string container_rhat0, container_v, container_h, container_s;
8989
std::string container_t, container_r, container_p, container_x, container_diag;
90-
90+
9191
static inline std::size_t id{0};
92+
9293
public:
9394
BiCGSTABSolver(const std::string &container_base, const std::string &container_u,
94-
const std::string &container_rhs, ParameterInput *pin,
95-
const std::string &input_block, equations eq_in = equations())
95+
const std::string &container_rhs, ParameterInput *pin,
96+
const std::string &input_block, equations eq_in = equations())
9697
: preconditioner(container_base, container_u, container_rhs, pin, input_block,
9798
eq_in),
9899
container_base(container_base), container_u(container_u),
@@ -174,8 +175,8 @@ class BiCGSTABSolver : public SolverBase {
174175
this);
175176
tl.AddTask(
176177
TaskQualifier::once_per_region, initialize, "print to screen",
177-
[&](BiCGSTABSolver *solver, std::shared_ptr<Real> res_tol,
178-
bool relative_residual, Mesh *pm) {
178+
[&](BiCGSTABSolver *solver, std::shared_ptr<Real> res_tol, bool relative_residual,
179+
Mesh *pm) {
179180
if (Globals::my_rank == 0 && params_.print_per_step) {
180181
Real tol = relative_residual
181182
? *res_tol * std::sqrt(solver->rhs2.val / pm->GetTotalCells())
@@ -372,4 +373,4 @@ class BiCGSTABSolver : public SolverBase {
372373

373374
} // namespace parthenon
374375

375-
#endif // SOLVERS_BICGSTAB_SOLVER_STAGES_HPP_
376+
#endif // SOLVERS_BICGSTAB_SOLVER_HPP_

src/solvers/cg_solver_stages.hpp renamed to src/solvers/cg_solver.hpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// license in this material to reproduce, prepare derivative works, distribute copies to
1111
// the public, perform publicly and display publicly, and to permit others to do so.
1212
//========================================================================================
13-
#ifndef SOLVERS_CG_SOLVER_STAGES_HPP_
14-
#define SOLVERS_CG_SOLVER_STAGES_HPP_
13+
#ifndef SOLVERS_CG_SOLVER_HPP_
14+
#define SOLVERS_CG_SOLVER_HPP_
1515

1616
#include <cstdio>
1717
#include <limits>
@@ -24,7 +24,7 @@
2424
#include "interface/meshblock_data.hpp"
2525
#include "interface/state_descriptor.hpp"
2626
#include "kokkos_abstraction.hpp"
27-
#include "solvers/mg_solver_stages.hpp"
27+
#include "solvers/mg_solver.hpp"
2828
#include "solvers/solver_base.hpp"
2929
#include "solvers/solver_utils.hpp"
3030
#include "tasks/tasks.hpp"
@@ -79,18 +79,19 @@ class CGSolver : public SolverBase {
7979
std::string container_x, container_r, container_v, container_p;
8080

8181
static inline std::size_t id{0};
82+
8283
public:
8384
CGSolver(const std::string &container_base, const std::string &container_u,
84-
const std::string &container_rhs, ParameterInput *pin,
85-
const std::string &input_block, const equations &eq_in = equations())
85+
const std::string &container_rhs, ParameterInput *pin,
86+
const std::string &input_block, const equations &eq_in = equations())
8687
: preconditioner(container_base, container_u, container_rhs, pin, input_block,
8788
eq_in),
8889
container_base(container_base), container_u(container_u),
8990
container_rhs(container_rhs), params_(pin, input_block), iter_counter(0),
9091
eqs_(eq_in) {
9192
FieldTL::IterateTypes(
9293
[this](auto t) { this->sol_fields.push_back(decltype(t)::name()); });
93-
std::string solver_id = "cg" + std::to_string(id++);
94+
std::string solver_id = "cg" + std::to_string(id++);
9495
container_x = solver_id + "_x";
9596
container_r = solver_id + "_r";
9697
container_v = solver_id + "_v";
@@ -146,8 +147,8 @@ class CGSolver : public SolverBase {
146147
if (params_.print_per_step && Globals::my_rank == 0) {
147148
initialize = tl.AddTask(
148149
TaskQualifier::once_per_region, initialize, "print to screen",
149-
[&](CGSolver *solver, std::shared_ptr<Real> res_tol,
150-
bool relative_residual, Mesh *pm) {
150+
[&](CGSolver *solver, std::shared_ptr<Real> res_tol, bool relative_residual,
151+
Mesh *pm) {
151152
Real tol = relative_residual
152153
? *res_tol * std::sqrt(solver->rhs2.val / pm->GetTotalCells())
153154
: *res_tol;
@@ -240,8 +241,8 @@ class CGSolver : public SolverBase {
240241

241242
auto check = itl.AddTask(
242243
TaskQualifier::completion, get_res | correct_x, "completion",
243-
[](CGSolver *solver, Mesh *pmesh, int max_iter,
244-
std::shared_ptr<Real> res_tol, bool relative_residual) {
244+
[](CGSolver *solver, Mesh *pmesh, int max_iter, std::shared_ptr<Real> res_tol,
245+
bool relative_residual) {
245246
Real rms_res = std::sqrt(solver->residual.val / pmesh->GetTotalCells());
246247
solver->final_residual = rms_res;
247248
solver->final_iteration = solver->iter_counter;
@@ -278,4 +279,4 @@ class CGSolver : public SolverBase {
278279
} // namespace solvers
279280
} // namespace parthenon
280281

281-
#endif // SOLVERS_CG_SOLVER_STAGES_HPP_
282+
#endif // SOLVERS_CG_SOLVER_HPP_

src/solvers/mg_solver_stages.hpp renamed to src/solvers/mg_solver.hpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// license in this material to reproduce, prepare derivative works, distribute copies to
1111
// the public, perform publicly and display publicly, and to permit others to do so.
1212
//========================================================================================
13-
#ifndef SOLVERS_MG_SOLVER_STAGES_HPP_
14-
#define SOLVERS_MG_SOLVER_STAGES_HPP_
13+
#ifndef SOLVERS_MG_SOLVER_HPP_
14+
#define SOLVERS_MG_SOLVER_HPP_
1515

1616
#include <algorithm>
1717
#include <cstdio>
@@ -77,6 +77,7 @@ struct MGParams {
7777
template <class equations_t, class prolongator_t = ProlongationBlockInteriorDefault>
7878
class MGSolver : public SolverBase {
7979
static inline std::size_t id{0};
80+
8081
public:
8182
using FieldTL = typename equations_t::IndependentVars;
8283

@@ -95,16 +96,14 @@ class MGSolver : public SolverBase {
9596
std::string container_res_err, container_temp, container_u0, container_diag;
9697

9798
MGSolver(const std::string &container_base, const std::string &container_u,
98-
const std::string &container_rhs, ParameterInput *pin,
99-
const std::string &input_block, equations_t eq_in = equations_t())
100-
: MGSolver(container_base, container_u, container_rhs,
101-
MGParams(pin, input_block), eq_in,
102-
prolongator_t(pin, input_block)) {}
99+
const std::string &container_rhs, ParameterInput *pin,
100+
const std::string &input_block, equations_t eq_in = equations_t())
101+
: MGSolver(container_base, container_u, container_rhs, MGParams(pin, input_block),
102+
eq_in, prolongator_t(pin, input_block)) {}
103103

104104
MGSolver(const std::string &container_base, const std::string &container_u,
105-
const std::string &container_rhs, MGParams params_in,
106-
equations_t eq_in = equations_t(),
107-
prolongator_t prol_in = prolongator_t())
105+
const std::string &container_rhs, MGParams params_in,
106+
equations_t eq_in = equations_t(), prolongator_t prol_in = prolongator_t())
108107
: container_base(container_base), container_u(container_u),
109108
container_rhs(container_rhs), params_(params_in), iter_counter(0), eqs_(eq_in),
110109
prolongator_(prol_in) {
@@ -292,8 +291,8 @@ class MGSolver : public SolverBase {
292291
auto comm =
293292
AddBoundaryExchangeTasks<comm_boundary>(depends_on, tl, md_in, multilevel);
294293
auto mat_mult = eqs_.Ax(tl, comm, md_base, md_in, md_out);
295-
return tl.AddTask(mat_mult, TF(&MGSolver::Jacobi), this, md_rhs, md_out,
296-
md_diag, md_in, md_out, omega);
294+
return tl.AddTask(mat_mult, TF(&MGSolver::Jacobi), this, md_rhs, md_out, md_diag,
295+
md_in, md_out, omega);
297296
}
298297

299298
template <parthenon::BoundaryType comm_boundary, class TL_t>
@@ -530,4 +529,4 @@ class MGSolver : public SolverBase {
530529

531530
} // namespace parthenon
532531

533-
#endif // SOLVERS_MG_SOLVER_STAGES_HPP_
532+
#endif // SOLVERS_MG_SOLVER_HPP_

src/solvers/solver_utils.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ TaskStatus SetToZero(const std::shared_ptr<MeshData<Real>> &md) {
215215
int nblocks = md->NumBlocks();
216216
using TE = parthenon::TopologicalElement;
217217
TE te = TE::CC;
218-
static auto desc = [&]{
218+
static auto desc = [&] {
219219
if constexpr (isTypeList<TL>::value) {
220220
return parthenon::MakePackDescriptorFromTypeList<TL>(md.get());
221221
} else {
@@ -245,7 +245,6 @@ TaskStatus SetToZero(const std::shared_ptr<MeshData<Real>> &md) {
245245
return TaskStatus::complete;
246246
}
247247

248-
249248
template <class a_t, class b_t, class out_t, bool only_fine_on_composite = true>
250249
TaskStatus AddFieldsAndStoreInteriorSelect(const std::shared_ptr<MeshData<Real>> &md,
251250
Real wa = 1.0, Real wb = 1.0,

src/utils/type_list.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ auto GetNames() {
9494
}
9595

9696
template <class>
97-
struct isTypeList : public std::false_type
98-
{ };
97+
struct isTypeList : public std::false_type {};
9998

10099
template <class... Ts>
101-
struct isTypeList<TypeList<Ts...>> : public std::true_type
102-
{ };
100+
struct isTypeList<TypeList<Ts...>> : public std::true_type {};
103101

104102
} // namespace parthenon
105103

0 commit comments

Comments
 (0)