BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
RealLimits Class Reference

Description

Limits for a real fit parameter.

Definition at line 24 of file RealLimits.h.

Public Member Functions

 RealLimits ()
 Default constructor creates a "limitless" instance. More...
 
void check (const std::string &name, double value) const
 Throws if value is outside limits. Parameter 'name' is for exception message. More...
 
bool hasLowerAndUpperLimits () const
 if has lower and upper limit More...
 
bool hasLowerLimit () const
 if has lower limit More...
 
bool hasUpperLimit () const
 if has upper limit More...
 
bool isInRange (double value) const
 Returns true if proposed value is in limits range. More...
 
bool isLimited () const
 
bool isLimitless () const
 
bool isLowerLimited () const
 
bool isNonnegative () const
 
bool isPositive () const
 
bool isUpperLimited () const
 
double lowerLimit () const
 Returns lower limit. More...
 
bool operator!= (const RealLimits &other) const
 
bool operator== (const RealLimits &other) const
 
void removeLimits ()
 remove limits More...
 
void removeLowerLimit ()
 remove lower limit More...
 
void removeUpperLimit ()
 remove upper limit More...
 
RealLimits scaledLimits (double factor) const
 Creates a copy with scaled boundaries, if applicable. More...
 
void setLimits (double xmin, double xmax)
 Sets lower and upper limits. More...
 
void setLowerLimit (double value)
 Sets lower limit. More...
 
void setUpperLimit (double value)
 Sets upper limit. More...
 
std::string toString () const
 
double upperLimit () const
 Returns upper limit. More...
 

Static Public Member Functions

static RealLimits limited (double left_bound_value, double right_bound_value)
 Creates an object bounded from the left and right. More...
 
static RealLimits limitless ()
 Creates an object without bounds (default) More...
 
static RealLimits lowerLimited (double bound_value)
 Creates an object bounded from the left. More...
 
static RealLimits nonnegative ()
 Creates an object which can have only positive values with 0. included. More...
 
static RealLimits positive ()
 Creates an object which can have only positive values (>0., zero is not included) More...
 
static RealLimits upperLimited (double bound_value)
 Creates an object bounded from the right. More...
 

Protected Member Functions

 RealLimits (bool has_lower_limit, bool has_upper_limit, double lower_limit, double upper_limit)
 

Protected Attributes

bool m_has_lower_limit
 
bool m_has_upper_limit
 parameter has lower bound More...
 
double m_lower_limit
 parameter has upper bound More...
 
double m_upper_limit
 minimum allowed value More...
 

Friends

std::ostream & operator<< (std::ostream &ostr, const RealLimits &m)
 Prints class. More...
 

Constructor & Destructor Documentation

◆ RealLimits() [1/2]

RealLimits::RealLimits ( )

Default constructor creates a "limitless" instance.

Definition at line 21 of file RealLimits.cpp.

22  : m_has_lower_limit(false)
23  , m_has_upper_limit(false)
24  , m_lower_limit(0.)
25  , m_upper_limit(0.)
26 {
27 }
bool m_has_lower_limit
Definition: RealLimits.h:111
double m_lower_limit
parameter has upper bound
Definition: RealLimits.h:113
bool m_has_upper_limit
parameter has lower bound
Definition: RealLimits.h:112
double m_upper_limit
minimum allowed value
Definition: RealLimits.h:114

Referenced by limited(), limitless(), lowerLimited(), scaledLimits(), and upperLimited().

◆ RealLimits() [2/2]

RealLimits::RealLimits ( bool  has_lower_limit,
bool  has_upper_limit,
double  lower_limit,
double  upper_limit 
)
protected

Definition at line 29 of file RealLimits.cpp.

31  : m_has_lower_limit(has_lower_limit)
32  , m_has_upper_limit(has_upper_limit)
33  , m_lower_limit(lower_limit)
34  , m_upper_limit(upper_limit)
35 {
36 }

Member Function Documentation

◆ check()

void RealLimits::check ( const std::string &  name,
double  value 
) const

Throws if value is outside limits. Parameter 'name' is for exception message.

Definition at line 170 of file RealLimits.cpp.

171 {
172  if (!isInRange(value)) {
173  std::ostringstream message;
174  message << "Parameter " << name << ": value " << value << " is out of bounds [" << *this
175  << "]\n";
176  throw std::runtime_error(message.str());
177  }
178 }
bool isInRange(double value) const
Returns true if proposed value is in limits range.
Definition: RealLimits.cpp:105

References isInRange().

Referenced by BasicLattice2D::BasicLattice2D(), Beam::Beam(), HexagonalLattice2D::HexagonalLattice2D(), IInterference::IInterference(), Interference1DLattice::Interference1DLattice(), Interference2DParaCrystal::Interference2DParaCrystal(), InterferenceHardDisk::InterferenceHardDisk(), InterferenceRadialParaCrystal::InterferenceRadialParaCrystal(), InterferenceTwin::InterferenceTwin(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), SquareLattice2D::SquareLattice2D(), INode::checkNodeArgs(), and Beam::setInclinationAngleGuarded().

Here is the call graph for this function:

◆ hasLowerAndUpperLimits()

bool RealLimits::hasLowerAndUpperLimits ( ) const

if has lower and upper limit

Definition at line 88 of file RealLimits.cpp.

89 {
91 }

References m_has_lower_limit, and m_has_upper_limit.

Referenced by IRangedDistribution::checkInitialization(), and AttLimits::isLimited().

◆ hasLowerLimit()

◆ hasUpperLimit()

◆ isInRange()

bool RealLimits::isInRange ( double  value) const

Returns true if proposed value is in limits range.

Definition at line 105 of file RealLimits.cpp.

106 {
107  if (hasLowerLimit() && value < m_lower_limit)
108  return false;
109  if (hasUpperLimit() && value >= m_upper_limit)
110  return false;
111  return true;
112 }
bool hasUpperLimit() const
if has upper limit
Definition: RealLimits.cpp:66
bool hasLowerLimit() const
if has lower limit
Definition: RealLimits.cpp:44

References hasLowerLimit(), hasUpperLimit(), m_lower_limit, and m_upper_limit.

Referenced by check().

Here is the call graph for this function:

◆ isLimited()

bool RealLimits::isLimited ( ) const

Definition at line 218 of file RealLimits.cpp.

219 {
220  return hasLowerLimit() && hasUpperLimit();
221 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by Py::Fmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isLimitless()

bool RealLimits::isLimitless ( ) const

Definition at line 192 of file RealLimits.cpp.

193 {
194  return !hasLowerLimit() && !hasUpperLimit();
195 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by Py::Fmt2::printRangedDistribution(), Py::Fmt::printRealLimits(), Py::Fmt::printRealLimitsArg(), and toString().

Here is the call graph for this function:

◆ isLowerLimited()

bool RealLimits::isLowerLimited ( ) const

Definition at line 208 of file RealLimits.cpp.

209 {
210  return hasLowerLimit() && !hasUpperLimit();
211 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by Py::Fmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isNonnegative()

bool RealLimits::isNonnegative ( ) const

Definition at line 203 of file RealLimits.cpp.

204 {
205  return hasLowerLimit() && !hasUpperLimit() && lowerLimit() == 0.0;
206 }
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:49

References hasLowerLimit(), hasUpperLimit(), and lowerLimit().

Referenced by Py::Fmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isPositive()

bool RealLimits::isPositive ( ) const

Definition at line 197 of file RealLimits.cpp.

198 {
199  return hasLowerLimit() && !hasUpperLimit()
200  && lowerLimit() == std::numeric_limits<double>::min();
201 }

References hasLowerLimit(), hasUpperLimit(), and lowerLimit().

Referenced by Py::Fmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ isUpperLimited()

bool RealLimits::isUpperLimited ( ) const

Definition at line 213 of file RealLimits.cpp.

214 {
215  return !hasLowerLimit() && hasUpperLimit();
216 }

References hasLowerLimit(), and hasUpperLimit().

Referenced by Py::Fmt::printRealLimits(), and toString().

Here is the call graph for this function:

◆ limited()

RealLimits RealLimits::limited ( double  left_bound_value,
double  right_bound_value 
)
static

Creates an object bounded from the left and right.

Definition at line 134 of file RealLimits.cpp.

135 {
136  return RealLimits(true, true, left_bound_value, right_bound_value);
137 }
RealLimits()
Default constructor creates a "limitless" instance.
Definition: RealLimits.cpp:21

References RealLimits().

Referenced by DepthProbeSimulation::DepthProbeSimulation(), INode::checkNodeArgs(), and AttLimits::limited().

Here is the call graph for this function:

◆ limitless()

RealLimits RealLimits::limitless ( )
static

Creates an object without bounds (default)

Definition at line 139 of file RealLimits.cpp.

140 {
141  return RealLimits();
142 }

References RealLimits().

Referenced by INode::checkNodeArgs(), and AttLimits::fixed().

Here is the call graph for this function:

◆ lowerLimit()

double RealLimits::lowerLimit ( ) const

◆ lowerLimited()

RealLimits RealLimits::lowerLimited ( double  bound_value)
static

Creates an object bounded from the left.

Definition at line 114 of file RealLimits.cpp.

115 {
116  return RealLimits(true, false, bound_value, 0.);
117 }

References RealLimits().

Referenced by AttLimits::lowerLimited(), nonnegative(), and positive().

Here is the call graph for this function:

◆ nonnegative()

RealLimits RealLimits::nonnegative ( )
static

Creates an object which can have only positive values with 0. included.

Definition at line 124 of file RealLimits.cpp.

125 {
126  return lowerLimited(0.);
127 }
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:114

References lowerLimited().

Referenced by Beam::Beam(), IInterference::IInterference(), Interference1DLattice::Interference1DLattice(), Interference2DParaCrystal::Interference2DParaCrystal(), InterferenceHardDisk::InterferenceHardDisk(), InterferenceRadialParaCrystal::InterferenceRadialParaCrystal(), InterferenceTwin::InterferenceTwin(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), INode::checkNodeArgs(), and AttLimits::nonnegative().

Here is the call graph for this function:

◆ operator!=()

bool RealLimits::operator!= ( const RealLimits other) const

Definition at line 187 of file RealLimits.cpp.

188 {
189  return !(*this == other);
190 }

◆ operator==()

bool RealLimits::operator== ( const RealLimits other) const

Definition at line 180 of file RealLimits.cpp.

181 {
182  return (m_has_lower_limit == other.m_has_lower_limit)
184  && (m_lower_limit == other.m_lower_limit) && (m_upper_limit == other.m_upper_limit);
185 }

References m_has_lower_limit, m_has_upper_limit, m_lower_limit, and m_upper_limit.

◆ positive()

RealLimits RealLimits::positive ( )
static

Creates an object which can have only positive values (>0., zero is not included)

Definition at line 119 of file RealLimits.cpp.

120 {
121  return lowerLimited(std::numeric_limits<double>::min());
122 }

References lowerLimited().

Referenced by BasicLattice2D::BasicLattice2D(), HexagonalLattice2D::HexagonalLattice2D(), SquareLattice2D::SquareLattice2D(), and AttLimits::positive().

Here is the call graph for this function:

◆ removeLimits()

void RealLimits::removeLimits ( )

remove limits

Definition at line 99 of file RealLimits.cpp.

100 {
103 }
void removeLowerLimit()
remove lower limit
Definition: RealLimits.cpp:60
void removeUpperLimit()
remove upper limit
Definition: RealLimits.cpp:82

References removeLowerLimit(), and removeUpperLimit().

Referenced by AttLimits::setFixed().

Here is the call graph for this function:

◆ removeLowerLimit()

void RealLimits::removeLowerLimit ( )

remove lower limit

Definition at line 60 of file RealLimits.cpp.

61 {
62  m_lower_limit = 0.;
63  m_has_lower_limit = false;
64 }

References m_has_lower_limit, and m_lower_limit.

Referenced by removeLimits().

◆ removeUpperLimit()

void RealLimits::removeUpperLimit ( )

remove upper limit

Definition at line 82 of file RealLimits.cpp.

83 {
84  m_upper_limit = 0.;
85  m_has_upper_limit = false;
86 }

References m_has_upper_limit, and m_upper_limit.

Referenced by removeLimits().

◆ scaledLimits()

RealLimits RealLimits::scaledLimits ( double  factor) const

Creates a copy with scaled boundaries, if applicable.

Definition at line 38 of file RealLimits.cpp.

39 {
41  m_upper_limit * factor);
42 }

References RealLimits(), m_has_lower_limit, m_has_upper_limit, m_lower_limit, and m_upper_limit.

Here is the call graph for this function:

◆ setLimits()

void RealLimits::setLimits ( double  xmin,
double  xmax 
)

Sets lower and upper limits.

Definition at line 93 of file RealLimits.cpp.

94 {
95  setLowerLimit(xmin);
96  setUpperLimit(xmax);
97 }
void setLowerLimit(double value)
Sets lower limit.
Definition: RealLimits.cpp:54
void setUpperLimit(double value)
Sets upper limit.
Definition: RealLimits.cpp:76

References setLowerLimit(), and setUpperLimit().

Here is the call graph for this function:

◆ setLowerLimit()

void RealLimits::setLowerLimit ( double  value)

Sets lower limit.

Definition at line 54 of file RealLimits.cpp.

55 {
56  m_lower_limit = value;
57  m_has_lower_limit = true;
58 }

References m_has_lower_limit, and m_lower_limit.

Referenced by setLimits().

◆ setUpperLimit()

void RealLimits::setUpperLimit ( double  value)

Sets upper limit.

Definition at line 76 of file RealLimits.cpp.

77 {
78  m_upper_limit = value;
79  m_has_upper_limit = true;
80 }

References m_has_upper_limit, and m_upper_limit.

Referenced by setLimits().

◆ toString()

std::string RealLimits::toString ( ) const

Definition at line 144 of file RealLimits.cpp.

145 {
146  std::ostringstream result;
147 
148  if (isLimitless())
149  result << "unlimited";
150 
151  else if (isPositive())
152  result << "positive";
153 
154  else if (isNonnegative())
155  result << "nonnegative";
156 
157  else if (isLowerLimited())
158  result << "lowerLimited(" << std::fixed << std::setprecision(2) << lowerLimit() << ")";
159 
160  else if (isUpperLimited())
161  result << "upperLimited(" << std::fixed << std::setprecision(2) << upperLimit() << ")";
162 
163  else if (isLimited())
164  result << "limited(" << std::fixed << std::setprecision(2) << lowerLimit() << ","
165  << std::fixed << std::setprecision(2) << upperLimit() << ")";
166 
167  return result.str();
168 }
bool isLimited() const
Definition: RealLimits.cpp:218
bool isLowerLimited() const
Definition: RealLimits.cpp:208
bool isPositive() const
Definition: RealLimits.cpp:197
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:71
bool isNonnegative() const
Definition: RealLimits.cpp:203
bool isLimitless() const
Definition: RealLimits.cpp:192
bool isUpperLimited() const
Definition: RealLimits.cpp:213

References isLimited(), isLimitless(), isLowerLimited(), isNonnegative(), isPositive(), isUpperLimited(), lowerLimit(), and upperLimit().

Here is the call graph for this function:

◆ upperLimit()

double RealLimits::upperLimit ( ) const

◆ upperLimited()

RealLimits RealLimits::upperLimited ( double  bound_value)
static

Creates an object bounded from the right.

Definition at line 129 of file RealLimits.cpp.

130 {
131  return RealLimits(false, true, 0., bound_value);
132 }

References RealLimits().

Referenced by AttLimits::upperLimited().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  ostr,
const RealLimits m 
)
friend

Prints class.

Definition at line 92 of file RealLimits.h.

93  {
94  ostr << m.toString();
95  return ostr;
96  }
std::string toString() const
Definition: RealLimits.cpp:144

Member Data Documentation

◆ m_has_lower_limit

bool RealLimits::m_has_lower_limit
protected

◆ m_has_upper_limit

bool RealLimits::m_has_upper_limit
protected

parameter has lower bound

Definition at line 112 of file RealLimits.h.

Referenced by hasLowerAndUpperLimits(), hasUpperLimit(), operator==(), removeUpperLimit(), scaledLimits(), and setUpperLimit().

◆ m_lower_limit

double RealLimits::m_lower_limit
protected

parameter has upper bound

Definition at line 113 of file RealLimits.h.

Referenced by isInRange(), lowerLimit(), operator==(), removeLowerLimit(), scaledLimits(), and setLowerLimit().

◆ m_upper_limit

double RealLimits::m_upper_limit
protected

minimum allowed value

Definition at line 114 of file RealLimits.h.

Referenced by isInRange(), operator==(), removeUpperLimit(), scaledLimits(), setUpperLimit(), and upperLimit().


The documentation for this class was generated from the following files: