overlappingscalarproduct.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef EWOMS_OVERLAPPING_SCALAR_PRODUCT_HH
28#define EWOMS_OVERLAPPING_SCALAR_PRODUCT_HH
29
30#include <dune/common/parallel/mpihelper.hh>
31#include <dune/istl/scalarproducts.hh>
32
33namespace Opm {
34namespace Linear {
35
39template <class OverlappingBlockVector, class Overlap>
41 : public Dune::ScalarProduct<OverlappingBlockVector>
42{
43public:
44 using field_type = typename OverlappingBlockVector::field_type;
45
46 using CollectiveCommunication = typename Dune::Communication<typename Dune::MPIHelper::MPICommunicator>;
47 using real_type = typename Dune::ScalarProduct<OverlappingBlockVector>::real_type;
48
50 Dune::SolverCategory::Category category() const override
51 { return Dune::SolverCategory::overlapping; }
52
53 OverlappingScalarProduct(const Overlap& overlap)
54 : overlap_(overlap),
55 comm_( Dune::MPIHelper::getCommunication() )
56 {}
57
59 const OverlappingBlockVector& y) const override
60 {
61 field_type sum = 0;
62 size_t numLocal = overlap_.numLocal();
63 for (unsigned localIdx = 0; localIdx < numLocal; ++localIdx) {
64 if (overlap_.iAmMasterOf(static_cast<int>(localIdx)))
65 sum += x[localIdx] * y[localIdx];
66 }
67
68 // return the global sum
69 return comm_.sum( sum );
70 }
71
72 real_type norm(const OverlappingBlockVector& x) const override
73 { return std::sqrt(dot(x, x)); }
74
75private:
76 const Overlap& overlap_;
77 const CollectiveCommunication comm_;
78};
79
80} // namespace Linear
81} // namespace Opm
82
83#endif
An overlap aware block vector.
Definition: overlappingblockvector.hh:50
An overlap aware ISTL scalar product.
Definition: overlappingscalarproduct.hh:42
field_type dot(const OverlappingBlockVector &x, const OverlappingBlockVector &y) const override
Definition: overlappingscalarproduct.hh:58
typename OverlappingBlockVector::field_type field_type
Definition: overlappingscalarproduct.hh:44
typename Dune::Communication< typename Dune::MPIHelper::MPICommunicator > CollectiveCommunication
Definition: overlappingscalarproduct.hh:46
OverlappingScalarProduct(const Overlap &overlap)
Definition: overlappingscalarproduct.hh:53
Dune::SolverCategory::Category category() const override
the kind of computations supported by the operator. Either overlapping or non-overlapping
Definition: overlappingscalarproduct.hh:50
typename Dune::ScalarProduct< OverlappingBlockVector >::real_type real_type
Definition: overlappingscalarproduct.hh:47
real_type norm(const OverlappingBlockVector &x) const override
Definition: overlappingscalarproduct.hh:72
Definition: fvbaseprimaryvariables.hh:141
Definition: blackoilboundaryratevector.hh:37