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());
}
5 changes: 5 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,10 @@ 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};

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

// Vector of averaged potentials over multiple iterations
std::vector<std::map<std::string, EPData>> averagedPotentialsStore;
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
std::map<std::string, EPData> averagedPotentials = potentials;
// Check if ran the right amount of iterations before averaging
if (averagedPotentialsStore.size() < averagingLength_)
{
// If not then add data to vector
averagedPotentialsStore.emplace_back(potentials);
}
else
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
{
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
// If yes then average the potentials and replace the map with the new averaged
for (auto n : averagedPotentialsStore)
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
{
for (auto &&[key, epData] : n)
{
averagedPotentials[key].ep += epData.ep;
Danbr4d marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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