Skip to content

Commit 4040c83

Browse files
authored
refactor: Range based pair algorithms (#2202)
1 parent 8701baf commit 4040c83

31 files changed

Lines changed: 873 additions & 130 deletions

src/classes/kVector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void KVector::calculateIntensities(std::vector<BraggReflection> &reflections)
7272
auto &braggReflection = reflections[braggReflectionIndex_];
7373
braggReflection.addKVectors(halfSphereNorm);
7474
dissolve::for_each_pair(
75-
ParallelPolicies::par, 0, cosTerms_.size(),
75+
ParallelPolicies::par, cosTerms_.size(),
7676
[&](auto i, auto j)
7777
{ braggReflection.addIntensity(i, j, (cosTerms_[i] * cosTerms_[j] + sinTerms_[i] * sinTerms_[j]) * halfSphereNorm); });
7878
}

src/classes/neutronWeights.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void NeutronWeights::calculateWeightingMatrices()
118118
double ci, cj, bi, bj;
119119

120120
// Determine atomic concentration products, bound coherent products, and full scattering weights
121-
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_.begin(), atomTypes_.end(),
121+
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_,
122122
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
123123
{
124124
ci = atd1.fraction();
@@ -166,7 +166,7 @@ void NeutronWeights::calculateWeightingMatrices()
166166
auto weight = speciesWeight * isoWeight.weight();
167167
const auto *tope = isoWeight.isotopologue();
168168

169-
dissolve::for_each_pair(ParallelPolicies::seq, speciesAtomTypes.begin(), speciesAtomTypes.end(),
169+
dissolve::for_each_pair(ParallelPolicies::seq, speciesAtomTypes,
170170
[&](int spTypeI, const AtomTypeData &atd1, int spTypeJ, const AtomTypeData &atd2)
171171
{
172172
// First, check that both of atom types used in the species are present in the weights
@@ -200,7 +200,7 @@ void NeutronWeights::calculateWeightingMatrices()
200200
}
201201

202202
// Normalise the boundWeights_ array, and multiply by atomic concentrations and Kronecker delta
203-
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_.begin(), atomTypes_.end(),
203+
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_,
204204
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
205205
{
206206
// Skip this pair if there are no such intramolecular interactions

src/classes/partialSet.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool PartialSet::setUpPartials(const AtomTypeMix &atomTypeMix, bool half)
5959

6060
// Set up array matrices for partials
6161
dissolve::for_each_pair(
62-
ParallelPolicies::par, atomTypeMix_.begin(), atomTypeMix_.end(),
62+
ParallelPolicies::par, atomTypeMix_,
6363
[&](int n, const AtomTypeData &at1, int m, const AtomTypeData &at2)
6464
{
6565
partials_[{n, m}].setTag(std::format("{}-{}//Full", at1.atomTypeName(), at2.atomTypeName()));
@@ -89,7 +89,7 @@ void PartialSet::setUpHistograms(double rdfRange, double binWidth)
8989
unboundHistograms_.initialise(nTypes, nTypes, half_);
9090

9191
dissolve::for_each_pair(
92-
ParallelPolicies::par, 0, nTypes,
92+
ParallelPolicies::par, nTypes,
9393
[&](int i, int j)
9494
{
9595
fullHistograms_[{i, j}].initialise(0.0, rdfRange, binWidth);
@@ -113,7 +113,7 @@ void PartialSet::reset()
113113

114114
// Zero partials
115115
dissolve::for_each_pair(
116-
ParallelPolicies::par, 0, atomTypeMix_.nItems(),
116+
ParallelPolicies::par, atomTypeMix_.nItems(),
117117
[&](int i, int j)
118118
{
119119
std::ranges::fill(partials_[{i, j}].values(), 0.0);
@@ -186,7 +186,7 @@ void PartialSet::formTotals(bool applyConcentrationWeights)
186186
std::fill(total_.values().begin(), total_.values().end(), 0.0);
187187

188188
dissolve::for_each_pair(
189-
ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
189+
ParallelPolicies::seq, atomTypeMix_,
190190
[&](int typeI, const AtomTypeData &at1, int typeJ, const AtomTypeData &at2)
191191
{
192192
// Set weighting factor if requested
@@ -229,7 +229,7 @@ void PartialSet::formTRTotals(NeutronWeights weights)
229229
std::fill(total_.values().begin(), total_.values().end(), 0.0);
230230

231231
dissolve::for_each_pair(
232-
ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
232+
ParallelPolicies::seq, atomTypeMix_,
233233
[&](int typeI, const AtomTypeData &at1, int typeJ, const AtomTypeData &at2)
234234
{
235235
// Set weighting factor if requested
@@ -280,7 +280,7 @@ bool PartialSet::save(std::string_view prefix, std::string_view tag, std::string
280280

281281
// Write partials
282282
for_each_pair_early(
283-
atomTypeMix_.begin(), atomTypeMix_.end(),
283+
atomTypeMix_,
284284
[&](int typeI, const AtomTypeData &at1, int typeJ, const AtomTypeData &at2) -> EarlyReturn<bool>
285285
{
286286
// Open file and check that we're OK to proceed writing to it
@@ -327,7 +327,7 @@ bool PartialSet::save(std::string_view prefix, std::string_view tag, std::string
327327
void PartialSet::adjust(double delta)
328328
{
329329
dissolve::for_each_pair(
330-
ParallelPolicies::par, atomTypeMix_.begin(), atomTypeMix_.end(),
330+
ParallelPolicies::par, atomTypeMix_,
331331
[&](int n, const AtomTypeData &at1, int m, const AtomTypeData &at2)
332332
{
333333
partials_[{n, m}] += delta;
@@ -345,7 +345,7 @@ void PartialSet::adjust(double delta)
345345
void PartialSet::formPartials(double boxVolume)
346346
{
347347
dissolve::for_each_pair(
348-
ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
348+
ParallelPolicies::seq, atomTypeMix_,
349349
[&](int n, const AtomTypeData &at1, int m, const AtomTypeData &at2)
350350
{
351351
// Calculate RDFs from histogram data
@@ -450,7 +450,7 @@ void PartialSet::operator+=(const PartialSet &source)
450450
// Loop over partials in source set
451451
const auto &types = source.atomTypeMix();
452452
dissolve::for_each_pair(
453-
ParallelPolicies::seq, types.begin(), types.end(),
453+
ParallelPolicies::seq, types,
454454
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
455455
{
456456
auto optPairIndex = atomTypeMix_.indexOf(atd1.atomType(), atd2.atomType());
@@ -482,7 +482,7 @@ void PartialSet::operator-=(const double delta) { adjust(-delta); }
482482
void PartialSet::operator*=(const double factor)
483483
{
484484
dissolve::for_each_pair(
485-
ParallelPolicies::par, 0, atomTypeMix_.nItems(),
485+
ParallelPolicies::par, atomTypeMix_.nItems(),
486486
[&](auto n, auto m)
487487
{
488488
partials_[{n, m}] *= factor;
@@ -557,7 +557,7 @@ bool PartialSet::deserialise(LineParser &parser, const CoreData &coreData)
557557
emptyBoundPartials_ = false;
558558

559559
for_each_pair_early(
560-
0, nTypes,
560+
nTypes,
561561
[&](int typeI, int typeJ) -> EarlyReturn<bool>
562562
{
563563
auto &part = partials_[{typeI, typeJ}];
@@ -657,7 +657,7 @@ bool PartialSet::serialise(LineParser &parser) const
657657

658658
// Write individual Data1D
659659
auto success = for_each_pair_early(
660-
0, nTypes,
660+
nTypes,
661661
[&](int typeI, int typeJ) -> EarlyReturn<bool>
662662
{
663663
const auto &part = partials_[{typeI, typeJ}];

src/classes/partialSetAccumulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void PartialSetAccumulator::operator+=(const PartialSet &source)
2323
total_.clear();
2424

2525
// Copy tags (for retrieval and sanity checking purposes)
26-
dissolve::for_each_pair(ParallelPolicies::par, 0, n,
26+
dissolve::for_each_pair(ParallelPolicies::par, n,
2727
[&](auto i, auto j)
2828
{
2929
partials_[{i, j}].setTag(source.partial(i, j).tag());
@@ -37,7 +37,7 @@ void PartialSetAccumulator::operator+=(const PartialSet &source)
3737

3838
// Accumulate the data, ensuring tags are identical - if not, we really don't want to be blindly accumulating
3939
dissolve::for_each_pair(
40-
ParallelPolicies::par, 0, n,
40+
ParallelPolicies::par, n,
4141
[&](auto i, auto j)
4242
{
4343
// Full partials

src/classes/scatteringMatrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void ScatteringMatrix::initialise(const AtomTypeMix &typeMix, Array2D<Data1D> &e
355355
// Copy atom types and construct pairs
356356
atomTypes_.resize(typeMix.nItems());
357357
std::transform(typeMix.begin(), typeMix.end(), atomTypes_.begin(), [](const auto &atd) { return atd.atomType(); });
358-
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_.begin(), atomTypes_.end(),
358+
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_,
359359
[this](int i, auto &at1, int j, auto &at2) { typePairs_.emplace_back(at1, at2); });
360360

361361
// Create partials array

src/classes/xRayWeights.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void XRayWeights::setUpMatrices()
135135
preFactors_.initialise(atomTypeMix_.nItems(), atomTypeMix_.nItems(), true);
136136

137137
// Determine atomic concentration products and full pre-factor
138-
dissolve::for_each_pair(ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
138+
dissolve::for_each_pair(ParallelPolicies::seq, atomTypeMix_,
139139
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
140140
{
141141
double ci = atd1.fraction();

src/kernels/energy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PairPotentialEnergyValue EnergyKernel::pairPotentialEnergy(const Molecule &mol,
282282
if (includeIntraMolecular)
283283
{
284284
auto intra = 0.0;
285-
dissolve::for_each_pair(ParallelPolicies::seq, 0, mol.nAtoms(),
285+
dissolve::for_each_pair(ParallelPolicies::seq, mol.nAtoms(),
286286
[&](int i, int j)
287287
{
288288
if (i == j)

src/kernels/force.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void ForceKernel::totalForces(ForceVector &fUnbound, ForceVector &fBound, Flags<
159159
auto &fLocal = combinableUnbound.local();
160160

161161
// Interatomic interactions between atoms in this cell, excluding those within the same molecule
162-
dissolve::for_each_pair(ParallelPolicies::seq, cellI->atoms().begin(), cellI->atoms().end(),
162+
dissolve::for_each_pair(ParallelPolicies::seq, cellI->atoms(),
163163
[&](int indexI, const auto &i, int indexJ, const auto &j)
164164
{
165165
if (indexI == indexJ)
@@ -199,7 +199,7 @@ void ForceKernel::totalForces(ForceVector &fUnbound, ForceVector &fBound, Flags<
199199

200200
// Pair potential interactions between atoms within the molecule
201201
if (!flags.isSet(ExcludeIntraMolecularPairPotential))
202-
dissolve::for_each_pair(ParallelPolicies::seq, mol->atoms().begin(), mol->atoms().end(),
202+
dissolve::for_each_pair(ParallelPolicies::seq, mol->atoms(),
203203
[&](int indexI, const auto &i, int indexJ, const auto &j)
204204
{
205205
if (indexI == indexJ)

src/main/pairPotentials.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool Dissolve::updatePairPotentials(std::optional<bool> useCombinationRulesHint)
119119
pairPotentials_.end());
120120

121121
// Second step - add or update tabulated pair potentials defined by the parameters and form of the associated atom types
122-
if (!for_each_pair_early(coreData_.atomTypes().begin(), coreData_.atomTypes().end(),
122+
if (!for_each_pair_early(coreData_.atomTypes(),
123123
[&](int typeI, const auto &at1, int typeJ, const auto &at2) -> EarlyReturn<bool>
124124
{
125125
// Try to locate existing pair potential between these atom types

src/modules/bragg/functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool BraggModule::formReflectionFunctions(GenericList &moduleData, Configuration
347347
double qCentre;
348348
int bin;
349349
auto &types = cfg->atomTypePopulations();
350-
dissolve::for_each_pair(ParallelPolicies::seq, types.begin(), types.end(),
350+
dissolve::for_each_pair(ParallelPolicies::seq, types,
351351
[&](int typeI, auto &atd1, int typeJ, auto &atd2)
352352
{
353353
// Retrieve partial container and make sure its tag is set

0 commit comments

Comments
 (0)