MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WallHandler.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 <Math/Helpers.h>
28 #include "WallHandler.h"
29 #include "Walls/BaseWall.h"
30 #include "Walls/CylindricalWall.h"
33 #include "Walls/InfiniteWall.h"
35 #include "Walls/Screw.h"
36 #include "Walls/Coil.h"
37 
42 {
43  clear();
44  logger(DEBUG, "WallHandler::WallHandler() finished");
45 }
46 
54 {
55  clear();
56  setDPMBase(WH.getDPMBase());
58  logger(DEBUG, "WallHandler::WallHandler(const WallHandler &PH) finished");
59 }
60 
68 {
69  if(this != &rhs)
70  {
71  clear();
72  setDPMBase(rhs.getDPMBase());
74  }
75 #ifdef DEBUG_CONSTRUCTOR
76  logger(DEBUG, "WallHandler::operator = (const WallHandler& rhs) finished");
77 #endif
78  return *this;
79 }
80 
82 {
83 #ifdef DEBUG_DESTRUCTOR
84  logger(DEBUG, "WallHandler::~WallHandler() finished");
85 #endif
86 }
87 
94 {
95  //\todo I diasbled the MERCURY_DEPRECATED attribute until we actually fixed the deprecation issue. This will scare users away.
96  // if (W->getSpecies() == nullptr)
97  // {
98  // logger(WARN, "WARNING: The wall with ID % that is added in WallHandler::addObject "
99  // "does not have a species yet. Please make sure that you have "
100  // "set the species somewhere in the driver code.", W->getId());
101  // }
102  //Puts the wall in the Wall list
104  //set the particleHandler pointer
105  W->setHandler(this);
106 }
107 
111 void WallHandler::readObject(std::istream& is)
112 {
113  std::string type;
114  is >> type;
115  if (type == "CylindricalWall")
116  {
117  CylindricalWall cylindricalWall;
118  is >> cylindricalWall;
119  copyAndAddObject(cylindricalWall);
120  }
121  else if (type == "AxisymmetricIntersectionOfWalls")
122  {
123  AxisymmetricIntersectionOfWalls axisymmetricIntersectionOfWalls;
124  is >> axisymmetricIntersectionOfWalls;
125  copyAndAddObject(axisymmetricIntersectionOfWalls);
126  }
127  else if (type == "IntersectionOfWalls")
128  {
129  IntersectionOfWalls intersectionOfWalls;
130  is >> intersectionOfWalls;
131  copyAndAddObject(intersectionOfWalls);
132  }
133  else if (type == "InfiniteWall")
134  {
135  InfiniteWall infiniteWall;
136  is >> infiniteWall;
137  copyAndAddObject(infiniteWall);
138  }
139  else if (type == "InfiniteWallWithHole")
140  {
141  InfiniteWallWithHole infiniteWallWithHole;
142  is >> infiniteWallWithHole;
143  copyAndAddObject(infiniteWallWithHole);
144  }
145  else if (type == "Screw")
146  {
147  Screw screw;
148  is >> screw;
149  copyAndAddObject(screw);
150  }
151  else if (type == "Coil")
152  {
153  Coil coil;
154  is >> coil;
155  copyAndAddObject(coil);
156  }
157  //for backward compatibility (before svnversion ~2360)
158  else if (type == "numFiniteWalls")
159  {
160  readOldObject(is);
161  }
162  else
163  {
164  logger(ERROR, "Wall type: % not understood in restart file", type);
165  }
166 }
167 
175 void WallHandler::readOldObject(std::istream& is)
176 {
177  //read in next line
178  std::stringstream line(std::stringstream::in | std::stringstream::out);
180  logger(VERBOSE, line.str());
181 
182  std::string dummy;
183  unsigned int numWalls;
184  Mdouble position;
185  Vec3D normal;
186  line >> numWalls;
187 
188  if (numWalls == 0)
189  {
190  InfiniteWall infiniteWall;
191  line >> dummy >> normal >> dummy >> position;
192  infiniteWall.set(normal, position*normal);
193  copyAndAddObject(infiniteWall);
194  }
195  else
196  {
197  IntersectionOfWalls intersectionOfWalls;
198  for (unsigned int i = 0; i < numWalls; ++i)
199  {
200  line >> dummy >> normal >> dummy >> position;
201  intersectionOfWalls.addObject(normal, position*normal);
202  }
203  copyAndAddObject(intersectionOfWalls);
204  }
205 }
206 
210 std::string WallHandler::getName() const
211 {
212  return "WallHandler";
213 }
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
This function defines an Archimedes' screw in the z-direction from a (constant) starting point...
Definition: Screw.h:38
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void readOldObject(std::istream &is)
Reads a BaseWall into the WallHandler from old-style restart data.
Definition: WallHandler.cc:175
void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:76
double Mdouble
void addObject(Vec3D normal, Vec3D point)
Adds a wall to the set of infinite walls, given an outward normal vector s.t. normal*x=normal*point.
void readObject(std::istream &is)
Reads BaseWall into the WallHandler from restart data.
Definition: WallHandler.cc:111
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
WallHandler()
Default constructor, it creates an empty WallHandler.
Definition: WallHandler.cc:41
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:284
Basic class for walls.
Definition: BaseWall.h:39
A AxisymmetricIntersectionOfWalls is a axisymmetric wall, defined by rotating a twodimensional Inters...
Container to store all BaseWall.
Definition: WallHandler.h:42
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Definition: InfiniteWall.cc:70
This is a class defining walls.
Definition: InfiniteWall.h:43
void addObject(BaseWall *W)
Adds a BaseWall to the WallHandler.
Definition: WallHandler.cc:93
WallHandler operator=(const WallHandler &rhs)
Assignment operator that copies the pointer to the DPMBase and all BaseWall in the given WallHandler...
Definition: WallHandler.cc:67
~WallHandler()
Destructor, it destructs the WallHandler and all BaseWall it contains.
Definition: WallHandler.cc:81
void copyContentsFromOtherHandler(const BaseHandler< BaseWall > &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
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:512
This class defines a coil in the z-direction from a (constant) starting point, a (constant) length L...
Definition: Coil.h:40
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
std::string getName() const
Returns the name of the handler, namely the string "WallHandler".
Definition: WallHandler.cc:210