mirror of https://github.com/QMCPACK/qmcpack.git
add to SpinorSet mw_evaluateVGLandRatioGradsWithSpin
This commit is contained in:
parent
dc8ccd8324
commit
e32d3aba45
|
@ -313,7 +313,7 @@ public:
|
|||
* @param phi_vgl_v orbital values, gradients and laplacians of all the walkers
|
||||
* @param ratios, ratios of all walkers
|
||||
* @param grads, spatial gradients of all walkers
|
||||
* @param spingras, spin gradients of all walkers
|
||||
* @param spingrads, spin gradients of all walkers
|
||||
*/
|
||||
virtual void mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader<SPOSet>& spo_list,
|
||||
const RefVectorWithLeader<ParticleSet>& P_list,
|
||||
|
|
|
@ -211,6 +211,75 @@ void SpinorSet::mw_evaluateVGLWithSpin(const RefVectorWithLeader<SPOSet>& spo_li
|
|||
}
|
||||
}
|
||||
|
||||
void SpinorSet::mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader<SPOSet>& spo_list,
|
||||
const RefVectorWithLeader<ParticleSet>& P_list,
|
||||
int iat,
|
||||
const std::vector<const ValueType*>& invRow_ptr_list,
|
||||
OffloadMWVGLArray& phi_vgl_v,
|
||||
std::vector<ValueType>& ratios,
|
||||
std::vector<GradType>& grads,
|
||||
std::vector<ValueType>& spingrads) const
|
||||
{
|
||||
auto& spo_leader = spo_list.getCastedLeader<SpinorSet>();
|
||||
auto& P_leader = P_list.getLeader();
|
||||
assert(this == &spo_leader);
|
||||
assert(phi_vgl_v.size(0) == DIM_VGL);
|
||||
assert(phi_vgl_v.size(1) == spo_list.size());
|
||||
const size_t nw = spo_list.size();
|
||||
const size_t norb_requested = phi_vgl_v.size(2);
|
||||
|
||||
OffloadMWVGLArray up_phi_vgl_v, dn_phi_vgl_v;
|
||||
up_phi_vgl_v.resize(DIM_VGL, nw, norb_requested);
|
||||
dn_phi_vgl_v.resize(DIM_VGL, nw, norb_requested);
|
||||
std::vector<ValueType> up_ratios(nw), dn_ratios(nw);
|
||||
std::vector<GradType> up_grads(nw), dn_grads(nw);
|
||||
|
||||
SPOSet& up_spo_leader = *(spo_leader.spo_up);
|
||||
SPOSet& dn_spo_leader = *(spo_leader.spo_dn);
|
||||
RefVectorWithLeader<SPOSet> up_spo_list(up_spo_leader);
|
||||
RefVectorWithLeader<SPOSet> dn_spo_list(dn_spo_leader);
|
||||
up_spo_list.reserve(nw);
|
||||
dn_spo_list.reserve(nw);
|
||||
|
||||
for (int iw = 0; iw < nw; iw++)
|
||||
{
|
||||
SpinorSet& spinor = spo_list.getCastedElement<SpinorSet>(iw);
|
||||
up_spo_list.emplace_back(*(spinor.spo_up));
|
||||
dn_spo_list.emplace_back(*(spinor.spo_dn));
|
||||
}
|
||||
|
||||
up_spo_leader.mw_evaluateVGLandDetRatioGrads(up_spo_list, P_list, iat, invRow_ptr_list, up_phi_vgl_v, up_ratios,
|
||||
up_grads);
|
||||
dn_spo_leader.mw_evaluateVGLandDetRatioGrads(dn_spo_list, P_list, iat, invRow_ptr_list, dn_phi_vgl_v, dn_ratios,
|
||||
dn_grads);
|
||||
|
||||
for (int iw = 0; iw < nw; iw++)
|
||||
{
|
||||
ParticleSet::Scalar_t s = P_list[iw].activeSpin(iat);
|
||||
RealType coss = std::cos(s);
|
||||
RealType sins = std::sin(s);
|
||||
|
||||
ValueType eis(coss, sins);
|
||||
ValueType emis(coss, -sins);
|
||||
ValueType eye(0, 1.0);
|
||||
|
||||
ratios[iw] = eis * up_ratios[iw] + emis * dn_ratios[iw];
|
||||
grads[iw] = (eis * up_grads[iw] * up_ratios[iw] + emis * dn_grads[iw] * dn_ratios[iw]) / ratios[iw];
|
||||
spingrads[iw] = eye * (eis * up_ratios[iw] - emis * dn_ratios[iw]) / ratios[iw];
|
||||
|
||||
for (int idim = 0; idim < DIM_VGL; idim++)
|
||||
{
|
||||
ValueType* phi_g = phi_vgl_v.data_at(idim, iw, 0);
|
||||
ValueType* up_phi_g = up_phi_vgl_v.data_at(idim, iw, 0);
|
||||
ValueType* dn_phi_g = dn_phi_vgl_v.data_at(idim, iw, 0);
|
||||
for (int iorb = 0; iorb < norb_requested; iorb++)
|
||||
phi_g[iorb] = eis * up_phi_g[iorb] + emis * dn_phi_g[iorb];
|
||||
}
|
||||
}
|
||||
|
||||
phi_vgl_v.updateTo();
|
||||
}
|
||||
|
||||
void SpinorSet::evaluate_notranspose(const ParticleSet& P,
|
||||
int first,
|
||||
int last,
|
||||
|
|
|
@ -89,6 +89,26 @@ public:
|
|||
const RefVector<ValueVector>& d2psi_v_list,
|
||||
const RefVector<ValueVector>& dspin_v_list) const override;
|
||||
|
||||
/** evaluate the values, gradients and laplacians of this single-particle orbital sets and determinant ratio
|
||||
* and grads of multiple walkers. Device data of phi_vgl_v must be up-to-date upon return.
|
||||
* Includes spin gradients
|
||||
* @param spo_list the list of SPOSet pointers in a walker batch
|
||||
* @param P_list the list of ParticleSet pointers in a walker batch
|
||||
* @param iat active particle
|
||||
* @param phi_vgl_v orbital values, gradients and laplacians of all the walkers
|
||||
* @param ratios, ratios of all walkers
|
||||
* @param grads, spatial gradients of all walkers
|
||||
* @param spingrads, spin gradients of all walkers
|
||||
*/
|
||||
void mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader<SPOSet>& spo_list,
|
||||
const RefVectorWithLeader<ParticleSet>& P_list,
|
||||
int iat,
|
||||
const std::vector<const ValueType*>& invRow_ptr_list,
|
||||
OffloadMWVGLArray& phi_vgl_v,
|
||||
std::vector<ValueType>& ratios,
|
||||
std::vector<GradType>& grads,
|
||||
std::vector<ValueType>& spingrads) const override;
|
||||
|
||||
/** evaluate the values, gradients and laplacians of this single-particle orbital for [first,last) particles
|
||||
* @param P current ParticleSet
|
||||
* @param first starting index of the particles
|
||||
|
|
|
@ -758,6 +758,8 @@ void test_DiracDeterminantBatched_spinor_update(const int delay_rank, DetMatInve
|
|||
REQUIRE(grads[iw][2] == ComplexApprox(ValueType(1.2792642963632226, 0.12110307514989149)));
|
||||
}
|
||||
|
||||
std::fill(ratios.begin(), ratios.end(), 0);
|
||||
std::fill(grads.begin(), grads.end(), 0);
|
||||
dd.mw_ratioGradWithSpin(dd_ref_list, p_ref_list, 1, ratios, grads, spingrads);
|
||||
for (int iw = 0; iw < grads.size(); iw++)
|
||||
{
|
||||
|
@ -769,6 +771,7 @@ void test_DiracDeterminantBatched_spinor_update(const int delay_rank, DetMatInve
|
|||
}
|
||||
|
||||
//reject move and check for initial values for mw_evalGrad
|
||||
std::fill(grads.begin(), grads.end(), 0);
|
||||
elec_.mw_accept_rejectMove<CoordsType::POS_SPIN>(p_ref_list, 1, {false, false});
|
||||
dd.mw_evalGrad(dd_ref_list, p_ref_list, 1, grads);
|
||||
for (int iw = 0; iw < grads.size(); iw++)
|
||||
|
@ -778,6 +781,8 @@ void test_DiracDeterminantBatched_spinor_update(const int delay_rank, DetMatInve
|
|||
REQUIRE(grads[iw][2] == ComplexApprox(G_list[iw].get()[1][2]));
|
||||
}
|
||||
|
||||
std::fill(grads.begin(), grads.end(), 0);
|
||||
std::fill(spingrads.begin(), spingrads.end(), 0);
|
||||
dd.mw_evalGradWithSpin(dd_ref_list, p_ref_list, 1, grads, spingrads);
|
||||
for (int iw = 0; iw < grads.size(); iw++)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue