Skip to content

Commit

Permalink
Improved SOcells to allow arbitrarily large cell diameters
Browse files Browse the repository at this point in the history
  • Loading branch information
toastedcrumpets committed Dec 21, 2019
1 parent 06024e5 commit 7005a67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/dynamo/dynamo/globals/socells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <boost/math/special_functions/pow.hpp>
#include <magnet/xmlwriter.hpp>
#include <magnet/xmlreader.hpp>
#include <magnet/intersection/ray_sphere.hpp>

namespace dynamo {
GSOCells::GSOCells(dynamo::Simulation* nSim, const std::string& name):
Expand Down Expand Up @@ -86,9 +87,6 @@ namespace dynamo {
//The following is not needed as we compensate for particle delay
//Sim->dynamics->updateParticle(part);

//Create a fake particle which represents the cell center
const Particle cellParticle(cell_origins[part.getID()], Vector({0,0,0}), -1);

//Vector pos = part.getPosition() - cellParticle.getPosition();
//Sim->BCs->applyBC(pos); //We don't apply the PBC, as
//if (part.getID() == 2) {
Expand All @@ -104,8 +102,11 @@ namespace dynamo {
// dout << "#Relative final p" << (finalP.nrm() - _cellD)/_cellD<< std::endl;
// dout << " cell origin " << cell_origins[part.getID()] / Sim->units.unitLength() << std::endl;
//}

return Event(part, Sim->dynamics->SphereSphereOutRoot(part, cellParticle, _cellD/2) - Sim->dynamics->getParticleDelay(part), GLOBAL, CELL, ID);

const Vector r12 = part.getPosition() - cell_origins[part.getID()];
const Vector v12 = part.getVelocity();

return Event(part, magnet::intersection::ray_sphere<true>(r12, v12, _cellD/2) - Sim->dynamics->getParticleDelay(part), GLOBAL, CELL, ID);
}

void
Expand Down Expand Up @@ -170,15 +171,17 @@ namespace dynamo {
_cellD = std::cbrt(cellVolume * 6 / M_PI);
}

if (((_cellD >= 0.5 * Sim->primaryCellSize[0])
|| (_cellD >= 0.5 * Sim->primaryCellSize[1])
|| (_cellD >= 0.5 * Sim->primaryCellSize[2]))
&& (std::dynamic_pointer_cast<BCPeriodic>(Sim->BCs)))
M_throw() << "ERROR: SOCells diameter (" << _cellD / Sim->units.unitLength() << ") is more than half the primary image size (" << Sim->primaryCellSize << "), this will break in periodic boundary conditions";
//We need to use unwrapped positions always to stop particles
//being wrapped into the primary cell and somehow out of their
//SOcell.
Sim->_force_unwrapped = true;

if (typeid(*Sim->dynamics) != typeid(DynNewtonian))
M_throw() << "ERROR: SOCells requires Newtonian dynamics, its not been generalised for other dynamics yet.";

for (const Particle& p : Sim->particles) {
Vector pos = p.getPosition() - cell_origins[p.getID()];
Sim->BCs->applyBC(pos);

if (pos.nrm2() > _cellD * _cellD)
derr << "Particle " << p.getID() << " is at a distance of "
<< (pos).nrm() / Sim->units.unitLength()
Expand Down
4 changes: 4 additions & 0 deletions src/dynamo/dynamo/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace dynamo
endEventCount(100000),
eventPrintInterval(50000),
nextPrintEvent(0),
_force_unwrapped(false),
primaryCellSize({1,1,1}),
ranGenerator(std::random_device()()),
lastRunMFT(0.0),
Expand Down Expand Up @@ -426,6 +427,9 @@ namespace dynamo
void
Simulation::writeXMLfile(std::string fileName, bool applyBC, bool round)
{
//Facilitate forced unwrapping when needed
applyBC = applyBC || _force_unwrapped;

namespace xml = magnet::xml;
xml::XmlStream XML;
XML.setFormatXML(true);
Expand Down
5 changes: 5 additions & 0 deletions src/dynamo/dynamo/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ namespace dynamo
output collision number.*/
size_t nextPrintEvent;

/*! \brief Force the output file to have particles in unwrapped
coordinates. Needed for some interactions that break
periodicity (like SOCells).*/
bool _force_unwrapped;

/*! \brief Number of Particle's in the system. */
size_t N() const { return particles.size(); }

Expand Down

0 comments on commit 7005a67

Please sign in to comment.