MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
Container that stores all CG objects.
Definition: CGHandler.h:64
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields...
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:180
std::size_t getNX() const
Returns nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:126
void selectSpecies(unsigned speciesIndex)
Definition: BaseCG.cc:228
void write(std::ostream &os) const override
Writes class content into an output stream, usually a stat file.
Definition: BaseCG.cc:59
CGHandler * getHandler() const
Returns handler_, a pointer to the CGHandler.
Definition: BaseCG.cc:80
Mdouble timeMax_
Definition: BaseCG.h:333
virtual void setWidth(Mdouble width)=0
Sets width_, the coarse-graining width.
double Mdouble
Definition: GeneralDefine.h:34
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:50
std::size_t getNY() const
Returns nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:116
void setTimeMax(Mdouble timeMax)
Sets timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:150
void setXGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:203
void setNZ(std::size_t nZ)
Sets nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:101
void setN(std::size_t n)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction.
Definition: BaseCG.cc:131
void setEps(Mdouble eps)
Definition: BaseCG.cc:91
Vec3D getMin() const
Returns min_, the lower limit of the spatial domain.
Definition: BaseCG.cc:155
virtual void setStandardDeviation(Mdouble std)=0
~BaseCG() override=default
Default destructor, does nothing.
void setY(Mdouble min, Mdouble max)
Sets min_.Y, max_.Y, the limits of the spatial domain in Y.
Definition: BaseCG.cc:191
Vec3D getMax() const
Returns max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:160
void clear()
This class seems to have no use (?), but is required for any derivative of BaseObject.
Definition: BaseCG.cc:46
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
std::function< bool(const BaseInteractable *)> selectedParticle_
Definition: BaseCG.h:350
std::size_t getNZ() const
Returns nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:106
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
Mdouble eps_
Definition: BaseCG.h:320
void setNY(std::size_t nY)
Sets nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:111
BaseCG()
Simple constructor, sets default values.
Definition: BaseCG.cc:29
void setAverageBeyondDomain(const bool val)
Definition: BaseCG.h:275
void setNX(std::size_t nX)
Sets nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:121
bool averageBeyondDomain_
Determines whether particles outside the domain are considered when computing the averaged fields...
Definition: BaseCG.h:363
virtual BaseCG * copy() const =0
Copy operator. Required for BaseHandler::copyAndAddObject.
void setMax(Vec3D max)
Sets max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:170
void setGrid(Vec3D min, Vec3D max, Mdouble h)
Definition: BaseCG.cc:221
Vec3D min_
Definition: BaseCG.h:340
void setSelectedParticle(const std::function< const bool(const BaseInteractable *)> &selectedParticle)
Definition: BaseCG.cc:236
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
void setX(Mdouble min, Mdouble max)
Sets min_.X, max_.X, the limits of the spatial domain in X.
Definition: BaseCG.cc:185
void setYGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:209
void setZGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:215
Mdouble getEps() const
Definition: BaseCG.cc:96
void setMin(Vec3D min)
Sets max_, the lower limit of the spatial domain.
Definition: BaseCG.cc:165
std::size_t nY_
Definition: BaseCG.h:309
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:369
std::size_t nZ_
Definition: BaseCG.h:314
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
bool getAverageBeyondDomain() const
Definition: BaseCG.h:277
Defines the basic properties that a interactable object can have.
virtual void initialise()=0
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...
CGHandler * handler_
Definition: BaseCG.h:295
std::size_t nX_
Definition: BaseCG.h:304
Definition: Vector.h:49
virtual Mdouble getWidth() const =0
Returns width_, the coarse-graining width.
Definition: File.h:80
void setTimeMin(Mdouble timeMin)
Sets timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:145
Mdouble timeMin_
Definition: BaseCG.h:328
Vec3D max_
Definition: BaseCG.h:345
void setZ(Mdouble min, Mdouble max)
Sets min_.Z, max_.Z, the limits of the spatial domain in Z.
Definition: BaseCG.cc:197
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile...
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:175
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:72
void setH(Mdouble h)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction. However, instead of explicitly defining n, the mesh size h=(max-min)/n is defined.
Definition: BaseCG.cc:241
virtual void setRadius(Mdouble radius)=0