CG.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 CG_H
27 #define CG_H
28 
29 #include "CG/BaseCG.h"
30 #include <vector>
31 
32 class CGHandler;
33 
34 class Function;
35 
36 class BaseParticle;
37 
38 class BaseInteraction;
39 
40 #include "CG/CGPoint.h"
41 #include "DPMBase.h"
42 #include "CG/CGHandler.h"
44 #include "Logger.h"
45 #include "CG/Functions/Lucy.h"
46 #include "CG/Functions/Heaviside.h"
47 
72 template<class Coordinates = CGCoordinates::O,
73  template<class> class BaseFunction=CGFunctions::Lucy,
74  class Fields=CGFields::StandardFields>
75 class CG : public BaseCG
76 {
77 public:
84  typedef BaseFunction<Coordinates> Function;
86 
91  CG() = default;
92 
96  CG(Mdouble width, unsigned n);
97 
101  CG(const CG& p) = default;
102 
106  virtual ~CG() = default;
107 
112 
116  void write(std::ostream& os) const override;
117 
122  void writeAll(std::ostream& os) const;
123 
127  std::string getName() const override;
128 
133  void initialise() override;
134 
138  virtual void createMesh();
139 
144  void evaluate() override;
145 
150 
155 
156  void evaluateParticleAtPoint(Fields& currentInteraction, const BaseParticle& p, Point& r);
157 
165 
173 
175 
180  void finish() override;
181 
182  const Point& getPoint(size_t i) const
183  {
184  return points_[i];
185  }
186 
187  const std::vector<Point>& getPoints() const
188  {
189  return points_;
190  }
191 
193  {
194  return function_;
195  }
196 
197  void setStandardDeviation(Mdouble std) override
198  {
199  function_.setStandardDeviation(std);
200  }
201 
202  void setRadius(Mdouble radius) override
203  {
204  if (std::is_base_of<CGCoordinates::Base_X_Y_Z, Coordinates>::value)
205  {
206  function_.setStandardDeviation(radius * sqrt(.2));
207  }
208  else if (std::is_base_of<CGCoordinates::Base_XY_XZ_YZ, Coordinates>::value)
209  {
210  function_.setStandardDeviation(radius * sqrt(.4));
211  }
212  else /*XYZ*/ {
213  function_.setStandardDeviation(radius * sqrt(.6));
214  }
215  }
216 
220  void setWidth(Mdouble width) override
221  {
222  function_.setWidth(width);
223  }
224 
228  Mdouble getWidth() const override
229  {
230  return function_.getWidth();
231  }
232 
233 protected:
234 
239 
244 
249 
254 
259 
260 protected:
261 
266  std::vector<Point> points_;
267 
269 
270 
271 };
272 
273 #include "CG/CG.hcc"
274 
275 #endif
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
IntegralType
Specifies the two points between which a line integral is computed.
Definition: IntegralType.h:34
@ O
Definition: StatisticsVector.h:42
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:57
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
Definition: BaseParticle.h:54
Contains the computed field values, like density, momentum and stress.
Definition: StandardFields.h:51
A specialisation of Polynomials for PolynomialType::Lucy. See Polynomial for details.
Definition: Lucy.h:39
Container that stores all CG objects.
Definition: CGHandler.h:65
Combines the position of the CGPoint (e.g. x, y, z), the parameters of the coarse-graining function (...
Definition: CGPoint.h:44
Evaluates time-resolved continuum fields and writes the data into a stat file.
Definition: CG.h:76
void evaluateParticle(const BaseParticle &p)
Contains the basic for loop over all CGPoints, required to do particle statistics.
Function & getFunction()
Definition: CG.h:192
virtual void createMesh()
Creates spatial mesh of CGPoints, the points where the CG-variables are evaluated.
std::string getName() const override
returns the name of the class, which is required by write.
const std::vector< Point > & getPoints() const
Definition: CG.h:187
void evaluateCommon()
The part of evaluate that is used for CG, timeAveragedCG and timeSmoothedCG.
BaseFunction< Coordinates > Function
Because of this typedefs, Point can be used instead of CGPoint<Function> and Function can be used ins...
Definition: CG.h:84
void resetVariables()
set all variables to zero
Point evaluateTotal()
Computes the total value (integrated over space) for each field.
void setStandardDeviation(Mdouble std) override
Definition: CG.h:197
virtual ~CG()=default
Default destructor; does nothing.
void write(std::ostream &os) const override
Writes class content, except for the points, into an output stream.
void evaluateParticleAtPoint(Fields &currentInteraction, const BaseParticle &p, Point &r)
Function function_
Definition: CG.h:268
CGPoint< Coordinates, Fields > Point
Definition: CG.h:85
void evaluateContact(const BaseInteraction &i)
Contains the basic for loop over all CGPoints, required to do contact statistics.
void writeVariables()
write variables to the stat file
CG(const CG &p)=default
Default copy Constructor; copies all member variables.
std::vector< Point > points_
Contains the CGPoint's, i.e. the positions at which the StandardFields are evaluated.
Definition: CG.h:266
void initialise() override
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...
void evaluate() override
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields.
const Point & getPoint(size_t i) const
Definition: CG.h:182
CG()=default
Default constructor; does nothing, i.e. no points are created initially.
void writeAll(std::ostream &os) const
Writes class content, including the points_, into an output stream, usually a stat file.
IntegralType getIntegralType(const BaseInteraction &c)
Mdouble getWidth() const override
Definition: CG.h:228
void volumeAverageVariables()
divide each variable by the domain volume
void setWidth(Mdouble width) override
Definition: CG.h:220
void setRadius(Mdouble radius) override
Definition: CG.h:202
Point evaluateAverage()
Computes the spatially-averaged value for each field.
void finish() override
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile.
void outputSumOfVariables()
plot total to console
CG(Mdouble width, unsigned n)
CG< Coordinates, BaseFunction, Fields > * copy() const override
Copy operator; creates a new'ed CG object.
Template argument; use a member class of CGCoordinates to instantiate.
Template argument; use a member class of CGFunctions to instantiate.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51