BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
RealLimits.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/Tools/RealLimits.h
6 //! @brief Defines class RealLimits.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_FIT_TOOLS_REALLIMITS_H
16 #define BORNAGAIN_FIT_TOOLS_REALLIMITS_H
17 
18 #include <ostream>
19 #include <string>
20 
21 //! Limits for a real fit parameter.
22 //! @ingroup fitting
23 
25 {
26 public:
27  RealLimits();
28 
29  //! if has lower limit
30  bool hasLowerLimit() const;
31 
32  //! Returns lower limit
33  double lowerLimit() const;
34 
35  //! Sets lower limit
36  void setLowerLimit(double value);
37 
38  //! remove lower limit
39  void removeLowerLimit();
40 
41  //! if has upper limit
42  bool hasUpperLimit() const;
43 
44  //! Returns upper limit
45  double upperLimit() const;
46 
47  //! Sets upper limit
48  void setUpperLimit(double value);
49 
50  //! remove upper limit
51  void removeUpperLimit();
52 
53  //! if has lower and upper limit
54  bool hasLowerAndUpperLimits() const;
55 
56  //! Sets lower and upper limits
57  void setLimits(double xmin, double xmax);
58 
59  //! remove limits
60  void removeLimits();
61 
62  //! returns true if proposed value is in limits range
63  bool isInRange(double value) const;
64 
65  //! Creates an object bounded from the left
66  static RealLimits lowerLimited(double bound_value);
67 
68  //! Creates an object which can have only positive values (>0., zero is not included)
69  static RealLimits positive();
70 
71  //! Creates an object which can have only positive values with 0. included
72  static RealLimits nonnegative();
73 
74  //! Creates an object bounded from the right
75  static RealLimits upperLimited(double bound_value);
76 
77  //! Creates an object bounded from the left and right
78  static RealLimits limited(double left_bound_value, double right_bound_value);
79 
80  //! Creates an object withoud bounds (default)
81  static RealLimits limitless();
82 
83  std::string toString() const;
84 
85  //! Prints class
86  friend std::ostream& operator<<(std::ostream& ostr, const RealLimits& m)
87  {
88  ostr << m.toString();
89  return ostr;
90  }
91 
92  bool operator==(const RealLimits& other) const;
93  bool operator!=(const RealLimits& other) const;
94 
95  bool isLimitless() const;
96  bool isPositive() const;
97  bool isNonnegative() const;
98  bool isLowerLimited() const;
99  bool isUpperLimited() const;
100  bool isLimited() const;
101 
102 protected:
103  RealLimits(bool has_lower_limit, bool has_upper_limit, double lower_limit, double upper_limit);
104 
105  bool m_has_lower_limit; //! parameter has lower bound
106  bool m_has_upper_limit; //! parameter has upper bound
107  double m_lower_limit; //! minimum allowed value
108  double m_upper_limit; //! maximum allowed value
109 };
110 
111 #endif // BORNAGAIN_FIT_TOOLS_REALLIMITS_H
Limits for a real fit parameter.
Definition: RealLimits.h:25
bool isLimited() const
Definition: RealLimits.cpp:197
static RealLimits limitless()
Creates an object withoud bounds (default)
Definition: RealLimits.cpp:128
std::string toString() const
Definition: RealLimits.cpp:133
bool m_has_lower_limit
Definition: RealLimits.h:105
void removeLowerLimit()
remove lower limit
Definition: RealLimits.cpp:49
static RealLimits upperLimited(double bound_value)
Creates an object bounded from the right.
Definition: RealLimits.cpp:118
bool isLowerLimited() const
Definition: RealLimits.cpp:187
bool isPositive() const
Definition: RealLimits.cpp:176
bool operator==(const RealLimits &other) const
Definition: RealLimits.cpp:159
bool hasUpperLimit() const
if has upper limit
Definition: RealLimits.cpp:55
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:103
bool hasLowerAndUpperLimits() const
if has lower and upper limit
Definition: RealLimits.cpp:77
static RealLimits positive()
Creates an object which can have only positive values (>0., zero is not included)
Definition: RealLimits.cpp:108
friend std::ostream & operator<<(std::ostream &ostr, const RealLimits &m)
Prints class.
Definition: RealLimits.h:86
bool isInRange(double value) const
returns true if proposed value is in limits range
Definition: RealLimits.cpp:94
double m_lower_limit
parameter has upper bound
Definition: RealLimits.h:107
bool m_has_upper_limit
parameter has lower bound
Definition: RealLimits.h:106
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:60
void setLowerLimit(double value)
Sets lower limit.
Definition: RealLimits.cpp:43
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:38
void removeUpperLimit()
remove upper limit
Definition: RealLimits.cpp:71
bool isNonnegative() const
Definition: RealLimits.cpp:182
bool operator!=(const RealLimits &other) const
Definition: RealLimits.cpp:166
void setLimits(double xmin, double xmax)
Sets lower and upper limits.
Definition: RealLimits.cpp:82
bool isLimitless() const
Definition: RealLimits.cpp:171
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:113
double m_upper_limit
minimum allowed value
Definition: RealLimits.h:108
void removeLimits()
remove limits
Definition: RealLimits.cpp:88
bool isUpperLimited() const
Definition: RealLimits.cpp:192
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:123
bool hasLowerLimit() const
if has lower limit
Definition: RealLimits.cpp:33
void setUpperLimit(double value)
Sets upper limit.
Definition: RealLimits.cpp:65