MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSD Class Reference

Contains a vector with radii and probabilities of a user defined particle size distribution (PSD) More...

#include <PSD.h>

Classes

class  RadiusAndProbability
 Class which stores radii and probabilities of a PSD. This class should be used as a vector<PSD::RadiusAndProbability>. More...
 

Public Types

enum  TYPE {
  TYPE::CUMULATIVE_NUMBER_DISTRIBUTION, TYPE::CUMULATIVE_LENGTH_DISTRIBUTION, TYPE::CUMULATIVE_VOLUME_DISTRIBUTION, TYPE::CUMULATIVE_AREA_DISTRIBUTION,
  TYPE::PROBABILITYDENSITY_NUMBER_DISTRIBUTION, TYPE::PROBABILITYDENSITY_LENGTH_DISTRIBUTION, TYPE::PROBABILITYDENSITY_AREA_DISTRIBUTION, TYPE::PROBABILITYDENSITY_VOLUME_DISTRIBUTION
}
 Enum class which stores the possible types of CDFs and PDFs. Particle size distributions can be represented by different probabilities based on number of particles, length of particles, surface area of particles or volume of particles. More...
 

Public Member Functions

 PSD ()
 Constructor; sets everything to 0 or default. More...
 
 PSD (const PSD &other)
 Copy constructor with deep copy. More...
 
 ~PSD ()
 Destructor; default destructor. More...
 
PSDcopy () const
 Creates a copy on the heap and returns a pointer. More...
 
void printPSD () const
 Prints radii and probabilities of the PSD vector. More...
 
Mdouble drawSample ()
 Draw a sample radius from a CUMULATIVE_NUMBER_DISTRIBUTION. More...
 
Mdouble insertManuallyByVolume (Mdouble volume)
 Draw sample radius manually per size class and check the volumeAllowed of each size class to insert the PSD as accurate as possible. More...
 
void validateCumulativeDistribution ()
 Validates if a CDF starts with zero and adds up to unity. More...
 
void validateProbabilityDensityDistribution ()
 Validates if the integral of the PDF equals to unity. More...
 
MERCURY_DEPRECATED void setPSDFromVector (std::vector< RadiusAndProbability > psd, TYPE PSDType)
 Deprecated version of reading in PSDs from a vector. More...
 
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. More...
 
void setDistributionUniform (Mdouble radMin, Mdouble radMax, int numberOfBins)
 create a PSD vector for a uniform distribution. More...
 
void setDistributionNormal (Mdouble mean, Mdouble standardDeviation, int numberOfBins)
 create a PSD vector for a normal distribution. More...
 
void convertProbabilityDensityToCumulative ()
 Converts a PDF to a CDF by integration. More...
 
void convertCumulativeToProbabilityDensity ()
 Converts a CDF to a PDF by derivation. More...
 
void convertProbabilityDensityToProbabilityDensityNumberDistribution (TYPE PDFType)
 convert any PDF to a PROBABILITYDENSITY_NUMBER_DISTRIBUTION. More...
 
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution ()
 convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION. More...
 
void convertCumulativeToCumulativeNumberDistribution (TYPE CDFType)
 convert any other CDF to a CUMULATIVE_NUMBER_DISTRIBUTION. More...
 
void cutoffCumulativeNumber (Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity=0.1)
 cutoff the PSD at given quantiles. More...
 
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. More...
 
Mdouble getMinRadius () const
 Get smallest radius of the PSD. More...
 
Mdouble getMaxRadius () const
 Get largest radius of the PSD. More...
 
std::vector< RadiusAndProbabilitygetParticleSizeDistribution () const
 Get the PSD vector. More...
 
void setParticleSizeDistribution (std::vector< RadiusAndProbability >)
 set the PSD by a suitable vector. More...
 
int getInsertedParticleNumber () const
 Get the number of particles already inserted into the simulation. More...
 
Mdouble getNumberDx (Mdouble x) const
 Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the number based PSD. More...
 
Mdouble getVolumeDx (Mdouble x) const
 Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the volume based PSD. More...
 
Mdouble getRadiusByQuantile (Mdouble quantile) const
 Calculate the quantile of the PSD. More...
 
Mdouble getVolumetricMeanRadius () const
 get a volumetric mean radius of the PSD. More...
 
Mdouble getSizeRatio () const
 get the size ratio (width) of the PSD. More...
 
void cutHighSizeRatio ()
 Check if the size ratio is too high and cut it. More...
 
void computeRawMomenta ()
 compute raw momenta of the user defined PSD. More...
 
void computeCentralMomenta ()
 compute central momenta of the user defined PSD. More...
 
void computeStandardisedMomenta ()
 compute standardised momenta of the user defined PSD. More...
 
std::array< Mdouble, 6 > getMomenta () const
 get momenta of the user defined PSD. More...
 

Private Attributes

std::vector< RadiusAndProbabilityparticleSizeDistribution_
 
std::array< Mdouble, 6 > momenta_ {}
 
std::vector< int > nParticlesPerClass_
 
std::vector< MdoublevolumePerClass_
 

Friends

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() More...
 
bool operator< (const PSD::RadiusAndProbability &l, Mdouble r)
 determines if a certain value of the PSD vector is lower than a double. More...
 
std::ostream & operator<< (std::ostream &os, PSD::RadiusAndProbability &p)
 Writes to output stream. More...
 
std::istream & operator>> (std::istream &is, PSD::RadiusAndProbability &p)
 Reads from input stream. More...
 
Mdouble operator== (PSD::RadiusAndProbability l, Mdouble r)
 Determines if a certain value of the PSD vector is equal to a double. More...
 

Detailed Description

Contains a vector with radii and probabilities of a user defined particle size distribution (PSD)

Stores radii and probabilities of a particle size distribution (PSD) in a vector of type PSD::RadiusAndProbability and converts them to a PSD which can be used by insertionBoundaries which insert particles into a simulation:

Cumulative distribution function (CDF): gives percentage of particles p_i whose radius r is less than a certain radius r_i. It requires p_0 = 0 and p_end = 1. The CDF's probabilities can be number, length, area or volume based. The cumulative number distribution function (CUMULATIVE_NUMBER_DISTRIBUTION) is used as PSD in MercuryDPM, as it can be interpreted as the probability that a particle's radius is less than r_i: CDF(r<r_i) = p_i.

Probability density function (PDF): p_i is the percentage of particles whose radius is between r_i-1 and r_i. It requires p_0=0 and sum(p_i)=1. The PDF's probabilities can also be number, length, area or volume based. PDF's are utilized to convert any type of PDF to a probability number density function (PROBABILITYDENSITY_NUMBER_DISTRIBUTION) which in a next step are converted to the default CUMULATIVE_NUMBER_DISTRIBUTION.

Sieve data: p_i is the percentage of particles whose radius is between r_i and r_i+1. It requires sum(p_i)=1. relation to PDF: p_i = p(PDF)_i-1. Sieve data is not yet used in this class.

Default distribution is the CUMULATIVE_NUMBER_DISTRIBUTION.

Definition at line 62 of file PSD.h.

Member Enumeration Documentation

enum PSD::TYPE
strong

Enum class which stores the possible types of CDFs and PDFs. Particle size distributions can be represented by different probabilities based on number of particles, length of particles, surface area of particles or volume of particles.

Enumerator
CUMULATIVE_NUMBER_DISTRIBUTION 
CUMULATIVE_LENGTH_DISTRIBUTION 
CUMULATIVE_VOLUME_DISTRIBUTION 
CUMULATIVE_AREA_DISTRIBUTION 
PROBABILITYDENSITY_NUMBER_DISTRIBUTION 
PROBABILITYDENSITY_LENGTH_DISTRIBUTION 
PROBABILITYDENSITY_AREA_DISTRIBUTION 
PROBABILITYDENSITY_VOLUME_DISTRIBUTION 

Definition at line 71 of file PSD.h.

72  {
73  CUMULATIVE_NUMBER_DISTRIBUTION,
74  CUMULATIVE_LENGTH_DISTRIBUTION,
75  CUMULATIVE_VOLUME_DISTRIBUTION,
76  CUMULATIVE_AREA_DISTRIBUTION,
77  PROBABILITYDENSITY_NUMBER_DISTRIBUTION,
78  PROBABILITYDENSITY_LENGTH_DISTRIBUTION,
79  PROBABILITYDENSITY_AREA_DISTRIBUTION,
80  PROBABILITYDENSITY_VOLUME_DISTRIBUTION
81  };

Constructor & Destructor Documentation

PSD::PSD ( )

Constructor; sets everything to 0 or default.

Default constructor; sets every data member to 0 or default.

Definition at line 32 of file PSD.cc.

References momenta_.

Referenced by copy().

33 {
34  for (auto& momenta: momenta_)
35  momenta = 0;
36 }
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
PSD::PSD ( const PSD other)

Copy constructor with deep copy.

Copy constructor

Definition at line 41 of file PSD.cc.

References momenta_, and particleSizeDistribution_.

42 {
44  momenta_ = other.momenta_;
45 }
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
PSD::~PSD ( )
default

Destructor; default destructor.

Destructor. Since there are no pointers in this class, there is no need for any actions here.

Member Function Documentation

void PSD::computeCentralMomenta ( )

compute central momenta of the user defined PSD.

Compute the central momenta of the PSD from their respective raw momenta.

Definition at line 876 of file PSD.cc.

References computeRawMomenta(), and momenta_.

Referenced by computeStandardisedMomenta().

877 {
879  Mdouble mean = momenta_[1];
880  momenta_[5] += -5 * mean * momenta_[4] + 10 * mean * mean * momenta_[3]
881  - 10 * mean * mean * mean * momenta_[2] + 4 * mean * mean * mean * mean * mean;
882  momenta_[4] += -4 * mean * momenta_[3] + 6 * mean * mean * momenta_[2] - 3 * mean * mean * mean * mean;
883  momenta_[3] += -3 * mean * momenta_[2] + 2 * mean * mean * mean;
884  momenta_[2] += -mean * mean;
885 }
double Mdouble
Definition: GeneralDefine.h:34
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
void computeRawMomenta()
compute raw momenta of the user defined PSD.
Definition: PSD.cc:856
void PSD::computeRawMomenta ( )

compute raw momenta of the user defined PSD.

Compute the raw momenta of the inserted PSD by converting it to a PDF, calculating the moments m_i according to \( m_i = \sum_{j=0}^n \) scaling it by the number of particles inserted into the simulation (moments are computed from a PROBABILITYDENSITY_NUMBER_DISTRIBUTION) and converting it back to a CDF. See Wikipedia for details.

Definition at line 856 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityToCumulative(), getInsertedParticleNumber(), and momenta_.

Referenced by computeCentralMomenta().

857 {
859  for (size_t im = 0; im < momenta_.size(); ++im)
860  {
861  // prevent summing up of moments for each time step of the simulation
862  momenta_[im] = 0;
863  for (auto& it : particleSizeDistribution_)
864  {
865  momenta_[im] += std::pow(it.radius, im) * it.probability;
866  }
867  }
868  // zeroth-moment equals particle number for a PROBABILITYDENSITY_NUMBER_DISTRIBUTION
871 }
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
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void convertCumulativeToProbabilityDensity()
Converts a CDF to a PDF by derivation.
Definition: PSD.cc:502
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:487
void PSD::computeStandardisedMomenta ( )

compute standardised momenta of the user defined PSD.

Compute the standardised momenta of the PSD from their respective central momenta.

Definition at line 890 of file PSD.cc.

References computeCentralMomenta(), and momenta_.

891 {
893  Mdouble std = std::sqrt(momenta_[2]);
894  momenta_[3] /= std * std * std;
895  momenta_[4] /= std * std * std * std;
896  momenta_[5] /= std * std * std * std * std;
897 }
double Mdouble
Definition: GeneralDefine.h:34
void computeCentralMomenta()
compute central momenta of the user defined PSD.
Definition: PSD.cc:876
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
void PSD::convertCumulativeToCumulativeNumberDistribution ( TYPE  CDFType)

convert any other CDF to a CUMULATIVE_NUMBER_DISTRIBUTION.

converts any of the CDFTypes to a the default CUMULATIVE_NUMBER_DISTRIBUTION based on their TYPE.

Parameters
[in]PDFTypeType of the PDF: PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_AREA_DISTRIBUTION or PROBABILITYDENSITY_VOLUME_DISTRIBUTION, Where L = Length, A = Area and V = Volume.
Todo:
TP: NOT WORKING! If anyone knows how to do it feel free to add

Definition at line 609 of file PSD.cc.

610 {
611  Mdouble sum = 0;
612  switch (CDFType)
613  {
614  default:
615  logger(ERROR, "Wrong CDFType");
616  break;
618  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
619  {
620  // add conversion here
621 
622  // sum up probabilities
623  sum += it->probability;
624  }
625  // normalize
626  for (auto& p : particleSizeDistribution_)
627  {
628  p.probability /= sum;
629  }
630  break;
632  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
633  {
634  // add conversion here
635 
636  // sum up probabilities
637  sum += it->probability;
638  }
639  // normalize
640  for (auto& p : particleSizeDistribution_)
641  {
642  p.probability /= sum;
643  }
644  break;
646  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
647  {
648  // add conversion here
649 
650  // sum up probabilities
651  sum += it->probability;
652  }
653  // normalize
654  for (auto& p : particleSizeDistribution_)
655  {
656  p.probability /= sum;
657  }
658  break;
659  }
660 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::convertCumulativeToProbabilityDensity ( )

Converts a CDF to a PDF by derivation.

Convert any type of CDF to a PDF. Probabilities are derivated for each radius by substracting the CDF probabilities (i.e. pPDF_i = pCDF_i - pCDF_i-1).

Definition at line 502 of file PSD.cc.

References particleSizeDistribution_, and validateProbabilityDensityDistribution().

Referenced by computeRawMomenta(), getVolumeDx(), getVolumetricMeanRadius(), insertManuallyByVolume(), setPSDFromCSV(), and setPSDFromVector().

503 {
504  // subtract cumulative probabilities
505  Mdouble probabilityOld = 0, probabilityCDF;
506  for (auto& it : particleSizeDistribution_)
507  {
508  probabilityCDF = it.probability;
509  it.probability -= probabilityOld;
510  probabilityOld = probabilityCDF;
511  }
512  // check whether probability density distribution is valid
514 }
double Mdouble
Definition: GeneralDefine.h:34
void validateProbabilityDensityDistribution()
Validates if the integral of the PDF equals to unity.
Definition: PSD.cc:251
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution ( )

convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.

converts a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION. Used for getVolumetricMeanRadius() and insertManuallyByVolume().

Definition at line 584 of file PSD.cc.

References particleSizeDistribution_, and mathsFunc::square().

Referenced by getVolumeDx(), getVolumetricMeanRadius(), and insertManuallyByVolume().

585 {
586  Mdouble sum = 0;
587  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
588  {
589  it->probability *=
590  0.25 * (square(it->radius) + square((it - 1)->radius)) * (it->radius + (it - 1)->radius);
591  // old conversion
592  //p.probability /= cubic(p.radius);
593  // sum up probabilities
594  sum += it->probability;
595  }
596  // normalize
597  for (auto& p : particleSizeDistribution_)
598  {
599  p.probability /= sum;
600  }
601 }
double Mdouble
Definition: GeneralDefine.h:34
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
T square(const T val)
squares a number
Definition: ExtendedMath.h:106
void PSD::convertProbabilityDensityToCumulative ( )

Converts a PDF to a CDF by integration.

Convert any type of PDF to a CDF. Probabilities are integrated for each radius by cumulatively summing them up (i.e. p_i = p_i + p_i-1).

Definition at line 487 of file PSD.cc.

References particleSizeDistribution_, and validateCumulativeDistribution().

Referenced by computeRawMomenta(), getVolumeDx(), insertManuallyByVolume(), setPSDFromCSV(), and setPSDFromVector().

488 {
489  // add up probabilities
490  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
491  {
492  it->probability = std::min(1.0, it->probability + (it - 1)->probability);
493  }
494  // check whether cumulative distribution is valid
496 }
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::convertProbabilityDensityToProbabilityDensityNumberDistribution ( TYPE  PDFType)

convert any PDF to a PROBABILITYDENSITY_NUMBER_DISTRIBUTION.

converts any of the PDFTypes to a PROBABILITYDENSITY_NUMBER_DISTRIBUTION based on their TYPE. This is a helper function which enables the convertProbabilityDensityToCumulative function to convert the psd into the default TYPE (CUMULATIVE_NUMBER_DISTRIBUTION).

Parameters
[in]PDFTypeType of the PDF: PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_AREA_DISTRIBUTION or PROBABILITYDENSITY_VOLUME_DISTRIBUTION, Where L = Length, A = Area and V = Volume.

Definition at line 522 of file PSD.cc.

References ERROR, logger, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and mathsFunc::square().

Referenced by insertManuallyByVolume(), setPSDFromCSV(), and setPSDFromVector().

523 {
524  Mdouble sum = 0;
525  switch (PDFType)
526  {
527  default:
528  logger(ERROR, "Wrong PDFType");
529  break;
531  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
532  {
533  it->probability /= 0.5 * (it->radius + (it - 1)->radius);
534  // old conversion
535  //p.probability /= p.radius;
536  // sum up probabilities
537  sum += it->probability;
538  }
539  // normalize
540  for (auto& p : particleSizeDistribution_)
541  {
542  p.probability /= sum;
543  }
544  break;
546  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
547  {
548  it->probability /=
549  1.0 / 3.0 * (square(it->radius) + it->radius * (it - 1)->radius + square((it - 1)->radius));
550  // old conversion
551  //p.probability /= square(p.radius);
552  // sum up probabilities
553  sum += it->probability;
554  }
555  // normalize
556  for (auto& p : particleSizeDistribution_)
557  {
558  p.probability /= sum;
559  }
560  break;
562  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
563  {
564  it->probability /=
565  0.25 * (square(it->radius) + square((it - 1)->radius)) * (it->radius + (it - 1)->radius);
566  // old conversion
567  //p.probability /= cubic(p.radius);
568  // sum up probabilities
569  sum += it->probability;
570  }
571  // normalize
572  for (auto& p : particleSizeDistribution_)
573  {
574  p.probability /= sum;
575  }
576  break;
577  }
578 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
T square(const T val)
squares a number
Definition: ExtendedMath.h:106
PSD * PSD::copy ( ) const

Creates a copy on the heap and returns a pointer.

Copy method; creates a copy on the heap and returns its pointer.

Returns
pointer to the copy on the heap

Definition at line 59 of file PSD.cc.

References PSD().

60 {
61 #ifdef DEBUG_CONSTRUCTOR
62  std::cout << "PSD::copy() const finished" << std::endl;
63 #endif
64  return new PSD(*this);
65 }
PSD()
Constructor; sets everything to 0 or default.
Definition: PSD.cc:32
void PSD::cutHighSizeRatio ( )

Check if the size ratio is too high and cut it.

Checks if the Size ratio of the PSD is too high and cuts the PSD at head and tail by 10 percent to avoid inaccurate results.

Definition at line 789 of file PSD.cc.

References cutoffCumulativeNumber(), getSizeRatio(), logger, and WARN.

790 {
791  Mdouble SR = getSizeRatio();
792  if (SR > 100)
793  {
794  logger(WARN, "Size ratio > 100; Cutting the PSD to avoid inaccurate results");
795  cutoffCumulativeNumber(0.1, 0.9, 0.5);
796  }
797 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
void cutoffCumulativeNumber(Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity=0.1)
cutoff the PSD at given quantiles.
Definition: PSD.cc:668
Mdouble getSizeRatio() const
get the size ratio (width) of the PSD.
Definition: PSD.cc:778
void PSD::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.

Cuts off the CDF at given minimum and maximum quantiles, applies a minimum polydispersity at the base and squeezes the distribution to make it less polydisperse.

Parameters
[in]quantileMinundersize quantile to cut off the lower part of the CDF.
[in]quantileMaxoversize quantile to cut off the upper part of the CDF.
[in]squeezeapplies a squeezing factor ([0,1]) which determines the degree the PDF gets squeezed.
[in]minPolydispersityapplies a minimum of polydispersity ([0,1]) at the base of the CDF.

Definition at line 702 of file PSD.cc.

References cutoffCumulativeNumber(), and getNumberDx().

704 {
705  Mdouble r50 = 0.5 * PSD::getNumberDx(50);
706  // cut off
707  cutoffCumulativeNumber(quantileMin, quantileMax, minPolydispersity);
708  // squeeze psd
709  for (auto& p: particleSizeDistribution_)
710  {
711  p.radius = r50 + (p.radius - r50) * squeeze;
712  }
713 }
double Mdouble
Definition: GeneralDefine.h:34
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
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
void PSD::cutoffCumulativeNumber ( Mdouble  quantileMin,
Mdouble  quantileMax,
Mdouble  minPolydispersity = 0.1 
)

cutoff the PSD at given quantiles.

Cuts off the CDF at given minimum and maximum quantiles and applies a minimum polydispersity at the base.

Parameters
[in]quantileMinundersize quantile to cut off the lower part of the CDF.
[in]quantileMaxoversize quantile to cut off the upper part of the CDF.
[in]minPolydispersityApplies a minimum of polydispersity ([0,1]) at the base of the CDF.

Definition at line 668 of file PSD.cc.

References getRadiusByQuantile(), getSizeRatio(), INFO, and logger.

Referenced by cutHighSizeRatio(), and cutoffAndSqueezeCumulative().

669 {
670  Mdouble radiusMin = getRadiusByQuantile(quantileMin);
671  Mdouble radiusMax = getRadiusByQuantile(quantileMax);
672  // to get a minimum polydispersity at the base
673  Mdouble radiusMinCut = std::min(radiusMin * (1 + minPolydispersity), radiusMax);
674  // cut off min
675  while (particleSizeDistribution_.front().radius <= radiusMinCut)
676  {
678  }
679  particleSizeDistribution_.insert(particleSizeDistribution_.begin(), {radiusMinCut, quantileMin});
680  particleSizeDistribution_.insert(particleSizeDistribution_.begin(), {radiusMin, 0});
681  // cut off max
682  while (particleSizeDistribution_.back().radius >= radiusMax)
683  {
684  particleSizeDistribution_.pop_back();
685  }
686  Mdouble radiusMaxCut = std::max(radiusMax - (1 - minPolydispersity) * (radiusMax - particleSizeDistribution_.back()
687  .radius), radiusMin);
688  particleSizeDistribution_.push_back({radiusMaxCut, quantileMax});
689  particleSizeDistribution_.push_back({radiusMax, 1});
690  logger(INFO, "PSD was cut successfully and now has a size ratio of %", getSizeRatio());
691 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getRadiusByQuantile(Mdouble quantile) const
Calculate the quantile of the PSD.
Definition: PSD.cc:744
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
Mdouble getSizeRatio() const
get the size ratio (width) of the PSD.
Definition: PSD.cc:778
Mdouble PSD::drawSample ( )

Draw a sample radius from a CUMULATIVE_NUMBER_DISTRIBUTION.

Draws a sample probability of a real uniform distribution. A random number is generated in range [0,1] and by linear interpolation a suitable radius is returned. This function is only valid for CumulativeNumberDistributions as particles are drawn and not volumes, areas or lengths.

Returns
A Radius for a randomly assigned probability.
Todo:
TP: We should add a variable seed. Maybe make it definable by the user?

Definition at line 109 of file PSD.cc.

References particleSizeDistribution_.

110 {
111  // draw a number between 0 and 1, uniformly distributed
113  static std::mt19937 gen(0);
114  static std::uniform_real_distribution<Mdouble> dist(0, 1);
115  Mdouble prob = dist(gen);
116  // find the interval [low,high] of the psd in which the number sits
117  auto high = std::lower_bound(particleSizeDistribution_.begin(), particleSizeDistribution_.end(), prob);
118  auto low = std::max(particleSizeDistribution_.begin(), high - 1);
119  Mdouble rMin = low->radius;
120  Mdouble rMax = high->radius;
121  Mdouble pMin = low->probability;
122  Mdouble pMax = high->probability;
123  // interpolate linearly between [low.radius,high.radius] (assumption: CDF is piecewise linear)
124  Mdouble a = (prob - pMin) / (pMax - pMin);
125  return a * rMin + (1 - a) * rMax;
126 }
double Mdouble
Definition: GeneralDefine.h:34
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
int PSD::getInsertedParticleNumber ( ) const

Get the number of particles already inserted into the simulation.

Gets the number of particles already inserted into the simulation by summing up the particles inserted in each class.

Returns
An integer containing the number of particles already inserted into the simulation.

Definition at line 840 of file PSD.cc.

References nParticlesPerClass_.

Referenced by computeRawMomenta().

841 {
842  int sum = 0;
843  for (auto& it: nParticlesPerClass_)
844  sum += it;
845  return sum;
846 }
std::vector< int > nParticlesPerClass_
Definition: PSD.h:314
Mdouble PSD::getMaxRadius ( ) const

Get largest radius of the PSD.

Gets the maximum radius of the PSD.

Returns
A double which corresponds to the maximum radius of the PSD.

Definition at line 812 of file PSD.cc.

Referenced by getSizeRatio().

813 {
814  return particleSizeDistribution_.back().radius;
815 }
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
Mdouble PSD::getMinRadius ( ) const

Get smallest radius of the PSD.

Gets the minimal radius of the PSD.

Returns
A double which corresponds to the minimal radius of the PSD.

Definition at line 803 of file PSD.cc.

Referenced by getSizeRatio().

804 {
805  return particleSizeDistribution_[0].radius;
806 }
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
std::array< Mdouble, 6 > PSD::getMomenta ( ) const

get momenta of the user defined PSD.

Get momenta of the user defined particleSizeDistributionVector_ vector.

Returns
Array of momenta corresponding to the first six moments of the user defined PSD.

Definition at line 903 of file PSD.cc.

References momenta_.

904 {
905  return momenta_;
906 }
std::array< Mdouble, 6 > momenta_
Definition: PSD.h:307
Mdouble PSD::getNumberDx ( Mdouble  x) const

Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the number based PSD.

Gets the diameter from a certain percentile of the number based PSD.

Returns
A double which is the diameter corresponding to a certain percentile.
Parameters
[in]xdouble which determines the obtained diameter as a percentile of the PSD.

Definition at line 720 of file PSD.cc.

References getRadiusByQuantile().

Referenced by cutoffAndSqueezeCumulative().

721 {
722  return 2.0 * getRadiusByQuantile(x / 100);
723 }
Mdouble getRadiusByQuantile(Mdouble quantile) const
Calculate the quantile of the PSD.
Definition: PSD.cc:744
std::vector< PSD::RadiusAndProbability > PSD::getParticleSizeDistribution ( ) const

Get the PSD vector.

Gets the vector containing radii and probabilities of the PSD.

Returns
A vector containing radii and probabilities of the PSD.

Definition at line 821 of file PSD.cc.

References particleSizeDistribution_.

822 {
824 }
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
Mdouble PSD::getRadiusByQuantile ( Mdouble  quantile) const

Calculate the quantile of the PSD.

gets the radius from a certain quantile of the PSD

Returns
A double which is the radius corresponding to a certain quantile of the PSD.
Parameters
[in]quantiledouble which determines the returned radius as a quantile of the PSD.

Definition at line 744 of file PSD.cc.

References logger.

Referenced by cutoffCumulativeNumber(), getNumberDx(), and getVolumeDx().

745 {
746  logger.assert_always(quantile <= 1 && quantile >= 0, "quantile is not between 0 and 1");
747  // find the quantile corresponding to the PSD
748  auto high = std::lower_bound(particleSizeDistribution_.begin(), particleSizeDistribution_.end(), quantile);
749  auto low = std::max(particleSizeDistribution_.begin(), high - 1);
750  if (high->probability == low->probability)
751  return high->radius;
752  else
753  return low->radius + (high->radius - low->radius) * (quantile - low->probability) /
754  (high->probability - low->probability);
755 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
Mdouble PSD::getSizeRatio ( ) const

get the size ratio (width) of the PSD.

Gets the size ratio (width) of the PSD defined by the ratio of minimum to maximum particle radius.

Returns
A double which corresponds to the size ratio of the PSD.

Definition at line 778 of file PSD.cc.

References getMaxRadius(), and getMinRadius().

Referenced by cutHighSizeRatio(), cutoffCumulativeNumber(), and setPSDFromCSV().

779 {
780  Mdouble rMin = getMaxRadius();
781  Mdouble rMax = getMinRadius();
782  return rMin / rMax;
783 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMinRadius() const
Get smallest radius of the PSD.
Definition: PSD.cc:803
Mdouble getMaxRadius() const
Get largest radius of the PSD.
Definition: PSD.cc:812
Mdouble PSD::getVolumeDx ( Mdouble  x) const

Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the volume based PSD.

Gets the diameter from a certain percentile of the volume based PSD.

Returns
A double which is the diameter corresponding to a certain percentile.
Parameters
[in]xdouble which determines the obtained diameter as a percentile of the PSD.

Definition at line 730 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution(), convertProbabilityDensityToCumulative(), and getRadiusByQuantile().

731 {
732  PSD psd = *this;
736  return 2.0 * psd.getRadiusByQuantile(x / 100);
737 }
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution()
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Definition: PSD.cc:584
Mdouble getRadiusByQuantile(Mdouble quantile) const
Calculate the quantile of the PSD.
Definition: PSD.cc:744
void convertCumulativeToProbabilityDensity()
Converts a CDF to a PDF by derivation.
Definition: PSD.cc:502
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD) ...
Definition: PSD.h:62
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:487
Mdouble PSD::getVolumetricMeanRadius ( ) const

get a volumetric mean radius of the PSD.

Gets a radius such that a monodisperse system has the same number of particles as a polydisperse system. (i.e. mean += p_i * 0.5*(r_i^3 + r_i-1^3)

Returns
A double which corresponds to the volumetric mean radius.

Definition at line 762 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution(), and mathsFunc::cubic().

763 {
764  PSD psd = *this;
767  Mdouble mean = 0;
768  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
769  mean += it->probability * 0.5 * (cubic(it->radius) + cubic((it - 1)->radius));
770  mean = pow(mean, 1. / 3.);
771  return mean;
772 }
double Mdouble
Definition: GeneralDefine.h:34
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution()
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Definition: PSD.cc:584
T cubic(const T val)
calculates the cube of a number
Definition: ExtendedMath.h:115
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void convertCumulativeToProbabilityDensity()
Converts a CDF to a PDF by derivation.
Definition: PSD.cc:502
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD) ...
Definition: PSD.h:62
Mdouble PSD::insertManuallyByVolume ( Mdouble  volume)

Draw sample radius manually per size class and check the volumeAllowed of each size class to insert the PSD as accurate as possible.

Draws a sample probability of a real uniform distribution within a given size class. A random number is generated in the size class range [r_i,r_i+1] and by linear interpolation a suitable radius is returned. from a CUMULATIVE_VOLUME_DISTRIBUTION the volumeAllowed of each class is checked to insert the PSD as accurate as possible. This function is only valid for cumulativeNumberDistributions as particles are drawn and not volumes, areas or lengths. Furthermore this insertion routine is most accurate for non-continuous particle insertion.

Parameters
[in]volumevolume of the geometry to be filled.
Returns
A Radius for a randomly assigned probability of a specific size class.

Definition at line 137 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), nParticlesPerClass_, particleSizeDistribution_, constants::pi, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and volumePerClass_.

138 {
139  // initialize the particleNumberPerClass vector if empty.
140  if (nParticlesPerClass_.empty())
142  // initialize the particleNumberPerClass vector if empty.
143  if (volumePerClass_.empty())
145 
146  for (auto it = particleSizeDistribution_.end() - 1; it != particleSizeDistribution_.begin(); --it)
147  {
148  static std::mt19937 gen(0);
149  static std::uniform_real_distribution<Mdouble> dist(0, 1);
150  Mdouble prob = dist(gen);
151  // map the probability to the current class interval
152  prob = (it - 1)->probability + (it->probability - (it - 1)->probability) * prob;
153  // find the interval [low,high] of the psd in which the number sits
154  auto high = std::lower_bound(particleSizeDistribution_.begin(), particleSizeDistribution_.end(), prob);
155  auto low = std::max(particleSizeDistribution_.begin(), high - 1);
156  Mdouble rMin = low->radius;
157  Mdouble rMax = high->radius;
158  Mdouble pMin = low->probability;
159  Mdouble pMax = high->probability;
160  // interpolate linearly between [low.radius,high.radius] (assumption: CDF is piecewise linear)
161  int index = std::distance(particleSizeDistribution_.begin(), high);
162  Mdouble a = (prob - pMin) / (pMax - pMin);
163  Mdouble rad = a * rMin + (1 - a) * rMax;
164  // Compare inserted volume against volumeAllowed
165  Mdouble radVolume = 4.0 / 3.0 * constants::pi * rad * rad * rad;
168  Mdouble volumeAllowed = particleSizeDistribution_[index].probability * volume;
171  if (volumePerClass_[index] > volumeAllowed)
172  {
173  continue;
174  }
175  else if (radVolume + volumePerClass_[index] > volumeAllowed)
176  {
177  Mdouble differenceVolumeLow = -(volumePerClass_[index] - volumeAllowed);
178  Mdouble differenceVolumeHigh = radVolume + volumePerClass_[index] - volumeAllowed;
179  Mdouble volumeRatio = differenceVolumeLow / differenceVolumeHigh;
180  // If volumeRatio > 1 it will insert anyways, because it should be no problem for the distribution
181  prob = dist(gen);
182  if (prob <= volumeRatio)
183  {
184  ++nParticlesPerClass_[index];
185  volumePerClass_[index] += radVolume;
186  return rad;
187  }
188  else
189  {
190  continue;
191  }
192  }
193  else
194  {
195  ++nParticlesPerClass_[index];
196  volumePerClass_[index] += radVolume;
197  return rad;
198  }
199  }
200  return 0;
201 }
double Mdouble
Definition: GeneralDefine.h:34
std::vector< int > nParticlesPerClass_
Definition: PSD.h:314
void convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution()
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Definition: PSD.cc:584
const Mdouble pi
Definition: ExtendedMath.h:45
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
std::vector< Mdouble > volumePerClass_
Definition: PSD.h:323
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
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:487
void PSD::printPSD ( ) const

Prints radii and probabilities of the PSD vector.

Prints the radii [m] and probabilities [%] of the psd vector. It currently supports nanometers, micrometers, milimeters and meters as size units.

Definition at line 71 of file PSD.cc.

References INFO, logger, and particleSizeDistribution_.

72 {
73  if (particleSizeDistribution_.front().radius > 1e-1)
74  {
75  for (const auto p : particleSizeDistribution_)
76  {
77  logger(INFO, "%m\t %\%", p.radius, p.probability * 100);
78  }
79  }
80  else if (particleSizeDistribution_.front().radius > 1e-4)
81  {
82  for (const auto p : particleSizeDistribution_)
83  {
84  logger(INFO, "%mm\t %\%", p.radius * 1000, p.probability * 100);
85  }
86  }
87  else if (particleSizeDistribution_.front().radius > 1e-7)
88  {
89  for (const auto p : particleSizeDistribution_)
90  {
91  logger(INFO, "%um\t %\%", p.radius * 1e6, p.probability * 100);
92  }
93  }
94  else
95  {
96  for (const auto p : particleSizeDistribution_)
97  {
98  logger(INFO, "%nm\t %\%", p.radius * 1e9, p.probability * 100);
99  }
100  }
101 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::setDistributionNormal ( Mdouble  mean,
Mdouble  standardDeviation,
int  numberOfBins 
)

create a PSD vector for a normal distribution.

sets the particle size distribution to a discretised normal (gaussian) cumulative number distribution, which covers the range of 3 * standardDeviation (99,73% of all values covered).

Parameters
[in]meanDouble representing the mean of the particle size distribution
[in]standardDeviationDouble representing the standard deviation of the particle size distribution
[in]numberOfBinsInteger determining the number of bins (aka. particle size classes or resolution) of the particle size distribution

Definition at line 314 of file PSD.cc.

References constants::i, helpers::linspace(), logger, particleSizeDistribution_, and validateCumulativeDistribution().

315 {
316  logger.assert_always(mean > 3 * standardDeviation,
317  "Reduce standardDeviation of your normal distribution to avoid negative radii; The mean "
318  "should be greater than 3*standardDeviation");
319  if (!particleSizeDistribution_.empty())
320  {
322  }
323  Mdouble radMin = mean - 3 * standardDeviation;
324  Mdouble radMax = mean + 3 * standardDeviation;
325  std::vector<Mdouble> radii = helpers::linspace(radMin, radMax, numberOfBins);
326  std::vector<Mdouble> probabilities;
327  for (int i = 0; i < radii.size(); i++)
328  {
329  Mdouble probability = 0.5 * (1 + erf((radii[i] - mean) / (sqrt(2) * standardDeviation)));
330  probabilities.push_back(probability);
331  }
332  for (int j = 0; j < radii.size(); j++)
333  {
334  particleSizeDistribution_.push_back({radii[j], probabilities[j]});
335  }
337 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
std::vector< Mdouble > linspace(Mdouble a, Mdouble b, int N)
Definition: Helpers.cc:887
void PSD::setDistributionUniform ( Mdouble  radMin,
Mdouble  radMax,
int  numberOfBins 
)

create a PSD vector for a uniform distribution.

sets the particle size distribution to a discretised uniform (linear) cumulative number distribution

Parameters
[in]radMinDouble representing The smallest particle radius of the particle size distribution
[in]radMaxDouble representing the biggest particle radius of the particle size distribution
[in]numberOfBinsInteger determining the number of bins (aka. particle size classes or resolution) of the particle size distribution

Definition at line 290 of file PSD.cc.

References constants::i, helpers::linspace(), particleSizeDistribution_, and validateCumulativeDistribution().

Referenced by CubeInsertionBoundary::set(), Chute::setupInitialConditions(), and ChuteWithHopper::setupInitialConditions().

291 {
292  if (!particleSizeDistribution_.empty())
293  {
295  }
296  std::vector<Mdouble> probabilities = helpers::linspace(0.0, 1.0, numberOfBins);
297  std::vector<Mdouble> radii = helpers::linspace(radMin, radMax, numberOfBins);
298  // combine radii and probabilities
299  for (int i = 0; i < radii.size(); ++i)
300  {
301  particleSizeDistribution_.push_back({radii[i], probabilities[i]});
302  }
304 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
std::vector< Mdouble > linspace(Mdouble a, Mdouble b, int N)
Definition: Helpers.cc:887
void PSD::setParticleSizeDistribution ( std::vector< RadiusAndProbability particleSizeDistribution)

set the PSD by a suitable vector.

sets the PSD from a vector of the PSD::RadiusAndProbability class; used to read in PSDs from a restart file.

Parameters
[in]particleSizeDistributionvector containing the radii and probabilities specifying the PSD.

Definition at line 830 of file PSD.cc.

831 {
832  particleSizeDistribution_ = particleSizeDistribution;
833 }
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::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.

creates the PSD vector from probabilities and radii saved in a .csv file. Radii should be located at the first column and probabilities at the second column of the file. The Type of PSD will be converted to the default cumulative number distribution function (CUMULATIVE_NUMBER_DISTRIBUTION) for further processing.

Parameters
[in]fileNameName of the .csv file containing the radii and probabilities of the PSD.
[in]PSDTypeType of the PSD: CUMULATIVE_VOLUME_DISTRIBUTION, CUMULATIVE_NUMBER_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_AREA_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION PROBABILITYDENSITY_AREA_DISTRIBUTION.
[in]headingsIf TRUE the file is assumed to have headings and the first row will be skipped. If FALSE the file has no headings and the file will be read in as is. Default is FALSE.
[in]unitScalingFactorRadiiScaling factor of radii to match SI-units.

Definition at line 418 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, csvReader::getFirstColumn(), csvReader::getSecondColumn(), getSizeRatio(), constants::i, INFO, logger, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, csvReader::read(), csvReader::setHeader(), validateCumulativeDistribution(), and validateProbabilityDensityDistribution().

419 {
420  // read in csv file using the csvReader class
421  csvReader csv;
422  csv.setHeader(headings);
423  csv.read(fileName);
424  std::vector<Mdouble> radii = csv.getFirstColumn(unitScalingFactorRadii);
425  std::vector<Mdouble> probabilities = csv.getSecondColumn(1.0);
426  logger.assert_always(radii.size() == probabilities.size(), "The radii and probabilities vector have to be the "
427  "same size");
428  // combine radii and probabilities
429  for (int i = 0; i < radii.size(); ++i)
430  {
431  particleSizeDistribution_.push_back({radii[i], probabilities[i]});
432  }
433  logger.assert_always(!particleSizeDistribution_.empty(), "PSD cannot be empty");
434  switch (PSDType)
435  {
436  // default case is a CUMULATIVE_NUMBER_DISTRIBUTION
437  default:
439  break;
446  break;
452  break;
459  break;
463  break;
468  break;
473  break;
478  break;
479  }
480  logger(INFO, "A PSD with size ratio % is now ready to be set", getSizeRatio());
481 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
void read(const std::string &filename)
Reads .csv files into Mercury.
Definition: csvReader.cc:40
void setHeader(bool headings)
Set the boolean hasHeader_.
Definition: csvReader.cc:109
void validateProbabilityDensityDistribution()
Validates if the integral of the PDF equals to unity.
Definition: PSD.cc:251
std::vector< Mdouble > getFirstColumn(Mdouble scalingFactor)
Get first column of a .csv file and return it as a double.
Definition: csvReader.cc:128
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
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 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
std::vector< Mdouble > getSecondColumn(Mdouble scalingFactor)
Get second column of a .csv file and return it as a double.
Definition: csvReader.cc:145
Enables reading of .csv files into MercuryDPM.
Definition: csvReader.h:45
MERCURY_DEPRECATED void PSD::setPSDFromVector ( std::vector< RadiusAndProbability psdVector,
TYPE  PSDType 
)

Deprecated version of reading in PSDs from a vector.

creates the psd vector from radii and probabilities filled in by hand. The Type of PSD will be converted to the default cumulative number distribution function (CUMULATIVE_NUMBER_DISTRIBUTION) for further processing.

Parameters
[in]psdVectorVector containing radii and probabilities ([0,1]).
[in]PSDTypeType of the PSD: CUMULATIVE_VOLUME_DISTRIBUTION, CUMULATIVE_NUMBER_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_AREA_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_AREA_DISTRIBUTION.
Deprecated:
This is the old way of inserting PSDs. In the future use setPSDFromCSV().

Definition at line 352 of file PSD.cc.

References convertCumulativeToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, validateCumulativeDistribution(), and validateProbabilityDensityDistribution().

353 {
354  particleSizeDistribution_ = psdVector;
355  switch (PSDType)
356  {
357  // default case is a cumulative number distribution (CND)
358  default:
360  break;
367  break;
374  break;
380  break;
385  break;
389  break;
394  break;
399  break;
400  }
401 }
void validateCumulativeDistribution()
Validates if a CDF starts with zero and adds up to unity.
Definition: PSD.cc:210
void validateProbabilityDensityDistribution()
Validates if the integral of the PDF equals to unity.
Definition: PSD.cc:251
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
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
void convertProbabilityDensityToCumulative()
Converts a PDF to a CDF by integration.
Definition: PSD.cc:487
void PSD::validateCumulativeDistribution ( )

Validates if a CDF starts with zero and adds up to unity.

Validates if a distribution is cumulative by first checking if the psd vector is empty and that the scaling of probabilities is in the range [0,1]. Also it checks if each consecutive value is higher than the latter value (i.e. assuming piecewise linear CDF: p_i > p_i-1). Further it replaces probabilities if the CDF does not start with zero or does not end with unity (i.e. p_0=0 and p_end=1)

Definition at line 210 of file PSD.cc.

References constants::i, INFO, logger, and particleSizeDistribution_.

Referenced by convertProbabilityDensityToCumulative(), setDistributionNormal(), setDistributionUniform(), setPSDFromCSV(), and setPSDFromVector().

211 {
212  // ensure interval of probabilities to be [0,1]
213  for (auto p = 0; p < particleSizeDistribution_.size(); ++p)
214  particleSizeDistribution_[p].probability =
215  particleSizeDistribution_[p].probability / particleSizeDistribution_.back().probability;
216  // check whether the distribution is cumulative
217  for (auto it = particleSizeDistribution_.begin() + 1; it != particleSizeDistribution_.end(); ++it)
218  {
219  logger.assert_always(it->probability >= (it - 1)->probability, "psd is not cumulative", true);
220  }
221  // cdf needs to start with a probability of zero
222  if (particleSizeDistribution_[0].probability != 0)
223  {
224  logger(INFO, "adding a zero at the beginning of the psd");
226  {std::max(1e-3 * particleSizeDistribution_[0].radius,
227  2 * particleSizeDistribution_[0].radius -
228  particleSizeDistribution_[1].radius), 0});
229  }
230  // cdf needs to end with a probability of one
231  if (particleSizeDistribution_.back().probability < 1)
232  {
233  logger(INFO, "adding a one at the end of the psd");
234  particleSizeDistribution_.push_back({particleSizeDistribution_.back().radius, 1});
235  }
236  // cut off equal subsequent values on the end of the cdf to remove zero size classes.
237  for (auto i = particleSizeDistribution_.end() - 1; i != particleSizeDistribution_.begin(); i--)
238  {
239  if (i->probability == (i - 1)->probability)
240  {
242  .end(), i));
243  }
244  }
245 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301
void PSD::validateProbabilityDensityDistribution ( )

Validates if the integral of the PDF equals to unity.

Validates if a PDF is valid by first checking if the PDF starts with zero (i.e. p_0=0). Further it checks if the integral is equal to unity (i.e. assuming piecewise constant PDF: sum(p_i)=1).

Definition at line 251 of file PSD.cc.

References INFO, logger, and particleSizeDistribution_.

Referenced by convertCumulativeToProbabilityDensity(), setPSDFromCSV(), and setPSDFromVector().

252 {
253  Mdouble sum = 0;
254  // check if the psd starts with zero probability (i.e. p_0=0)
255  if (particleSizeDistribution_[0].probability != 0)
256  {
257  logger(INFO, "adding a zero at the beginning of PDF");
259  {std::max(1e-3 * particleSizeDistribution_[0].radius,
260  2 * particleSizeDistribution_[0].radius -
261  particleSizeDistribution_[1].radius), 0});
262  }
263  // sum up probabilities to check if it equals to unity (sum(p_i)=1)
264  for (auto& it : particleSizeDistribution_)
265  {
266  sum += it.probability;
267  }
268  // ensure interval of probabilities to be [0,1] by normalization.
269  for (auto& it : particleSizeDistribution_)
270  it.probability /= sum;
271  // if the sum of probabilities is not equal to unity, sum up the normalized probabilities again
272  if (sum - 1 > 1e-6)
273  {
274  sum = 0;
275  for (auto& it: particleSizeDistribution_)
276  {
277  sum += it.probability;
278  }
279  }
280  logger.assert_debug(sum - 1 < 1e-6, "PDF is not valid: Integral of PDF is not equal to unity");
281 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
std::vector< RadiusAndProbability > particleSizeDistribution_
Definition: PSD.h:301

Friends And Related Function Documentation

bool operator< ( const PSD::RadiusAndProbability l,
const PSD::RadiusAndProbability r 
)
friend

determines if a certain value of the PSD vector is lower than another one. Used for std::lower_bound()

Required to use std::lower_bound for finding when the probability is higher than a certain value.

Returns
TRUE if probability from a vector of type PSD::RadiusAndProbability is higher than a certain value from a vector of type PSD::RadiusAndProbability and FALSE in the opposite case.

Definition at line 913 of file PSD.cc.

914 {
915  return l.probability < r.probability;
916 }
Mdouble probability
Definition: PSD.h:90
bool operator< ( const PSD::RadiusAndProbability l,
Mdouble  r 
)
friend

determines if a certain value of the PSD vector is lower than a double.

required to use std::lower_bound for finding when the probability provided as a double is higher than a certain value.

Returns
TRUE if probability as double is higher than a certain value from a PSD::RadiusAndProbability vector and FALSE in the opposite case.

Definition at line 924 of file PSD.cc.

925 {
926  return l.probability < prob;
927 }
Mdouble probability
Definition: PSD.h:90
std::ostream& operator<< ( std::ostream &  os,
PSD::RadiusAndProbability p 
)
friend

Writes to output stream.

Writes to output stream. This function is used for restart files.

Returns
a reference to an output stream.

Definition at line 953 of file PSD.cc.

954 {
955  os << p.radius << ' ' << p.probability << ' ';
956  return os;
957 }
Mdouble probability
Definition: PSD.h:90
Mdouble operator== ( PSD::RadiusAndProbability  l,
Mdouble  r 
)
friend

Determines if a certain value of the PSD vector is equal to a double.

Required to use std::distance to find the index of the PSD size class in which a particle has to be inserted

Returns
A double which determines the size class (radius) a particle will be inserted to.

Definition at line 933 of file PSD.cc.

934 {
935  return l.radius == r;
936 }
std::istream& operator>> ( std::istream &  is,
PSD::RadiusAndProbability p 
)
friend

Reads from input stream.

reads from input stream. This function is used for restart files.

Returns
a reference to an input stream.

Definition at line 942 of file PSD.cc.

943 {
944  is >> p.radius;
945  is >> p.probability;
946  return is;
947 }
Mdouble probability
Definition: PSD.h:90

Member Data Documentation

std::array<Mdouble, 6> PSD::momenta_ {}
private

Array of doubles which stores the moments of a user defined discrete PROBABILITYDENSITY_NUMBER_DISTRIBUTION.

Todo:
TW can we make this a local variable instead of a class variable?

Definition at line 307 of file PSD.h.

Referenced by computeCentralMomenta(), computeRawMomenta(), computeStandardisedMomenta(), getMomenta(), and PSD().

std::vector<int> PSD::nParticlesPerClass_
private

Vector of integers which represents the number of inserted particles in each size class. The classes in this vector are defined to contain the particles between size r_i and r_i-1. (e.g. size class 12 consists of particles between size class 12 and 11 of the PDF)

Definition at line 314 of file PSD.h.

Referenced by getInsertedParticleNumber(), and insertManuallyByVolume().

std::vector<Mdouble> PSD::volumePerClass_
private

Vector of doubles which stores the volume of inserted particles for each size class. This vector is used in the insertManuallyByVolume() function to check if the volumeAllowed per class is exceeded and thus no further particles should be added to a certain class. The classes in this vector are defined to contain the volume of particles between size r_i and r_i-1. (e.g. size class 12 consists of the particles' volume between size class 12 and 11 of the PDF)

Definition at line 323 of file PSD.h.

Referenced by insertManuallyByVolume().


The documentation for this class was generated from the following files: