From 7a1fb62c4637e0009cb70b684f376bc25204d5ab Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Thu, 18 Aug 2016 19:15:19 +0200 Subject: [PATCH] Comments; throw exception upon inappropriate call of createDWBASimulation() --- .../DecouplingApproximationStrategy.cpp | 7 ++- .../DecouplingApproximationStrategy.h | 3 -- .../Aggregate/InterferenceFunction2DLattice.h | 4 +- .../InterferenceFunction2DParaCrystal.cpp | 8 +++ .../InterferenceFunction2DParaCrystal.h | 33 +++--------- .../InterferenceFunctionRadialParaCrystal.h | 6 +-- Core/Multilayer/MultiLayer.cpp | 17 +++---- Core/Multilayer/MultiLayer.h | 2 +- Core/Sample/ICompositeSample.cpp | 51 ++++++------------- Core/Sample/ICompositeSample.h | 10 ++-- Core/Sample/ISample.cpp | 8 +-- Core/Sample/ISample.h | 16 +++--- Tests/UnitTests/Core/1/LayerTest.h | 11 ++-- 13 files changed, 64 insertions(+), 112 deletions(-) diff --git a/Core/Aggregate/DecouplingApproximationStrategy.cpp b/Core/Aggregate/DecouplingApproximationStrategy.cpp index 239d526b6b9..3d80ce09711 100644 --- a/Core/Aggregate/DecouplingApproximationStrategy.cpp +++ b/Core/Aggregate/DecouplingApproximationStrategy.cpp @@ -34,6 +34,7 @@ void DecouplingApproximationStrategy::init( "No formfactors for Decoupling Approximation."); } +//! Evaluates the intensity for given list of evaluated form factors. double DecouplingApproximationStrategy::evaluateForList( const SimulationElement& sim_element, const std::vector<complex_t>& ff_list) const { @@ -58,8 +59,10 @@ double DecouplingApproximationStrategy::evaluateForList( return total_abundance * (intensity + amplitude_norm * (itf_function - 1.0)); } -double DecouplingApproximationStrategy::evaluateForMatrixList(const SimulationElement& sim_element, - const matrixFFVector_t& ff_list) const +//! Evaluates the intensity for given list of evaluated form factors +//! in the presence of polarization of beam and detector. +double DecouplingApproximationStrategy::evaluateForMatrixList( + const SimulationElement& sim_element, const matrixFFVector_t& ff_list) const { Eigen::Matrix2cd mean_intensity = Eigen::Matrix2cd::Zero(); Eigen::Matrix2cd mean_amplitude = Eigen::Matrix2cd::Zero(); diff --git a/Core/Aggregate/DecouplingApproximationStrategy.h b/Core/Aggregate/DecouplingApproximationStrategy.h index bd7f4dfd012..6d5ecaeaaae 100644 --- a/Core/Aggregate/DecouplingApproximationStrategy.h +++ b/Core/Aggregate/DecouplingApproximationStrategy.h @@ -34,12 +34,9 @@ public: const IInterferenceFunction& iff) final; private: - //! Evaluates the intensity for given list of evaluated form factors double evaluateForList(const SimulationElement& sim_element, const std::vector<complex_t>& ff_list) const final; - //! Evaluates the intensity for given list of evaluated form factors - //! in the presence of polarization of beam and detector double evaluateForMatrixList(const SimulationElement& sim_element, const matrixFFVector_t& ff_list) const final; }; diff --git a/Core/Aggregate/InterferenceFunction2DLattice.h b/Core/Aggregate/InterferenceFunction2DLattice.h index df87fc5befb..0695e05a0da 100644 --- a/Core/Aggregate/InterferenceFunction2DLattice.h +++ b/Core/Aggregate/InterferenceFunction2DLattice.h @@ -70,15 +70,13 @@ private: InterferenceFunction2DLattice(const Lattice2DParameters& lattice_params); - //! Registers some class members for later access via parameter pool void init_parameters(); //! Initializes the x,y coordinates of the a*,b* reciprocal bases void initialize_rec_vectors(); //! Initializes factors needed in each calculation - void initialize_calc_factors(double coherence_length_x, - double coherence_length_y); + void initialize_calc_factors(double coherence_length_x, double coherence_length_y); double m_asx, m_asy; //!< x,y coordinates of a* double m_bsx, m_bsy; //!< x,y coordinates of b* diff --git a/Core/Aggregate/InterferenceFunction2DParaCrystal.cpp b/Core/Aggregate/InterferenceFunction2DParaCrystal.cpp index cd52c07875b..3d64448d67e 100644 --- a/Core/Aggregate/InterferenceFunction2DParaCrystal.cpp +++ b/Core/Aggregate/InterferenceFunction2DParaCrystal.cpp @@ -82,6 +82,9 @@ std::string InterferenceFunction2DParaCrystal::to_str(int indent) const return ss.str(); } +//! Sets the probability distributions (Fourier transformed) for the two lattice directions. +//! @param pdf_1: probability distribution in first lattice direction +//! @param pdf_2: probability distribution in second lattice direction void InterferenceFunction2DParaCrystal::setProbabilityDistributions( const IFTDistribution2D& pdf_1, const IFTDistribution2D& pdf_2) { @@ -144,6 +147,9 @@ InterferenceFunction2DParaCrystal* InterferenceFunction2DParaCrystal::createHexa return p_new; } +//! Sets the sizes of coherence domains. +//! @param size_1: size in first lattice direction +//! @param size_2: size in second lattice direction void InterferenceFunction2DParaCrystal::setDomainSizes(double size_1, double size_2) { m_domain_sizes[0] = size_1; @@ -168,6 +174,7 @@ void InterferenceFunction2DParaCrystal::init_parameters() registerParameter(DomainSize2, &m_domain_sizes[1]).setUnit("nm").setNonnegative(); } +//! Returns interference function for fixed angle xi. double InterferenceFunction2DParaCrystal::interferenceForXi(double xi) const { double result = interference1D(m_qx, m_qy, xi, 0)* @@ -175,6 +182,7 @@ double InterferenceFunction2DParaCrystal::interferenceForXi(double xi) const return result; } +//! Returns interference function for fixed xi in the dimension determined by the given index. double InterferenceFunction2DParaCrystal::interference1D( double qx, double qy, double xi, size_t index) const { diff --git a/Core/Aggregate/InterferenceFunction2DParaCrystal.h b/Core/Aggregate/InterferenceFunction2DParaCrystal.h index eee291dd039..a10dc5224d9 100644 --- a/Core/Aggregate/InterferenceFunction2DParaCrystal.h +++ b/Core/Aggregate/InterferenceFunction2DParaCrystal.h @@ -40,7 +40,6 @@ public: void accept(ISampleVisitor* visitor) const final { visitor->visit(this); } - //! Returns textual representation of *this and its descendants. std::string to_str(int indent=0) const final; static InterferenceFunction2DParaCrystal* createSquare(double peak_distance, @@ -52,19 +51,11 @@ public: double domain_size_1 = 0.0, double domain_size_2 = 0.0); - //! @brief Sets the sizes of coherence domains - //! @param size_1: size in first lattice direction - //! @param size_2: size in second lattice direction void setDomainSizes(double size_1, double size_2); - //! @brief Sets the probability distributions (Fourier transformed) for the two - //! lattice directions. - //! @param pdf_1: probability distribution in first lattice direction - //! @param pdf_2: probability distribution in second lattice direction void setProbabilityDistributions(const IFTDistribution2D& pdf_1, const IFTDistribution2D& pdf_2); - double evaluate(const kvector_t q) const final; std::vector<double> getDomainSizes() const; @@ -76,17 +67,16 @@ public: Lattice2DParameters getLatticeParameters() const { return m_lattice_params; } - //! Adds parameters from local pool to external pool and recursively calls its direct children. - virtual std::string addParametersToExternalPool(std::string path, ParameterPool* external_pool, - int copy_number = -1) const; + std::string addParametersToExternalPool(std::string path, ParameterPool* external_pool, + int copy_number = -1) const final; - //! Returns the particle density associated with this 2d paracrystal lattice double getParticleDensity() const final; private: - //! Registers some class members for later access via parameter pool void init_parameters(); - + double interferenceForXi(double xi) const; + double interference1D(double qx, double qy, double xi, size_t index) const; + complex_t FTPDF(double qx, double qy, double xi, size_t index) const; void transformToPrincipalAxes(double qx, double qy, double gamma, double delta, double& q_pa_1, double& q_pa_2) const; @@ -96,20 +86,11 @@ private: double m_damping_length; //!< Damping length for removing delta function singularity at q=0. bool m_use_damping_length; //!< Flag that determines if the damping length should be used. double m_domain_sizes[2]; //!< Coherence domain sizes - - //! Returns interference function for fixed angle xi. - double interferenceForXi(double xi) const; - - //! Returns interference function for fixed xi in the dimension determined by the given index. - double interference1D(double qx, double qy, double xi, size_t index) const; - - complex_t FTPDF(double qx, double qy, double xi, size_t index) const; - + mutable double m_qx; + mutable double m_qy; #ifndef SWIG std::unique_ptr<IntegratorReal<InterferenceFunction2DParaCrystal>> mP_integrator; #endif - mutable double m_qx; - mutable double m_qy; }; #endif // INTERFERENCEFUNCTION2DPARACRYSTAL_H diff --git a/Core/Aggregate/InterferenceFunctionRadialParaCrystal.h b/Core/Aggregate/InterferenceFunctionRadialParaCrystal.h index b5ccc8526d6..2cb3af41e42 100644 --- a/Core/Aggregate/InterferenceFunctionRadialParaCrystal.h +++ b/Core/Aggregate/InterferenceFunctionRadialParaCrystal.h @@ -32,7 +32,6 @@ public: void accept(ISampleVisitor* visitor) const final { visitor->visit(this); } - //! Returns textual representation of *this and its descendants. std::string to_str(int indent=0) const final; void setKappa(double kappa) { m_kappa = kappa; } @@ -53,6 +52,8 @@ public: double getDampingLength() const { return m_damping_length; } private: + void init_parameters(); + double m_peak_distance; //!< the distance to the first neighbor peak double m_damping_length; //!< damping length of paracrystal //! Fourier transformed probability distribution of the nearest particle @@ -60,9 +61,6 @@ private: bool m_use_damping_length; double m_kappa; //!< Size-spacing coupling parameter double m_domain_size; //!< Size of coherence domain - - //! Registers some class members for later access via parameter pool - void init_parameters(); }; #endif // INTERFERENCEFUNCTIONRADIALPARACRYSTAL_H diff --git a/Core/Multilayer/MultiLayer.cpp b/Core/Multilayer/MultiLayer.cpp index 8f501bbdb80..19c28453991 100644 --- a/Core/Multilayer/MultiLayer.cpp +++ b/Core/Multilayer/MultiLayer.cpp @@ -48,10 +48,12 @@ void MultiLayer::init_parameters() void MultiLayer::clear() // TODO: understand need { - for(size_t i=0; i<m_layers.size(); i++) delete m_layers[i]; + for(size_t i=0; i<m_layers.size(); i++) + delete m_layers[i]; m_layers.clear(); - for(size_t i=0; i<m_interfaces.size(); i++) delete m_interfaces[i]; + for(size_t i=0; i<m_interfaces.size(); i++) + delete m_interfaces[i]; m_interfaces.clear(); m_layers_z.clear(); @@ -66,22 +68,19 @@ MultiLayer* MultiLayer::clone() const newMultiLayer->m_layers_z = m_layers_z; std::vector<Layer*> layer_buffer; - for(size_t i=0; i<m_layers.size(); i++) { + for(size_t i=0; i<m_layers.size(); i++) layer_buffer.push_back(m_layers[i]->clone() ); - } for(size_t i=0; i<m_interfaces.size(); i++) { const Layer* topLayer = layer_buffer[i]; const Layer* bottomLayer = layer_buffer[i+1]; LayerInterface* newInterface(0); - if(m_interfaces[i]->getRoughness()) { + if(m_interfaces[i]->getRoughness()) newInterface = LayerInterface::createRoughInterface(topLayer, bottomLayer, *m_interfaces[i]->getRoughness() ); - } else { - newInterface = LayerInterface::createSmoothInterface(topLayer, - bottomLayer ); - } + else + newInterface = LayerInterface::createSmoothInterface(topLayer, bottomLayer ); newMultiLayer->addAndRegisterLayer( layer_buffer[i] ); newMultiLayer->addAndRegisterInterface( newInterface ); } diff --git a/Core/Multilayer/MultiLayer.h b/Core/Multilayer/MultiLayer.h index cc76849a8a8..c419be78af8 100644 --- a/Core/Multilayer/MultiLayer.h +++ b/Core/Multilayer/MultiLayer.h @@ -113,7 +113,7 @@ public: //! look for the presence of DWBA terms (e.g. included particles) //! and return ISimulation if needed - virtual DWBASimulation* createDWBASimulation() const; + DWBASimulation* createDWBASimulation() const final; //! returns layer index int getIndexOfLayer(const Layer* layer) const; diff --git a/Core/Sample/ICompositeSample.cpp b/Core/Sample/ICompositeSample.cpp index 2ec3d9982a4..0e9c1e2cca0 100644 --- a/Core/Sample/ICompositeSample.cpp +++ b/Core/Sample/ICompositeSample.cpp @@ -22,7 +22,7 @@ ICompositeSample::~ICompositeSample() {} //! Registers child in the container -void ICompositeSample::registerChild(ISample *sample) +void ICompositeSample::registerChild(ISample* sample) { if(!sample) throw Exceptions::NullPointerException( @@ -32,41 +32,37 @@ void ICompositeSample::registerChild(ISample *sample) //! remove registered child from the container -void ICompositeSample::deregisterChild(ISample *sample) +void ICompositeSample::deregisterChild(ISample* sample) { - std::vector<ISample*>::iterator it = std::find(m_samples.begin(), m_samples.end(), sample); - if (it != m_samples.end()) { + auto it = std::find(m_samples.begin(), m_samples.end(), sample); + if (it != m_samples.end()) m_samples.erase(it); - } } -ISample *ICompositeSample::operator[](size_t index) +ISample* ICompositeSample::operator[](size_t index) { - if (childIndexInRange(index)) { + if (childIndexInRange(index)) return m_samples[index]; - } - return 0; + return nullptr; } -const ISample *ICompositeSample::operator[](size_t index) const +const ISample* ICompositeSample::operator[](size_t index) const { - if (childIndexInRange(index)) { + if (childIndexInRange(index)) return m_samples[index]; - } - return 0; + return nullptr; } -std::vector<const ISample *> ICompositeSample::getChildren() const +std::vector<const ISample*> ICompositeSample::getChildren() const { - std::vector<const ISample *> result; - for (size_t i=0; i<m_samples.size(); ++i) { + std::vector<const ISample*> result; + for (size_t i=0; i<m_samples.size(); ++i) result.push_back(m_samples[i]); - } return result; } std::string ICompositeSample::addParametersToExternalPool(std::string path, - ParameterPool *external_pool, + ParameterPool* external_pool, int copy_number) const { std::string new_path @@ -75,9 +71,9 @@ std::string ICompositeSample::addParametersToExternalPool(std::string path, // We need a mechanism to handle cases with multiple children with the same name. // First run through all direct children and save their names Utils::StringUsageMap strUsageMap; - for (size_t i = 0; i < m_samples.size(); ++i) { + for (size_t i = 0; i < m_samples.size(); ++i) strUsageMap.add(new_path + m_samples[i]->getName()); // saving child names - } + // Now run through the direct children again and assign a copy number for // all children with the same name Utils::StringUsageMap strUsageMap2; @@ -95,18 +91,3 @@ std::string ICompositeSample::addParametersToExternalPool(std::string path, } return new_path; } - -bool ICompositeSample::childIndexInRange(size_t index) const -{ - return index<m_samples.size(); -} - -void ICompositeSample::accept(ISampleVisitor* visitor) const -{ - visitor->visit(this); -} - -size_t ICompositeSample::size() const -{ - return m_samples.size(); -} diff --git a/Core/Sample/ICompositeSample.h b/Core/Sample/ICompositeSample.h index 8470abb3aba..e9498b1d3e6 100644 --- a/Core/Sample/ICompositeSample.h +++ b/Core/Sample/ICompositeSample.h @@ -20,9 +20,8 @@ class ISampleVisitor; -//! @class ICompositeSample +//! Pure virtual base class for tree-like composite samples. //! @ingroup samples_internal -//! @brief Interface to describe the tree-like composition of samples class BA_CORE_API_ ICompositeSample : public ISample { @@ -32,8 +31,7 @@ public: ICompositeSample* clone() const = 0; - //! calls the ISampleVisitor's visit method - virtual void accept(ISampleVisitor* visitor) const; + virtual void accept(ISampleVisitor* visitor) const { visitor->visit(this); } //! Registers child in the container. virtual void registerChild(ISample* sample); @@ -51,7 +49,7 @@ public: virtual std::vector<const ISample*> getChildren() const; //! Returns number of children. - virtual size_t size() const; + virtual size_t size() const { return m_samples.size(); } //! Adds parameters from local pool to external pool and recursively calls its direct children. virtual std::string addParametersToExternalPool(std::string path, ParameterPool* external_pool, @@ -59,7 +57,7 @@ public: private: //! Check child index - bool childIndexInRange(size_t index) const; + bool childIndexInRange(size_t index) const { return index<m_samples.size(); } //! List of registered children. std::vector<ISample*> m_samples; diff --git a/Core/Sample/ISample.cpp b/Core/Sample/ISample.cpp index b531be3aeec..e1c25898ec6 100644 --- a/Core/Sample/ISample.cpp +++ b/Core/Sample/ISample.cpp @@ -26,7 +26,8 @@ ISample* ISample::cloneInvertB() const DWBASimulation* ISample::createDWBASimulation() const { - return nullptr; + throw Exceptions::NotImplementedException( + "ISample::createDWBASimulation() -> Error! Method is not implemented"); } std::string ISample::to_str(int indent) const @@ -64,8 +65,3 @@ bool ISample::containsMagneticMaterial() const return true; return false; } - -std::vector<const ISample*> ISample::getChildren() const -{ - return std::vector<const ISample*> {}; -} diff --git a/Core/Sample/ISample.h b/Core/Sample/ISample.h index 4cd3139af07..730b6e67105 100644 --- a/Core/Sample/ISample.h +++ b/Core/Sample/ISample.h @@ -25,9 +25,11 @@ class IMaterial; class ISampleVisitor; class DWBASimulation; -//! @class ISample +//! Interface for sample components and properties related to scattering. //! @ingroup samples_internal -//! @brief Interface for objects related to scattering. + +//! Pure virtual base class of ICompositeSample, IFormFactor, IInterferenceFunction, +//! IRoughness, IRotation. So it is somewhat more abstract than the name "ISample" suggests. class BA_CORE_API_ ISample : public ICloneable, public IParameterized { @@ -41,10 +43,9 @@ public: //! Calls the ISampleVisitor's visit method. virtual void accept(ISampleVisitor* p_visitor) const=0; - //! Returns an ISimulation if DWBA is required. virtual DWBASimulation* createDWBASimulation() const; - //! Returns textual representation of *this and its descendants. + //! Returns textual representation of this and its descendants. virtual std::string to_str(int indent=0) const; //! Returns nullptr, unless overwritten to return a specific material. @@ -54,18 +55,15 @@ public: virtual const IMaterial* getAmbientMaterial() const { return nullptr; } //! Returns set of unique materials contained in this ISample. - //! Must be reimplemented in derived classes that define a material. std::vector<const IMaterial*> containedMaterials() const; //! Indicates if this ISample object contains any material with magnetic properties. bool containsMagneticMaterial() const; - //! Returns a vector of children (const). - //! Default implementation returns empty vector. - virtual std::vector<const ISample*> getChildren() const; + //! Returns a vector of children. + virtual std::vector<const ISample*> getChildren() const { return {}; } //! Returns number of children. - //! Default implementation returns zero. virtual size_t size() const { return 0; } template<class T> std::vector<const T*> containedSubclass() const; diff --git a/Tests/UnitTests/Core/1/LayerTest.h b/Tests/UnitTests/Core/1/LayerTest.h index ed1a2beed73..7c9593a640d 100644 --- a/Tests/UnitTests/Core/1/LayerTest.h +++ b/Tests/UnitTests/Core/1/LayerTest.h @@ -24,9 +24,8 @@ TEST_F(LayerTest, LayerInitialState) EXPECT_EQ(complex_t(1.0, 0.0), layer.getRefractiveIndex()); EXPECT_EQ(0.0, layer.getTotalParticleSurfaceDensity(0)); EXPECT_EQ("Layer", layer.getName()); - EXPECT_EQ(nullptr, layer.createDWBASimulation()); - Layer *new_layer = layer.clone(); + Layer* new_layer = layer.clone(); EXPECT_EQ(nullptr, new_layer->getMaterial()); EXPECT_EQ(nullptr, new_layer->getLayout(0)); EXPECT_EQ(0, new_layer->getThickness()); @@ -34,7 +33,6 @@ TEST_F(LayerTest, LayerInitialState) EXPECT_EQ(complex_t(1.0, 0.0), new_layer->getRefractiveIndex()); EXPECT_EQ(0.0, new_layer->getTotalParticleSurfaceDensity(0)); EXPECT_EQ("Layer", new_layer->getName()); - EXPECT_EQ(nullptr, new_layer->createDWBASimulation()); delete new_layer; } @@ -52,7 +50,6 @@ TEST_F(LayerTest, LayerGetAndSet) EXPECT_EQ(complex_t(1,0), layer.getRefractiveIndex()); EXPECT_EQ(0.0, layer.getTotalParticleSurfaceDensity(0)); EXPECT_EQ("Layer", layer.getName()); - EXPECT_EQ(nullptr, layer.createDWBASimulation()); layer.setThickness(20.0); EXPECT_EQ(20, layer.getThickness()); @@ -61,7 +58,7 @@ TEST_F(LayerTest, LayerGetAndSet) EXPECT_EQ("Layer", layer.getName()); EXPECT_EQ(complex_t(1,0.5), layer.getRefractiveIndex()); - Layer *new_layer = layer.clone(); + Layer* new_layer = layer.clone(); EXPECT_EQ(something.getName(), new_layer->getMaterial()->getName()); EXPECT_EQ(nullptr, new_layer->getLayout(0)); EXPECT_EQ(20, new_layer->getThickness()); @@ -69,7 +66,6 @@ TEST_F(LayerTest, LayerGetAndSet) EXPECT_EQ(complex_t(1,0.5), new_layer->getRefractiveIndex()); EXPECT_EQ(0.0, new_layer->getTotalParticleSurfaceDensity(0)); EXPECT_EQ("Layer", new_layer->getName()); - EXPECT_EQ(nullptr, new_layer->createDWBASimulation()); delete new_layer; } @@ -77,7 +73,7 @@ TEST_F(LayerTest, LayerGetAndSet) TEST_F(LayerTest, LayerAndDecoration) { HomogeneousMaterial air("air",0,0); - ParticleLayout *p_layout1 = new ParticleLayout(); + ParticleLayout* p_layout1 = new ParticleLayout(); Layer layer(air, 10*Units::nanometer); layer.addLayout(*p_layout1); @@ -89,5 +85,4 @@ TEST_F(LayerTest, LayerAndDecoration) EXPECT_EQ("ParticleLayout", layer.getLayout(1)->getName()); } - #endif // LAYERTEST_H -- GitLab