-
Notifications
You must be signed in to change notification settings - Fork 19
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: Running CNs added to SiteRDF #1819
Conversation
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.
Close! The ultimate result at the maximum of the distanceRange_
is indeed the integral of the whole histogram, and every bin up to that point is the sum of all those before it. So what you can do here is create your sumRunNHist
histogram (and maybe rename to runningCNHist
or similar) using the same distanceRange_
as histAB
.
Then, you can simply step over the bins in each with a zip
and keep track of the running bin total from histAB
as you go, adding those total values at each bin into your new histogram. Note that we should do this for the raw (i.e. instantaneous, just calculated) bins of histAB
so that we can form an average.
src/modules/siteRDF/process.cpp
Outdated
@@ -98,6 +98,35 @@ Module::ExecutionResult SiteRDFModule::process(ModuleContext &moduleContext) | |||
} | |||
} | |||
|
|||
auto &dataRunningCN = processingData.realise<SampledData1D>("RunningCNTest", name(), GenericItem::InRestartFileFlag); | |||
dataRunningCN.initialise(distanceRange_.x); |
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.
Careful - distanceRange_.x
is just the minimum value of the distance range to use. In fact, you don't need to initialise this class at all, since that will happen automatically on the first addition (+=
) to it later on.
dataRunningCN.initialise(distanceRange_.x); |
src/modules/siteRDF/process.cpp
Outdated
std::vector<double> runningCN; | ||
|
||
// Zip over all distanceRange and calculate running CN | ||
double countCN{}; | ||
for (const auto &&[x, currentCN] : zip(histAB.binCentres(), histAB.data().values())) | ||
{ | ||
runningCN[x] += currentCN; | ||
} | ||
|
||
// Add data into SampledData1D | ||
dataRunningCN += runningCN; |
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.
In fact, we can do all of this summation in a std::transform
...
std::vector<double> runningCN; | |
// Zip over all distanceRange and calculate running CN | |
double countCN{}; | |
for (const auto &&[x, currentCN] : zip(histAB.binCentres(), histAB.data().values())) | |
{ | |
runningCN[x] += currentCN; | |
} | |
// Add data into SampledData1D | |
dataRunningCN += runningCN; |
|
||
// Normalise by A site population | ||
normaliserInstBinValues.normaliseDivide(double(a.sites().size())); | ||
|
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.
Here we go. So we have the normalised bin data in instBinValues
, and we can convert that into the running coordination numbers in-place by doing this nice std::transform
. Essentially we just step over each value and calculate and return a replacement value which is the running coordination number (which we keep track of the in the sum
variable):
auto sum = 0.0; | |
std::transform(instBinValues.values().begin(), instBinValues.values().end(), instBinValues.values().begin(), [&](const auto ¤tBin) {sum += currentBin; return sum; } ); |
69b5861
to
21f3ca2
Compare
Added into SiteRDF the functionality to calculate the running coordination number for a configuration