CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Reference.hh
Go to the documentation of this file.
1 #ifndef CASM_Reference
2 #define CASM_Reference
3 
4 #include <functional>
5 #include <map>
6 #include <memory>
7 #include <string>
8 
11 #include "casm/global/eigen.hh"
13 
14 namespace CASM {
15 
16 class Configuration;
17 
19 
28 class ConstantReference : public Reference {
29  public:
30  static const std::string Name;
31  static const std::string Desc;
32 
33  explicit ConstantReference(double _value = 0.0)
34  : Reference(Name, Desc), m_value(_value) {}
35 
37  double value() const { return m_value; }
38 
40  double evaluate(const Configuration &config) const override {
41  return value();
42  }
43 
44  std::unique_ptr<ConstantReference> clone() const {
45  return notstd::make_unique<ConstantReference>(*this->_clone());
46  }
47 
48  private:
50  virtual ConstantReference *_clone() const override {
51  return new ConstantReference(*this);
52  }
53 
54  double m_value;
55 };
56 
69  public:
70  typedef std::map<std::string, Eigen::VectorXd> SpecializedRef;
71  typedef std::function<Eigen::VectorXd(const Configuration &)> InputFunction;
72 
94  HyperPlaneReferenceBase(std::string _name, std::string _desc,
95  const Eigen::VectorXd &_global_ref,
96  InputFunction _input,
97  SpecializedRef _supercell_ref = SpecializedRef(),
98  SpecializedRef _config_ref = SpecializedRef())
99  : Reference(_name, _desc),
100  m_input(_input),
101  m_config_ref(_config_ref),
102  m_supercell_ref(_supercell_ref),
103  m_global_ref(_global_ref) {}
104 
106 
108  std::unique_ptr<HyperPlaneReferenceBase> clone() const {
109  return notstd::make_unique<HyperPlaneReferenceBase>(*this->_clone());
110  }
111 
114  const Eigen::VectorXd &global() const { return m_global_ref; }
115 
119  const std::map<std::string, Eigen::VectorXd> &supercell() const {
120  return m_supercell_ref;
121  }
122 
126  const std::map<std::string, Eigen::VectorXd> &config() const {
127  return m_config_ref;
128  }
129 
132  std::function<Eigen::VectorXd(const Configuration &)> input() const {
133  return m_input;
134  }
135 
138  return m_input(config);
139  }
140 
146 
153  double evaluate(const Configuration &config) const override {
154  return hyperplane(config).dot(input(config));
155  }
156 
157  protected:
161 
165  std::map<std::string, Eigen::VectorXd> &supercell() {
166  return m_supercell_ref;
167  }
168 
172  std::map<std::string, Eigen::VectorXd> &config() { return m_config_ref; }
173 
174  private:
176  virtual HyperPlaneReferenceBase *_clone() const override {
177  return new HyperPlaneReferenceBase(*this);
178  }
179 
181 
182  std::map<std::string, Eigen::VectorXd> m_config_ref;
183 
184  std::map<std::string, Eigen::VectorXd> m_supercell_ref;
185 
187 };
188 
199  public:
200  static const std::string Name;
201  static const std::string Desc;
202 
225  SpecializedRef _supercell_ref = SpecializedRef(),
226  SpecializedRef _config_ref = SpecializedRef())
227  : HyperPlaneReferenceBase(Name, Desc, _global_ref, _input, _config_ref,
228  _supercell_ref) {}
229 
231  std::unique_ptr<HyperPlaneReference> clone() const {
232  return notstd::make_unique<HyperPlaneReference>(*this->_clone());
233  }
234 
235  // --- Prevent hiding of const accessors ---
236 
240 
241  // --- Make protected inherited members public ---
242 
246 
250  std::map<std::string, Eigen::VectorXd> &supercell() {
252  }
253 
257  std::map<std::string, Eigen::VectorXd> &config() {
259  }
260 
261  private:
263  HyperPlaneReference *_clone() const override {
264  return new HyperPlaneReference(*this);
265  }
266 };
267 
270 } // namespace CASM
271 
272 #endif
Base class for creating scalar DatumFormatter.
Maps all Configurations to the same value.
Definition: Reference.hh:28
static const std::string Desc
Definition: Reference.hh:31
std::unique_ptr< ConstantReference > clone() const
Definition: Reference.hh:44
double evaluate(const Configuration &config) const override
Returns the same constant value for all Configuration.
Definition: Reference.hh:40
ConstantReference(double _value=0.0)
Definition: Reference.hh:33
double value() const
Return the constant value used for all Configuration.
Definition: Reference.hh:37
virtual ConstantReference * _clone() const override
Clone.
Definition: Reference.hh:50
static const std::string Name
Definition: Reference.hh:30
Maps a Configuration to a scalar value via a hyperplane.
Definition: Reference.hh:68
Eigen::VectorXd input(const Configuration &config) const
Return the 'input' coordinates that a Configuration is mapped to.
Definition: Reference.hh:137
virtual HyperPlaneReferenceBase * _clone() const override
Clone.
Definition: Reference.hh:176
std::map< std::string, Eigen::VectorXd > & supercell()
Access a map of scelname to reference for Supercell specialized references.
Definition: Reference.hh:165
std::map< std::string, Eigen::VectorXd > & config()
Access a map of configname to reference for Configuration specialized references.
Definition: Reference.hh:172
Eigen::VectorXd m_global_ref
Definition: Reference.hh:186
std::map< std::string, Eigen::VectorXd > SpecializedRef
Definition: Reference.hh:70
HyperPlaneReferenceBase(std::string _name, std::string _desc, const Eigen::VectorXd &_global_ref, InputFunction _input, SpecializedRef _supercell_ref=SpecializedRef(), SpecializedRef _config_ref=SpecializedRef())
Constructor.
Definition: Reference.hh:94
std::unique_ptr< HyperPlaneReferenceBase > clone() const
Clone.
Definition: Reference.hh:108
Eigen::VectorXd hyperplane(const Configuration &config) const
Return the reference hyperplane used for a particular configuration.
Definition: Reference.cc:20
std::map< std::string, Eigen::VectorXd > m_config_ref
Definition: Reference.hh:182
double evaluate(const Configuration &config) const override
Return the reference for a particular configuration.
Definition: Reference.hh:153
const std::map< std::string, Eigen::VectorXd > & supercell() const
const Access a map of scelname to reference for Supercell specialized references
Definition: Reference.hh:119
std::function< Eigen::VectorXd(const Configuration &)> InputFunction
Definition: Reference.hh:71
std::map< std::string, Eigen::VectorXd > m_supercell_ref
Definition: Reference.hh:184
Eigen::VectorXd & global()
Access the global reference.
Definition: Reference.hh:160
const Eigen::VectorXd & global() const
const Access the global reference
Definition: Reference.hh:114
const std::map< std::string, Eigen::VectorXd > & config() const
const Access a map of configname to reference for Configuration specialized references
Definition: Reference.hh:126
std::function< Eigen::VectorXd(const Configuration &)> input() const
Return the 'input' function that maps a Configuration to coordinates.
Definition: Reference.hh:132
Maps a Configuration to a scalar value via a hyperplane.
Definition: Reference.hh:198
std::map< std::string, Eigen::VectorXd > & config()
Access a map of configname to reference for Configuration specialized references.
Definition: Reference.hh:257
Eigen::VectorXd & global()
Access the global reference.
Definition: Reference.hh:245
static const std::string Name
Definition: Reference.hh:200
HyperPlaneReference * _clone() const override
Clone.
Definition: Reference.hh:263
std::map< std::string, Eigen::VectorXd > & supercell()
Access a map of scelname to reference for Supercell specialized references.
Definition: Reference.hh:250
static const std::string Desc
Definition: Reference.hh:201
HyperPlaneReference(const Eigen::VectorXd &_global_ref, InputFunction _input, SpecializedRef _supercell_ref=SpecializedRef(), SpecializedRef _config_ref=SpecializedRef())
Constructor.
Definition: Reference.hh:224
std::unique_ptr< HyperPlaneReference > clone() const
Clone.
Definition: Reference.hh:231
ConfigIO::GenericConfigFormatter< jsonParser > config()
Definition: ConfigIO.cc:777
Main CASM namespace.
Definition: APICommand.hh:8
ScalarAttribute< Configuration > Reference
Definition: Reference.hh:16
Eigen::VectorXd VectorXd