3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
scalarproducts.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_LINEAR_SCALAR_PRODUCTS_HH
25#define DUMUX_LINEAR_SCALAR_PRODUCTS_HH
26
27#include <array>
28#include <memory>
29#include <algorithm>
30
31#include <dune/common/ftraits.hh>
32#include <dune/common/hybridutilities.hh>
33
34#include <dune/istl/solvercategory.hh>
35#include <dune/istl/scalarproducts.hh>
36
37namespace Dumux {
38
53template<class X, class C>
54class ParallelMultiTypeScalarProduct : public Dune::ScalarProduct<X>
55{
56 static constexpr std::size_t numSubDomains = X::size();
57public:
58 // public aliases for a dune-istl like interface
59 using domain_type = X;
60 using field_type = typename X::field_type;
61 using real_type = typename Dune::FieldTraits<field_type>::real_type;
63
64 ParallelMultiTypeScalarProduct (const std::array<std::shared_ptr<const communication_type>, numSubDomains>& comms)
65 : comms_(comms)
66 {}
67
75 field_type dot (const X& x, const X& y) const override
76 {
77 field_type result = 0.0;
78
79 // use the communicators for the subdomain scalar products and sum up
80 using namespace Dune::Hybrid;
81 forEach(integralRange(Dune::Hybrid::size(y)), [&](auto&& i)
82 {
83 field_type subResult = 0.0;
84 comms_[i]->dot(x[i], y[i], subResult);
85 result += subResult;
86 });
87
88 return result;
89 }
90
94 real_type norm (const X& x) const override
95 {
96 using std::sqrt;
97 return sqrt(dot(x, x));
98 }
99
111 Dune::SolverCategory::Category category() const override
112 {
113 if (std::all_of(comms_.begin(), comms_.end(),
114 [](auto& c){ return c->category() == Dune::SolverCategory::sequential; }
115 ))
116 return Dune::SolverCategory::sequential;
117 else if (std::all_of(comms_.begin(), comms_.end(),
118 [](auto& c){ return c->category() == Dune::SolverCategory::nonoverlapping; }
119 ))
120 return Dune::SolverCategory::nonoverlapping;
121 else
122 return Dune::SolverCategory::overlapping;
123 }
124
125private:
126 std::array<std::shared_ptr<const communication_type>, numSubDomains> comms_;
127};
128
129} // end namespace Dumux
130
131#endif
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A scalar product for multi-type vectors.
Definition: scalarproducts.hh:55
typename X::field_type field_type
Definition: scalarproducts.hh:60
ParallelMultiTypeScalarProduct(const std::array< std::shared_ptr< const communication_type >, numSubDomains > &comms)
Definition: scalarproducts.hh:64
C communication_type
Definition: scalarproducts.hh:62
X domain_type
Definition: scalarproducts.hh:59
Dune::SolverCategory::Category category() const override
category of the scalar product
Definition: scalarproducts.hh:111
typename Dune::FieldTraits< field_type >::real_type real_type
Definition: scalarproducts.hh:61
field_type dot(const X &x, const X &y) const override
Dot product of two vectors It is assumed that the vectors are consistent on the interior+border parti...
Definition: scalarproducts.hh:75
real_type norm(const X &x) const override
compute 2-norm of a right-hand side vector
Definition: scalarproducts.hh:94