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

Correctness testing with TOML #1682

Merged
merged 12 commits into from
Nov 3, 2023
12 changes: 8 additions & 4 deletions src/classes/serializablePairPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include "classes/serializablePairPotential.h"

SerializablePairPotential::SerializablePairPotential(double &range, double &delta, bool &source,
std::vector<std::shared_ptr<AtomType>> &types)
: range_(range), delta_(delta), atomTypeChargeSource_(source), atomTypes_(types),
coulombTruncationScheme_(PairPotential::coulombTruncationScheme_),
SerializablePairPotential::SerializablePairPotential(double &range, double &delta, bool &source, bool &forceCharge,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the SerializablePairPotential class? It feels like its just wrapping functionality that could be added into Dissolve::serialise() and Dissolve::deserialise()...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we need to review SerializablePairPotential, as I'm increasingly unhappy with the design. However, I'm not sure that Dissolve is the right place for it, either. I'll add an issue for it and we can review that before the final TOML addition.

bool &autoCharge, std::vector<std::shared_ptr<AtomType>> &types)
: range_(range), delta_(delta), atomTypeChargeSource_(source), atomTypes_(types), forceCharge_(forceCharge),
autoCharge_(autoCharge), coulombTruncationScheme_(PairPotential::coulombTruncationScheme_),
shortRangeTruncationScheme_(PairPotential::shortRangeTruncationScheme_){};

double &SerializablePairPotential::range() { return range_; }
Expand Down Expand Up @@ -44,6 +44,8 @@ SerialisedValue SerializablePairPotential::serialise() const
{"range", range_},
{"delta", delta_},
{"includeCoulomb", atomTypeChargeSource_},
{"forceChargeSource", forceCharge_},
{"autoChargeSource", autoCharge_},
{"coulombTruncation", PairPotential::coulombTruncationSchemes().serialise(coulombTruncationScheme_)},
{"shortRangeTruncation", PairPotential::shortRangeTruncationSchemes().serialise(shortRangeTruncationScheme_)}};
for (auto &atomType : atomTypes_)
Expand All @@ -57,6 +59,8 @@ void SerializablePairPotential::deserialise(const SerialisedValue &node)
range_ = toml::find_or<double>(node, "range", 15.0);
delta_ = toml::find_or<double>(node, "delta", 0.005);
atomTypeChargeSource_ = toml::find_or<bool>(node, "includeCoulomb", false);
forceCharge_ = toml::find_or<bool>(node, "forceChargeSource", false);
autoCharge_ = toml::find_or<bool>(node, "autoChargeSource", false);
rprospero marked this conversation as resolved.
Show resolved Hide resolved

coulombTruncationScheme_ =
PairPotential::coulombTruncationSchemes().deserialise(toml::find_or<std::string>(node, "coulombTruncation", "Shifted"));
Expand Down
5 changes: 3 additions & 2 deletions src/classes/serializablePairPotential.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SerializablePairPotential : public Serialisable<>
private:
double &range_;
double &delta_;
bool &atomTypeChargeSource_;
bool &atomTypeChargeSource_, &forceCharge_, &autoCharge_;

std::vector<std::shared_ptr<AtomType>> &atomTypes_;

Expand All @@ -24,7 +24,8 @@ class SerializablePairPotential : public Serialisable<>

// AtomTypes
public:
SerializablePairPotential(double &range, double &delta, bool &source, std::vector<std::shared_ptr<AtomType>> &types);
SerializablePairPotential(double &range, double &delta, bool &source, bool &forceCharge, bool &autoCharge,
std::vector<std::shared_ptr<AtomType>> &types);

double &range();
const double &range() const;
Expand Down
4 changes: 2 additions & 2 deletions src/main/dissolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "classes/species.h"

Dissolve::Dissolve(CoreData &coreData)
: coreData_(coreData),
serializablePairPotential_(pairPotentialRange_, pairPotentialDelta_, atomTypeChargeSource_, coreData_.atomTypes())
: coreData_(coreData), serializablePairPotential_(pairPotentialRange_, pairPotentialDelta_, atomTypeChargeSource_,
forceChargeSource_, automaticChargeSource_, coreData_.atomTypes())
{
// Set core simulation variables
restartFileFrequency_ = 10;
Expand Down
13 changes: 0 additions & 13 deletions src/main/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ SerialisedValue Dissolve::serialise() const
{
SerialisedValue root;

// If TOML is disabled,
if constexpr (!toml_testing_flag)
{
Messenger::error("This build does not support TOML.");
return root;
}

if (!coreData_.masterBonds().empty() || !coreData_.masterAngles().empty() || !coreData_.masterTorsions().empty() ||
!coreData_.masterImpropers().empty())
root["master"] = coreData_.serialiseMaster();
Expand All @@ -152,12 +145,6 @@ SerialisedValue Dissolve::serialise() const
// Read values from a serialisable value
void Dissolve::deserialise(const SerialisedValue &node)
{
// If TOML is disabled,
if constexpr (!toml_testing_flag)
{
Messenger::error("This build does not support TOML.");
return;
}

if (node.contains("pairPotentials"))
{
Expand Down
8 changes: 4 additions & 4 deletions tests/modules/avgMol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class AvgMolModuleWaterTest : public ::testing::Test

void SetUp() override
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/avgMol-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/avgMol-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));
}
};

Expand All @@ -33,7 +33,7 @@ class AvgMolModuleBendyTest : public ::testing::Test
protected:
DissolveSystemTest systemTest;

void SetUp() override { ASSERT_NO_THROW(systemTest.setUp("dissolve/input/avgMol-bendy.txt")); }
void SetUp() override { ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/avgMol-bendy.txt")); }

void checkCoordinates()
{
Expand All @@ -45,7 +45,7 @@ class AvgMolModuleBendyTest : public ::testing::Test

TEST_F(AvgMolModuleBendyTest, AverageCoordinates)
{
ASSERT_TRUE(systemTest.iterateRestart(201));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(201));

checkCoordinates();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/dAngle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DAngleModuleTest : public ::testing::Test

TEST_F(DAngleModuleTest, Water)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/dAngle.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/dAngle.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

EXPECT_TRUE(systemTest.checkData1D(
"DAngle(X-H...O)//Process1D//RDF(BC)",
Expand Down
10 changes: 5 additions & 5 deletions tests/modules/epsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EPSRModuleTest : public ::testing::Test

TEST_F(EPSRModuleTest, Water3NInpA)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-water-inpa.txt"));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-water-inpa.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Estimated Partials
Expand Down Expand Up @@ -107,7 +107,7 @@ TEST_F(EPSRModuleTest, Water3NInpA)

TEST_F(EPSRModuleTest, Water3NX)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-water-3n-x.txt"));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-water-3n-x.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Test total neutron-weighted F(r)
Expand Down Expand Up @@ -138,7 +138,7 @@ TEST_F(EPSRModuleTest, Water3NX)

TEST_F(EPSRModuleTest, Benzene)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-benzene-3n.txt"));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-benzene-3n.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Test total neutron-weighted F(r)
Expand Down Expand Up @@ -200,7 +200,7 @@ TEST_F(EPSRModuleTest, BenzeneReadPCof) { ASSERT_NO_THROW(systemTest.setUp("diss

TEST_F(EPSRModuleTest, ScatteringMatrix)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-5datasets.txt"));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-5datasets.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Find EPSR module
Expand All @@ -221,7 +221,7 @@ TEST_F(EPSRModuleTest, ScatteringMatrix)

TEST_F(EPSRModuleTest, DataWeighting)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/epsr-5datasets-weighted.txt"));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/epsr-5datasets-weighted.txt"));
ASSERT_TRUE(systemTest.dissolve().iterate(1));

// Find EPSR module
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/histogramCN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ TEST_F(HistogramCNModuleTest, Simple)

TEST_F(HistogramCNModuleTest, Water)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/histogramCN-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/histogramCN-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

EXPECT_TRUE(systemTest.checkData1D(
"CN(COM-COM)//Process1D//Histogram",
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/intraDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class IntraDistanceModuleTest : public ::testing::Test

TEST_F(IntraDistanceModuleTest, Water)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/intraDistance.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/intraDistance.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

EXPECT_TRUE(systemTest.checkData1D(
"D(O-H1)//Process1D//NormalisedHistogram",
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/orientedSDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class OrientedSDFModuleTest : public ::testing::Test

TEST_F(OrientedSDFModuleTest, Benzene)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/orientedSDF-benzene.txt"));
ASSERT_TRUE(systemTest.iterateRestart(80));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/orientedSDF-benzene.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(80));

EXPECT_TRUE(systemTest.checkData3D(
"OrientedSDF(R-R)//Process3D//SDF",
Expand Down
8 changes: 4 additions & 4 deletions tests/modules/sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class SDFModuleTest : public ::testing::Test

TEST_F(SDFModuleTest, Water)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/sdf-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/sdf-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

EXPECT_TRUE(systemTest.checkData3D(
"SDF(O)//Process3D//SDF",
Expand All @@ -26,8 +26,8 @@ TEST_F(SDFModuleTest, Water)

TEST_F(SDFModuleTest, Benzene)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/sdf-benzene.txt"));
ASSERT_TRUE(systemTest.iterateRestart(80));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/sdf-benzene.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(80));

EXPECT_TRUE(systemTest.checkData3D(
"SDF(R-R)//Process3D//SDF",
Expand Down
16 changes: 8 additions & 8 deletions tests/modules/siteRDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SiteRDFModuleTest : public ::testing::Test

TEST_F(SiteRDFModuleTest, Water)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/siteRDF-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/siteRDF-water.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

// O-O RDF
EXPECT_TRUE(systemTest.checkData1D(
Expand Down Expand Up @@ -53,8 +53,8 @@ TEST_F(SiteRDFModuleTest, Water)

TEST_F(SiteRDFModuleTest, WaterNPT)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/siteRDF-waterNPT.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/siteRDF-waterNPT.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

// O-O RDF
EXPECT_TRUE(systemTest.checkData1D(
Expand Down Expand Up @@ -83,8 +83,8 @@ TEST_F(SiteRDFModuleTest, WaterNPT)

TEST_F(SiteRDFModuleTest, WaterDynamic)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/siteRDF-waterDynamic.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/siteRDF-waterDynamic.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

// O-O RDF
EXPECT_TRUE(systemTest.checkData1D(
Expand All @@ -109,8 +109,8 @@ TEST_F(SiteRDFModuleTest, WaterDynamic)

TEST_F(SiteRDFModuleTest, WaterFragments)
{
ASSERT_NO_THROW(systemTest.setUp("dissolve/input/siteRDF-waterFragments.txt"));
ASSERT_TRUE(systemTest.iterateRestart(95));
ASSERT_NO_THROW(systemTest.setUp<TomlFailure>("dissolve/input/siteRDF-waterFragments.txt"));
ASSERT_TRUE(systemTest.iterateRestart<TomlFailure>(95));

// O-O RDF
EXPECT_TRUE(systemTest.checkData1D(
Expand Down
Loading