-
Notifications
You must be signed in to change notification settings - Fork 16
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
Danbr4d
wants to merge
17
commits into
develop
Choose a base branch
from
epsr-averaging
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1ad2d1b
added in start of averaging into epsrManager
Danbr4d bae42c4
add in averaged potentials
Danbr4d 2e107e9
code review updated loops and averaging
Danbr4d 2be06a0
initial addition of potentialSet class
Danbr4d 57a0c5a
cleared functions
Danbr4d ca5bb3e
added operator +=
Danbr4d 6f84266
Apply suggestions for serialise
Danbr4d 88e0bbb
correction to serialise
Danbr4d 8e345d2
added *= operator
Danbr4d b2d20d7
added operators for like terms
Danbr4d 677a2a2
registerProducer
Danbr4d dd10495
registerSerialiser
Danbr4d b1bd16b
registerDeserialiser
Danbr4d 87e8029
Apply suggestions from code review
Danbr4d b5467b8
format
Danbr4d fb0068a
added in PotentialSet changes to epsrManager
Danbr4d 7f6629e
corrected averaging and function name
Danbr4d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#include "classes/potentialSet.h" | ||
#include "base/lineParser.h" | ||
#include "classes/atomType.h" | ||
#include "classes/box.h" | ||
#include "classes/configuration.h" | ||
#include "io/export/data1D.h" | ||
#include "items/deserialisers.h" | ||
#include "items/serialisers.h" | ||
#include "templates/algorithms.h" | ||
|
||
PotentialSet::PotentialSet() { fingerprint_ = "NO_FINGERPRINT"; } | ||
|
||
PotentialSet::~PotentialSet() { potentials_.clear(); } | ||
|
||
// Reset partial arrays | ||
void PotentialSet::reset() | ||
{ | ||
potentials_.clear(); | ||
fingerprint_ = "NO_FINGERPRINT"; | ||
} | ||
|
||
// Set new fingerprint | ||
void PotentialSet::setFingerprint(std::string_view fingerprint) { fingerprint_ = fingerprint; } | ||
|
||
// Return full map of potentials specified | ||
std::map<std::string, PotentialSet::EPData> &PotentialSet::potentialMap() { return potentials_; } | ||
const std::map<std::string, PotentialSet::EPData> &PotentialSet::potentialMap() const { return potentials_; } | ||
|
||
/* | ||
* Operators | ||
*/ | ||
|
||
PotentialSet &PotentialSet::operator+=(const double delta) | ||
{ | ||
for (auto &[key, potential] : potentials_) | ||
potential.ep += delta; | ||
return (*this); | ||
} | ||
|
||
PotentialSet &PotentialSet::operator+=(const PotentialSet &source) | ||
{ | ||
for (auto &[key, potential] : source.potentialMap()) | ||
potentials_[key].ep += potential.ep; | ||
return (*this); | ||
} | ||
|
||
PotentialSet &PotentialSet::operator*=(const double factor) | ||
{ | ||
for (auto &[key, potential] : potentials_) | ||
potential.ep *= factor; | ||
return (*this); | ||
} | ||
|
||
/* | ||
* Serialisation | ||
*/ | ||
|
||
// Read data through specified LineParser | ||
bool PotentialSet::deserialise(LineParser &parser, const CoreData &coreData) | ||
{ | ||
if (parser.readNextLine(LineParser::Defaults, fingerprint_) != LineParser::Success) | ||
return false; | ||
|
||
if (parser.getArgsDelim(LineParser::Defaults) != LineParser::Success) | ||
return false; | ||
auto size = parser.argli(0); | ||
for (auto n = 0; n < size; ++n) | ||
{ | ||
if (parser.getArgsDelim(LineParser::Defaults) != LineParser::Success) | ||
return false; | ||
EPData value; | ||
auto key = parser.args(0); | ||
value.count = parser.argi(1); | ||
value.at1 = coreData.findAtomType(parser.args(2)); | ||
value.at2 = coreData.findAtomType(parser.args(3)); | ||
|
||
if (!value.ep.deserialise(parser)) | ||
return false; | ||
|
||
potentials_[key] = value; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Write data through specified LineParser | ||
bool PotentialSet::serialise(LineParser &parser) const | ||
{ | ||
if (!parser.writeLineF("{}\n", fingerprint_)) | ||
return false; | ||
if (!parser.writeLineF("{}\n", potentials_.size())) | ||
return false; | ||
for (auto &[key, value] : potentials_) | ||
{ | ||
if (!parser.writeLineF("{} {} {} {}\n", key, value.count, value.at1->name(), value.at2->name())) | ||
return false; | ||
if (!value.ep.serialise(parser)) | ||
return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#pragma once | ||
|
||
#include "classes/atomTypeMix.h" | ||
#include "classes/neutronWeights.h" | ||
#include "math/data1D.h" | ||
#include "math/histogram1D.h" | ||
#include "modules/epsr/epsr.h" | ||
#include "modules/epsrManager/epsrManager.h" | ||
#include "templates/array2D.h" | ||
|
||
// Forward Declarations | ||
class Configuration; | ||
class Interpolator; | ||
|
||
// Set of Partials | ||
class PotentialSet | ||
{ | ||
public: | ||
PotentialSet(); | ||
~PotentialSet(); | ||
|
||
/* | ||
* Potentials Data | ||
*/ | ||
private: | ||
// Fingerprint for these partials (e.g. reflecting Configuration indices at which they were calculated) | ||
std::string fingerprint_; | ||
struct EPData | ||
{ | ||
Data1D ep; | ||
double count{0}; | ||
std::shared_ptr<AtomType> at1, at2; | ||
}; | ||
// Pair matrix, containing full atom-atom partial | ||
std::map<std::string, EPData> potentials_; | ||
|
||
public: | ||
// Reset partial arrays | ||
void reset(); | ||
// Set new fingerprint | ||
void setFingerprint(std::string_view fingerprint); | ||
// Return fingerprint of partials | ||
std::string_view fingerprint() const; | ||
// Return full atom-atom partial specified | ||
std::map<std::string, EPData> &potentialMap(); | ||
const std::map<std::string, EPData> &potentialMap() const; | ||
|
||
/* | ||
* Operators | ||
*/ | ||
public: | ||
PotentialSet &operator+=(const double delta); | ||
PotentialSet &operator+=(const PotentialSet &source); | ||
PotentialSet &operator*=(const double factor); | ||
|
||
/* | ||
* Serialisation | ||
*/ | ||
public: | ||
// Read data through specified LineParser | ||
bool deserialise(LineParser &parser, const CoreData &coreData); | ||
// Write data through specified LineParser | ||
bool serialise(LineParser &parser) const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,8 +3,10 @@ | |||||
|
||||||
#pragma once | ||||||
|
||||||
#include "classes/potentialSet.h" | ||||||
#include "classes/scatteringMatrix.h" | ||||||
#include "generator/generator.h" | ||||||
#include "math/averaging.h" | ||||||
#include "module/groups.h" | ||||||
#include "module/module.h" | ||||||
#include <tuple> | ||||||
|
@@ -27,14 +29,12 @@ class EPSRManagerModule : public Module | |||||
std::optional<int> modifyPotential_{1}; | ||||||
// Vector storing atom pairs and associated potentials | ||||||
std::vector<std::tuple<std::shared_ptr<AtomType>, std::shared_ptr<AtomType>, Data1D>> potentials_; | ||||||
struct EPData | ||||||
{ | ||||||
Data1D ep; | ||||||
double count{0}; | ||||||
std::shared_ptr<AtomType> at1, at2; | ||||||
}; | ||||||
// Potential scalings | ||||||
std::string potentialScalings_; | ||||||
// Number of historical partial sets to combine into final partials | ||||||
std::optional<int> averagingLength_; | ||||||
// Weighting scheme to use when averaging partials | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Averaging::AveragingScheme averagingScheme_{Averaging::LinearAveraging}; | ||||||
|
||||||
/* | ||||||
* Functions | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.