Skip to content
Snippets Groups Projects
Commit 1ef1123a authored by Oliver Sander's avatar Oliver Sander Committed by sander
Browse files

Copy the file interval.hh from dune-fufem to here.

dune-tnnmg needs it, but we want dune-tnnmg to be independent from dune-fufem.
Hence we make a copy here in dune-solvers, which dune-tnnmg will always depend
on.

[[Imported from SVN: r12745]]
parent 185fc5df
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ commondir = $(includedir)/dune/solvers/common ...@@ -4,6 +4,7 @@ commondir = $(includedir)/dune/solvers/common
common_HEADERS = boxconstraint.hh \ common_HEADERS = boxconstraint.hh \
genericvectortools.hh \ genericvectortools.hh \
canignore.hh \ canignore.hh \
interval.hh \
numproc.hh \ numproc.hh \
permutationmanager.hh \ permutationmanager.hh \
preconditioner.hh \ preconditioner.hh \
......
#ifndef DUNE_SOLVERS_COMMON_INTERVAL_HH
#define DUNE_SOLVERS_COMMON_INTERVAL_HH
#include <iostream>
#include <algorithm>
#include <dune/common/array.hh>
/** \brief Encapsulates a closed interval
* \tparam field_type The type used for real numbers
*/
template <class field_type>
class Interval
{
public:
/** \brief Array-like access
*/
field_type& operator[](int i)
{
return data_[i];
}
/** \brief Const array-like access
*/
const field_type& operator[](int i) const
{
return data_[i];
}
/** \brief Project a scalar onto the interval
*/
field_type projectIn(const field_type& x) const
{
return std::max(std::min(x,data_[1]), data_[0]);
}
/** \brief Fast projection onto the interval if you know that your value
* is smaller than your upper bound
*/
field_type projectFromBelow(const field_type& x) const
{
return std::max(x,data_[0]);
};
/** \brief Fast projection onto the interval if you know that your value
* is larger than your lower bound
*/
field_type projectFromAbove(const field_type& x) const
{
return std::min(x,data_[1]);
};
/** \brief Return true if zero is contained in the interval
* \param safety An additive safety distance
*/
bool containsZero(const field_type& safety) const
{
return (data_[0] <= safety) and (-safety <= data_[1]);
};
private:
/** \brief The actual data */
Dune::array<field_type,2> data_;
};
//! Output operator for Interval
template <class field_type>
inline std::ostream& operator<< (std::ostream& s, const Interval<field_type>& interval)
{
s << "[" << interval[0] << ", " << interval[1] << "]";
return s;
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment