BaseCG.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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  void setVerbose(const bool verbose) {verbose_=verbose;}
280 
281  bool getVerbose() const {return verbose_;}
282 
283  /*
284  * Sets width such that the CG function has a fixed standard deviation
285  * See CGStandardDeviationUnitTest.
286  */
287  virtual void setStandardDeviation(Mdouble std) = 0;
288 
289  /*
290  * Sets width such that the CG function has the same standard deviation as a spherical cg function.
291  * See CGStandardDeviationUnitTest.
292  */
293  virtual void setRadius(Mdouble radius) = 0;
294 
295 protected:
296 
301 
309  std::size_t nX_;
310 
314  std::size_t nY_;
315 
319  std::size_t nZ_;
320 
326 
334 
339 
346 
351 
355  std::function<bool(const BaseInteractable*)> selectedParticle_;
356 
368  bool averageBeyondDomain_ = true;
369 
370  bool verbose_ = false;
371 
372 public:
377 };
378 
379 #endif
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:57
virtual Mdouble getWidth() const =0
Returns width_, the coarse-graining width.
void setHX(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:250
void setNY(std::size_t nY)
Sets nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:112
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:181
~BaseCG() override=default
Default destructor, does nothing.
void setMax(Vec3D max)
Sets max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:171
void setVerbose(const bool verbose)
Definition: BaseCG.h:279
bool averageBeyondDomain_
Determines whether particles outside the domain are considered when computing the averaged fields.
Definition: BaseCG.h:368
BaseCG(const BaseCG &p)=default
Default copy constructor, copies all values.
void setSelectedParticle(const std::function< const bool(const BaseInteractable *)> &selectedParticle)
Definition: BaseCG.cc:237
Mdouble timeMin_
Definition: BaseCG.h:333
void setZ(Mdouble min, Mdouble max)
Sets min_.Z, max_.Z, the limits of the spatial domain in Z.
Definition: BaseCG.cc:198
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:376
void setNX(std::size_t nX)
Sets nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:122
std::size_t getNY() const
Returns nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:117
Mdouble getEps() const
Definition: BaseCG.cc:97
void setHY(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:259
void setYGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:210
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:73
virtual void setWidth(Mdouble width)=0
Sets width_, the coarse-graining width.
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields.
std::size_t nY_
Definition: BaseCG.h:314
void clear()
This class seems to have no use (?), but is required for any derivative of BaseObject.
Definition: BaseCG.cc:46
Vec3D min_
Definition: BaseCG.h:345
Mdouble eps_
Definition: BaseCG.h:325
BaseCG()
Simple constructor, sets default values.
Definition: BaseCG.cc:29
void setTimeMin(Mdouble timeMin)
Sets timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:146
void setX(Mdouble min, Mdouble max)
Sets min_.X, max_.X, the limits of the spatial domain in X.
Definition: BaseCG.cc:186
void setH(Mdouble h)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction....
Definition: BaseCG.cc:242
CGHandler * getHandler() const
Returns handler_, a pointer to the CGHandler.
Definition: BaseCG.cc:81
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile.
void setAverageBeyondDomain(const bool val)
Definition: BaseCG.h:275
std::function< bool(const BaseInteractable *)> selectedParticle_
Definition: BaseCG.h:355
Vec3D getMin() const
Returns min_, the lower limit of the spatial domain.
Definition: BaseCG.cc:156
void setXGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:204
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:176
void setEps(Mdouble eps)
Definition: BaseCG.cc:92
std::size_t nZ_
Definition: BaseCG.h:319
void write(std::ostream &os) const override
Writes class content into an output stream, usually a stat file.
Definition: BaseCG.cc:59
void setMin(Vec3D min)
Sets max_, the lower limit of the spatial domain.
Definition: BaseCG.cc:166
virtual void initialise()=0
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...
void setZGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:216
void selectSpecies(unsigned speciesIndex)
Definition: BaseCG.cc:229
virtual void setRadius(Mdouble radius)=0
bool getVerbose() const
Definition: BaseCG.h:281
void setNZ(std::size_t nZ)
Sets nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:102
virtual BaseCG * copy() const =0
Copy operator. Required for BaseHandler::copyAndAddObject.
std::size_t getNZ() const
Returns nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:107
void setTimeMax(Mdouble timeMax)
Sets timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:151
void setGrid(Vec3D min, Vec3D max, Mdouble h)
Definition: BaseCG.cc:222
void setN(std::size_t n)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction.
Definition: BaseCG.cc:132
std::size_t nX_
Definition: BaseCG.h:309
std::size_t getNX() const
Returns nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:127
Mdouble timeMax_
Definition: BaseCG.h:338
CGHandler * handler_
Definition: BaseCG.h:300
void setHZ(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX,...
Definition: BaseCG.cc:268
bool verbose_
Definition: BaseCG.h:370
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
virtual void setStandardDeviation(Mdouble std)=0
bool getAverageBeyondDomain() const
Definition: BaseCG.h:277
Vec3D max_
Definition: BaseCG.h:350
Vec3D getMax() const
Returns max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:161
void setY(Mdouble min, Mdouble max)
Sets min_.Y, max_.Y, the limits of the spatial domain in Y.
Definition: BaseCG.cc:192
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:51
Container that stores all CG objects.
Definition: CGHandler.h:65
Definition: File.h:81
Definition: Vector.h:51
bool verbose
Definition: statXZ.cpp:28