MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BoundaryHandler.cc
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 #include "Math/Helpers.h"
27 #include "BoundaryHandler.h"
48 
51 {
52  writeVTK_ = false;
53  logger(DEBUG, "BoundaryHandler::BoundaryHandler() finished");
54 }
55 
63 {
64  writeVTK_ = BH.writeVTK_;
66  logger(DEBUG, "BoundaryHandler::BoundaryHandler(const BoundaryHandler &BH) finished");
67 }
68 
75 {
76  if (this != &rhs)
77  {
78  clear();
80  }
81  logger(DEBUG, "BoundaryHandler BoundaryHandler::operator =(const BoundaryHandler& rhs)");
82 
83  return *this;
84 }
85 
88 {
89  logger(DEBUG, "BoundaryHandler::~BoundaryHandler() finished");
90 }
91 
95 {
96  //Puts the boundary in the Boundary list
98  //set the handler pointer
99  P->setHandler(this);
100 
101 #ifdef MERCURY_USE_MPI
102  //Different manner of treating periodic boundaries in MPI: hence there is a periodicBoundaryHandler
103  BasePeriodicBoundary* upcast = dynamic_cast<BasePeriodicBoundary*>(P);
104  if (upcast != nullptr)
105  {
107  }
108 #endif
109 
110 }
111 
113 {
114  //Note that compare returns 0 if the strings are the same.
115  if (type == "AngledPeriodicBoundary")
116  {
117  return new AngledPeriodicBoundary;
118  }
119  else if (type == "ChuteInsertionBoundary")
120  {
121  return new ChuteInsertionBoundary;
122  }
123  else if (type == "CubeInsertionBoundary")
124  {
125  return new CubeInsertionBoundary;
126  }
127  else if (type == "CubeDeletionBoundary")
128  {
129  return new CubeDeletionBoundary;
130  }
131  else if (type == "CircularPeriodicBoundary")
132  {
133  return new CircularPeriodicBoundary;
134  }
135  else if (type == "DeletionBoundary")
136  {
137  return new DeletionBoundary;
138  }
139  else if (type == "HopperInsertionBoundary")
140  {
141  return new HopperInsertionBoundary;
142  }
143  else if (type == "PeriodicBoundary")
144  {
145  return new PeriodicBoundary;
146  }
147  else if (type == "ConstantMassFlowMaserBoundary" || type == "MaserBoundary")
148  {
150  }
151  else if (type == "SubcriticalMaserBoundary")
152  {
153  return new SubcriticalMaserBoundary;
154  }
155  else if (type == "SubcriticalMaserBoundaryTEST")
156  {
157  return new SubcriticalMaserBoundaryTEST;
158  }
159  else if (type == "LeesEdwardsBoundary")
160  {
161  return new LeesEdwardsBoundary;
162  }
163  else if (type == "MPIDomainBoundary")
164  {
165  return new PeriodicBoundary;
166  }
167  else if (type == "FluxBoundary")
168  {
169  return new FluxBoundary;
170  }
171  else if (type == "HeaterBoundary")
172  {
173  return new HeaterBoundary;
174  }
175  else if (type == "StressStrainControlBoundary")
176  {
177  return new StressStrainControlBoundary;
178  }
179  else if (type == "BaseClusterInsertionBoundary")
180  {
181  return new BaseClusterInsertionBoundary;
182  }
183  else if (type == "RandomClusterInsertionBoundary")
184  {
186  }
187  else if (type == "FixedClusterInsertionBoundary")
188  {
190  }
191  else if (type == "DropletBoundary")
192  {
193  return new DropletBoundary;
194  }
195  else if (type == "normal") //for backward compatibility (before svnversion ~2360)
196  {
197  return new PeriodicBoundary;
198  }
199  else
200  {
201  logger(WARN, "Boundary type: % not understood in restart file.", type);
202  return nullptr;
203  }
204 }
205 
209 void BoundaryHandler::readAndAddObject(std::istream& is)
210 {
211  //Note that compare returns 0 if the strings are the same.
212  std::string type;
213  is >> type;
214  logger(VERBOSE, "BoundaryHandler::readAndAddObject(is): restarting a boundary of type %.", type);
215  if (type == "normal")
216  {
217  readOldObject(is);
218  }
219  else
220  {
221  BaseBoundary* boundary = createObject(type);
222  if (boundary == nullptr)
223  {
224  std::string line;
225  getline(is, line);
226  logger(WARN, "This boundary could not be read and is ignored:\n%%", type, line);
227  return;
228  }
229  boundary->setHandler(this);
230  is >> *boundary;
231  addObject(boundary);
232  }
233 }
234 
239 void BoundaryHandler::readOldObject(std::istream& is)
240 {
241  //read in next line
242  std::stringstream line;
244 
245  std::string dummy;
246  Vec3D normal;
247  Mdouble positionLeft, positionRight;
248 
249  PeriodicBoundary periodicBoundary;
250  line >> normal >> dummy >> positionLeft >> dummy >> positionRight;
251  periodicBoundary.set(normal, positionLeft, positionRight);
252  copyAndAddObject(periodicBoundary);
253 }
254 
256 std::string BoundaryHandler::getName() const
257 {
258  return "BoundaryHandler";
259 }
260 
262 {
263  for (BaseBoundary* b : objects_)
264  {
265  b->actionsBeforeTimeLoop();
266  }
267 }
268 
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a PeriodicBoundary by its normal and positions.
Container to store pointers to all BaseBoundary objects.
Class which creates a boundary with Lees-Edwards type periodic boundary conditions.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
BoundaryHandler()
Default constructor, it creates an empty BoundaryHandler.
void readOldObject(std::istream &is)
Reads a periodic boundary from old-style restart data.
Used for removing particles from the problem. Inherits from BaseBoundary. By default, a plane that deletes everything past it, but there are derived classes such as CubeDeletionBoundary.
Variation on the PeriodicBoundary which also has an outflow part.
used to create a circular periodic boundary
Defines a pair of periodic walls. Inherits from BaseBoundary.
void readAndAddObject(std::istream &is) final
Reads BaseBoundary into the BoundaryHandler from restart data.
Variation on the PeriodicBoundary which also has an outflow part.
Used for measuring flow rates through a given plane; acts like a pair of scales Inherits from BaseBou...
Definition: FluxBoundary.h:41
It's an insertion boundary which has cuboidal shape (yes, 'CuboidalInsertionBoundary' would have been...
Supplies a 'constant heat flux' to a cuboidal region (specified by two corner points) by adding a ran...
~BoundaryHandler() final
Destructor, it destructs the BoundaryHandler and all BaseBoundary it contains.
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
Definition: Helpers.cc:424
PeriodicBoundaryHandler periodicBoundaryHandler
Internal handler that deals with periodic boundaries, especially in a parallel build.
Definition: DPMBase.h:1349
void setHandler(BoundaryHandler *handler)
Sets the boundary's BoundaryHandler.
A cuboid box consists of periodic boundaries that can be strain/stress controlled and achieve differe...
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
std::vector< BaseBoundary * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:50
static BaseBoundary * createObject(const std::string &type)
Inherits from InsertionBoundary Some images are useful to better understand the structure of both the...
BoundaryHandler & operator=(const BoundaryHandler &rhs)
Assignment operator, copies only the vector of BaseBoundary and sets the other variables to 0/nullptr...
void boundaryActionsBeforeTimeLoop()
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
Used for modeling chute inflow. Inherits from InsertionBoundary.
void copyContentsFromOtherHandler(const BaseHandler< BaseBoundary > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: Vector.h:49
void addObject(BasePeriodicBoundary *P) override
Adds a BasePeriodicBoundary to the PeriodicBoundaryHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
std::string getName() const final
Returns the name of the handler, namely the string "BoundaryHandler".
void addObject(BaseBoundary *P) final
Adds a BaseBoundary to the BoundaryHandler.
Supplies a 'constant heat flux' to a cuboidal region (specified by two corner points) by adding a ran...
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...