17 throw std::runtime_error(
18 "Error in ClexBasisWriter: Invalid param_pack_type");
32 for (
auto const &doftype : doftypes) {
40 for (
auto const &doftype : doftypes) {
48 namespace ClexBasisWriter_impl {
51 std::string
const &class_name,
ClexBasis const &clex,
53 std::vector<std::unique_ptr<OrbitFunctionTraits> >
const
55 Index N_flower, std::string
const &indent) {
60 for (
auto const &writer_ptr : orbit_func_writers) {
61 writer_ptr->print_typedefs(ss, class_name, indent);
64 for (
auto const &writer_ptr : orbit_func_writers) {
65 writer_ptr->print_eval_table_declarations(ss, class_name, clex, indent);
71 <<
"// ParamPack object, which stores temporary data for calculations\n"
72 << indent <<
"mutable ParamPack m_params;\n\n";
75 for (
auto const &specialization :
79 indent <<
"// typedef for method pointers of scalar type "
80 << specialization.second <<
"\n"
81 << indent <<
"typedef " << specialization.second <<
" (" << class_name
82 <<
"::*BasisFuncPtr_" << ispec <<
")() const;\n\n"
85 indent <<
"// typedef for method pointers\n"
86 << indent <<
"typedef " << specialization.second <<
" (" << class_name
87 <<
"::*DeltaBasisFuncPtr_" << ispec <<
")(int, int) const;\n\n"
91 <<
"// array of pointers to member functions for calculating basis "
92 "functions of scalar type "
93 << specialization.second <<
"\n"
94 << indent <<
"BasisFuncPtr_" << ispec <<
" m_orbit_func_table_" << ispec
95 <<
"[" << N_corr <<
"];\n\n"
99 <<
"// array of pointers to member functions for calculating flower "
100 "functions of scalar type "
101 << specialization.second <<
"\n"
102 << indent <<
"BasisFuncPtr_" << ispec <<
" m_flower_func_table_" << ispec
103 <<
"[" << N_flower <<
"][" << N_corr <<
"];\n\n"
107 <<
"// array of pointers to member functions for calculating DELTA "
108 "flower functions of scalar type "
109 << specialization.second <<
"\n"
110 << indent <<
"DeltaBasisFuncPtr_" << ispec <<
" m_delta_func_table_"
111 << ispec <<
"[" << N_flower <<
"][" << N_corr <<
"];\n\n";
118 clex.
prim(), dof.second, indent);
122 clex.
prim(), dof.second, indent);
124 ss << indent <<
"//ClexParamPack allocation for evaluated correlations \n"
125 << indent <<
"ParamPack::Key m_corr_param_key;\n";
128 std::vector<DoFType::ParamAllocation> allo =
131 if (allo.empty())
continue;
132 ss << indent <<
"//ClexParamPack allocation for DoF " << dof.first <<
"\n";
133 for (
const auto &el : allo)
134 ss << indent <<
"ParamPack::Key m_" << el.param_name <<
"_param_key;\n";
139 std::vector<DoFType::ParamAllocation> allo =
142 if (allo.empty())
continue;
143 ss << indent <<
"//ClexParamPack allocation for DoF " << dof.first <<
"\n";
144 for (
const auto &el : allo)
145 ss << indent <<
"ParamPack::Key m_" << el.param_name <<
"_param_key;\n";
155 std::string
const &class_name,
ClexBasis const &clex,
156 std::string
const &indent) {
157 std::stringstream ss;
160 indent <<
"/// \\brief Clone the " << class_name <<
"\n"
161 << indent <<
"Clexulator_impl::Base *_clone() const override {\n"
162 << indent <<
" return new " << class_name <<
"(*this);\n"
167 <<
"/// \\brief Calculate contribution to global correlations from one "
169 << indent <<
"/// Result is recorded in ClexParamPack\n"
170 << indent <<
"void _calc_global_corr_contribution() const override;\n\n"
174 <<
"/// \\brief Calculate contribution to global correlations from one "
177 <<
"/// Result is recorded in double array starting at corr_begin\n"
179 <<
"void _calc_global_corr_contribution(double *corr_begin) const "
184 <<
"/// \\brief Calculate contribution to select global correlations from "
185 "one unit cell into ClexParamPack\n"
186 << indent <<
"/// Result is recorded in ClexParamPack\n"
188 <<
"void _calc_restricted_global_corr_contribution(size_type const "
189 "*ind_list_begin, size_type const *ind_list_end) const override;\n\n"
193 <<
"/// \\brief Calculate contribution to select global correlations from "
196 <<
"/// Result is recorded in double array starting at corr_begin\n"
198 <<
"void _calc_restricted_global_corr_contribution(double *corr_begin, "
199 "size_type const *ind_list_begin, size_type const *ind_list_end) const "
204 <<
"/// \\brief Calculate point correlations about neighbor site "
207 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
210 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
212 << indent <<
"/// Result is recorded in ClexParamPack\n"
213 << indent <<
"void _calc_point_corr(int nlist_ind) const override;\n\n"
217 <<
"/// \\brief Calculate point correlations about neighbor site "
220 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
223 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
226 <<
"/// Result is recorded in double array starting at corr_begin\n"
228 <<
"void _calc_point_corr(int nlist_ind, double *corr_begin) const "
233 <<
"/// \\brief Calculate select point correlations about neighbor site "
236 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
239 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
241 << indent <<
"/// Result is recorded in ClexParamPack\n"
243 <<
"void _calc_restricted_point_corr(int nlist_ind, size_type const "
244 "*ind_list_begin, size_type const *ind_list_end) const override;\n\n"
248 <<
"/// \\brief Calculate select point correlations about neighbor site "
251 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
254 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
257 <<
"/// Result is recorded in double array starting at corr_begin\n"
259 <<
"void _calc_restricted_point_corr(int nlist_ind, double *corr_begin, "
260 "size_type const *ind_list_begin, size_type const *ind_list_end) const "
265 <<
"/// \\brief Calculate the change in point correlations due to "
266 "changing an occupant at neighbor site 'nlist_ind'\n"
268 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
271 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
273 << indent <<
"/// Result is recorded in ClexParamPack\n"
275 <<
"void _calc_delta_point_corr(int nlist_ind, int occ_i, int occ_f) "
276 "const override;\n\n"
280 <<
"/// \\brief Calculate the change in point correlations due to "
281 "changing an occupant at neighbor site 'nlist_ind'\n"
283 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
286 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
289 <<
"/// Result is recorded in double array starting at corr_begin\n"
291 <<
"void _calc_delta_point_corr(int nlist_ind, int occ_i, int occ_f, "
292 "double *corr_begin) const override;\n\n"
296 <<
"/// \\brief Calculate the change in select point correlations due to "
297 "changing an occupant at neighbor site 'nlist_ind'\n"
299 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
302 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
304 << indent <<
"/// Result is recorded in ClexParamPack\n"
306 <<
"void _calc_restricted_delta_point_corr(int nlist_ind, int occ_i, int "
307 "occ_f, size_type const *ind_list_begin, size_type const "
308 "*ind_list_end) const override;\n\n"
312 <<
"/// \\brief Calculate the change in select point correlations due to "
313 "changing an occupant at neighbor site 'nlist_ind'\n"
315 <<
"/// For global clexulators, 'nlist_ind' only ranges over sites in the "
318 <<
"/// For local clexulators, 'nlist_ind' ranges over all sites in the "
321 <<
"/// Result is recorded in double array starting at corr_begin\n"
323 <<
"void _calc_restricted_delta_point_corr(int nlist_ind, int occ_i, int "
324 "occ_f, double *corr_begin, size_type const *ind_list_begin, size_type "
325 "const *ind_list_end) const override;\n\n"
328 indent <<
"template<typename Scalar>\n"
329 << indent <<
"void _global_prepare() const;\n\n"
332 indent <<
"template<typename Scalar>\n"
333 << indent <<
"void _point_prepare(int nlist_ind) const;\n\n";
337 for (; it != end_it; ++it) {
340 clex.
prim(), it->second, indent);
346 for (; it != end_it; ++it) {
349 clex.
prim(), it->second, indent);
353 ss << indent <<
"//default functions for basis function evaluation\n"
354 << indent <<
"template <typename Scalar>\n"
355 << indent <<
"Scalar zero_func() const {\n"
356 << indent <<
" return Scalar(0.0);\n"
360 indent <<
"template <typename Scalar>\n"
361 << indent <<
"Scalar zero_func(int, int) const {\n"
362 << indent <<
" return Scalar(0.0);\n"
363 << indent <<
"}\n\n";
372 std::string
const &indent) {
373 std::stringstream ss;
374 ss << indent << class_name <<
"();\n\n"
375 << indent <<
"~" << class_name <<
"();\n\n"
378 indent <<
"ClexParamPack const ¶m_pack() const override {\n"
379 << indent <<
" return m_params;\n"
383 indent <<
"ClexParamPack ¶m_pack() override {\n"
384 << indent <<
" return m_params;\n"
385 << indent <<
"}\n\n";
389 for (; it != end_it; ++it) {
392 clex.
prim(), it->second, indent);
397 for (; it != end_it; ++it) {
400 clex.
prim(), it->second, indent);
409 std::string
const &class_name,
ClexBasis const &clex,
410 ParamPackMixIn const &_param_pack_mix_in, std::string
const &indent) {
411 std::stringstream ss;
413 ss << indent << class_name <<
"::~" << class_name <<
"() {\n"
414 << indent <<
" //nothing here for now\n"
415 << indent <<
"}\n\n";
420 <<
"/// \\brief Calculate contribution to global correlations from one "
422 << indent <<
"void " << class_name
423 <<
"::_calc_global_corr_contribution(double *corr_begin) const {\n"
424 << indent <<
" _calc_global_corr_contribution();\n"
425 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
427 <<
" *(corr_begin + i) = ParamPack::Val<double>::get(m_params, "
428 "m_corr_param_key, i);\n"
436 <<
"/// \\brief Calculate contribution to global correlations from one "
438 << indent <<
"void " << class_name
439 <<
"::_calc_global_corr_contribution() const {\n"
440 << indent <<
" m_params.pre_eval();\n";
444 for (
auto const &specialization : specializations) {
445 if (specializations.size() > 1) {
447 if (ispec > 0) ss <<
"else ";
448 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
450 ss << indent <<
" {\n"
451 << indent <<
" _global_prepare<" << specialization.second <<
">();\n"
452 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
453 << indent <<
" ParamPack::Val<" << specialization.second
454 <<
">::set(m_params, m_corr_param_key, i, (this->*m_orbit_func_table_"
455 << ispec <<
"[i])());\n"
460 ss << indent <<
" m_params.post_eval();\n"
467 <<
"/// \\brief Calculate contribution to select global correlations from "
469 << indent <<
"void " << class_name
470 <<
"::_calc_restricted_global_corr_contribution(double *corr_begin, "
471 "size_type const *ind_list_begin, size_type const *ind_list_end) const "
474 <<
" _calc_restricted_global_corr_contribution(ind_list_begin, "
476 << indent <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
478 <<
" *(corr_begin + *ind_list_begin) = "
479 "ParamPack::Val<double>::get(m_params, m_corr_param_key, "
480 "*ind_list_begin);\n"
488 <<
"/// \\brief Calculate contribution to select global correlations from "
490 << indent <<
"void " << class_name
491 <<
"::_calc_restricted_global_corr_contribution(size_type const "
492 "*ind_list_begin, size_type const *ind_list_end) const {\n"
493 << indent <<
" m_params.pre_eval();\n";
496 for (
auto const &specialization : specializations) {
497 if (specializations.size() > 1) {
499 if (ispec > 0) ss <<
"else ";
500 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
502 ss << indent <<
" {\n"
503 << indent <<
" _global_prepare<" << specialization.second <<
">();\n"
505 <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
506 << indent <<
" ParamPack::Val<" << specialization.second
507 <<
">::set(m_params, m_corr_param_key, *ind_list_begin, "
508 "(this->*m_orbit_func_table_"
509 << ispec <<
"[*ind_list_begin])());\n"
514 ss << indent <<
" m_params.post_eval();\n"
521 <<
"/// \\brief Calculate point correlations about basis site "
523 << indent <<
"void " << class_name
524 <<
"::_calc_point_corr(int nlist_ind, double *corr_begin) const {\n"
525 << indent <<
" _calc_point_corr(nlist_ind);\n"
526 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
528 <<
" *(corr_begin + i) = ParamPack::Val<double>::get(m_params, "
529 "m_corr_param_key, i);\n"
537 <<
"/// \\brief Calculate point correlations about basis site "
539 << indent <<
"void " << class_name
540 <<
"::_calc_point_corr(int nlist_ind) const {\n"
541 << indent <<
" m_params.pre_eval();\n";
544 for (
auto const &specialization : specializations) {
545 if (specializations.size() > 1) {
547 if (ispec > 0) ss <<
"else ";
548 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
550 ss << indent <<
" {\n"
551 << indent <<
" _point_prepare<" << specialization.second
553 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
554 << indent <<
" ParamPack::Val<" << specialization.second
555 <<
">::set(m_params, m_corr_param_key, i, (this->*m_flower_func_table_"
556 << ispec <<
"[nlist_ind][i])());\n"
561 ss << indent <<
" m_params.post_eval();\n"
568 <<
"/// \\brief Calculate select point correlations about basis site "
570 << indent <<
"void " << class_name
571 <<
"::_calc_restricted_point_corr(int nlist_ind, double *corr_begin, "
572 "size_type const *ind_list_begin, size_type const *ind_list_end) const "
575 <<
" _calc_restricted_point_corr(nlist_ind, ind_list_begin, "
577 << indent <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
579 <<
" *(corr_begin + *ind_list_begin) = "
580 "ParamPack::Val<double>::get(m_params, m_corr_param_key, "
581 "*ind_list_begin);\n"
589 <<
"/// \\brief Calculate select point correlations about basis site "
591 << indent <<
"void " << class_name
592 <<
"::_calc_restricted_point_corr(int nlist_ind, size_type const "
593 "*ind_list_begin, size_type const *ind_list_end) const {\n"
594 << indent <<
" m_params.pre_eval();\n";
597 for (
auto const &specialization : specializations) {
598 if (specializations.size() > 1) {
600 if (ispec > 0) ss <<
"else ";
601 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
603 ss << indent <<
" {\n"
604 << indent <<
" _point_prepare<" << specialization.second
607 <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
608 << indent <<
" ParamPack::Val<" << specialization.second
609 <<
">::set(m_params, m_corr_param_key, *ind_list_begin, "
610 "(this->*m_flower_func_table_"
611 << ispec <<
"[nlist_ind][*ind_list_begin])());\n"
616 ss << indent <<
" m_params.post_eval();\n"
623 <<
"/// \\brief Calculate the change in point correlations due to "
624 "changing an occupant\n"
625 << indent <<
"void " << class_name
626 <<
"::_calc_delta_point_corr(int nlist_ind, int occ_i, int occ_f, double "
627 "*corr_begin) const {\n"
628 << indent <<
" _calc_delta_point_corr(nlist_ind, occ_i, occ_f);\n"
629 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
631 <<
" *(corr_begin + i) = ParamPack::Val<double>::get(m_params, "
632 "m_corr_param_key, i);\n"
640 <<
"/// \\brief Calculate the change in point correlations due to "
641 "changing an occupant\n"
642 << indent <<
"void " << class_name
643 <<
"::_calc_delta_point_corr(int nlist_ind, int occ_i, int occ_f) const "
645 << indent <<
" m_params.pre_eval();\n";
648 for (
auto const &specialization : specializations) {
649 if (specializations.size() > 1) {
651 if (ispec > 0) ss <<
"else ";
652 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
654 ss << indent <<
" {\n"
655 << indent <<
" _point_prepare<" << specialization.second
657 << indent <<
" for(size_type i = 0; i < corr_size(); i++) {\n"
658 << indent <<
" ParamPack::Val<" << specialization.second
659 <<
">::set(m_params, m_corr_param_key, i, (this->*m_delta_func_table_"
660 << ispec <<
"[nlist_ind][i])(occ_i, occ_f));\n"
665 ss << indent <<
" m_params.post_eval();\n"
672 <<
"/// \\brief Calculate the change in select point correlations due to "
673 "changing an occupant\n"
674 << indent <<
"void " << class_name
675 <<
"::_calc_restricted_delta_point_corr(int nlist_ind, int occ_i, int "
676 "occ_f, double *corr_begin, size_type const *ind_list_begin, size_type "
677 "const *ind_list_end) const {\n"
679 <<
" _calc_restricted_delta_point_corr(nlist_ind, occ_i, occ_f, "
680 "ind_list_begin, ind_list_end);\n"
681 << indent <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
683 <<
" *(corr_begin + *ind_list_begin) = "
684 "ParamPack::Val<double>::get(m_params, m_corr_param_key, "
685 "*ind_list_begin);\n"
693 <<
"/// \\brief Calculate the change in select point correlations due to "
694 "changing an occupant\n"
695 << indent <<
"void " << class_name
696 <<
"::_calc_restricted_delta_point_corr(int nlist_ind, int occ_i, int "
697 "occ_f, size_type const *ind_list_begin, size_type const "
698 "*ind_list_end) const {\n"
699 << indent <<
" m_params.pre_eval();\n";
702 for (
auto const &specialization : specializations) {
703 if (specializations.size() > 1) {
705 if (ispec > 0) ss <<
"else ";
706 ss <<
"if(m_params.eval_mode() == " << specialization.first <<
")";
708 ss << indent <<
" {\n"
709 << indent <<
" _point_prepare<" << specialization.second
712 <<
" for(; ind_list_begin < ind_list_end; ind_list_begin++) {\n"
713 << indent <<
" ParamPack::Val<" << specialization.second
714 <<
">::set(m_params, m_corr_param_key, *ind_list_begin, "
715 "(this->*m_delta_func_table_"
716 << ispec <<
"[nlist_ind][*ind_list_begin])(occ_i, occ_f));\n"
721 ss << indent <<
" m_params.post_eval();\n" << indent <<
"}\n\n";
std::map< DoFKey, std::vector< BasisSet > > const & site_bases() const
Const access to dictionary of all site BasisSets.
std::map< DoFKey, std::vector< BasisSet > > const & global_bases() const
Const access to dictionary of all global BasisSets.
PrimType const & prim() const
Index n_functions() const
Total number of basis functions.
notstd::cloneable_ptr< ParamPackMixIn > m_param_pack_mix_in
ClexBasisWriter(Structure const &_prim, PARAM_PACK_TYPE const ¶m_pack_type)
Construct ClexBasisWriter, collecting requisite DoF info from '_prim'.
std::vector< std::unique_ptr< FunctionVisitor > > m_site_visitors
std::vector< std::unique_ptr< FunctionVisitor > > m_clust_visitors
void _initialize(Structure const &_prim, ParamPackMixIn const ¶mpack_mix_in)
virtual std::string clexulator_public_method_declarations_string(Structure const &_prim, std::vector< BasisSet > const &site_bases, std::string const &indent) const
virtual std::string clexulator_private_method_declarations_string(Structure const &_prim, std::vector< BasisSet > const &site_bases, std::string const &indent) const
virtual std::string clexulator_member_declarations_string(Structure const &_prim, std::vector< BasisSet > const &site_bases, std::string const &indent) const
virtual std::vector< ParamAllocation > param_pack_allocation(Structure const &_prim, std::vector< BasisSet > const &_bases) const
virtual std::vector< std::unique_ptr< FunctionVisitor > > clust_function_visitors() const
virtual std::vector< std::unique_ptr< FunctionVisitor > > site_function_visitors(std::string const &nlist_specifier="%n") const
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 > const & scalar_specializations() const
Dictionary of pairs ("EvalMode", "ScalarType") These correspond to the underlying scalar type to be u...
std::unique_ptr< ParamPackMixIn > clone() const
Clone the ParamPackMixIn.
Structure specifies the lattice and atomic basis of a crystal.
std::vector< DoFKey > all_local_dof_types(BasicStructure const &_struc)
std::vector< DoFKey > global_dof_types(BasicStructure const &_struc)
std::string clexulator_interface_declaration(std::string const &class_name, ClexBasis const &clex, ParamPackMixIn const &_param_pack_mix_in, std::string const &indent)
std::string clexulator_private_method_declarations(std::string const &class_name, ClexBasis const &clex, std::string const &indent)
std::string clexulator_member_declarations(std::string const &class_name, ClexBasis const &clex, ParamPackMixIn const &_param_pack_mix_in, std::vector< std::unique_ptr< OrbitFunctionTraits > > const &orbit_func_traits, Index N_flower, std::string const &indent)
std::string clexulator_public_method_declarations(std::string const &class_name, ClexBasis const &clex, std::string const &indent)
Traits const & traits(std::string const &dof_key)
Lookup DoFType::Traits in the global dictionary.
INDEX_TYPE Index
For long integer indexing: