MercuryDPM  Beta
 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-2014, 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 #include <iostream>
28 #include <string>
29 #include <stdlib.h>
30 #include <Math/Helpers.h>
31 
32 #include "BoundaryHandler.h"
42 
43 
46 {
47  logger(DEBUG, "BoundaryHandler::BoundaryHandler() finished");
48 }
49 
57 {
59  logger(DEBUG, "BoundaryHandler::BoundaryHandler(const BoundaryHandler &BH) finished");
60 }
61 
68 {
69  if (this != &rhs)
70  {
71  clear();
73  }
74  logger(DEBUG, "BoundaryHandler BoundaryHandler::operator =(const BoundaryHandler& rhs)");
75  return *this;
76 }
77 
80 {
81  logger(DEBUG, "BoundaryHandler::~BoundaryHandler() finished");
82 }
83 
87 {
88  //Puts the particle in the Particle list
90  //set the particleHandler pointer
91  P->setHandler(this);
92 }
93 
97 void BoundaryHandler::readObject(std::istream& is)
98 {
99  //Note that compare returns 0 if the strings are the same.
100  std::string type;
101  is >> type;
102  if (type == "AngledPeriodicBoundary")
103  {
105  is >> AngledPeriodicBoundary;
106  copyAndAddObject(AngledPeriodicBoundary);
107  }
108  else if (type == "ChuteInsertionBoundary")
109  {
110  ChuteInsertionBoundary chuteInsertionBoundary;
111  is >> chuteInsertionBoundary;
112  copyAndAddObject(chuteInsertionBoundary);
113  }
114  else if (type == "CubeInsertionBoundary")
115  {
116  CubeInsertionBoundary cubeInsertionBoundary;
117  is >> cubeInsertionBoundary;
118  copyAndAddObject(cubeInsertionBoundary);
119  }
120  else if (type == "CircularPeriodicBoundary")
121  {
122  CircularPeriodicBoundary circularPeriodicBoundary;
123  is >> circularPeriodicBoundary;
124  copyAndAddObject(circularPeriodicBoundary);
125  }
126  else if (type == "DeletionBoundary")
127  {
128  DeletionBoundary deletionBoundary;
129  is >> deletionBoundary;
130  copyAndAddObject(deletionBoundary);
131  }
132  else if (type == "HopperInsertionBoundary")
133  {
134  HopperInsertionBoundary hopperInsertionBoundary;
135  is >> hopperInsertionBoundary;
136  copyAndAddObject(hopperInsertionBoundary);
137  }
138  else if (type == "PeriodicBoundary")
139  {
140  PeriodicBoundary periodicBoundary;
141  is >> periodicBoundary;
142  copyAndAddObject(periodicBoundary);
143  }
144  else if (type.compare("LeesEdwardsBoundary") == 0)
145  {
146  LeesEdwardsBoundary leesEdwardsBoundary;
147  is >> leesEdwardsBoundary;
148  copyAndAddObject(leesEdwardsBoundary);
149  }
150  //for backward compatibility (before svnversion ~2360)
151  else if (type == "normal")
152  {
153  readOldObject(is);
154  }
155  else
156  {
157  logger(ERROR, "Boundary type: % not understood in restart file.", type);
158  }
159 }
160 
165 void BoundaryHandler::readOldObject(std::istream& is)
166 {
167  //read in next line
168  std::stringstream line(std::stringstream::in | std::stringstream::out);
170 
171  std::string dummy;
172  Vec3D normal;
173  Mdouble positionLeft, positionRight;
174 
175  PeriodicBoundary periodicBoundary;
176  line >> normal >> dummy >> positionLeft >> dummy >> positionRight;
177  periodicBoundary.set(normal, positionLeft, positionRight);
178  copyAndAddObject(periodicBoundary);
179 }
180 
182 std::string BoundaryHandler::getName() const
183 {
184  return "BoundaryHandler";
185 }
186 
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall.
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
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.
std::string getName() const
Returns the name of the handler, namely the string "BoundaryHandler".
used to create a circular periodic boundary
Defines a pair of periodic walls. Inherits from BaseBoundary.
void readObject(std::istream &is)
Reads BaseBoundary into the BoundaryHandler from restart data.
It's an insertion boundary which has cuboidal shape (yes, 'CuboidalInsertionBoundary' would have been...
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
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:389
void setHandler(BoundaryHandler *handler)
Sets the boundary's BoundaryHandler.
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:284
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:50
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...
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...
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void addObject(BaseBoundary *P)
Adds a BaseBoundary to the BoundaryHandler.
~BoundaryHandler()
Destructor, it destructs the BoundaryHandler and all BaseBoundary it contains.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...