24 #include "../Atomicrex.h" 25 #include "../minimizers/Minimizer.h" 26 #include "../util/xml/XMLUtilities.h" 31 class AtomicStructure;
56 _relax(false), _object(nullptr), _resetBeforeRelax(true) {}
80 bool relax()
const {
return _relax; }
83 void setRelax(
bool enable) { _relax = enable; }
107 virtual void getBoundConstraints(std::vector<Minimizer::BoundConstraints>::iterator& types, std::vector<double>::iterator& lowerBounds, std::vector<double>::iterator& upperBounds) {
108 std::fill(types, types +
numScalars(), Minimizer::NO_BOUNDS);
158 bool _resetBeforeRelax;
175 double minValue = -std::numeric_limits<double>::infinity(),
176 double maxValue = std::numeric_limits<double>::infinity()) :
DegreeOfFreedom(
id),
177 _value(defaultValue),
178 _initialValue(defaultValue),
181 _masterDOF(nullptr) {}
184 operator double()
const {
return _value; }
214 virtual void importValue(
const double*& src)
override;
223 bool hasLowerBound()
const {
return _minValue != -std::numeric_limits<double>::infinity(); }
232 bool hasUpperBound()
const {
return _maxValue != std::numeric_limits<double>::infinity(); }
242 if(hasLowerBound() && _value < lowerBound())
return false;
243 if(hasUpperBound() && _value > upperBound())
return false;
248 virtual void getBoundConstraints(std::vector<Minimizer::BoundConstraints>::iterator& types, std::vector<double>::iterator& lowerBounds, std::vector<double>::iterator& upperBounds)
override {
249 if(hasLowerBound()) {
251 *types++ = Minimizer::BOTH_BOUNDS;
253 *types++ = Minimizer::LOWER_BOUNDS;
255 else if(hasUpperBound())
256 *types++ = Minimizer::UPPER_BOUNDS;
258 *types++ = Minimizer::NO_BOUNDS;
259 *lowerBounds++ = _minValue;
260 *upperBounds++ = _maxValue;
293 double _initialValue;
305 std::vector<std::function<void(ScalarDOF&)>> _changeListeners;
void setResetBeforeRelax(bool enableReset)
Definition: DegreeOfFreedom.h:123
double upperBound() const
Returns the upper bound if this DOF has a constraint applied to it.
Definition: DegreeOfFreedom.h:229
void setId(const FPString &id)
Sets the identifier of this degree of freedom.
Definition: DegreeOfFreedom.h:65
virtual bool satisfiesBoundConstraints() const
Returns whether this DOF satisfies the bound constraints applied to it.
Definition: DegreeOfFreedom.h:104
double getValue()
Returns the current value of the DoF.
Definition: DegreeOfFreedom.h:187
virtual void reset()
Resets the value of the DOF to what was specified in the job file.
Definition: DegreeOfFreedom.h:126
virtual XML::OElement generateXMLFitDefinition() const
Produces an XML representation of the DOF's fit settings.
Definition: DegreeOfFreedom.cpp:158
virtual int numScalars() override
Returns the number of scalar degrees of freedom this DOF is composed of.
Definition: DegreeOfFreedom.h:208
void setFitEnabled(bool enable)
Sets whether this DOF should be varied during the fitting process.
Definition: DegreeOfFreedom.h:77
const FPString & id() const
Return the identifier of this degree of freedom.
Definition: DegreeOfFreedom.h:62
virtual bool hasBoundConstraints() const override
Returns whether this DOF has any bound constraints applied to it.
Definition: DegreeOfFreedom.h:238
virtual void print(MsgLogger &stream)
Outputs the current value of the DOF.
Definition: DegreeOfFreedom.h:115
virtual void getBoundConstraints(std::vector< Minimizer::BoundConstraints >::iterator &types, std::vector< double >::iterator &lowerBounds, std::vector< double >::iterator &upperBounds) override
Lets the DOF write its constraints information to the given linear arrays.
Definition: DegreeOfFreedom.h:248
virtual void parseRelax(XML::Element relaxElement)
Parse the contents of the <relax> element in the job file.
Definition: DegreeOfFreedom.cpp:139
void setLowerBound(double lowerBound)
Sets a lower bound constraint on this DOF.
Definition: DegreeOfFreedom.h:226
virtual void exportValue(double *&dst)=0
Lets the DOF export its current value(s) into the given value array.
bool hasUpperBound() const
Returns whether this DOF has an upper bound constraint applied to it.
Definition: DegreeOfFreedom.h:232
virtual bool hasBoundConstraints() const
Returns whether this DOF has any bound constraints applied to it.
Definition: DegreeOfFreedom.h:101
virtual bool satisfiesBoundConstraints() const override
Returns whether this DOF satisfies the bound constraints applied to it.
Definition: DegreeOfFreedom.h:241
virtual int numScalars()=0
Returns the number of scalar degrees of freedom this DOF is composed of.
void setInitialValue(double value)
Sets the initial value of this DOF. This also changes the current value to the same value...
Definition: DegreeOfFreedom.h:199
virtual void getBoundConstraints(std::vector< Minimizer::BoundConstraints >::iterator &types, std::vector< double >::iterator &lowerBounds, std::vector< double >::iterator &upperBounds)
Lets the DOF write its constraints information to the given linear arrays.
Definition: DegreeOfFreedom.h:107
virtual XML::OElement generateXMLValueDefinition() const
Produces an XML representation of the DOF's current value.
Definition: DegreeOfFreedom.cpp:150
ScalarDOF(const FPString &id=FPString(), double defaultValue=0, double minValue=-std::numeric_limits< double >::infinity(), double maxValue=std::numeric_limits< double >::infinity())
Constructor.
Definition: DegreeOfFreedom.h:174
bool relax() const
Returns whether this DOF should be relaxed during each iteration when fitting.
Definition: DegreeOfFreedom.h:80
virtual void parseFit(XML::Element fitElement)
Parse the contents of the <fit> element in the job file.
Definition: DegreeOfFreedom.cpp:127
void setValue(double value)
Assigns a new value to the DOF.
Definition: DegreeOfFreedom.h:193
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
A simple scalar degree of freedom that consists of a single value.
Definition: DegreeOfFreedom.h:169
DegreeOfFreedom(const FPString &id=FPString(), const FPString &tag=FPString())
Constructor.
Definition: DegreeOfFreedom.h:55
virtual ~DegreeOfFreedom()
Virtual destructor.
Definition: DegreeOfFreedom.h:59
bool hasLowerBound() const
Returns whether this DOF has a lower bound constraint applied to it.
Definition: DegreeOfFreedom.h:223
virtual void importValue(const double *&src)=0
Lets the DOF import its value(s) from the given value array.
void setTag(const FPString &tag)
Sets the tag on this DOF.
Definition: DegreeOfFreedom.h:71
std::string FPString
The default string type used throughout the code:
Definition: Atomicrex.h:70
Definition: XMLUtilities.h:226
Definition: XMLUtilities.h:69
double initialValue() const
Returns the initial value of this DOF.
Definition: DegreeOfFreedom.h:202
Definition: FitObject.h:42
double * getValuePointer()
Returns a pointer to the internal storage field of this DoF.
Definition: DegreeOfFreedom.h:196
FitObject * object() const
Returns a pointer to the potential or structure to which this DOF belongs.
Definition: DegreeOfFreedom.h:86
double lowerBound() const
Returns the lower bound if this DOF has a constraint applied to it.
Definition: DegreeOfFreedom.h:220
Base class for all degrees of freedom a potential or a structure may have.
Definition: DegreeOfFreedom.h:46
void setUpperBound(double upperBound)
Sets an upper bound constraint on this DOF.
Definition: DegreeOfFreedom.h:235
const FPString & tag() const
Returns the tag on this DOF.
Definition: DegreeOfFreedom.h:68
virtual void reset() override
Resets the value of the DOF to what was given in the job file.
Definition: DegreeOfFreedom.h:205
bool resetBeforeRelax() const
Definition: DegreeOfFreedom.h:119
bool fitEnabled() const
Returns whether this DOF should be varied during the fitting process.
Definition: DegreeOfFreedom.h:74
void setRelax(bool enable)
Sets whether this DOF is being relaxed during each iteration when fitting.
Definition: DegreeOfFreedom.h:83