InteractionHandler.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 #ifndef INTERACTIONHANDLER_H
26 #define INTERACTIONHANDLER_H
27 
31 #include "BaseHandler.h"
33 #include "File.h"
34 #include "MpiContainer.h"
35 #include <map>
36 
37 class SpeciesHandler;
38 
44 class InteractionHandler final : public BaseHandler<BaseInteraction>
45 {
46 public:
51 
56 
61 
65  ~InteractionHandler() override;
66 
70  void addObject(BaseInteraction* I) override;
71 
73  void read(std::istream& is);
74 
78  void readAndAddObject(std::istream& is) override;
79 
85 
87 
88  /*
89  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
90  * It is step 1 of the add-by-reduction approach:
91  * 1. Declare an empty vector newObjects_, one element per thread.
92  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
93  * Add it to newObjects_[threadNum] instead
94  * 3. Add all objects in newObjects_ to teh interactionHandler.
95  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
96  * It is efficient, since step 3 is much quicker than step 2.
97  */
98  void resetNewObjectsOMP();
99 
100  /*
101  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
102  * It is step 3 of the add-by-reduction approach:
103  * 1. Declare an empty vector newObjects_, one element per thread.
104  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
105  * Add it to newObjects_[threadNum] instead
106  * 3. Add all objects in newObjects_ to teh interactionHandler.
107  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
108  * It is efficient, since step 3 is much quicker than step 2.
109  */
110  void addNewObjectsOMP();
111 
116 
120  //BaseInteraction* getExistingInteraction(BaseInteractable* P, BaseInteractable* I) const;
121 
126 
130  void deleteEmptyInteraction(BaseInteraction* interaction) const;
131 
135  void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
136 
140  void deleteMPIInteractionDataArray(void* dataArray);
141 
145  void getInteractionDetails(void* interactionData, unsigned int index, unsigned int& identificationP,
146  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
147 
151  BaseInteraction* getInteraction(BaseInteractable* P, BaseInteractable* I, unsigned timeStamp, const Vec3D& normal);
152 
157  void removeObjectKeepingPeriodics(unsigned int id);
158 
162  void eraseOldInteractions(unsigned);
163 
164  void actionsAfterTimeStep();
165 
169  Mdouble getMeanOverlap() const;
170 
174  void write(std::ostream& os) const;
175 
179  void setWriteVTK(FileType f);
180 
181  void setWriteVTK(bool);
182 
186  FileType getWriteVTK() const;
187 
191  std::string getName() const override;
192 
193  /*
194  * This variable is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
195  * Objects are added in three steps:
196  * 1. Declare an empty vector newObjects_, one element per thread.
197  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
198  * Add it to newObjects_[threadNum] instead
199  * 3. Add all objects in newObjects_ to teh interactionHandler.
200  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
201  * It is efficient, since step 3 is much quicker than step 2.
202  */
203  std::vector<std::vector<BaseInteraction*>> newObjects_;
204 
205  double getLiquidBridgeVolume() const;
206 
207  unsigned getNumberOfLiquidBridges() const;
208 
209 private:
210 
212 
213  std::map<unsigned,BaseParticle*> particleById;
214  std::map<unsigned,BaseWall*> wallById;
215 };
216 
217 #endif
218 
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:41
#define UNUSED
Definition: GeneralDefine.h:39
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:51
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
Container to store Interaction objects.
Definition: InteractionHandler.h:45
Mdouble getMeanOverlap() const
The mean overlap of all interactions.
Definition: InteractionHandler.cc:406
void removeObjectKeepingPeriodics(unsigned int id)
Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::remo...
Definition: InteractionHandler.cc:316
void read(std::istream &is)
Definition: InteractionHandler.cc:454
unsigned getNumberOfLiquidBridges() const
Definition: InteractionHandler.cc:573
InteractionHandler()
Default constructor, it creates an empty InteractionHandler.
Definition: InteractionHandler.cc:43
~InteractionHandler() override
Destructor, it destructs the InteractionHandler and all BaseInteraction it contains.
Definition: InteractionHandler.cc:79
std::vector< std::vector< BaseInteraction * > > newObjects_
Definition: InteractionHandler.h:203
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Definition: InteractionHandler.cc:146
void deleteMPIInteractionDataArray(void *dataArray)
deletes an MPIInteractionDataArray
Definition: InteractionHandler.cc:227
void actionsAfterTimeStep()
Definition: InteractionHandler.cc:395
void resetNewObjectsOMP()
Definition: InteractionHandler.cc:122
void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
creates an empty MPIInteractionDataArray
Definition: InteractionHandler.cc:211
double getLiquidBridgeVolume() const
Definition: InteractionHandler.cc:564
std::string getName() const override
Returns the name of the object.
Definition: InteractionHandler.cc:424
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
Definition: InteractionHandler.cc:87
FileType writeVTK_
Definition: InteractionHandler.h:211
void eraseOldInteractions(unsigned)
erases interactions which have an old timestamp.
Definition: InteractionHandler.cc:377
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
Definition: InteractionHandler.cc:492
std::map< unsigned, BaseWall * > wallById
Definition: InteractionHandler.h:214
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
Definition: InteractionHandler.cc:245
void write(std::ostream &os) const
Writes the InteractionHandler to an output stream, for example a restart file.
Definition: InteractionHandler.cc:433
void addNewObjectsOMP()
Definition: InteractionHandler.cc:129
std::map< unsigned, BaseParticle * > particleById
Definition: InteractionHandler.h:213
void setWriteVTK(FileType f)
Definition: InteractionHandler.cc:549
InteractionHandler & operator=(const InteractionHandler &rhs)
Assignment operator.
Definition: InteractionHandler.cc:68
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
Definition: InteractionHandler.cc:182
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...
Definition: InteractionHandler.cc:103
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
Definition: InteractionHandler.cc:197
BaseInteraction * addInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Definition: InteractionHandler.cc:114
FileType getWriteVTK() const
Definition: InteractionHandler.cc:559
Container to store all ParticleSpecies.
Definition: SpeciesHandler.h:37
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73