PSDConversionUnitTest.cpp File Reference
#include "Math/PSD.h"

Functions

std::string getPSDTypeName (PSD::TYPE psdType)
 
bool isEqual (const std::vector< DistributionElements > &l, const std::vector< DistributionElements > &r)
 
void testPSD (PSD::TYPE psdType)
 Sets a PSD by vector with a given type and gets the PSD vector back by the same type to confirm it's the same. More...
 
void runTest ()
 
int main ()
 

Function Documentation

◆ getPSDTypeName()

std::string getPSDTypeName ( PSD::TYPE  psdType)
8 {
10  return "CUMULATIVE_NUMBER_DISTRIBUTION";
12  return "CUMULATIVE_LENGTH_DISTRIBUTION";
13  else if (psdType == PSD::TYPE::CUMULATIVE_AREA_DISTRIBUTION)
14  return "CUMULATIVE_AREA_DISTRIBUTION";
16  return "CUMULATIVE_VOLUME_DISTRIBUTION";
18  return "PROBABILITYDENSITY_NUMBER_DISTRIBUTION";
20  return "PROBABILITYDENSITY_LENGTH_DISTRIBUTION";
22  return "PROBABILITYDENSITY_AREA_DISTRIBUTION";
24  return "PROBABILITYDENSITY_VOLUME_DISTRIBUTION";
25  else
26  logger(ERROR, "Unknown PSD type");
27  return "";
28 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:32
@ PROBABILITYDENSITY_VOLUME_DISTRIBUTION
@ CUMULATIVE_AREA_DISTRIBUTION
@ CUMULATIVE_VOLUME_DISTRIBUTION
@ PROBABILITYDENSITY_NUMBER_DISTRIBUTION
@ PROBABILITYDENSITY_LENGTH_DISTRIBUTION
@ PROBABILITYDENSITY_AREA_DISTRIBUTION
@ CUMULATIVE_LENGTH_DISTRIBUTION
@ CUMULATIVE_NUMBER_DISTRIBUTION

References PSD::CUMULATIVE_AREA_DISTRIBUTION, PSD::CUMULATIVE_LENGTH_DISTRIBUTION, PSD::CUMULATIVE_NUMBER_DISTRIBUTION, PSD::CUMULATIVE_VOLUME_DISTRIBUTION, ERROR, logger, PSD::PROBABILITYDENSITY_AREA_DISTRIBUTION, PSD::PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PSD::PROBABILITYDENSITY_NUMBER_DISTRIBUTION, and PSD::PROBABILITYDENSITY_VOLUME_DISTRIBUTION.

Referenced by testPSD().

◆ isEqual()

bool isEqual ( const std::vector< DistributionElements > &  l,
const std::vector< DistributionElements > &  r 
)
31 {
32  if (l.size() != r.size())
33  return false;
34 
35  Mdouble tol = 1.0e-15;
36  for (int i = 0; i < l.size(); i++)
37  if (std::fabs(l[i].internalVariable - r[i].internalVariable) > tol || std::fabs(l[i].probability - r[i].probability) > tol)
38  return false;
39 
40  return true;
41 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
r
Definition: UniformPSDSelfTest.py:20
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:117

References boost::multiprecision::fabs(), i, and UniformPSDSelfTest::r.

Referenced by mathsFunc::isEqual(), main(), and testPSD().

◆ main()

int main ( )
101 {
102  runTest();
103 }
void runTest()
Definition: PSDConversionUnitTest.cpp:88

References runTest().

◆ runTest()

◆ testPSD()

void testPSD ( PSD::TYPE  psdType)

Sets a PSD by vector with a given type and gets the PSD vector back by the same type to confirm it's the same.

The PSD class internally converts any PSD type to CUMULATIVE_NUMBER_DISTRIBUTION. It is also possible to get the PSD vector by any type, where internally it is converted back from CUMULATIVE_NUMBER_DISTRIBUTION. Doing this for the same type should of course give the same PSD vector back, provided the PSD vector was perfect to start with, so that internal validation didn't alter it in any way.

Note
This merely checks if converting to and converting back from CUMULATIVE_NUMBER_DISTRIBUTION will yield the same PSD vector. It does not check for the correctness of the conversions itself. It is therefore possible that forwards and backwards conversion both contain the same but opposite mistake. This test would then still pass.
Parameters
psdTypeThe PSD type the test.
55 {
56  // Set a default PSD vector, differentiating between cumulative and probability density.
57  // Note: it is important that this is a proper normalised PSD vector, so that the PSD class does not alter it in any
58  // way when validating it. Because then converting back would result in a different PSD vector.
59  std::vector<DistributionElements> psdVector;
60  switch (psdType)
61  {
66  psdVector = { {1.0, 0.0}, {2.0, 0.5}, {3.0, 0.6}, {4.0, 1.0} };
67  break;
72  psdVector = { {1.0, 0.0}, {2.0, 0.5}, {3.0, 0.1}, {4.0, 0.4} };
73  break;
74  default:
75  logger(ERROR, "Unknown PSD type");
76  }
77 
78  PSD psd;
79  // Set the PSD by the correct type (internally converted to CUMULATIVE_NUMBER_DISTRIBUTION).
80  psd.setPSDFromVector(psdVector, psdType);
81  // Get the PSD vector by the same type (internally converted from CUMULATIVE_NUMBER_DISTRIBUTION).
82  std::vector<DistributionElements> psdVectorBack = psd.getParticleSizeDistributionByType(psdType);
83 
84  // The original and converted back PSD vectors should be equal.
85  logger.assert_always(isEqual(psdVector, psdVectorBack), "Original and converted back PSD vectors of PSD type % are not equal!", getPSDTypeName(psdType));
86 }
bool isEqual(const std::vector< DistributionElements > &l, const std::vector< DistributionElements > &r)
Definition: PSDConversionUnitTest.cpp:30
std::string getPSDTypeName(PSD::TYPE psdType)
Definition: PSDConversionUnitTest.cpp:7
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD)
Definition: PSD.h:47
std::vector< DistributionElements > getParticleSizeDistributionByType(TYPE psdType, Mdouble scalingFactor=1.0) const
Gets the PSD vector, converted to the preferred type.
Definition: PSD.cc:1067
void setPSDFromVector(std::vector< DistributionElements > psd, TYPE PSDType)
Sets the PSD from a vector with DistributionElements.
Definition: PSD.cc:513

References PSD::CUMULATIVE_AREA_DISTRIBUTION, PSD::CUMULATIVE_LENGTH_DISTRIBUTION, PSD::CUMULATIVE_NUMBER_DISTRIBUTION, PSD::CUMULATIVE_VOLUME_DISTRIBUTION, ERROR, PSD::getParticleSizeDistributionByType(), getPSDTypeName(), isEqual(), logger, PSD::PROBABILITYDENSITY_AREA_DISTRIBUTION, PSD::PROBABILITYDENSITY_LENGTH_DISTRIBUTION, PSD::PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PSD::PROBABILITYDENSITY_VOLUME_DISTRIBUTION, and PSD::setPSDFromVector().

Referenced by runTest().