MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WallHandler Class Referencefinal

Container to store all BaseWall. More...

#include <WallHandler.h>

+ Inheritance diagram for WallHandler:

Public Member Functions

 WallHandler ()
 Default constructor, it creates an empty WallHandler. More...
 
 WallHandler (const WallHandler &BH)
 Constructor that copies a pointer to the DPMBase and all BaseWall in the given WallHandler. More...
 
WallHandleroperator= (const WallHandler &rhs)
 Assignment operator that copies the pointer to the DPMBase and all BaseWall in the given WallHandler. More...
 
 ~WallHandler () final
 Destructor, it destructs the WallHandler and all BaseWall it contains. More...
 
void addObject (BaseWall *W) final
 Adds a BaseWall to the WallHandler. More...
 
BaseWallreadAndCreateObject (std::istream &is)
 Create a new wall, based on the information provided in a restart file. More...
 
void readAndAddObject (std::istream &is) final
 Create a new wall in the WallHandler, based on the information provided in a restart file. More...
 
std::string getName () const final
 Returns the name of the handler, namely the string "WallHandler". More...
 
unsigned readTriangleWall (std::string filename, ParticleSpecies *species, Mdouble scaleFactor=1, Vec3D centerOfRotation={0, 0, 0}, Vec3D velocity={0, 0, 0}, Vec3D angularVelocity={0, 0, 0})
 Reads triangulated walls from vtk or stl files, and converts them into a set of TriangleWalls. More...
 
- Public Member Functions inherited from BaseHandler< BaseWall >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseWall > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< BaseWall > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
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. More...
 
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. More...
 
std::enable_if
<!std::is_pointer< U >::value,
U * >::type 
copyAndAddGhostObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
std::enable_if
< std::is_pointer< U >::value,
U >::type 
copyAndAddGhostObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
virtual void addExistingObject (BaseWall *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addGhostObject (BaseWall *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(BaseWall *)> cond)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
virtual void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
BaseWallgetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< BaseWall * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
BaseWallgetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
const BaseWallgetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseWallgetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseWallgetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
virtual unsigned int getNumberOfObjects () const
 Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) More...
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles) More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
void resize (const unsigned int N, const BaseWall &obj)
 Resizes the container to contain N elements. More...
 
const std::vector< BaseWall * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< BaseWall * >
::iterator 
begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseWall * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseWall * >
::iterator 
end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
void setId (BaseWall *object, unsigned int id)
 This function sets the id and ensures that nextId is a bigger value than id. More...
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 
virtual void writeVTK () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. More...
 

Static Public Member Functions

static BaseWallcreateObject (const std::string &type)
 Create a new wall, with the type given as a string (required for restarting). More...
 

Private Member Functions

BaseWallreadAndCreateOldObject (std::istream &is)
 Create a new wall, based on the information from old-style restart data. More...
 
void writeVTKBoundingBox () const
 Writes a bounding box around the domain into a vtk file. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseHandler< BaseWall >
std::vector< BaseWall * > objects_
 The actual list of Object pointers. More...
 

Detailed Description

Container to store all BaseWall.

The WallHandler is a container to store all BaseWall. It is implemented by a vector of pointers to BaseWall.

Definition at line 42 of file WallHandler.h.

Constructor & Destructor Documentation

WallHandler::WallHandler ( )

Default constructor, it creates an empty WallHandler.

Constructor of the WallHandler class. It creates an empty WallHandler.

Todo:
why is this being done?

Definition at line 50 of file WallHandler.cc.

References BaseHandler< BaseWall >::clear().

51 {
53  clear();
54 #ifdef DEBUG_CONSTRUCTOR
55  std::cerr << "WallHandler::WallHandler() finished" << std::endl;
56 #endif
57 }
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
WallHandler::WallHandler ( const WallHandler WH)

Constructor that copies a pointer to the DPMBase and all BaseWall in the given WallHandler.

Parameters
[in]WHThe WallHandler that has to be copied.

This is not a copy constructor! It only copies the pointer to the DPMBase and the BaseWall in objects_, it sets the other data members to 0 or nullptr.

Todo:
why is this being done?

Definition at line 65 of file WallHandler.cc.

References BaseHandler< BaseWall >::clear(), BaseHandler< BaseWall >::copyContentsFromOtherHandler(), BaseHandler< T >::getDPMBase(), and BaseHandler< BaseWall >::setDPMBase().

66 {
68  clear();
69  setDPMBase(WH.getDPMBase());
71 #ifdef DEBUG_CONSTRUCTOR
72  std::cerr << "WallHandler::WallHandler(const WallHandler&) finished" << std::endl;
73 #endif
74 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void copyContentsFromOtherHandler(const BaseHandler< BaseWall > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
WallHandler::~WallHandler ( )
final

Destructor, it destructs the WallHandler and all BaseWall it contains.

Definition at line 96 of file WallHandler.cc.

97 {
98 #ifdef DEBUG_CONSTRUCTOR
99  std::cerr << "WallHandler::~WallHandler() finished" << std::endl;
100 #endif
101 }

Member Function Documentation

void WallHandler::addObject ( BaseWall W)
finalvirtual

Adds a BaseWall to the WallHandler.

Parameters
[in]WA pointer to the BaseWall (or derived class) that has to be added.

First the new BaseWall is added to the vector of BaseWall, then it is told that this is its handler.

Reimplemented from BaseHandler< BaseWall >.

Definition at line 108 of file WallHandler.cc.

References BaseHandler< T >::addObject(), BaseObject::getId(), BaseInteractable::getSpecies(), logger, BaseWall::setHandler(), and WARN.

Referenced by readAndAddObject().

109 {
110  if (W->getSpecies() == nullptr)
111  {
112  logger(WARN, "WARNING: The wall with ID % that is added in WallHandler::addObject "
113  "does not have a species yet. Please make sure that you have "
114  "set the species somewhere in the driver code.", W->getId());
115  }
116  //Puts the wall in the Wall list
118  //set the particleHandler pointer
119  W->setHandler(this);
120 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
virtual void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:127
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
BaseWall * WallHandler::createObject ( const std::string &  type)
static

Create a new wall, with the type given as a string (required for restarting).

Todo:
Review this line. Problem came up in merging.

Definition at line 122 of file WallHandler.cc.

References logger, and WARN.

Referenced by BaseWall::read(), BasicUnionOfWalls::read(), BasicIntersectionOfWalls::read(), and readAndCreateObject().

123 {
124  if (type == "CylindricalWall")
125  {
126  return new CylindricalWall;
127  }
128  else if (type == "AxisymmetricIntersectionOfWalls")
129  {
131  }
132  else if (type == "ScrewsymmetricIntersectionOfWalls")
133  {
135  }
136  else if (type == "IntersectionOfWalls")
137  {
138  return new IntersectionOfWalls;
139  }
140  else if (type == "BasicIntersectionOfWalls")
141  {
142  return new BasicIntersectionOfWalls;
143  }
144  else if (type == "BasicUnionOfWalls")
145  {
146  return new BasicUnionOfWalls;
147  }
148  else if (type == "InfiniteWall")
149  {
150  return new InfiniteWall;
151  }
152  else if (type == "InfiniteWallWithHole")
153  {
154  return new InfiniteWallWithHole;
155  }
156  else if (type == "Screw")
157  {
158  return new Screw;
159  }
160  else if (type == "Coil")
161  {
162  return new Coil;
163  }
164  else if (type == "TriangleWall")
165  {
166  return new TriangleWall;
167  }
168  else if (type == "VChute")
169  {
170  return new VChute;
171  }
172  else if (type == "NurbsWall")
173  {
174  return new NurbsWall();
175  }
176  //for backward compatibility (before svnversion ~2360)
177  else if (type == "numFiniteWalls")
178  {
179  return new BasicIntersectionOfWalls;
180  }
182  // else if (!getDPMBase()->readUserDefinedWall(type,is))
183  else
184  {
185  logger(WARN, "Wall type: % not understood in restart file", type);
186  return nullptr;
187  }
188 }
A TriangleWall is convex polygon defined as an intersection of InfiniteWall's.
Definition: TriangleWall.h:56
This function defines a wall via a NurbsSurface.
Definition: NurbsWall.h:35
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:43
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
This is a class defining walls.
This is a class defining walls.
Definition: VChute.h:34
Use ScrewsymmetricIntersectionOfWalls to define screwsymmetric walls, such as cylinders, cones, etc.
Use AxisymmetricIntersectionOfWalls to Screw Screw::read Screw::read Screw::read define axisymmetric ...
This is a class defining walls.
Definition: InfiniteWall.h:47
This class defines a coil in the z-direction from a (constant) starting point, a (constant) length L...
Definition: Coil.h:40
std::string WallHandler::getName ( ) const
finalvirtual

Returns the name of the handler, namely the string "WallHandler".

Returns
The string "WallHandler".

Implements BaseHandler< BaseWall >.

Definition at line 287 of file WallHandler.cc.

288 {
289  return "WallHandler";
290 }
WallHandler & WallHandler::operator= ( const WallHandler rhs)

Assignment operator that copies the pointer to the DPMBase and all BaseWall in the given WallHandler.

Parameters
[in]rhsThe WallHandler on the right hand side of the assignment.

This is not a copy assignment operator! It only copies the pointer to the DPMBase and the BaseWall in objects_, it sets the other data members to 0 or nullptr.

Definition at line 82 of file WallHandler.cc.

References BaseHandler< BaseWall >::clear(), BaseHandler< BaseWall >::copyContentsFromOtherHandler(), BaseHandler< T >::getDPMBase(), and BaseHandler< BaseWall >::setDPMBase().

83 {
84  if (this != &rhs)
85  {
86  clear();
87  setDPMBase(rhs.getDPMBase());
89  }
90  return *this;
91 #ifdef DEBUG_CONSTRUCTOR
92  std::cerr << "WallHandler::operator =(const WallHandler&) finished" << std::endl;
93 #endif
94 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void copyContentsFromOtherHandler(const BaseHandler< BaseWall > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void WallHandler::readAndAddObject ( std::istream &  is)
finalvirtual

Create a new wall in the WallHandler, based on the information provided in a restart file.

As we add the object into the handler, we need to make sure that the object keeps its existing ID. This is not always the same as the index, e.g. if walls have been removed during the simulation.

Parameters
[in]isThe input stream from which the information is read.

Implements BaseHandler< BaseWall >.

Definition at line 276 of file WallHandler.cc.

References addObject(), BaseObject::getId(), BaseHandler< BaseWall >::getLastObject(), readAndCreateObject(), and BaseObject::setId().

Referenced by DPMBase::read().

277 {
278  BaseWall* o = readAndCreateObject(is);
279  unsigned int id = o->getId();
280  addObject(o);
281  getLastObject()->setId(id);
282 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
void addObject(BaseWall *W) final
Adds a BaseWall to the WallHandler.
Definition: WallHandler.cc:108
BaseWall * readAndCreateObject(std::istream &is)
Create a new wall, based on the information provided in a restart file.
Definition: WallHandler.cc:190
Basic class for walls.
Definition: BaseWall.h:47
BaseWall * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:72
BaseWall * WallHandler::readAndCreateObject ( std::istream &  is)

Create a new wall, based on the information provided in a restart file.

Definition at line 190 of file WallHandler.cc.

References createObject(), DEBUG, BaseHandler< BaseWall >::getDPMBase(), logger, readAndCreateOldObject(), DPMBase::readUserDefinedWall(), BaseWall::setHandler(), BaseWall::setSpecies(), and WARN.

Referenced by readAndAddObject().

191 {
192  std::string type;
193  is >> type;
194  logger(DEBUG, "WallHandler::readAndAddObject(is): reading type %.", type);
195 
196  //for backward compatibility (before svnversion ~2360)
197  if (type == "numFiniteWalls")
198  {
199  return readAndCreateOldObject(is);
200  }
201  else
202  {
203  BaseWall* wall = createObject(type);
204  //check if wall is user-defined
205  if (wall == nullptr)
206  {
207  wall = getDPMBase()->readUserDefinedWall(type);
208  }
209  //throw warning if wall could not be found
210  if (wall == nullptr)
211  {
212  std::string line;
213  getline(is, line);
214  logger(WARN, "This wall could not be read; dummy wall is inserted instead:\n%%", type, line);
215  BaseWall* wall = new InfiniteWall;
216  wall->setHandler(this);
217  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
218  return wall;
219  }
220  wall->setHandler(this);
221  is >> *wall;
222  wall->setSpecies(getDPMBase()->speciesHandler.getObject(wall->getIndSpecies()));
223  return wall;
224  }
225 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:127
static BaseWall * createObject(const std::string &type)
Create a new wall, with the type given as a string (required for restarting).
Definition: WallHandler.cc:122
BaseWall * readAndCreateOldObject(std::istream &is)
Create a new wall, based on the information from old-style restart data.
Definition: WallHandler.cc:236
virtual BaseWall * readUserDefinedWall(const std::string &type) const
Allows you to read in a wall defined in a Driver directory; see USER/Luca/ScrewFiller.
Definition: DPMBase.h:279
Basic class for walls.
Definition: BaseWall.h:47
This is a class defining walls.
Definition: InfiniteWall.h:47
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:171
BaseWall * WallHandler::readAndCreateOldObject ( std::istream &  is)
private

Create a new wall, based on the information from old-style restart data.

First determine whether or not the wall is an infinite wall. If it is an infinite wall, read the normal and position and add the wall to the handler. If it is a finite wall, read the normal and position of each part and construct an IntersectionOfWalls from it, which can then be added to the handler.

Parameters
[in,out]isThe input stream from which the information is read.
Todo:
This is deprecated since r ~2360.

Definition at line 236 of file WallHandler.cc.

References IntersectionOfWalls::addObject(), BaseHandler< BaseWall >::getDPMBase(), helpers::getLineFromStringStream(), constants::i, logger, InfiniteWall::set(), IntersectionOfWalls::setSpecies(), BaseWall::setSpecies(), and VERBOSE.

Referenced by readAndCreateObject().

237 {
238  //read in next line
239  std::stringstream line;
241  logger(VERBOSE, line.str());
242 
243  std::string dummy;
244  unsigned int numWalls;
245  Mdouble position;
246  Vec3D normal;
247  line >> numWalls;
248 
249  if (numWalls == 0)
250  {
251  InfiniteWall* wall = new InfiniteWall();
252  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
253  line >> dummy >> normal >> dummy >> position;
254  wall->set(normal, position * normal);
255  return wall;
256  }
257  else
258  {
260  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
261  for (unsigned int i = 0; i < numWalls; ++i)
262  {
263  line >> dummy >> normal >> dummy >> position;
264  wall->addObject(normal, position * normal);
265  }
266  return wall;
267  }
268 }
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
void addObject(Vec3D normal, Vec3D point)
Adds a wall to the set of infinite walls, given a normal vector pointing into the wall (i...
void setSpecies(const ParticleSpecies *species)
sets species of subwalls as well
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
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...
This is a class defining walls.
Definition: InfiniteWall.h:47
Definition: Vector.h:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:171
unsigned WallHandler::readTriangleWall ( std::string  filename,
ParticleSpecies species,
Mdouble  scaleFactor = 1,
Vec3D  centerOfRotation = {0,0,0},
Vec3D  velocity = {0,0,0},
Vec3D  angularVelocity = {0,0,0} 
)

Reads triangulated walls from vtk or stl files, and converts them into a set of TriangleWalls.

The stl files have to be binary STL files. If you have ascii files, you need to convert them (use e.g. https://www.meshconvert.com/)

The vtk files need to be of type POLYDATA and contain triangle strips (see see www.cacr.caltech.edu/~slombey)

Parameters
[in]filenamename of vtk input file, e.g. TriangulatedWallSelfTest.vtk
[in]speciespointer to a species in the species handler that will be assigned to the walls
[in]scaleFactorallows the vertex positions to be scaled (necessary if the vtk file is written in different units than the Mercury implementation, e.g. if the stl file is given in mm, but the Mercury implementation uses meters)

Definition at line 357 of file WallHandler.cc.

References BaseHandler< BaseWall >::copyAndAddObject(), ERROR, BaseHandler< BaseWall >::getNextGroupId(), BaseHandler< BaseWall >::getSize(), constants::i, BinaryReader::ignoreChar(), INFO, logger, helpers::lower(), STLTriangle::normal, BinaryReader::readFloat(), BinaryReader::readString(), BinaryReader::readUnsignedInt(), BaseInteractable::setAngularVelocity(), BaseObject::setGroupId(), BaseWall::setSpecies(), BaseInteractable::setVelocity(), TriangleWall::setVertices(), STLTriangle::vertex1, STLTriangle::vertex2, STLTriangle::vertex3, Vec3D::X, Vec3D::x(), Vec3D::Y, Vec3D::y(), Vec3D::Z, and Vec3D::z().

358 {
359  const unsigned groupId = getNextGroupId();
360  std::string fileType = filename.substr(filename.find_last_of('.') + 1);
361 
362  //define a default triangle wall
363  TriangleWall triangleWall;
364  triangleWall.setSpecies(species);
365  triangleWall.setVelocity(velocity);
366  triangleWall.setAngularVelocity(angularVelocity);
367  triangleWall.setGroupId(groupId);
368 
369  if (helpers::lower(fileType) == "vtk")
370  {
371  //try open the input file
372  std::fstream file;
373  file.open(filename.c_str(), std::ios::in);
374  logger.assert_always(file.is_open(), "File opening failed: %", filename);
375 
376  //skip the header lines
377  std::string dummy;
378  getline(file, dummy);
379  getline(file, dummy);
380  getline(file, dummy);
381  getline(file, dummy);
382 
383  //read vertices, apply scaling
384  unsigned num;
385  file >> dummy >> num >> dummy;
386  std::vector<Vec3D> vertex;
387  vertex.reserve(num);
388  Vec3D v;
389  for (unsigned i = 0; i < num; i++)
390  {
391  file >> v.X >> v.Y >> v.Z;
392  v *= scaleFactor;
393  vertex.push_back(v);
394  }
395 
396  //read faces
397  unsigned n = getSize();
398  file >> dummy >> num >> dummy;
399  unsigned id0, id1, id2;
400  for (unsigned i = 0; i < num; i++)
401  {
402  file >> dummy >> id0 >> id1 >> id2;
403  triangleWall.setVertices(vertex[id0], vertex[id1], vertex[id2], centerOfRotation);
404  copyAndAddObject(triangleWall);
405  }
406 
407  //close file
408  file.close();
409 
410  logger(INFO, "Read in % walls from %", getSize() - n,filename);
411 
412  }
413  else if (helpers::lower(fileType) == "stl")
414  {
415 
416  BinaryReader file(filename);
417 
418  STLTriangle triangle;
419 
420  std::string header = file.readString(80);
421  unsigned numTriangles = file.readUnsignedInt(4);
422 
423  for (unsigned i = 0; i < numTriangles; i++)
424  {
425  triangle.normal.x() = file.readFloat(4);
426  triangle.normal.y() = file.readFloat(4);
427  triangle.normal.z() = file.readFloat(4);
428 
429 
430  triangle.vertex1.x() = file.readFloat(4);
431  triangle.vertex1.y() = file.readFloat(4);
432  triangle.vertex1.z() = file.readFloat(4);
433 
434  triangle.vertex2.x() = file.readFloat(4);
435  triangle.vertex2.y() = file.readFloat(4);
436  triangle.vertex2.z() = file.readFloat(4);
437 
438 
439  triangle.vertex3.x() = file.readFloat(4);
440  triangle.vertex3.y() = file.readFloat(4);
441  triangle.vertex3.z() = file.readFloat(4);
442 
443  triangle.vertex1 *= scaleFactor;
444  triangle.vertex2 *= scaleFactor;
445  triangle.vertex3 *= scaleFactor;
446 
447  //add to triangle wall
448  triangleWall.setVertices(triangle.vertex1, triangle.vertex2, triangle.vertex3, centerOfRotation);
449  copyAndAddObject(triangleWall);
450 
451  //Now ignore (read) the two dummy characters
452  file.ignoreChar(2);
453 
454  }
455 
456  logger(INFO, "Read in % walls from %", numTriangles,filename);
457 
458  }
459  else
460  {
461 
462  logger(ERROR, "File type of % must be vtk or stl");
463 
464  }
465 
466  return groupId;
467 }
A TriangleWall is convex polygon defined as an intersection of InfiniteWall's.
Definition: TriangleWall.h:56
Mdouble X
the vector components
Definition: Vector.h:65
std::string lower(std::string s)
Definition: Helpers.cc:55
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D vertex3
Definition: STLTriangle.h:57
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Mdouble & z()
RW reference to Z.
Definition: Vector.h:368
Vec3D vertex1
Definition: STLTriangle.h:55
Vec3D vertex2
Definition: STLTriangle.h:56
unsigned getNextGroupId()
Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases next...
Definition: BaseHandler.h:293
Vec3D normal
Definition: STLTriangle.h:54
Mdouble & x()
RW reference to X.
Definition: Vector.h:344
void setVertices(Vec3D A, Vec3D B, Vec3D C)
Sets member variables such that the wall represents a triangle with vertices A, B, C.
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.
Mdouble & y()
RW reference to Y.
Definition: Vector.h:356
Mdouble Y
Definition: Vector.h:65
void setGroupId(unsigned groupId)
Definition: BaseObject.h:131
This gives functionality to read information from binary formats like STL etc. This class is complete...
Definition: BinaryReader.h:36
Definition: Vector.h:49
Mdouble Z
Definition: Vector.h:65
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:171
void WallHandler::writeVTKBoundingBox ( ) const
private

Writes a bounding box around the domain into a vtk file.

Writes a box around all the data to a vtk file. The filename is hard-coded and depends on the DPMBase. Note that there is no static counter that makes sure new files don't have the same name as the old ones.

Todo:
Check that this should indeed be WARN

000 001 010 011 ...

Definition at line 297 of file WallHandler.cc.

References BaseHandler< BaseWall >::getDPMBase(), DPMBase::getMax(), DPMBase::getMin(), DPMBase::getName(), constants::i, logger, and WARN.

298 {
299  const std::string fileName = getDPMBase()->getName() + "BoundingBox.vtu";
300  //logger(INFO, "% writing vtk file for bounding box: %",
301  // getDPMBase()->getTime(), fileName);
302  std::fstream file;
303  file.open(fileName.c_str(), std::ios::out);
304  if (file.fail())
305  {
307  logger(WARN, "Error in writeToFile: file could not be opened");
308  }
309  file << "<?xml version=\"1.0\"?>\n\n";
310  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
311  file << "<UnstructuredGrid>\n";
312  file << "<Piece NumberOfPoints=\"8\" NumberOfCells=\"1\">\n";
313  file << "<Points>\n";
314  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
315  Vec3D P[2] = {getDPMBase()->getMax(), getDPMBase()->getMin()};
316  for (auto& i : P)
317  {
318  for (auto& j : P)
319  {
320  for (auto& k : P)
321  {
322  Vec3D p = Vec3D(i.X, j.Y, k.Z);
323  file << '\t' << p << '\n';
324  }
325  }
326  }
328  file << " </DataArray>\n";
329  file << "</Points>\n";
330  file << "<Cells>\n";
331  file <<
332  " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
333  file << "\t0 1 3 2 0 4 5 1 5 7 3 7 6 2 6 4\n";
334  file << " </DataArray>\n";
335  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
336  file <<
337  "\t16\n"; //offset into the connectivity array for the end of each cell.
338  file << " </DataArray>\n";
339  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
340  file << "\t4\n";
341  file << " </DataArray>\n";
342  file << "</Cells>\n";
343  file << "</Piece>\n";
344  file << "</UnstructuredGrid>\n";
345  file << "</VTKFile>\n";
346  file.close();
347 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D getMin() const
Definition: DPMBase.h:623
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: DPMBase.cc:389
Vec3D getMax() const
Definition: DPMBase.h:629
Definition: Vector.h:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.

The documentation for this class was generated from the following files: