CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Clexulator.cc
Go to the documentation of this file.
2 
4 #include "casm/casm_io/Log.hh"
7 
8 namespace CASM {
9 
32 Clexulator::Clexulator(std::string name, fs::path dirpath,
33  PrimNeighborList &nlist, std::string compile_options,
34  std::string so_options)
35  : m_name(name) {
36  // Construct the RuntimeLibrary that will store the loaded clexulator library
37  try {
39  (dirpath / name).string(), compile_options, so_options,
40  "compile time depends on how many basis functions are included");
41  } catch (std::exception &e) {
42  log() << "Clexulator construction failed: could not construct runtime "
43  "library."
44  << std::endl;
45  throw;
46  }
47 
48  // Get the Clexulator factory function
49  std::function<Clexulator_impl::Base *(void)> factory;
50  factory = m_lib->get_function<Clexulator_impl::Base *(void)>("make_" + name);
51 
52  // Use the factory to construct the clexulator and store it in m_clex
53  m_clex.reset(factory());
54 
55  // Check nlist has the right weight_matrix
56  if (nlist.weight_matrix() != m_clex->weight_matrix()) {
57  std::cerr << "Error in Clexulator constructor: weight matrix of neighbor "
58  "list does not match the weight matrix used to print the "
59  "clexulator."
60  << std::endl;
61  std::cerr << "nlist weight matrix: \n"
62  << nlist.weight_matrix() << std::endl;
63  std::cerr << "clexulator weight matrix: \n"
64  << m_clex->weight_matrix() << std::endl;
65  throw std::runtime_error(
66  "Error in Clexulator constructor: weight matrix of neighbor list does "
67  "not match the weight matrix used to print the clexulator. Try 'casm "
68  "bset -uf'.");
69  }
70 
71  // Expand the given neighbor list as necessary
72  nlist.expand(neighborhood().begin(), neighborhood().end());
73 }
74 
76 Clexulator::Clexulator(const Clexulator &B) : m_name(B.name()), m_lib(B.m_lib) {
77  if (B.m_clex != nullptr) {
78  m_clex = B.m_clex->clone();
79  }
80 }
81 
84 
86  // ensure Clexulator is deleted before library
87  m_clex.reset();
88 }
89 
92  swap(*this, B);
93  return *this;
94 }
95 
98  std::string const &_param_name) const {
99  return m_clex->param_key(_param_name);
100 }
101 
105  ClexParamKey const _param_key,
106  std::vector<std::function<double(ConfigDoF const &)> > const &_basis_set) {
107  m_clex->set_evaluation(_param_key, _basis_set);
108 }
109 
113  ClexParamKey const _param_key,
114  std::vector<std::function<double(std::vector<double> const &)> > const
115  &_basis_set) {
116  m_clex->set_evaluation(_param_key, _basis_set);
117 }
118 
124  std::string _eval_type) {
125  m_clex->set_evaluation(_param_key, _eval_type);
126 }
127 
131 std::string Clexulator::check_evaluation(ClexParamKey const _param_key) const {
132  return m_clex->check_evaluation(_param_key);
133 }
134 
135 namespace Clexulator_impl {
136 
137 Base::Base(size_type _nlist_size, size_type _corr_size, size_type _n_point_corr)
138  : m_nlist_size(_nlist_size),
139  m_corr_size(_corr_size),
140  m_n_point_corr(_n_point_corr),
141  m_config_ptr(nullptr) {}
142 
144 
146 std::unique_ptr<Base> Base::clone() const {
147  return std::unique_ptr<Base>(_clone());
148 }
149 
153  ClexParamKey const &_param_key,
154  std::vector<std::function<double(ConfigDoF const &)> > const &_basis_set) {}
155 
159  ClexParamKey const &_param_key,
160  std::vector<std::function<double(std::vector<double> const &)> > const
161  &_basis_set) {}
162 
165 // which can be at least either "READ" (i.e., read from ClexParamPack) or
166 // "DEFAULT" (i.e., the Clexulator's default implementation)
167 void Base::set_evaluation(ClexParamKey const &_param_key,
168  std::string const &_eval_type) {}
169 
173 std::string Base::check_evaluation(ClexParamKey const &_param_key) const {
174  return "";
175 }
176 
178 ClexParamKey const &Base::param_key(std::string const &_param_name) const {
179  return param_pack().key(_param_name);
180 }
181 
182 } // namespace Clexulator_impl
183 
184 } // namespace CASM
Key for indexing clexulator parameters Contains pointer to implementation of the Key.
ClexParamKey const & key(std::string const &_name) const
Obtain key for managed data block by name.
Abstract base class for cluster expansion correlation calculations.
Definition: Clexulator.hh:25
ClexParamKey const & param_key(std::string const &_param_name) const
Obtain ClexParamKey for a particular parameter.
Definition: Clexulator.cc:178
Base(size_type _nlist_size, size_type _corr_size, size_type _n_point_corr)
Definition: Clexulator.cc:137
std::string check_evaluation(ClexParamKey const &_param_key) const
Check evaluation mode of parameters specified by.
Definition: Clexulator.cc:173
std::unique_ptr< Base > clone() const
Clone the Clexulator.
Definition: Clexulator.cc:146
virtual ClexParamPack const & param_pack() const =0
Obtain const reference to abstract ClexParamPack object.
virtual Base * _clone() const =0
Clone the Clexulator.
void set_evaluation(ClexParamKey const &_param_key, std::vector< std::function< double(ConfigDoF const &)> > const &_basis_set)
Alter evaluation of parameters specified by.
Definition: Clexulator.cc:152
Evaluates correlations.
Definition: Clexulator.hh:440
Clexulator & operator=(Clexulator B)
Assignment operator.
Definition: Clexulator.cc:91
ClexParamKey const & param_key(std::string const &_param_name) const
Obtain ClexParamKey for a particular parameter.
Definition: Clexulator.cc:97
void set_evaluation(ClexParamKey const _param_key, std::vector< std::function< double(ConfigDoF const &)> > const &_basis_set)
Alter evaluation of parameters specified by.
Definition: Clexulator.cc:104
friend void swap(Clexulator &first, Clexulator &second)
Swap.
Definition: Clexulator.hh:462
std::unique_ptr< Clexulator_impl::Base > m_clex
Definition: Clexulator.hh:730
std::string name() const
Name.
Definition: Clexulator.hh:474
std::string check_evaluation(ClexParamKey const _param_key) const
Check evaluation mode of parameters specified by.
Definition: Clexulator.cc:131
const std::set< UnitCell > & neighborhood() const
The UnitCellCoord involved in calculating the basis functions, relative origin UnitCell.
Definition: Clexulator.hh:523
std::shared_ptr< RuntimeLibrary > m_lib
Definition: Clexulator.hh:731
The PrimNeighborList gives the coordinates of UnitCell that are neighbors of the origin UnitCell.
Definition: NeighborList.hh:39
void expand(UnitCell const &uc)
Expand the neighbor list to include the given UnitCellCoord.
Definition: NeighborList.cc:23
Matrix3Type weight_matrix() const
Return the weighting matrix W used to define the canonical order.
Definition: NeighborList.cc:13
Main CASM namespace.
Definition: APICommand.hh:8
std::shared_ptr< RuntimeLibrary > log_make_shared_runtime_lib(std::string filename_base, std::string compile_options, std::string so_options, std::string compile_msg)
Make shared_ptr<RuntimeLibrary>, logging progress and errors.
Log & log()
Definition: Log.hh:424
GenericDatumFormatter< std::string, DataObject > name()