InteractionHandler.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef INTERACTIONHANDLER_H
6 #define INTERACTIONHANDLER_H
7 
11 #include "BaseHandler.h"
13 #include "File.h"
14 #include "MpiContainer.h"
15 #include <map>
16 
17 class SpeciesHandler;
18 
24 class InteractionHandler final : public BaseHandler<BaseInteraction>
25 {
26 public:
31 
36 
41 
45  ~InteractionHandler() override;
46 
50  void addObject(BaseInteraction* I) override;
51 
53  void read(std::istream& is);
54 
58  void readAndAddObject(std::istream& is) override;
59 
65 
67 
68  /*
69  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
70  * It is step 1 of the add-by-reduction approach:
71  * 1. Declare an empty vector newObjects_, one element per thread.
72  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
73  * Add it to newObjects_[threadNum] instead
74  * 3. Add all objects in newObjects_ to the interactionHandler.
75  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
76  * It is efficient, since step 3 is much quicker than step 2.
77  */
78  void resetNewObjectsOMP();
79 
80  /*
81  * This function is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
82  * It is step 3 of the add-by-reduction approach:
83  * 1. Declare an empty vector newObjects_, one element per thread.
84  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
85  * Add it to newObjects_[threadNum] instead
86  * 3. Add all objects in newObjects_ to the interactionHandler.
87  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
88  * It is efficient, since step 3 is much quicker than step 2.
89  */
90  void addNewObjectsOMP();
91 
96 
100  //BaseInteraction* getExistingInteraction(BaseInteractable* P, BaseInteractable* I) const;
101 
106 
110  void deleteEmptyInteraction(BaseInteraction* interaction) const;
111 
115  void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
116 
120  void deleteMPIInteractionDataArray(void* dataArray);
121 
125  void getInteractionDetails(void* interactionData, unsigned int index, unsigned int& identificationP,
126  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
127 
132 
137  void removeObjectKeepingPeriodics(unsigned int id);
138 
142  void eraseOldInteractions(unsigned);
143 
144  void actionsAfterTimeStep();
145 
149  Mdouble getMeanOverlap() const;
150 
154  void write(std::ostream& os) const;
155 
159  void setWriteVTK(FileType f);
160 
161  void setWriteVTK(bool);
162 
166  FileType getWriteVTK() const;
167 
171  std::string getName() const override;
172 
173  /*
174  * This variable is used in omp simulations to add new objects to the interactionHandler during computeOneTimeStep.
175  * Objects are added in three steps:
176  * 1. Declare an empty vector newObjects_, one element per thread.
177  * 2. When a new object needs to be added to the interactionHandler, don't add it immediately.
178  * Add it to newObjects_[threadNum] instead
179  * 3. Add all objects in newObjects_ to the interactionHandler.
180  * This reduction approach allows step 2 to be run in parallel, while step 3 needs to be done in sequence.
181  * It is efficient, since step 3 is much quicker than step 2.
182  */
183  std::vector<std::vector<BaseInteraction*>> newObjects_;
184 
185  double getLiquidBridgeVolume() const;
186 
187  unsigned getNumberOfLiquidBridges() const;
188 
189  unsigned getNumberOfWallContacts() const;
190 
191 private:
192 
194 
195  std::map<unsigned,BaseParticle*> particleById;
196  std::map<unsigned,BaseWall*> wallById;
197 };
198 
199 #endif
200 
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:19
#define UNUSED
Definition: GeneralDefine.h:18
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:30
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:34
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
Container to store Interaction objects.
Definition: InteractionHandler.h:25
Mdouble getMeanOverlap() const
The mean overlap of all interactions.
Definition: InteractionHandler.cc:386
void removeObjectKeepingPeriodics(unsigned int id)
Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::remo...
Definition: InteractionHandler.cc:296
void read(std::istream &is)
Definition: InteractionHandler.cc:434
unsigned getNumberOfLiquidBridges() const
Definition: InteractionHandler.cc:553
InteractionHandler()
Default constructor, it creates an empty InteractionHandler.
Definition: InteractionHandler.cc:23
~InteractionHandler() override
Destructor, it destructs the InteractionHandler and all BaseInteraction it contains.
Definition: InteractionHandler.cc:59
std::vector< std::vector< BaseInteraction * > > newObjects_
Definition: InteractionHandler.h:183
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Definition: InteractionHandler.cc:126
void deleteMPIInteractionDataArray(void *dataArray)
deletes an MPIInteractionDataArray
Definition: InteractionHandler.cc:207
unsigned getNumberOfWallContacts() const
Definition: InteractionHandler.cc:562
void actionsAfterTimeStep()
Definition: InteractionHandler.cc:375
void resetNewObjectsOMP()
Definition: InteractionHandler.cc:102
void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
creates an empty MPIInteractionDataArray
Definition: InteractionHandler.cc:191
double getLiquidBridgeVolume() const
Definition: InteractionHandler.cc:544
std::string getName() const override
Returns the name of the object.
Definition: InteractionHandler.cc:404
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
Definition: InteractionHandler.cc:67
FileType writeVTK_
Definition: InteractionHandler.h:193
void eraseOldInteractions(unsigned)
erases interactions which have an old timestamp.
Definition: InteractionHandler.cc:357
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
Definition: InteractionHandler.cc:472
std::map< unsigned, BaseWall * > wallById
Definition: InteractionHandler.h:196
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:225
void write(std::ostream &os) const
Writes the InteractionHandler to an output stream, for example a restart file.
Definition: InteractionHandler.cc:413
void addNewObjectsOMP()
Definition: InteractionHandler.cc:109
std::map< unsigned, BaseParticle * > particleById
Definition: InteractionHandler.h:195
void setWriteVTK(FileType f)
Definition: InteractionHandler.cc:529
InteractionHandler & operator=(const InteractionHandler &rhs)
Assignment operator.
Definition: InteractionHandler.cc:48
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
Definition: InteractionHandler.cc:162
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:83
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
Definition: InteractionHandler.cc:177
BaseInteraction * addInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Definition: InteractionHandler.cc:94
FileType getWriteVTK() const
Definition: InteractionHandler.cc:539
Container to store all ParticleSpecies.
Definition: SpeciesHandler.h:15
Definition: Kernel/Math/Vector.h:30
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
#define I
Definition: main.h:127
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286