Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
interval.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_INTERVAL_HH
5#define DUNE_FUFEM_INTERVAL_HH
6
7#include <array>
8#include <iostream>
9#include <algorithm>
10
14template <class field_type>
16{
17public:
20 field_type& operator[](int i)
21 {
22 return data_[i];
23 }
24
27 const field_type& operator[](int i) const
28 {
29 return data_[i];
30 }
31
34 field_type projectIn(const field_type& x) const
35 {
36 return std::max(std::min(x,data_[1]), data_[0]);
37 }
38
42 field_type projectFromBelow(const field_type& x) const
43 {
44 return std::max(x,data_[0]);
45 };
46
50 field_type projectFromAbove(const field_type& x) const
51 {
52 return std::min(x,data_[1]);
53 };
54
58 bool containsZero(const field_type& safety) const
59 {
60 return (data_[0] <= safety) and (-safety <= data_[1]);
61 };
62
63private:
64
67};
68
70template <class field_type>
72{
73 s << "[" << interval[0] << ", " << interval[1] << "]";
74 return s;
75}
76
77#endif
std::ostream & operator<<(std::ostream &s, const Interval< field_type > &interval)
Output operator for Interval.
Definition interval.hh:71
Encapsulates a closed interval.
Definition interval.hh:16
field_type & operator[](int i)
Array-like access.
Definition interval.hh:20
const field_type & operator[](int i) const
Const array-like access.
Definition interval.hh:27
field_type projectIn(const field_type &x) const
Project a scalar onto the interval.
Definition interval.hh:34
field_type projectFromBelow(const field_type &x) const
Fast projection onto the interval if you know that your value is smaller than your upper bound.
Definition interval.hh:42
bool containsZero(const field_type &safety) const
Return true if zero is contained in the interval.
Definition interval.hh:58
field_type projectFromAbove(const field_type &x) const
Fast projection onto the interval if you know that your value is larger than your lower bound.
Definition interval.hh:50
T max(T... args)
T min(T... args)