24 ParticleDistribution::ParticleDistribution(
const IParticle& prototype,
26 : m_par_distribution(par_distr)
28 setName(
"ParticleDistribution");
29 mP_particle.reset(prototype.
clone());
30 registerChild(mP_particle.get());
31 mP_particle->registerAbundance(
false);
32 if (
auto dist = m_par_distribution.getDistribution())
34 registerParameter(
"Abundance", &m_abundance);
46 mP_particle->translate(translation);
51 mP_particle->rotate(rotation);
58 std::unique_ptr<ParameterPool> P_pool{mP_particle->createParameterTree()};
60 double main_par_value = P_pool->getUniqueMatch(main_par_name)->value();
63 std::map<std::string, double> linked_ratios;
66 main_par_value == 0 ? 1.0 : P_pool->getUniqueMatch(name)->value() / main_par_value;
69 std::vector<ParameterSample> main_par_samples = m_par_distribution.
generateSamples();
72 IParticle* p_particle_clone = mP_particle->clone();
75 for (
auto it = linked_ratios.begin(); it != linked_ratios.end(); ++it)
76 P_new_pool->setUniqueMatchValue(it->first, main_sample.value * it->second);
77 p_particle_clone->
setAbundance(abundance() * main_sample.weight);
78 result.push_back(p_particle_clone);
85 std::vector<const INode*> result = std::vector<const INode*>() << mP_particle;
86 if (
auto dist = m_par_distribution.getDistribution())
87 result.push_back(dist);
91 std::string ParticleDistribution::mainUnits()
const
93 return ParameterUtils::poolParameterUnits(
prototype(),
Defines classes representing one-dimensional distributions.
Defines many exception classes in namespace Exceptionss.
Defines interface IParticle.
Defines class ParameterPool.
Defines namespace ParameterUtils.
Defines class ParticleDistribution.
Defines class RealParameter.
void setAbundance(double abundance)
Sets particle abundance.
ParameterPool * createParameterTree() const
Creates new parameter pool, with all local parameters and those of its children.
Pure virtual base class for Particle, ParticleComposition, ParticleCoreShell, MesoCrystal.
IParticle * clone() const override=0
Returns a clone of this ISample object.
Pure virtual interface for rotations.
A parametric distribution function, for use with any model parameter.
std::vector< ParameterSample > generateSamples() const
generate list of sampled values with their weight
std::vector< std::string > getLinkedParameterNames() const
get list of linked parameter names
std::string getMainParameterName() const
get the main parameter's name
void setUniqueMatchValue(const std::string &pattern, double value)
Sets value of the one parameter that matches pattern ('*' allowed), or throws.
A parameter value with a weight, as obtained when sampling from a distribution.
A particle type that is a parametric distribution of IParticle's.
const IParticle & prototype() const
Returns the prototype particle, used for generating multiple ones.
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
SafePointerVector< IParticle > generateParticles() const
Returns list of new particles generated according to a distribution.
ParameterDistribution parameterDistribution() const
Returns the distributed parameter data.
void rotate(const IRotation &rotation) override final
Applies the given rotation to the particle.
ParticleDistribution * clone() const override final
Returns a clone of this ISample object.
void translate(kvector_t translation) override final
Translates the particle with the given vector.
A vector of pointers, owned by *this, with methods to handle them safely.