BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IParameterized Class Reference
Inheritance diagram for IParameterized:
Collaboration diagram for IParameterized:

Public Member Functions

 IParameterized (const std::string &name="")
 
 IParameterized (const IParameterized &other)
 
virtual ~IParameterized ()
 
IParameterizedoperator= (const IParameterized &other)=delete
 
ParameterPoolparameterPool () const
 
virtual ParameterPoolcreateParameterTree () const
 
std::string parametersToString () const
 
RealParameterregisterParameter (const std::string &name, double *parpointer)
 
void registerVector (const std::string &base_name, kvector_t *p_vec, const std::string &units="nm")
 
void setParameterValue (const std::string &name, double value)
 
void setVectorValue (const std::string &base_name, kvector_t value)
 
RealParameterparameter (const std::string &name) const
 
virtual void onChange ()
 
void removeParameter (const std::string &name)
 
void removeVector (const std::string &base_name)
 
void setName (const std::string &name)
 
const std::string & getName () const
 

Static Public Member Functions

static std::string XComponentName (const std::string &base_name)
 
static std::string YComponentName (const std::string &base_name)
 
static std::string ZComponentName (const std::string &base_name)
 

Private Attributes

std::string m_name
 
std::unique_ptr< ParameterPoolm_pool
 

Detailed Description

Manages a local parameter pool, and a tree of child pools.

Definition at line 28 of file IParameterized.h.

Constructor & Destructor Documentation

◆ IParameterized() [1/2]

IParameterized::IParameterized ( const std::string &  name = "")

Definition at line 23 of file IParameterized.cpp.

23 : m_name{name}, m_pool{new ParameterPool} {}
std::string m_name
std::unique_ptr< ParameterPool > m_pool
parameter pool (kind of pointer-to-implementation)
Container with parameters for IParameterized object.
Definition: ParameterPool.h:30

◆ IParameterized() [2/2]

IParameterized::IParameterized ( const IParameterized other)

Definition at line 25 of file IParameterized.cpp.

25  : IParameterized(other.getName())
26 {
27  if (!other.parameterPool()->empty())
28  throw std::runtime_error("BUG: not prepared to copy parameters of " + getName());
29 }
IParameterized(const std::string &name="")
const std::string & getName() const
ParameterPool * parameterPool() const
Returns pointer to the parameter pool.
bool empty() const
Definition: ParameterPool.h:43

References ParameterPool::empty(), getName(), and parameterPool().

Here is the call graph for this function:

◆ ~IParameterized()

IParameterized::~IParameterized ( )
virtualdefault

Member Function Documentation

◆ operator=()

IParameterized& IParameterized::operator= ( const IParameterized other)
delete

◆ parameterPool()

ParameterPool* IParameterized::parameterPool ( ) const
inline

◆ createParameterTree()

ParameterPool * IParameterized::createParameterTree ( ) const
virtual

Creates new parameter pool, with all local parameters and those of its children.

Reimplemented in INode.

Definition at line 33 of file IParameterized.cpp.

34 {
35  auto* result = new ParameterPool;
36  m_pool->copyToExternalPool("/" + getName() + "/", result);
37  return result;
38 }

References getName(), and m_pool.

Referenced by parametersToString(), ParameterUtils::poolParameterUnits(), and setParameterValue().

Here is the call graph for this function:

◆ parametersToString()

std::string IParameterized::parametersToString ( ) const

Returns multiline string representing available parameters.

Definition at line 40 of file IParameterized.cpp.

41 {
42  std::ostringstream result;
43  std::unique_ptr<ParameterPool> P_pool(createParameterTree());
44  result << *P_pool << "\n";
45  return result.str();
46 }
virtual ParameterPool * createParameterTree() const
Creates new parameter pool, with all local parameters and those of its children.

References createParameterTree().

Here is the call graph for this function:

◆ registerParameter()

RealParameter & IParameterized::registerParameter ( const std::string &  name,
double *  parpointer 
)

Definition at line 48 of file IParameterized.cpp.

49 {
50  return m_pool->addParameter(
51  new RealParameter(name, data, getName(), [&]() -> void { onChange(); }));
52 }
virtual void onChange()
Action to be taken in inherited class when a parameter has changed.
Wraps a parameter of type double.
Definition: RealParameter.h:32

References getName(), m_pool, and onChange().

Referenced by BasicLattice::BasicLattice(), Beam::Beam(), CylindersInBABuilder::CylindersInBABuilder(), DetectionProperties::DetectionProperties(), HexagonalLattice::HexagonalLattice(), IInterferenceFunction::IInterferenceFunction(), INode::INode(), InterferenceFunction1DLattice::InterferenceFunction1DLattice(), InterferenceFunction2DParaCrystal::InterferenceFunction2DParaCrystal(), InterferenceFunctionHardDisk::InterferenceFunctionHardDisk(), InterferenceFunctionRadialParaCrystal::InterferenceFunctionRadialParaCrystal(), InterferenceFunctionTwin::InterferenceFunctionTwin(), Lattice2D::Lattice2D(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), ParticleDistribution::ParticleDistribution(), PlainMultiLayerBySLDBuilder::PlainMultiLayerBySLDBuilder(), IParticle::registerAbundance(), ParticleLayout::registerParticleDensity(), Layer::registerThickness(), registerVector(), ParticleLayout::registerWeight(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), ResonatorBuilder::ResonatorBuilder(), Lattice2D::setRotationEnabled(), SquareLattice::SquareLattice(), and TriangularRippleBuilder::TriangularRippleBuilder().

Here is the call graph for this function:

◆ registerVector()

void IParameterized::registerVector ( const std::string &  base_name,
kvector_t p_vec,
const std::string &  units = "nm" 
)

Definition at line 54 of file IParameterized.cpp.

56 {
57  registerParameter(XComponentName(base_name), &((*p_vec)[0])).setUnit(units);
58  registerParameter(YComponentName(base_name), &((*p_vec)[1])).setUnit(units);
59  registerParameter(ZComponentName(base_name), &((*p_vec)[2])).setUnit(units);
60 }
RealParameter & registerParameter(const std::string &name, double *parpointer)
static std::string XComponentName(const std::string &base_name)
static std::string YComponentName(const std::string &base_name)
static std::string ZComponentName(const std::string &base_name)
RealParameter & setUnit(const std::string &name)

References registerParameter(), RealParameter::setUnit(), XComponentName(), YComponentName(), and ZComponentName().

Referenced by Beam::Beam(), DetectionProperties::DetectionProperties(), InterferenceFunctionTwin::InterferenceFunctionTwin(), MultiLayer::MultiLayer(), Lattice::registerBasisVectors(), and IParticle::registerPosition().

Here is the call graph for this function:

◆ setParameterValue()

void IParameterized::setParameterValue ( const std::string &  name,
double  value 
)

Definition at line 62 of file IParameterized.cpp.

63 {
64  if (name.find('*') == std::string::npos && name.find('/') == std::string::npos) {
65  m_pool->setParameterValue(name, value);
66  } else {
67  std::unique_ptr<ParameterPool> P_pool{createParameterTree()};
68  if (name.find('*') != std::string::npos)
69  P_pool->setMatchedParametersValue(name, value);
70  else
71  P_pool->setParameterValue(name, value);
72  }
73 }
int setMatchedParametersValue(const std::string &wildcards, double value)
Sets value of the nonzero parameters that match pattern ('*' allowed), or throws.

References createParameterTree(), m_pool, and ParameterPool::setMatchedParametersValue().

Referenced by AsymRippleBuilder::buildSample(), and setVectorValue().

Here is the call graph for this function:

◆ setVectorValue()

void IParameterized::setVectorValue ( const std::string &  base_name,
kvector_t  value 
)

Definition at line 75 of file IParameterized.cpp.

76 {
77  setParameterValue(XComponentName(base_name), value.x());
78  setParameterValue(YComponentName(base_name), value.y());
79  setParameterValue(ZComponentName(base_name), value.z());
80 }
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:66
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:64
void setParameterValue(const std::string &name, double value)

References setParameterValue(), BasicVector3D< T >::x(), XComponentName(), BasicVector3D< T >::y(), YComponentName(), BasicVector3D< T >::z(), and ZComponentName().

Here is the call graph for this function:

◆ parameter()

RealParameter * IParameterized::parameter ( const std::string &  name) const

◆ onChange()

◆ removeParameter()

void IParameterized::removeParameter ( const std::string &  name)

◆ removeVector()

void IParameterized::removeVector ( const std::string &  base_name)

Definition at line 93 of file IParameterized.cpp.

94 {
95  removeParameter(XComponentName(base_name));
96  removeParameter(YComponentName(base_name));
97  removeParameter(ZComponentName(base_name));
98 }
void removeParameter(const std::string &name)

References removeParameter(), XComponentName(), YComponentName(), and ZComponentName().

Referenced by IParticle::registerPosition().

Here is the call graph for this function:

◆ XComponentName()

std::string IParameterized::XComponentName ( const std::string &  base_name)
static

Definition at line 100 of file IParameterized.cpp.

101 {
102  return base_name + "X";
103 }

Referenced by Lattice::registerBasisVectors(), IParticle::registerPosition(), registerVector(), removeVector(), and setVectorValue().

◆ YComponentName()

std::string IParameterized::YComponentName ( const std::string &  base_name)
static

Definition at line 105 of file IParameterized.cpp.

106 {
107  return base_name + "Y";
108 }

Referenced by registerVector(), removeVector(), and setVectorValue().

◆ ZComponentName()

std::string IParameterized::ZComponentName ( const std::string &  base_name)
static

Definition at line 110 of file IParameterized.cpp.

111 {
112  return base_name + "Z";
113 }

Referenced by registerVector(), removeVector(), and setVectorValue().

◆ setName()

void IParameterized::setName ( const std::string &  name)
inline

Definition at line 68 of file IParameterized.h.

68 { m_name = name; }

References m_name.

Referenced by BasicLattice::BasicLattice(), Beam::Beam(), Layer::clone(), ConvolutionDetectorResolution::ConvolutionDetectorResolution(), LayersWithAbsorptionBuilder::createSampleByIndex(), Basic2DParaCrystalBuilder::createSampleByIndex(), ParticleInVacuumBuilder::createSampleByIndex(), SimpleMagneticRotationBuilder::createSampleByIndex(), Crystal::Crystal(), DetectionProperties::DetectionProperties(), DistributionHandler::DistributionHandler(), FormFactorBAPol::FormFactorBAPol(), FormFactorCoreShell::FormFactorCoreShell(), FormFactorCrystal::FormFactorCrystal(), FormFactorDecoratorMaterial::FormFactorDecoratorMaterial(), FormFactorDecoratorPositionFactor::FormFactorDecoratorPositionFactor(), FormFactorDecoratorRotation::FormFactorDecoratorRotation(), FormFactorDWBA::FormFactorDWBA(), FormFactorDWBAPol::FormFactorDWBAPol(), FormFactorWeighted::FormFactorWeighted(), HexagonalLattice::HexagonalLattice(), IDetector::IDetector(), DepthProbeSimulation::initialize(), GISASSimulation::initialize(), OffSpecSimulation::initialize(), SpecularSimulation::initialize(), SpecularDetector1D::initialize(), MesoCrystal::initialize(), Particle::initialize(), ParticleComposition::initialize(), INode::INode(), Instrument::Instrument(), InterferenceFunction1DLattice::InterferenceFunction1DLattice(), InterferenceFunction2DLattice::InterferenceFunction2DLattice(), InterferenceFunction2DParaCrystal::InterferenceFunction2DParaCrystal(), InterferenceFunction2DSuperLattice::InterferenceFunction2DSuperLattice(), InterferenceFunction3DLattice::InterferenceFunction3DLattice(), InterferenceFunctionFinite2DLattice::InterferenceFunctionFinite2DLattice(), InterferenceFunctionFinite3DLattice::InterferenceFunctionFinite3DLattice(), InterferenceFunctionHardDisk::InterferenceFunctionHardDisk(), InterferenceFunctionNone::InterferenceFunctionNone(), InterferenceFunctionRadialParaCrystal::InterferenceFunctionRadialParaCrystal(), InterferenceFunctionTwin::InterferenceFunctionTwin(), ISampleBuilder::ISampleBuilder(), IsGISAXSDetector::IsGISAXSDetector(), Lattice::Lattice(), Layer::Layer(), LayerInterface::LayerInterface(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), Beam::operator=(), SampleBuilderNode::operator=(), ParticleCoreShell::ParticleCoreShell(), ParticleDistribution::ParticleDistribution(), ParticleLayout::ParticleLayout(), RectangularDetector::RectangularDetector(), SampleBuilderNode::reset(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), SampleBuilderNode::SampleBuilderNode(), SampleBuilderNode::setSBN(), SphericalDetector::SphericalDetector(), and SquareLattice::SquareLattice().

◆ getName()

Member Data Documentation

◆ m_name

std::string IParameterized::m_name
private

Definition at line 72 of file IParameterized.h.

Referenced by getName(), and setName().

◆ m_pool

std::unique_ptr<ParameterPool> IParameterized::m_pool
private

parameter pool (kind of pointer-to-implementation)

Definition at line 73 of file IParameterized.h.

Referenced by createParameterTree(), parameter(), parameterPool(), registerParameter(), removeParameter(), and setParameterValue().


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