MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StatisticsVector.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 FSTAT_H
27 #define FSTAT_H
28 #include "MD.h"
29 #include "MatrixSymmetric.h"
30 #include <string.h>
31 #include <fstream>
32 #include <math.h>
34 enum StatType {O, X, Y, Z, XY, XZ, YZ, XYZ, RAZ, RZ, AZ, RA, R, A};
35 #include "Polynomial.h"
36 #include "StatisticsPoint.h"
37 
47 template <StatType T>
48 class StatisticsVector : public virtual MD
49 {
50 public:
52  void constructor();
53  void constructor(std::string name);
54 
57  StatisticsVector(std::string name) {constructor(name);}
58 
61 
63  StatisticsVector(unsigned int argc, char *argv[]);
64  void readStatArguments(unsigned int argc, char *argv[]);
65 
67  std::string print();
68 
69  void set_statType();
70 
71  void print_help();
72 
73  //set functions should be called before executing the statistical routine
74  void set_nx(int new_) { nx = new_;};
75  void set_hx(Mdouble hx) { set_nx( ceil((get_xmaxStat()-get_xminStat())/hx) ); };
76  void set_ny(int new_) { ny = new_;};
77  void set_hy(Mdouble hy) { set_ny( ceil((get_ymaxStat()-get_yminStat())/hy) ); };
78  void set_nz(int new_) { nz = new_; if (get_dim()<3) std::cerr << "Warning in set_nz: dimension less than 3"<<std::endl; };
79  void set_hz(Mdouble hz) { set_nz( ceil((get_zmaxStat()-get_zminStat())/hz) ); };
80  void set_n(int n) { set_nx(n); set_ny(n); set_nz(n); };
81  void set_h(Mdouble h) { set_hx(h); set_hy(h); set_hz(h);};
82  int get_nx() {return nx;};
83  int get_ny() {return ny;};
84  int get_nz() {return nz;};
89  Mdouble get_tmaxStat() {if(std::isnan(tmaxStat)) return get_tmax(); else return tmaxStat;};
92 
93  void set_CG_type(const char* new_);
94  void set_CG_type(CG new_);
95  CG get_CG_type() {return CG_type;};
96 
97  void set_n(int nx_, int ny_, int nz_) {nx=nx_; ny=ny_; nz=nz_;};
98  void get_n(int& nx_, int& ny_, int& nz_) {nx_=nx; ny_=ny; nz_=nz;};
99 
101  void set_w(Mdouble w) {set_w2(sqr(w));};
102 
104  void set_w2(Mdouble new_);
105 
106  Mdouble get_w() {return sqrt(w2);};
107  Mdouble get_w2() {return w2;};
108  Mdouble get_cutoff() {return cutoff;};
110 
111  //~ bool get_boundedDomain() {return boundedDomain;};
112  //~ void set_boundedDomain(bool new_) {boundedDomain=new_;};
113 
115  std::string print_CG();
116 
119 
121  virtual void reset_statistics();
122 
125  void statistics_from_p3();
126  void jump_p3c();
127 
128  void set_doTimeAverage(bool new_) {doTimeAverage = new_;};
130 
133 
134  // to keep compatible with older versions
136 
139 
140  void set_doVariance(bool new_) {doVariance = new_;};
141  bool get_doVariance() {return doVariance;};
142 
143  void set_doGradient(bool new_) {doGradient = new_;};
144  bool get_doGradient() {return doGradient;};
145 
146  void set_superexact(bool new_) {superexact = new_;};
147  bool get_superexact() {return superexact;};
148 
151 
152  void verbose() {verbosity = 2;};
153  void set_verbosity(int new_) {verbosity = new_;};
154  int get_verbosity() {return verbosity;};
155 
156  void set_walls(bool new_) {walls = new_;};
157  bool get_walls() {return walls;};
158 
159  void set_periodicWalls(bool new_) {periodicWalls = new_;};
161 
162  void set_w_over_rmax(Mdouble new_) {w_over_rmax = new_;};
164 
166  void set_Positions();
167 
168  bool read_next_from_data_file (unsigned int format);
169 
171  void gather_force_statistics_from_p3c(int version);
172  void gather_force_statistics_from_p3w(int version, std::vector<int>& index);
173  void evaluate_force_statistics(int wp=0);
174  void evaluate_wall_force_statistics(Vec3D P, int wp=0);
175  void jump_fstat();
176 
178  void initialize_statistics();
179 
181  void output_statistics();
183  void gather_statistics_collision(int index1,int index2, Vec3D Contact, Mdouble delta, Mdouble ctheta, Mdouble fdotn, Mdouble fdott, Vec3D P1_P2_normal_, Vec3D P1_P2_tangential);
185  void process_statistics(bool usethese);
187  void finish_statistics();
188 
190  void write_statistics();
193 
195  void evaluate_particle_statistics(std::vector<BaseParticle*>::iterator P, int wp=0);
196 
197  std::vector<StatisticsPoint<T> > get_Points(){return Points;};
198 
200  Mdouble get_xminStat() {if(std::isnan(xminStat)) return get_xmin(); else return xminStat;};
201  Mdouble get_yminStat() {if(std::isnan(yminStat)) return get_ymin(); else return yminStat;};
202  Mdouble get_zminStat() {if(std::isnan(zminStat)) return get_zmin(); else return zminStat;};
203  Mdouble get_xmaxStat() {if(std::isnan(xmaxStat)) return get_xmax(); else return xmaxStat;};
204  Mdouble get_ymaxStat() {if(std::isnan(ymaxStat)) return get_ymax(); else return ymaxStat;};
205  Mdouble get_zmaxStat() {if(std::isnan(zmaxStat)) return get_zmax(); else return zmaxStat;};
206  void set_xminStat(Mdouble xminStat_){xminStat=xminStat_;};
207  void set_yminStat(Mdouble yminStat_){yminStat=yminStat_;};
208  void set_zminStat(Mdouble zminStat_){zminStat=zminStat_;};
209  void set_xmaxStat(Mdouble xmaxStat_){xmaxStat=xmaxStat_;};
210  void set_ymaxStat(Mdouble ymaxStat_){ymaxStat=ymaxStat_;};
211  void set_zmaxStat(Mdouble zmaxStat_){zmaxStat=zmaxStat_;};
213 
215 
216  void set_Polynomial(std::vector<Mdouble> new_coefficients, unsigned int new_dim) {
217  CGPolynomial.set_polynomial(new_coefficients, new_dim);
218  }
219 
220  void set_Polynomial(Mdouble* new_coefficients, unsigned int num_coeff, unsigned int new_dim) {
221  CGPolynomial.set_polynomial(new_coefficients, num_coeff, new_dim);
222  }
223 
224  void set_PolynomialName(const char* new_name) {
225  CGPolynomial.set_name(new_name);
226  }
227 
228  std::string get_PolynomialName() {
229  return CGPolynomial.get_name();
230  }
231 
232  void set_doublePoints(bool new_) {doublePoints=new_;}
233 
235 
237 
239 
240  void set_rmin(Mdouble new_) {rmin=new_;}
241  void set_rmax(Mdouble new_) {rmax=new_;}
242  void set_hmax(Mdouble new_) {hmax=new_;}
243 
245  return CGPolynomial.evaluate(r);
246  }
247 
249  return CGPolynomial.evaluateGradient(r);
250  }
251 
253  return CGPolynomial.evaluateIntegral(n1,n2,t);
254  }
255 
256 
257 //Member Variables
258 protected:
259 
260  //General Variables
264  int nx;
266  int ny;
268  int nz;
274 
275  //Storage of points and gradients
277  std::vector<StatisticsPoint<T> > Points;
279  std::vector<StatisticsPoint<T> > dx;
281  std::vector<StatisticsPoint<T> > dy;
283  std::vector<StatisticsPoint<T> > dz;
284 
285  //For time averaging
287  std::vector<StatisticsPoint<T> > timeAverage;
289  std::vector<StatisticsPoint<T> > timeVariance;
291  std::vector<StatisticsPoint<T> > dxTimeAverage;
293  std::vector<StatisticsPoint<T> > dyTimeAverage;
295  std::vector<StatisticsPoint<T> > dzTimeAverage;
306 
307  //Coarse graining variables
312  // ///<if true, then the course-graining function will be cut at the domain boundaries and resized to satisfy int(W) = 1
313  // bool boundedDomain;
320 
321  //Options that can be set before evaluation
322 
339  bool walls;
353 
354  int verbosity; //<Determines how much is outputted to the terminal
355  int format; //< format of the data input file
356  Mdouble mirrorAtDomainBoundary; //< 0: Statistics near the wall are equal to statistics away from the wall; 1: Statistics are mirrored at the domain boundaries; up to a maximum depth specified by this number
357 
358  bool isMDCLR;
360  bool superexact;
361 
362  //uses close points to allow calculation of gradients
364 
366 
367 
368  //Variables communicate values between member functions #evaluate_force_statistics and #gather_statistics_collision)used to communicate values between member functions evaluate_force_statistics and gather_force_statistics
396 
397  bool loadVelocityProfile (const char* filename);
398  Vec3D getVelocityProfile (Vec3D Position);
399 
400  std::vector<Vec3D> VelocityProfile;
403 
404  std::fstream p3p_file;
405  std::fstream p3c_file;
406  std::fstream p3w_file;
407  bool read_next_from_p3p_file ();
408  void auto_setdim ();
409 
410 
411 
412 };
413 
414 #include "StatisticsPoint.hcc"
415 #include "StatisticsVector.hcc"
416 
417 #endif
void set_hx(Mdouble hx)
StatisticsVector()
Basic constructor only calls constructor()
bool periodicWalls
Turns off periodic walls before evaluation (needed for averaging, because we do not yet check if part...
void set_TimeAverageReset(int new_)
bool read_next_from_data_file(unsigned int format)
StatisticsPoint< T > average(std::vector< StatisticsPoint< T > > &P)
Output average of statistical variables.
void initialize_statistics()
Initializes statistics, i.e. setting w2, setting the grid and writing the header lines in the ...
Mdouble get_zmin()
Gets zmin.
Definition: MD.h:313
void gather_force_statistics_from_fstat_and_data()
get force statistics from particle collisions
std::vector< StatisticsPoint< T > > dyTimeAverage
a vector used to sum up all statistical gradients in dy for time-averaging
void output_statistics()
Calculates statistics for Particles (i.e. not collisions)
Vec3D P2
Position of second contact point.
void finish_statistics()
Finish all statistics (i.e. write out final data)
Mdouble get_tminStat()
bool walls
Turns off walls before evaluation.
StatType statType
Possible values X,Y,Z,XY,XZ,YZ,XYZ,RAZ,RA,RZ,AZ,R,A are used to determine if the statistics are avera...
bool check_current_time_for_statistics()
Vec3D P1_P2_TangentialTraction
Traction from tangential forces at contact of flow with fixed particles or walls. ...
StatType
Creates averaged statistics (only valid if density field is homogenous along averaged direction) ...
void write_time_average_statistics()
Writes out time averaged statistics.
void set_yminStat(Mdouble yminStat_)
int get_StressTypeForFixedParticles()
Mdouble evaluatePolynomialGradient(Mdouble r)
bool satisfiesInclusionCriteria(BaseParticle *P)
Mdouble w_over_rmax
if w is not set manually then w will be set by multiplying this value by the largest particle radius ...
void set_h(Mdouble h)
void set_zminStat(Mdouble zminStat_)
Mdouble tmaxStat
Statistical output will only be created if t
Mdouble get_xminStat()
Functions to acces and change the domain of statistics.
void set_n(int nx_, int ny_, int nz_)
Mdouble get_dt()
Allows the time step dt to be accessed.
Definition: MD.h:339
std::vector< Vec3D > VelocityProfile
std::vector< StatisticsPoint< T > > dz
A vector that stores the gradient in z of all statistical variables at a given position.
Mdouble cutoff
The distance from the origin at which the cg function vanishes; cutoff=w for HeavisideSphere or Polyn...
void gather_force_statistics_from_p3w(int version, std::vector< int > &index)
get force statistics from particle collisions
std::vector< StatisticsPoint< T > > dy
A vector that stores the gradient in y of all statistical variables at a given position.
Mdouble xminStat
By default the points of evaluation are placed in an grid on the domain [xminStat,xmaxStat]x[yminStat,ymaxStat]x[zminStat,zmaxStat].
void constructor()
Sets up all basic things.
std::fstream p3p_file
#define sqr(a)
Definition: ExtendedMath.h:36
StatisticsVector(std::string name)
Vec3D P1
Position of first contact point.
bool loadVelocityProfile(const char *filename)
Mdouble w2
coarse graining width squared; for HeavisideSphere and Gaussian
Mdouble tintStat
Statistical output will only be created if tmaxStat-tintStat< t< tmaxStat.
std::fstream p3w_file
void set_zmaxStat(Mdouble zmaxStat_)
void set_ignoreFixedParticles(bool new_)
void write_statistics()
Writes regular statistics.
Mdouble get_tintStat()
void jump_p3c()
get force statistics from particle collisions
Mdouble P1_P2_Dissipation
not yet working
int get_dim()
Allows the dimension of the simulation to be accessed.
Definition: MD.h:369
std::vector< StatisticsPoint< T > > dx
A vector that stores the gradient in x of all statistical variables at a given position.
Mdouble P1_P2_distance
Length of contact line.
void set_nz(int new_)
void set_hy(Mdouble hy)
void set_infiniteStressForFixedParticles(bool new_)
void set_tmaxStat(Mdouble t)
void evaluate_wall_force_statistics(Vec3D P, int wp=0)
get force statistics (i.e. first particle is a wall particle)
void set_doublePoints(bool new_)
int nx
Grid size nx,ny,nz (by default the points of evaluation are placed in an grid on the domain [xminStat...
void set_CG_type(const char *new_)
void set_nx(int new_)
Mdouble get_ymax()
Gets ymax.
Definition: MD.h:311
void set_StressTypeForFixedParticles(int new_)
Mdouble evaluatePolynomial(Mdouble r)
void set_xminStat(Mdouble xminStat_)
CG
enum used to store the type of coarse-graining function used
void set_w2(Mdouble new_)
Set CG variables w2 and CG_invvolume.
void set_Positions()
Set position of StatisticsPoint points and set variables to 0.
void set_hz(Mdouble hz)
int nTimeAverage
A counter needed to average over time.
void get_n(int &nx_, int &ny_, int &nz_)
void set_doTimeAverage(bool new_)
int nTimeAverageReset
Determines after how many timesteps the time average is reset.
std::vector< StatisticsPoint< T > > dxTimeAverage
a vector used to sum up all statistical gradients in dx for time-averaging
std::string print()
Outputs member variable values to a std::string.
std::vector< StatisticsPoint< T > > dzTimeAverage
a vector used to sum up all statistical gradients in dz for time-averaging
void set_tminStat(Mdouble t)
void set_mirrorAtDomainBoundary(Mdouble new_)
Mdouble get_t()
Access function for the time.
Definition: MD.h:108
Mdouble indSpecies
defines the species for which statistics are extracted (-1 for all species)
Mdouble get_ymin()
Gets ymin.
Definition: MD.h:309
void evaluate_force_statistics(int wp=0)
get force statistics
void statistics_from_p3()
this is a modified version of statistics_from_fstat_and_data. It is used to read p3d files ...
Mdouble tminStat
Statistical output will only be created if t>tminStat.
void set_ymaxStat(Mdouble ymaxStat_)
Mdouble t
This stores the current time.
Definition: MD.h:687
Mdouble rmin
defines the minimum radius of the particles for which statistics are extracted
Mdouble get_xmin()
Get xmin.
Definition: MD.h:305
void set_xmaxStat(Mdouble xmaxStat_)
double Mdouble
Definition: ExtendedMath.h:33
Vec3D getVelocityProfile(Vec3D Position)
Mdouble get_tmaxStat()
void set_rmax(Mdouble new_)
NORMALIZED_POLYNOMIAL< T > CGPolynomial
Stores the Polynomial, if the cg function is an axisymmetric function Polynomial in r...
std::vector< StatisticsPoint< T > > get_Points()
void statistics_from_fstat_and_data()
get StatisticsPoint
void evaluate_particle_statistics(std::vector< BaseParticle * >::iterator P, int wp=0)
Calculates statistics for a single Particle.
Vec3D P1_P2_normal
Direction of contact.
void set_periodicWalls(bool new_)
void set_doVariance(bool new_)
Mdouble get_tmax()
Allows the upper time limit to be accessed.
Definition: MD.h:144
bool doTimeAverage
Determines if output is averaged over time.
void process_statistics(bool usethese)
Processes all gathered statistics and resets them afterwards. (Processing means either calculating ti...
void set_Polynomial(std::vector< Mdouble > new_coefficients, unsigned int new_dim)
Mdouble get_w_over_rmax()
void set_doGradient(bool new_)
void set_superexact(bool new_)
std::vector< StatisticsPoint< T > > timeVariance
a vector used to sum up the variance in time of all statistical values
Mdouble mirrorAtDomainBoundary
bool doVariance
Determines if variance is outputted.
MatrixSymmetric3D P1_P2_Fabric
Fabric.
std::string get_PolynomialName()
bool get_ignoreFixedParticles()
void set_hmax(Mdouble new_)
Matrix3D P1_P2_NormalStress
Contact stress from normal forces along the line of contact.
std::fstream p3c_file
Vec3D P1_P2_CollisionalHeatFlux
not yet working
std::vector< StatisticsPoint< T > > Points
A vector that stores the values of the statistical variables at a given position. ...
A class that defines and solves a MD problem.
Definition: MD.h:70
void set_tintStat(Mdouble t)
This class stores statistical values for a given spatial position; to be used in combination with Sta...
int verbosity
0 no output 1 basic output (timesteps) 2 full output (number of forces and particles, md and stat parameters)
void gather_statistics_collision(int index1, int index2, Vec3D Contact, Mdouble delta, Mdouble ctheta, Mdouble fdotn, Mdouble fdott, Vec3D P1_P2_normal_, Vec3D P1_P2_tangential)
Calculates statistics for one collision (can be any kind of collision)
CG CG_type
coarse graining type (Gaussian, Heaviside, Polynomial)
Mdouble hmax
defines the maximum height of the particles for which statistics are extracted
This class is used to extract statistical data from MD simulations.
Matrix3D P1_P2_ContactCoupleStress
void set_PolynomialName(const char *new_name)
void set_verbosity(int new_)
std::vector< StatisticsPoint< T > > timeAverage
A vector used to sum up all statistical values in Points for time-averaging.
This class is used to define polynomial axisymmetric coarse-graining functions.
Definition: Polynomial.h:52
void set_ny(int new_)
Mdouble setInfinitelyLongDistance()
bool superexact
If true, cutoff radius for Gaussian is set to 5*w (from 3*w)
virtual void reset_statistics()
Set all statistical variables to zero.
void set_Polynomial(Mdouble *new_coefficients, unsigned int num_coeff, unsigned int new_dim)
Mdouble get_xmax()
Get xmax.
Definition: MD.h:307
bool ignoreFixedParticles
Determines if fixed particles contribute to particle statistics (density, ...)
Implementation of a 3D matrix.
Definition: Matrix.h:35
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Mdouble get_mirrorAtDomainBoundary()
int StressTypeForFixedParticles
0 no Stress from fixed particles 1 Stress from fixed particles distributed between Contact and flowin...
Mdouble P1_P2_Potential
not yet working
Mdouble evaluateIntegral(Mdouble n1, Mdouble n2, Mdouble t)
Mdouble rmax
defines the maximum radius of the particles for which statistics are extracted
Mdouble get_zmax()
Gets zmax.
Definition: MD.h:315
void set_rmin(Mdouble new_)
Implementation of a 3D symmetric matrix.
void readStatArguments(unsigned int argc, char *argv[])
std::string print_CG()
Output coarse graining variables.
Matrix3D P1_P2_TangentialStress
Contact stress from tangential forces along the line of contact.
bool doGradient
Determines if gradient is outputted.
Vec3D P1_P2_NormalTraction
Traction from normal forces at contact of flow with fixed particles or walls.
void set_w(Mdouble w)
Set CG variables w2 and CG_invvolume.
void gather_force_statistics_from_p3c(int version)
get force statistics from particle collisions
void set_w_over_rmax(Mdouble new_)
void set_walls(bool new_)
int nxMirrored
extension of grid size from mirrored points