MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InteractionHandler.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 #ifndef INTERACTIONHANDLER_H
26 #define INTERACTIONHANDLER_H
27 
30 #include "BaseHandler.h"
32 #include "File.h"
33 #include "MpiContainer.h"
34 #include <map>
35 
36 class SpeciesHandler;
37 
43 class InteractionHandler final : public BaseHandler<BaseInteraction>
44 {
45 public:
50 
55 
60 
64  ~InteractionHandler() override;
65 
69  void addObject(BaseInteraction* I) override;
70 
72  void read(std::istream& is);
73 
77  void readAndAddObject(std::istream& is) override;
78 
84 
86 
87  /*
88  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
89  * It is step 1 of the add-by-reduction approach:
90  * 1. Declare an empty vector newObjects_, one element per thread.
91  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
92  * Add it to newObjects_[threadNum] instead
93  * 3. Add all objects in newObjects_ to teh interactionHandler.
94  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
95  * It is efficient, since step 3 is much quicker than step 2.
96  */
97  void resetNewObjectsOMP();
98 
99  /*
100  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
101  * It is step 3 of the add-by-reduction approach:
102  * 1. Declare an empty vector newObjects_, one element per thread.
103  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
104  * Add it to newObjects_[threadNum] instead
105  * 3. Add all objects in newObjects_ to teh interactionHandler.
106  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
107  * It is efficient, since step 3 is much quicker than step 2.
108  */
109  void addNewObjectsOMP();
110 
115 
119  //BaseInteraction* getExistingInteraction(BaseInteractable* P, BaseInteractable* I) const;
120 
125 
129  void deleteEmptyInteraction(BaseInteraction* interaction) const;
130 
134  void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
135 
139  void deleteMPIInteractionDataArray(void* dataArray);
140 
144  void getInteractionDetails(void* interactionData, unsigned int index, unsigned int& identificationP,
145  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
146 
150  BaseInteraction* getInteraction(BaseInteractable* P, BaseInteractable* I, unsigned timeStamp, const Vec3D& normal);
151 
156  void removeObjectKeepingPeriodics(unsigned int id);
157 
161  void eraseOldInteractions(unsigned);
162 
163  void actionsAfterTimeStep();
164 
168  Mdouble getMeanOverlap() const;
169 
173  void write(std::ostream& os) const;
174 
178  void setWriteVTK(FileType f);
179 
183  FileType getWriteVTK() const;
184 
188  std::string getName() const override;
189 
190  /*
191  * This variable is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
192  * Objects are added in three steps:
193  * 1. Declare an empty vector newObjects_, one element per thread.
194  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
195  * Add it to newObjects_[threadNum] instead
196  * 3. Add all objects in newObjects_ to teh interactionHandler.
197  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
198  * It is efficient, since step 3 is much quicker than step 2.
199  */
200  std::vector<std::vector<BaseInteraction*>> newObjects_;
201 
202  double getLiquidBridgeVolume() const;
203 
204 private:
205 
207 
208  std::map<unsigned,BaseParticle*> particleById;
209  std::map<unsigned,BaseWall*> wallById;
210 };
211 
212 #endif
213 
Container to store all ParticleSpecies.
InteractionHandler & operator=(const InteractionHandler &rhs)
Assignment operator.
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
void eraseOldInteractions(unsigned)
erases interactions which have an old timestamp.
void write(std::ostream &os) const
Writes the InteractionHandler to an output stream, for example a restart file.
FileType getWriteVTK() const
double Mdouble
Definition: GeneralDefine.h:34
void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
creates an empty MPIInteractionDataArray
std::map< unsigned, BaseParticle * > particleById
void read(std::istream &is)
void removeObjectKeepingPeriodics(unsigned int id)
Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::remo...
~InteractionHandler() override
Destructor, it destructs the InteractionHandler and all BaseInteraction it contains.
InteractionHandler()
Default constructor, it creates an empty InteractionHandler.
void deleteMPIInteractionDataArray(void *dataArray)
deletes an MPIInteractionDataArray
Mdouble getMeanOverlap() const
The mean overlap of all interactions.
Stores information about interactions between two interactable objects; often particles but could be ...
std::string getName() const override
Returns the name of the object.
FileType
With FileType options, one is able to choose if data is to be read/written from/into no or single or ...
Definition: File.h:40
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
void getInteractionDetails(void *interactionData, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
reads the basic interaction details from an MPIInteractionDataArray
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Container to store Interaction objects.
BaseInteraction * addInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
#define UNUSED
Definition: GeneralDefine.h:39
double getLiquidBridgeVolume() const
std::vector< std::vector< BaseInteraction * > > newObjects_
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:50
std::map< unsigned, BaseWall * > wallById
void setWriteVTK(FileType f)
Defines the basic properties that a interactable object can have.
Definition: Vector.h:49
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
BaseInteraction * getExistingInteraction(const BaseInteractable *P, const BaseInteractable *I) const
Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null...