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

feat: more control of averaging potentials #1970

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions src/modules/epsrManager/epsrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ EPSRManagerModule::EPSRManagerModule() : Module(ModuleTypes::EPSRManager)
keywords_.setOrganisation("Options", "Potential Scaling");
keywords_.add<StringKeyword>("PotScale", "Comma-separated list of atom type pairs and scaling factors in the form A-B=1.0",
potentialScalings_);
keywords_.setOrganisation("Options", "Averaging");
keywords_.add<OptionalIntegerKeyword>("Averaging", "Number of historical potential sets to combine into final potentials",
averagingLength_, 1, std::nullopt, 1, "Off");
keywords_.add<EnumOptionsKeyword<Averaging::AveragingScheme>>("AveragingScheme",
"Weighting scheme to use when averaging potentials",
averagingScheme_, Averaging::averagingSchemes());
}
7 changes: 7 additions & 0 deletions src/modules/epsrManager/epsrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "classes/scatteringMatrix.h"
#include "generator/generator.h"
#include "math/averaging.h"
#include "module/groups.h"
#include "module/module.h"
#include <tuple>
Expand Down Expand Up @@ -35,6 +36,12 @@ class EPSRManagerModule : public Module
};
// Potential scalings
std::string potentialScalings_;
// Number of historical partial sets to combine into final partials
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Number of historical partial sets to combine into final partials
// Number of historical partial sets to combine into final potentials

std::optional<int> averagingLength_;
// Weighting scheme to use when averaging partials
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Weighting scheme to use when averaging partials
// Weighting scheme to use when averaging potentials

Averaging::AveragingScheme averagingScheme_{Averaging::LinearAveraging};
// Vector of averaged potentials over multiple iterations
std::vector<std::map<std::string, EPData>> averagedPotentialsStore;

/*
* Functions
Expand Down
20 changes: 20 additions & 0 deletions src/modules/epsrManager/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext)
for (auto &&[key, epData] : potentials)
epData.ep /= epData.count;

std::map<std::string, EPData> averagedPotentials = potentials;

averagedPotentialsStore.emplace_back(potentials);
// Check if ran the right amount of iterations before averaging
if (averagedPotentialsStore.size() > averagingLength_)
{
averagedPotentialsStore.pop_back();
}
Copy link
Member

Choose a reason for hiding this comment

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

This won't account for cases where the user changes the averaging length and we need to remove more than one. This curation of data is also handled for us if we move to using the proper Averaging namespace functions.


// Average the potentials and replace the map with the new averaged
for (const auto &pots : averagedPotentialsStore)
{
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
for (auto &&[key, epData] : pots)
{
averagedPotentials[key].ep += epData.ep;
averagedPotentials[key].ep /= averagingLength_.value();
Copy link
Member

Choose a reason for hiding this comment

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

Careful - the value of averagingLength_ may very well not be equal to the number of potential sets in the averagedPotentialStore.

}
}
potentials = averagedPotentials;
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved

// Apply potential scalings
auto scalings = DissolveSys::splitString(potentialScalings_, ",");
for (const auto &scaling : scalings)
Expand Down