11//
22// Created by Yury Lysogorskiy on 24.06.24
33//
4- #include " ace/tdace_evaluator .h"
4+ #include " ace/grace_fs_evaluator .h"
55#include " ace-evaluator/ace_types.h"
66#include " ace/ace_yaml_input.h"
77#include " ace-evaluator/ace_radial.h"
1010#define sqr (x ) ((x)*(x))
1111const DOUBLE_TYPE pi = 3.14159265358979323846264338327950288419 ; // pi
1212
13- void TDACEEmbeddingSpecification ::from_YAML (YAML_PACE::Node emb_yaml) {
13+ void GRACEFSEmbeddingSpecification ::from_YAML (YAML_PACE::Node emb_yaml) {
1414 this ->type = emb_yaml[" type" ].as <string>();
1515 this ->FS_parameters = emb_yaml[" params" ].as <vector<double >>();
1616 if (this ->FS_parameters .size () % 2 == 0 )
@@ -21,7 +21,7 @@ void TDACEEmbeddingSpecification::from_YAML(YAML_PACE::Node emb_yaml) {
2121// this->ndensity = emb_yaml["ndensity"].as<DENSITY_TYPE>();
2222}
2323
24- void TDACERadialFunction ::from_YAML (YAML_PACE::Node bond_yaml) {
24+ void GRACEFSRadialFunction ::from_YAML (YAML_PACE::Node bond_yaml) {
2525
2626 this ->radbasename = bond_yaml[" radbasename" ].as <string>();
2727
@@ -40,7 +40,7 @@ void TDACERadialFunction::from_YAML(YAML_PACE::Node bond_yaml) {
4040 this ->crad .set_flatten_vector (crad_flat);
4141
4242 auto Z_flat = bond_yaml[" Z" ].as <vector<DOUBLE_TYPE>>();
43- this ->Z .init (Z_shape[0 ], Z_shape[1 ]);
43+ this ->Z .init (Z_shape[0 ], Z_shape[1 ], " Z " );
4444 Z.set_flatten_vector (Z_flat);
4545
4646
@@ -51,7 +51,7 @@ void TDACERadialFunction::from_YAML(YAML_PACE::Node bond_yaml) {
5151 if (bond_yaml[" dcut_in" ]) dcut_in = bond_yaml[" dcut_in" ].as <DOUBLE_TYPE>();
5252}
5353
54- void TDACEBasisFunction ::from_YAML (YAML_PACE::Node node) {
54+ void GRACEFSBasisFunction ::from_YAML (YAML_PACE::Node node) {
5555 this ->mu0 = node[" mu0" ].as <SPECIES_TYPE>();
5656
5757 this ->ns = node[" ns" ].as <NS_TYPE>();
@@ -73,7 +73,7 @@ void TDACEBasisFunction::from_YAML(YAML_PACE::Node node) {
7373 throw invalid_argument (" ndensity != coeff.size" );
7474}
7575
76- void TDACEBasisFunction ::print () const {
76+ void GRACEFSBasisFunction ::print () const {
7777 cout << " TDACEBasisFunction(mu0=" << this ->mu0 << " , rank=" << (int ) this ->rank << endl;
7878 int rank = this ->rank ;
7979
@@ -85,11 +85,11 @@ void TDACEBasisFunction::print() const {
8585 cout << " )" << endl;
8686}
8787
88- TDACEBasisSet::TDACEBasisSet (const string &filename) {
88+ GRACEFSBasisSet::GRACEFSBasisSet (const string &filename) {
8989 this ->load (filename);
9090}
9191
92- void TDACEBasisSet ::load (const string &filename) {
92+ void GRACEFSBasisSet ::load (const string &filename) {
9393 this ->filename = filename;
9494
9595 if (!if_file_exist (filename)) {
@@ -122,9 +122,9 @@ void TDACEBasisSet::load(const string &filename) {
122122 for (const auto &mu_functions_node: YAML_input[" functions" ]) {
123123 SPECIES_TYPE mu0 = mu_functions_node.first .as <SPECIES_TYPE>();
124124 const auto &functions_list = mu_functions_node.second ;
125- vector<TDACEBasisFunction > basis_functions_vec;
125+ vector<GRACEFSBasisFunction > basis_functions_vec;
126126 for (const auto &func_node: functions_list) {
127- TDACEBasisFunction func;
127+ GRACEFSBasisFunction func;
128128 func.from_YAML (func_node);
129129 basis_functions_vec.emplace_back (func);
130130 if (func.rank > rankmax)
@@ -171,7 +171,7 @@ void TDACEBasisSet::load(const string &filename) {
171171 else this ->scale = 1.0 ;
172172}
173173
174- void TDACEBasisSet ::convert_to_flatten_arrays () {
174+ void GRACEFSBasisSet ::convert_to_flatten_arrays () {
175175 ranks_flatten.resize (nelements);
176176 ndensity_flatten.resize (nelements);
177177 num_ms_combs_flatten.resize (nelements);
@@ -262,9 +262,9 @@ void TDACEBasisSet::convert_to_flatten_arrays() {
262262 }
263263}
264264
265- void TDACEBasisSet ::FS_values_and_derivatives (Array1D<DOUBLE_TYPE> &rhos, DOUBLE_TYPE &value,
266- Array1D<DOUBLE_TYPE> &derivatives,
267- SPECIES_TYPE mu_i) {
265+ void GRACEFSBasisSet ::FS_values_and_derivatives (Array1D<DOUBLE_TYPE> &rhos, DOUBLE_TYPE &value,
266+ Array1D<DOUBLE_TYPE> &derivatives,
267+ SPECIES_TYPE mu_i) {
268268 DOUBLE_TYPE F, DF = 0 , wpre, mexp;
269269 DENSITY_TYPE ndensity = this ->ndensitymax ;
270270
@@ -283,7 +283,7 @@ void TDACEBasisSet::FS_values_and_derivatives(Array1D<DOUBLE_TYPE> &rhos, DOUBLE
283283 }
284284}
285285
286- void TDACEBasisSet ::print_functions () {
286+ void GRACEFSBasisSet ::print_functions () {
287287 for (int el = 0 ; el < nelements; el++) {
288288 printf (" ============================= Element: %d =====================\n " , el);
289289 for (const auto &func: basis[el]) {
@@ -292,12 +292,12 @@ void TDACEBasisSet::print_functions() {
292292 }
293293}
294294
295- void TDACEBEvaluator ::set_basis (TDACEBasisSet &basis_set) {
295+ void GRACEFSBEvaluator ::set_basis (GRACEFSBasisSet &basis_set) {
296296 this ->basis_set = basis_set;
297297 init (this ->basis_set );
298298}
299299
300- void TDACEBEvaluator ::init (TDACEBasisSet &basis_set) {
300+ void GRACEFSBEvaluator ::init (GRACEFSBasisSet &basis_set) {
301301 A.init (basis_set.nradmax + 1 , basis_set.lmax + 1 , " A" );
302302
303303 rhos.init (basis_set.ndensitymax , " rhos" );
@@ -329,7 +329,7 @@ void TDACEBEvaluator::init(TDACEBasisSet &basis_set) {
329329}
330330
331331
332- void TDACEBEvaluator ::resize_neighbours_cache (int max_jnum) {
332+ void GRACEFSBEvaluator ::resize_neighbours_cache (int max_jnum) {
333333 if (R_cache.get_dim (0 ) < max_jnum) {
334334
335335 // TODO: implement grow
@@ -360,7 +360,7 @@ void TDACEBEvaluator::resize_neighbours_cache(int max_jnum) {
360360}
361361
362362
363- void TDACEBEvaluator ::compute_atom (int i, DOUBLE_TYPE **x, const SPECIES_TYPE *type, const int jnum, const int *jlist) {
363+ void GRACEFSBEvaluator ::compute_atom (int i, DOUBLE_TYPE **x, const SPECIES_TYPE *type, const int jnum, const int *jlist) {
364364 per_atom_calc_timer.start ();
365365
366366 setup_timer.start ();
@@ -382,11 +382,11 @@ void TDACEBEvaluator::compute_atom(int i, DOUBLE_TYPE **x, const SPECIES_TYPE *t
382382
383383 int j, jj, func_ind, ms_ind;
384384
385- DOUBLE_TYPE Y{ 0 } , Y_DR{ 0 .} ;
386- DOUBLE_TYPE B{ 0 .} ;
387- DOUBLE_TYPE dB{ 0 } ;
385+ DOUBLE_TYPE Y, Y_DR;
386+ DOUBLE_TYPE B;
387+ DOUBLE_TYPE dB;
388388 Array1D<DOUBLE_TYPE> A_cache (basis_set.rankmax );
389- ACEDRealYcomponent grad_phi_nlm{ 0 } , DY{ 0 .} ;
389+ ACEDRealYcomponent grad_phi_nlm, DY;
390390
391391 // size is +1 of max to avoid out-of-boundary array access in double-triangular scheme
392392 Array1D<DOUBLE_TYPE> A_forward_prod (basis_set.rankmax + 1 );
@@ -495,6 +495,8 @@ void TDACEBEvaluator::compute_atom(int i, DOUBLE_TYPE **x, const SPECIES_TYPE *t
495495
496496 // loop for computing A's
497497 // for rank > 1
498+ // A_construction_timer2.start();
499+
498500 for (n = 0 ; n < basis_set.nradmax ; n++) {
499501 auto &A_lm = A (n);
500502 for (l = 0 ; l <= basis_set.lmax ; l++) {
@@ -512,6 +514,7 @@ void TDACEBEvaluator::compute_atom(int i, DOUBLE_TYPE **x, const SPECIES_TYPE *t
512514
513515 }
514516 }
517+ // A_construction_timer2.stop();
515518
516519 } // end loop over neighbours
517520 A_construction_timer.stop ();
@@ -687,8 +690,9 @@ void TDACEBEvaluator::compute_atom(int i, DOUBLE_TYPE **x, const SPECIES_TYPE *t
687690 per_atom_calc_timer.stop ();
688691}
689692
690- void TDACEBEvaluator ::init_timers () {
693+ void GRACEFSBEvaluator ::init_timers () {
691694 A_construction_timer.init ();
695+ A_construction_timer2.init ();
692696 forces_calc_loop_timer.init ();
693697 energy_calc_timer.init ();
694698 per_atom_calc_timer.init ();
@@ -698,7 +702,7 @@ void TDACEBEvaluator::init_timers() {
698702}
699703
700704
701- void TDACEBEvaluator ::load_active_set (const string &asi_filename) {
705+ void GRACEFSBEvaluator ::load_active_set (const string &asi_filename) {
702706 cnpy::npz_t asi_npz = cnpy::npz_load (asi_filename);
703707 if (asi_npz.size () != this ->basis_set .nelements ) {
704708 stringstream ss;
@@ -746,7 +750,7 @@ void TDACEBEvaluator::load_active_set(const string &asi_filename) {
746750}
747751
748752
749- void TDACERadialFunction ::init () {
753+ void GRACEFSRadialFunction ::init () {
750754
751755 gr.init (nradbasemax, " gr" );
752756 dgr.init (nradbasemax, " dgr" );
@@ -765,7 +769,7 @@ void TDACERadialFunction::init() {
765769 * @param rc
766770 * @param x
767771 */
768- void TDACERadialFunction ::simplified_bessel (DOUBLE_TYPE rc, DOUBLE_TYPE x) {
772+ void GRACEFSRadialFunction ::simplified_bessel (DOUBLE_TYPE rc, DOUBLE_TYPE x) {
769773 if (x < rc) {
770774 gr (0 ) = simplified_bessel_aux (x, rc, 0 );
771775 dgr (0 ) = dsimplified_bessel_aux (x, rc, 0 );
@@ -784,8 +788,8 @@ void TDACERadialFunction::simplified_bessel(DOUBLE_TYPE rc, DOUBLE_TYPE x) {
784788 }
785789}
786790
787- void TDACERadialFunction ::radbase (DOUBLE_TYPE lam, DOUBLE_TYPE cut, DOUBLE_TYPE dcut, string radbasename, DOUBLE_TYPE r,
788- DOUBLE_TYPE cut_in, DOUBLE_TYPE dcut_in) {
791+ void GRACEFSRadialFunction ::radbase (DOUBLE_TYPE lam, DOUBLE_TYPE cut, DOUBLE_TYPE dcut, string radbasename, DOUBLE_TYPE r,
792+ DOUBLE_TYPE cut_in, DOUBLE_TYPE dcut_in) {
789793 /* lam is given by the formula (24), that contains cut */
790794 if (r <= cut_in - dcut_in || r >= cut) {
791795 gr.fill (0 );
@@ -799,14 +803,14 @@ void TDACERadialFunction::radbase(DOUBLE_TYPE lam, DOUBLE_TYPE cut, DOUBLE_TYPE
799803 }
800804}
801805
802- void TDACERadialFunction ::all_radfunc (DOUBLE_TYPE r) {
806+ void GRACEFSRadialFunction ::all_radfunc (DOUBLE_TYPE r) {
803807
804808 // set up radial functions
805809 radbase (rad_lamba, rcut, dcut, radbasename, r, 0 , 0 ); // update gr, dgr
806810 radfunc (); // update fr(nr, l), dfr(nr, l)
807811}
808812
809- void TDACERadialFunction ::radfunc () {
813+ void GRACEFSRadialFunction ::radfunc () {
810814 DOUBLE_TYPE frval, dfrval;
811815 for (NS_TYPE n = 0 ; n < nradmax; n++) {
812816 for (LS_TYPE l = 0 ; l <= lmax; l++) {
@@ -824,23 +828,23 @@ void TDACERadialFunction::radfunc() {
824828 }
825829}
826830
827- void TDACERadialFunction ::setuplookupRadspline () {
831+ void GRACEFSRadialFunction ::setuplookupRadspline () {
828832 using namespace std ::placeholders;
829833 splines_gk.setupSplines (gr.get_size (),
830- std::bind (&TDACERadialFunction ::radbase, this , this ->rad_lamba ,
834+ std::bind (&GRACEFSRadialFunction ::radbase, this , this ->rad_lamba ,
831835 this ->rcut , this ->dcut ,
832836 this ->radbasename ,
833837 _1, 0 , 0 ),// update gr, dgr
834838 gr.get_data (),
835839 dgr.get_data (), deltaSplineBins, this ->rcut );
836840
837841 splines_rnl.setupSplines (fr.get_size (),
838- std::bind (&TDACERadialFunction ::all_radfunc, this , _1), // update fr(nr, l), dfr(nr, l)
842+ std::bind (&GRACEFSRadialFunction ::all_radfunc, this , _1), // update fr(nr, l), dfr(nr, l)
839843 fr.get_data (),
840844 dfr.get_data (), deltaSplineBins, rcut);
841845}
842846
843- void TDACERadialFunction ::evaluate (DOUBLE_TYPE r, SPECIES_TYPE mu_i, SPECIES_TYPE mu_j) {
847+ void GRACEFSRadialFunction ::evaluate (DOUBLE_TYPE r, SPECIES_TYPE mu_i, SPECIES_TYPE mu_j) {
844848 splines_gk.calcSplines (r);
845849 for (NS_TYPE nr = 0 ; nr < nradbasemax; nr++) {
846850 gr (nr) = splines_gk.values (nr);
0 commit comments