From 7cca67209f8bc1ad0d9ce281c23dcda4a9493500 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Mon, 5 Aug 2013 13:24:49 +0200 Subject: [PATCH] Added check for need to use polarization analysis (based on the materials used in the sample) --- Core/Algorithms/inc/Simulation.h | 3 +++ Core/Algorithms/src/Simulation.cpp | 19 +++++++++++++++++++ .../Samples/inc/HomogeneousMagneticMaterial.h | 2 +- Core/Samples/inc/IMaterial.h | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Core/Algorithms/inc/Simulation.h b/Core/Algorithms/inc/Simulation.h index 5219d429c97..8b4f61d2ff2 100644 --- a/Core/Algorithms/inc/Simulation.h +++ b/Core/Algorithms/inc/Simulation.h @@ -130,6 +130,9 @@ class BA_CORE_API_ Simulation : public IParameterized, public ICloneable //! Update the sample by calling the sample builder, if present void updateSample(); + //! Checks if the sample requires a polarized calculation + bool checkPolarizationPresent() const; + // components describing an experiment and its simulation: ISample *mp_sample; const ISampleBuilder *mp_sample_builder; diff --git a/Core/Algorithms/src/Simulation.cpp b/Core/Algorithms/src/Simulation.cpp index 8e156154cef..174ad4b7bee 100644 --- a/Core/Algorithms/src/Simulation.cpp +++ b/Core/Algorithms/src/Simulation.cpp @@ -19,6 +19,7 @@ #include "ProgramOptions.h" #include "DWBASimulation.h" #include "MessageService.h" +#include "SampleMaterialVisitor.h" #include <boost/thread.hpp> #include <gsl/gsl_errno.h> @@ -334,6 +335,24 @@ void Simulation::updateSample() } } +bool Simulation::checkPolarizationPresent() const +{ + if (!mp_sample) { + throw ClassInitializationException("Simulation::" + "checkPolarizationPresent(): sample not initialized"); + } + SampleMaterialVisitor material_vis; + mp_sample->accept(&material_vis); + std::vector<const IMaterial *> materials = material_vis.getMaterials(); + for (std::vector<const IMaterial *>::const_iterator it = materials.begin(); + it != materials.end(); ++it) { + if (!(*it)->isScalarMaterial()) { + return true; + } + } + return false; +} + void Simulation::setDetectorParameters(const OutputData<double >& output_data) { m_instrument.matchDetectorParameters(output_data); diff --git a/Core/Samples/inc/HomogeneousMagneticMaterial.h b/Core/Samples/inc/HomogeneousMagneticMaterial.h index 5dc32985d2c..299d32561b7 100644 --- a/Core/Samples/inc/HomogeneousMagneticMaterial.h +++ b/Core/Samples/inc/HomogeneousMagneticMaterial.h @@ -48,7 +48,7 @@ public: //! Indicates that the material is not scalar. This means that different //! polarization states will be diffracted differently - virtual bool isScalarMaterial() { return false; } + virtual bool isScalarMaterial() const { return false; } //! Get the scattering matrix from the refractive index, the //! magnetic field and a given wavevector diff --git a/Core/Samples/inc/IMaterial.h b/Core/Samples/inc/IMaterial.h index eb414eb182d..12dfad9d02b 100644 --- a/Core/Samples/inc/IMaterial.h +++ b/Core/Samples/inc/IMaterial.h @@ -40,7 +40,7 @@ public: //! Indicates whether the interaction with the material is scalar. //! This means that different polarization states will be diffracted //! equally - virtual bool isScalarMaterial() { return true; } + virtual bool isScalarMaterial() const { return true; } friend std::ostream &operator<<(std::ostream &ostr, const IMaterial &m) { m.print(ostr); return ostr; } -- GitLab