![]() |
|
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD) More...
#include <PSD.h>
Public Types | |
enum class | TYPE { CUMULATIVE_NUMBER_DISTRIBUTION , CUMULATIVE_LENGTH_DISTRIBUTION , CUMULATIVE_VOLUME_DISTRIBUTION , CUMULATIVE_AREA_DISTRIBUTION , PROBABILITYDENSITY_NUMBER_DISTRIBUTION , PROBABILITYDENSITY_LENGTH_DISTRIBUTION , PROBABILITYDENSITY_AREA_DISTRIBUTION , 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 (std::unique_ptr< PSD > psdPtr) | |
Constructor; sets everything to 0 or default. This constructor is mainly used in MercuryPBM where smart pointers are used. More... | |
PSD (const PSD &other) | |
Copy constructor with deep copy. More... | |
~PSD () | |
Destructor; default destructor. More... | |
PSD * | copy () 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... | |
void | setPSDFromVector (std::vector< DistributionElements > psd, TYPE PSDType) |
Sets the PSD from a vector with DistributionElements. 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 | setDistributionLogNormal (Mdouble mean, Mdouble standardDeviation, int numberOfBins) |
create a PSD vector for a normal distribution. More... | |
void | setDistributionPhiNormal (Mdouble D50, Mdouble standardDeviationinPhi, int numberOfBins) |
create a PSD vector for a normal distribution in Phi Units that has the demanded D50. 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 | convertProbabilityDensityNumberDistributionToProbabilityDensity (TYPE PDFType) |
Convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to any PDF. More... | |
MERCURYDPM_DEPRECATED void | convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution () |
convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to a PROBABILITYDENSITY_VOLUME_DISTRIBUTION. More... | |
void | convertCumulativeToCumulativeNumberDistribution (TYPE CDFType) |
Convert any CDF to a CUMULATIVE_NUMBER_DISTRIBUTION. More... | |
void | convertCumulativeNumberDistributionToCumulative (TYPE CDFType) |
Convert a CUMULATIVE_NUMBER_DISTRIBUTION to any CDF. More... | |
MERCURYDPM_DEPRECATED void | cutoffCumulativeNumber (Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity=0.1) |
cutoff the PSD at given quantiles. More... | |
void | cutoffCumulativeDistribution (TYPE CDFType, Mdouble quantileMin, Mdouble quantileMax, Mdouble minPolydispersity=0.1) |
Cut off the PSD at the given quantiles, with the PSD in the provided CDF form. More... | |
MERCURYDPM_DEPRECATED 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... | |
void | cutoffAndSqueezeCumulativeDistribution (TYPE CDFType, Mdouble quantileMin, Mdouble quantileMax, Mdouble squeeze, Mdouble minPolydispersity=0.1) |
Cut off the PSD at the given quantiles, with the PSD in the provided CDF form, and make it less polydisperese 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< DistributionElements > | getParticleSizeDistribution () const |
Get the PSD vector. More... | |
std::vector< DistributionElements > | getParticleSizeDistributionByType (TYPE psdType, Mdouble scalingFactor=1.0) const |
Gets the PSD vector, converted to the preferred type. More... | |
MERCURYDPM_DEPRECATED void | setParticleSizeDistribution (std::vector< DistributionElements >) |
set the PSD by a suitable vector. More... | |
void | scaleParticleSize (double scale) |
Scales all particle sizes by a factor. More... | |
double | scaleParticleSizeAuto (int numberOfParticles, double targetVolume, bool allowScaleDown=false) |
Scales all particle sizes, such that the total volume of N particles approximately equals the target volume. More... | |
int | getInsertedParticleNumber () const |
Get the number of particles already inserted into the simulation. More... | |
void | decrementNParticlesPerClass () |
Decrement nParticlesPerClass_ counter. More... | |
void | decrementVolumePerClass (Mdouble volume) |
Decrement volumePerClass_ counter. More... | |
Mdouble | getRadius (int index) const |
get a radius at a certain index of the particleSizeDistribution_ 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 | getLengthDx (Mdouble x) const |
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the length based PSD. More... | |
Mdouble | getAreaDx (Mdouble x) const |
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the area 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 | getQuantileByRadius (Mdouble radius) const |
Calculates the quantile corresponding to a certain radius. 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... | |
std::vector< std::pair< Mdouble, Mdouble > > | convertPdfPhiToPdfMeter (Mdouble meaninPhi, Mdouble standardDeviationinPhi, int numberOfBins) |
compute central momenta of the user defined PSD. / void computeCentralMomenta(); More... | |
Mdouble | computeD50 (std::vector< std::pair< Mdouble, Mdouble > > vectorOfPair) |
compute the mass-based D_50 of the paired diameter and probabilityDensity. More... | |
void | setFixedSeed (int seed) |
set a fixed seed for the random number generator; this is used for the PSDSelfTest to reproduce results More... | |
Static Public Member Functions | |
static PSD | getDistributionNormal (Mdouble mean, Mdouble standardDeviation, int numberOfBins) |
static PSD | getDistributionLogNormal (Mdouble mean, Mdouble standardDeviation, int numberOfBins) |
static std::vector< Mdouble > | linspace (Mdouble Min, Mdouble Max, int numberOfBins) |
create a vector of linearly spaced values. More... | |
Private Attributes | |
std::vector< DistributionElements > | particleSizeDistribution_ |
std::vector< int > | nParticlesPerClass_ |
std::vector< Mdouble > | volumePerClass_ |
int | index_ |
RNG | random_ |
Friends | |
bool | operator< (const DistributionElements &l, const DistributionElements &r) |
determines if a certain value of the PSD vector is lower than another one. Used for std::lower_bound() More... | |
bool | operator< (const DistributionElements &l, Mdouble r) |
determines if a certain value of the PSD vector is lower than a double. More... | |
std::ostream & | operator<< (std::ostream &os, DistributionElements &p) |
Writes to output stream. More... | |
std::istream & | operator>> (std::istream &is, DistributionElements &p) |
Reads from input stream. More... | |
Mdouble | operator== (DistributionElements l, Mdouble r) |
Determines if a certain value of the PSD vector is equal to a double. More... | |
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 DistributionElements 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.
|
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.
PSD::PSD | ( | ) |
Constructor; sets everything to 0 or default.
Default constructor; sets every data member to 0 or default.
References index_, random_, and RNG::setRandomSeed().
Referenced by copy().
|
inline |
Constructor; sets everything to 0 or default. This constructor is mainly used in MercuryPBM where smart pointers are used.
[in] | psdPtr | smart pointer to a PSD object. |
PSD::PSD | ( | const PSD & | other | ) |
Copy constructor with deep copy.
Copy constructor
References index_, particleSizeDistribution_, and random_.
|
default |
Destructor; default destructor.
Destructor. Since there are no pointers in this class, there is no need for any actions here.
compute the mass-based D_50 of the paired diameter and probabilityDensity.
computes the mass-based D50 of the paired diameter and probabilityDensity
[in] | vectorOfPair | vector of pair containing paired data of diameter and probabilityDensity |
References boost::multiprecision::fabs(), i, j, Eigen::bfloat16_impl::pow(), and V.
Referenced by setDistributionPhiNormal().
void PSD::convertCumulativeNumberDistributionToCumulative | ( | TYPE | CDFType | ) |
Convert a CUMULATIVE_NUMBER_DISTRIBUTION to any CDF.
CDFType | The CDF type to convert to. |
References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensity(), convertProbabilityDensityToCumulative(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_NUMBER_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, ERROR, logger, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, and PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Referenced by cutoffCumulativeDistribution(), getAreaDx(), getLengthDx(), and getVolumeDx().
void PSD::convertCumulativeToCumulativeNumberDistribution | ( | TYPE | CDFType | ) |
Convert any CDF to a CUMULATIVE_NUMBER_DISTRIBUTION.
Converts any of the CDFTypes to a the default CUMULATIVE_NUMBER_DISTRIBUTION based on their TYPE.
[in] | CDFType | Type of the PDF: CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_AREA_DISTRIBUTION or CUMULATIVE_VOLUME_DISTRIBUTION. |
References convertCumulativeToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_NUMBER_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, ERROR, logger, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, and PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Referenced by cutoffCumulativeDistribution().
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).
References particleSizeDistribution_, and validateProbabilityDensityDistribution().
Referenced by convertCumulativeNumberDistributionToCumulative(), convertCumulativeToCumulativeNumberDistribution(), getParticleSizeDistributionByType(), getVolumetricMeanRadius(), insertManuallyByVolume(), and setPSDFromVector().
std::vector< std::pair< Mdouble, Mdouble > > PSD::convertPdfPhiToPdfMeter | ( | Mdouble | meanInPhi, |
Mdouble | standardDeviationInPhi, | ||
int | numberOfBins | ||
) |
compute central momenta of the user defined PSD. / void computeCentralMomenta();
\brief compute raw momenta of the user defined PSD. ‍/
void computeRawMomenta();
/*!
/*!
compute standardised momenta of the user defined PSD. / void computeStandardisedMomenta();
/*!
get momenta of the user defined PSD. / std::array<Mdouble, 6> getMomenta() const;
/*!
convert the probabilityDensity of diameter in Phi to the probabilityDensity of diameter in Meter.
generates a normal particle size distribution in Phi units and converts it to the distribution in meters.
[in] | meanInPhi | Double representing the mean diameter of the particle size distribution in phi units |
[in] | standardDeviationInPhi | Double representing the standard deviation of the particle size distribution (diameter) in phi units |
[in] | numberOfBins | Integer determining the number of bins (aka. particle size classes or resolution) of the particle size distribution |
References D, Eigen::bfloat16_impl::exp(), boost::multiprecision::fabs(), i, helpers::linspace(), constants::pi, Eigen::bfloat16_impl::pow(), and sqrt().
Referenced by setDistributionPhiNormal().
void PSD::convertProbabilityDensityNumberDistributionToProbabilityDensity | ( | TYPE | PDFType | ) |
Convert a PROBABILITYDENSITY_NUMBER_DISTRIBUTION to any PDF.
This is a helper function to have full flexibility in converting from a PROBABILITYDENSITY_NUMBER_DISTRIBUTION type to any other PDF type. This can be useful e.g. when wanting to output the PSD with a certain type.
PDFType | The PDF type to convert to. |
References ERROR, logger, p, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and Eigen::square().
Referenced by convertCumulativeNumberDistributionToCumulative(), convertProbabilityDensityNumberDistributionToProbabilityDensityVolumeDistribution(), getParticleSizeDistributionByType(), getVolumetricMeanRadius(), and insertManuallyByVolume().
MERCURYDPM_DEPRECATED 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().
References convertProbabilityDensityNumberDistributionToProbabilityDensity(), and PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
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).
References particleSizeDistribution_, and validateCumulativeDistribution().
Referenced by convertCumulativeNumberDistributionToCumulative(), convertCumulativeToCumulativeNumberDistribution(), getParticleSizeDistributionByType(), insertManuallyByVolume(), setDistributionPhiNormal(), and setPSDFromVector().
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).
[in] | PDFType | Type of the PDF: PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_AREA_DISTRIBUTION or PROBABILITYDENSITY_VOLUME_DISTRIBUTION. |
References ERROR, logger, p, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and Eigen::square().
Referenced by convertCumulativeToCumulativeNumberDistribution(), insertManuallyByVolume(), and setPSDFromVector().
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.
References PSD().
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.
References CUMULATIVE_NUMBER_DISTRIBUTION, cutoffCumulativeDistribution(), getSizeRatio(), logger, and WARN.
|
inline |
cutoff the PSD at given quantiles and make it less polydisperse by squeezing it.
References CUMULATIVE_NUMBER_DISTRIBUTION, and cutoffAndSqueezeCumulativeDistribution().
void PSD::cutoffAndSqueezeCumulativeDistribution | ( | PSD::TYPE | CDFType, |
Mdouble | quantileMin, | ||
Mdouble | quantileMax, | ||
Mdouble | squeeze, | ||
Mdouble | minPolydispersity = 0.1 |
||
) |
Cut off the PSD at the given quantiles, with the PSD in the provided CDF form, and make it less polydisperese 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.
[in] | CDFType | The CDF form the PSD should have when applying the cut off and squeeze. |
[in] | quantileMin | Undersize quantile to cut off the lower part of the CDF. |
[in] | quantileMax | Oversize quantile to cut off the upper part of the CDF. |
[in] | squeeze | Applies a squeezing factor ([0,1]) which determines the degree the PDF gets squeezed. |
[in] | minPolydispersity | Applies a minimum polydispersity ([0,1]) at the base of the CDF. |
References CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_NUMBER_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, cutoffCumulativeDistribution(), ERROR, getAreaDx(), getLengthDx(), getNumberDx(), getVolumeDx(), logger, p, and particleSizeDistribution_.
Referenced by cutoffAndSqueezeCumulative().
void PSD::cutoffCumulativeDistribution | ( | PSD::TYPE | CDFType, |
Mdouble | quantileMin, | ||
Mdouble | quantileMax, | ||
Mdouble | minPolydispersity = 0.1 |
||
) |
Cut off the PSD at the given quantiles, with the PSD in the provided CDF form.
Cuts off the CDF at given minimum and maximum quantiles and applies a minimum polydispersity at the base.
[in] | CDFType | The CDF form the PSD should have when applying the cut off. |
[in] | quantileMin | Undersize quantile to cut off the lower part of the CDF. |
[in] | quantileMax | Oversize quantile to cut off the upper part of the CDF. |
[in] | minPolydispersity | Applies a minimum polydispersity ([0,1]) at the base of the CDF. |
References convertCumulativeNumberDistributionToCumulative(), convertCumulativeToCumulativeNumberDistribution(), getRadiusByQuantile(), getSizeRatio(), INFO, logger, max, min, and particleSizeDistribution_.
Referenced by cutHighSizeRatio(), cutoffAndSqueezeCumulativeDistribution(), and cutoffCumulativeNumber().
|
inline |
cutoff the PSD at given quantiles.
References CUMULATIVE_NUMBER_DISTRIBUTION, and cutoffCumulativeDistribution().
void PSD::decrementNParticlesPerClass | ( | ) |
Decrement nParticlesPerClass_ counter.
Decrement the nParticlesPerClass_ counter of the last inserted class by 1. This is utilized when a particle is generated but failed to be placed into an insertionBoundary.
References index_, and nParticlesPerClass_.
void PSD::decrementVolumePerClass | ( | Mdouble | volume | ) |
Decrement volumePerClass_ counter.
Decrement the volumePerClass_ counter of the last inserted class by the volume of the particle. This is utilized when a particle is generated but failed to be placed into an insertionBoundary.
[in] | volume | Volume of the particle which failed to be inserted. |
References index_, and volumePerClass_.
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.
References a, RNG::getRandomNumber(), max, particleSizeDistribution_, and random_.
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the area based PSD.
Gets the diameter from a certain percentile of the area based PSD.
[in] | x | double [0, 100] which determines the obtained diameter as a percentile of the PSD. |
References convertCumulativeNumberDistributionToCumulative(), CUMULATIVE_AREA_DISTRIBUTION, getRadiusByQuantile(), logger, and plotDoE::x.
Referenced by cutoffAndSqueezeCumulativeDistribution().
|
inlinestatic |
References setDistributionLogNormal().
Referenced by DistributionSelfTest::setupInitialConditions().
|
inlinestatic |
References setDistributionNormal().
Referenced by Material::setPSD(), Drum::setupInitialConditions(), and RotatingDrumWet::setupInitialConditions().
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.
References nParticlesPerClass_.
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the length based PSD.
Gets the diameter from a certain percentile of the length based PSD.
[in] | x | double [0, 100] which determines the obtained diameter as a percentile of the PSD. |
References convertCumulativeNumberDistributionToCumulative(), CUMULATIVE_LENGTH_DISTRIBUTION, getRadiusByQuantile(), logger, and plotDoE::x.
Referenced by cutoffAndSqueezeCumulativeDistribution().
Mdouble PSD::getMaxRadius | ( | ) | const |
Get largest radius of the PSD.
Gets the maximum radius of the PSD.
References particleSizeDistribution_.
Referenced by getSizeRatio(), GranuDrum::GranuDrum(), and GranuHeap::GranuHeap().
Mdouble PSD::getMinRadius | ( | ) | const |
Get smallest radius of the PSD.
Gets the minimal radius of the PSD.
References particleSizeDistribution_.
Referenced by getSizeRatio(), GranuHeap::GranuHeap(), Calibration::setSpecies(), and Material::setSpecies().
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.
[in] | x | double [0, 100] which determines the obtained diameter as a percentile of the PSD. |
References getRadiusByQuantile(), logger, and plotDoE::x.
Referenced by cutoffAndSqueezeCumulativeDistribution(), and GranuHeap::GranuHeap().
std::vector< DistributionElements > PSD::getParticleSizeDistribution | ( | ) | const |
Get the PSD vector.
Gets the vector containing radii and probabilities of the PSD.
References particleSizeDistribution_.
Referenced by getParticleSizeDistributionByType(), DistributionPhiNormalSelfTest::setupInitialConditions(), and SetDistributionPhiNormalSelfTest::setupInitialConditions().
std::vector< DistributionElements > PSD::getParticleSizeDistributionByType | ( | TYPE | PSDType, |
Mdouble | scalingFactor = 1.0 |
||
) | const |
Gets the PSD vector, converted to the preferred type.
This returns the PSD vector converted to the specified type, with an optional scale factor for the internal variable. This can be used e.g. to output the PSD with a certain type.
PSDType | The type the PSD should be. |
scalingFactor | The scale factor by which the the internal variable is multiplied. |
References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensity(), convertProbabilityDensityToCumulative(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, getParticleSizeDistribution(), PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, and PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
Referenced by ParticleHandler::saveNumberPSDtoCSV(), and testPSD().
Calculates the quantile corresponding to a certain radius.
Calculates the quantile corresponding to a certain radius.
radius | The radius to find the quantile for. |
References max, particleSizeDistribution_, UniformPSDSelfTest::radius, and Eigen::value.
get a radius at a certain index of the particleSizeDistribution_
\details Compute the raw momenta of the inserted PSD by converting it to a PDF, calculating the moments m_i according to \f$ m_i = \sum_{j=0}^n \f$ 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 <a href="https://en.wikipedia.org/wiki/Moment_(mathematics)#Significance_of_the_moments">Wikipedia</a> for details. ‍/
void PSD::computeRawMomenta() { convertCumulativeToProbabilityDensity(); for (size_t im = 0; im < momenta_.size(); ++im) { // prevent summing up of moments for each time step of the simulation momenta_[im] = 0; for (auto& it : particleSizeDistribution_) { momenta_[im] += std::pow(it.internalVariable, im) * it.probability; } } // zeroth-moment equals particle number for a PROBABILITYDENSITY_NUMBER_DISTRIBUTION momenta_[0] *= getInsertedParticleNumber(); convertProbabilityDensityToCumulative(); }
/*!
Compute the central momenta of the PSD from their respective raw momenta. / void PSD::computeCentralMomenta() { computeRawMomenta(); Mdouble mean = momenta_[1]; momenta_[5] += -5 * mean * momenta_[4] + 10 * mean * mean * momenta_[3]
/*!
Compute the standardised momenta of the PSD from their respective central momenta. / void PSD::computeStandardisedMomenta() { computeCentralMomenta(); Mdouble std = std::sqrt(momenta_[2]); momenta_[3] /= std * std * std; momenta_[4] /= std * std * std * std; momenta_[5] /= std * std * std * std * std; }
/*!
Gets the radius of a particle from the PSD.
[in] | i | An integer which is the index of the vector containing the radius. |
References particleSizeDistribution_.
Calculate the quantile of the PSD.
gets the radius from a certain quantile of the PSD
[in] | quantile | double which determines the returned radius as a quantile of the PSD. |
References logger, max, and particleSizeDistribution_.
Referenced by cutoffCumulativeDistribution(), getAreaDx(), getLengthDx(), getNumberDx(), and getVolumeDx().
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.
References getMaxRadius(), and getMinRadius().
Referenced by cutHighSizeRatio(), cutoffCumulativeDistribution(), and setPSDFromCSV().
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.
[in] | x | double [0, 100] which determines the obtained diameter as a percentile of the PSD. |
References convertCumulativeNumberDistributionToCumulative(), CUMULATIVE_VOLUME_DISTRIBUTION, getRadiusByQuantile(), logger, and plotDoE::x.
Referenced by cutoffAndSqueezeCumulativeDistribution(), GranuDrum::GranuDrum(), GranuHeap::GranuHeap(), Calibration::setSpecies(), and Material::setSpecies().
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)
References convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensity(), mathsFunc::cubic(), particleSizeDistribution_, Eigen::bfloat16_impl::pow(), and PROBABILITYDENSITY_VOLUME_DISTRIBUTION.
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.
[in] | volume | volume of the geometry to be filled. |
References a, convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), index_, max, nParticlesPerClass_, particleSizeDistribution_, constants::pi, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and volumePerClass_.
create a vector of linearly spaced values.
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.
References e(), INFO, logger, p, and particleSizeDistribution_.
void PSD::scaleParticleSize | ( | double | scale | ) |
Scales all particle sizes by a factor.
References p, and particleSizeDistribution_.
Referenced by scaleParticleSizeAuto().
double PSD::scaleParticleSizeAuto | ( | int | numberOfParticles, |
double | targetVolume, | ||
bool | allowScaleDown = false |
||
) |
Scales all particle sizes, such that the total volume of N particles approximately equals the target volume.
numberOfParticles | The number of particles N. |
targetVolume | The volume to match. |
allowScaleDown | Whether or not to scale down the particle sizes when the scale factor is smaller than 1. |
References Eigen::numext::cbrt(), INFO, logger, particleSizeDistribution_, constants::pi, Eigen::bfloat16_impl::pow(), and scaleParticleSize().
create a PSD vector for a normal distribution.
sets the particle size distribution to a discretised lognormal cumulative number distribution, which generates random values of radius following a lognormal distribution and iterates until the mass-based D50 is close to two times the user-defined mean radius.
[in] | mean | Double representing the mean of the particle size distribution in meters (radius) |
[in] | standardDeviation | Double representing the standard deviation of the particle size distribution in meters (radius) |
[in] | numberOfBins | Integer determining the number of bins (aka. particle size classes or resolution) of the particle size distribution See https://en.cppreference.com/w/cpp/numeric/random/lognormal_distribution |
References Eigen::bfloat16_impl::exp(), i, j, helpers::linspace(), p, particleSizeDistribution_, sqrt(), and validateCumulativeDistribution().
Referenced by getDistributionLogNormal().
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).
[in] | mean | Double representing the mean of the particle size distribution |
[in] | standardDeviation | Double representing the standard deviation of the particle size distribution |
[in] | numberOfBins | Integer determining the number of bins (aka. particle size classes or resolution) of the particle size distribution |
References i, j, helpers::linspace(), logger, particleSizeDistribution_, sqrt(), and validateCumulativeDistribution().
Referenced by getDistributionNormal(), and DistributionToPSDSelfTest::setupInitialConditions().
void PSD::setDistributionPhiNormal | ( | Mdouble | D50, |
Mdouble | standardDeviationInPhi, | ||
int | numberOfBins | ||
) |
create a PSD vector for a normal distribution in Phi Units that has the demanded D50.
sets the particle size distribution to a discretised cumulative number distribution, which is a normal distribution in phi units and has the demanded D50. D50 is the mass-based median grain size, while the Phi scale is a logarithmic scale computed by: Phi = -log2(1000*D). It can be used for visualizing sediment grain size distributions over a wide range of grain sizes. The combination of D50 and standardDeviation in Phi units is a representative measure of grain size distribution in the field of Sedimentology. Source: Donoghue, J.F. (2016). Phi Scale. In: Kennish, M.J. (eds) Encyclopedia of Estuaries. Encyclopedia of Earth Sciences Series. Springer, Dordrecht. https://doi.org/10.1007/978-94-017-8801-4_277
[in] | D50 | Double representing the mass-based D50 of the particle size distribution in meters |
[in] | standardDeviationInPhi | Double representing the standard deviation of the particle size distribution (diameter) in phi units |
[in] | numberOfBins | Integer determining the number of bins (aka. particle size classes or resolution) of the particle size distribution |
References computeD50(), convertPdfPhiToPdfMeter(), convertProbabilityDensityToCumulative(), e(), i, INFO, j, log2(), logger, particleSizeDistribution_, res, and validateCumulativeDistribution().
Referenced by DistributionPhiNormalSelfTest::setupInitialConditions(), and SetDistributionPhiNormalSelfTest::setupInitialConditions().
create a PSD vector for a uniform distribution.
sets the particle size distribution to a discretised uniform (linear) cumulative number distribution
[in] | radMin | Double representing The smallest particle radius of the particle size distribution |
[in] | radMax | Double representing the biggest particle radius of the particle size distribution |
[in] | numberOfBins | Integer determining the number of bins (aka. particle size classes or resolution) of the particle size distribution |
References i, helpers::linspace(), particleSizeDistribution_, and validateCumulativeDistribution().
Referenced by BoundariesSelfTest::BoundariesSelfTest(), FluxBoundarySelfTest::FluxBoundarySelfTest(), RandomClusterInsertionBoundary::set(), HopperInsertionBoundary::set(), CylinderInsertionBoundary::set(), SphereInsertionBoundary::set(), ChuteInsertionBoundary::set(), CubeInsertionBoundary::set(), InsertionBoundarySelfTest::setupInitialConditions(), FullRestartTest::setupInitialConditions(), Chute::setupInitialConditions(), ChuteWithHopper::setupInitialConditions(), and T_protectiveWall::T_protectiveWall().
|
inline |
set a fixed seed for the random number generator; this is used for the PSDSelfTest to reproduce results
References random_, and RNG::setRandomSeed().
void PSD::setParticleSizeDistribution | ( | std::vector< DistributionElements > | particleSizeDistribution | ) |
set the PSD by a suitable vector.
sets the PSD from a vector of the DistributionElements class; used to read in PSDs from a restart file.
[in] | particleSizeDistribution | vector containing the radii and probabilities specifying the PSD. |
References particleSizeDistribution_.
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.
[in] | fileName | Name of the .csv file containing the radii and probabilities of the PSD. |
[in] | PSDType | Type 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] | headings | If 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] | unitScalingFactorRadii | Scaling factor of radii to match SI-units. |
References UniformPSDSelfTest::fileName, csvReader::getFirstColumn(), csvReader::getSecondColumn(), getSizeRatio(), i, INFO, logger, csvReader::read(), csvReader::setHeader(), and setPSDFromVector().
Referenced by MultiplePSDSelfTest::setupInitialConditions(), PSDManualInsertionSelfTest::setupInitialConditions(), and PSDSelfTest::setupInitialConditions().
void PSD::setPSDFromVector | ( | std::vector< DistributionElements > | psdVector, |
TYPE | PSDType | ||
) |
Sets the PSD from a vector with DistributionElements.
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.
[in] | psdVector | Vector containing radii and probabilities ([0,1]). |
[in] | PSDType | Type 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. |
References convertCumulativeToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), CUMULATIVE_AREA_DISTRIBUTION, CUMULATIVE_LENGTH_DISTRIBUTION, CUMULATIVE_VOLUME_DISTRIBUTION, logger, particleSizeDistribution_, PROBABILITYDENSITY_AREA_DISTRIBUTION, PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PROBABILITYDENSITY_VOLUME_DISTRIBUTION, validateCumulativeDistribution(), validateProbabilityDensityDistribution(), and WARN.
Referenced by convertPSD2ToPSD(), ParticleHandler::getPSD(), Calibration::setPSD(), Material::setPSD(), setPSDFromCSV(), PSDSelfTest::setupInitialConditions(), and testPSD().
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)
References i, INFO, logger, p, and particleSizeDistribution_.
Referenced by convertProbabilityDensityToCumulative(), setDistributionLogNormal(), setDistributionNormal(), setDistributionPhiNormal(), setDistributionUniform(), and setPSDFromVector().
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).
References e(), INFO, logger, and particleSizeDistribution_.
Referenced by convertCumulativeToProbabilityDensity(), and setPSDFromVector().
|
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.
|
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.
|
friend |
|
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
|
friend |
|
private |
Integer which determines the class in which a particle has to be inserted for the manual insertion routine.
Referenced by decrementNParticlesPerClass(), decrementVolumePerClass(), insertManuallyByVolume(), and PSD().
|
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)
Referenced by decrementNParticlesPerClass(), getInsertedParticleNumber(), and insertManuallyByVolume().
|
private |
Vector of the DistributionElements class which stores radii as internalVariable and probabilities of a PSD.
Referenced by convertCumulativeToProbabilityDensity(), convertProbabilityDensityNumberDistributionToProbabilityDensity(), convertProbabilityDensityToCumulative(), convertProbabilityDensityToProbabilityDensityNumberDistribution(), cutoffAndSqueezeCumulativeDistribution(), cutoffCumulativeDistribution(), drawSample(), getMaxRadius(), getMinRadius(), getParticleSizeDistribution(), getQuantileByRadius(), getRadius(), getRadiusByQuantile(), getVolumetricMeanRadius(), insertManuallyByVolume(), printPSD(), PSD(), scaleParticleSize(), scaleParticleSizeAuto(), setDistributionLogNormal(), setDistributionNormal(), setDistributionPhiNormal(), setDistributionUniform(), setParticleSizeDistribution(), setPSDFromVector(), validateCumulativeDistribution(), and validateProbabilityDensityDistribution().
|
private |
Mercury random number generator object used to draw random numbers from a random initial seed
Referenced by drawSample(), PSD(), and setFixedSeed().
|
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)
Referenced by decrementVolumePerClass(), and insertManuallyByVolume().