WallHandler Class Referencefinal

Container to store all BaseWall. More...

#include <WallHandler.h>

+ Inheritance diagram for WallHandler:

Public Types

enum class  DetailsVTKOptions { BOUNDINGBOX = 0 , NURBSWALL = 1 , WEARABLENURBSWALL = 2 }
 

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...
 
void setWriteVTK (FileType)
 Sets whether walls are written into a VTK file. More...
 
void setWriteVTK (bool)
 Sets whether walls are written into a VTK file. More...
 
FileType getWriteVTK () const
 Returns whether walls are written in a VTK file. More...
 
void setWriteDetailsVTK (DetailsVTKOptions, FileType)
 
void setWriteDetailsVTK (DetailsVTKOptions, bool)
 
FileType getWriteDetailsVTK (DetailsVTKOptions) const
 
bool getWriteDetailsVTKAny () const
 
std::unordered_map< DetailsVTKOptions, FileTypegetWriteWallDetailsVTKAll () const
 
void writeWallDetailsVTKBoundingBox (VTKData &data) const
 
void setWriteWallSurfaceAreaVTK (bool writeWallSurfaceAreaVTK)
 Enables/disables the calculation and writing of the surface area of the cells. More...
 
bool getWriteWallSurfaceAreaVTK () const
 
- 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 addObject (BaseWall *object)
 Adds a new Object to the BaseHandler. 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)
 
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...
 

Private Attributes

FileType writeVTK_
 
std::unordered_map< DetailsVTKOptions, FileTypewriteDetailsVTK_
 unordered_map storing the file types corresponding to each of the enum DetailsVTKOptions 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.

Member Enumeration Documentation

◆ DetailsVTKOptions

Enumerator
BOUNDINGBOX 

Writes a bounding box around the domain.

NURBSWALL 

Writes the NURBS control points.

WEARABLENURBSWALL 

Writes the debris.

118  {
119  // Used as keys for an unordered_map.
120  // The actual enum values are written to the restart file and their meaning should therefore never change.
121  // So when adding new options, be sure to hardcode a unique enum value!
122  // The options can be in any order and their values are completely free to choose, as long as they're unique.
123 
127  BOUNDINGBOX = 0,
128 
132  NURBSWALL = 1,
133 
137  WEARABLENURBSWALL = 2
138  };

Constructor & Destructor Documentation

◆ WallHandler() [1/2]

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?
55 {
57  clear();
59 #ifdef DEBUG_CONSTRUCTOR
60  std::cerr << "WallHandler::WallHandler() finished" << std::endl;
61 #endif
62 }
@ NO_FILE
file will not be created/read
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
FileType writeVTK_
Definition: WallHandler.h:166

References BaseHandler< BaseWall >::clear(), NO_FILE, and writeVTK_.

◆ WallHandler() [2/2]

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?
71 {
73  clear();
74  setDPMBase(WH.getDPMBase());
76  writeVTK_ = WH.writeVTK_;
77 #ifdef DEBUG_CONSTRUCTOR
78  std::cerr << "WallHandler::WallHandler(const WallHandler&) finished" << std::endl;
79 #endif
80 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:718
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void copyContentsFromOtherHandler(const BaseHandler< BaseWall > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:367

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

◆ ~WallHandler()

WallHandler::~WallHandler ( )
final

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

104 {
105 #ifdef DEBUG_CONSTRUCTOR
106  std::cerr << "WallHandler::~WallHandler() finished" << std::endl;
107 #endif
108 }

Member Function Documentation

◆ actionsAfterParticleGhostUpdate()

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).

459 {
460  // #pragma omp parallel for //schedule(dynamic)
461  for (auto w: *this)
462  {
463  w->actionsAfterParticleGhostUpdate();
464  }
465 }

Referenced by DPMBase::computeOneTimeStep().

◆ addObject()

void WallHandler::addObject ( BaseWall W)
final

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.

116 {
117  if (W->getSpecies() == nullptr)
118  {
119  logger(WARN, "WARNING: The wall with ID % that is added in WallHandler::addObject "
120  "does not have a species yet. Please make sure that you have "
121  "set the species somewhere in the driver code.", W->getId());
122  }
123  //Puts the wall in the Wall list
125  //set the particleHandler pointer
126  W->setHandler(this);
127 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
Definition: BaseInteractable.h:108
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
virtual void setHandler(WallHandler *handler)
A function which sets the WallHandler for this BaseWall.
Definition: BaseWall.cc:125

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

Referenced by readAndAddObject(), and Chutebelt::setupInitialConditions().

◆ createObject()

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.
130 {
131  if (type == "CylindricalWall")
132  {
133  return new CylindricalWall;
134  }
135  else if (type == "AxisymmetricIntersectionOfWalls")
136  {
138  }
139  else if (type == "ScrewsymmetricIntersectionOfWalls")
140  {
142  }
143  else if (type == "IntersectionOfWalls")
144  {
145  return new IntersectionOfWalls;
146  }
147  else if (type == "BasicIntersectionOfWalls")
148  {
149  return new BasicIntersectionOfWalls;
150  }
151  else if (type == "BasicUnionOfWalls")
152  {
153  return new BasicUnionOfWalls;
154  }
155  else if (type == "InfiniteWall")
156  {
157  return new InfiniteWall;
158  }
159  else if (type == "InfiniteWallWithHole")
160  {
161  return new InfiniteWallWithHole;
162  }
163  else if (type == "Screw")
164  {
165  return new Screw;
166  }
167  else if (type == "Coil")
168  {
169  return new Coil;
170  }
171  else if (type == "TriangleWall")
172  {
173  return new TriangleWall;
174  }
175  else if (type == "MeshTriangle")
176  {
177  return new MeshTriangle;
178  }
179  else if (type == "VChute")
180  {
181  return new VChute;
182  }
183  else if (type == "NurbsWall")
184  {
185  return new NurbsWall();
186  }
187  else if (type == "WearableNurbsWall")
188  {
189  return new WearableNurbsWall();
190  }
191  else if (type == "TriangleMeshWall")
192  {
193  return new TriangleMeshWall;
194  }
195  else if (type == "WearableTriangleMeshWall")
196  {
197  return new WearableTriangleMeshWall;
198  }
199  //for backward compatibility (before svnversion ~2360)
200  else if (type == "numFiniteWalls")
201  {
202  return new BasicIntersectionOfWalls;
203  }
205  // else if (!getDPMBase()->readUserDefinedWall(type,is))
206  else
207  {
208  logger(WARN, "Wall type: % not understood in restart file", type);
209  return nullptr;
210  }
211 }
Use AxisymmetricIntersectionOfWalls to Screw Screw::read Screw::read Screw::read define axisymmetric ...
Definition: AxisymmetricIntersectionOfWalls.h:126
Restriction of a wall to the intersection with another wall.
Definition: BasicIntersectionOfWalls.h:43
Restriction of a wall to the intersection with another wall.
Definition: BasicUnionOfWalls.h:43
This class defines a coil in the z-direction from a (constant) starting point, a (constant) length L,...
Definition: Coil.h:41
Definition: CylindricalWall.h:38
Definition: InfiniteWallWithHole.h:38
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:48
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
Definition: IntersectionOfWalls.h:59
MeshTriangle implements a triangle whose vertex positions are defined by three particles.
Definition: MeshTriangle.h:75
This function defines a wall via a NurbsSurface.
Definition: NurbsWall.h:37
This function defines an Archimedes' screw in the z-direction from a (constant) starting point,...
Definition: Screw.h:44
Use ScrewsymmetricIntersectionOfWalls to define screwsymmetric walls, such as cylinders,...
Definition: ScrewsymmetricIntersectionOfWalls.h:126
Definition: TriangleMeshWall.h:33
A TriangleWall is convex polygon defined as an intersection of InfiniteWall's.
Definition: TriangleWall.h:57
Definition: VChute.h:35
Definition: WearableNurbsWall.h:32
Definition: WearableTriangleMeshWall.h:32

References logger, and WARN.

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

◆ getName()

std::string WallHandler::getName ( ) const
finalvirtual

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

Returns
The string "WallHandler".

Implements BaseHandler< BaseWall >.

311 {
312  return "WallHandler";
313 }

◆ getWriteDetailsVTK()

FileType WallHandler::getWriteDetailsVTK ( DetailsVTKOptions  option) const
495 {
496  // This function has to be marked constant, so accessing by key is not an option, as it will automatically add keys
497  // not present in the map yet.
498 
499  // Try to find the option to see if it's already added to the map or not
500  auto it = writeDetailsVTK_.find(option);
501  // When the iterator does not equal the end, the key has been found
502  if (it != writeDetailsVTK_.end())
503  return it->second;
504  else
505  return FileType::NO_FILE; // Else return a default file type
506 }
std::unordered_map< DetailsVTKOptions, FileType > writeDetailsVTK_
unordered_map storing the file types corresponding to each of the enum DetailsVTKOptions
Definition: WallHandler.h:173

References NO_FILE, and writeDetailsVTK_.

Referenced by WallDetailsVTKWriter::shouldWrite(), and DPMBase::writePythonFileForVTKVisualisation().

◆ getWriteDetailsVTKAny()

bool WallHandler::getWriteDetailsVTKAny ( ) const
509 {
510  // Simple lambda expression to check if any of the file types are not of type NO_FILE
511  return std::any_of(writeDetailsVTK_.begin(), writeDetailsVTK_.end(),
512  [](const auto& p) { return p.second != FileType::NO_FILE; });
513 }

References writeDetailsVTK_.

Referenced by DPMBase::write(), and DPMBase::writeVTKFiles().

◆ getWriteVTK()

FileType WallHandler::getWriteVTK ( ) const

Returns whether walls are written in a VTK file.

478 {
479  return writeVTK_;
480 }

References writeVTK_.

Referenced by DPMBase::getWallsWriteVTK(), DPMBase::write(), DPMBase::writePythonFileForVTKVisualisation(), and DPMBase::writeVTKFiles().

◆ getWriteWallDetailsVTKAll()

std::unordered_map< WallHandler::DetailsVTKOptions, FileType > WallHandler::getWriteWallDetailsVTKAll ( ) const
516 {
517  return writeDetailsVTK_;
518 }

References writeDetailsVTK_.

Referenced by DPMBase::write().

◆ getWriteWallSurfaceAreaVTK()

bool WallHandler::getWriteWallSurfaceAreaVTK ( ) const
526 {
528 }
WallVTKWriter & getWallVTKWriter()
Definition: DPMBase.cc:5505
bool getWriteWallSurfaceAreaVTK() const
Definition: WallVTKWriter.cc:192

References BaseHandler< BaseWall >::getDPMBase(), DPMBase::getWallVTKWriter(), and WallVTKWriter::getWriteWallSurfaceAreaVTK().

◆ operator=()

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.

89 {
90  if (this != &rhs)
91  {
92  clear();
93  setDPMBase(rhs.getDPMBase());
95  writeVTK_ = rhs.writeVTK_;
96  }
97  return *this;
98 #ifdef DEBUG_CONSTRUCTOR
99  std::cerr << "WallHandler::operator =(const WallHandler&) finished" << std::endl;
100 #endif
101 }

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

◆ readAndAddObject()

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 >.

300 {
301  BaseWall* o = readAndCreateObject(is);
302  unsigned int id = o->getId();
303  addObject(o);
304  getLastObject()->setId(id);
305 }
BaseWall * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
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
Basic class for walls.
Definition: BaseWall.h:49
BaseWall * readAndCreateObject(std::istream &is)
Create a new wall, based on the information provided in a restart file.
Definition: WallHandler.cc:213
void addObject(BaseWall *W) final
Adds a BaseWall to the WallHandler.
Definition: WallHandler.cc:115

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

Referenced by DPMBase::read().

◆ readAndCreateObject()

BaseWall * WallHandler::readAndCreateObject ( std::istream &  is)

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

214 {
215  std::string type;
216  is >> type;
217  logger(DEBUG, "WallHandler::readAndAddObject(is): reading type %.", type);
218 
219  //for backward compatibility (before svnversion ~2360)
220  if (type == "numFiniteWalls")
221  {
222  return readAndCreateOldObject(is);
223  }
224  else
225  {
226  BaseWall* wall = createObject(type);
227  //check if wall is user-defined
228  if (wall == nullptr)
229  {
230  wall = getDPMBase()->readUserDefinedWall(type);
231  }
232  //throw warning if wall could not be found
233  if (wall == nullptr)
234  {
235  std::string line;
236  getline(is, line);
237  logger(WARN, "This wall could not be read; dummy wall is inserted instead:\n%%", type, line);
238  BaseWall* wall = new InfiniteWall;
239  wall->setHandler(this);
240  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
241  return wall;
242  }
243  wall->setHandler(this);
244  is >> *wall;
245  wall->setSpecies(getDPMBase()->speciesHandler.getObject(wall->getIndSpecies()));
246  return wall;
247  }
248 }
@ DEBUG
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:169
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:293
BaseWall * readAndCreateOldObject(std::istream &is)
Create a new wall, based on the information from old-style restart data.
Definition: WallHandler.cc:259
static BaseWall * createObject(const std::string &type)
Create a new wall, with the type given as a string (required for restarting).
Definition: WallHandler.cc:129

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

Referenced by readAndAddObject().

◆ readAndCreateOldObject()

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.
260 {
261  //read in next line
262  std::stringstream line;
264  logger(VERBOSE, line.str());
265 
266  std::string dummy;
267  unsigned int numWalls;
268  Mdouble position;
269  Vec3D normal;
270  line >> numWalls;
271 
272  if (numWalls == 0)
273  {
274  InfiniteWall* wall = new InfiniteWall();
275  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
276  line >> dummy >> normal >> dummy >> position;
277  wall->set(normal, position * normal);
278  return wall;
279  }
280  else
281  {
283  wall->setSpecies(getDPMBase()->speciesHandler.getObject(0));
284  for (unsigned int i = 0; i < numWalls; ++i)
285  {
286  line >> dummy >> normal >> dummy >> position;
287  wall->addObject(normal, position * normal);
288  }
289  return wall;
290  }
291 }
double Mdouble
Definition: GeneralDefine.h:34
@ VERBOSE
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:118
void addObject(Vec3D normal, Vec3D point)
Adds a wall to the set of infinite walls, given a normal vector pointing into the wall (i....
Definition: IntersectionOfWalls.cc:138
void setSpecies(const ParticleSpecies *species)
sets species of subwalls as well
Definition: IntersectionOfWalls.cc:72
Definition: Vector.h:51
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: StringHelpers.cc:62

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

Referenced by readAndCreateObject().

◆ readTriangleWall()

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)
342 {
343  const unsigned groupId = getNextGroupId();
344  std::string fileType = filename.substr(filename.find_last_of('.') + 1);
345 
346  //define a default triangle wall
347  TriangleWall triangleWall;
348  triangleWall.setSpecies(species);
349  triangleWall.setVelocity(velocity);
350  triangleWall.setAngularVelocity(angularVelocity);
351  triangleWall.setGroupId(groupId);
352 
353  if (helpers::lower(fileType) == "vtk")
354  {
355  //try open the input file
356  std::fstream file;
357  file.open(filename.c_str(), std::ios::in);
358  logger.assert_always(file.is_open(), "File opening failed: %", filename);
359 
360  //skip the header lines
361  std::string dummy;
362  getline(file, dummy);
363  getline(file, dummy);
364  getline(file, dummy);
365  getline(file, dummy);
366 
367  //read vertices, apply scaling
368  unsigned num;
369  file >> dummy >> num >> dummy;
370  std::vector<Vec3D> vertex;
371  vertex.reserve(num);
372  Vec3D v;
373  for (unsigned i = 0; i < num; i++)
374  {
375  file >> v.X >> v.Y >> v.Z;
376  v *= scaleFactor;
377  vertex.push_back(v);
378  }
379 
380  //read faces
381  unsigned n = getSize();
382  file >> dummy >> num >> dummy;
383  unsigned id0, id1, id2;
384  for (unsigned i = 0; i < num; i++)
385  {
386  file >> dummy >> id0 >> id1 >> id2;
387  triangleWall.setVertices(vertex[id0], vertex[id1], vertex[id2], centerOfRotation);
388  copyAndAddObject(triangleWall);
389  }
390 
391  //close file
392  file.close();
393 
394  logger(INFO, "Read in % walls from %", getSize() - n,filename);
395 
396  }
397  else if (helpers::lower(fileType) == "stl")
398  {
399 
400  BinaryReader file(filename);
401 
402  STLTriangle triangle;
403 
404  std::string header = file.readString(80);
405  unsigned numTriangles = file.readUnsignedInt(4);
406 
407  for (unsigned i = 0; i < numTriangles; i++)
408  {
409  triangle.normal.x() = file.readFloat(4);
410  triangle.normal.y() = file.readFloat(4);
411  triangle.normal.z() = file.readFloat(4);
412 
413 
414  triangle.vertex1.x() = file.readFloat(4);
415  triangle.vertex1.y() = file.readFloat(4);
416  triangle.vertex1.z() = file.readFloat(4);
417 
418  triangle.vertex2.x() = file.readFloat(4);
419  triangle.vertex2.y() = file.readFloat(4);
420  triangle.vertex2.z() = file.readFloat(4);
421 
422 
423  triangle.vertex3.x() = file.readFloat(4);
424  triangle.vertex3.y() = file.readFloat(4);
425  triangle.vertex3.z() = file.readFloat(4);
426 
427  triangle.vertex1 *= scaleFactor;
428  triangle.vertex2 *= scaleFactor;
429  triangle.vertex3 *= scaleFactor;
430 
431  //add to triangle wall
432  triangleWall.setVertices(triangle.vertex1, triangle.vertex2, triangle.vertex3, centerOfRotation);
433  copyAndAddObject(triangleWall);
434 
435  //Now ignore (read) the two dummy characters
436  file.ignoreChar(2);
437 
438  }
439 
440  logger(INFO, "Read in % walls from %", numTriangles,filename);
441 
442  }
443  else
444  {
445 
446  logger(ERROR, "File type of % must be vtk or stl");
447 
448  }
449 
450  return groupId;
451 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
@ INFO
@ ERROR
unsigned getNextGroupId()
Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases next...
Definition: BaseHandler.h:293
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.
Definition: BaseHandler.h:379
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Definition: BaseInteractable.cc:360
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Definition: BaseInteractable.cc:350
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:37
Test of the STL reader. The files used is STL file with containing 12 triange that a 1 by 1 by 1 squa...
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:39
Vec3D vertex2
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:62
Vec3D vertex3
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:63
Vec3D vertex1
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:61
Vec3D normal
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:60
void setVertices(Vec3D A, Vec3D B, Vec3D C)
Sets member variables such that the wall represents a triangle with vertices A, B,...
Definition: TriangleWall.cc:165
Mdouble & y()
RW reference to Y.
Definition: Vector.h:372
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble & z()
RW reference to Z.
Definition: Vector.h:384
Mdouble X
the vector components
Definition: Vector.h:66
Mdouble & x()
RW reference to X.
Definition: Vector.h:360
std::string lower(std::string s)
returns the input string after converting upper-case characters to lower case
Definition: StringHelpers.cc:32

References BaseHandler< BaseWall >::copyAndAddObject(), ERROR, BaseHandler< BaseWall >::getNextGroupId(), BaseHandler< BaseWall >::getSize(), constants::i, BinaryReader::ignoreChar(), INFO, logger, helpers::lower(), n, 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().

Referenced by MarbleRun::loadBigSeesaw(), MarbleRun::loadSmallSeesaw(), MarbleRun::loadSTLFile(), main(), multiParticleT1::setupInitialConditions(), NozzleDemo::setupInitialConditions(), NozzleSelfTest::setupInitialConditions(), and AreaVTK::setupInitialConditions().

◆ setWriteDetailsVTK() [1/2]

void WallHandler::setWriteDetailsVTK ( DetailsVTKOptions  option,
bool  writeVTK 
)
489 {
491  setWriteDetailsVTK(option, fileType);
492 }
FileType
With FileType options, one is able to choose if data is to be read/written from/into no or single or ...
Definition: File.h:41
@ MULTIPLE_FILES
each time-step will be written into/read from separate files numbered consecutively: name_....
virtual void writeVTK() const
now empty function for writing VTK files.
Definition: BaseHandler.h:286
void setWriteDetailsVTK(DetailsVTKOptions, FileType)
Definition: WallHandler.cc:482

References MULTIPLE_FILES, NO_FILE, setWriteDetailsVTK(), and BaseHandler< BaseWall >::writeVTK().

◆ setWriteDetailsVTK() [2/2]

void WallHandler::setWriteDetailsVTK ( DetailsVTKOptions  option,
FileType  fileType 
)
483 {
484  // Automatically adds option when it doesn't exist in the map yet
485  writeDetailsVTK_[option] = fileType;
486 }

References writeDetailsVTK_.

Referenced by DPMBase::read(), and setWriteDetailsVTK().

◆ setWriteVTK() [1/2]

void WallHandler::setWriteVTK ( bool  writeVTK)

Sets whether walls are written into a VTK file.

References MULTIPLE_FILES, NO_FILE, BaseHandler< BaseWall >::writeVTK(), and writeVTK_.

◆ setWriteVTK() [2/2]

◆ setWriteWallSurfaceAreaVTK()

void WallHandler::setWriteWallSurfaceAreaVTK ( bool  writeWallSurfaceAreaVTK)

Enables/disables the calculation and writing of the surface area of the cells.

521 {
522  getDPMBase()->getWallVTKWriter().setWriteWallSurfaceAreaVTK(writeWallSurfaceAreaVTK);
523 }
void setWriteWallSurfaceAreaVTK(bool writeWallSurfaceAreaVTK)
Definition: WallVTKWriter.cc:187

References BaseHandler< BaseWall >::getDPMBase(), DPMBase::getWallVTKWriter(), and WallVTKWriter::setWriteWallSurfaceAreaVTK().

Referenced by AreaVTK::setupInitialConditions().

◆ writeWallDetailsVTKBoundingBox()

void WallHandler::writeWallDetailsVTKBoundingBox ( VTKData data) const
316 {
317  Vec3D P[2] = { getDPMBase()->getMax(), getDPMBase()->getMin() };
318  for (const Vec3D& i : P)
319  {
320  for (const Vec3D& j : P)
321  {
322  for (const Vec3D& k : P)
323  {
324  data.addToPoints(Vec3D(i.X, j.Y, k.Z));
325  }
326  }
327  }
328 
329  data.addToConnectivity({ 0, 1, 3, 2, 0, 4, 5, 1, 5, 7, 3, 7, 6, 2, 6, 4 });
330  data.addToTypes(4);
331 }
Vec3D getMax() const
Definition: DPMBase.h:670
Vec3D getMin() const
Definition: DPMBase.h:664
void addToTypes(int type)
Adds a type to the types vector.
Definition: VTKData.cc:43
void addToPoints(Vec3D point)
Adds a point to the points vector.
Definition: VTKData.cc:28
void addToConnectivity(const std::vector< size_t > &indices)
Adds a vector of indices to the connectivity vector.
Definition: VTKData.cc:38
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73

References VTKData::addToConnectivity(), VTKData::addToPoints(), VTKData::addToTypes(), BaseHandler< BaseWall >::getDPMBase(), DPMBase::getMax(), DPMBase::getMin(), constants::i, and Global_Physical_Variables::P.

Referenced by WallDetailsVTKWriter::writeVTK().

Member Data Documentation

◆ writeDetailsVTK_

std::unordered_map<DetailsVTKOptions, FileType> WallHandler::writeDetailsVTK_
private

unordered_map storing the file types corresponding to each of the enum DetailsVTKOptions

The filetypes are only actually added to the map when setting or getting it. The getter automatically adds the default filetype NO_FILE when the requested options had not yet been added.

Referenced by getWriteDetailsVTK(), getWriteDetailsVTKAny(), getWriteWallDetailsVTKAll(), and setWriteDetailsVTK().

◆ writeVTK_

FileType WallHandler::writeVTK_
private

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