From 0144cbabda2eaed3e319d47e47a7835b7ea9735c Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Mon, 21 Dec 2020 13:02:56 +0100 Subject: [PATCH] call beam() and detector() w/o instrument() --- Core/Export/SimulationToPython.cpp | 6 +++--- Core/Simulation/DepthProbeSimulation.cpp | 10 +++++----- Core/Simulation/GISASSimulation.cpp | 6 +++--- Core/Simulation/ISimulation.cpp | 8 +++----- Core/Simulation/OffSpecularSimulation.cpp | 11 +++++------ Core/Simulation/SpecularSimulation.cpp | 2 +- GUI/coregui/Models/TransformFromDomain.cpp | 6 +++--- .../Core/Fresnel/DepthProbeSimulationTest.cpp | 4 ++-- .../Core/Fresnel/SpecularSimulationTest.cpp | 8 ++++---- .../Core/Instrument/RectangularDetectorTest.cpp | 16 ++++++++-------- auto/Wrap/libBornAgainBase_wrap.cpp | 2 +- auto/Wrap/libBornAgainFit_wrap.cpp | 2 +- 12 files changed, 39 insertions(+), 42 deletions(-) diff --git a/Core/Export/SimulationToPython.cpp b/Core/Export/SimulationToPython.cpp index 133512ac2a2..3835e78b16f 100644 --- a/Core/Export/SimulationToPython.cpp +++ b/Core/Export/SimulationToPython.cpp @@ -272,7 +272,7 @@ std::string defineBeamIntensity(const Beam& beam) std::string defineGISASBeam(const GISASSimulation& simulation) { std::ostringstream result; - const Beam& beam = simulation.instrument().beam(); + const Beam& beam = simulation.beam(); result << indent() << "beam = ba.Beam(" << pyfmt::printDouble(beam.intensity()) << ", " << pyfmt::printNm(beam.wavelength()) << ", ba.Direction(" @@ -287,7 +287,7 @@ std::string defineGISASBeam(const GISASSimulation& simulation) std::string defineOffSpecularBeam(const OffSpecularSimulation& simulation) { std::ostringstream result; - const Beam& beam = simulation.instrument().beam(); + const Beam& beam = simulation.beam(); const std::string axidef = indent() + "alpha_i_axis = "; result << axidef << pyfmt2::printAxis(simulation.beamAxis(), "rad") << "\n"; @@ -310,7 +310,7 @@ std::string defineSpecularScan(const SpecularSimulation& simulation) "does not contain any scan"); result << defineScan(scan) << "\n"; result << indent() << "simulation.setScan(scan)\n"; - result << defineBeamIntensity(simulation.instrument().beam()) << "\n"; + result << defineBeamIntensity(simulation.beam()) << "\n"; return result.str(); } diff --git a/Core/Simulation/DepthProbeSimulation.cpp b/Core/Simulation/DepthProbeSimulation.cpp index f254f3e86ad..a9e03a73500 100644 --- a/Core/Simulation/DepthProbeSimulation.cpp +++ b/Core/Simulation/DepthProbeSimulation.cpp @@ -98,7 +98,7 @@ size_t DepthProbeSimulation::intensityMapSize() const std::unique_ptr<IUnitConverter> DepthProbeSimulation::createUnitConverter() const { - return std::make_unique<DepthProbeConverter>(instrument().beam(), *m_alpha_axis, *m_z_axis); + return std::make_unique<DepthProbeConverter>(beam(), *m_alpha_axis, *m_z_axis); } DepthProbeSimulation::DepthProbeSimulation(const DepthProbeSimulation& other) @@ -141,12 +141,12 @@ void DepthProbeSimulation::setBeamParameters(double lambda, const IAxis& alpha_a instrument().setBeamParameters(lambda, zero_alpha_i, zero_phi_i); if (beam_shape) - instrument().beam().setFootprintFactor(*beam_shape); + beam().setFootprintFactor(*beam_shape); } void DepthProbeSimulation::initSimulationElementVector() { - m_sim_elements = generateSimulationElements(instrument().beam()); + m_sim_elements = generateSimulationElements(beam()); if (!m_cache.empty()) return; @@ -222,7 +222,7 @@ void DepthProbeSimulation::initialize() // allow for negative inclinations in the beam of specular simulation // it is required for proper averaging in the case of divergent beam - auto inclination = instrument().beam().parameter("InclinationAngle"); + auto inclination = beam().parameter("InclinationAngle"); inclination->setLimits(RealLimits::limited(-M_PI_2, M_PI_2)); } @@ -232,7 +232,7 @@ void DepthProbeSimulation::normalize(size_t start_ind, size_t n_elements) for (size_t i = start_ind, stop_point = start_ind + n_elements; i < stop_point; ++i) { auto& element = m_sim_elements[i]; const double alpha_i = -element.getAlphaI(); - const auto footprint = instrument().beam().footprintFactor(); + const auto footprint = beam().footprintFactor(); double intensity_factor = beam_intensity; if (footprint != nullptr) intensity_factor = intensity_factor * footprint->calculate(alpha_i); diff --git a/Core/Simulation/GISASSimulation.cpp b/Core/Simulation/GISASSimulation.cpp index ec4a277f073..2e9df72829b 100644 --- a/Core/Simulation/GISASSimulation.cpp +++ b/Core/Simulation/GISASSimulation.cpp @@ -51,7 +51,7 @@ SimulationResult GISASSimulation::result() const { const auto converter = UnitConverterUtils::createConverterForGISAS(instrument()); const std::unique_ptr<OutputData<double>> data( - instrument().detector().createDetectorIntensity(m_sim_elements)); + detector().createDetectorIntensity(m_sim_elements)); return SimulationResult(*data, *converter); } @@ -66,7 +66,7 @@ void GISASSimulation::setBeamParameters(double wavelength, double alpha_i, doubl size_t GISASSimulation::intensityMapSize() const { size_t result = 0; - instrument().detector().iterate([&result](IDetector::const_iterator) { ++result; }, true); + detector().iterate([&result](IDetector::const_iterator) { ++result; }, true); return result; } @@ -77,7 +77,7 @@ GISASSimulation::GISASSimulation(const GISASSimulation& other) : ISimulation2D(o void GISASSimulation::initSimulationElementVector() { - m_sim_elements = generateSimulationElements(instrument().beam()); + m_sim_elements = generateSimulationElements(beam()); if (m_cache.empty()) m_cache.resize(m_sim_elements.size(), 0.0); } diff --git a/Core/Simulation/ISimulation.cpp b/Core/Simulation/ISimulation.cpp index 8dbc85d37bb..6bec0749100 100644 --- a/Core/Simulation/ISimulation.cpp +++ b/Core/Simulation/ISimulation.cpp @@ -317,12 +317,10 @@ SimulationResult ISimulation::convertData(const OutputData<double>& data, auto converter = UnitConverterUtils::createConverter(*this); auto roi_data = UnitConverterUtils::createOutputData(*converter, converter->defaultUnits()); - const IDetector& detector = instrument().detector(); - if (roi_data->hasSameDimensions(data)) { // data is already cropped to ROI if (put_masked_areas_to_zero) { - detector.iterate( + detector().iterate( [&](IDetector::const_iterator it) { (*roi_data)[it.roiIndex()] = data[it.roiIndex()]; }, @@ -331,9 +329,9 @@ SimulationResult ISimulation::convertData(const OutputData<double>& data, roi_data->setRawDataVector(data.getRawDataVector()); } - } else if (detHasSameDimensions(detector, data)) { + } else if (detHasSameDimensions(detector(), data)) { // exp data has same shape as the detector, we have to put orig data to smaller roi map - detector.iterate( + detector().iterate( [&](IDetector::const_iterator it) { (*roi_data)[it.roiIndex()] = data[it.detectorIndex()]; }, diff --git a/Core/Simulation/OffSpecularSimulation.cpp b/Core/Simulation/OffSpecularSimulation.cpp index a2610b9eb13..4e454e19f93 100644 --- a/Core/Simulation/OffSpecularSimulation.cpp +++ b/Core/Simulation/OffSpecularSimulation.cpp @@ -48,7 +48,7 @@ size_t OffSpecularSimulation::numberOfSimulationElements() const SimulationResult OffSpecularSimulation::result() const { auto data = std::unique_ptr<OutputData<double>>(m_intensity_map.clone()); - OffSpecularConverter converter(instrument().detector2D(), instrument().beam(), *m_alpha_i_axis); + OffSpecularConverter converter(instrument().detector2D(), beam(), *m_alpha_i_axis); return SimulationResult(*data, converter); } @@ -75,8 +75,7 @@ std::unique_ptr<IUnitConverter> OffSpecularSimulation::createUnitConverter() con if (!axis) throw std::runtime_error("Error in OffSpecularSimulation::createUnitConverter:" " missing inclination angle axis"); - return std::make_unique<OffSpecularConverter>(instrument().detector2D(), instrument().beam(), - *axis); + return std::make_unique<OffSpecularConverter>(instrument().detector2D(), beam(), *axis); } size_t OffSpecularSimulation::intensityMapSize() const @@ -97,10 +96,10 @@ OffSpecularSimulation::OffSpecularSimulation(const OffSpecularSimulation& other) void OffSpecularSimulation::initSimulationElementVector() { m_sim_elements.clear(); - Beam beam = instrument().beam(); + Beam beam2 = beam(); for (size_t i = 0; i < m_alpha_i_axis->size(); ++i) { - beam.setInclination(m_alpha_i_axis->bin(i).center()); - std::vector<SimulationElement> sim_elements_i = generateSimulationElements(beam); + beam2.setInclination(m_alpha_i_axis->bin(i).center()); + std::vector<SimulationElement> sim_elements_i = generateSimulationElements(beam2); for (auto ele : sim_elements_i) m_sim_elements.emplace_back(ele); } diff --git a/Core/Simulation/SpecularSimulation.cpp b/Core/Simulation/SpecularSimulation.cpp index 24b0863a6b8..37f0d9d7bdd 100644 --- a/Core/Simulation/SpecularSimulation.cpp +++ b/Core/Simulation/SpecularSimulation.cpp @@ -204,7 +204,7 @@ void SpecularSimulation::normalize(size_t start_ind, size_t n_elements) std::vector<double> footprints; // TODO: use just m_scan when pointwise resolution is implemented if (const auto* aScan = dynamic_cast<const AngularSpecScan*>(m_scan.get())) - footprints = mangledScan(*aScan, instrument().beam())->footprint(start_ind, n_elements); + footprints = mangledScan(*aScan, beam())->footprint(start_ind, n_elements); else footprints = m_scan->footprint(start_ind, n_elements); diff --git a/GUI/coregui/Models/TransformFromDomain.cpp b/GUI/coregui/Models/TransformFromDomain.cpp index ca6fa3ecc4c..854491afb3f 100644 --- a/GUI/coregui/Models/TransformFromDomain.cpp +++ b/GUI/coregui/Models/TransformFromDomain.cpp @@ -239,7 +239,7 @@ bool TransformFromDomain::isValidRoughness(const LayerRoughness* roughness) void TransformFromDomain::setGISASBeamItem(BeamItem* beam_item, const GISASSimulation& simulation) { ASSERT(beam_item); - Beam beam = simulation.instrument().beam(); + Beam beam = simulation.beam(); beam_item->setIntensity(beam.intensity()); beam_item->setWavelength(beam.wavelength()); @@ -265,7 +265,7 @@ void TransformFromDomain::setGISASBeamItem(BeamItem* beam_item, const GISASSimul void TransformFromDomain::setOffSpecularBeamItem(BeamItem* beam_item, const OffSpecularSimulation& simulation) { - Beam beam = simulation.instrument().beam(); + Beam beam = simulation.beam(); beam_item->setIntensity(beam.intensity()); beam_item->setWavelength(beam.wavelength()); @@ -277,7 +277,7 @@ void TransformFromDomain::setOffSpecularBeamItem(BeamItem* beam_item, void TransformFromDomain::setSpecularBeamItem(SpecularBeamItem* beam_item, const SpecularSimulation& simulation) { - const Beam& beam = simulation.instrument().beam(); + const Beam& beam = simulation.beam(); beam_item->setIntensity(beam.intensity()); beam_item->setWavelength(beam.wavelength()); diff --git a/Tests/UnitTests/Core/Fresnel/DepthProbeSimulationTest.cpp b/Tests/UnitTests/Core/Fresnel/DepthProbeSimulationTest.cpp index 224e44ab82b..70f6d245b21 100644 --- a/Tests/UnitTests/Core/Fresnel/DepthProbeSimulationTest.cpp +++ b/Tests/UnitTests/Core/Fresnel/DepthProbeSimulationTest.cpp @@ -48,7 +48,7 @@ std::unique_ptr<DepthProbeSimulation> DepthProbeSimulationTest::defaultSimulatio void DepthProbeSimulationTest::checkBeamState(const DepthProbeSimulation& sim) { - const auto* inclination = sim.instrument().beam().parameter("InclinationAngle"); + const auto* inclination = sim.beam().parameter("InclinationAngle"); const auto test_limits = RealLimits::limited(-M_PI_2, M_PI_2); EXPECT_EQ(test_limits, inclination->limits()); EXPECT_EQ(0.0, inclination->value()); @@ -98,7 +98,7 @@ TEST_F(DepthProbeSimulationTest, CheckAxesOfDefaultSimulation) TEST_F(DepthProbeSimulationTest, SetBeamParameters) { DepthProbeSimulation sim; - const auto& beam = sim.instrument().beam(); + const auto& beam = sim.beam(); sim.setBeamParameters(1.0, 10, 1.0 * Units::deg, 10.0 * Units::deg); EXPECT_EQ(10u, sim.getAlphaAxis()->size()); diff --git a/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.cpp b/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.cpp index 04b9ce2a001..742919cc530 100644 --- a/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.cpp +++ b/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.cpp @@ -60,7 +60,7 @@ std::unique_ptr<SpecularSimulation> SpecularSimulationTest::defaultSimulation() void SpecularSimulationTest::checkBeamState(const SpecularSimulation& sim) { - const auto* inclination = sim.instrument().beam().parameter("InclinationAngle"); + const auto* inclination = sim.beam().parameter("InclinationAngle"); const auto test_limits = RealLimits::limited(-M_PI_2, M_PI_2); EXPECT_EQ(test_limits, inclination->limits()); EXPECT_EQ(0.0, inclination->value()); @@ -85,7 +85,7 @@ TEST_F(SpecularSimulationTest, SetAngularScan) SpecularSimulation sim; AngularSpecScan scan(1.0, std::vector<double>{1.0 * Units::deg, 3.0 * Units::deg}); sim.setScan(scan); - const auto& beam = sim.instrument().beam(); + const auto& beam = sim.beam(); EXPECT_EQ(2u, sim.coordinateAxis()->size()); EXPECT_EQ(1.0 * Units::deg, sim.coordinateAxis()->lowerBound()); @@ -134,7 +134,7 @@ TEST_F(SpecularSimulationTest, SetQScan) QSpecScan scan(std::vector<double>{1.0, 3.0}); sim.setScan(scan); - const auto& beam = sim.instrument().beam(); + const auto& beam = sim.beam(); EXPECT_EQ(2u, sim.coordinateAxis()->size()); EXPECT_EQ(1.0, sim.coordinateAxis()->lowerBound()); @@ -243,7 +243,7 @@ TEST_F(SpecularSimulationTest, AddingBeamDistributions) TEST_F(SpecularSimulationTest, OutOfRangeAngles) { auto sim = defaultSimulation(); - auto& beam = sim->instrument().beam(); + auto& beam = sim->beam(); beam.parameter("InclinationAngle")->setValue(-0.2 * Units::deg); sim->runSimulation(); diff --git a/Tests/UnitTests/Core/Instrument/RectangularDetectorTest.cpp b/Tests/UnitTests/Core/Instrument/RectangularDetectorTest.cpp index ecd91bd6c27..0bb315d3b8c 100644 --- a/Tests/UnitTests/Core/Instrument/RectangularDetectorTest.cpp +++ b/Tests/UnitTests/Core/Instrument/RectangularDetectorTest.cpp @@ -80,13 +80,13 @@ TEST_F(RectangularDetectorTest, PerpToSample) // initializing with the simulation GISASSimulation simulation; simulation.setBeamParameters(1.0, 10.0 * Units::deg, 0.0); - det.init(simulation.instrument().beam()); + det.init(simulation.beam()); EXPECT_TRUE(kvector_t(distance, 0, 0) == det.getNormalVector()); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); // FIXME cleanup, replace with DetectorContext tests // std::vector<DetectorElement> elements - // = det.createDetectorElements(simulation.instrument().beam()); + // = det.createDetectorElements(simulation.beam()); // EXPECT_EQ(elements.size(), nbinsx * nbinsy); // double wavelength = 1.0; @@ -134,13 +134,13 @@ TEST_F(RectangularDetectorTest, PerpToDirectBeam) // initializing with the simulation GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); - det.init(simulation.instrument().beam()); + det.init(simulation.beam()); kvector_t normal(distance * cos(alpha_i), 0.0, -1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); // std::vector<DetectorElement> elements - // = det.createDetectorElements(simulation.instrument().beam()); + // = det.createDetectorElements(simulation.beam()); // EXPECT_EQ(elements.size(), nbinsx * nbinsy); // // lower left bin @@ -177,14 +177,14 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeam) // initializing with the simulation GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); - det.init(simulation.instrument().beam()); + det.init(simulation.beam()); kvector_t normal(distance * cos(alpha_i), 0.0, 1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); // // checking detector elements // std::vector<DetectorElement> elements - // = det.createDetectorElements(simulation.instrument().beam()); + // = det.createDetectorElements(simulation.beam()); // EXPECT_EQ(elements.size(), nbinsx * nbinsy); // double ds = v0 - dy / 2.; @@ -232,7 +232,7 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeamDpos) // initializing with the simulation GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); - det.init(simulation.instrument().beam()); + det.init(simulation.beam()); kvector_t normal(distance * cos(alpha_i), 0.0, 1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); @@ -242,7 +242,7 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeamDpos) // // checking detector elements // std::vector<DetectorElement> elements - // = det.createDetectorElements(simulation.instrument().beam()); + // = det.createDetectorElements(simulation.beam()); // EXPECT_EQ(elements.size(), nbinsx * nbinsy); // double ds = v0 - dy / 2.; diff --git a/auto/Wrap/libBornAgainBase_wrap.cpp b/auto/Wrap/libBornAgainBase_wrap.cpp index 3f552042266..1ba716ca029 100644 --- a/auto/Wrap/libBornAgainBase_wrap.cpp +++ b/auto/Wrap/libBornAgainBase_wrap.cpp @@ -5665,7 +5665,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_ (PyObject *o, std::complex<double>* val) SWIGINTERNINLINE PyObject* -SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/share/swig4.0/typemaps/swigmacros.swg,104,%ifcplusplus@*/ +SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/local/share/swig/4.0.2/typemaps/swigmacros.swg,104,%ifcplusplus@*/ const std::complex<double>& diff --git a/auto/Wrap/libBornAgainFit_wrap.cpp b/auto/Wrap/libBornAgainFit_wrap.cpp index 4da2484a8ce..1a63f365542 100644 --- a/auto/Wrap/libBornAgainFit_wrap.cpp +++ b/auto/Wrap/libBornAgainFit_wrap.cpp @@ -5665,7 +5665,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_ (PyObject *o, std::complex<double>* val) SWIGINTERNINLINE PyObject* -SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/share/swig4.0/typemaps/swigmacros.swg,104,%ifcplusplus@*/ +SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/local/share/swig/4.0.2/typemaps/swigmacros.swg,104,%ifcplusplus@*/ const std::complex<double>& -- GitLab