From 9052e1fe44c0e8029b5106b2491cf275fbb0c869 Mon Sep 17 00:00:00 2001 From: Sebastian Kehl Date: Fri, 1 Oct 2021 14:22:21 +0200 Subject: [PATCH] Template sc-gapsys functions on computeForces. --- .../gmxlib/nonbonded/nb_free_energy.cpp | 79 ++++++++++--------- src/gromacs/gmxlib/nonbonded/nb_softcore.h | 21 +++-- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp index 8e0ce26e43..d441bd199a 100644 --- a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp +++ b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp @@ -808,18 +808,18 @@ static void nb_free_energy_kernel(const t_nblist& if constexpr (softcoreType == KernelSoftcoreType::Gapsys) { - ewaldQuadraticPotential(qq[i], - facel, - rC, - rCutoffCoul, - LFC[i], - DLF[i], - gapsysScaleLinpointCoulEff, - sh_ewald, - &fScalC[i], - &vCoul[i], - &dvdlCoul, - computeElecInteraction); + ewaldQuadraticPotential(qq[i], + facel, + rC, + rCutoffCoul, + LFC[i], + DLF[i], + gapsysScaleLinpointCoulEff, + sh_ewald, + &fScalC[i], + &vCoul[i], + &dvdlCoul, + computeElecInteraction); } } else @@ -832,19 +832,20 @@ static void nb_free_energy_kernel(const t_nblist& if constexpr (softcoreType == KernelSoftcoreType::Gapsys) { - reactionFieldQuadraticPotential(qq[i], - facel, - rC, - rCutoffCoul, - LFC[i], - DLF[i], - gapsysScaleLinpointCoulEff, - krf, - crf, - &fScalC[i], - &vCoul[i], - &dvdlCoul, - computeElecInteraction); + reactionFieldQuadraticPotential( + qq[i], + facel, + rC, + rCutoffCoul, + LFC[i], + DLF[i], + gapsysScaleLinpointCoulEff, + krf, + crf, + &fScalC[i], + &vCoul[i], + &dvdlCoul, + computeElecInteraction); } } @@ -899,20 +900,20 @@ static void nb_free_energy_kernel(const t_nblist& if constexpr (softcoreType == KernelSoftcoreType::Gapsys) { - lennardJonesQuadraticPotential(c6[i], - c12[i], - r, - rSq, - LFV[i], - DLF[i], - gapsysSigma6VdWEff[i], - gapsysScaleLinpointVdWEff, - repulsionShift, - dispersionShift, - &fScalV[i], - &vVdw[i], - &dvdlVdw, - computeVdwInteraction); + lennardJonesQuadraticPotential(c6[i], + c12[i], + r, + rSq, + LFV[i], + DLF[i], + gapsysSigma6VdWEff[i], + gapsysScaleLinpointVdWEff, + repulsionShift, + dispersionShift, + &fScalV[i], + &vVdw[i], + &dvdlVdw, + computeVdwInteraction); } if constexpr (vdwInteractionTypeIsEwald) diff --git a/src/gromacs/gmxlib/nonbonded/nb_softcore.h b/src/gromacs/gmxlib/nonbonded/nb_softcore.h index a2615ede4a..dabbaa2853 100644 --- a/src/gromacs/gmxlib/nonbonded/nb_softcore.h +++ b/src/gromacs/gmxlib/nonbonded/nb_softcore.h @@ -68,7 +68,7 @@ static inline void quadraticApproximationCoulomb(const RealType qq, } /* reaction-field linearized electrostatics */ -template +template static inline void reactionFieldQuadraticPotential(const RealType qq, const real facel, const RealType r, @@ -118,7 +118,10 @@ static inline void reactionFieldQuadraticPotential(const RealType qq, potentialQuad = potentialQuad + qq * (krf * r * r - potentialShift); // update - *force = gmx::blend(*force, forceQuad, computeValues); + if constexpr (computeForces) + { + *force = gmx::blend(*force, forceQuad, computeValues); + } *potential = gmx::blend(*potential, potentialQuad, computeValues); *dvdl = *dvdl + gmx::selectByMask(dvdlQuad, computeValues && withinCutoff); } @@ -126,7 +129,7 @@ static inline void reactionFieldQuadraticPotential(const RealType qq, } /* ewald linearized electrostatics */ -template +template static inline void ewaldQuadraticPotential(const RealType qq, const real facel, const RealType r, @@ -174,7 +177,10 @@ static inline void ewaldQuadraticPotential(const RealType qq, potentialQuad = potentialQuad - qq * potentialShift; // update - *force = gmx::blend(*force, forceQuad, computeValues); + if constexpr (computeForces) + { + *force = gmx::blend(*force, forceQuad, computeValues); + } *potential = gmx::blend(*potential, potentialQuad, computeValues); *dvdl = *dvdl + gmx::selectByMask(dvdlQuad, computeValues && withinCutoff); } @@ -182,7 +188,7 @@ static inline void ewaldQuadraticPotential(const RealType qq, } /* cutoff LJ with quadratic appximation of lj-potential */ -template +template static inline void lennardJonesQuadraticPotential(const RealType c6, const RealType c12, const RealType r, @@ -252,7 +258,10 @@ static inline void lennardJonesQuadraticPotential(const RealType c6, potentialQuad = potentialQuad + gmx::selectByMask(((c12s * repulsionShift) - (c6s * dispersionShift)), computeValues); - *force = gmx::blend(*force, forceQuad, computeValues); + if constexpr (computeForces) + { + *force = gmx::blend(*force, forceQuad, computeValues); + } *potential = gmx::blend(*potential, potentialQuad, computeValues); *dvdl = *dvdl + gmx::selectByMask(dvdlQuad, computeValues); } -- 2.22.0