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