26 std::unique_ptr<Resource>
makeClone()
const override 28 return std::make_unique<SOECPotentialMultiWalkerResource>(*this);
49 elec_neighbor_ions_(els),
50 ion_neighbor_elecs_(ions),
51 use_exact_spin_(use_exact_spin)
60 for (
size_t ig = 0; ig < els.
groups(); ig++)
84 for (
int ipp = 0; ipp <
ppset_.size(); ipp++)
96 const auto& dist = ble.getDistRow(jel);
97 const auto& displ = ble.getDisplRow(jel);
100 if (
pp_[iat] !=
nullptr && dist[iat] <
pp_[iat]->getRmax())
104 pairpot =
pp_[iat]->evaluateOneExactSpinIntegration(P, iat,
psi_, jel, dist[iat], -displ[iat]);
106 pairpot =
pp_[iat]->evaluateOne(P, iat,
psi_, jel, dist[iat], -displ[iat]);
108 NeighborIons.push_back(iat);
120 for (
int ipp = 0; ipp <
ppset_.size(); ipp++)
128 const auto& displ = ble.getDisplRow(jel);
129 for (
int iat = 0; iat <
num_ions_; iat++)
130 if (
pp_[iat] !=
nullptr && dist[iat] <
pp_[iat]->getRmax())
131 value_ +=
pp_[iat]->evaluateValueAndDerivatives(P, iat,
psi_, jel, dist[iat], -displ[iat], optvars, dlogpsi,
150 std::optional<ListenerOption<Real>> l_opt(std::in_place, listeners, listeners_ions);
162 const size_t nw = o_list.size();
164 for (
size_t iw = 0; iw < nw; iw++)
170 for (
size_t ipp = 0; ipp < O.ppset_.size(); ipp++)
175 const auto& ble = P.getDistTableAB(O.my_table_index_);
177 for (
size_t iat = 0; iat < O.num_ions_; iat++)
178 O.ion_neighbor_elecs_.getNeighborList(iat).clear();
179 for (
size_t jel = 0; jel < P.getTotalNum(); jel++)
180 O.elec_neighbor_ions_.getNeighborList(jel).clear();
182 for (
size_t ig = 0; ig < P.groups(); ig++)
184 auto& joblist = O.sopp_jobs_[ig];
187 for (
size_t jel = P.first(ig); jel < P.last(ig); jel++)
189 const auto& dist = ble.getDistRow(jel);
190 const auto& displ = ble.getDisplRow(jel);
191 std::vector<int>& NeighborIons = O.elec_neighbor_ions_.getNeighborList(jel);
192 for (
size_t iat = 0; iat < O.num_ions_; iat++)
193 if (O.pp_[iat] !=
nullptr && dist[iat] < O.pp_[iat]->getRmax())
195 NeighborIons.push_back(iat);
196 O.ion_neighbor_elecs_.getNeighborList(iat).push_back(jel);
197 joblist.emplace_back(iat, jel, dist[iat], -displ[iat]);
206 auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
207 auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
208 ve_samples.resize(nw, pset_leader.getTotalNum());
209 vi_samples.resize(nw, O_leader.ion_config_.getTotalNum());
212 auto pp_component = std::find_if(O_leader.ppset_.begin(), O_leader.ppset_.end(), [](
auto& ptr) {
return bool(ptr); });
213 assert(pp_component != std::end(O_leader.ppset_));
219 assert(&O_leader.psi_ == &wf_list.
getLeader());
220 for (
size_t iw = 0; iw < nw; iw++)
224 std::vector<RealType> pairpots(nw);
226 soecp_potential_list.reserve(nw);
227 soecp_component_list.reserve(nw);
228 pset_list.reserve(nw);
229 psi_list.reserve(nw);
230 batch_list.reserve(nw);
232 for (
size_t ig = 0; ig < pset_leader.groups(); ig++)
236 size_t max_num_jobs = 0;
237 for (
size_t iw = 0; iw < nw; iw++)
240 max_num_jobs = std::max(max_num_jobs, O.
sopp_jobs_[ig].size());
243 for (
size_t jobid = 0; jobid < max_num_jobs; jobid++)
245 soecp_potential_list.clear();
246 soecp_component_list.clear();
250 for (
size_t iw = 0; iw < nw; iw++)
253 if (jobid < O.sopp_jobs_[ig].size())
256 soecp_potential_list.push_back(O);
257 soecp_component_list.push_back(*O.pp_[job.ion_id]);
258 pset_list.push_back(p_list[iw]);
259 psi_list.push_back(wf_list[iw]);
260 batch_list.push_back(job);
265 O_leader.mw_res_handle_.getResource().collection);
267 for (
size_t j = 0; j < soecp_potential_list.size(); j++)
269 soecp_potential_list[j].get().value_ += pairpots[j];
273 auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
274 auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
276 ve_samples(iw, batch_list[j].
get().electron_id) += pairpots[j];
277 vi_samples(iw, batch_list[j].
get().ion_id) += pairpots[j];
285 auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
286 auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
287 int num_electrons = pset_leader.getTotalNum();
288 for (
int iw = 0; iw < nw; iw++)
290 Vector<Real> ve_sample(ve_samples.begin(iw), num_electrons);
291 Vector<Real> vi_sample(vi_samples.begin(iw), O_leader.num_ions_);
293 listener.
report(iw, O_leader.getName(), ve_sample);
295 listener.
report(iw, O_leader.getName(), vi_sample);
305 for (
int ig = 0; ig <
ppset_.size(); ++ig)
307 myclone->addComponent(ig, std::unique_ptr<SOECPComponent>(
ppset_[ig]->
makeClone(qp)));
313 for (
int iat = 0; iat <
pp_.size(); iat++)
315 pp_[iat] = ppot.get();
316 ppset_[groupID] = std::move(ppot);
321 auto new_res = std::make_unique<SOECPotentialMultiWalkerResource>();
322 for (
int ig = 0; ig <
ppset_.size(); ig++)
325 ppset_[ig]->getVP()->createResource(new_res->collection);
328 auto resource_index = collection.
addResource(std::move(new_res));
void evaluateImpl(ParticleSet &elec, bool keep_grid=false)
void twoBodyQuantumDomain(const ParticleSet &P)
set quantum domain for two-body operator
std::vector< std::unique_ptr< SOECPComponent > > ppset_
size_t addResource(std::unique_ptr< Resource > &&res, bool noprint=false)
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) final
void takebackResource(ResourceHandle< RS > &res_handle)
helper functions for EinsplineSetBuilder
void mw_evaluate(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const override
Evaluate the contribution of this component of multiple walkers.
const DistRow & getDistRow(int iel) const
return a row of distances for a given target particle
size_t getTotalNum() const
static void mw_prepareGroup(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int ig)
batched version of prepareGroup
Return_t evaluateValueAndDerivatives(ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Evaluate value and derivatives wrt the optimizables.
const bool use_exact_spin_
An object of this type is a listener expecting a callback to the report function with a vector of val...
std::vector< std::vector< NLPPJob< RealType > > > sopp_jobs_
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
Return a shared resource to a collection.
std::unique_ptr< Resource > makeClone() const override
NeighborLists ion_neighbor_elecs_
neighborlist of ions
~SOECPotential() override
void createResource(ResourceCollection &collection) const override
Initialize a shared resource and hand it to a collection.
int my_table_index_
index of distance table for ion-el pair
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
ParticleIndex GroupID
Species ID.
std::vector< SOECPComponent * > pp_
int getTotalNum() const
return the number of species
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
int groups() const
return the number of groups
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
CASTTYPE & getCastedElement(size_t i) const
int groupsize(int igroup) const
return the size of a group
class to handle a set of variables that can be modified during optimizations
Matrix< Real > ve_samples
NeighborLists elec_neighbor_ions_
neighborlist of electrons
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
Acquire a shared resource from a collection.
void setEnergyDomain(EnergyDomains edomain)
Set the Energy Domain.
static void mw_evaluateImpl(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::optional< ListenerOption< Real >> listeners, bool keep_grid=false)
ResourceHandle< SOECPotentialMultiWalkerResource > mw_res_handle_
int num_ions_
number of ions
QMCTraits::TensorType generateRandomRotationMatrix(RandomBase< QMCTraits::FullPrecRealType > &rng)
Create a random 3D rotation matrix using a random generator.
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
FullPrecRealType Return_t
type of return value of evaluate
Return_t evaluateDeterministic(ParticleSet &P) override
Evaluate the local energy contribution of this component, deterministically based on current state...
ParticleSet & ion_config_
std::vector< std::reference_wrapper< T > > RefVector
CASTTYPE & getCastedLeader() const
Class to represent a many-body trial wave function.
Return_t value_
current value
void addComponent(int groupID, std::unique_ptr< SOECPComponent > &&pp)
ResourceCollection collection
std::vector< int > & getNeighborList(int source)
get the neighbor list of the source particle
ResourceHandle< RS > lendResource()
RandomBase< FullPrecRealType > * my_rng_
SOECPotentialMultiWalkerResource()
SOECPotential(ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool use_exact_spin)
constructor
Convenience container for common optional element to mw_eval.._impl.
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
Matrix< Real > vi_samples
static void mw_evaluateOne(const RefVectorWithLeader< SOECPComponent > &soecp_component_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVectorWithLeader< TrialWaveFunction > &psi_list, const RefVector< const NLPPJob< RealType >> &joblist, std::vector< RealType > &pairpots, ResourceCollection &collection)
void mw_evaluatePerParticle(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< Real >> &listeners, const std::vector< ListenerVector< Real >> &listeners_ions) const override