19 #ifndef OPM_MULTICOMM_HEADER_INCLUDED 20 #define OPM_MULTICOMM_HEADER_INCLUDED 22 #include <dune/common/hybridutilities.hh> 26 #include <dune/common/parallel/mpicommunication.hh> 32 #include <type_traits> 40 using size_type = std::size_t;
42 static constexpr size_type size()
47 void project(T& )
const 50 template <
typename T1,
typename T2>
51 void dot(
const T1& x,
const T1& y, T2& result)
const 56 double norm(
const T& x)
const 61 void copyOwnerToAll(
const T& x, T& y)
const 66 auto communicator()
const 68 return Dune::Communication<int>{};
76 using size_type = std::size_t;
79 : colcom_(MPI_COMM_WORLD)
82 static constexpr size_type size()
87 void project(T& )
const 91 template <
typename T1,
typename T2>
92 void dot(
const T1& x,
const T1& y, T2& result)
const 95 result = colcom_.sum(result);
99 double norm(
const T& x)
const 101 double result = x.dot(x);
102 result = colcom_.sum(result);
103 return std::sqrt(result);
106 template <
typename T>
107 void copyOwnerToAll(
const T& x, T& y)
const 113 Communication<MPI_Comm> colcom_;
117 template <
typename... Args>
120 using TupleType = std::tuple<Args...>;
122 using field_type = double;
125 using std::tuple<Args...>::tuple;
126 using size_type = std::size_t;
128 static constexpr size_type size()
130 return sizeof...(Args);
133 template <
size_type index>
134 typename std::tuple_element<index, TupleType>::type&
135 operator[]([[maybe_unused]]
const std::integral_constant<size_type, index> indexVariable)
137 return std::get<index>(*this);
139 template <
size_type index>
140 const typename std::tuple_element<index, TupleType>::type&
141 operator[]([[maybe_unused]]
const std::integral_constant<size_type, index> indexVariable)
const 143 return std::get<index>(*this);
146 template <
typename T>
147 void project(T& x)
const 149 using namespace Dune::Hybrid;
150 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) { (*this)[i].project(x[i]); });
152 template <
typename T1,
typename T2>
153 void dot(
const T1& x,
const T1& y, T2& result)
const 155 result = field_type(0);
156 using namespace Dune::Hybrid;
157 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) {
158 double result_tmp = 0;
159 (*this)[i].dot(x[i], y[i], result_tmp);
160 result += result_tmp;
163 template <
typename T>
164 field_type norm(
const T& x)
const 166 field_type result(0);
167 using namespace Dune::Hybrid;
168 forEach(integralRange(Hybrid::size(*
this)), [&](
auto&& i) {
169 double result_tmp = 0.0;
170 (*this)[i].dot(x[i], x[i], result_tmp);
171 result += result_tmp;
173 return std::sqrt(result);
175 template <
typename T>
176 void copyOwnerToAll(
const T& x, T& y)
const 178 using namespace Dune::Hybrid;
179 forEach(integralRange(Hybrid::size(*
this)),
180 [&](
auto&& i) { (*this)[i].copyOwnerToAll(x[i], y[i]); });
183 decltype(
auto) communicator()
const 185 return std::get<0>(*this).communicator();
191 #endif // OPM_MULTICOMM_HEADER_INCLUDED Definition: MultiComm.hpp:118
Definition: fvbaseprimaryvariables.hh:161
Definition: MultiComm.hpp:37