15#include "autopas/containers/linkedCells/LinkedCellsReferences.h"
39template <
class Particle_T>
48 ContainerSelector(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax,
double cutoff)
49 : _boxMin(boxMin), _boxMax(boxMax), _cutoff(cutoff), _currentContainer(nullptr), _currentInfo() {}
63 void resizeBox(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax) {
67 _currentContainer = std::move(generateContainer(_currentContainer->getContainerType(), _currentInfo));
89 std::unique_ptr<autopas::ParticleContainerInterface<Particle_T>> generateContainer(
92 std::array<double, 3> _boxMin, _boxMax;
94 std::unique_ptr<autopas::ParticleContainerInterface<Particle_T>> _currentContainer;
98template <
class Particle_T>
99std::unique_ptr<autopas::ParticleContainerInterface<Particle_T>> ContainerSelector<Particle_T>::generateContainer(
100 ContainerOption containerChoice, ContainerSelectorInfo containerInfo) {
101 std::unique_ptr<autopas::ParticleContainerInterface<Particle_T>> container;
102 switch (containerChoice) {
103 case ContainerOption::directSum: {
104 container = std::make_unique<DirectSum<Particle_T>>(_boxMin, _boxMax, _cutoff, containerInfo.verletSkin,
105 containerInfo.verletRebuildFrequency);
109 case ContainerOption::linkedCells: {
110 container = std::make_unique<LinkedCells<Particle_T>>(_boxMin, _boxMax, _cutoff, containerInfo.verletSkin,
111 containerInfo.verletRebuildFrequency,
112 containerInfo.cellSizeFactor, containerInfo.loadEstimator);
115 case ContainerOption::linkedCellsReferences: {
116 container = std::make_unique<LinkedCellsReferences<Particle_T>>(
117 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
118 containerInfo.cellSizeFactor);
121 case ContainerOption::verletLists: {
122 container = std::make_unique<VerletLists<Particle_T>>(
123 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
127 case ContainerOption::verletListsCells: {
128 container = std::make_unique<VerletListsCells<Particle_T, VLCAllCellsNeighborList<Particle_T>>>(
129 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
130 containerInfo.cellSizeFactor, containerInfo.loadEstimator, VerletListsCellsHelpers::VLCBuildType::soaBuild);
133 case ContainerOption::verletClusterLists: {
134 container = std::make_unique<VerletClusterLists<Particle_T>>(
135 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
136 containerInfo.verletClusterSize, containerInfo.loadEstimator);
139 case ContainerOption::varVerletListsAsBuild: {
140 container = std::make_unique<VarVerletLists<Particle_T, VerletNeighborListAsBuild<Particle_T>>>(
141 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
142 containerInfo.cellSizeFactor);
146 case ContainerOption::pairwiseVerletLists: {
147 container = std::make_unique<VerletListsCells<Particle_T, VLCCellPairNeighborList<Particle_T>>>(
148 _boxMin, _boxMax, _cutoff, containerInfo.verletSkin, containerInfo.verletRebuildFrequency,
149 containerInfo.cellSizeFactor, containerInfo.loadEstimator, VerletListsCellsHelpers::VLCBuildType::soaBuild);
152 case ContainerOption::octree: {
154 std::make_unique<Octree<Particle_T>>(_boxMin, _boxMax, _cutoff, containerInfo.verletSkin,
155 containerInfo.verletRebuildFrequency, containerInfo.cellSizeFactor);
160 containerChoice.to_string());
165 if (_currentContainer !=
nullptr) {
167 const auto numParticlesTotal = _currentContainer->size();
169 numParticlesTotal, _currentContainer->getBoxMin(), _currentContainer->getBoxMax(),
170 _currentContainer->getInteractionLength());
172 container->reserve(numParticlesTotal, numParticlesHalo);
173 for (
auto particleIter = _currentContainer->begin(IteratorBehavior::ownedOrHalo); particleIter.isValid();
176 if (particleIter->isOwned()) {
177 container->addParticle(*particleIter);
179 container->addHaloParticle(*particleIter);
187template <
class Particle_T>
189 if (_currentContainer ==
nullptr) {
191 "ContainerSelector: getCurrentContainer() called before any container was selected!");
193 return *_currentContainer;
196template <
class Particle_T>
198 if (_currentContainer ==
nullptr) {
200 "ContainerSelector: getCurrentContainer() called before any container was selected!");
202 return *_currentContainer;
205template <
class Particle_T>
209 if (_currentContainer ==
nullptr or _currentContainer->getContainerType() != containerOption or
210 _currentInfo != containerInfo) {
211 _currentContainer = std::move(generateContainer(containerOption, containerInfo));
212 _currentInfo = containerInfo;
Info to generate a container.
Definition: ContainerSelectorInfo.h:17
Selector for a particle container.
Definition: ContainerSelector.h:40
void selectContainer(ContainerOption containerOption, ContainerSelectorInfo containerInfo)
Sets the container to the given option.
Definition: ContainerSelector.h:206
ContainerSelector(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, double cutoff)
Constructor for the ContainerSelecor class.
Definition: ContainerSelector.h:48
void resizeBox(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax)
Set new boundaries, convert the container and reevaluate particle ownership.
Definition: ContainerSelector.h:63
autopas::ParticleContainerInterface< Particle_T > & getCurrentContainer()
Getter for the optimal container.
Definition: ContainerSelector.h:188
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
@ VerletSoA
Build it using AoS.
Definition: VerletLists.h:47
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
size_t estimateNumHalosUniform(size_t numParticles, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, double haloWidth)
Given a number of particles and the dimensions of a box, estimate the number of halo particles.
Definition: NumParticlesEstimator.cpp:9
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32