MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpeciesHandler.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, 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  virtual void write(std::ostream& os) const;
87 
89  std::string getName() const override;
90 
92  bool useAngularDOFs();
93 
94 private:
96  std::vector<BaseSpecies*> mixedObjects_;
97 };
98 
99 #endif
100 
Container to store all ParticleSpecies.
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
~SpeciesHandler() override
Destructor, it destructs the SpeciesHandler and all ParticleSpecies it contains.
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
const std::vector< BaseSpecies * > & getMixedObjects() const
Returns a pointer to the vector of all mixed objects.
SpeciesHandler()
Default constructor, it creates an empty SpeciesHandler.
virtual void write(std::ostream &os) const
Write all the species and mixed species to an output stream.
ParticleSpecies * readOldObject(std::istream &is)
Reads ParticleSpecies into the SpeciesHandler from old-style restart data.
SpeciesHandler & operator=(const SpeciesHandler &rhs)
Assignment operator that copies all species and the pointer to the DPMBase from the given SpeciesHand...
std::vector< BaseSpecies * > mixedObjects_
The list of pointers to the mixed species.
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:50
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void readAndAddObject(std::istream &is) override
Reads Species data into the SpeciesHandler from restart file.
void removeObject(unsigned int index) override
Remove the ParticleSpecies with given id.
std::string getName() const override
Returns the name of the handler, namely the string "SpeciesHandler".
bool useAngularDOFs()
Check if angular DOF have to be used.
unsigned int getMixedId(unsigned int id1, unsigned int id2) const
Gets the Id of the behaviour between two given species.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
void addObject(ParticleSpecies *S) override
Adds a new ParticleSpecies to the SpeciesHandler.