atomicrex  0.1
An advanced atomistic model building tool
FitProperty.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include "../Atomicrex.h"
25 #include "../job/FitObject.h"
26 #include "../util/xml/XMLUtilities.h"
27 
28 namespace atomicrex {
29 
30 class ScalarDOF;
31 class FitJob; // defined in FitJob.h
32 
38 class FitProperty : public FitObject
39 {
40 public:
41 
43  enum ResidualNorm {
48  };
49 
50 public:
51 
54 
56  FitProperty(const FPString& id, const FPString& units, FitJob* job) : FitObject(id, job) {
57  setFitEnabled(false);
58  setOutputEnabled(false);
59  initialize(id, units, job);
60  }
61 
63  void initialize(const FPString& id, const FPString& units, FitJob* job);
64 
66  virtual double residual(ResidualNorm norm) const = 0;
67 
69  bool shouldCompute(bool isFitting) const { return (isFitting && _fitEnabled) || (!isFitting && _outputEnabled); }
70 
72  virtual void print(MsgLogger& stream) override {}
73 
75  virtual void compute() {}
76 
79 
81  double absoluteWeight() const { return _absoluteWeight; }
82 
84  double tolerance() const { return _tolerance; }
85 
87  void setTolerance(double tolerance) { _tolerance = tolerance; }
88 
91 
93  const FPString& units() const { return _units; }
94 
95 public:
96 
98  virtual void parse(XML::Element propertyElement) override;
99 
100 protected:
101 
103  double _absoluteWeight = 1.0;
104 
105 private:
106 
108  double _tolerance = 1.0;
109 
110 protected:
111 
114 
117 
118  friend class FitObject;
119 };
120 
127 {
128 public:
129 
131  ScalarFitProperty() : _computedValue(0), _targetValue(0) {}
132 
134  ScalarFitProperty(const FPString& id, const FPString& units, FitJob* job) : FitProperty(id, units, job), _computedValue(0), _targetValue(0) {}
135 
137  void initialize(const FPString& id, const FPString& units, FitJob* job) { FitProperty::initialize(id, units, job); }
138 
140  virtual double residual(ResidualNorm norm) const override;
141 
143  operator double() const { return _computedValue; }
144 
146  double computedValue() const { return _computedValue;}
148  ScalarFitProperty& operator=(double value) { _computedValue = value; return *this; }
149 
151  virtual void print(MsgLogger& stream) override;
152 
153 public:
154 
156  virtual void parse(XML::Element propertyElement) override;
157 
159  double targetValue() { return _targetValue; }
160 
162  void setTargetValue(double targetValue ) { _targetValue = targetValue;}
163 
164 
165 protected:
166 
169 
171  double _targetValue;
172 };
173 
174 
185 {
186 public:
187 
190 
192  ScalarDOF& dof() const { return _dof; }
193 
195  virtual void compute() override;
196 
198  virtual void print(MsgLogger& stream) override;
199 
200 public:
201 
203  virtual void parse(XML::Element propertyElement) override;
204 
205 private:
206 
208  ScalarDOF& _dof;
209 };
210 
211 } // End of namespace
Definition: Logger.h:37
FitProperty()
Default constructor.
Definition: FitProperty.h:53
ScalarFitProperty(const FPString &id, const FPString &units, FitJob *job)
Initialization constructor.
Definition: FitProperty.h:134
double absoluteWeight() const
Returns the absolute fit weight assigned to this object.
Definition: FitProperty.h:81
Indicates that the norm selected by the user should be used.
Definition: FitProperty.h:44
double _absoluteWeight
The weight factor which is applied to the residual.
Definition: FitProperty.h:103
void setFitEnabled(bool enable)
Sets whether this object and it&#39;s children are included in the fit.
Definition: FitObject.h:127
FitProperty(const FPString &id, const FPString &units, FitJob *job)
Initialization constructor.
Definition: FitProperty.h:56
bool _outputEnabled
Definition: FitObject.h:170
ResidualNorm residualNorm() const
Returns how residual contributions are calculated by this property.
Definition: FitProperty.h:90
double _targetValue
The target value for the property.
Definition: FitProperty.h:171
void setTargetValue(double targetValue)
Sets target value.
Definition: FitProperty.h:162
virtual void parse(XML::Element propertyElement) override
Parse the contents of the <property> element in the job file.
Definition: FitProperty.cpp:126
FPString _units
The units of this property.
Definition: FitProperty.h:116
void setOutputEnabled(bool enable)
Definition: FitObject.h:135
double _computedValue
The computed value of the property.
Definition: FitProperty.h:168
ScalarFitProperty & operator=(double value)
Assigns a new value to the property.
Definition: FitProperty.h:148
Definition: FitProperty.h:38
void assignAbsoluteWeights(double absoluteWeight) override
Recursively assigns absolute weights to the properties.
Definition: FitProperty.h:78
Definition: FitProperty.h:184
void setTolerance(double tolerance)
Sets the tolerance assigned to this fit property.
Definition: FitProperty.h:87
void initialize(const FPString &id, const FPString &units, FitJob *job)
Initializes the property object. This method must be called if the default constructor has been used...
Definition: FitProperty.h:137
double computedValue() const
Getter for _computedValue since double() operator was hard to interface.
Definition: FitProperty.h:146
ResidualNorm _residualNorm
Specifies how residual contributions are calculated.
Definition: FitProperty.h:113
virtual void print(MsgLogger &stream) override
Outputs the current value of the property.
Definition: FitProperty.h:72
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
virtual void compute()
Lets the property object compute the current value of the property.
Definition: FitProperty.h:75
std::string FPString
The default string type used throughout the code:
Definition: Atomicrex.h:70
ScalarDOF & dof() const
Returns the degree of freedom to which this property is coupled.
Definition: FitProperty.h:192
void initialize(const FPString &id, const FPString &units, FitJob *job)
Initializes the property object. This method must be called if the default constructor was used to cr...
Definition: FitProperty.cpp:35
Definition: XMLUtilities.h:69
Definition: FitObject.h:42
L2 norm, use square of difference from target value divided by target value.
Definition: FitProperty.h:46
Definition: FitJob.h:37
bool shouldCompute(bool isFitting) const
Returns whether this property should be computed because it is included in the fit and/or in the outp...
Definition: FitProperty.h:69
FitJob * job() const
Returns a pointer to the job to which this object belongs.
Definition: FitObject.h:150
L2 norm, use squared difference from target value.
Definition: FitProperty.h:45
const FPString & units() const
Returns the units of this property.
Definition: FitProperty.h:93
double targetValue()
Returns target value (scalar)
Definition: FitProperty.h:159
virtual double residual(ResidualNorm norm) const =0
Returns the residual of this property used for fitting.
Definition: FitProperty.h:126
ResidualNorm
Specifies how residual contributions are calculated.
Definition: FitProperty.h:43
ScalarFitProperty()
Default constructor.
Definition: FitProperty.h:131
double tolerance() const
Returns the tolerance assigned to this fit property.
Definition: FitProperty.h:84
L1 norm, absolute value of difference from target value.
Definition: FitProperty.h:47
bool _fitEnabled
Controls whether this object and it&#39;s children are included in the fit.
Definition: FitObject.h:166