diff --git a/Core/Algorithms/inc/Simulation.h b/Core/Algorithms/inc/Simulation.h index 5219d429c97106adf5b392f796ec085309ba1b7a..8b4f61d2ff2d1bb0886cb259214e52e3ab984058 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 8e156154cef2b3f70c51a14cd5b7e0939c2f6437..174ad4b7bee312e59367dedd2b2f4788acb89f5e 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 5dc32985d2caf722c86b19b39583f9c9dd6b9f83..299d32561b712c12d43596140332d9099124f9ab 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 eb414eb182de396e4c9a7482374d7b30ac6bd5ba..12dfad9d02b20e58eaff2d3f4a4ae7ee949d5e1c 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; }