28 std::unique_ptr<Resource>
makeClone()
const override 30 return std::make_unique<CoulombPBCABMultiWalkerResource>(*this);
45 myTableIndex(elns.addTable(ions)),
47 ComputeForces(computeForces),
59 app_log() <<
" Maximum K shell " <<
AB->MaxKshell << std::endl;
60 app_log() <<
" Number of k vectors " <<
AB->Fk.size() << std::endl;
65 return std::make_unique<CoulombPBCAB>(*this);
75 APP_ABORT(
"CoulombPBCAB::resetTargetParticleSet found inconsistent table index");
77 AB->resetTargetParticleSet(P);
88 #if !defined(REMOVE_TRACEMANAGER) 130 #if !defined(REMOVE_TRACEMANAGER) 157 #if !defined(REMOVE_TRACEMANAGER) 172 for (
size_t b = 0; b <
NptclB; ++b)
175 const auto& dist = d_ab.getDistRow(b);
176 for (
size_t a = 0; a <
NptclA; ++a)
178 Return_t pairpot = z *
Zat[a] *
Vat[a]->splint(dist[a]) / dist[a];
179 Vi_samp(a) += pairpot;
180 Ve_samp(b) += pairpot;
192 APP_ABORT(
"CoulombPBCAB::evaluate_sp single particle traces have not been implemented for slab geometry");
196 assert(RhoKA.isStorePerParticle());
197 assert(RhoKB.isStorePerParticle());
208 RhoKB.eikr_r[i], RhoKB.eikr_i[i]);
218 AB->evaluate(P.
getSimulationCell().getKLists().kshell, RhoKB.rhok_r[
s], RhoKB.rhok_i[
s], RhoKA.eikr_r[i],
225 for (
int i = 0; i < Ve_samp.
size(); ++i)
227 for (
int i = 0; i < Vi_samp.
size(); ++i)
230 #if defined(TRACE_CHECK) 234 RealType Vnow = Vlrnow + Vsrnow + Vcnow;
243 app_log() <<
"accumtest: CoulombPBCAA::evaluate()" << std::endl;
244 app_log() <<
"accumtest: tot:" << Vnow << std::endl;
245 app_log() <<
"accumtest: sum:" << Vsum << std::endl;
250 app_log() <<
"accumtest: CoulombPBCAA::evalConsts()" << std::endl;
251 app_log() <<
"accumtest: tot:" << Vcnow << std::endl;
252 app_log() <<
"accumtest: sum:" << Vcsum << std::endl;
257 app_log() <<
"sharetest: CoulombPBCAB::evaluate()" << std::endl;
258 app_log() <<
"sharetest: e share:" << Vesum << std::endl;
259 app_log() <<
"sharetest: i share:" << Visum << std::endl;
263 app_log() <<
"sharetest: CoulombPBCAB::evalConsts()" << std::endl;
264 app_log() <<
"sharetest: e share:" << Vecsum << std::endl;
265 app_log() <<
"sharetest: i share:" << Vicsum << std::endl;
283 auto num_centers = p_leader.getTotalNum();
284 auto& name = o_leader.
name_;
285 auto& mw_res = o_leader.mw_res_handle_.getResource();
288 const auto& ve_consts = mw_res.pp_consts_trg;
289 const auto& vi_consts = mw_res.pp_consts_src;
290 auto num_species = p_leader.getSpeciesSet().getTotalNum();
295 auto evaluate_walker = [name, &ve_sample, &vi_sample, &ve_consts,
297 const std::vector<ListenerVector<RealType>>& listeners,
298 const std::vector<ListenerVector<RealType>>& ion_listeners) ->
RealType {
302 std::fill(ve_sample.begin(), ve_sample.end(), 0.0);
303 std::fill(vi_sample.begin(), vi_sample.end(), 0.0);
304 auto& pset_source = cpbcab.getSourcePSet();
307 const auto& d_ab(
pset.getDistTableAB(cpbcab.myTableIndex));
310 for (
size_t b = 0; b <
pset.getTotalNum(); ++b)
312 z = 0.5 * cpbcab.Qat[b];
313 const auto& dist = d_ab.getDistRow(b);
314 for (
size_t a = 0; a < pset_source.getTotalNum(); ++a)
316 Return_t pairpot = z * cpbcab.Zat[a] * cpbcab.Vat[a]->splint(dist[a]) / dist[a];
317 vi_sample[a] += pairpot;
318 ve_sample[b] += pairpot;
331 APP_ABORT(
"CoulombPBCAB::evaluate_sp single particle traces have not been implemented for slab geometry");
335 assert(RhoKA.isStorePerParticle());
336 assert(RhoKB.isStorePerParticle());
340 int num_species_source = pset_source.getSpeciesSet().size();
341 for (
int i = 0; i <
pset.getTotalNum(); ++i)
343 q = .5 * cpbcab.Qat[i];
345 for (
int s = 0;
s < num_species_source;
s++)
346 v1 += cpbcab.Zspec[
s] * q *
347 cpbcab.AB->evaluate(pset_source.getSimulationCell().getKLists().kshell, RhoKA.rhok_r[
s],
348 RhoKA.rhok_i[
s], RhoKB.eikr_r[i], RhoKB.eikr_i[i]);
352 int num_species_target =
pset.getSpeciesSet().size();
353 for (
int i = 0; i < pset_source.getTotalNum(); ++i)
355 q = .5 * cpbcab.Zat[i];
357 for (
int s = 0;
s < num_species_target;
s++)
358 v1 += cpbcab.Qspec[
s] * q *
359 cpbcab.AB->evaluate(
pset.getSimulationCell().getKLists().kshell, RhoKB.rhok_r[
s], RhoKB.rhok_i[
s],
360 RhoKA.eikr_r[i], RhoKA.eikr_i[i]);
366 for (
int i = 0; i < ve_sample.size(); ++i)
367 ve_sample[i] += ve_consts[i];
368 for (
int i = 0; i < vi_sample.size(); ++i)
369 vi_sample[i] += vi_consts[i];
372 listener.report(walker_index, name, ve_sample);
374 ion_listener.report(walker_index, name, vi_sample);
378 for (
int iw = 0; iw < o_list.size(); iw++)
381 coulomb_ab.
value_ = evaluate_walker(iw, coulomb_ab, p_list[iw], listeners, ion_listeners);
394 #if !defined(REMOVE_TRACEMANAGER) 403 for (
int i = 0; i < nelns; ++i)
408 v1 *= -.5 *
Qat[i] * vs_k0;
409 #if !defined(REMOVE_TRACEMANAGER) 414 for (
int i = 0; i < nions; ++i)
419 v1 *= -.5 *
Zat[i] * vs_k0;
420 #if !defined(REMOVE_TRACEMANAGER) 426 app_log() <<
" Constant of PBCAB " << Consts << std::endl;
437 for (
size_t b = 0; b <
NptclB; ++b)
439 const auto& dist = d_ab.getDistRow(b);
441 for (
size_t a = 0; a <
NptclA; ++a)
442 esum +=
Zat[a] *
Vat[a]->splint(dist[a]) / dist[a];
443 res += esum *
Qat[b];
455 throw std::runtime_error(
456 "CoulombPBCAB::evalLR RhoKA.SuperCellEnum == SUPERCELL_SLAB case not implemented. There was an implementation " 457 "with complex-valued storage that may be resurrected using real-valued storage.");
466 RhoKB.rhok_r[j], RhoKB.rhok_i[j]);
467 res +=
Zspec[i] * esum;
481 int ChargeAttribIndxA = tspeciesA.
addAttribute(
"charge");
482 int ChargeAttribIndxB = tspeciesB.addAttribute(
"charge");
496 Zspec[spec] = tspeciesA(ChargeAttribIndxA, spec);
501 Qspec[spec] = tspeciesB(ChargeAttribIndxB, spec);
504 for (
int iat = 0; iat <
NptclA; iat++)
523 const int ng = P.
getLattice().num_ewald_grid_points;
524 app_log() <<
" CoulombPBCAB::initBreakup\n Setting a linear grid=[0," <<
myRcut 525 <<
") number of grid points =" << ng << std::endl;
532 APP_ABORT(
"CoulombPBCAB::initBreakup. Vat is not empty\n");
548 APP_ABORT(
"CoulombPBCAB::initBreakup. Vat is not empty\n");
564 const int MaxGridPoints = 10000;
565 const size_t ng =
std::min(MaxGridPoints, static_cast<int>(
myRcut / 1
e-3) + 1);
566 app_log() <<
" CoulombPBCAB::add \n Setting a linear grid=[0," <<
myRcut <<
") number of grid =" << ng
570 RealType dr = agrid_local[1] - agrid_local[0];
571 if (
Vspec[groupID] ==
nullptr)
575 app_log() <<
" Creating the short-range pseudopotential for species " << groupID << std::endl;
576 std::vector<RealType> v(ng);
577 for (
int ig = 1; ig < ng - 2; ig++)
581 v[ig] = -r *
AB->evaluateLR(r) + ppot->splint(r);
583 v[0] = 2.0 * v[1] - v[2];
587 RealType deriv = (v[1] - v[0]) / dr;
588 auto rfunc = std::make_unique<RadFunctorType>(agrid_local.makeClone(), v);
589 rfunc->spline(0, deriv, ng - 1, 0.0);
590 for (
int iat = 0; iat <
NptclA; iat++)
593 Vat[iat] = rfunc.get();
595 Vspec[groupID] = std::move(rfunc);
600 app_log() <<
" Creating the short-range pseudopotential derivatives for species " << groupID << std::endl;
603 std::vector<RealType> v(ng);
604 std::vector<RealType> dv(ng);
606 RealType ppot_val(0), ppot_deriv(0), ppot_2deriv(0);
608 for (
int ig = 1; ig < ng - 2; ig++)
611 ppot_val = ppot->splint(r, ppot_deriv, ppot_2deriv);
612 lr_val =
dAB->evaluateLR(r);
613 lr_deriv =
dAB->lrDf(r);
615 v[ig] = ppot_val - r * lr_val;
616 dv[ig] = ppot_deriv - (lr_val + lr_deriv * r);
619 v[0] = 2.0 * v[1] - v[2];
623 dv[0] = 2.0 * dv[1] - dv[2];
627 auto ffunc = std::make_unique<RadFunctorType>(agrid_local.makeClone(), v);
628 auto fdfunc = std::make_unique<RadFunctorType>(agrid_local.makeClone(), dv);
630 RealType fderiv = (dv[1] - dv[0]) / dr;
632 ffunc->spline(0, dv[0], ng - 1, 0.0);
633 fdfunc->spline(0, fderiv, ng - 1, 0.0);
635 for (
int iat = 0; iat <
NptclA; iat++)
639 fVat[iat] = ffunc.get();
640 fdVat[iat] = fdfunc.get();
643 fVspec[groupID] = std::move(ffunc);
644 fdVspec[groupID] = std::move(fdfunc);
652 FILE* fout = fopen(
"Vlocal.dat",
"w");
656 RealType Vr =
Vat[0]->splint(r, d_rV_dr, d2_rV_dr2);
657 Vr =
Vat[0]->splint(r);
658 fprintf(fout,
"%1.8e %1.12e %1.12e %1.12e\n", r, Vr, d_rV_dr, d2_rV_dr2);
672 for (
int iat = 0; iat < grad.size(); iat++)
675 for (
int iat = 0; iat < grad.size(); iat++)
692 for (
size_t b = 0; b <
NptclB; ++b)
694 const auto& dist = d_ab.getDistRow(b);
695 const auto& dr = d_ab.getDisplRow(b);
697 for (
size_t a = 0; a <
NptclA; ++a)
700 rinv = 1.0 / dist[a];
701 rV =
Vat[a]->splint(dist[a]);
702 frV =
fVat[a]->splint(dist[a]);
703 fdrV =
fdVat[a]->splint(dist[a]);
704 dvdr =
Qat[b] *
Zat[a] * (fdrV - frV * rinv) * rinv;
705 forces_[a][0] -= dvdr * dr[a][0] * rinv;
706 forces_[a][1] -= dvdr * dr[a][1] * rinv;
707 forces_[a][2] -= dvdr * dr[a][2] * rinv;
708 esum +=
Zat[a] * rV * rinv;
710 res += esum *
Qat[b];
719 pp_consts_trg.
resize(nelns, 0.0);
720 pp_consts_src.
resize(nions, 0.0);
724 for (
int i = 0; i < nelns; ++i)
729 v1 *= -.5 *
Qat[i] * vs_k0;
730 pp_consts_trg[i] = v1;
732 for (
int i = 0; i < nions; ++i)
737 v1 *= -.5 *
Zat[i] * vs_k0;
738 pp_consts_src[i] = v1;
744 auto new_res = std::make_unique<CoulombPBCABMultiWalkerResource>();
746 auto resource_index = collection.
addResource(std::move(new_res));
Array< TraceReal, 1 > * Vi_sample
void resize(size_type n, Type_t val=Type_t())
Resize the container.
void twoBodyQuantumDomain(const ParticleSet &P)
set quantum domain for two-body operator
std::vector< const RadFunctorType * > fdVat
bool streaming_particles_
static std::unique_ptr< LRHandlerType > getDerivHandler(ParticleSet &ref)
This returns a force/stress optimized LR handler. If non existent, it creates one.
int NumSpeciesB
number of species of B particle set
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
Vector< RealType > pp_samples_src
a walkers worth of per ion AB potential values
std::shared_ptr< const RadFunctorType > fV0
Radial functor for bare coulomb, optimized for forces.
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
Return_t evaluateWithIonDerivs(ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_terms, ParticleSet::ParticlePos &pulay_terms) override
Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase...
size_t addResource(std::unique_ptr< Resource > &&res, bool noprint=false)
Vector< RealType > pp_consts_src
constant values for the source particles aka ions aka A
void set(T ri, T rf, int n) override
Set the grid given the parameters.
Return_t myConst
const energy after breakup
std::vector< const RadFunctorType * > Vat
Short-range potential for each ion.
void takebackResource(ResourceHandle< RS > &res_handle)
helper functions for EinsplineSetBuilder
Calculates the AA Coulomb potential using PBCs.
bool streaming_array(const std::string &name)
Array< TraceReal, 1 > Vi_const
std::shared_ptr< LRHandlerType > AB
long-range Handler. Should be const LRHandlerType eventually
static std::unique_ptr< RadFunctorType > createSpline4RbyVs(const LRHandlerType *aLR, mRealType rcut, const GridType &agrid)
create a linear spline function
ParticleSet::ParticlePos forces_
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
size_t getTotalNum() const
int my_index_
starting index of this object
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
acquire a shared resource from a collection
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
return a shared resource to a collection
constexpr std::complex< float > czero
std::vector< std::shared_ptr< RadFunctorType > > Vspec
Short-range potential for each species.
void addObservablesF(QMCTraits::PropertySetType &plist)
An object of this type is a listener expecting a callback to the report function with a vector of val...
Vector< RealType > pp_consts_trg
constant values for the target particles aka electrons aka B
std::vector< std::shared_ptr< const RadFunctorType > > fVspec
Vectorized record engine for scalar properties.
LRHandlerType::mRealType mRealType
bool ComputeForces
Flag for whether to compute forces or not.
Attaches a unit to a Vector for IO.
Communicate * Controller
Global Communicator for a process.
Calculates the structure-factor for a particle set.
void resize(const std::array< SIZET, D > &dims)
Resize the container.
const int myTableIndex
locator of the distance table
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
TraceRequest request_
whether traces are being collected
ParticleIndex GroupID
Species ID.
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
std::shared_ptr< const RadFunctorType > V0
Always mave a radial functor for the bare coulomb.
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
void turnOnPerParticleSK()
Turn on per particle storage in Structure Factor.
std::shared_ptr< const RadFunctorType > dfV0
Radial functor for derivative of bare coulomb, optimized for forces.
const auto & getSimulationCell() const
std::vector< std::shared_ptr< const RadFunctorType > > fdVspec
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Array< TraceReal, 1 > * Ve_sample
std::string name_
name of this object
Specialized paritlce class for atomistic simulations.
int NptclB
number of particles of B
RealType myRcut
cutoff radius of the short-range part
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
Return_t evaluate_sp(ParticleSet &P)
int add(const std::string &aname)
static std::unique_ptr< RadFunctorType > createSpline4RbyVsDeriv(const LRHandlerType *aLR, mRealType rcut, const GridType &agrid)
create a linear spline of the derivative of short-range potential
Final class and should not be derived.
declaration of ProgressReportEngine
void initBreakup(ParticleSet &P)
Creates the long-range handlers, then splines and stores it by particle and species for quick evaluat...
CASTTYPE & getCastedElement(size_t i) const
int groupsize(int igroup) const
return the size of a group
int NptclA
number of particles of A
Array< TraceReal, 1 > Ve_const
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
void checkoutParticleQuantities(TraceManager &tm) override
void setEnergyDomain(EnergyDomains edomain)
Set the Energy Domain.
const StructFact & getSK() const
return Structure Factor
Vector< RealType > pp_samples_trg
a walkers worth of per electron AB potential values
int NumSpeciesA
number of species of A particle set
std::vector< RealType > Qspec
Qspec[spec] charge for the spec-th species of B.
ParticleSet & pset_ions_
source particle set
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
void add(int groupID, std::unique_ptr< RadFunctorType > &&ppot)
Adds a local pseudopotential channel "ppot" to all source species of type "groupID".
Array< TraceReal, D > * checkout_real(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
std::vector< int > NofSpeciesA
number of particles per species of A
void evalPerParticleConsts(Vector< RealType > &pp_consts_src, Vector< RealType > &pp_consts_trg) const
Compute the const part of the per particle coulomb AB potential.
CoulombPBCAB(ParticleSet &ions, ParticleSet &elns, bool computeForces=false)
FullPrecRealType Return_t
type of return value of evaluate
std::vector< const RadFunctorType * > fVat
Short-range potential (r*V) and potential derivative d/dr(rV) derivative for each ion Required for fo...
ResourceHandle< CoulombPBCABMultiWalkerResource > mw_res_handle_
CASTTYPE & getCastedLeader() const
Return_t evalLRwithForces(ParticleSet &P)
Computes the long-range contribution to the coulomb energy and forces.
Class to represent a many-body trial wave function.
void addObservables(PropertySetType &plist, BufferType &collectables) override
named values to the property list Default implementaton uses addValue(plist_)
Return_t value_
current value
std::vector< RealType > Qat
Qat[iat] charge for the iat-th particle of B.
std::vector< RealType > Zspec
Zspec[spec] charge for the spec-th species of A.
std::vector< RealType > Zat
Zat[iat] charge for the iat-th particle of A.
static std::unique_ptr< LRHandlerType > getHandler(ParticleSet &ref)
This returns an energy optimized LR handler. If non existent, it creates one.
void contribute_array(const std::string &name, bool default_quantity=false)
virtual void informOfPerParticleListener()
std::shared_ptr< const LRHandlerType > dAB
long-range derivative handler
const auto & getLattice() const
std::unique_ptr< Resource > makeClone() const override
ResourceHandle< RS > lendResource()
Custom container for set of attributes for a set of species.
void mw_evaluatePerParticle(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &ion_listeners) const override
Evaluate the contribution of this component of multiple walkers per particle reporting to registered ...
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
void contributeParticleQuantities() override
CoulombPBCABMultiWalkerResource()
void informOfPerParticleListener() override
Call to inform objects associated with this operator of per particle listeners.
Return_t evalLR(ParticleSet &P)
Computes the long-range contribution to the coulomb energy.
std::vector< int > NofSpeciesB
number of particles per species of B
Return_t evalSR(ParticleSet &P)
Computes the short-range contribution to the coulomb energy.
Return_t evalSRwithForces(ParticleSet &P)
Computes the short-range contribution to the coulomb energy and forces.
void deleteParticleQuantities() override
Return_t evalConsts(const ParticleSet &P, bool report=true)
Evaluates madelung and background contributions to total energy.