Skip to content

Commit

Permalink
Migrated the static spheres test to the unit testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
toastedcrumpets committed Nov 29, 2013
1 parent 1ed2d8d commit 3010214
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 107 deletions.
4 changes: 3 additions & 1 deletion src/dynamo/jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ unit-test infmass_spheres_test : tests/infmass_spheres_test.cpp dynamo_core/<coi

unit-test lines_test : tests/lines_test.cpp dynamo_core/<coil-integration>no /system//boost_unit_test_framework : <coil-integration>no <dynamo-buildable>no:<build>no <tag>@tags.exe-naming ;

alias test : scheduler_sorter_test hardsphere_test binaryhardsphere_test squarewell_test 2dstepped_potential_test infmass_spheres_test lines_test ;
unit-test static_spheres_test : tests/static_spheres_test.cpp dynamo_core/<coil-integration>no /system//boost_unit_test_framework : <coil-integration>no <dynamo-buildable>no:<build>no <tag>@tags.exe-naming ;

alias test : scheduler_sorter_test hardsphere_test binaryhardsphere_test squarewell_test 2dstepped_potential_test infmass_spheres_test lines_test static_spheres_test ;
88 changes: 88 additions & 0 deletions src/dynamo/tests/static_spheres_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#define BOOST_TEST_MODULE Static_Spheres_test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include <dynamo/simulation.hpp>
#include <dynamo/BC/include.hpp>
#include <dynamo/ranges/include.hpp>
#include <dynamo/inputplugins/cells/include.hpp>
#include <dynamo/species/point.hpp>
#include <dynamo/species/fixedCollider.hpp>
#include <dynamo/dynamics/gravity.hpp>
#include <dynamo/schedulers/include.hpp>
#include <dynamo/schedulers/sorters/include.hpp>
#include <dynamo/locals/lwall.hpp>
#include <dynamo/inputplugins/include.hpp>
#include <dynamo/inputplugins/compression.hpp>
#include <dynamo/interactions/hardsphere.hpp>
#include <dynamo/outputplugins/misc.hpp>
#include <dynamo/outputplugins/msd.hpp>
#include <random>

std::mt19937 RNG;

dynamo::Vector getRandVelVec()
{
//See http://mathworld.wolfram.com/SpherePointPicking.html
std::normal_distribution<> normal_dist(0.0, (1.0 / sqrt(double(NDIM))));

dynamo::Vector tmpVec;
for (size_t iDim = 0; iDim < NDIM; iDim++)
tmpVec[iDim] = normal_dist(RNG);

return tmpVec;
}

void init(dynamo::Simulation& Sim, const double density)
{
RNG.seed(std::random_device()());
Sim.ranGenerator.seed(std::random_device()());
Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynGravity(&Sim, dynamo::Vector(0,-1,0)));
Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCNone(&Sim));
Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new dynamo::FELCBT()));
Sim.primaryCellSize = dynamo::Vector(52,52,52);

Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeRange(0, 0), 1.0, "Bulk", 0)));
Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpFixedCollider(&Sim, new dynamo::IDRangeRange(1, 8), "FixedColliders", 1)));

Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, 1.0, 1, new dynamo::IDPairRangeAll(), "Bulk")));

Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, 1.0, 1.0, dynamo::Vector(0,1,0), dynamo::Vector(0,-2.67753263802375e+01,0), "GroundPlate", new dynamo::IDRangeAll(&Sim))));

Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0, 4, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0.6, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-1.51, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-2.51, 1.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(1.6, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(2, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-0.75, 0.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));

Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);
}

BOOST_AUTO_TEST_CASE( Test_Simulation )
{
{
dynamo::Simulation Sim;
init(Sim, 0.5);
Sim.initialise();
Sim.writeXMLfile("staticsphere.xml");
}

dynamo::Simulation Sim;
Sim.loadXMLfile("staticsphere.xml");

Sim.endEventCount = 500000;
Sim.addOutputPlugin("Misc");
Sim.initialise();
while (Sim.runSimulationStep()) {}

const double expectedMFT = 7.81945252098576;
dynamo::OPMisc& opMisc = *Sim.getOutputPlugin<dynamo::OPMisc>();
//Check the mean free time is roughly what is expected
double MFT = opMisc.getMFT();
BOOST_CHECK_CLOSE(MFT, expectedMFT, 0.1);
BOOST_CHECK_MESSAGE(Sim.checkSystem() <= 1, "There are more than two invalid states in the final configuration");
}
79 changes: 0 additions & 79 deletions test/static-spheres.xml

This file was deleted.

27 changes: 0 additions & 27 deletions test/test_dynarun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,6 @@ function GravityPlateTest {
tmp.xml.bz2 run.log
}

function StaticSpheresTest {
> run.log

./dynarun -c 500000 static-spheres.xml >> run.log 2>&1

if [ -e output.xml.bz2 ]; then
if [ $(bzcat output.xml.bz2 \
| $Xml sel -t -v '/OutputData/Misc/totMeanFreeTime/@val' \
| gawk '{mft=7.81945252098576; var=($1-mft)/mft; print ((var < 0.02) && (var > -0.02))}') != "1" ]; then
echo "StaticSpheresTest -: FAILED"
exit 1
else
echo "StaticSpheresTest -: PASSED"
fi
else
echo "Error, no output.0.xml.bz2 in StaticSpheresTest"
exit 1
fi

#Cleanup
rm -Rf config.end.xml.bz2 config.out.xml.bz2 output.xml.bz2 \
tmp.xml.bz2 run.log
}

function SwingSpheresTest {
> run.log

Expand Down Expand Up @@ -424,9 +400,6 @@ function BinaryThermalisedGranulate {
rm -Rf output.xml.bz2 config.out.xml.bz2 run.log
}

echo "INTERACTIONS+Dynamod Systems"
echo "Testing static spheres in gravity, NeighbourLists and BoundedPQ's"
StaticSpheresTest
#######THIS TEST IS GOOD, BUT A RECENT PATCH CHANGED THE cubic root finder, altering the result##### PLEASE RECALIBRATE
#echo "Testing static and bonded spheres in gravity, NeighbourLists and BoundedPQ's"
#SwingSpheresTest
Expand Down

0 comments on commit 3010214

Please sign in to comment.