atomicrex  0.1
An advanced atomistic model building tool
FitObject.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 "../util/xml/XMLUtilities.h"
26 
27 namespace atomicrex {
28 
29 class FitJob; // Declared in FitJob.h
30 class DegreeOfFreedom; // Declared in DegreeOfFreedom.h
31 class FitProperty; // Declared in FitProperty.h
32 
42 class FitObject : boost::noncopyable
43 {
44 protected:
45 
47  FitObject() {}
48 
50  FitObject(const FPString& id, FitJob* job, const FPString& tag = FPString()) :
51  _id(id), _job(job), _tag(tag) {}
52 
53 public:
54 
56  virtual ~FitObject() = default;
57 
58  /************************************ Weights **************************************/
59 
61  double relativeWeight() const { return _relativeWeight; }
62 
64  void setRelativeWeight(double weight) { _relativeWeight = weight; }
65 
67  virtual void assignAbsoluteWeights(double absoluteWeight);
68 
69  /*********************************** Properties ***********************************/
70 
72  virtual bool computeProperties(bool isFitting) { return true; }
73 
75  const std::vector<FitProperty*>& properties() const { return _fitPropertiesList; }
76 
78  void listAllProperties(std::vector<FitProperty*>& list) const;
79 
81  FitProperty* propertyById(const FPString& id) const;
82 
83  /************************************** DOFs ***************************************/
84 
86  const std::vector<DegreeOfFreedom*>& DOF() const { return _dofList; }
87 
89  void listAllDOF(std::vector<DegreeOfFreedom*>& list) const;
90 
92  DegreeOfFreedom* DOFById(const FPString& id, const FPString& tag = FPString()) const;
93 
95  virtual void dofValueChanged(DegreeOfFreedom& dof) {}
96 
97  /*************************************** Hierarchy **********************************/
98 
100  const std::vector<FitObject*>& fitObjects() const { return _subobjectList; }
101 
103  void registerSubObject(FitObject* subobject, bool deleteOnShutdown = false);
104 
105  /*************************************** I/O ****************************************/
106 
108  virtual void print(MsgLogger& stream) {
109  if(_parent) {
110  _parent->print(stream);
111  stream << ".";
112  }
113  stream << id();
114  if(tag().empty() == false)
115  stream << "[" << tag() << "]";
116  }
117 
119  virtual void parse(XML::Element element);
120 
121  /************************************* Attributes ***********************************/
122 
124  bool fitEnabled() const { return _fitEnabled; }
125 
127  void setFitEnabled(bool enable) { _fitEnabled = enable; }
128 
131  bool outputEnabled() const { return _outputEnabled; }
132 
135  void setOutputEnabled(bool enable) { _outputEnabled = enable; }
136 
138  const FPString& id() const { return _id; }
139 
141  void setId(const FPString& id) { _id = id; }
142 
144  const FPString& tag() const { return _tag; }
145 
147  void setTag(const FPString& tag) { _tag = tag; }
148 
150  FitJob* job() const { return _job; }
151 
153  FitObject* parent() const { return _parent; }
154 
155 protected:
156 
158  void registerProperty(FitProperty* prop, bool deleteOnShutdown = false);
159 
161  void registerDOF(DegreeOfFreedom* dof);
162 
163 protected:
164 
166  bool _fitEnabled = true;
167 
170  bool _outputEnabled = true;
171 
173  FitJob* _job = nullptr;
174 
177 
179  double _relativeWeight = 1.0;
180 
181 private:
182 
184  FPString _tag;
185 
187  std::vector<DegreeOfFreedom*> _dofList;
188 
190  std::vector<FitProperty*> _fitPropertiesList;
191 
193  std::vector<FitObject*> _subobjectList;
194 
197  std::vector<std::unique_ptr<FitObject>> _ownedObjects;
198 
200  FitObject* _parent = nullptr;
201 
202 };
203 
204 } // End of namespace
FitObject(const FPString &id, FitJob *job, const FPString &tag=FPString())
Constructor.
Definition: FitObject.h:50
const std::vector< FitObject * > & fitObjects() const
Returns the list of FitObjects which are part of this group.
Definition: FitObject.h:100
Definition: Logger.h:37
void listAllProperties(std::vector< FitProperty *> &list) const
Builds a list of properties of this object and all its sub-objects.
Definition: FitObject.cpp:93
FitObject * parent() const
Returns the parent of this object in the hierarchy.
Definition: FitObject.h:153
bool fitEnabled() const
Returns whether this object and it&#39;s children are included in the fit.
Definition: FitObject.h:124
void setFitEnabled(bool enable)
Sets whether this object and it&#39;s children are included in the fit.
Definition: FitObject.h:127
virtual void parse(XML::Element element)
Parses the base parameters, common to structures, groups, and potentials, from the XML element in the...
Definition: FitObject.cpp:149
bool _outputEnabled
Definition: FitObject.h:170
FitObject()
Default Constructor.
Definition: FitObject.h:47
FitJob * _job
Pointer to the job this object belongs to.
Definition: FitObject.h:173
void setOutputEnabled(bool enable)
Definition: FitObject.h:135
void registerSubObject(FitObject *subobject, bool deleteOnShutdown=false)
Registers a sub-object.
Definition: FitObject.cpp:57
Definition: FitProperty.h:38
const std::vector< DegreeOfFreedom * > & DOF() const
Returns a list of degrees of freedom of this object.
Definition: FitObject.h:86
virtual void print(MsgLogger &stream)
Outputs the name of the object.
Definition: FitObject.h:108
const FPString & tag() const
Returns the assigned tag string.
Definition: FitObject.h:144
double relativeWeight() const
Returns the relative fit weight assigned to this object.
Definition: FitObject.h:61
virtual void assignAbsoluteWeights(double absoluteWeight)
Recursively assigns absolute weights to the properties of this object and its sub-objects.
Definition: FitObject.cpp:114
FPString _id
The identifier string of this object instance.
Definition: FitObject.h:176
virtual void dofValueChanged(DegreeOfFreedom &dof)
This callback function is called by the DOFs of this fit object each time when their values changes...
Definition: FitObject.h:95
void registerProperty(FitProperty *prop, bool deleteOnShutdown=false)
Registers a property of this object.
Definition: FitObject.cpp:47
FitProperty * propertyById(const FPString &id) const
Returns the property with the given ID.
Definition: FitObject.cpp:103
void listAllDOF(std::vector< DegreeOfFreedom *> &list) const
Builds a list of degrees of freedom of this object and all its sub-objects.
Definition: FitObject.cpp:72
bool outputEnabled() const
Definition: FitObject.h:131
DegreeOfFreedom * DOFById(const FPString &id, const FPString &tag=FPString()) const
Returns the degree of freedom with the given ID (and tag).
Definition: FitObject.cpp:82
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
void registerDOF(DegreeOfFreedom *dof)
Registers a DOF of this object.
Definition: FitObject.cpp:36
const std::vector< FitProperty * > & properties() const
Returns a list of fitting properties of this object.
Definition: FitObject.h:75
const FPString & id() const
Returns the identifier of this object instance.
Definition: FitObject.h:138
std::string FPString
The default string type used throughout the code:
Definition: Atomicrex.h:70
Definition: XMLUtilities.h:69
virtual ~FitObject()=default
Virtual destructor.
Definition: FitObject.h:42
Definition: FitJob.h:37
FitJob * job() const
Returns a pointer to the job to which this object belongs.
Definition: FitObject.h:150
void setRelativeWeight(double weight)
Assigns a relative fit weight to this object.
Definition: FitObject.h:64
Base class for all degrees of freedom a potential or a structure may have.
Definition: DegreeOfFreedom.h:46
void setId(const FPString &id)
Sets the main identification tag.
Definition: FitObject.h:141
void setTag(const FPString &tag)
Sets the complementary identification tag.
Definition: FitObject.h:147
double _relativeWeight
The relative fit weight assigned to this object.
Definition: FitObject.h:179
virtual bool computeProperties(bool isFitting)
Computes all enabled properties of the object.
Definition: FitObject.h:72
bool _fitEnabled
Controls whether this object and it&#39;s children are included in the fit.
Definition: FitObject.h:166