|
| 1 | +//======================================================================================== |
| 2 | +// (C) (or copyright) 2021. Triad National Security, LLC. All rights reserved. |
| 3 | +// |
| 4 | +// This program was produced under U.S. Government contract 89233218CNA000001 for Los |
| 5 | +// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC |
| 6 | +// for the U.S. Department of Energy/National Nuclear Security Administration. All rights |
| 7 | +// in the program are reserved by Triad National Security, LLC, and the U.S. Department |
| 8 | +// of Energy/National Nuclear Security Administration. The Government is granted for |
| 9 | +// itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide |
| 10 | +// license in this material to reproduce, prepare derivative works, distribute copies to |
| 11 | +// the public, perform publicly and display publicly, and to permit others to do so. |
| 12 | +//======================================================================================== |
| 13 | + |
| 14 | +#include <memory> |
| 15 | +#include <string> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +// Local Includes |
| 19 | +#include "bvals/cc/bvals_cc_in_one.hpp" |
| 20 | +#include "interface/metadata.hpp" |
| 21 | +#include "interface/update.hpp" |
| 22 | +#include "mesh/meshblock_pack.hpp" |
| 23 | +#include "mesh/refinement_cc_in_one.hpp" |
| 24 | +#include "parthenon/driver.hpp" |
| 25 | +#include "poisson_driver.hpp" |
| 26 | +#include "poisson_package.hpp" |
| 27 | +#include "refinement/refinement.hpp" |
| 28 | + |
| 29 | +using namespace parthenon::driver::prelude; |
| 30 | + |
| 31 | +namespace poisson_example { |
| 32 | + |
| 33 | +parthenon::DriverStatus PoissonDriver::Execute() { |
| 34 | + pouts->MakeOutputs(pmesh, pinput); |
| 35 | + ConstructAndExecuteTaskLists<>(this); |
| 36 | + pouts->MakeOutputs(pmesh, pinput); |
| 37 | + return DriverStatus::complete; |
| 38 | +} |
| 39 | + |
| 40 | +TaskCollection PoissonDriver::MakeTaskCollection(BlockList_t &blocks) { |
| 41 | + using namespace parthenon::Update; |
| 42 | + TaskCollection tc; |
| 43 | + TaskID none(0); |
| 44 | + |
| 45 | + for (int i = 0; i < blocks.size(); i++) { |
| 46 | + auto &pmb = blocks[i]; |
| 47 | + auto &base = pmb->meshblock_data.Get(); |
| 48 | + pmb->meshblock_data.Add("delta", base); |
| 49 | + } |
| 50 | + |
| 51 | + int max_iters = pmesh->packages.Get("poisson_package")->Param<int>("max_iterations"); |
| 52 | + int check_interval = |
| 53 | + pmesh->packages.Get("poisson_package")->Param<int>("check_interval"); |
| 54 | + bool fail_flag = |
| 55 | + pmesh->packages.Get("poisson_package")->Param<bool>("fail_without_convergence"); |
| 56 | + bool warn_flag = |
| 57 | + pmesh->packages.Get("poisson_package")->Param<bool>("warn_without_convergence"); |
| 58 | + |
| 59 | + const int num_partitions = pmesh->DefaultNumPartitions(); |
| 60 | + TaskRegion &solver_region = tc.AddRegion(num_partitions); |
| 61 | + |
| 62 | + for (int i = 0; i < num_partitions; i++) { |
| 63 | + // make/get a mesh_data container for the state |
| 64 | + auto &md = pmesh->mesh_data.GetOrAdd("base", i); |
| 65 | + auto &mdelta = pmesh->mesh_data.GetOrAdd("delta", i); |
| 66 | + |
| 67 | + TaskList &tl = solver_region[i]; |
| 68 | + |
| 69 | + auto &solver = tl.AddIteration("poisson solver"); |
| 70 | + solver.SetMaxIterations(max_iters); |
| 71 | + solver.SetCheckInterval(check_interval); |
| 72 | + solver.SetFailWithMaxIterations(fail_flag); |
| 73 | + solver.SetWarnWithMaxIterations(warn_flag); |
| 74 | + auto start_recv = solver.AddTask(none, &MeshData<Real>::StartReceiving, md.get(), |
| 75 | + BoundaryCommSubset::all); |
| 76 | + |
| 77 | + auto update = solver.AddTask(none, poisson_package::UpdatePhi<MeshData<Real>>, |
| 78 | + md.get(), mdelta.get()); |
| 79 | + |
| 80 | + auto send = |
| 81 | + solver.AddTask(update, parthenon::cell_centered_bvars::SendBoundaryBuffers, md); |
| 82 | + |
| 83 | + auto recv = solver.AddTask( |
| 84 | + start_recv, parthenon::cell_centered_bvars::ReceiveBoundaryBuffers, md); |
| 85 | + |
| 86 | + auto setb = |
| 87 | + solver.AddTask(recv | update, parthenon::cell_centered_bvars::SetBoundaries, md); |
| 88 | + |
| 89 | + auto clear = solver.AddTask(send | setb, &MeshData<Real>::ClearBoundary, md.get(), |
| 90 | + BoundaryCommSubset::all); |
| 91 | + |
| 92 | + auto check = solver.SetCompletionTask( |
| 93 | + clear, poisson_package::CheckConvergence<MeshData<Real>>, md.get(), mdelta.get()); |
| 94 | + // mark task so that dependent tasks (below) won't execute |
| 95 | + // until all task lists have completed it |
| 96 | + solver_region.AddRegionalDependencies(0, i, check); |
| 97 | + |
| 98 | + auto print = tl.AddTask(check, poisson_package::PrintComplete); |
| 99 | + } |
| 100 | + |
| 101 | + return tc; |
| 102 | +} |
| 103 | + |
| 104 | +} // namespace poisson_example |
0 commit comments