AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Communication.inc.hpp
1 #pragma once
2 
3 #include <amdis/Initfile.hpp>
4 #include <amdis/Output.hpp>
5 
6 namespace AMDiS {
7 
8 #if HAVE_MPI
9 
10 template <class G, class L>
11  template <class Basis>
12 ISTLCommunication<G,L> CommunicationCreator<ISTLCommunication<G,L>>
13  ::create(Basis const& basis, std::string const& prefix)
14 {
15  using SolverType = Dune::SolverCategory::Category;
16  std::string category = "";
17  Parameters::get(prefix + "->category", category);
18  if (category == "")
19  {
20  // check global parameter if no local one was found
21  category = "default";
22  Parameters::get("solver category", category);
23  }
24  SolverType cat = SolverType::sequential;
25  auto const& gv = basis.gridView();
26  int mpiSize = gv.comm().size();
27 
28  if (category == "default")
29  {
30  if (mpiSize == 1)
31  {
32  cat = SolverType::sequential;
33  }
34  else
35  {
36  // Use overlapping solver if grid has overlap
37  if (gv.overlapSize(0) > 0)
38  cat = SolverType::overlapping;
39  else
40  {
41  // TODO(FM): Remove once nonoverlapping solvers are supported
42  warning("Nonoverlapping solvers are currently not supported.");
43  cat = SolverType::nonoverlapping;
44  }
45  }
46  }
47  else if (category != "sequential" && mpiSize == 1)
48  {
49  warning("Only one process detected. Solver category set to sequential\n");
50  cat = SolverType::sequential;
51  }
52  else if (category == "sequential")
53  {
54  test_exit(mpiSize == 1, "Solver category sequential is not supported in parallel\n");
55  cat = SolverType::sequential;
56  }
57  else if (category == "overlapping")
58  {
59  if (gv.overlapSize(0) == 0)
60  warning("Overlapping solver category chosen for grid with no overlap\n");
61  cat = SolverType::overlapping;
62  }
63  else if (category == "nonoverlapping")
64  {
65  // TODO(FM): Remove once nonoverlapping solvers are supported
66  warning("Nonoverlapping solvers are currently not supported.");
67  cat = SolverType::nonoverlapping;
68  }
69  else
70  {
71  error_exit("Unknown solver category\n");
72  }
73 
74  return {basis, cat};
75 }
76 
77 #else // HAVE_MPI
78 
79 template <class G, class L>
80  template <class Basis>
81 ISTLCommunication<G,L> CommunicationCreator<ISTLCommunication<G,L>>
82  ::create(Basis const& /*basis*/, std::string const& /*prefix*/)
83 {
84  return {};
85 }
86 
87 #endif // HAVE_MPI
88 
89 } // end namespace AMDiS
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
auto cat(Dune::TypeTree::HybridTreePath< S... > const &tp0, Dune::TypeTree::HybridTreePath< T... > const &tp1)
Concatenate two treepaths.
Definition: TreePath.hpp:209
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void test_exit(bool condition, std::string const &str, Args &&... args)
test for condition and in case of failure print message and exit
Definition: Output.hpp:163