MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSD.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 PSD_H
27 #define PSD_H
28 
29 #include <fstream>
30 #include <Logger.h>
31 #include <vector>
32 #include <Tools/csvReader.h>
33 #include <random>
34 #include "iostream"
35 #include "ExtendedMath.h"
36 
37 using mathsFunc::square;
38 using mathsFunc::cubic;
39 
62 class PSD
63 {
64 
65 public:
71  enum class TYPE
72  {
81  };
82 
87  {
88  public:
91  };
92 
96  PSD();
97 
101  PSD(const PSD& other);
102 
106  ~PSD();
107 
111  PSD* copy() const;
112 
116  void printPSD();
117 
122 
128 
133 
138 
143  void setPSDFromVector(std::vector<RadiusAndProbability> psd, TYPE PSDType);
144 
148  void setPSDFromCSV(const std::string& fileName, TYPE PSDType, bool headings = false, Mdouble
149  unitScalingFactorRadii = 1.0);
150 
155 
160 
165 
170 
175 
179  void cutoffCumulativeNumber(Mdouble percentileMin, Mdouble percentileMax, Mdouble minPolydispersity = 0.1);
180 
184  void cutoffAndSqueezeCumulative(Mdouble percentileMin, Mdouble percentileMax, Mdouble squeeze,
185  Mdouble minPolydispersity = 0.1);
186 
191 
196 
200  std::vector<RadiusAndProbability> getParticleSizeDistribution() const;
201 
206 
210  Mdouble getDx(Mdouble x);
211 
216 
221 
225  void computeRawMomenta();
226 
230  void computeCentralMomenta();
231 
236 
240  std::array<Mdouble, 6> getMomenta();
241 
245  friend bool operator<(const PSD::RadiusAndProbability& l, const PSD::RadiusAndProbability& r);
246 
250  friend bool operator<(const PSD::RadiusAndProbability& l, Mdouble r);
251 
255  friend std::ostream& operator<<(std::ostream& os, PSD::RadiusAndProbability& p);
256 
260  friend std::istream& operator>>(std::istream& is, PSD::RadiusAndProbability& p);
261 
266 
267 
268 private:
272  std::vector<RadiusAndProbability> particleSizeDistribution_;
273 
277  std::array<Mdouble, 6> momenta_{};
278 
284  std::vector<int> nParticlesPerClass_;
285 
293  std::vector<Mdouble> volumePerClass_;
294 };
295 
296 
297 #endif //PSD_H
PSD()
Constructor; sets everything to 0 or default.
Definition: PSD.cc:32
Class which stores radii and probabilities of a PSD. This class should be used as a vector
Definition: PSD.h:86
void computeStandardisedMomenta()
compute standardised momenta of the user defined PSD.
Definition: PSD.cc:778
friend bool operator<(const PSD::RadiusAndProbability &l, const PSD::RadiusAndProbability &r)
determines if a certain value of the PSD vector is lower than another one. Used for std::lower_bound(...
Definition: PSD.cc:801
std::vector< RadiusAndProbability > getParticleSizeDistribution() const
Get the PSD vector.
Definition: PSD.cc:718
~PSD()
Destructor; default destructor.
MERCURY_DEPRECATED void setPSDFromVector(std::vector< RadiusAndProbability > psd, TYPE PSDType)
Deprecated version of reading in PSDs from a vector.
Definition: PSD.cc:295
friend std::istream & operator>>(std::istream &is, PSD::RadiusAndProbability &p)
Reads from input stream.
Definition: PSD.cc:830
friend std::ostream & operator<<(std::ostream &os, PSD::RadiusAndProbability &p)
Writes to output stream.
Definition: PSD.cc:841
double Mdouble
Definition: GeneralDefine.h:34
void computeCentralMomenta()
compute central momenta of the user defined PSD.
Definition: PSD.cc:764
std::vector< int > nParticlesPerClass_
Definition: PSD.h:284
void convertCumulativeToCumulativeNumberDistribution(TYPE CDFType)
convert any other CDF to a CUMULATIVE_NUMBER_DISTRIBUTION.
Definition: PSD.cc:551
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution()
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Definition: PSD.cc:526
friend Mdouble operator==(PSD::RadiusAndProbability l, Mdouble r)
Determines if a certain value of the PSD vector is equal to a double.
Definition: PSD.cc:821
Mdouble insertManuallyByVolume(Mdouble volume)
Draw sample radius manually per size class and check the volumeAllowed of each size class to insert t...
Definition: PSD.cc:137
TYPE
Enum class which stores the possible types of CDFs and PDFs. Particle size distributions can be repre...
Definition: PSD.h:71
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
T cubic(const T val)
calculates the cube of a number
Definition: ExtendedMath.h:113
Mdouble getVolumetricMeanRadius()
get a volumetric mean radius of the PSD.
Definition: PSD.cc:683
Mdouble getMaxRadius()
Get largest radius of the PSD.
Definition: PSD.cc:709
Mdouble getDx(Mdouble x)
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile of the PSD.
Definition: PSD.cc:655
#define MERCURY_DEPRECATED
Definition: GeneralDefine.h:37
PSD * copy() const
Creates a copy on the heap and returns a pointer.
Definition: PSD.cc:59
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:277
void validateProbabilityDensityDistribution()
Validates if the integral of the PDF equals to unity.
Definition: PSD.cc:251
void cutoffAndSqueezeCumulative(Mdouble percentileMin, Mdouble percentileMax, Mdouble squeeze, Mdouble minPolydispersity=0.1)
cutoff the PSD at given percentiles and make it less polydisperse by squeezing it.
Definition: PSD.cc:637
Mdouble drawSample()
Draw a sample radius from a CUMULATIVE_NUMBER_DISTRIBUTION.
Definition: PSD.cc:109
Mdouble getMinRadius()
Get smallest radius of the PSD.
Definition: PSD.cc:700
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:272
void printPSD()
Prints radii and probabilities of the PSD vector.
Definition: PSD.cc:71
std::vector< Mdouble > volumePerClass_
Definition: PSD.h:293
void convertProbabilityDensityToProbabilityDensityNumberDistribution(TYPE PDFType)
convert any PDF to a PROBABILITYDENSITY_NUMBER_DISTRIBUTION.
Definition: PSD.cc:464
void cutoffCumulativeNumber(Mdouble percentileMin, Mdouble percentileMax, Mdouble minPolydispersity=0.1)
cutoff the PSD at given percentiles.
Definition: PSD.cc:610
void convertCumulativeToProbabilityDensity()
Converts a CDF to a PDF by derivation.
Definition: PSD.cc:444
int getInsertedParticleNumber()
Get the number of particles already inserted into the simulation.
Definition: PSD.cc:728
std::array< Mdouble, 6 > getMomenta()
get momenta of the user defined PSD.
Definition: PSD.cc:791
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD) ...
Definition: PSD.h:62
void setPSDFromCSV(const std::string &fileName, TYPE PSDType, bool headings=false, Mdouble unitScalingFactorRadii=1.0)
read in the PSD vector with probabilities and radii saved in a .csv file.
Definition: PSD.cc:361
Mdouble getRadiusByPercentile(Mdouble percentile)
Calculate the percentile of the PSD.
Definition: PSD.cc:665
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:429
T square(const T val)
squares a number
Definition: ExtendedMath.h:104
Mdouble probability
Definition: PSD.h:90
void computeRawMomenta()
compute raw momenta of the user defined PSD.
Definition: PSD.cc:744