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

Fix wrong output size in SplineC2ROMPTarget::mw_evaluateVGLandDetRatioGrads #4408

Merged
merged 7 commits into from
Jan 23, 2023
Merged
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
Prev Previous commit
Next Next commit
Protect the case when output size is smaller.
Fix SplineC2R. When the requested size is smaller than what can be supplied, only output the requested size.
What is the right way of selecting a subset of orbitals in an already built SplineC2R remains a big question.
The trucation is subject to the sorting of orbitals in C2R which puts all the "complex" orbitals first.
"complex" orbitals produce two real orbitals.
  • Loading branch information
ye-luo committed Jan 23, 2023
commit d3725c8874ff248c2f7d970e4d79ff1f275bdf40
63 changes: 38 additions & 25 deletions src/QMCWaveFunctions/BsplineFactory/SplineC2R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ inline void SplineC2R<ST>::assign_v(const PointType& r,
const ST* restrict ky = myKcart.data(1);
const ST* restrict kz = myKcart.data(2);

TT* restrict psi_s = psi.data() + first_spo;
TT* restrict psi_s = psi.data() + first_spo;
const size_t requested_orb_size = psi.size();
#pragma omp simd
for (size_t j = first; j < std::min(nComplexBands, last); j++)
{
Expand All @@ -79,8 +80,10 @@ inline void SplineC2R<ST>::assign_v(const PointType& r,
const ST val_r = myV[jr];
const ST val_i = myV[ji];
qmcplusplus::sincos(-(x * kx[j] + y * ky[j] + z * kz[j]), &s, &c);
psi_s[jr] = val_r * c - val_i * s;
psi_s[ji] = val_i * c + val_r * s;
if (jr < requested_orb_size)
psi_s[jr] = val_r * c - val_i * s;
if (ji < requested_orb_size)
psi_s[ji] = val_i * c + val_r * s;
}

psi_s += nComplexBands;
Expand All @@ -91,7 +94,8 @@ inline void SplineC2R<ST>::assign_v(const PointType& r,
const ST val_r = myV[2 * j];
const ST val_i = myV[2 * j + 1];
qmcplusplus::sincos(-(x * kx[j] + y * ky[j] + z * kz[j]), &s, &c);
psi_s[j] = val_r * c - val_i * s;
if (j < requested_orb_size)
psi_s[j] = val_r * c - val_i * s;
}
}

Expand Down Expand Up @@ -203,6 +207,7 @@ inline void SplineC2R<ST>::assign_vgl(const PointType& r,
const ST* restrict h22 = myH.data(5);
ASSUME_ALIGNED(h22);

const size_t requested_orb_size = psi.size();
#pragma omp simd
for (size_t j = first; j < std::min(nComplexBands, last); j++)
{
Expand Down Expand Up @@ -242,16 +247,22 @@ inline void SplineC2R<ST>::assign_vgl(const PointType& r,
const ST lap_i = lcart_i + mKK[j] * val_i - two * (kX * dX_r + kY * dY_r + kZ * dZ_r);

const size_t psiIndex = first_spo + jr;
psi[psiIndex] = c * val_r - s * val_i;
psi[psiIndex + 1] = c * val_i + s * val_r;
d2psi[psiIndex] = c * lap_r - s * lap_i;
d2psi[psiIndex + 1] = c * lap_i + s * lap_r;
dpsi[psiIndex][0] = c * gX_r - s * gX_i;
dpsi[psiIndex][1] = c * gY_r - s * gY_i;
dpsi[psiIndex][2] = c * gZ_r - s * gZ_i;
dpsi[psiIndex + 1][0] = c * gX_i + s * gX_r;
dpsi[psiIndex + 1][1] = c * gY_i + s * gY_r;
dpsi[psiIndex + 1][2] = c * gZ_i + s * gZ_r;
if (psiIndex < requested_orb_size)
{
psi[psiIndex] = c * val_r - s * val_i;
dpsi[psiIndex][0] = c * gX_r - s * gX_i;
dpsi[psiIndex][1] = c * gY_r - s * gY_i;
dpsi[psiIndex][2] = c * gZ_r - s * gZ_i;
d2psi[psiIndex] = c * lap_r - s * lap_i;
}
if (psiIndex + 1 < requested_orb_size)
{
psi[psiIndex + 1] = c * val_i + s * val_r;
dpsi[psiIndex + 1][0] = c * gX_i + s * gX_r;
dpsi[psiIndex + 1][1] = c * gY_i + s * gY_r;
dpsi[psiIndex + 1][2] = c * gZ_i + s * gZ_r;
d2psi[psiIndex + 1] = c * lap_i + s * lap_r;
}
}

#pragma omp simd
Expand Down Expand Up @@ -287,17 +298,19 @@ inline void SplineC2R<ST>::assign_vgl(const PointType& r,
const ST gY_i = dY_i - val_r * kY;
const ST gZ_i = dZ_i - val_r * kZ;

const size_t psiIndex = first_spo + nComplexBands + j;
psi[psiIndex] = c * val_r - s * val_i;
dpsi[psiIndex][0] = c * gX_r - s * gX_i;
dpsi[psiIndex][1] = c * gY_r - s * gY_i;
dpsi[psiIndex][2] = c * gZ_r - s * gZ_i;

const ST lcart_r = SymTrace(h00[jr], h01[jr], h02[jr], h11[jr], h12[jr], h22[jr], symGG);
const ST lcart_i = SymTrace(h00[ji], h01[ji], h02[ji], h11[ji], h12[ji], h22[ji], symGG);
const ST lap_r = lcart_r + mKK[j] * val_r + two * (kX * dX_i + kY * dY_i + kZ * dZ_i);
const ST lap_i = lcart_i + mKK[j] * val_i - two * (kX * dX_r + kY * dY_r + kZ * dZ_r);
d2psi[psiIndex] = c * lap_r - s * lap_i;
if (const size_t psiIndex = first_spo + nComplexBands + j; psiIndex < requested_orb_size)
{
psi[psiIndex] = c * val_r - s * val_i;
dpsi[psiIndex][0] = c * gX_r - s * gX_i;
dpsi[psiIndex][1] = c * gY_r - s * gY_i;
dpsi[psiIndex][2] = c * gZ_r - s * gZ_i;

const ST lcart_r = SymTrace(h00[jr], h01[jr], h02[jr], h11[jr], h12[jr], h22[jr], symGG);
const ST lcart_i = SymTrace(h00[ji], h01[ji], h02[ji], h11[ji], h12[ji], h22[ji], symGG);
const ST lap_r = lcart_r + mKK[j] * val_r + two * (kX * dX_i + kY * dY_i + kZ * dZ_i);
const ST lap_i = lcart_i + mKK[j] * val_i - two * (kX * dX_r + kY * dY_r + kZ * dZ_r);
d2psi[psiIndex] = c * lap_r - s * lap_i;
}
}
}

Expand Down