MercuryDPM  Alpha
 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  logger.log(Log::DEBUG, "BoundaryHandler::readObject(is): restarting a boundary of type %.", type);
103  if (type == "AngledPeriodicBoundary")
104  {
106  is >> AngledPeriodicBoundary;
107  copyAndAddObject(AngledPeriodicBoundary);
108  }
109  else if (type == "ChuteInsertionBoundary")
110  {
111  ChuteInsertionBoundary chuteInsertionBoundary;
112  is >> chuteInsertionBoundary;
113  copyAndAddObject(chuteInsertionBoundary);
114  }
115  else if (type == "CubeInsertionBoundary")
116  {
117  CubeInsertionBoundary cubeInsertionBoundary;
118  is >> cubeInsertionBoundary;
119  copyAndAddObject(cubeInsertionBoundary);
120  }
121  else if (type == "CircularPeriodicBoundary")
122  {
123  CircularPeriodicBoundary circularPeriodicBoundary;
124  is >> circularPeriodicBoundary;
125  copyAndAddObject(circularPeriodicBoundary);
126  }
127  else if (type == "DeletionBoundary")
128  {
129  DeletionBoundary deletionBoundary;
130  is >> deletionBoundary;
131  copyAndAddObject(deletionBoundary);
132  }
133  else if (type == "HopperInsertionBoundary")
134  {
135  HopperInsertionBoundary hopperInsertionBoundary;
136  is >> hopperInsertionBoundary;
137  copyAndAddObject(hopperInsertionBoundary);
138  }
139  else if (type == "PeriodicBoundary")
140  {
141  PeriodicBoundary periodicBoundary;
142  is >> periodicBoundary;
143  copyAndAddObject(periodicBoundary);
144  }
145  else if (type.compare("LeesEdwardsBoundary") == 0)
146  {
147  LeesEdwardsBoundary leesEdwardsBoundary;
148  is >> leesEdwardsBoundary;
149  copyAndAddObject(leesEdwardsBoundary);
150  }
151  //for backward compatibility (before svnversion ~2360)
152  else if (type == "normal")
153  {
154  readOldObject(is);
155  }
156  else
157  {
158  logger(ERROR, "Boundary type: % not understood in restart file.", type);
159  }
160 }
161 
166 void BoundaryHandler::readOldObject(std::istream& is)
167 {
168  //read in next line
169  std::stringstream line(std::stringstream::in | std::stringstream::out);
171 
172  std::string dummy;
173  Vec3D normal;
174  Mdouble positionLeft, positionRight;
175 
176  PeriodicBoundary periodicBoundary;
177  line >> normal >> dummy >> positionLeft >> dummy >> positionRight;
178  periodicBoundary.set(normal, positionLeft, positionRight);
179  copyAndAddObject(periodicBoundary);
180 }
181 
183 std::string BoundaryHandler::getName() const
184 {
185  return "BoundaryHandler";
186 }
187 
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...
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:396
void setHandler(BoundaryHandler *handler)
Sets the boundary's BoundaryHandler.
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.
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:51
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...
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:313
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...