@@ -108,23 +108,25 @@ void projectors::OnsiteProjector<T, Device>::init(const std::string& orbital_dir
108108 const ModuleBase::matrix& ekb)
109109{
110110 this ->device = base_device::get_device_type<Device>(this ->ctx );
111- if (!this ->initialed )
112- {
113- this ->ucell = ucell_in;
114- this ->ntype = ucell_in->ntype ;
111+
112+ this ->ucell = ucell_in;
113+ this ->ntype = ucell_in->ntype ;
115114
116- this ->pw_basis_ = &pw_basis;
117- this ->sf_ = &sf;
115+ this ->pw_basis_ = &pw_basis;
116+ this ->sf_ = &sf;
118117
119- std::vector<std::string> orb_files (ntype);
120- std::vector<int > nproj (ntype);
121- int sum_nproj = 0 ;
122- for (int it=0 ;it<ntype;++it)
123- {
124- orb_files[it] = ucell->orbital_fn [it];
125- nproj[it] = ucell->atoms [it].nwl ;
126- sum_nproj += nproj[it];
127- }
118+ std::vector<std::string> orb_files (ntype);
119+ std::vector<int > nproj (ntype);
120+ int sum_nproj = 0 ;
121+ for (int it=0 ;it<ntype;++it)
122+ {
123+ orb_files[it] = ucell->orbital_fn [it];
124+ nproj[it] = ucell->atoms [it].nwl ;
125+ sum_nproj += nproj[it];
126+ }
127+ // do orbital modulate only once
128+ if (!this ->initialed )
129+ {
128130 this ->lproj .resize (sum_nproj);
129131 int index = 0 ;
130132 for (int it=0 ;it<ntype;++it)
@@ -157,7 +159,7 @@ void projectors::OnsiteProjector<T, Device>::init(const std::string& orbital_dir
157159 iproj,
158160 onsite_r);
159161
160- ModuleBase::timer::tick ( " OnsiteProj " , " cubspl_tabulate " );
162+
161163 // STAGE 0 - making the interpolation table
162164 // CACHE 0 - if cache the irow2it, irow2iproj, irow2m, itiaiprojm2irow, <G+k|p> can be reused for
163165 // SCF, RELAX and CELL-RELAX calculation
@@ -166,24 +168,26 @@ void projectors::OnsiteProjector<T, Device>::init(const std::string& orbital_dir
166168 RadialProjection::RadialProjector::_build_forward_map (it2ia, it2iproj, lproj, itiaiprojm2irow_);
167169 // rp_._build_sbt_tab(rgrid, projs, lproj, nq, dq);
168170 rp_._build_sbt_tab (nproj, rgrid, projs, lproj, nq, dq, ucell_in->omega , psi.npol , tab, nhtol);
169- // For being compatible with present cal_force and cal_stress framework
170- // uncomment the following code block if you want to use the FS_Nonlocal_tools
171- if (this ->tab_atomic_ == nullptr )
172- {
173- this ->tot_nproj = itiaiprojm2irow_.size ();
174- this ->npwx_ = this ->pw_basis_ ->npwk_max ;
175- this ->size_vproj = this ->tot_nproj * this ->npwx_ ;
176- resmem_complex_op ()(this ->ctx , this ->tab_atomic_ , this ->size_vproj , " OnsiteP::tab_atomic_" );
177- }
178-
179- delete this ->fs_tools ; // it is okay to delete nullptr
180- this ->fs_tools = new hamilt::FS_Nonlocal_tools<T, Device>(
181- nproj, lproj, tab, nhtol, this ->tab_atomic_ , ucell_in, &psi, &kv, &pw_basis, &sf, wg, ekb);
182171
183172 ModuleBase::timer::tick (" OnsiteProj" , " cubspl_tabulate" );
184173
185174 this ->initialed = true ;
186175 }
176+
177+ // For being compatible with present cal_force and cal_stress framework
178+ // uncomment the following code block if you want to use the FS_Nonlocal_tools
179+ ModuleBase::timer::tick (" OnsiteProj" , " cubspl_tabulate" );
180+ {
181+ this ->tot_nproj = itiaiprojm2irow_.size ();
182+ this ->npwx_ = this ->pw_basis_ ->npwk_max ;
183+ this ->size_vproj = this ->tot_nproj * this ->npwx_ ;
184+ resmem_complex_op ()(this ->ctx , this ->tab_atomic_ , this ->size_vproj , " OnsiteP::tab_atomic_" );
185+ }
186+
187+ delete this ->fs_tools ; // it is okay to delete nullptr
188+ this ->fs_tools = new hamilt::FS_Nonlocal_tools<T, Device>(
189+ nproj, lproj, tab, nhtol, this ->tab_atomic_ , ucell_in, &psi, &kv, &pw_basis, &sf, wg, ekb);
190+ ModuleBase::timer::tick (" OnsiteProj" , " cubspl_tabulate" );
187191}
188192
189193template <typename T, typename Device>
0 commit comments