Skip to content
Snippets Groups Projects
Commit dd7e8ed3 authored by Oliver Sander's avatar Oliver Sander
Browse files

Implement the infinity_norm method for the MultiTypeBlockVector class

parent f9aede6e
No related branches found
No related tags found
No related merge requests found
...@@ -228,6 +228,38 @@ namespace Dune { ...@@ -228,6 +228,38 @@ namespace Dune {
static real_type result (const T&) {return 0.0;} static real_type result (const T&) {return 0.0;}
}; };
/** \brief Calculate the \infty-norm
Each element of the vector has to provide the method "infinity_norm()"
in order to calculate the whole vector's norm.
*/
template<int count, typename T>
class MultiTypeBlockVector_InfinityNorm {
public:
typedef typename T::field_type field_type;
typedef typename FieldTraits<field_type>::real_type real_type;
/**
* Take the maximum over all elements' norms
*/
static real_type result (const T& a)
{
using std::max;
return max(std::get<count-1>(a).infinity_norm(), MultiTypeBlockVector_InfinityNorm<count-1,T>::result(a));
}
};
template<typename T> //recursion end
class MultiTypeBlockVector_InfinityNorm<0,T> {
public:
typedef typename T::field_type field_type;
typedef typename FieldTraits<field_type>::real_type real_type;
static real_type result (const T&)
{
return 0.0;
}
};
/** /**
@brief A Vector class to support different block types @brief A Vector class to support different block types
...@@ -377,6 +409,13 @@ namespace Dune { ...@@ -377,6 +409,13 @@ namespace Dune {
*/ */
typename FieldTraits<field_type>::real_type two_norm() const {return sqrt(this->two_norm2());} typename FieldTraits<field_type>::real_type two_norm() const {return sqrt(this->two_norm2());}
/** \brief Compute the maximum norm
*/
typename FieldTraits<field_type>::real_type infinity_norm() const
{
return MultiTypeBlockVector_InfinityNorm<sizeof...(Args),type>::result(*this);
}
/** \brief Axpy operation on this vector (*this += a * y) /** \brief Axpy operation on this vector (*this += a * y)
* *
* \tparam Ta Type of the scalar 'a' * \tparam Ta Type of the scalar 'a'
......
...@@ -69,6 +69,9 @@ int main(int argc, char** argv) try ...@@ -69,6 +69,9 @@ int main(int argc, char** argv) try
// Test two_norm2 // Test two_norm2
std::cout << "multivector2 has two_norm2: " << multiVector2.two_norm2() << std::endl; std::cout << "multivector2 has two_norm2: " << multiVector2.two_norm2() << std::endl;
// Test infinity_norm
std::cout << "multivector2 has infinity_norm: " << multiVector2.infinity_norm() << std::endl;
// Test operator* // Test operator*
std::cout << multiVector * multiVector2 << std::endl; std::cout << multiVector * multiVector2 << std::endl;
......
  • Developer

    (This is mostly a note to self unless somebody beats me to it): This new infinity_norm() is not yet specialised to handle NaN values gracefully(*).

    (*) unlike all the other infinity_norm() implementations in dune-common and dune-istl that I know of.

  • Elias Pipping @pipping

    mentioned in merge request !15 (merged)

    ·

    mentioned in merge request !15 (merged)

    Toggle commit list
  • Christian Engwer @christi

    mentioned in commit c9ee3bdf

    ·

    mentioned in commit c9ee3bdf

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment