faunus
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Faunus::Space Class Reference

Placeholder for atoms and molecules. More...

#include <space.h>

Collaboration diagram for Faunus::Space:
Collaboration graph
[legend]

Public Types

enum  Selection {
  ALL, ACTIVE, INACTIVE, ALL_NEUTRAL,
  ACTIVE_NEUTRAL, INACTIVE_NEUTRAL
}
 
using GeometryType = Geometry::Chameleon
 
using GroupType = Group
 Continuous range of particles defining molecules.
 
using GroupVector = std::vector< GroupType >
 
using GroupRefVector = std::vector< std::reference_wrapper< Group > >
 
using ConstGroupRefVector = std::vector< std::reference_wrapper< const Group > >
 
using ScaleVolumeTrigger = std::function< void(Space &, double, double)>
 
using ChangeTrigger = std::function< void(Space &, const Change &)>
 
using SyncTrigger = std::function< void(Space &, const Space &, const Change &)>
 

Public Member Functions

const std::map< MoleculeData::index_type, std::size_t > & getImplicitReservoir () const
 Implicit molecules.
 
std::map< MoleculeData::index_type, std::size_t > & getImplicitReservoir ()
 Implicit molecules. More...
 
void clear ()
 Clears particle and molecule list.
 
GroupTypeaddGroup (MoleculeData::index_type molid, const ParticleVector &particles)
 Append a group. More...
 
GroupVector::iterator findGroupContaining (const Particle &particle, bool include_inactive=false)
 Finds the group containing the given atom.
 
GroupVector::iterator findGroupContaining (AtomData::index_type atom_index)
 Find group containing atom index.
 
size_t numParticles (Selection selection=Selection::ACTIVE) const
 Number of (active) particles.
 
Point scaleVolume (double new_volume, Geometry::VolumeMethod method=Geometry::VolumeMethod::ISOTROPIC)
 Scales atoms, molecules, container. More...
 
GroupVector::iterator randomMolecule (MoleculeData::index_type molid, Random &rand, Selection selection=Selection::ACTIVE)
 Random group matching molid.
 
json info ()
 
std::size_t getGroupIndex (const GroupType &group) const
 Get index of given group in the group vector. More...
 
std::size_t getFirstParticleIndex (const GroupType &group) const
 Index of first particle in group.
 
std::size_t getFirstActiveParticleIndex (const GroupType &group) const
 Index of first particle w. respect to active particles. More...
 
template<std::forward_iterator iterator, class copy_operation = std::function<void(const Particle&, Particle&)>>
void updateParticles (const iterator begin, const iterator end, ParticleVector::iterator destination, copy_operation copy_function=[](const Particle &src, Particle &dst) { dst=src;})
 Update particles in Space from a source range. More...
 
void updateInternalState (const Change &change)
 This will make sure that the internal state is updated to reflect a change. More...
 
auto positions () const
 Iterable range of all particle positions.
 
auto positions ()
 Mutable iterable range of all particle positions.
 
auto findMolecules (MoleculeData::index_type molid, Selection selection=Selection::ACTIVE)
 Finds all groups of type molid (complexity: order N) More...
 
auto findMolecules (MoleculeData::index_type molid, Selection selection=Selection::ACTIVE) const
 
auto activeParticles ()
 Range with all active particles.
 
auto activeParticles () const
 Range with all active particles.
 
template<std::integral index_type = int>
auto toIndices (const RequireParticles auto &particle_range) const
 Get vector of indices of given range of particles. More...
 
auto findAtoms (AtomData::index_type atomid)
 Find active atoms of type atomid (complexity: order N) More...
 
auto findAtoms (AtomData::index_type atomid) const
 Find active atoms of type atomid (complexity: order N) More...
 
size_t countAtoms (AtomData::index_type atomid) const
 Count active particles.
 
template<unsigned int mask>
auto numMolecules (MoleculeData::index_type molid) const
 Count number of molecules matching criteria. More...
 
void sync (const Space &other, const Change &change)
 Copy differing data from other Space using Change object. More...
 

Static Public Member Functions

static std::function< bool(const GroupType &)> getGroupFilter (MoleculeData::index_type molid, const Selection &selection)
 

Public Attributes

ParticleVector particles
 All particles are stored here!
 
GroupVector groups
 All groups are stored here (i.e. molecules)
 
GeometryType geometry
 Container geometry (boundaries, shape, volume)
 
std::vector< ScaleVolumeTrigger > scaleVolumeTriggers
 Functions triggered whenever the volume is scaled.
 

Detailed Description

Placeholder for atoms and molecules.

Space is pervasive in the code as it stores the state of

It has methods to insert, find, and probe particles, groups, as well as scaling the volume of the system

Member Function Documentation

◆ addGroup()

Space::GroupType & Faunus::Space::addGroup ( MoleculeData::index_type  molid,
const ParticleVector new_particles 
)

Append a group.

The following is considered:

  • groups vector is expanded with a new group at the end
  • if the space particle vector is relocated, all existing group iterators are updated to reflect the new memory positions
  • for molecular groups, the mass center is calculated and set
Parameters
molidMolecule id of inserted data
new_particlesParticles to generate group from
Returns
Reference to the inserted group
Exceptions
ifparticles is empty or if the given particles do not match the molecule id

◆ findAtoms() [1/2]

auto Faunus::Space::findAtoms ( AtomData::index_type  atomid)
inline

Find active atoms of type atomid (complexity: order N)

Parameters
atomidAtom id to look for
Returns
Range of filtered particles

◆ findAtoms() [2/2]

auto Faunus::Space::findAtoms ( AtomData::index_type  atomid) const
inline

Find active atoms of type atomid (complexity: order N)

Parameters
atomidAtom id to look for
Returns
Range of filtered particles

◆ findMolecules()

auto Faunus::Space::findMolecules ( MoleculeData::index_type  molid,
Selection  selection = Selection::ACTIVE 
)
inline

Finds all groups of type molid (complexity: order N)

Parameters
molidMolecular id to look for
selectionSelection
Returns
range with all groups of molid

◆ getFirstActiveParticleIndex()

std::size_t Faunus::Space::getFirstActiveParticleIndex ( const GroupType group) const

Index of first particle w. respect to active particles.

Returns the index of the first particle of the group in the range returned by activeParticles()

◆ getGroupFilter()

static std::function<bool(const GroupType&)> Faunus::Space::getGroupFilter ( MoleculeData::index_type  molid,
const Selection &  selection 
)
inlinestatic

< determines if range of particles is neutral

< Lambda to filter groups according to selection

◆ getGroupIndex()

std::size_t Faunus::Space::getGroupIndex ( const GroupType group) const

Get index of given group in the group vector.

Exceptions
Ifgroup is not part of space

◆ getImplicitReservoir()

std::map< MoleculeData::index_type, std::size_t > & Faunus::Space::getImplicitReservoir ( )

Implicit molecules.

Keywords to select particles based on the their active/inactive state and charge neutrality

◆ numMolecules()

template<unsigned int mask>
auto Faunus::Space::numMolecules ( MoleculeData::index_type  molid) const
inline

Count number of molecules matching criteria.

Parameters
molidMolecule id to match
Template Parameters
maskSelection mask based on Group::Selectors
Returns
Number of molecules matching molid and mask

◆ scaleVolume()

Point Faunus::Space::scaleVolume ( double  Vnew,
Geometry::VolumeMethod  method = Geometry::VolumeMethod::ISOTROPIC 
)

Scales atoms, molecules, container.

Parameters
VnewNew volume
methodScaling policy
Returns
Scaling factors in each dimension
Warning
Check new_volume/old_volume for ISOCHORIC in case of external triggers (see end of function)

< unary helper function to scale position and apply PBC

◆ sync()

void Faunus::Space::sync ( const Space other,
const Change change 
)

Copy differing data from other Space using Change object.

Parameters
otherSpace to copy from
changeChange object describing the changes beteeen the two Space objects

Copy data from another Space according to Change object. This is typically done after a Monte Carlo move has either been accepted or rejected. The other space must be populated in the exact same way, i.e. must have the same molecules and particles. In DEBUG mode, several assertions are included to ensure this is true.

Copied data includes:

  • geometry
  • groups
  • particles
  • implicit molecules

◆ toIndices()

template<std::integral index_type = int>
auto Faunus::Space::toIndices ( const RequireParticles auto &  particle_range) const
inline

Get vector of indices of given range of particles.

Returns
std::vector of indices pointing to Space::particles
Exceptions
std::out_of_rangeif any particle in range does not belong to Space::particles

◆ updateInternalState()

void Faunus::Space::updateInternalState ( const Change change)

This will make sure that the internal state is updated to reflect a change.

Typically this is called after a modification of the system, e.g. a MC move and will update the following:

  • mass centers;
  • particle trackers
  • cell lists
Todo:
Under construction and currently not in use

◆ updateParticles()

template<std::forward_iterator iterator, class copy_operation = std::function<void(const Particle&, Particle&)>>
void Faunus::Space::updateParticles ( const iterator  begin,
const iterator  end,
ParticleVector::iterator  destination,
copy_operation  copy_function = [](const Particle& src, Particle& dst) { dst = src; } 
)
inline

Update particles in Space from a source range.

Template Parameters
iteratorIterator for source range
copy_operationFunctor used to copy data from an element in the source range to element in Space:p
Parameters
beginBegin of source particle range
endEnd of source particle range
destinationIterator to target particle vector (should be in Space::p)
copy_functionFunction used to copy from source range to destination particle

By default a source range of particles is expected and all content is copied. This can be customised to e.g. a position range by giving a copy_function such as [](const auto &pos, auto &particle){particle.pos = pos;}.

The following is updated:

  • particles
  • molecular mass centers of affected groups
  • future: update cell list?
Todo:
Since Space::groups is ordered, binary search could be used to filter

The documentation for this class was generated from the following files: