CGHandler Class Reference

Container that stores all CG objects. More...

#include <CGHandler.h>

+ Inheritance diagram for CGHandler:

Public Member Functions

 CGHandler ()=default
 Default constructor, creates an empty CGHandler. More...
 
 CGHandler (const CGHandler &BH)
 Copy constructor, copies the CGHandler and all BaseCGPoint's it contains. More...
 
CGHandleroperator= (const CGHandler &rhs)
 Assignment operator that copies the pointer to the DPMBase and all objects. More...
 
 ~CGHandler () final=default
 Destructor, destructs the CGHandler and all BaseCGPoint's it contains. More...
 
void addObject (BaseCG *cg) final
 
std::string getName () const final
 
void readAndAddObject (std::istream &is) final
 Reads objects into the CGHandler from an istream (currently not implemented). More...
 
void write (std::ostream &os) const
 Writes objects into the CGHandler to an ostream (currently not implemented). More...
 
void initialise ()
 Contains the code executed before the first time step. More...
 
void evaluate ()
 Contains the code executed at each time step. More...
 
void finish ()
 Contains the code executed after the last time step. More...
 
void restart (std::string name)
 loads restart file, before evaluateDataFiles is run More...
 
void restartAndEvaluateRestartFiles (const std::string &name)
 
void restartAndEvaluateDataFiles (const std::string &name, bool evaluateFStatFiles=true)
 
bool evaluateDataFiles (bool evaluateFStatFiles=true)
 does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing), then several data files, and fstat files (if existing) More...
 
bool evaluateRestartFiles ()
 
void computeContactPoints ()
 
Mdouble getTimeMin ()
 
Mdouble getTimeMax ()
 
void setInitialFileCounter (unsigned initialFileCounter)
 
unsigned getInitialFileCounter () const
 
Mdouble getPreviousEvaluationTime ()
 Returns the time of the last read/evaluated time step. More...
 
void setPreviousEvaluationTime (Mdouble time)
 Sets the time of the last read/evaluated time step to a specified time. More...
 
void setPreviousEvaluationTimeToCurrentTime ()
 Sets the previous evaluation time to the current time. More...
 
void setPreviousPositionToCurrentPosition ()
 Sets the previous position for every particle to its current position. More...
 
void handlePreviousInformation ()
 Sets data from the current time step as data from the previous time step. More...
 
- Public Member Functions inherited from BaseHandler< BaseCG >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseCG > &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< BaseCG > &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 (BaseCG *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addObject (BaseCG *object)
 Adds a new Object to the BaseHandler. More...
 
virtual void addGhostObject (BaseCG *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(BaseCG *)> cond)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
virtual void removeObjects (std::vector< unsigned int > indices)
 
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...
 
BaseCGgetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< BaseCG * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
BaseCGgetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler.
More...
 
const BaseCGgetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseCGgetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseCGgetLastObject () 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 BaseCG &obj)
 Resizes the container to contain N elements. More...
 
const std::vector< BaseCG * >::const_iterator begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< BaseCG * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseCG * >::const_iterator end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseCG * >::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 (BaseCG *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...
 

Public Attributes

unsigned initialFileCounter = 0
 

Private Attributes

Mdouble previousEvaluationTime_ = 0
 Saves the time of the last read/evaluated data/restartFile. More...
 

Additional Inherited Members

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

Detailed Description

Container that stores all CG objects.

Todo:

get function that by default can distinguish species, but also density

make tests

change output format

command line arguments

make more readable definitions

read (a) restart, (b) data/fstat files

add speed by using the mesh

introduce standardDev

add 2D support

do we need to store the BaseObject::index_ anymore?

Can Interaction inherit directly from BaseInteraction?

make Files::statFile_, ... public, like the handlers; remove get functions for File's and handlers.

take out dependence on DPMBase::statFile (i.e. the savecount)

TW note, to keep the code working on Windows:

  • std::exit requires correct header cstdlib,
  • don't use toString (thanks to Silvia for debugging)

The CGHandler stores all CG objects. Its member functions initialise, evaluate, and finish are called by the DPMBase before, during and after the time loop, respectively, and call the member functions initialise, evaluate, and finish of each CG object.

See also: MercuryCG: Post-processing discrete particle data using the coarse-graining formulation (in development).

Constructor & Destructor Documentation

◆ CGHandler() [1/2]

CGHandler::CGHandler ( )
default

Default constructor, creates an empty CGHandler.

◆ CGHandler() [2/2]

CGHandler::CGHandler ( const CGHandler ch)

Copy constructor, copies the CGHandler and all BaseCGPoint's it contains.

Parameters
[in]chThe CGHandler that has to be copied.
15  : BaseHandler(ch)
16 {
17  setDPMBase(ch.getDPMBase());
18  //copyContentsFromOtherHandler(ch);
19 }
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
Definition: BaseHandler.h:316
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:726
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733

References BaseHandler< T >::getDPMBase(), and BaseHandler< BaseCG >::setDPMBase().

◆ ~CGHandler()

CGHandler::~CGHandler ( )
finaldefault

Destructor, destructs the CGHandler and all BaseCGPoint's it contains.

Member Function Documentation

◆ addObject()

void CGHandler::addObject ( BaseCG cg)
final
Parameters
[in]cgA pointer to the CG object that has to be added to the handler.
45 {
46  //Puts the cg object in the list
48  //set the CGHandler pointer
49  cg->setHandler(this);
50 }
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:52
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:412

References BaseHandler< T >::addObject(), and BaseCG::setHandler().

◆ computeContactPoints()

void CGHandler::computeContactPoints ( )
180 {
181  //recompute contact point (necessary for old restart files)
182  for (BaseInteraction* const c : getDPMBase()->interactionHandler)
183  {
184  if (c->getContactPoint().isNaN())
185  {
186  const Vec3D& p = c->getP()->getPosition();
187  const Vec3D& i = c->getI()->getPosition();
188  const BaseParticle* const PParticle = dynamic_cast<BaseParticle*>(c->getP());
189  const BaseParticle* const IParticle = dynamic_cast<BaseParticle*>(c->getI());
190  if (IParticle != nullptr)
191  {
192  const Vec3D branchVector = p - i;
193  const Mdouble distance = branchVector.getLength();
194  c->setNormal(branchVector / distance);
195  c->setOverlap(PParticle->getRadius() + IParticle->getRadius() - distance);
196  c->setDistance(distance);
197  c->setContactPoint(p - (PParticle->getRadius() - 0.5 * c->getOverlap()) * c->getNormal());
198  }
199  else
200  {
201  const InfiniteWall* const IWall = dynamic_cast<InfiniteWall*>(c->getI());
202  if (IWall != nullptr)
203  {
204  const Mdouble dist = Vec3D::dot(i - p, IWall->getNormal());
205  const Mdouble r = dynamic_cast<BaseParticle*>(c->getP())->getRadius();
206  const Vec3D branch = (0.5 * (dist + r)) * IWall->getNormal();
207  c->setNormal(-IWall->getNormal());
208  c->setContactPoint(p + branch);
209  }
210  else
211  {
212  const Vec3D IP = p - i;
213  const Mdouble distance = Vec3D::getLength(IP);
214  c->setNormal(IP / distance);
215  c->setContactPoint(i);
216  }
217  }
218  //logger(INFO,"c%",c->getContactPoint());
219  static bool firstTime = true;
220  if (firstTime)
221  {
222  cgLogger(WARN,
223  "recomputing contact point, as contact point information is not available\n"
224  "Contact point is placed assuming spherical particles\n"
225  "Complex walls, non-spherical particles, periodic walls can create errors");
226  firstTime = false;
227  }
228  }
229  }
230 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
@ WARN
float * p
Definition: Tutorial_Map_using.cpp:9
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
Definition: BaseParticle.h:33
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:331
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:27
Vec3D getNormal() const
Access function for normal.
Definition: InfiniteWall.cc:192
Definition: Kernel/Math/Vector.h:30
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:350
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:56
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:339
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100

References calibrate::c, cgLogger, Vec3D::dot(), BaseHandler< BaseCG >::getDPMBase(), Vec3D::getLength(), InfiniteWall::getNormal(), BaseParticle::getRadius(), i, p, UniformPSDSelfTest::r, and WARN.

Referenced by evaluateRestartFiles().

◆ evaluate()

void CGHandler::evaluate ( )

Contains the code executed at each time step.

78 {
79  //evaluate all CG objects in the handler
80  for (BaseCG* it : *this)
81  {
82  //if we are below timeMax and the next time step should be written
83  if (it->getTimeMin() <= getDPMBase()->getTime() && it->getTimeMax() > getDPMBase()->getTime()
84  && it->statFile.saveCurrentTimeStep(getDPMBase()->getNumberOfTimeSteps()))
85  {
86  //logger(INFO,"evaluate %, nt=%",it->statFile.getName(), getDPMBase()->getNumberOfTimeSteps());
87  it->statFile.setLastSavedTimeStep(getDPMBase()->getNumberOfTimeSteps());
88  it->evaluate();
89  }
90  }
91 
92  // Remember information from this read
94 };
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:36
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:160
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:363
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields.
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:155
void handlePreviousInformation()
Sets data from the current time step as data from the previous time step.
Definition: CGHandler.cc:409
bool saveCurrentTimeStep(unsigned int ntimeSteps)
determined if this time step has to be written; if so, opens the output file
Definition: File.cc:290
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:280

References BaseCG::evaluate(), BaseHandler< BaseCG >::getDPMBase(), BaseCG::getTimeMax(), BaseCG::getTimeMin(), handlePreviousInformation(), File::saveCurrentTimeStep(), File::setLastSavedTimeStep(), and BaseCG::statFile.

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::writeOutputFiles().

◆ evaluateDataFiles()

bool CGHandler::evaluateDataFiles ( bool  evaluateFStatFiles = true)

does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing), then several data files, and fstat files (if existing)

Todo:
use ignore if time is out of bounds
308 {
309 
310 #ifdef MERCURYDPM_USE_MPI
311  //Make sure that the number of processors is equal to the number of processors used for the run
312  MPIContainer& communicator = MPIContainer::Instance();
313  std::vector<unsigned> numberOfDomains = this->getDPMBase()->getNumberOfDomains();
314  int numberOfRequiredProcessors = numberOfDomains[0]*numberOfDomains[1]*numberOfDomains[2];
315  if(!(numberOfRequiredProcessors == communicator.getNumberOfProcessors()))
316  {
317  if (communicator.getProcessorID() == 0)
318  {
319  logger(ERROR,"Please re-run the program with % cores",numberOfRequiredProcessors);
320  }
321  else
322  {
323  std::exit(-1);
324  }
325  }
326 #endif
327  // reset counters so reading begins with the first data/fstat file
328  DPMBase* const dpm = getDPMBase();
329  //dpm->interactionHandler.clear();
332 
333  initialise();
334 
335  // return false if no data file can be read
337  if (!dpm->readNextDataFile()) return false;
338 
339  //define and check time limits
340  const Mdouble timeMin = getTimeMin();
341  const Mdouble timeMax = getTimeMax();
342  if (dpm->getTime() > timeMax)
343  {
344  logger(ERROR, "Time stamp of initial data file (%) is beyond the maximum cg time (tMax=%)", dpm->getTime(),
345  timeMax);
346  }
347  else
348  while (dpm->getTime() < timeMin)
349  {
350  // Remember information from this read
352 
353  if (evaluateFStatFiles) dpm->readNextFStatFile();
354  cgLogger(INFO, "Skipped %, t = %, because time is below tMin = %", dpm->dataFile.getFullName(),
355  dpm->getTime(), timeMin);
356  dpm->readNextDataFile();
357  }
358 
359  // read data file
360  do
361  {
362  if (evaluateFStatFiles) dpm->readNextFStatFile();
363 
364  evaluate();
365 
366  cgLogger(INFO, "Evaluated %: t=%, Np=%, Nc=%", dpm->dataFile.getFullName()+(evaluateFStatFiles?" and "+dpm->fStatFile.getFullName():""), dpm->getTime(), dpm->particleHandler.getSize(), dpm->interactionHandler.getNumberOfObjects());
367 
368  } while (dpm->readNextDataFile() && getDPMBase()->getTime() <= timeMax);
369  cgLogger(INFO, "Finished reading from %", dpm->dataFile.getFullName());
370 
371  finish();
372  dpm->dataFile.close();
373  return true;
374 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO
@ ERROR
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:656
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:663
unsigned initialFileCounter
Definition: CGHandler.h:163
void evaluate()
Contains the code executed at each time step.
Definition: CGHandler.cc:77
void finish()
Contains the code executed after the last time step.
Definition: CGHandler.cc:96
Mdouble getTimeMin()
Definition: CGHandler.cc:376
Mdouble getTimeMax()
Definition: CGHandler.cc:386
void initialise()
Contains the code executed before the first time step.
Definition: CGHandler.cc:70
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:56
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1489
std::vector< unsigned > getNumberOfDomains()
returns the number of domains
Definition: DPMBase.cc:5369
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:799
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1484
bool readNextDataFile(unsigned int format=0)
Reads the next data file with default format=0. However, one can modify the format based on whether t...
Definition: DPMBase.cc:2711
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1473
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
void readNextFStatFile()
Reads the next fstat file.
Definition: DPMBase.cc:2903
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter,...
Definition: File.cc:148
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:385
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:209
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:109
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
Definition: MpiContainer.cc:83
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:113
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
Definition: MpiContainer.cc:92

References cgLogger, File::close(), DPMBase::dataFile, ERROR, evaluate(), finish(), DPMBase::fStatFile, BaseHandler< BaseCG >::getDPMBase(), File::getFullName(), DPMBase::getNumberOfDomains(), BaseHandler< T >::getNumberOfObjects(), MPIContainer::getNumberOfProcessors(), MPIContainer::getProcessorID(), BaseHandler< T >::getSize(), DPMBase::getTime(), getTimeMax(), getTimeMin(), handlePreviousInformation(), INFO, initialFileCounter, initialise(), MPIContainer::Instance(), DPMBase::interactionHandler, logger, DPMBase::particleHandler, DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), and File::setCounter().

Referenced by commandLineCG(), and restartAndEvaluateDataFiles().

◆ evaluateRestartFiles()

bool CGHandler::evaluateRestartFiles ( )
233 {
234 
235 #ifdef MERCURYDPM_USE_MPI
236  //Make sure that the number of processors is equal to the number of processors used for the run
237  MPIContainer& communicator = MPIContainer::Instance();
238  std::vector<unsigned> numberOfDomains = this->getDPMBase()->getNumberOfDomains();
239  int numberOfRequiredProcessors = numberOfDomains[0]*numberOfDomains[1]*numberOfDomains[2];
240  if(!(numberOfRequiredProcessors == communicator.getNumberOfProcessors()))
241  {
242  if (communicator.getProcessorID() == 0)
243  {
244  logger(ERROR,"Please re-run the program with % cores",numberOfRequiredProcessors);
245  }
246  else
247  {
248  std::exit(-1);
249  }
250  }
251 #endif
252  // reset counters so reading begins with the first data/fstat file
253  DPMBase* const dpm = getDPMBase();
254 
255  //define and check time limits
256  Mdouble timeMin = getTimeMin();
257  Mdouble timeMax = getTimeMax();
258  if (getDPMBase()->getTime() > timeMax)
259  {
260  logger(ERROR, "initial restart file (t=%) is beyond the maximum cg time (tMax=%)", dpm->getTime(), timeMax);
261  }
262  else
263  while (getDPMBase()->getTime() < timeMin)
264  {
265  // Remember information from this read
267 
268  cgLogger(INFO, "Skipped %, t = %, because time is below tMin = %", dpm->restartFile.getFullName(),
269  dpm->getTime(), timeMin);
270  //the particle and wall handler is cleared here, because BaseSpecies doesn't delete particles belonging to it
271  dpm->particleHandler.clear();
272  dpm->wallHandler.clear();
273  dpm->readRestartFile();
274  }
275 
276  //call initialise to set up mesh, stat files, etc
277  initialise();
278 
279  // evaluate restart files, starting with the one already read (since interactions where not read)
280  while (dpm->readRestartFile() && getDPMBase()->getTime() < timeMax)
281  {
282  cgLogger(INFO, "Read %, t=%, Np=%, Nc=%", dpm->restartFile.getFullName(), dpm->getTime(),
284 
285  //recompute contact point (necessary for old restart files)
287 
288  evaluate();
289 
290  //the particle and wall handler is cleared here, because BaseSpecies doesn't delete particles belonging to it
291  dpm->particleHandler.clear();
292  dpm->wallHandler.clear();
293 
294  //continue if the next restart file can be read and the max time has not been reached
296  logger(INFO,"Note: the evaluation is based on a single restart file. Please switch output to FileType::MULTIPLE_FILES if you want to coarse grain over multiple time steps");
297  break;
298  }
299  }
300  cgLogger(INFO, "Finished reading from %", dpm->restartFile.getFullName());
301 
302  finish();
303  dpm->dataFile.close();
304  return true;
305 }
@ ONE_FILE
all data will be written into/ read from a single file called name_
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:536
void computeContactPoints()
Definition: CGHandler.cc:179
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1453
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1499
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition: DPMBase.cc:3043
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition: File.cc:185
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
Definition: ParticleHandler.cc:971

References cgLogger, BaseHandler< T >::clear(), ParticleHandler::clear(), File::close(), computeContactPoints(), DPMBase::dataFile, ERROR, evaluate(), finish(), BaseHandler< BaseCG >::getDPMBase(), File::getFileType(), File::getFullName(), DPMBase::getNumberOfDomains(), BaseHandler< T >::getNumberOfObjects(), MPIContainer::getNumberOfProcessors(), MPIContainer::getProcessorID(), BaseHandler< T >::getSize(), DPMBase::getTime(), getTimeMax(), getTimeMin(), handlePreviousInformation(), INFO, initialise(), MPIContainer::Instance(), DPMBase::interactionHandler, logger, ONE_FILE, DPMBase::particleHandler, DPMBase::readRestartFile(), DPMBase::restartFile, and DPMBase::wallHandler.

Referenced by commandLineCG(), and restartAndEvaluateRestartFiles().

◆ finish()

void CGHandler::finish ( )

Contains the code executed after the last time step.

97 {
98  //enforce that data gets written
99  for (BaseCG* it : *this)
100  {
102  }
103  //evaluate all CG objects in the handler
104  //evaluate();
105  //finish all CG objects in the handler
106  for (BaseCG* it : *this)
107  it->finish();
108 }
const unsigned NEVER
Definition: File.h:13
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile.

References BaseCG::finish(), NEVER, File::setLastSavedTimeStep(), and BaseCG::statFile.

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::finishStatistics().

◆ getInitialFileCounter()

unsigned CGHandler::getInitialFileCounter ( ) const
inline
125  {
126  return initialFileCounter;
127  }

References initialFileCounter.

◆ getName()

std::string CGHandler::getName ( ) const
finalvirtual
Returns
a string containing the name.

Implements BaseHandler< BaseCG >.

56 {
57  return "CGHandler";
58 }

◆ getPreviousEvaluationTime()

Mdouble CGHandler::getPreviousEvaluationTime ( )
inline

Returns the time of the last read/evaluated time step.

132 { return previousEvaluationTime_; }
Mdouble previousEvaluationTime_
Saves the time of the last read/evaluated data/restartFile.
Definition: CGHandler.h:171

References previousEvaluationTime_.

Referenced by CGFields::DisplacementField::setFields().

◆ getTimeMax()

Mdouble CGHandler::getTimeMax ( )
387 {
388  Mdouble time = -constants::inf;
389  for (BaseCG* it : *this)
390  {
391  time = std::max(time, it->getTimeMax());
392  }
393  return time;
394 }
#define max(a, b)
Definition: datatypes.h:23
const Mdouble inf
Definition: GeneralDefine.h:23

References BaseCG::getTimeMax(), constants::inf, and max.

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

◆ getTimeMin()

Mdouble CGHandler::getTimeMin ( )
377 {
378  Mdouble time = constants::inf;
379  for (BaseCG* it : *this)
380  {
381  time = std::min(time, it->getTimeMin());
382  }
383  return time;
384 }
#define min(a, b)
Definition: datatypes.h:22

References BaseCG::getTimeMin(), constants::inf, and min.

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

◆ handlePreviousInformation()

void CGHandler::handlePreviousInformation ( )

Sets data from the current time step as data from the previous time step.

This is needed, so that fields like the displacementField, which rely on the previous data, can be calculated.

It calls the functions setPreviousEvaluationTimeToCurrentTime() and setPreviousPositionToCurrentPosition().

410 {
413 }
void setPreviousEvaluationTimeToCurrentTime()
Sets the previous evaluation time to the current time.
Definition: CGHandler.cc:396
void setPreviousPositionToCurrentPosition()
Sets the previous position for every particle to its current position.
Definition: CGHandler.cc:401

References setPreviousEvaluationTimeToCurrentTime(), and setPreviousPositionToCurrentPosition().

Referenced by evaluate(), evaluateDataFiles(), and evaluateRestartFiles().

◆ initialise()

void CGHandler::initialise ( )

Contains the code executed before the first time step.

71 {
72  //initialise all CG objects in the handler
73  for (BaseCG* it : *this)
74  it->initialise();
75 };
virtual void initialise()=0
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...

References BaseCG::initialise().

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::initialiseStatistics().

◆ operator=()

CGHandler & CGHandler::operator= ( const CGHandler rhs)

Assignment operator that copies the pointer to the DPMBase and all objects.

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.

28 {
29  if (this != &rhs)
30  {
31  clear();
32  setDPMBase(rhs.getDPMBase());
34  }
35  return *this;
36 #ifdef DEBUG_CONSTRUCTOR
37  std::cerr << "CGHandler::operator =(const CGHandler&) finished" << std::endl;
38 #endif
39 }
void copyContentsFromOtherHandler(const BaseHandler< BaseCG > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:348

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

◆ readAndAddObject()

void CGHandler::readAndAddObject ( std::istream &  is)
finalvirtual

Reads objects into the CGHandler from an istream (currently not implemented).

Implements BaseHandler< BaseCG >.

61 {
62 
63 }

◆ restart()

void CGHandler::restart ( std::string  name)

loads restart file, before evaluateDataFiles is run

111 {
112  DPMBase* dpm = getDPMBase();
113 
114  // determines if the variable name contains the name of a restart file, or a problem name
115  // (in which case the restart file is assumed to be name.restart)
116  std::string::size_type endName = name.find(".restart");
117  if (endName == std::string::npos)
118  {
119  dpm->setName(name);
120  }
121  else
122  {
123  dpm->setName(name.substr(0, endName));
124  dpm->restartFile.setName(name);
125  }
126 
127  // read restart file
128  cgLogger(INFO, "Reading %", dpm->restartFile.getFullName());
129 
131  {
132  // if restart file could not be read
133 
134  // invent a species if necessary
135  if (dpm->speciesHandler.getNumberOfObjects() == 0)
136  {
138  }
139 
140  // read data file
141  std::ifstream data(dpm->dataFile.getName());
142  if (data.is_open())
143  {
144  Mdouble N = 0, t = 0;
145  Vec3D min, max;
146  data >> N >> t >> min >> max;
147  data.close();
148  dpm->setDomain(min, max);
149  logger(INFO, "Reading domain size from %: min %, max % ", dpm->dataFile.getName(), min, max);
150  }
151  else
152  {
153  logger(ERROR, "Data file '%' could not be opened", dpm->dataFile.getFullName());
154  }
155 
156  //what to do if restart file could not be loaded
157  cgLogger(WARN, "Restart file could not be read. No density is specified, thus density is assumed to be 1. Provide % file if you want to specify the density.", dpm->restartFile.getName());
158  }
159  else
160  {
161  cgLogger(INFO, "Successfully restarted from %, t=%, Np=%, Nc=%", dpm->restartFile.getFullName(), dpm->getTime(),
164  }
165 }
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:11
int data[]
Definition: Map_placement_new.cpp:1
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:360
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1089
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:400
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
Definition: File.cc:143
void decreaseCounter()
Definition: File.h:128
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:176
@ N
Definition: constructor.cpp:22
string name
Definition: plotDoE.py:33
t
Definition: plotPSD.py:36

References cgLogger, BaseHandler< T >::copyAndAddObject(), data, DPMBase::dataFile, File::decreaseCounter(), ERROR, BaseHandler< BaseCG >::getDPMBase(), File::getFullName(), File::getName(), BaseHandler< T >::getNumberOfObjects(), BaseHandler< T >::getSize(), DPMBase::getTime(), INFO, DPMBase::interactionHandler, logger, max, min, N, plotDoE::name, DPMBase::particleHandler, DPMBase::ReadNoInteractions, DPMBase::readRestartFile(), DPMBase::restartFile, DPMBase::setDomain(), DPMBase::setName(), File::setName(), DPMBase::speciesHandler, plotPSD::t, and WARN.

Referenced by commandLineCG(), restartAndEvaluateDataFiles(), and restartAndEvaluateRestartFiles().

◆ restartAndEvaluateDataFiles()

void CGHandler::restartAndEvaluateDataFiles ( const std::string &  name,
bool  evaluateFStatFiles = true 
)
174 {
175  restart(name);
176  evaluateDataFiles(evaluateFStatFiles);
177 }
bool evaluateDataFiles(bool evaluateFStatFiles=true)
does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing)...
Definition: CGHandler.cc:307
void restart(std::string name)
loads restart file, before evaluateDataFiles is run
Definition: CGHandler.cc:110

References evaluateDataFiles(), plotDoE::name, and restart().

Referenced by main().

◆ restartAndEvaluateRestartFiles()

void CGHandler::restartAndEvaluateRestartFiles ( const std::string &  name)
168 {
169  restart(name);
171 }
bool evaluateRestartFiles()
Definition: CGHandler.cc:232

References evaluateRestartFiles(), plotDoE::name, and restart().

Referenced by main().

◆ setInitialFileCounter()

void CGHandler::setInitialFileCounter ( unsigned  initialFileCounter)
inline
121  {
122  this->initialFileCounter = initialFileCounter;
123  }

References initialFileCounter.

Referenced by commandLineCG().

◆ setPreviousEvaluationTime()

void CGHandler::setPreviousEvaluationTime ( Mdouble  time)
inline

Sets the time of the last read/evaluated time step to a specified time.

137 { previousEvaluationTime_= time; }

References previousEvaluationTime_.

◆ setPreviousEvaluationTimeToCurrentTime()

void CGHandler::setPreviousEvaluationTimeToCurrentTime ( )

Sets the previous evaluation time to the current time.

This is needed, so that fields like the displacementField, which rely on the previous evaluation time, can be calculated.

397 {
399 }

References BaseHandler< BaseCG >::getDPMBase(), DPMBase::getTime(), and previousEvaluationTime_.

Referenced by handlePreviousInformation().

◆ setPreviousPositionToCurrentPosition()

void CGHandler::setPreviousPositionToCurrentPosition ( )

Sets the previous position for every particle to its current position.

This is needed, so that fields like the displacementField, which rely on the previous particle position, can be calculated.

402 {
403  for (BaseParticle* p : getDPMBase()->particleHandler)
404  {
405  p->setPreviousPosition(p->getPosition());
406  }
407 }

References BaseHandler< BaseCG >::getDPMBase(), and p.

Referenced by handlePreviousInformation().

◆ write()

void CGHandler::write ( std::ostream &  os) const

Writes objects into the CGHandler to an ostream (currently not implemented).

66 {
67 
68 }

Member Data Documentation

◆ initialFileCounter

unsigned CGHandler::initialFileCounter = 0

◆ previousEvaluationTime_

Mdouble CGHandler::previousEvaluationTime_ = 0
private

Saves the time of the last read/evaluated data/restartFile.

This counter is used to calculate displacement fields.

Referenced by getPreviousEvaluationTime(), setPreviousEvaluationTime(), and setPreviousEvaluationTimeToCurrentTime().


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