BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
AttLimits.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Fit/Param/AttLimits.cpp
6 //! @brief Implements and implements class AttLimits.
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 #include "Fit/Param/AttLimits.h"
16 #include <iomanip>
17 #include <sstream>
18 
20  : m_limits(RealLimits::limitless())
21  , m_att_fixed(Attributes::free())
22 {
23 }
24 
25 AttLimits::AttLimits(const RealLimits& limits, const Attributes& fixedAttr)
26  : m_limits(limits)
27  , m_att_fixed(fixedAttr)
28 {
29 }
30 
32 {
33  return AttLimits();
34 }
35 
37 {
38  return AttLimits(RealLimits::lowerLimited(bound_value), Attributes::free());
39 }
40 
42 {
44 }
45 
47 {
49 }
50 
52 {
53  return AttLimits(RealLimits::upperLimited(bound_value), Attributes::free());
54 }
55 
56 AttLimits AttLimits::limited(double left_bound_value, double right_bound_value)
57 {
58  return AttLimits(RealLimits::limited(left_bound_value, right_bound_value), Attributes::free());
59 }
60 
62 {
64 }
65 
66 bool AttLimits::isFixed() const
67 {
68  return m_att_fixed.isFixed();
69 }
70 
72 {
74 }
75 
77 {
79 }
80 
82 {
84 }
85 
87 {
89 }
90 
91 double AttLimits::lowerLimit() const
92 {
93  return m_limits.lowerLimit();
94 }
95 
96 double AttLimits::upperLimit() const
97 {
98  return m_limits.upperLimit();
99 }
100 
101 void AttLimits::setFixed(bool isFixed)
102 {
105 }
106 
107 bool AttLimits::operator==(const AttLimits& other) const
108 {
109  return m_limits == other.m_limits && m_att_fixed == other.m_att_fixed;
110 }
111 
112 bool AttLimits::operator!=(const AttLimits& other) const
113 {
114  return !(*this == other);
115 }
116 
117 std::string AttLimits::toString() const
118 {
119  std::ostringstream result;
120 
121  if (isFixed())
122  result << "fixed";
123  else if (isLimitless())
124  result << "free";
125  else if (isLowerLimited())
126  result << "lowerLimited(" << std::scientific << std::setprecision(2) << lowerLimit() << ")";
127  else if (isUpperLimited())
128  result << "upperLimited(" << std::scientific << std::setprecision(2) << upperLimit() << ")";
129  else if (isLimited())
130  result << "limited(" << std::scientific << std::setprecision(2) << lowerLimit() << ","
131  << std::scientific << std::setprecision(2) << upperLimit() << ")";
132 
133  return result.str();
134 }
Defines and implements class AttLimits.
Attributes and limits of a fit parameter, and coupling between these properties.
Definition: AttLimits.h:25
double lowerLimit() const
Definition: AttLimits.cpp:91
std::string toString() const
Definition: AttLimits.cpp:117
static AttLimits lowerLimited(double bound_value)
Definition: AttLimits.cpp:36
void setFixed(bool isFixed)
Definition: AttLimits.cpp:101
RealLimits m_limits
Definition: AttLimits.h:62
static AttLimits limitless()
Definition: AttLimits.cpp:31
double upperLimit() const
Definition: AttLimits.cpp:96
static AttLimits fixed()
Definition: AttLimits.cpp:61
bool isUpperLimited() const
Definition: AttLimits.cpp:76
bool operator==(const AttLimits &other) const
Definition: AttLimits.cpp:107
bool operator!=(const AttLimits &other) const
Definition: AttLimits.cpp:112
bool isFixed() const
Definition: AttLimits.cpp:66
bool isLimitless() const
Definition: AttLimits.cpp:86
bool isLimited() const
Definition: AttLimits.cpp:71
Attributes m_att_fixed
Definition: AttLimits.h:63
static AttLimits upperLimited(double bound_value)
Definition: AttLimits.cpp:51
static AttLimits nonnegative()
Definition: AttLimits.cpp:46
static AttLimits positive()
Definition: AttLimits.cpp:41
static AttLimits limited(double left_bound_value, double right_bound_value)
Definition: AttLimits.cpp:56
bool isLowerLimited() const
Definition: AttLimits.cpp:81
Attributes for a fit parameter. Currently, the only attribute is fixed/free.
Definition: Attributes.h:26
static Attributes fixed()
Creates a fixed value object.
Definition: Attributes.h:30
bool isFree() const
Definition: Attributes.h:35
static Attributes free()
Definition: Attributes.h:31
bool isFixed() const
Definition: Attributes.h:34
void setFixed(bool is_fixed)
Definition: Attributes.h:33
Limits for a real fit parameter.
Definition: RealLimits.h:24
static RealLimits limitless()
Creates an object without bounds (default)
Definition: RealLimits.cpp:139
static RealLimits upperLimited(double bound_value)
Creates an object bounded from the right.
Definition: RealLimits.cpp:129
bool hasUpperLimit() const
if has upper limit
Definition: RealLimits.cpp:66
static RealLimits lowerLimited(double bound_value)
Creates an object bounded from the left.
Definition: RealLimits.cpp:114
bool hasLowerAndUpperLimits() const
if has lower and upper limit
Definition: RealLimits.cpp:88
static RealLimits positive()
Creates an object which can have only positive values (>0., zero is not included)
Definition: RealLimits.cpp:119
double upperLimit() const
Returns upper limit.
Definition: RealLimits.cpp:71
double lowerLimit() const
Returns lower limit.
Definition: RealLimits.cpp:49
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124
void removeLimits()
remove limits
Definition: RealLimits.cpp:99
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:134
bool hasLowerLimit() const
if has lower limit
Definition: RealLimits.cpp:44
std::string scientific(T value, int n=10)
Returns scientific string representing given value of any numeric type.
Definition: StringUtils.h:75