From fb0068a301d11ec830e21ec2522baad4e37b2c38 Mon Sep 17 00:00:00 2001 From: Danbr4d Date: Thu, 31 Oct 2024 13:40:39 +0000 Subject: [PATCH] added in PotentialSet changes to epsrManager --- src/modules/epsrManager/epsrManager.h | 9 +--- src/modules/epsrManager/process.cpp | 71 ++++++++++++++++----------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/modules/epsrManager/epsrManager.h b/src/modules/epsrManager/epsrManager.h index 3e41c94e61..197319129d 100644 --- a/src/modules/epsrManager/epsrManager.h +++ b/src/modules/epsrManager/epsrManager.h @@ -3,6 +3,7 @@ #pragma once +#include "classes/potentialSet.h" #include "classes/scatteringMatrix.h" #include "generator/generator.h" #include "math/averaging.h" @@ -28,20 +29,12 @@ class EPSRManagerModule : public Module std::optional modifyPotential_{1}; // Vector storing atom pairs and associated potentials std::vector, std::shared_ptr, Data1D>> potentials_; - struct EPData - { - Data1D ep; - double count{0}; - std::shared_ptr at1, at2; - }; // Potential scalings std::string potentialScalings_; // Number of historical partial sets to combine into final partials std::optional averagingLength_; // Weighting scheme to use when averaging partials Averaging::AveragingScheme averagingScheme_{Averaging::LinearAveraging}; - // Vector of averaged potentials over multiple iterations - std::vector> averagedPotentialsStore; /* * Functions diff --git a/src/modules/epsrManager/process.cpp b/src/modules/epsrManager/process.cpp index 5f8c2d683e..329dcc7767 100644 --- a/src/modules/epsrManager/process.cpp +++ b/src/modules/epsrManager/process.cpp @@ -25,9 +25,19 @@ bool EPSRManagerModule::setUp(ModuleContext &moduleContext, Flags potentials; + // Does a PotentialSet already exist for this Configuration? + auto originalPotentialsObject = + moduleData.realiseIf(fmt::format("AveragingPotentials"), name_, GenericItem::InRestartFileFlag); + + PotentialSet potentials = originalPotentialsObject.first; // Loop over target data for (auto *module : target_) @@ -38,40 +48,45 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext) for (auto &&[at1, at2, ep] : eps) { auto key = EPSRManagerModule::pairKey(at1, at2); - auto keyIt = potentials.find(key); - if (keyIt == potentials.end()) - potentials[key] = {ep, 1, at1, at2}; + auto keyIt = potentials.potential().find(key); + if (keyIt == potentials.potential().end()) + potentials.potential()[key] = {ep, 1, at1, at2}; else { - Interpolator::addInterpolated(ep, potentials[key].ep, 1.0); - ++potentials[key].count; + Interpolator::addInterpolated(ep, potentials.potential()[key].ep, 1.0); + ++potentials.potential()[key].count; } } } - // Form averages - for (auto &&[key, epData] : potentials) - epData.ep /= epData.count; + // Perform averaging of potentials data if requested + if (averagingLength_) + Averaging::average>(moduleContext.dissolve().processingModuleData(), "AveragingPotentials", + name(), averagingLength_.value(), averagingScheme_); - std::map averagedPotentials = potentials; + /* // Form averages + for (auto &&[key, epData] : potentials) + epData.ep /= epData.count; - averagedPotentialsStore.emplace_back(potentials); - // Check if ran the right amount of iterations before averaging - if (averagedPotentialsStore.size() > averagingLength_) - { - averagedPotentialsStore.pop_back(); - } + std::map averagedPotentials = potentials; - // Average the potentials and replace the map with the new averaged - for (const auto &pots : averagedPotentialsStore) - { - for (auto &&[key, epData] : pots) - { - averagedPotentials[key].ep += epData.ep; - averagedPotentials[key].ep /= averagingLength_.value(); - } - } - potentials = averagedPotentials; + averagedPotentialsStore.emplace_back(potentials); + // Check if ran the right amount of iterations before averaging + if (averagedPotentialsStore.size() > averagingLength_) + { + averagedPotentialsStore.pop_back(); + } + + // Average the potentials and replace the map with the new averaged + for (const auto &pots : averagedPotentialsStore) + { + for (auto &&[key, epData] : pots) + { + averagedPotentials[key].ep += epData.ep; + averagedPotentials[key].ep /= averagingLength_.value(); + } + } + potentials = averagedPotentials; */ // Apply potential scalings auto scalings = DissolveSys::splitString(potentialScalings_, ","); @@ -91,7 +106,7 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext) Messenger::print("Apply scaling factor of {} to potential(s) {}-{}...\n", scaleFactor, typeA, typeB); auto count = 0; - for (auto &&[key, epData] : potentials) + for (auto &&[key, epData] : potentials.potential()) { // Is this potential a match if ((DissolveSys::sameWildString(typeA, epData.at1->name()) && @@ -108,7 +123,7 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext) } // Adjust global potentials - for (auto &&[key, epData] : potentials) + for (auto &&[key, epData] : potentials.potential()) { // Grab pointer to the relevant pair potential (if it exists) auto *pp = moduleContext.dissolve().pairPotential(epData.at1, epData.at2);