KASKADE 7 development version
norm.hh
Go to the documentation of this file.
1/*
2 * norm.hh
3 *
4 * Created on: May 2, 2015
5 * Author: sunayana_ghosh
6 */
7/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8/* */
9/* This file is part of the library KASKADE 7 */
10/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
11/* */
12/* Copyright (C) 2015-2015 Zuse Institute Berlin */
13/* */
14/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
15/* see $KASKADE/academic.txt */
16/* */
17/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18#ifndef KASKADE_TIMESTEPPING_EULERSDC_NORM_HH_
19#define KASKADE_TIMESTEPPING_EULERSDC_NORM_HH_
20
21#include <numeric>
22#include <vector>
23
24//includes from Kaskade7.3
26
27namespace Kaskade {
28
29 //=======================================================================================================
30 // Implementation for enum class NormType
31 //=======================================================================================================
32
38 //---C++11 strongly typed enums. Would be used in the work model to call different functions.
39 enum class NormType {
40 ONE_NORM,
42 };
43
44 //=======================================================================================================
45 // Implementation abstract base class Norm
46 //=======================================================================================================
57 template <class Vector>
58 class Norm
59 {
60 public:
61 using field_type = typename Vector::value_type;
62
63
64
65 //pure virtual functions
71 virtual field_type value(std::vector<Vector> const& vecs) = 0;
72
73 //every abstract base class has a virtual destructor
74 virtual ~Norm (){}
75
76 private:
77 NormType norm_t;
78
79 };
80
81 //=================================================================================================
82 // Implementation for derive class one norm
83 //=================================================================================================
95 template <class Vector>
96 class OneNorm: public Norm<Vector>
97 {
98 public:
99 using field_type = typename Vector::value_type;
100
101
102
103 virtual field_type value(std::vector<Vector> const& vecs)
104 {
105
106 //Using Kaskade::LinAlg::OneNorm instead of one_norm for Dune::FieldVector since the one norm defined
107 //in Kaskade works for stl-container, Dune::FieldVector and Dune::FieldMatrix making it more generic.
108 return std::accumulate(vecs.begin(),vecs.end(),0.0,[](field_type init, Vector const& v)
109 {
110 Kaskade::LinAlg::OneNorm on;
111 return init + on(v);
112 });
113 }
114
115 virtual ~OneNorm () {}
116 };
117
118 //=======================================================================================================
119 // Implementation for derived class max norm
120 //=======================================================================================================
129 template <class Vector>
130 class MaxNorm : public Norm<Vector>
131 {
132 public:
133 using field_type = typename Vector::value_type;
134
135 virtual field_type value(std::vector<Vector> const& vecs)
136 {
137 //Using Kaskade::LinAlg::OneNorm instead of one_norm for Dune::FieldVector since the one norm defined
138 //in Kaskade works for stl-container, Dune::FieldVector and Dune::FieldMatrix making it more generic.
140 field_type max = in(vecs[0]);
141 for (auto i = 1u; i < vecs.size(); ++i)
142 max = std::max(max, in(vecs[i]));
143
144 return max;
145 }
146
147 virtual ~MaxNorm () {}
148 };
149
150
151} //end namespace Kaskade
152
153
154#endif /* KASKADE_TIMESTEPPING_EULERSDC_NORM_HH_ */
MaxNorm class derived from the abstract base class Norm. Here the max norm represents the max norm of...
Definition: norm.hh:131
virtual field_type value(std::vector< Vector > const &vecs)
Definition: norm.hh:135
virtual ~MaxNorm()
Definition: norm.hh:147
Abstract base class of various norms.
Definition: norm.hh:59
virtual field_type value(std::vector< Vector > const &vecs)=0
typename Vector::value_type field_type
Definition: norm.hh:61
virtual ~Norm()
Definition: norm.hh:74
OneNorm class derived from the abstract base class Norm.
Definition: norm.hh:97
virtual ~OneNorm()
Definition: norm.hh:115
virtual field_type value(std::vector< Vector > const &vecs)
Definition: norm.hh:103
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition: fixdune.hh:109
Dune::FieldVector< Scalar, dim > Vector
NormType
Enum class to define the norm type in class Norm.
Definition: norm.hh:39
@ ONE_NORM
ONE_NORM.
@ MAX_NORM
MAX_NORM.
Infinity norm for stl-container, Dune::FieldVector and Dune::FieldMatrix.