Loading...
Searching...
No Matches
scalarproducts.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_SCALARPRODUCTS_HH
#define DUNE_ISTL_SCALARPRODUCTS_HH
#include <cmath>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <memory>
#include <dune/common/exceptions.hh>
#include <dune/common/shared_ptr.hh>
#include "bvector.hh"
#include "solvercategory.hh"
namespace Dune {
template<class X>
class ScalarProduct {
public:
typedef X domain_type;
typedef typename X::field_type field_type;
typedef typename FieldTraits<field_type>::real_type real_type;
virtual field_type dot (const X& x, const X& y) const
{
return x.dot(y);
}
virtual real_type norm (const X& x) const
{
return x.two_norm();
}
virtual SolverCategory::Category category() const
{
return SolverCategory::sequential;
}
virtual ~ScalarProduct () {}
};
template<class X, class C>
class ParallelScalarProduct : public ScalarProduct<X>
{
public:
typedef X domain_type;
typedef typename X::field_type field_type;
typedef typename FieldTraits<field_type>::real_type real_type;
typedef C communication_type;
ParallelScalarProduct (std::shared_ptr<const communication_type> com, SolverCategory::Category cat)
: _communication(com), _category(cat)
{}
ParallelScalarProduct (const communication_type& com, SolverCategory::Category cat)
: ParallelScalarProduct(stackobject_to_shared_ptr(com), cat)
{}
field_type dot (const X& x, const X& y) const override
{
field_type result(0);
_communication->dot(x,y,result); // explicitly loop and apply masking
return result;
}
real_type norm (const X& x) const override
{
return _communication->norm(x);
}
SolverCategory::Category category() const override
{
return _category;
}
private:
std::shared_ptr<const communication_type> _communication;
SolverCategory::Category _category;
};
template<class X>
class SeqScalarProduct : public ScalarProduct<X>
{
using ScalarProduct<X>::ScalarProduct;
};
template<class X, class C>
class NonoverlappingSchwarzScalarProduct : public ParallelScalarProduct<X,C>
{
public:
NonoverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
ParallelScalarProduct<X,C>(comm,SolverCategory::nonoverlapping) {}
NonoverlappingSchwarzScalarProduct (const C& comm) :
ParallelScalarProduct<X,C>(comm,SolverCategory::nonoverlapping) {}
};
template<class X, class C>
class OverlappingSchwarzScalarProduct : public ParallelScalarProduct<X,C>
{
public:
OverlappingSchwarzScalarProduct (std::shared_ptr<const C> comm) :
ParallelScalarProduct<X,C>(comm, SolverCategory::overlapping) {}
OverlappingSchwarzScalarProduct (const C& comm) :
ParallelScalarProduct<X,C>(comm,SolverCategory::overlapping) {}
};
template<class X, class Comm>
std::shared_ptr<ScalarProduct<X>> makeScalarProduct(std::shared_ptr<const Comm> comm, SolverCategory::Category category)
{
switch(category)
{
case SolverCategory::sequential:
return
std::make_shared<ScalarProduct<X>>();
default:
return
std::make_shared<ParallelScalarProduct<X,Comm>>(comm,category);
}
}
template<class X, class Comm>
std::shared_ptr<ScalarProduct<X>> createScalarProduct(const Comm& comm, SolverCategory::Category category)
{ return makeScalarProduct<X>(stackobject_to_shared_ptr(comm), category); }
} // end namespace Dune
#endif
bvector.hh
This file implements a vector space as a tensor product of a given vector space. The number of compon...
solvercategory.hh
Dune
Definition allocator.hh:11
Dune::createScalarProduct
std::shared_ptr< ScalarProduct< X > > createScalarProduct(const Comm &comm, SolverCategory::Category category)
Definition scalarproducts.hh:242
Dune::makeScalarProduct
std::shared_ptr< ScalarProduct< X > > makeScalarProduct(std::shared_ptr< const Comm > comm, SolverCategory::Category category)
Choose the appropriate scalar product for a solver category.
Definition scalarproducts.hh:224
Dune::ScalarProduct
Base class for scalar product and norm computation.
Definition scalarproducts.hh:52
Dune::ScalarProduct::dot
virtual field_type dot(const X &x, const X &y) const
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition scalarproducts.hh:63
Dune::ScalarProduct::category
virtual SolverCategory::Category category() const
Category of the scalar product (see SolverCategory::Category).
Definition scalarproducts.hh:77
Dune::ScalarProduct::field_type
X::field_type field_type
Definition scalarproducts.hh:56
Dune::ScalarProduct::domain_type
X domain_type
export types, they come from the derived class
Definition scalarproducts.hh:55
Dune::ScalarProduct::~ScalarProduct
virtual ~ScalarProduct()
every abstract base class has a virtual destructor
Definition scalarproducts.hh:83
Dune::ScalarProduct::real_type
FieldTraits< field_type >::real_type real_type
Definition scalarproducts.hh:57
Dune::ScalarProduct::norm
virtual real_type norm(const X &x) const
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition.
Definition scalarproducts.hh:71
Dune::ParallelScalarProduct::dot
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 part...
Definition scalarproducts.hh:139
Dune::ParallelScalarProduct::real_type
FieldTraits< field_type >::real_type real_type
Definition scalarproducts.hh:108
Dune::ParallelScalarProduct::communication_type
C communication_type
The type of the communication object.
Definition scalarproducts.hh:113
Dune::ParallelScalarProduct::ParallelScalarProduct
ParallelScalarProduct(const communication_type &com, SolverCategory::Category cat)
Definition scalarproducts.hh:130
Dune::ParallelScalarProduct::domain_type
X domain_type
The type of the vector to compute the scalar product on.
Definition scalarproducts.hh:105
Dune::ParallelScalarProduct::ParallelScalarProduct
ParallelScalarProduct(std::shared_ptr< const communication_type > com, SolverCategory::Category cat)
Definition scalarproducts.hh:120
Dune::ParallelScalarProduct::norm
real_type norm(const X &x) const override
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition.
Definition scalarproducts.hh:149
Dune::ParallelScalarProduct::category
SolverCategory::Category category() const override
Category of the scalar product (see SolverCategory::Category).
Definition scalarproducts.hh:155
Dune::ParallelScalarProduct::field_type
X::field_type field_type
The field type used by the vector type domain_type.
Definition scalarproducts.hh:107
Dune::SeqScalarProduct
Default implementation for the scalar case.
Definition scalarproducts.hh:168
Dune::NonoverlappingSchwarzScalarProduct::NonoverlappingSchwarzScalarProduct
NonoverlappingSchwarzScalarProduct(std::shared_ptr< const C > comm)
Definition scalarproducts.hh:181
Dune::NonoverlappingSchwarzScalarProduct::NonoverlappingSchwarzScalarProduct
NonoverlappingSchwarzScalarProduct(const C &comm)
Definition scalarproducts.hh:184
Dune::OverlappingSchwarzScalarProduct::OverlappingSchwarzScalarProduct
OverlappingSchwarzScalarProduct(std::shared_ptr< const C > comm)
Definition scalarproducts.hh:203
Dune::OverlappingSchwarzScalarProduct::OverlappingSchwarzScalarProduct
OverlappingSchwarzScalarProduct(const C &comm)
Definition scalarproducts.hh:206
Dune::SolverCategory
Categories for the solvers.
Definition solvercategory.hh:22
Dune::SolverCategory::Category
Category
Definition solvercategory.hh:23
Dune::SolverCategory::sequential
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25