CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DiffClexParamPack.hh
Go to the documentation of this file.
1 #ifndef DIFFCLEXPARAMPACK_HH
2 #define DIFFCLEXPARAMPACK_HH
3 #include <cstddef>
4 #include <iostream>
5 #include <sstream>
6 #include <string>
7 
12 #include "casm/external/fadbad/badiff.h"
13 #include "casm/external/fadbad/fadiff.h"
15 
16 namespace CASM {
20 namespace DiffClexParamPack_impl {
21 enum class EvalMode {
22  DEFAULT,
23  READ,
24  DIFF,
25  DYNAM
26 
27 };
28 
29 using DiffScalar = fadbad::B<fadbad::F<double> >;
30 
31 } // namespace DiffClexParamPack_impl
32 
33 // DiffClexParamPack provides an interface for reading and writing an automaitic
34 // differentiation scalar type, which is implemented using the FADBAD++ library.
35 // By utilizing the autodiff scalar type as the input and output of algebraic
36 // expressions (as in the clexulator), first- and higher-order derivatives of
37 // the expressions can also be calculated simply and efficiently.
38 // DiffClexParamPack stores 'standalone' values, which comprise the independent
39 // variables utilized by the clexulator and the dependent function returnvalues,
40 // but it can also be queried for 'derived' values, which are obtained by
41 // performing additional operations on the standalone values. The standalone and
42 // derived values are both queried in an identical fashion, by passing a
43 // 'ClexParamKey' to the DiffClexParamPack corresponding to the quantity of
44 // interest.
45 class DiffClexParamPack;
46 
47 // Container struct for holding a particular standalone value
49 
50 // Abstract base class for all keys that interact with DiffClexParamPack
51 class DiffClexParamKey;
52 
53 // Key implementation for standalone values
55 
56 // Key implementation for derived values corresponding to first derivatives
58 
59 // Key implementation for derived values corresponding to second derivatives
61 
79  public:
81 
87  DiffClexParamKey(std::string const &_name, bool _standalone, size_type _ind,
88  std::vector<Index> const &_offset = {},
89  std::vector<Index> const &_stride = {})
90  : ClexParamPack_impl::BaseKey(_name, _standalone, _offset, _stride),
91  m_index(_ind) {
92  // std::cout << "Constructed key " << _name << " at index " << m_index << "
93  // with offset " << _offset << " and stride " << _stride << std::endl;
94  }
95 
96  DiffClexParamKey() : DiffClexParamKey("", -1, false) {}
97 
99  virtual ~DiffClexParamKey(){};
100 
103  virtual Eigen::MatrixXd const &eval(
104  DiffScalarContainer const &_data,
105  DiffClexParamPack_impl::EvalMode mode) const = 0;
106 
109  size_type index() const { return m_index; }
110 
111  private:
113 };
114 
115 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 
122 
125  std::string m_name;
126 
133 
137 
139  // In future, migrate to Eigen::Matrix<DiffScalar> ?
140  std::vector<std::vector<DiffScalar> > m_data;
141 
144 
147 
155  DiffScalarContainer(std::string const &_name, Index param_dim,
156  Index num_params, Index _lbegin, bool _independent)
157  : m_name(_name),
158  lbegin(_lbegin),
159  m_independent(_independent),
160  m_data(param_dim, std::vector<DiffScalar>(num_params)),
161  m_data_double(param_dim, num_params),
162  m_cache(param_dim, num_params) {
163  // std::cout << "Allocated "<< (_independent? "in" : "") << "dependent
164  // Container '" << _name << "' size " << param_dim << "x" << num_params << "
165  // starting at " << _lbegin << std::endl;
166  }
167 
173  Eigen::MatrixXd const &grad(Index f) const {
174  // std::cout << "WORKING ON f = " << f << "\n";
175  for (Index i = 0; i < m_data.size(); ++i) {
176  for (Index j = 0; j < m_data[i].size(); ++j) {
177  m_cache(i, j) = m_data[i][j].d(f).val();
178  // std::cout << "FOR (i,j) : (" << i << ", " << j << "), val=" <<
179  // m_data[i][j].val().val() << "; grad=" << m_cache(i,j) << std::endl;
180  }
181  }
182  return m_cache;
183  }
184 
192  Eigen::MatrixXd const &hess(Index f, Index a) const {
193  for (Index i = 0; i < m_data.size(); ++i) {
194  for (Index j = 0; j < m_data[i].size(); ++j) {
195  m_cache(i, j) = m_data[i][j].d(f).d(a);
196  }
197  }
198  return m_cache;
199  }
200 
204  void pre_eval(Index N) {
205  Index l = lbegin;
206  for (auto &dvec : m_data) {
207  for (auto &datum : dvec) {
208  datum.val().diff(l++, N);
209  }
210  }
211  }
212 
216  void post_eval(Index N) {
217  Index l = lbegin;
218  for (auto &dvec : m_data) {
219  for (auto &datum : dvec) {
220  datum.diff(l++, N);
221  }
222  }
223  }
224 
227  void eval_double() {
228  for (Index i = 0; i < m_cache.rows(); ++i) {
229  for (Index j = 0; j < m_cache.cols(); ++j) {
230  m_data_double(i, j) = m_data[i][j].val().val();
231  }
232  }
233  }
234 
237  Index linear_index_end() const { return lbegin + m_cache.size(); }
238 };
239 
243  public:
245 
247 
248  static const EvalMode DEFAULT;
249  static const EvalMode READ;
250  static const EvalMode DIFF;
251  static const EvalMode DYNAM;
252 
255  using DoubleReference = Eigen::MatrixXd::CoeffReturnType;
256 
257  template <typename Scalar>
259 
260  template <typename Scalar>
261  friend class ValAccess;
262 
267 
268  size_type size(ClexParamKey const &_key) const override {
269  return size(*static_cast<BaseKey const *>(_key.ptr()));
270  }
271 
272  size_type size(BaseKey const &_key) const {
273  return m_data[_key.index()].m_cache.cols();
274  }
275 
276  size_type dim(ClexParamKey const &_key) const override {
277  return dim(*static_cast<BaseKey const *>(_key.ptr()));
278  }
279 
280  size_type dim(BaseKey const &_key) const {
281  return m_data[_key.index()].m_cache.rows();
282  }
283 
284  std::string eval_mode(ClexParamKey const &_key) const override {
285  return to_string(eval_mode(*static_cast<BaseKey const *>(_key.ptr())));
286  }
287 
288  EvalMode eval_mode(BaseKey const &_key) const { return m_eval[_key.index()]; }
289 
290  EvalMode eval_mode() const { return m_tot_eval_mode; }
291 
292  Eigen::MatrixXd const &read(ClexParamKey const &_key) const override {
293  return read(*static_cast<BaseKey const *>(_key.ptr()));
294  }
295 
296  Eigen::MatrixXd const &read(BaseKey const &_key) const {
297  return _key.eval(m_data[_key.index()], eval_mode());
298  }
299 
300  double const &read(ClexParamKey const &_key, size_type _ind) const override {
301  return read(*static_cast<BaseKey const *>(_key.ptr()), _ind);
302  }
303 
304  double const &read(BaseKey const &_key, size_type _ind) const {
305  return _key.eval(m_data[_key.index()], eval_mode())(_ind, 0);
306  }
307 
308  double const &read(ClexParamKey const &_key, size_type _i,
309  size_type _j) const override {
310  return read(*static_cast<BaseKey const *>(_key.ptr()), _i, _j);
311  }
312 
313  double const &read(BaseKey const &_key, size_type _i, size_type _j) const {
314  return _key.eval(m_data[_key.index()], eval_mode())(_i, _j);
315  }
316 
317  void write(ClexParamKey const &_key,
318  Eigen::Ref<const Eigen::MatrixXd> const &_val) override {
319  write(*static_cast<BaseKey const *>(_key.ptr()), _val);
320  }
321 
322  void write(BaseKey const &_key,
323  Eigen::Ref<const Eigen::MatrixXd> const &_val);
324 
325  void write(ClexParamKey const &_key, size_type _i, double _val) override {
326  write(*static_cast<BaseKey const *>(_key.ptr()), _i, _val);
327  }
328 
329  void write(BaseKey const &_key, size_type _i, double _val);
330 
331  void write(ClexParamKey const &_key, size_type _i, size_type _j,
332  double _val) override {
333  write(*static_cast<BaseKey const *>(_key.ptr()), _i, _j, _val);
334  }
335 
336  void write(BaseKey const &_key, size_type _i, size_type _j, double _val);
337 
338  Key allocate(std::string const &_keyname, Index _rows, Index _cols,
339  bool _independent);
340 
341  void set_eval_mode(ClexParamKey const &_key,
342  std::string const &_mode) override {
343  set_eval_mode(*static_cast<BaseKey const *>(_key.ptr()),
344  from_string<EvalMode>(_mode));
345  }
346 
350  void set_eval_mode(BaseKey const &_key, EvalMode _mode) {
351  m_eval[_key.index()] = _mode;
353  for (auto const &eval : m_eval) {
354  if (eval == DIFF) {
356  break;
357  }
358  }
359  }
360 
363  void pre_eval() {
364  if (eval_mode() == DIFF) {
365  for (DiffScalarContainer &datum : m_data) {
366  if (datum.m_independent) {
367  datum.pre_eval(m_N_independent);
368  }
369  }
370  }
371  }
372 
375  void post_eval() {
376  if (eval_mode() == DIFF) {
377  for (DiffScalarContainer &datum : m_data) {
378  if (!datum.m_independent) {
379  datum.post_eval(m_N_dependent);
380  }
381  }
382  }
383  }
384 
385  private:
386  std::vector<DiffScalarContainer> m_data;
387  std::vector<EvalMode> m_eval;
391 };
392 
393 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
395 
397  public:
399 
400  DiffClexParamValKey(std::string const &_name = "", size_type _ind = -1)
401  : DiffClexParamKey(_name, true, _ind) {
402  // std::cout << "Constructing value key " << _name << "\n";
403  }
404 
406  DiffClexParamPack::EvalMode mode) const override {
407  if (mode == DiffClexParamPack::DIFF) {
408  for (Index i = 0; i < _data.m_cache.rows(); ++i) {
409  for (Index j = 0; j < _data.m_cache.cols(); ++j) {
410  _data.m_cache(i, j) = _data.m_data[i][j].val().val();
411  }
412  }
413  }
414  return _data.m_cache;
415  }
416 
417  protected:
419  return new DiffClexParamValKey(*this);
420  }
421 };
422 
423 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
424 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
425 
427  public:
429 
430  DiffClexParamGradKey(std::string const &_name = "", size_type _ix = -1,
431  std::vector<Index> const &_offset = {},
432  std::vector<Index> const &_stride = {})
433  : DiffClexParamKey(_name, false, _ix, _offset, _stride) {
434  // std::cout << "Constructing grad key " << _name << ", ID " << _ix << "\n";
435  }
436 
438  DiffClexParamPack::EvalMode mode) const override {
439  if (mode != DiffClexParamPack::DIFF)
440  throw std::runtime_error("Requested Gradient parameter " + name() +
441  " for incompatible evaluation mode " +
442  to_string(mode) + ".");
443  _data.grad(_l(0));
444  return _data.m_cache;
445  }
446 
447  protected:
449  return new DiffClexParamGradKey(*this);
450  }
451 };
452 
453 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
454 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
455 
457  public:
459 
460  DiffClexParamHessKey(std::string const &_name = "", size_type _ix = -1,
461  std::vector<Index> const &_offset = {},
462  std::vector<Index> const &_stride = {})
463  : DiffClexParamKey(_name, false, _ix, _offset, _stride) {
464  // std::cout << "Constructing hess key " << _name << ", ID " << _ix << "\n";
465  }
466 
468  DiffClexParamPack::EvalMode mode) const override {
469  if (mode != DiffClexParamPack::DIFF)
470  throw std::runtime_error("Requested Hessian parameter " + name() +
471  " for incompatible evaluation mode " +
472  to_string(mode) + ".");
473  _data.hess(_l(0), _l(1));
474  return _data.m_cache;
475  }
476 
477  protected:
479  return new DiffClexParamHessKey(*this);
480  }
481 };
482 
483 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
484 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
485 
486 template <>
488  static const std::string name;
489 
490  static const std::multimap<DiffClexParamPack::EvalMode,
491  std::vector<std::string> >
493 };
494 
495 template <>
496 struct ValAccess<double> {
498 
499  static double const &get(DiffClexParamPack const &_pack,
500  DiffClexParamKey const &_key, size_type i) {
501  return _pack.m_data[_key.index()].m_cache(i, 0);
502  }
503 
504  static double const &get(DiffClexParamPack const &_pack,
505  DiffClexParamKey const &_key, size_type i,
506  size_type j) {
507  return _pack.m_data[_key.index()].m_cache(i, j);
508  }
509 
510  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
511  Eigen::Ref<const Eigen::MatrixXd> const &_val) {
512  _pack.m_data[_key.index()].m_cache = _val;
513  }
514 
515  template <typename Scalar2>
516  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
517  size_type i, Scalar2 const &_val) {
518  _pack.m_data[_key.index()].m_cache(i, 0) = _val;
519  }
520 
521  template <typename Scalar2>
522  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
523  size_type i, size_type j, Scalar2 const &_val) {
524  _pack.m_data[_key.index()].m_cache(i, j) = _val;
525  }
526 };
527 
528 template <>
531 
532  static typename DiffClexParamPack::DiffScalar const &get(
533  DiffClexParamPack const &_pack, DiffClexParamKey const &_key,
534  size_type i) {
535  return _pack.m_data[_key.index()].m_data[i][0];
536  }
537 
538  static typename DiffClexParamPack::DiffScalar const &get(
539  DiffClexParamPack const &_pack, DiffClexParamKey const &_key, size_type i,
540  size_type j) {
541  return _pack.m_data[_key.index()].m_data[i][j];
542  }
543 
544  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
545  Eigen::Ref<const Eigen::MatrixXd> const &_val) {
546  assert(_val.rows() == _pack.m_data[_key.index()].m_data.size());
547  for (Index i = 0; i < _val.rows(); ++i) {
548  assert(_val.cols() == _pack.m_data[_key.index()].m_data[i].size());
549  for (Index j = 0; j < _val.cols(); ++j) {
550  _pack.m_data[_key.index()].m_data[i][j] = _val(i, j);
551  }
552  }
553  }
554 
555  template <typename Scalar2>
556  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
557  size_type i, Scalar2 const &_val) {
558  _pack.m_data[_key.index()].m_data[i][0] = _val;
559  }
560 
561  template <typename Scalar2>
562  static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key,
563  size_type i, size_type j, Scalar2 const &_val) {
564  _pack.m_data[_key.index()].m_data[i][j] = _val;
565  }
566 };
567 
569  BaseKey const &_key, Eigen::Ref<const Eigen::MatrixXd> const &_val) {
570  if (!_key.standalone()) {
571  throw std::runtime_error("Cannot write to dependent parameter " +
572  _key.name() + ".");
573  }
574  if (eval_mode() == DEFAULT) {
575  Val<double>::set(*this, _key, _val);
576  } else {
577  Val<DiffScalar>::set(*this, _key, _val);
578  }
579 }
580 
581 inline void DiffClexParamPack::write(BaseKey const &_key, size_type _i,
582  double _val) {
583  if (!_key.standalone()) {
584  throw std::runtime_error("Cannot write to dependent parameter " +
585  _key.name() + ".");
586  }
587 
588  if (eval_mode() == DEFAULT) {
589  Val<double>::set(*this, _key, _i, _val);
590  } else {
591  Val<DiffScalar>::set(*this, _key, _i, _val);
592  }
593 }
594 
595 inline void DiffClexParamPack::write(BaseKey const &_key, size_type _i,
596  size_type _j, double _val) {
597  if (!_key.standalone()) {
598  throw std::runtime_error("Cannot write to dependent parameter " +
599  _key.name() + ".");
600  }
601 
602  if (eval_mode() == DEFAULT) {
603  Val<double>::set(*this, _key, _i, _j, _val);
604  } else {
605  Val<DiffScalar>::set(*this, _key, _i, _j, _val);
606  }
607 }
608 
610  std::string const &_keyname, Index _rows, Index _cols, bool _independent) {
611  auto it = keys().find(_keyname);
612  if (it != keys().end())
613  throw std::runtime_error(
614  "Naming collision in DiffClexParamPack::allocate(), ClexParamPack "
615  "already managing parameter allocation corresponding to name " +
616  _keyname + ".");
617  Key protokey(_keyname, m_data.size());
618  m_keys[_keyname] = protokey;
619  if (_independent) {
620  m_data.push_back(
621  DiffScalarContainer(_keyname, _rows, _cols, m_N_independent, true));
622  m_N_independent += _rows * _cols;
623  Index i = protokey.index();
624  for (Index f = 0; f < m_data.size(); ++f) {
625  if (!m_data[f].m_independent) {
626  std::string gradname =
627  "diff/" + m_data[f].m_name + "/" + m_data[i].m_name;
628  m_keys[gradname] = DiffClexParamGradKey(gradname, i, {m_data[f].lbegin},
629  {m_data[f].m_cache.cols()});
630 
631  for (Index j = 0; j < m_data.size(); ++j) {
632  if (m_data[j].m_independent) {
633  std::string hessname = gradname + "/" + m_data[j].m_name;
634  m_keys[hessname] = DiffClexParamHessKey(
635  hessname, i, {m_data[f].lbegin, m_data[j].lbegin},
636  {m_data[f].m_cache.cols(), m_data[j].m_cache.cols()});
637  }
638  }
639  }
640  }
641  } else {
642  m_data.push_back(
643  DiffScalarContainer(_keyname, _rows, _cols, m_N_dependent, false));
644  m_N_dependent += _rows * _cols;
645 
646  Index f = protokey.index();
647 
648  for (Index i = 0; i < m_data.size(); ++i) {
649  if (m_data[i].m_independent) {
650  std::string gradname =
651  "diff/" + m_data[f].m_name + "/" + m_data[i].m_name;
652  m_keys[gradname] = DiffClexParamGradKey(gradname, i, {m_data[f].lbegin},
653  {m_data[f].m_cache.cols()});
654 
655  for (Index j = 0; j < m_data.size(); ++j) {
656  if (m_data[j].m_independent) {
657  std::string hessname = gradname + "/" + m_data[j].m_name;
658  m_keys[hessname] = DiffClexParamHessKey(
659  hessname, i, {m_data[f].lbegin, m_data[j].lbegin},
660  {m_data[f].m_cache.cols(), m_data[j].m_cache.cols()});
661  }
662  }
663  }
664  }
665  }
666 
667  m_eval.push_back(EvalMode::DEFAULT);
668 
669  return protokey;
670 }
671 
672 inline std::ostream &operator<<(std::ostream &sout,
673  const DiffClexParamPack::EvalMode &val) {
674  sout << to_string<DiffClexParamPack::EvalMode>(val);
675  return sout;
676 }
677 
678 inline std::istream &operator>>(std::istream &sin,
680  std::string s;
681  sin >> s;
682  val = from_string<DiffClexParamPack::EvalMode>(s);
683  return sin;
684 }
685 
686 const std::string traits<DiffClexParamPack::EvalMode>::name = "clex_eval_mode";
687 
688 const std::multimap<DiffClexParamPack::EvalMode, std::vector<std::string> >
691  {"Default", "DEFAULT", "default"}},
693  {"Diff", "DIFF", "diff", "Differential", "differential",
694  "DIFFERENTIAL"}},
695  {DiffClexParamPack::EvalMode::READ, {"Read", "READ", "read"}},
697  {"Dynamic", "Dynam", "DYNAMIC", "DYNAM", "dynamic", "dynam"}}};
698 
707 
709 } // namespace CASM
710 #endif
std::set< std::string > & s
Key for indexing clexulator parameters Contains pointer to implementation of the Key.
ClexParamPack_impl::BaseKey const * ptr() const
Returns pointer to Key implementation.
BaseKey is base class from which all ClexParamKey implementation classes inherit. Hides implementatio...
bool standalone() const
Returns true if key refers directly to managed data, false if it refers to values derived from manage...
std::string const & name() const
Name of this Key, should be descriptive of managed data. Ex.: "disp_var" of "magspin_site_basis".
Index _l(Index i) const
Returns i'th linear index identifier.
Abstract base class for reading/writing clexulator parameters Parameters are assumed to be stored as,...
unsigned int size_type
std::map< std::string, ClexParamKey > const & keys() const
Obtain registry of all keys for data blocks managed by this ClexParamPack.
std::map< std::string, ClexParamKey > m_keys
ClexParamPack_impl::BaseKey * _clone() const override
Clone the ClexParamKey.
Eigen::MatrixXd const & eval(DiffScalarContainer const &_data, DiffClexParamPack::EvalMode mode) const override
Operate on associated DiffScalarContainer to ensure the standalone or derived value associated with t...
ClexParamPack::size_type size_type
DiffClexParamGradKey(std::string const &_name="", size_type _ix=-1, std::vector< Index > const &_offset={}, std::vector< Index > const &_stride={})
DiffClexParamHessKey(std::string const &_name="", size_type _ix=-1, std::vector< Index > const &_offset={}, std::vector< Index > const &_stride={})
ClexParamPack_impl::BaseKey * _clone() const override
Clone the ClexParamKey.
ClexParamPack::size_type size_type
Eigen::MatrixXd const & eval(DiffScalarContainer const &_data, DiffClexParamPack::EvalMode mode) const override
Operate on associated DiffScalarContainer to ensure the standalone or derived value associated with t...
Abstract base class for all keys that interact with DiffClexParamPack DiffClexParamPack values are as...
virtual ~DiffClexParamKey()
Destructor of abstract base class must be virtual.
size_type index() const
Access the primary identifier of this value (which determines the associated standalone value and/or ...
DiffClexParamKey(std::string const &_name, bool _standalone, size_type _ind, std::vector< Index > const &_offset={}, std::vector< Index > const &_stride={})
DiffClexParamKey Constructor.
ClexParamPack::size_type size_type
virtual Eigen::MatrixXd const & eval(DiffScalarContainer const &_data, DiffClexParamPack_impl::EvalMode mode) const =0
Operate on associated DiffScalarContainer to ensure the standalone or derived value associated with t...
Class for managing the set of all dependent and independent paramters used/generated by clexulator.
void write(ClexParamKey const &_key, size_type _i, size_type _j, double _val) override
Write element to 2D parameter array for parameter specified by.
DiffClexParamPack_impl::EvalMode EvalMode
void set_eval_mode(ClexParamKey const &_key, std::string const &_mode) override
Sets evaluation mode for ClexParamPack parameter Choices are at least.
DiffClexParamValKey Key
static const EvalMode READ
Eigen::MatrixXd::CoeffReturnType DoubleReference
size_type size(BaseKey const &_key) const
Eigen::MatrixXd const & read(ClexParamKey const &_key) const override
Returns const reference to parameter array for parameter specified by.
std::vector< EvalMode > m_eval
size_type size(ClexParamKey const &_key) const override
'N' dimension of parameter array (either '1', or size of unit cell neighborhood) returns number of co...
DiffClexParamPack_impl::DiffScalar DiffScalar
size_type dim(ClexParamKey const &_key) const override
'm' dimension of parameter array returns number of rows in parameter array
Eigen::MatrixXd const & read(BaseKey const &_key) const
size_type dim(BaseKey const &_key) const
Key allocate(std::string const &_keyname, Index _rows, Index _cols, bool _independent)
static const EvalMode DYNAM
void pre_eval()
Prepares all independent parameters before function evaluation if derivatives are desired.
EvalMode eval_mode(BaseKey const &_key) const
double const & read(ClexParamKey const &_key, size_type _ind) const override
Returns const reference to element of 1D parameter array for parameter specified by.
DiffClexParamPack()
Default constructor initializes evaluation mode and zeros numbers of managed parameters.
double const & read(ClexParamKey const &_key, size_type _i, size_type _j) const override
Returns const reference to element of 2D parameter array for parameter specified by.
double const & read(BaseKey const &_key, size_type _ind) const
void write(ClexParamKey const &_key, Eigen::Ref< const Eigen::MatrixXd > const &_val) override
Write parameter array for parameter specified by.
void post_eval()
Processes all dependent parameters after function evaluation if derivatives are desired.
std::vector< DiffScalarContainer > m_data
static const EvalMode DEFAULT
void set_eval_mode(BaseKey const &_key, EvalMode _mode)
Set evaluation mode of specified parameter type.
std::string eval_mode(ClexParamKey const &_key) const override
Check evaluation mode for ClexParamPack parameter Choices are at least.
void write(ClexParamKey const &_key, size_type _i, double _val) override
Write element to 1D parameter array for parameter specified by.
static const EvalMode DIFF
double const & read(BaseKey const &_key, size_type _i, size_type _j) const
ClexParamPack::size_type size_type
ClexParamPack_impl::BaseKey * _clone() const override
Clone the ClexParamKey.
DiffClexParamValKey(std::string const &_name="", size_type _ind=-1)
Eigen::MatrixXd const & eval(DiffScalarContainer const &_data, DiffClexParamPack::EvalMode mode) const override
Operate on associated DiffScalarContainer to ensure the standalone or derived value associated with t...
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
fadbad::B< fadbad::F< double > > DiffScalar
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
std::istream & operator>>(std::istream &_in, std::vector< T > &vec)
Definition: stream_io.hh:10
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Definition: stream_io.hh:24
ProjectSettings & set
Definition: settings.cc:137
container struct for storing a standalone value as 2D arrays of both autodiff Scalars doubles
void eval_double()
Copy values of autodiff scalars from m_data to m_data_double (matrix of doubles) in preparation for e...
bool m_independent
Flag, set to true if this container holds independent values (false if dependent)
Index linear_index_end() const
Returns one past end of max linear index range allowed for this parameter set.
Index lbegin
linear offset for start of value index in linear array FADBAD forward (backward) autodiff types refer...
std::vector< std::vector< DiffScalar > > m_data
Stored data represented as autodif scalar type.
Eigen::MatrixXd const & grad(Index f) const
Gradient of dependent function index f wrt the independent variables contained in here.
DiffClexParamPack_impl::DiffScalar DiffScalar
Eigen::MatrixXd const & hess(Index f, Index a) const
Hessian components of dependent function index f corresponding to independent variable index 'a' and ...
Eigen::MatrixXd m_cache
Derived data cache, represented as matrix of doubles.
void post_eval(Index N)
Must be called on each dependent parameter after function evaluation if derivatives are desired.
std::string m_name
Name of the standalone value stored in this container. Should match name of associated key.
Eigen::MatrixXd m_data_double
Stored data, represented as matrix of doubles.
DiffScalarContainer(std::string const &_name, Index param_dim, Index num_params, Index _lbegin, bool _independent)
DiffSclarContainer constructor.
void pre_eval(Index N)
Must be called on each independent parameter before function evaluation if derivatives are desired.
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, size_type i, size_type j, Scalar2 const &_val)
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, size_type i, Scalar2 const &_val)
static double const & get(DiffClexParamPack const &_pack, DiffClexParamKey const &_key, size_type i)
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, Eigen::Ref< const Eigen::MatrixXd > const &_val)
BasicClexParamPack::size_type size_type
static double const & get(DiffClexParamPack const &_pack, DiffClexParamKey const &_key, size_type i, size_type j)
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, size_type i, Scalar2 const &_val)
static DiffClexParamPack::DiffScalar const & get(DiffClexParamPack const &_pack, DiffClexParamKey const &_key, size_type i, size_type j)
static DiffClexParamPack::DiffScalar const & get(DiffClexParamPack const &_pack, DiffClexParamKey const &_key, size_type i)
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, Eigen::Ref< const Eigen::MatrixXd > const &_val)
static void set(DiffClexParamPack &_pack, DiffClexParamKey const &_key, size_type i, size_type j, Scalar2 const &_val)
static const std::multimap< DiffClexParamPack::EvalMode, std::vector< std::string > > strval