Skip to content

Commit

Permalink
change variables in SOECPotential to follow convention
Browse files Browse the repository at this point in the history
  • Loading branch information
camelto2 committed Mar 9, 2023
1 parent bf0ba13 commit 4ba73a0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 75 deletions.
120 changes: 60 additions & 60 deletions src/QMCHamiltonians/SOECPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ struct SOECPotential::SOECPotentialMultiWalkerResource : public Resource
*\param psi Trial wave function
*/
SOECPotential::SOECPotential(ParticleSet& ions, ParticleSet& els, TrialWaveFunction& psi)
: myRNG_(nullptr), IonConfig_(ions), Psi_(psi), Peln_(els), ElecNeighborIons_(els), IonNeighborElecs_(ions)
: my_rng_(nullptr), ion_config_(ions), psi_(psi), peln_(els), elec_neighbor_ions_(els), ion_neighbor_elecs_(ions)
{
setEnergyDomain(POTENTIAL);
twoBodyQuantumDomain(ions, els);
myTableIndex_ = els.addTable(ions);
NumIons_ = ions.getTotalNum();
PP_.resize(NumIons_, nullptr);
PPset_.resize(IonConfig_.getSpeciesSet().getTotalNum());
my_table_index_ = els.addTable(ions);
num_ions_ = ions.getTotalNum();
pp_.resize(num_ions_, nullptr);
ppset_.resize(ion_config_.getSpeciesSet().getTotalNum());
sopp_jobs_.resize(els.groups());
for (size_t ig = 0; ig < els.groups(); ig++)
sopp_jobs_[ig].reserve(2 * els.groupsize(ig));
Expand All @@ -71,28 +71,28 @@ void SOECPotential::evaluateImpl(ParticleSet& P, bool keep_grid)
{
value_ = 0.0;
if (!keep_grid)
for (int ipp = 0; ipp < PPset_.size(); ipp++)
if (PPset_[ipp])
PPset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*myRNG_));
for (int ipp = 0; ipp < ppset_.size(); ipp++)
if (ppset_[ipp])
ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*my_rng_));

const auto& myTable = P.getDistTableAB(myTableIndex_);
for (int iat = 0; iat < NumIons_; iat++)
IonNeighborElecs_.getNeighborList(iat).clear();
const auto& ble = P.getDistTableAB(my_table_index_);
for (int iat = 0; iat < num_ions_; iat++)
ion_neighbor_elecs_.getNeighborList(iat).clear();
for (int jel = 0; jel < P.getTotalNum(); jel++)
ElecNeighborIons_.getNeighborList(jel).clear();
elec_neighbor_ions_.getNeighborList(jel).clear();

for (int jel = 0; jel < P.getTotalNum(); jel++)
{
const auto& dist = myTable.getDistRow(jel);
const auto& displ = myTable.getDisplRow(jel);
std::vector<int>& NeighborIons = ElecNeighborIons_.getNeighborList(jel);
for (int iat = 0; iat < NumIons_; iat++)
if (PP_[iat] != nullptr && dist[iat] < PP_[iat]->getRmax())
const auto& dist = ble.getDistRow(jel);
const auto& displ = ble.getDisplRow(jel);
std::vector<int>& NeighborIons = elec_neighbor_ions_.getNeighborList(jel);
for (int iat = 0; iat < num_ions_; iat++)
if (pp_[iat] != nullptr && dist[iat] < pp_[iat]->getRmax())
{
RealType pairpot = PP_[iat]->evaluateOne(P, iat, Psi_, jel, dist[iat], -displ[iat]);
RealType pairpot = pp_[iat]->evaluateOne(P, iat, psi_, jel, dist[iat], -displ[iat]);
value_ += pairpot;
NeighborIons.push_back(iat);
IonNeighborElecs_.getNeighborList(iat).push_back(jel);
ion_neighbor_elecs_.getNeighborList(iat).push_back(jel);
}
}
}
Expand All @@ -103,18 +103,18 @@ SOECPotential::Return_t SOECPotential::evaluateValueAndDerivatives(ParticleSet&
Vector<ValueType>& dhpsioverpsi)
{
value_ = 0.0;
for (int ipp = 0; ipp < PPset_.size(); ipp++)
if (PPset_[ipp])
PPset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*myRNG_));
for (int ipp = 0; ipp < ppset_.size(); ipp++)
if (ppset_[ipp])
ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*my_rng_));

const auto& myTable = P.getDistTableAB(myTableIndex_);
const auto& ble = P.getDistTableAB(my_table_index_);
for (int jel = 0; jel < P.getTotalNum(); jel++)
{
const auto& dist = myTable.getDistRow(jel);
const auto& displ = myTable.getDisplRow(jel);
for (int iat = 0; iat < NumIons_; iat++)
if (PP_[iat] != nullptr && dist[iat] < PP_[iat]->getRmax())
value_ += PP_[iat]->evaluateValueAndDerivatives(P, iat, Psi_, jel, dist[iat], -displ[iat], optvars, dlogpsi,
const auto& dist = ble.getDistRow(jel);
const auto& displ = ble.getDisplRow(jel);
for (int iat = 0; iat < num_ions_; iat++)
if (pp_[iat] != nullptr && dist[iat] < pp_[iat]->getRmax())
value_ += pp_[iat]->evaluateValueAndDerivatives(P, iat, psi_, jel, dist[iat], -displ[iat], optvars, dlogpsi,
dhpsioverpsi);
}
return value_;
Expand Down Expand Up @@ -153,17 +153,17 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l
const ParticleSet& P(p_list[iw]);

if (!keep_grid)
for (size_t ipp = 0; ipp < O.PPset_.size(); ipp++)
if (O.PPset_[ipp])
O.PPset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*O.myRNG_));
for (size_t ipp = 0; ipp < O.ppset_.size(); ipp++)
if (O.ppset_[ipp])
O.ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*O.my_rng_));

//loop over all the ions
const auto& myTable = P.getDistTableAB(O.myTableIndex_);
const auto& ble = P.getDistTableAB(O.my_table_index_);
//clear elec and ion neighbor lists
for (size_t iat = 0; iat < O.NumIons_; iat++)
O.IonNeighborElecs_.getNeighborList(iat).clear();
for (size_t iat = 0; iat < O.num_ions_; iat++)
O.ion_neighbor_elecs_.getNeighborList(iat).clear();
for (size_t jel = 0; jel < P.getTotalNum(); jel++)
O.ElecNeighborIons_.getNeighborList(jel).clear();
O.elec_neighbor_ions_.getNeighborList(jel).clear();

for (size_t ig = 0; ig < P.groups(); ig++) // loop over species
{
Expand All @@ -172,14 +172,14 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l

for (size_t jel = P.first(ig); jel < P.last(ig); jel++)
{
const auto& dist = myTable.getDistRow(jel);
const auto& displ = myTable.getDisplRow(jel);
std::vector<int>& NeighborIons = O.ElecNeighborIons_.getNeighborList(jel);
for (size_t iat = 0; iat < O.NumIons_; iat++)
if (O.PP_[iat] != nullptr && dist[iat] < O.PP_[iat]->getRmax())
const auto& dist = ble.getDistRow(jel);
const auto& displ = ble.getDisplRow(jel);
std::vector<int>& NeighborIons = O.elec_neighbor_ions_.getNeighborList(jel);
for (size_t iat = 0; iat < O.num_ions_; iat++)
if (O.pp_[iat] != nullptr && dist[iat] < O.pp_[iat]->getRmax())
{
NeighborIons.push_back(iat);
O.IonNeighborElecs_.getNeighborList(iat).push_back(jel);
O.ion_neighbor_elecs_.getNeighborList(iat).push_back(jel);
joblist.emplace_back(iat, jel, dist[iat], -displ[iat]);
}
}
Expand All @@ -192,19 +192,19 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l
auto& ve_samples = O_leader.mw_res_->ve_samples;
auto& vi_samples = O_leader.mw_res_->vi_samples;
ve_samples.resize(nw, pset_leader.getTotalNum());
vi_samples.resize(nw, O_leader.IonConfig_.getTotalNum());
vi_samples.resize(nw, O_leader.ion_config_.getTotalNum());
}

auto pp_component = std::find_if(O_leader.PPset_.begin(), O_leader.PPset_.end(), [](auto& ptr) { return bool(ptr); });
assert(pp_component != std::end(O_leader.PPset_));
auto pp_component = std::find_if(O_leader.ppset_.begin(), O_leader.ppset_.end(), [](auto& ptr) { return bool(ptr); });
assert(pp_component != std::end(O_leader.ppset_));

RefVector<SOECPotential> soecp_potential_list;
RefVectorWithLeader<SOECPComponent> soecp_component_list(**pp_component);
RefVectorWithLeader<ParticleSet> pset_list(pset_leader);
RefVectorWithLeader<TrialWaveFunction> psi_list(O_leader.Psi_);
assert(&O_leader.Psi_ == &wf_list.getLeader());
RefVectorWithLeader<TrialWaveFunction> psi_list(O_leader.psi_);
assert(&O_leader.psi_ == &wf_list.getLeader());
for (size_t iw = 0; iw < nw; iw++)
assert(&o_list.getCastedElement<SOECPotential>(iw).Psi_ == &wf_list[iw]);
assert(&o_list.getCastedElement<SOECPotential>(iw).psi_ == &wf_list[iw]);

RefVector<const NLPPJob<RealType>> batch_list;
std::vector<RealType> pairpots(nw);
Expand Down Expand Up @@ -240,7 +240,7 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l
{
const auto& job = O.sopp_jobs_[ig][jobid];
soecp_potential_list.push_back(O);
soecp_component_list.push_back(*O.PP_[job.ion_id]);
soecp_component_list.push_back(*O.pp_[job.ion_id]);
pset_list.push_back(p_list[iw]);
psi_list.push_back(wf_list[iw]);
batch_list.push_back(job);
Expand Down Expand Up @@ -274,7 +274,7 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l
for (int iw = 0; iw < nw; iw++)
{
Vector<Real> ve_sample(ve_samples.begin(iw), num_electrons);
Vector<Real> vi_sample(vi_samples.begin(iw), O_leader.NumIons_);
Vector<Real> vi_sample(vi_samples.begin(iw), O_leader.num_ions_);
for (const ListenerVector<Real>& listener : listeners->electron_values)
listener.report(iw, O_leader.getName(), ve_sample);
for (const ListenerVector<Real>& listener : listeners->ion_values)
Expand All @@ -287,28 +287,28 @@ void SOECPotential::mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_l

std::unique_ptr<OperatorBase> SOECPotential::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
{
std::unique_ptr<SOECPotential> myclone = std::make_unique<SOECPotential>(IonConfig_, qp, psi);
for (int ig = 0; ig < PPset_.size(); ++ig)
if (PPset_[ig])
myclone->addComponent(ig, std::unique_ptr<SOECPComponent>(PPset_[ig]->makeClone(qp)));
std::unique_ptr<SOECPotential> myclone = std::make_unique<SOECPotential>(ion_config_, qp, psi);
for (int ig = 0; ig < ppset_.size(); ++ig)
if (ppset_[ig])
myclone->addComponent(ig, std::unique_ptr<SOECPComponent>(ppset_[ig]->makeClone(qp)));
return myclone;
}

void SOECPotential::addComponent(int groupID, std::unique_ptr<SOECPComponent>&& ppot)
{
for (int iat = 0; iat < PP_.size(); iat++)
if (IonConfig_.GroupID[iat] == groupID)
PP_[iat] = ppot.get();
PPset_[groupID] = std::move(ppot);
for (int iat = 0; iat < pp_.size(); iat++)
if (ion_config_.GroupID[iat] == groupID)
pp_[iat] = ppot.get();
ppset_[groupID] = std::move(ppot);
}

void SOECPotential::createResource(ResourceCollection& collection) const
{
auto new_res = std::make_unique<SOECPotentialMultiWalkerResource>();
for (int ig = 0; ig < PPset_.size(); ig++)
if (PPset_[ig]->getVP())
for (int ig = 0; ig < ppset_.size(); ig++)
if (ppset_[ig]->getVP())
{
PPset_[ig]->getVP()->createResource(new_res->collection);
ppset_[ig]->getVP()->createResource(new_res->collection);
break;
}
auto resource_index = collection.addResource(std::move(new_res));
Expand Down
24 changes: 12 additions & 12 deletions src/QMCHamiltonians/SOECPotential.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ class SOECPotential : public OperatorBase

bool get(std::ostream& os) const override
{
os << "SOECPotential: " << IonConfig_.getName();
os << "SOECPotential: " << ion_config_.getName();
return true;
}

std::unique_ptr<OperatorBase> makeClone(ParticleSet& qp, TrialWaveFunction& psi) final;

void addComponent(int groupID, std::unique_ptr<SOECPComponent>&& pp);

void setRandomGenerator(RandomGenerator* rng) override { myRNG_ = rng; }
void setRandomGenerator(RandomGenerator* rng) override { my_rng_ = rng; }

//initialize shared resource and hand to collection
void createResource(ResourceCollection& collection) const override;
Expand All @@ -80,11 +80,11 @@ class SOECPotential : public OperatorBase
void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;

protected:
RandomGenerator* myRNG_;
std::vector<SOECPComponent*> PP_;
std::vector<std::unique_ptr<SOECPComponent>> PPset_;
ParticleSet& IonConfig_;
TrialWaveFunction& Psi_;
RandomGenerator* my_rng_;
std::vector<SOECPComponent*> pp_;
std::vector<std::unique_ptr<SOECPComponent>> ppset_;
ParticleSet& ion_config_;
TrialWaveFunction& psi_;
static void mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_list,
const RefVectorWithLeader<TrialWaveFunction>& wf_list,
const RefVectorWithLeader<ParticleSet>& p_list,
Expand All @@ -93,15 +93,15 @@ class SOECPotential : public OperatorBase

private:
///number of ions
int NumIons_;
int num_ions_;
///index of distance table for ion-el pair
int myTableIndex_;
int my_table_index_;
///reference to the electrons
ParticleSet& Peln_;
ParticleSet& peln_;
///neighborlist of electrons
NeighborLists ElecNeighborIons_;
NeighborLists elec_neighbor_ions_;
///neighborlist of ions
NeighborLists IonNeighborElecs_;
NeighborLists ion_neighbor_elecs_;
//job list for evaluation
std::vector<std::vector<NLPPJob<RealType>>> sopp_jobs_;
//multi walker resource
Expand Down
6 changes: 3 additions & 3 deletions src/QMCHamiltonians/tests/test_SOECPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ class TestSOECPotential
public:
static void copyGridUnrotatedForTest(SOECPotential& so_ecp)
{
so_ecp.PPset_[0]->rrotsgrid_m_ = so_ecp.PPset_[0]->sgridxyz_m_;
so_ecp.ppset_[0]->rrotsgrid_m_ = so_ecp.ppset_[0]->sgridxyz_m_;
}
static bool didGridChange(SOECPotential& so_ecp)
{
return so_ecp.PPset_[0]->rrotsgrid_m_ != so_ecp.PPset_[0]->sgridxyz_m_;
return so_ecp.ppset_[0]->rrotsgrid_m_ != so_ecp.ppset_[0]->sgridxyz_m_;
}
static void addVPs(const RefVectorWithLeader<OperatorBase>& o_list, const RefVectorWithLeader<ParticleSet>& p_list)
{
for (size_t iw = 0; iw < o_list.size(); iw++)
{
auto& sopp = o_list.getCastedElement<SOECPotential>(iw);
auto& pset = p_list[iw];
for (auto& uptr_comp : sopp.PPset_)
for (auto& uptr_comp : sopp.ppset_)
uptr_comp.get()->initVirtualParticle(pset);
}
}
Expand Down

0 comments on commit 4ba73a0

Please sign in to comment.