-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analysis Refactoring - Part 2 (#1795)
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
- Loading branch information
Showing
34 changed files
with
1,082 additions
and
643 deletions.
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,31 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#pragma once | ||
|
||
#include "base/processPool.h" | ||
|
||
template <typename DataND, typename DataNDExportFileFormat> class DataExporter | ||
{ | ||
public: | ||
// Try to export the specified data, if a valid filename has been provided | ||
static bool exportData(const DataND &targetData, DataNDExportFileFormat &fileAndFormat, const ProcessPool &procPool) | ||
{ | ||
if (fileAndFormat.hasFilename()) | ||
{ | ||
if (procPool.isMaster()) | ||
{ | ||
if (fileAndFormat.exportData(targetData)) | ||
procPool.decideTrue(); | ||
else | ||
{ | ||
procPool.decideFalse(); | ||
return false; | ||
} | ||
} | ||
else if (!procPool.decision()) | ||
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
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,72 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#include "analyser/dataNormaliser2D.h" | ||
#include "math/data2D.h" | ||
#include "math/integrator.h" | ||
|
||
DataNormaliser2D::DataNormaliser2D(Data2D &targetData) : DataNormaliserBase<Data2D, NormalisationFunction2D>(targetData) {} | ||
|
||
void DataNormaliser2D::normalise(NormalisationFunction2D normalisationFunction) | ||
{ | ||
const auto &xs = targetData_.xAxis(); | ||
const auto &ys = targetData_.yAxis(); | ||
auto &values = targetData_.values(); | ||
|
||
const auto xDelta = xs.size() > 1 ? xs[1] - xs[0] : 1.0; | ||
const auto yDelta = ys.size() > 1 ? ys[1] - ys[0] : 1.0; | ||
|
||
for (auto i = 0; i < xs.size(); ++i) | ||
{ | ||
for (auto j = 0; j < ys.size(); ++j) | ||
{ | ||
values[{i, j}] = normalisationFunction(xs[i], xDelta, ys[j], yDelta, values[{i, j}]); | ||
} | ||
} | ||
} | ||
|
||
void DataNormaliser2D::normaliseByGrid() { Messenger::warn("Grid normalisation not implemented for 2D data."); } | ||
|
||
void DataNormaliser2D::normaliseBySphericalShell() | ||
{ | ||
// We expect x values to be centre-bin values, and regularly spaced | ||
const auto &xAxis = targetData_.xAxis(); | ||
const auto &yAxis = targetData_.yAxis(); | ||
auto &values = targetData_.values(); | ||
|
||
if (xAxis.size() < 2) | ||
return; | ||
|
||
// Derive first left-bin boundary from the delta between points 0 and 1 | ||
auto leftBin = xAxis[0] - (xAxis[1] - xAxis[0]) * 0.5; | ||
auto r1Cubed = pow(leftBin, 3); | ||
for (auto n = 0; n < xAxis.size(); ++n) | ||
{ | ||
auto r2Cubed = 0.0, rightBin = 0.0; | ||
for (auto m = 0; m < yAxis.size(); ++m) | ||
{ | ||
// Get new right-bin from existing left bin boundary and current bin centre | ||
auto rightBin = leftBin + 2 * (xAxis[n] - leftBin); | ||
auto r2Cubed = pow(rightBin, 3); | ||
|
||
// Calculate divisor for normalisation | ||
auto divisor = (4.0 / 3.0) * PI * (r2Cubed - r1Cubed); | ||
|
||
// Peform normalisation step | ||
values[{n, m}] /= divisor; | ||
if (targetData_.valuesHaveErrors()) | ||
targetData_.error(n, m) /= divisor; | ||
} | ||
|
||
// Overwrite old values | ||
r1Cubed = r2Cubed; | ||
leftBin = rightBin; | ||
} | ||
} | ||
|
||
void DataNormaliser2D::normaliseTo(double value, bool absolute) | ||
{ | ||
auto sum = absolute ? Integrator::absSum(targetData_) : Integrator::sum(targetData_); | ||
targetData_ /= sum; | ||
targetData_ *= value; | ||
} |
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,24 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#pragma once | ||
|
||
#include "analyser/dataNormaliserBase.h" | ||
#include "math/data2D.h" | ||
|
||
using NormalisationFunction2D = | ||
std::function<double(const double &, const double &, const double &, const double &, const double &)>; | ||
class DataNormaliser2D : public DataNormaliserBase<Data2D, NormalisationFunction2D> | ||
{ | ||
public: | ||
DataNormaliser2D(Data2D &targetData); | ||
|
||
/* | ||
* Normalisation Functions | ||
*/ | ||
public: | ||
void normalise(NormalisationFunction2D normalisationFunction) override; | ||
void normaliseByGrid() override; | ||
void normaliseBySphericalShell() override; | ||
void normaliseTo(double value = 1.0, bool absolute = true) override; | ||
}; |
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
Oops, something went wrong.