Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setTwist/twist take/return a const reference. #4719

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Particle/ParticleSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ class ParticleSet : public QMCTraits, public OhmmsElementBase, public PtclOnLatt
///return the address of the i-th properties
inline const FullPrecRealType* restrict getPropertyBase(int i) const { return Properties[i]; }

inline void setTwist(SingleParticlePos& t) { myTwist = t; }
inline SingleParticlePos getTwist() const { return myTwist; }
inline void setTwist(const SingleParticlePos& t) { myTwist = t; }
inline const SingleParticlePos& getTwist() const { return myTwist; }

/** Initialize particles around another ParticleSet
* Used to initialize an electron ParticleSet by an ion ParticleSet
Expand Down
4 changes: 2 additions & 2 deletions src/QMCWaveFunctions/TrialWaveFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ class TrialWaveFunction

void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios);

void setTwist(std::vector<RealType> t) { myTwist = t; }
const std::vector<RealType> twist() { return myTwist; }
void setTwist(const std::vector<RealType>& t) { myTwist = t; }
const std::vector<RealType>& twist() const { return myTwist; }

inline void setMassTerm(ParticleSet& P)
{
Expand Down
5 changes: 3 additions & 2 deletions src/QMCWaveFunctions/WaveFunctionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ std::unique_ptr<TrialWaveFunction> WaveFunctionFactory::buildTWF(xmlNodePtr cur,
SPOSetBuilderFactory sposet_builder_factory(myComm, targetPtcl, ptclPool);

std::string vp_file_to_load;
std::vector<ParticleSet::RealType> tsts(3, 0.);
cur = cur->children;
while (cur != NULL)
{
Expand All @@ -91,7 +92,6 @@ std::unique_ptr<TrialWaveFunction> WaveFunctionFactory::buildTWF(xmlNodePtr cur,
attribs.add(hdfName, "name");
if (hdfName == "twistAngle")
{
std::vector<ParticleSet::RealType> tsts(3, 0);
putContent(tsts, kcur);
targetPsi->setTwist(tsts);
foundtwist = true;
Expand All @@ -102,7 +102,8 @@ std::unique_ptr<TrialWaveFunction> WaveFunctionFactory::buildTWF(xmlNodePtr cur,
if (!foundtwist)
{
//default twist is [0 0 0]
std::vector<ParticleSet::RealType> tsts(3, 0);
tsts.resize(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsts is size 3 in the declaration (and set to 0) in the declaration. Is there a need to set it again here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code where the declaration of 'tsts' occurs right before the use seems clear to me, but maybe I'm missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the name. In isolation, I would read 'tsts' as 'tests'. Maybe it could be expanded to 'twists'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the name and added a rvalue function overload to avoid the extra copy.

std::fill(std::begin(tsts), std::end(tsts), 0.);
targetPsi->setTwist(tsts);
}
}
Expand Down