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...
 
void actionsAfterParticleGhostUpdate ()
 Calls the method actionsAfterParticleGhostUpdate of every wall in the handler. 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 51 of file WallHandler.cc.

References BaseHandler< BaseWall >::clear().

52 {
54  clear();
55 #ifdef DEBUG_CONSTRUCTOR
56  std::cerr << "WallHandler::WallHandler() finished" << std::endl;
57 #endif
58 }
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 66 of file WallHandler.cc.

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

67 {
69  clear();
70  setDPMBase(WH.getDPMBase());
72 #ifdef DEBUG_CONSTRUCTOR
73  std::cerr << "WallHandler::WallHandler(const WallHandler&) finished" << std::endl;
74 #endif
75 }
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 97 of file WallHandler.cc.

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

Member Function Documentation

void WallHandler::actionsAfterParticleGhostUpdate ( )

Calls the method actionsAfterParticleGhostUpdate of every wall in the handler.

This function is called by DPMBase::computeOneTimeStep directly after the ghost particle update. It may be used to adjust wall properties based on the changed wall positions (for an example, look e.g. at MeshTriangle).

Definition at line 479 of file WallHandler.cc.

Referenced by DPMBase::computeOneTimeStep().

480 {
481  // #pragma omp parallel for //schedule(dynamic)
482  for (auto w: *this)
483  {
484  w->actionsAfterParticleGhostUpdate();
485  }
486 }
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 109 of file WallHandler.cc.

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

Referenced by readAndAddObject().

110 {
111  if (W->getSpecies() == nullptr)
112  {
113  logger(WARN, "WARNING: The wall with ID % that is added in WallHandler::addObject "
114  "does not have a species yet. Please make sure that you have "
115  "set the species somewhere in the driver code.", W->getId());
116  }
117  //Puts the wall in the Wall list
119  //set the particleHandler pointer
120  W->setHandler(this);
121 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
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 123 of file WallHandler.cc.

References logger, and WARN.

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

124 {
125  if (type == "CylindricalWall")
126  {
127  return new CylindricalWall;
128  }
129  else if (type == "AxisymmetricIntersectionOfWalls")
130  {
132  }
133  else if (type == "ScrewsymmetricIntersectionOfWalls")
134  {
136  }
137  else if (type == "IntersectionOfWalls")
138  {
139  return new IntersectionOfWalls;
140  }
141  else if (type == "BasicIntersectionOfWalls")
142  {
143  return new BasicIntersectionOfWalls;
144  }
145  else if (type == "BasicUnionOfWalls")
146  {
147  return new BasicUnionOfWalls;
148  }
149  else if (type == "InfiniteWall")
150  {
151  return new InfiniteWall;
152  }
153  else if (type == "InfiniteWallWithHole")
154  {
155  return new InfiniteWallWithHole;
156  }
157  else if (type == "Screw")
158  {
159  return new Screw;
160  }
161  else if (type == "Coil")
162  {
163  return new Coil;
164  }
165  else if (type == "TriangleWall")
166  {
167  return new TriangleWall;
168  }
169  else if (type == "MeshTriangle")
170  {
171  return new MeshTriangle;
172  }
173  else if (type == "VChute")
174  {
175  return new VChute;
176  }
177  else if (type == "NurbsWall")
178  {
179  return new NurbsWall();
180  }
181  //for backward compatibility (before svnversion ~2360)
182  else if (type == "numFiniteWalls")
183  {
184  return new BasicIntersectionOfWalls;
185  }
187  // else if (!getDPMBase()->readUserDefinedWall(type,is))
188  else
189  {
190  logger(WARN, "Wall type: % not understood in restart file", type);
191  return nullptr;
192  }
193 }
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")
Definition of different loggers with certain modules. A user can define its own custom logger here...
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
MeshTriangle implements a triangle whose vertex positions are defined by three particles.
Definition: MeshTriangle.h:74
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 292 of file WallHandler.cc.

293 {
294  return "WallHandler";
295 }
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 83 of file WallHandler.cc.

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

84 {
85  if (this != &rhs)
86  {
87  clear();
88  setDPMBase(rhs.getDPMBase());
90  }
91  return *this;
92 #ifdef DEBUG_CONSTRUCTOR
93  std::cerr << "WallHandler::operator =(const WallHandler&) finished" << std::endl;
94 #endif
95 }
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 281 of file WallHandler.cc.

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

Referenced by DPMBase::read().

282 {
283  BaseWall* o = readAndCreateObject(is);
284  unsigned int id = o->getId();
285  addObject(o);
286  getLastObject()->setId(id);
287 }
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:109
BaseWall * readAndCreateObject(std::istream &is)
Create a new wall, based on the information provided in a restart file.
Definition: WallHandler.cc:195
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 195 of file WallHandler.cc.

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

Referenced by readAndAddObject().

196 {
197  std::string type;
198  is >> type;
199  logger(DEBUG, "WallHandler::readAndAddObject(is): reading type %.", type);
200 
201  //for backward compatibility (before svnversion ~2360)
202  if (type == "numFiniteWalls")
203  {
204  return readAndCreateOldObject(is);
205  }
206  else
207  {
208  BaseWall* wall = createObject(type);
209  //check if wall is user-defined
210  if (wall == nullptr)
211  {
212  wall = getDPMBase()->readUserDefinedWall(type);
213  }
214  //throw warning if wall could not be found
215  if (wall == nullptr)
216  {
217  std::string line;
218  getline(is, line);
219  logger(WARN, "This wall could not be read; dummy wall is inserted instead:\n%%", type, line);
220  BaseWall* wall = new InfiniteWall;
221  wall->setHandler(this);
222  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
223  return wall;
224  }
225  wall->setHandler(this);
226  is >> *wall;
227  wall->setSpecies(getDPMBase()->speciesHandler.getObject(wall->getIndSpecies()));
228  return wall;
229  }
230 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
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:123
BaseWall * readAndCreateOldObject(std::istream &is)
Create a new wall, based on the information from old-style restart data.
Definition: WallHandler.cc:241
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:282
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 241 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().

242 {
243  //read in next line
244  std::stringstream line;
246  logger(VERBOSE, line.str());
247 
248  std::string dummy;
249  unsigned int numWalls;
250  Mdouble position;
251  Vec3D normal;
252  line >> numWalls;
253 
254  if (numWalls == 0)
255  {
256  InfiniteWall* wall = new InfiniteWall();
257  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
258  line >> dummy >> normal >> dummy >> position;
259  wall->set(normal, position * normal);
260  return wall;
261  }
262  else
263  {
265  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
266  for (unsigned int i = 0; i < numWalls; ++i)
267  {
268  line >> dummy >> normal >> dummy >> position;
269  wall->addObject(normal, position * normal);
270  }
271  return wall;
272  }
273 }
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
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:423
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 362 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().

363 {
364  const unsigned groupId = getNextGroupId();
365  std::string fileType = filename.substr(filename.find_last_of('.') + 1);
366 
367  //define a default triangle wall
368  TriangleWall triangleWall;
369  triangleWall.setSpecies(species);
370  triangleWall.setVelocity(velocity);
371  triangleWall.setAngularVelocity(angularVelocity);
372  triangleWall.setGroupId(groupId);
373 
374  if (helpers::lower(fileType) == "vtk")
375  {
376  //try open the input file
377  std::fstream file;
378  file.open(filename.c_str(), std::ios::in);
379  logger.assert_always(file.is_open(), "File opening failed: %", filename);
380 
381  //skip the header lines
382  std::string dummy;
383  getline(file, dummy);
384  getline(file, dummy);
385  getline(file, dummy);
386  getline(file, dummy);
387 
388  //read vertices, apply scaling
389  unsigned num;
390  file >> dummy >> num >> dummy;
391  std::vector<Vec3D> vertex;
392  vertex.reserve(num);
393  Vec3D v;
394  for (unsigned i = 0; i < num; i++)
395  {
396  file >> v.X >> v.Y >> v.Z;
397  v *= scaleFactor;
398  vertex.push_back(v);
399  }
400 
401  //read faces
402  unsigned n = getSize();
403  file >> dummy >> num >> dummy;
404  unsigned id0, id1, id2;
405  for (unsigned i = 0; i < num; i++)
406  {
407  file >> dummy >> id0 >> id1 >> id2;
408  triangleWall.setVertices(vertex[id0], vertex[id1], vertex[id2], centerOfRotation);
409  copyAndAddObject(triangleWall);
410  }
411 
412  //close file
413  file.close();
414 
415  logger(INFO, "Read in % walls from %", getSize() - n,filename);
416 
417  }
418  else if (helpers::lower(fileType) == "stl")
419  {
420 
421  BinaryReader file(filename);
422 
423  STLTriangle triangle;
424 
425  std::string header = file.readString(80);
426  unsigned numTriangles = file.readUnsignedInt(4);
427 
428  for (unsigned i = 0; i < numTriangles; i++)
429  {
430  triangle.normal.x() = file.readFloat(4);
431  triangle.normal.y() = file.readFloat(4);
432  triangle.normal.z() = file.readFloat(4);
433 
434 
435  triangle.vertex1.x() = file.readFloat(4);
436  triangle.vertex1.y() = file.readFloat(4);
437  triangle.vertex1.z() = file.readFloat(4);
438 
439  triangle.vertex2.x() = file.readFloat(4);
440  triangle.vertex2.y() = file.readFloat(4);
441  triangle.vertex2.z() = file.readFloat(4);
442 
443 
444  triangle.vertex3.x() = file.readFloat(4);
445  triangle.vertex3.y() = file.readFloat(4);
446  triangle.vertex3.z() = file.readFloat(4);
447 
448  triangle.vertex1 *= scaleFactor;
449  triangle.vertex2 *= scaleFactor;
450  triangle.vertex3 *= scaleFactor;
451 
452  //add to triangle wall
453  triangleWall.setVertices(triangle.vertex1, triangle.vertex2, triangle.vertex3, centerOfRotation);
454  copyAndAddObject(triangleWall);
455 
456  //Now ignore (read) the two dummy characters
457  file.ignoreChar(2);
458 
459  }
460 
461  logger(INFO, "Read in % walls from %", numTriangles,filename);
462 
463  }
464  else
465  {
466 
467  logger(ERROR, "File type of % must be vtk or stl");
468 
469  }
470 
471  return groupId;
472 }
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")
Definition of different loggers with certain modules. A user can define its own custom logger here...
Vec3D vertex3
Definition: STLTriangle.h:57
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
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 302 of file WallHandler.cc.

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

303 {
304  const std::string fileName = getDPMBase()->getName() + "BoundingBox.vtu";
305  //logger(INFO, "% writing vtk file for bounding box: %",
306  // getDPMBase()->getTime(), fileName);
307  std::fstream file;
308  file.open(fileName.c_str(), std::ios::out);
309  if (file.fail())
310  {
312  logger(WARN, "Error in writeToFile: file could not be opened");
313  }
314  file << "<?xml version=\"1.0\"?>\n\n";
315  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
316  file << "<UnstructuredGrid>\n";
317  file << "<Piece NumberOfPoints=\"8\" NumberOfCells=\"1\">\n";
318  file << "<Points>\n";
319  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
320  Vec3D P[2] = {getDPMBase()->getMax(), getDPMBase()->getMin()};
321  for (auto& i : P)
322  {
323  for (auto& j : P)
324  {
325  for (auto& k : P)
326  {
327  Vec3D p = Vec3D(i.X, j.Y, k.Z);
328  file << '\t' << p << '\n';
329  }
330  }
331  }
333  file << " </DataArray>\n";
334  file << "</Points>\n";
335  file << "<Cells>\n";
336  file <<
337  " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
338  file << "\t0 1 3 2 0 4 5 1 5 7 3 7 6 2 6 4\n";
339  file << " </DataArray>\n";
340  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
341  file <<
342  "\t16\n"; //offset into the connectivity array for the end of each cell.
343  file << " </DataArray>\n";
344  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
345  file << "\t4\n";
346  file << " </DataArray>\n";
347  file << "</Cells>\n";
348  file << "</Piece>\n";
349  file << "</UnstructuredGrid>\n";
350  file << "</VTKFile>\n";
351  file.close();
352 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
Vec3D getMin() const
Definition: DPMBase.h:637
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: DPMBase.cc:397
Vec3D getMax() const
Definition: DPMBase.h:643
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: