1 #ifndef CLEXPARAMPACK_HH
2 #define CLEXPARAMPACK_HH
30 template <
typename Scalar>
33 namespace ClexParamPack_impl {
48 BaseKey(std::string
const &_name,
bool _standalone,
49 std::vector<Index>
const &_offset = {},
50 std::vector<Index>
const &_stride = {})
70 template <
typename... Args>
76 std::unique_ptr<BaseKey>
clone()
const {
77 return std::unique_ptr<BaseKey>(
_clone());
89 template <
typename T,
typename... Args>
125 {{
"ParamPack::DEFAULT",
"double"}});
131 {{
"ParamPack::DEFAULT",
"double"},
132 {
"ParamPack::DIFF",
"ParamPack::DiffScalar"}});
139 std::map<std::string, std::string>
const &_specializations)
157 return "#include \"casm/clex/" +
name() +
".hh\"\n";
167 std::unique_ptr<ParamPackMixIn>
clone()
const {
168 return std::unique_ptr<ParamPackMixIn>(
_clone());
207 template <
typename... Args>
239 std::map<std::string, ClexParamKey>
const &
keys()
const {
return m_keys; }
243 auto it =
keys().find(_name);
244 if (it ==
keys().end()) {
245 std::stringstream ss;
246 for (it =
keys().begin(); it !=
keys().end(); ++it)
247 ss <<
" " << it->first <<
"\n";
248 throw std::runtime_error(
249 "In ClexParamPack::key(), ClexParamPack does not contain parameters "
250 "corresponding to name " +
251 _name +
". Options are:\n" + ss.str());
301 std::string
const &_mode) = 0;
305 Eigen::Ref<const Eigen::MatrixXd>
const &_val) = 0;
325 std::map<std::string, ClexParamKey>
m_keys;
Key for indexing clexulator parameters Contains pointer to implementation of the Key.
ClexParamKey & operator()(Args const &... args)
use parentheses operator to set identifiers. Permits syntax like
notstd::cloneable_ptr< ClexParamPack_impl::BaseKey > m_key_ptr
ptr to BaseKey class that hides implementation-specific access attributes
std::string const & name() const
Returns name of key.
ClexParamKey(ClexParamPack_impl::BaseKey const &_key)
Construct ClexParamKey by cloning specialization of BaseKey.
ClexParamPack_impl::BaseKey const * ptr() const
Returns pointer to Key implementation.
ClexParamKey()
Allow default construction.
BaseKey is base class from which all ClexParamKey implementation classes inherit. Hides implementatio...
std::vector< Index > m_identifiers
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".
BaseKey(std::string const &_name, bool _standalone, std::vector< Index > const &_offset={}, std::vector< Index > const &_stride={})
Must be constructed with at least a name.
std::vector< Index > m_stride
virtual ~BaseKey()
Abstract class must define virtual destructor.
std::unique_ptr< BaseKey > clone() const
Clone the ClexParamKey.
void _set_identifiers(Index i, std::pair< Index, Index > _inds)
Overload for pair indexed identifier.
void set_identifiers(Args const &... args)
Specify supplemental identifiers, either via linear indices or pair indices. Internally,...
void _set_identifiers(Index i, Index _ind)
Overload for linear indexed identifier.
virtual BaseKey * _clone() const =0
Clone the ClexParamKey.
std::vector< Index > m_offset
void _set_identifiers(Index i, T const &_val, Args const &... args)
Recursive unrolling of variadic template to set all identifiers.
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,...
virtual std::string eval_mode(ClexParamKey const &_key) const =0
Check evaluation mode for ClexParamPack parameter Choices are at least.
ClexParamKey const & key(std::string const &_name) const
Obtain key for managed data block by name.
virtual void write(ClexParamKey const &_key, size_type _i, double val)=0
Write element to 1D parameter array for parameter specified by.
virtual double const & read(ClexParamKey const &_key, size_type _i, size_type _j) const =0
Returns const reference to element of 2D parameter array for parameter specified by.
virtual void write(ClexParamKey const &_key, size_type _i, size_type _j, double val)=0
Write element to 2D parameter array for parameter specified by.
virtual size_type size(ClexParamKey const &_key) const =0
'N' dimension of parameter array (either '1', or size of unit cell neighborhood) returns number of co...
void post_eval()
May be specialized to perform postprocessing after function evaluation.
virtual void set_eval_mode(ClexParamKey const &_key, std::string const &_mode)=0
Sets evaluation mode for ClexParamPack parameter Choices are at least.
virtual Eigen::MatrixXd const & read(ClexParamKey const &_key) const =0
Returns const reference to parameter array for parameter specified by.
virtual void write(ClexParamKey const &_key, Eigen::Ref< const Eigen::MatrixXd > const &_val)=0
Write parameter array for parameter specified by.
virtual size_type dim(ClexParamKey const &_key) const =0
'm' dimension of parameter array returns number of rows in parameter array
virtual ~ClexParamPack()
Abstract class must define virtual destructor.
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
void pre_eval()
May be specialized to perform preprocessing before function evaluation.
virtual double const & read(ClexParamKey const &_key, size_type _i) const =0
Returns const reference to element of 1D parameter array for parameter specified by.
ParamPackMixIn is interface class to control ClexParamPack portion of Clexulator printing Used primar...
static ParamPackMixIn basic_mix_in()
static factory function for BasicClexParamPack
static ParamPackMixIn diff_mix_in()
static factory function for DiffClexParamPack
std::map< std::string, std::string > m_scalar_specializations
virtual ParamPackMixIn * _clone() const
Clone the ParamPackMixIn (implementation)
ParamPackMixIn(std::string const &_name, std::map< std::string, std::string > const &_specializations)
Constructor Constructed with.
std::map< std::string, std::string > const & scalar_specializations() const
Dictionary of pairs ("EvalMode", "ScalarType") These correspond to the underlying scalar type to be u...
virtual std::string cpp_includes_string() const
returns string with include directives for Clexulator.
virtual ~ParamPackMixIn()
Abstract class must define virtual destructor.
std::unique_ptr< ParamPackMixIn > clone() const
Clone the ParamPackMixIn.
std::string const & name() const
typename of the corresponding ClexParamPack
virtual std::string cpp_definitions_string(std::string const &_indent) const
returns string with c++ definitions to be written before Clexulator.
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
INDEX_TYPE Index
For long integer indexing:
std::unique_ptr< T > clone(const T &obj)