SpeciesHandler.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 #ifndef SPECIESHANDLER_H
28 #define SPECIESHANDLER_H
29 
30 #include "BaseHandler.h"
32 
36 class SpeciesHandler final : public BaseHandler<ParticleSpecies>
37 {
38 public:
41 
43  SpeciesHandler(const SpeciesHandler& other);
44 
47 
49  ~SpeciesHandler() override;
50 
52  void addObject(ParticleSpecies* S) override;
53 
54  void clear() override
55  {
57  mixedObjects_.clear();
58  }
59 
61  void removeObject(unsigned int index) override;
62 
64  void readAndAddObject(std::istream& is) override;
65 
67  ParticleSpecies* readOldObject(std::istream& is);
68 
70  unsigned int getMixedId(unsigned int id1, unsigned int id2) const;
71 
72  template<typename U>
73  typename std::enable_if<!std::is_pointer<typename U::MixedSpeciesType>::value, typename U::MixedSpeciesType*>::type
74  getMixedObject(const U* S, const U* T)
75  {
76  return static_cast<typename U::MixedSpeciesType*>(getMixedObject(S->getIndex(), T->getIndex()));
77  }
78 
80  BaseSpecies* getMixedObject(unsigned int id1, unsigned int id2);
81 
83  const std::vector<BaseSpecies*>& getMixedObjects() const;
84 
86  void updateMixedObjects();
87 
89  virtual void write(std::ostream& os) const;
90 
92  std::string getName() const override;
93 
95  bool useAngularDOFs();
96 
97 private:
99  std::vector<BaseSpecies*> mixedObjects_;
100 };
101 
102 #endif
103 
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:51
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
Definition: ParticleSpecies.h:37
Container to store all ParticleSpecies.
Definition: SpeciesHandler.h:37
void updateMixedObjects()
Updates the mixed species.
Definition: SpeciesHandler.cc:868
bool useAngularDOFs()
Check if angular DOF have to be used.
Definition: SpeciesHandler.cc:955
std::string getName() const override
Returns the name of the handler, namely the string "SpeciesHandler".
Definition: SpeciesHandler.cc:947
void removeObject(unsigned int index) override
Remove the ParticleSpecies with given id.
Definition: SpeciesHandler.cc:915
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: SpeciesHandler.h:54
SpeciesHandler & operator=(const SpeciesHandler &rhs)
Assignment operator that copies all species and the pointer to the DPMBase from the given SpeciesHand...
Definition: SpeciesHandler.cc:115
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
Definition: SpeciesHandler.h:99
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
Definition: SpeciesHandler.cc:814
void addObject(ParticleSpecies *S) override
Adds a new ParticleSpecies to the SpeciesHandler.
Definition: SpeciesHandler.cc:890
void readAndAddObject(std::istream &is) override
Reads Species data into the SpeciesHandler from restart file.
Definition: SpeciesHandler.cc:161
const std::vector< BaseSpecies * > & getMixedObjects() const
Returns a pointer to the vector of all mixed objects.
Definition: SpeciesHandler.cc:823
ParticleSpecies * readOldObject(std::istream &is)
Reads ParticleSpecies into the SpeciesHandler from old-style restart data.
Definition: SpeciesHandler.cc:736
~SpeciesHandler() override
Destructor, it destructs the SpeciesHandler and all ParticleSpecies it contains.
Definition: SpeciesHandler.cc:141
SpeciesHandler()
Default constructor, it creates an empty SpeciesHandler.
Definition: SpeciesHandler.cc:84
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:74
virtual void write(std::ostream &os) const
Write all the species and mixed species to an output stream.
Definition: SpeciesHandler.cc:929