Skip to content
Snippets Groups Projects
Commit d93a306b authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Moved getRefractiveIndex to IMaterial (no more dynamic_cast needed)

parent 5f3c58cf
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "IFormFactorBorn.h" #include "IFormFactorBorn.h"
#include "IStochasticParameter.h" #include "IStochasticParameter.h"
//! ? //! The form factor for a rectangular box
class FormFactorBox : public IFormFactorBorn class FormFactorBox : public IFormFactorBorn
{ {
......
...@@ -68,11 +68,9 @@ inline FormFactorDecoratorRefractiveIndex* FormFactorDecoratorRefractiveIndex::c ...@@ -68,11 +68,9 @@ inline FormFactorDecoratorRefractiveIndex* FormFactorDecoratorRefractiveIndex::c
inline void FormFactorDecoratorRefractiveIndex::setAmbientMaterial( inline void FormFactorDecoratorRefractiveIndex::setAmbientMaterial(
const IMaterial *p_material) const IMaterial *p_material)
{ {
const HomogeneousMaterial *p_hom_mat =
dynamic_cast<const HomogeneousMaterial *>(p_material);
complex_t ambient_refractive_index(1.0, 0.0); complex_t ambient_refractive_index(1.0, 0.0);
if (p_hom_mat) { if (p_material) {
ambient_refractive_index = p_hom_mat->getRefractiveIndex(); ambient_refractive_index = p_material->getRefractiveIndex();
} }
m_factor = getRefractiveIndexFactor(ambient_refractive_index, m_refractive_index); m_factor = getRefractiveIndexFactor(ambient_refractive_index, m_refractive_index);
} }
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
virtual ~HomogeneousMaterial() {} virtual ~HomogeneousMaterial() {}
//! Return refractive index. //! Return refractive index.
complex_t getRefractiveIndex() const { return m_refractive_index; } virtual complex_t getRefractiveIndex() const { return m_refractive_index; }
//! Set refractive index. //! Set refractive index.
void setRefractiveIndex(const complex_t &refractive_index) void setRefractiveIndex(const complex_t &refractive_index)
......
...@@ -45,6 +45,9 @@ public: ...@@ -45,6 +45,9 @@ public:
friend std::ostream &operator<<(std::ostream &ostr, const IMaterial &m) friend std::ostream &operator<<(std::ostream &ostr, const IMaterial &m)
{ m.print(ostr); return ostr; } { m.print(ostr); return ostr; }
//! Return refractive index.
virtual complex_t getRefractiveIndex() const { return 1.0; }
#ifndef GCCXML_SKIP_THIS #ifndef GCCXML_SKIP_THIS
//! Get the scattering matrix from the refractive index //! Get the scattering matrix from the refractive index
//! and a given wavevector //! and a given wavevector
......
...@@ -93,8 +93,8 @@ class BA_CORE_API_ Layer : public ICompositeSample ...@@ -93,8 +93,8 @@ class BA_CORE_API_ Layer : public ICompositeSample
inline complex_t Layer::getRefractiveIndex() const inline complex_t Layer::getRefractiveIndex() const
{ {
const HomogeneousMaterial *material = dynamic_cast<const HomogeneousMaterial *>(mp_material); return (mp_material ? mp_material->getRefractiveIndex()
return (material ? material->getRefractiveIndex() : complex_t(0,0)); : complex_t(1.0,0.0));
} }
inline double Layer::getTotalParticleSurfaceDensity() const inline double Layer::getTotalParticleSurfaceDensity() const
......
...@@ -107,8 +107,7 @@ inline IFormFactor* Particle::createFormFactor() const ...@@ -107,8 +107,7 @@ inline IFormFactor* Particle::createFormFactor() const
inline complex_t Particle::getRefractiveIndex() const inline complex_t Particle::getRefractiveIndex() const
{ {
const HomogeneousMaterial *material = dynamic_cast<const HomogeneousMaterial *>(mp_material); return (mp_material ? mp_material->getRefractiveIndex() : complex_t(0,0));
return (material ? material->getRefractiveIndex() : complex_t(0,0));
} }
inline bool Particle::hasDistributedFormFactor() const inline bool Particle::hasDistributedFormFactor() const
......
...@@ -43,13 +43,7 @@ IFormFactor *ParticleCoreShell::createFormFactor() const ...@@ -43,13 +43,7 @@ IFormFactor *ParticleCoreShell::createFormFactor() const
mp_shell->getRefractiveIndex()); mp_shell->getRefractiveIndex());
ff_shell.setAmbientMaterial(mp_ambient_material); ff_shell.setAmbientMaterial(mp_ambient_material);
p_result->addFormFactor(ff_shell, 1.0); p_result->addFormFactor(ff_shell, 1.0);
const HomogeneousMaterial *p_hom_mat = complex_t ambient_index = mp_ambient_material->getRefractiveIndex();
dynamic_cast<const HomogeneousMaterial *>(mp_ambient_material);
if (!p_hom_mat) {
throw NotImplementedException("ParticleCoreShell::createFormFactor:"
" ambient material must be homogeneous");
}
complex_t ambient_index = p_hom_mat->getRefractiveIndex();
complex_t core_index = std::sqrt(mp_core->getRefractiveIndex()*mp_core->getRefractiveIndex() complex_t core_index = std::sqrt(mp_core->getRefractiveIndex()*mp_core->getRefractiveIndex()
- mp_shell->getRefractiveIndex()*mp_shell->getRefractiveIndex() - mp_shell->getRefractiveIndex()*mp_shell->getRefractiveIndex()
+ ambient_index*ambient_index); + ambient_index*ambient_index);
......
...@@ -24,7 +24,7 @@ TEST_F(LayerTest, LayerInitialState) ...@@ -24,7 +24,7 @@ TEST_F(LayerTest, LayerInitialState)
EXPECT_EQ(NULL, layer.getDecoration()); EXPECT_EQ(NULL, layer.getDecoration());
EXPECT_EQ(0, layer.getThickness()); EXPECT_EQ(0, layer.getThickness());
EXPECT_FALSE(layer.hasDWBASimulation()); EXPECT_FALSE(layer.hasDWBASimulation());
EXPECT_EQ(complex_t(0,0), layer.getRefractiveIndex()); EXPECT_EQ(complex_t(1.0, 0.0), layer.getRefractiveIndex());
EXPECT_EQ(0.0, layer.getTotalParticleSurfaceDensity()); EXPECT_EQ(0.0, layer.getTotalParticleSurfaceDensity());
EXPECT_EQ("Layer", layer.getName()); EXPECT_EQ("Layer", layer.getName());
EXPECT_EQ(NULL, layer.createDWBASimulation()); EXPECT_EQ(NULL, layer.createDWBASimulation());
...@@ -35,7 +35,7 @@ TEST_F(LayerTest, LayerInitialState) ...@@ -35,7 +35,7 @@ TEST_F(LayerTest, LayerInitialState)
EXPECT_EQ(NULL, new_layer->getDecoration()); EXPECT_EQ(NULL, new_layer->getDecoration());
EXPECT_EQ(0, new_layer->getThickness()); EXPECT_EQ(0, new_layer->getThickness());
EXPECT_FALSE(new_layer->hasDWBASimulation()); EXPECT_FALSE(new_layer->hasDWBASimulation());
EXPECT_EQ(complex_t(0,0), new_layer->getRefractiveIndex()); EXPECT_EQ(complex_t(1.0, 0.0), new_layer->getRefractiveIndex());
EXPECT_EQ(0.0, new_layer->getTotalParticleSurfaceDensity()); EXPECT_EQ(0.0, new_layer->getTotalParticleSurfaceDensity());
EXPECT_EQ("Layer", new_layer->getName()); EXPECT_EQ("Layer", new_layer->getName());
EXPECT_EQ(NULL, new_layer->createDWBASimulation()); EXPECT_EQ(NULL, new_layer->createDWBASimulation());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment