revision: v0.14
BaseCG.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef BaseCG_H
27 #define BaseCG_H
28 
29 #include <cstdlib>
30 #include <functional>
31 #include "GeneralDefine.h"
32 #include "BaseObject.h"
33 #include "File.h"
34 #include "Math/Vector.h"
35 
36 class CGHandler;
37 
38 class BaseInteractable;
39 
56 class BaseCG : public BaseObject
57 {
58 public:
59 
63  BaseCG();
64 
68  BaseCG(const BaseCG& p) = default;
69 
73  ~BaseCG() override = default;
74 
79  void read(std::istream& is) override;
80 
84  void write(std::ostream& os) const override;
85 
90  void clear();
91 
95  virtual BaseCG* copy() const = 0;
96 
101  virtual void initialise() = 0;
102 
107  virtual void evaluate() = 0;
108 
113  virtual void finish() = 0;
114 
118  void setHandler(CGHandler* handler);
119 
123  CGHandler* getHandler() const;
124 
129  virtual void setWidth(Mdouble width)=0;
130 
134  virtual Mdouble getWidth() const =0;
135 
139  void setNZ(std::size_t nZ);
140 
144  std::size_t getNZ() const;
145 
149  void setNY(std::size_t nY);
150 
154  std::size_t getNY() const;
155 
159  void setNX(std::size_t nX);
160 
164  std::size_t getNX() const;
165 
169  void setN(std::size_t n);
170 
174  void setN(std::array<std::size_t, 3> n);
175 
180  void setH(Mdouble h);
181 
186  void setHX(Mdouble h);
187 
192  void setHY(Mdouble h);
193 
198  void setHZ(Mdouble h);
199 
203  void setTimeMin(Mdouble timeMin);
204 
208  void setTimeMax(Mdouble timeMax);
209 
213  Mdouble getTimeMin() const;
214 
218  Mdouble getTimeMax() const;
219 
223  void setMin(Vec3D min);
224 
228  void setX(Mdouble min, Mdouble max);
229 
233  void setY(Mdouble min, Mdouble max);
234 
238  void setZ(Mdouble min, Mdouble max);
239 
240  void setXGrid(Mdouble min, Mdouble max, Mdouble h);
241 
242  void setYGrid(Mdouble min, Mdouble max, Mdouble h);
243 
244  void setZGrid(Mdouble min, Mdouble max, Mdouble h);
245 
246  void setGrid(Vec3D min, Vec3D max, Mdouble h);
247 
251  void setMax(Vec3D max);
252 
256  Vec3D getMin() const;
257 
261  Vec3D getMax() const;
262 
267  void selectSpecies(unsigned speciesIndex);
268 
269  void setSelectedParticle(const std::function<const bool(const BaseInteractable*)>& selectedParticle);
270 
271  void setEps(Mdouble eps);
272 
273  Mdouble getEps() const;
274 
275  void setAverageBeyondDomain(const bool val) {averageBeyondDomain_=val;}
276 
278  /*
279  * Sets width such that the CG function has a fixed standard deviation
280  * See CGStandardDeviationUnitTest.
281  */
282  virtual void setStandardDeviation(Mdouble std) = 0;
283 
284  /*
285  * Sets width such that the CG function has the same standard deviation as a spherical cg function.
286  * See CGStandardDeviationUnitTest.
287  */
288  virtual void setRadius(Mdouble radius) = 0;
289 
290 protected:
291 
296 
304  std::size_t nX_;
305 
309  std::size_t nY_;
310 
314  std::size_t nZ_;
315 
321 
329 
334 
341 
346 
350  std::function<bool(const BaseInteractable*)> selectedParticle_;
351 
363  bool averageBeyondDomain_ = true;
364 
365 public:
370 };
371 
372 #endif
BaseCG::getNZ
std::size_t getNZ() const
Returns nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:106
BaseCG::setNZ
void setNZ(std::size_t nZ)
Sets nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:101
CGHandler
Container that stores all CG objects.
Definition: CGHandler.h:65
Vector.h
BaseCG::setN
void setN(std::size_t n)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction.
Definition: BaseCG.cc:131
BaseCG::setEps
void setEps(Mdouble eps)
Definition: BaseCG.cc:91
BaseObject::getName
virtual std::string getName() const =0
A purely virtual function.
BaseCG::finish
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile.
BaseCG::getAverageBeyondDomain
bool getAverageBeyondDomain() const
Definition: BaseCG.h:277
BaseCG::setHandler
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:72
BaseCG::setH
void setH(Mdouble h)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction....
Definition: BaseCG.cc:241
logger
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
BaseCG::setRadius
virtual void setRadius(Mdouble radius)=0
BaseCG::evaluate
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields.
Vec3D::X
Mdouble X
the vector components
Definition: Vector.h:65
BaseCG::read
void read(std::istream &is) override
Currently, no read functions are implemented for the CGHandler, but the function is required for any ...
Definition: BaseCG.cc:52
BaseCG::getMin
Vec3D getMin() const
Returns min_, the lower limit of the spatial domain.
Definition: BaseCG.cc:155
BaseCG::setNY
void setNY(std::size_t nY)
Sets nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:111
BaseCG::setWidth
virtual void setWidth(Mdouble width)=0
Sets width_, the coarse-graining width.
BaseCG::setHX
void setHX(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:249
BaseCG::getTimeMax
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:180
BaseObject.h
BaseCG::getNY
std::size_t getNY() const
Returns nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:116
BaseCG::eps_
Mdouble eps_
Definition: BaseCG.h:320
INFO
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
BaseCG::getNX
std::size_t getNX() const
Returns nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:126
BaseCG::BaseCG
BaseCG()
Simple constructor, sets default values.
Definition: BaseCG.cc:29
BaseInteractable
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
BaseCG::averageBeyondDomain_
bool averageBeyondDomain_
Determines whether particles outside the domain are considered when computing the averaged fields.
Definition: BaseCG.h:363
BaseCG::copy
virtual BaseCG * copy() const =0
Copy operator. Required for BaseHandler::copyAndAddObject.
Vec3D
Definition: Vector.h:50
bool
BaseCG::setAverageBeyondDomain
void setAverageBeyondDomain(const bool val)
Definition: BaseCG.h:275
BaseCG::setMax
void setMax(Vec3D max)
Sets max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:170
BaseCG::setNX
void setNX(std::size_t nX)
Sets nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:121
File
Definition: File.h:81
BaseCG::setXGrid
void setXGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:203
BaseCG::min_
Vec3D min_
Definition: BaseCG.h:340
BaseCG::setTimeMax
void setTimeMax(Mdouble timeMax)
Sets timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:150
double
BaseCG::setStandardDeviation
virtual void setStandardDeviation(Mdouble std)=0
BaseCG::setZGrid
void setZGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:215
BaseCG::getMax
Vec3D getMax() const
Returns max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:160
WARN
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
Log::FATAL
@ FATAL
BaseCG::setY
void setY(Mdouble min, Mdouble max)
Sets min_.Y, max_.Y, the limits of the spatial domain in Y.
Definition: BaseCG.cc:191
BaseCG::~BaseCG
~BaseCG() override=default
Default destructor, does nothing.
BaseCG.h
BaseCG::statFile
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:369
BaseCG::clear
void clear()
This class seems to have no use (?), but is required for any derivative of BaseObject.
Definition: BaseCG.cc:46
DPMBase.h
BaseCG::selectedParticle_
std::function< bool(const BaseInteractable *)> selectedParticle_
Definition: BaseCG.h:350
BaseCG::setMin
void setMin(Vec3D min)
Sets max_, the lower limit of the spatial domain.
Definition: BaseCG.cc:165
BaseCG::nY_
std::size_t nY_
Definition: BaseCG.h:309
File::setLastSavedTimeStep
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:302
BaseCG::initialise
virtual void initialise()=0
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...
Vec3D::Y
Mdouble Y
Definition: Vector.h:65
BaseCG::handler_
CGHandler * handler_
Definition: BaseCG.h:295
BaseCG::nX_
std::size_t nX_
Definition: BaseCG.h:304
NEVER
const unsigned NEVER
Definition: File.h:35
BaseCG::setHY
void setHY(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:258
BaseCG::getEps
Mdouble getEps() const
Definition: BaseCG.cc:96
BaseObject
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:51
BaseCG::setTimeMin
void setTimeMin(Mdouble timeMin)
Sets timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:145
BaseCG::getWidth
virtual Mdouble getWidth() const =0
Returns width_, the coarse-graining width.
BaseCG::max_
Vec3D max_
Definition: BaseCG.h:345
GeneralDefine.h
BaseCG::setGrid
void setGrid(Vec3D min, Vec3D max, Mdouble h)
Definition: BaseCG.cc:221
UNUSED
#define UNUSED
Definition: GeneralDefine.h:39
BaseCG::timeMin_
Mdouble timeMin_
Definition: BaseCG.h:328
n
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
BaseCG::setZ
void setZ(Mdouble min, Mdouble max)
Sets min_.Z, max_.Z, the limits of the spatial domain in Z.
Definition: BaseCG.cc:197
BaseCG::setHZ
void setHZ(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:267
BaseCG::setX
void setX(Mdouble min, Mdouble max)
Sets min_.X, max_.X, the limits of the spatial domain in X.
Definition: BaseCG.cc:185
BaseCG::getHandler
CGHandler * getHandler() const
Returns handler_, a pointer to the CGHandler.
Definition: BaseCG.cc:80
BaseCG::setYGrid
void setYGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:209
BaseCG::BaseCG
BaseCG(const BaseCG &p)=default
Default copy constructor, copies all values.
Vec3D::Z
Mdouble Z
Definition: Vector.h:65
BaseCG::setSelectedParticle
void setSelectedParticle(const std::function< const bool(const BaseInteractable *)> &selectedParticle)
Definition: BaseCG.cc:236
BaseCG::write
void write(std::ostream &os) const override
Writes class content into an output stream, usually a stat file.
Definition: BaseCG.cc:59
File::getFstream
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:153
BaseCG::timeMax_
Mdouble timeMax_
Definition: BaseCG.h:333
BaseCG::selectSpecies
void selectSpecies(unsigned speciesIndex)
Definition: BaseCG.cc:228
constants::inf
const Mdouble inf
Definition: GeneralDefine.h:44
File.h
BaseCG
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:57
BaseCG::getTimeMin
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:175
BaseCG::nZ_
std::size_t nZ_
Definition: BaseCG.h:314