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() const;
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 
154  void setDistributionUniform(Mdouble radMin, Mdouble radMax, int numberOfBins);
155 
159  void setDistributionNormal(Mdouble mean, Mdouble standardDeviation, int numberOfBins);
160 
165 
170 
175 
180 
185 
189  void cutoffCumulativeNumber(Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity = 0.1);
190 
194  void cutoffAndSqueezeCumulative(Mdouble quantileMin, Mdouble quantileMax, Mdouble squeeze,
195  Mdouble minPolydispersity = 0.1);
196 
200  Mdouble getMinRadius() const;
201 
205  Mdouble getMaxRadius() const;
206 
210  std::vector<RadiusAndProbability> getParticleSizeDistribution() const;
211 
215  void setParticleSizeDistribution(std::vector<RadiusAndProbability>);
216 
220  int getInsertedParticleNumber() const;
221 
225  Mdouble getNumberDx(Mdouble x) const;
226 
230  Mdouble getVolumeDx(Mdouble x) const;
231 
235  Mdouble getRadiusByQuantile(Mdouble quantile) const;
236 
241 
245  Mdouble getSizeRatio() const;
246 
250  void cutHighSizeRatio();
251 
255  void computeRawMomenta();
256 
260  void computeCentralMomenta();
261 
266 
270  std::array<Mdouble, 6> getMomenta() const;
271 
275  friend bool operator<(const PSD::RadiusAndProbability& l, const PSD::RadiusAndProbability& r);
276 
280  friend bool operator<(const PSD::RadiusAndProbability& l, Mdouble r);
281 
285  friend std::ostream& operator<<(std::ostream& os, PSD::RadiusAndProbability& p);
286 
290  friend std::istream& operator>>(std::istream& is, PSD::RadiusAndProbability& p);
291 
296 
297 private:
301  std::vector<RadiusAndProbability> particleSizeDistribution_;
302 
307  std::array<Mdouble, 6> momenta_{};
308 
314  std::vector<int> nParticlesPerClass_;
315 
323  std::vector<Mdouble> volumePerClass_;
324 };
325 
326 
327 #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:890
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:913
MERCURY_DEPRECATED void setPSDFromVector(std::vector< RadiusAndProbability > psd, TYPE PSDType)
Deprecated version of reading in PSDs from a vector.
Definition: PSD.cc:352
std::vector< RadiusAndProbability > getParticleSizeDistribution() const
Get the PSD vector.
Definition: PSD.cc:821
~PSD()
Destructor; default destructor.
friend std::istream & operator>>(std::istream &is, PSD::RadiusAndProbability &p)
Reads from input stream.
Definition: PSD.cc:942
friend std::ostream & operator<<(std::ostream &os, PSD::RadiusAndProbability &p)
Writes to output stream.
Definition: PSD.cc:953
double Mdouble
Definition: GeneralDefine.h:34
void computeCentralMomenta()
compute central momenta of the user defined PSD.
Definition: PSD.cc:876
std::vector< int > nParticlesPerClass_
Definition: PSD.h:314
void setDistributionNormal(Mdouble mean, Mdouble standardDeviation, int numberOfBins)
create a PSD vector for a normal distribution.
Definition: PSD.cc:314
void convertCumulativeToCumulativeNumberDistribution(TYPE CDFType)
convert any other CDF to a CUMULATIVE_NUMBER_DISTRIBUTION.
Definition: PSD.cc:609
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution()
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Definition: PSD.cc:584
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:933
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:115
void setParticleSizeDistribution(std::vector< RadiusAndProbability >)
set the PSD by a suitable vector.
Definition: PSD.cc:830
#define MERCURY_DEPRECATED
Definition: GeneralDefine.h:37
PSD * copy() const
Creates a copy on the heap and returns a pointer.
Definition: PSD.cc:59
void cutoffAndSqueezeCumulative(Mdouble quantileMin, Mdouble quantileMax, Mdouble squeeze, Mdouble minPolydispersity=0.1)
cutoff the PSD at given quantiles and make it less polydisperse by squeezing it.
Definition: PSD.cc:702
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
int getInsertedParticleNumber() const
Get the number of particles already inserted into the simulation.
Definition: PSD.cc:840
void validateProbabilityDensityDistribution()
Validates if the integral of the PDF equals to unity.
Definition: PSD.cc:251
Mdouble getRadiusByQuantile(Mdouble quantile) const
Calculate the quantile of the PSD.
Definition: PSD.cc:744
Mdouble getMinRadius() const
Get smallest radius of the PSD.
Definition: PSD.cc:803
Mdouble drawSample()
Draw a sample radius from a CUMULATIVE_NUMBER_DISTRIBUTION.
Definition: PSD.cc:109
void setDistributionUniform(Mdouble radMin, Mdouble radMax, int numberOfBins)
create a PSD vector for a uniform distribution.
Definition: PSD.cc:290
void cutoffCumulativeNumber(Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity=0.1)
cutoff the PSD at given quantiles.
Definition: PSD.cc:668
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
std::vector< Mdouble > volumePerClass_
Definition: PSD.h:323
void printPSD() const
Prints radii and probabilities of the PSD vector.
Definition: PSD.cc:71
void convertProbabilityDensityToProbabilityDensityNumberDistribution(TYPE PDFType)
convert any PDF to a PROBABILITYDENSITY_NUMBER_DISTRIBUTION.
Definition: PSD.cc:522
void convertCumulativeToProbabilityDensity()
Converts a CDF to a PDF by derivation.
Definition: PSD.cc:502
Mdouble getVolumeDx(Mdouble x) const
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the volume based PSD...
Definition: PSD.cc:730
Mdouble getVolumetricMeanRadius() const
get a volumetric mean radius of the PSD.
Definition: PSD.cc:762
Mdouble getNumberDx(Mdouble x) const
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the number based PSD...
Definition: PSD.cc:720
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:418
Mdouble getSizeRatio() const
get the size ratio (width) of the PSD.
Definition: PSD.cc:778
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:487
T square(const T val)
squares a number
Definition: ExtendedMath.h:106
Mdouble getMaxRadius() const
Get largest radius of the PSD.
Definition: PSD.cc:812
Mdouble probability
Definition: PSD.h:90
std::array< Mdouble, 6 > getMomenta() const
get momenta of the user defined PSD.
Definition: PSD.cc:903
void cutHighSizeRatio()
Check if the size ratio is too high and cut it.
Definition: PSD.cc:789
void computeRawMomenta()
compute raw momenta of the user defined PSD.
Definition: PSD.cc:856