Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/classes/kVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void KVector::calculateIntensities(std::vector<BraggReflection> &reflections)
auto &braggReflection = reflections[braggReflectionIndex_];
braggReflection.addKVectors(halfSphereNorm);
dissolve::for_each_pair(
ParallelPolicies::par, 0, cosTerms_.size(),
ParallelPolicies::par, cosTerms_.size(),
[&](auto i, auto j)
{ braggReflection.addIntensity(i, j, (cosTerms_[i] * cosTerms_[j] + sinTerms_[i] * sinTerms_[j]) * halfSphereNorm); });
}
Expand Down
6 changes: 3 additions & 3 deletions src/classes/neutronWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void NeutronWeights::calculateWeightingMatrices()
double ci, cj, bi, bj;

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

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

// Normalise the boundWeights_ array, and multiply by atomic concentrations and Kronecker delta
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_.begin(), atomTypes_.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_,
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
{
// Skip this pair if there are no such intramolecular interactions
Expand Down
24 changes: 12 additions & 12 deletions src/classes/partialSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool PartialSet::setUpPartials(const AtomTypeMix &atomTypeMix, bool half)

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

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

// Zero partials
dissolve::for_each_pair(
ParallelPolicies::par, 0, atomTypeMix_.nItems(),
ParallelPolicies::par, atomTypeMix_.nItems(),
[&](int i, int j)
{
std::ranges::fill(partials_[{i, j}].values(), 0.0);
Expand Down Expand Up @@ -186,7 +186,7 @@ void PartialSet::formTotals(bool applyConcentrationWeights)
std::fill(total_.values().begin(), total_.values().end(), 0.0);

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

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

// Write partials
for_each_pair_early(
atomTypeMix_.begin(), atomTypeMix_.end(),
atomTypeMix_,
[&](int typeI, const AtomTypeData &at1, int typeJ, const AtomTypeData &at2) -> EarlyReturn<bool>
{
// Open file and check that we're OK to proceed writing to it
Expand Down Expand Up @@ -327,7 +327,7 @@ bool PartialSet::save(std::string_view prefix, std::string_view tag, std::string
void PartialSet::adjust(double delta)
{
dissolve::for_each_pair(
ParallelPolicies::par, atomTypeMix_.begin(), atomTypeMix_.end(),
ParallelPolicies::par, atomTypeMix_,
[&](int n, const AtomTypeData &at1, int m, const AtomTypeData &at2)
{
partials_[{n, m}] += delta;
Expand All @@ -345,7 +345,7 @@ void PartialSet::adjust(double delta)
void PartialSet::formPartials(double boxVolume)
{
dissolve::for_each_pair(
ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
ParallelPolicies::seq, atomTypeMix_,
[&](int n, const AtomTypeData &at1, int m, const AtomTypeData &at2)
{
// Calculate RDFs from histogram data
Expand Down Expand Up @@ -450,7 +450,7 @@ void PartialSet::operator+=(const PartialSet &source)
// Loop over partials in source set
const auto &types = source.atomTypeMix();
dissolve::for_each_pair(
ParallelPolicies::seq, types.begin(), types.end(),
ParallelPolicies::seq, types,
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
{
auto optPairIndex = atomTypeMix_.indexOf(atd1.atomType(), atd2.atomType());
Expand Down Expand Up @@ -482,7 +482,7 @@ void PartialSet::operator-=(const double delta) { adjust(-delta); }
void PartialSet::operator*=(const double factor)
{
dissolve::for_each_pair(
ParallelPolicies::par, 0, atomTypeMix_.nItems(),
ParallelPolicies::par, atomTypeMix_.nItems(),
[&](auto n, auto m)
{
partials_[{n, m}] *= factor;
Expand Down Expand Up @@ -557,7 +557,7 @@ bool PartialSet::deserialise(LineParser &parser, const CoreData &coreData)
emptyBoundPartials_ = false;

for_each_pair_early(
0, nTypes,
nTypes,
[&](int typeI, int typeJ) -> EarlyReturn<bool>
{
auto &part = partials_[{typeI, typeJ}];
Expand Down Expand Up @@ -657,7 +657,7 @@ bool PartialSet::serialise(LineParser &parser) const

// Write individual Data1D
auto success = for_each_pair_early(
0, nTypes,
nTypes,
[&](int typeI, int typeJ) -> EarlyReturn<bool>
{
const auto &part = partials_[{typeI, typeJ}];
Expand Down
4 changes: 2 additions & 2 deletions src/classes/partialSetAccumulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void PartialSetAccumulator::operator+=(const PartialSet &source)
total_.clear();

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

// Accumulate the data, ensuring tags are identical - if not, we really don't want to be blindly accumulating
dissolve::for_each_pair(
ParallelPolicies::par, 0, n,
ParallelPolicies::par, n,
[&](auto i, auto j)
{
// Full partials
Expand Down
2 changes: 1 addition & 1 deletion src/classes/scatteringMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void ScatteringMatrix::initialise(const AtomTypeMix &typeMix, Array2D<Data1D> &e
// Copy atom types and construct pairs
atomTypes_.resize(typeMix.nItems());
std::transform(typeMix.begin(), typeMix.end(), atomTypes_.begin(), [](const auto &atd) { return atd.atomType(); });
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_.begin(), atomTypes_.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes_,
[this](int i, auto &at1, int j, auto &at2) { typePairs_.emplace_back(at1, at2); });

// Create partials array
Expand Down
2 changes: 1 addition & 1 deletion src/classes/xRayWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void XRayWeights::setUpMatrices()
preFactors_.initialise(atomTypeMix_.nItems(), atomTypeMix_.nItems(), true);

// Determine atomic concentration products and full pre-factor
dissolve::for_each_pair(ParallelPolicies::seq, atomTypeMix_.begin(), atomTypeMix_.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypeMix_,
[&](int typeI, const AtomTypeData &atd1, int typeJ, const AtomTypeData &atd2)
{
double ci = atd1.fraction();
Expand Down
2 changes: 1 addition & 1 deletion src/kernels/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ PairPotentialEnergyValue EnergyKernel::pairPotentialEnergy(const Molecule &mol,
if (includeIntraMolecular)
{
auto intra = 0.0;
dissolve::for_each_pair(ParallelPolicies::seq, 0, mol.nAtoms(),
dissolve::for_each_pair(ParallelPolicies::seq, mol.nAtoms(),
[&](int i, int j)
{
if (i == j)
Expand Down
4 changes: 2 additions & 2 deletions src/kernels/force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void ForceKernel::totalForces(ForceVector &fUnbound, ForceVector &fBound, Flags<
auto &fLocal = combinableUnbound.local();

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

// Pair potential interactions between atoms within the molecule
if (!flags.isSet(ExcludeIntraMolecularPairPotential))
dissolve::for_each_pair(ParallelPolicies::seq, mol->atoms().begin(), mol->atoms().end(),
dissolve::for_each_pair(ParallelPolicies::seq, mol->atoms(),
[&](int indexI, const auto &i, int indexJ, const auto &j)
{
if (indexI == indexJ)
Expand Down
2 changes: 1 addition & 1 deletion src/main/pairPotentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool Dissolve::updatePairPotentials(std::optional<bool> useCombinationRulesHint)
pairPotentials_.end());

// Second step - add or update tabulated pair potentials defined by the parameters and form of the associated atom types
if (!for_each_pair_early(coreData_.atomTypes().begin(), coreData_.atomTypes().end(),
if (!for_each_pair_early(coreData_.atomTypes(),
[&](int typeI, const auto &at1, int typeJ, const auto &at2) -> EarlyReturn<bool>
{
// Try to locate existing pair potential between these atom types
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bragg/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool BraggModule::formReflectionFunctions(GenericList &moduleData, Configuration
double qCentre;
int bin;
auto &types = cfg->atomTypePopulations();
dissolve::for_each_pair(ParallelPolicies::seq, types.begin(), types.end(),
dissolve::for_each_pair(ParallelPolicies::seq, types,
[&](int typeI, auto &atd1, int typeJ, auto &atd2)
{
// Retrieve partial container and make sure its tag is set
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bragg/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Module::ExecutionResult BraggModule::process(Dissolve &dissolve)
// Save intensity data
auto &types = targetConfiguration_->atomTypePopulations();
auto success = for_each_pair_early(
types.begin(), types.end(),
types,
[&](int i, const AtomTypeData &atd1, int j, const AtomTypeData &atd2) -> EarlyReturn<bool>
{
LineParser intensityParser;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/epsr/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool EPSRModule::generateEmpiricalPotentials(Dissolve &dissolve, double averaged
Array2D<std::vector<double>> &coefficients = potentialCoefficients(dissolve.processingModuleData(), nAtomTypes, ncoeffp);

auto result = for_each_pair_early(
atomTypes.begin(), atomTypes.end(),
atomTypes,
[&](int i, auto at1, int j, auto at2) -> EarlyReturn<bool>
{
auto &potCoeff = coefficients[{i, j}];
Expand Down
6 changes: 3 additions & 3 deletions src/modules/epsr/gui/epsrWidgetFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void EPSRModuleWidget::updateControls(const Flags<ModuleWidget::UpdateFlags> &up
{
// Add experimentally-determined partial S(Q)
dissolve::for_each_pair(
ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
ParallelPolicies::seq, atomTypes,
[&](int typeI, const auto &at1, int typeJ, const auto &at2)
{
const std::string id = std::format("{}-{}", at1->name(), at2->name());
Expand Down Expand Up @@ -152,7 +152,7 @@ void EPSRModuleWidget::updateControls(const Flags<ModuleWidget::UpdateFlags> &up

// Add experimentally-determined partial g(r)
dissolve::for_each_pair(
ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
ParallelPolicies::seq, atomTypes,
[&](int typeI, const auto &at1, int typeJ, const auto &at2)
{
const std::string id = std::format("{}-{}", at1->name(), at2->name());
Expand Down Expand Up @@ -183,7 +183,7 @@ void EPSRModuleWidget::updateControls(const Flags<ModuleWidget::UpdateFlags> &up
else if (ui_.PotentialsButton->isChecked())
{
// Add on additional potentials
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes,
[&](int typeI, const auto &at1, int typeJ, const auto &at2)
{
const std::string id = std::format("{}-{}", at1->name(), at2->name());
Expand Down
16 changes: 8 additions & 8 deletions src/modules/epsr/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)
// Create storage for our summed UnweightedSQ
auto &calculatedUnweightedSQ = moduleData.realise<Array2D<Data1D>>("UnweightedSQ", name_, GenericItem::InRestartFileFlag);
calculatedUnweightedSQ.initialise(nAtomTypes, nAtomTypes, true);
dissolve::for_each_pair(ParallelPolicies::par, atomTypes.begin(), atomTypes.end(),
dissolve::for_each_pair(ParallelPolicies::par, atomTypes,
[&](int i, auto at1, int j, auto at2) {
calculatedUnweightedSQ[{i, j}].setTag(std::format("{}-{}", at1->name(), at2->name()));
});
Expand Down Expand Up @@ -498,7 +498,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)

// Add the unweighted from this target to our combined, unweighted S(Q) data
auto &types = scatteringMatrix_.atomTypes();
dissolve::for_each_pair(ParallelPolicies::seq, types.begin(), types.end(),
dissolve::for_each_pair(ParallelPolicies::seq, types,
[&](int i, const auto &at1, int j, const auto &at2)
{
auto pairIndex = scatteringMatrix_.pairIndexOf(at1, at2);
Expand Down Expand Up @@ -549,7 +549,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)

// Add a contribution from each interatomic partial S(Q), weighted according to the feedback factor
auto success = for_each_pair_early(
atomTypes.begin(), atomTypes.end(),
atomTypes,
[&](int i, auto at1, int j, auto at2) -> EarlyReturn<bool>
{
// Copy and rename the data for clarity
Expand Down Expand Up @@ -608,7 +608,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)
*/
auto &estimatedGR = moduleData.realise<Array2D<Data1D>>("EstimatedGR", name_, GenericItem::InRestartFileFlag);
estimatedGR.initialise(nAtomTypes, nAtomTypes, true);
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes,
[&](int i, auto at1, int j, auto at2)
{
auto &expGR = estimatedGR[{i, j}];
Expand All @@ -635,7 +635,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)

// Loop over pair potentials and retrieve the inverse weight from the scattering matrix
dissolve::for_each_pair(
ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
ParallelPolicies::seq, atomTypes,
[&](int i, auto at1, int j, auto at2)
{
auto weight = scatteringMatrix_.qZeroMatrixInverse()[{scatteringMatrix_.columnIndex(at1, at2), dataIndex}];
Expand Down Expand Up @@ -673,7 +673,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)
{
// Sum fluctuation coefficients in to the potential coefficients
auto &coefficients = potentialCoefficients(moduleData, nAtomTypes, ncoeffp);
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes,
[&](int i, auto at1, int j, auto at2)
{
auto &potCoeff = coefficients[{i, j}];
Expand Down Expand Up @@ -741,7 +741,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)
// Save data?
if (saveEmpiricalPotentials_)
{
if (!for_each_pair_early(atomTypes.begin(), atomTypes.end(),
if (!for_each_pair_early(atomTypes,
[&](int i, auto at1, int j, auto at2) -> EarlyReturn<bool>
{
// Grab pointer to the relevant pair potential
Expand All @@ -760,7 +760,7 @@ Module::ExecutionResult EPSRModule::process(Dissolve &dissolve)
{
auto &coefficients = potentialCoefficients(moduleData, nAtomTypes, ncoeffp);

if (!for_each_pair_early(atomTypes.begin(), atomTypes.end(),
if (!for_each_pair_early(atomTypes,
[&](int i, auto at1, int j, auto at2) -> EarlyReturn<bool>
{
// Grab reference to coefficients
Expand Down
2 changes: 1 addition & 1 deletion src/modules/epsrManager/gui/epsrManagerFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void EPSRManagerModuleWidget::updateControls(const Flags<ModuleWidget::UpdateFla
if (ui_.PotentialsButton->isChecked())
{
// Add on additional potentials
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes.begin(), atomTypes.end(),
dissolve::for_each_pair(ParallelPolicies::seq, atomTypes,
[&](int typeI, const auto &at1, int typeJ, const auto &at2)
{
const std::string id = std::format("{}-{}", at1->name(), at2->name());
Expand Down
4 changes: 2 additions & 2 deletions src/modules/forces/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ void ForcesModule::totalForces(const Species *sp, const PotentialMap &potentialM
if (calculationType == ForceCalculationType::Full || calculationType == ForceCalculationType::PairPotentialOnly)
{
if (sp->nAtoms() < 100)
dissolve::for_each_pair(ParallelPolicies::seq, sp->atoms().begin(), sp->atoms().end(), pairwiseForceOperator);
dissolve::for_each_pair(ParallelPolicies::seq, std::span(sp->atoms().begin(), sp->nAtoms()), pairwiseForceOperator);
else
dissolve::for_each_pair(ParallelPolicies::par, sp->atoms().begin(), sp->atoms().end(), pairwiseForceOperator);
dissolve::for_each_pair(ParallelPolicies::par, std::span(sp->atoms().begin(), sp->nAtoms()), pairwiseForceOperator);
Comment on lines +118 to +120

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curious - why the use of std::span here and nowhere else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To zeroth order: I don't know.

To first order: if I pass just pass in sp->atoms(), I get a compiler error about SpeciesAtom missing a copy constructor. It seems that the specific std::vector implementation of ranges in GCC used the copy constructor for some optimizations. Thankfully, the standard does have std::span which just takes two iterators and doesn't make any assumptions, so we can use it as a wrapper.

combinableUnbound.finalize();
}

Expand Down
Loading
Loading