diff --git a/Sim/Computation/DepthprobeComputation.cpp b/Sim/Computation/DepthprobeComputation.cpp index cb3e249253186b11e530c714e7ae705b15d5d908..fc09f13ba29ef5f2d0614778a9c1ad557560fff7 100644 --- a/Sim/Computation/DepthprobeComputation.cpp +++ b/Sim/Computation/DepthprobeComputation.cpp @@ -22,59 +22,52 @@ DepthprobeComputation::DepthprobeComputation(const ReSample& re_sample, const SimulationOptions& options, - ProgressHandler& progress, - DepthprobeElementIter begin_it, - DepthprobeElementIter end_it) + ProgressHandler& progress) : IComputation(re_sample, options, progress) - , m_begin_it(begin_it) - , m_end_it(end_it) { } DepthprobeComputation::~DepthprobeComputation() = default; -void DepthprobeComputation::runProtected() +void DepthprobeComputation::run(DepthprobeElement& ele) { - for (auto it = m_begin_it; it != m_end_it; ++it) { - DepthprobeElement& ele = *it; - if (!ele.isCalculated()) - continue; + if (!ele.isCalculated()) + return; - const IAxis& z_positions = *ele.getZPositions(); - const size_t n_z = z_positions.size(); - const size_t n_layers = m_re_sample.numberOfSlices(); - size_t start_z_ind = n_z; - std::valarray<double> intensities(0.0, n_z); + const IAxis& z_positions = *ele.getZPositions(); + const size_t n_z = z_positions.size(); + const size_t n_layers = m_re_sample.numberOfSlices(); + size_t start_z_ind = n_z; + std::valarray<double> intensities(0.0, n_z); - Fluxes fluxes = m_re_sample.fluxesIn(ele.getKi()); + Fluxes fluxes = m_re_sample.fluxesIn(ele.getKi()); - double z_layer_bottom(0.0); - double z_layer_top(0.0); - for (size_t i_layer = 0; i_layer < n_layers && start_z_ind != 0; ++i_layer) { - z_layer_bottom = m_re_sample.sliceBottomZ(i_layer); - z_layer_top = i_layer ? m_re_sample.sliceTopZ(i_layer) : 0; + double z_layer_bottom(0.0); + double z_layer_top(0.0); + for (size_t i_layer = 0; i_layer < n_layers && start_z_ind != 0; ++i_layer) { + z_layer_bottom = m_re_sample.sliceBottomZ(i_layer); + z_layer_top = i_layer ? m_re_sample.sliceTopZ(i_layer) : 0; - // get R & T coefficients for current layer - const auto* flux = dynamic_cast<const ScalarFlux*>(fluxes[i_layer]); - ASSERT(flux); - const complex_t R = flux->getScalarR(); - const complex_t T = flux->getScalarT(); - const complex_t kz_out = flux->getScalarKz(); - const complex_t kz_in = -kz_out; + // get R & T coefficients for current layer + const auto* flux = dynamic_cast<const ScalarFlux*>(fluxes[i_layer]); + ASSERT(flux); + const complex_t R = flux->getScalarR(); + const complex_t T = flux->getScalarT(); + const complex_t kz_out = flux->getScalarKz(); + const complex_t kz_in = -kz_out; - // Compute intensity for z's of the layer - size_t ip1_z = start_z_ind; - for (; ip1_z > 0; --ip1_z) { - const size_t i_z = ip1_z - 1; - if (i_layer + 1 != n_layers && z_positions[i_z] <= z_layer_bottom) - break; - const double z = z_positions[i_z] - z_layer_top; - intensities[i_z] = std::norm(R * exp_I(kz_out * z) + T * exp_I(kz_in * z)); - } - start_z_ind = ip1_z; + // Compute intensity for z's of the layer + size_t ip1_z = start_z_ind; + for (; ip1_z > 0; --ip1_z) { + const size_t i_z = ip1_z - 1; + if (i_layer + 1 != n_layers && z_positions[i_z] <= z_layer_bottom) + break; + const double z = z_positions[i_z] - z_layer_top; + intensities[i_z] = std::norm(R * exp_I(kz_out * z) + T * exp_I(kz_in * z)); } - ele.setIntensities(std::move(intensities)); - - stepProgress(); + start_z_ind = ip1_z; } + ele.setIntensities(std::move(intensities)); + + stepProgress(); } diff --git a/Sim/Computation/DepthprobeComputation.h b/Sim/Computation/DepthprobeComputation.h index efc7108151fdbb188b1cca8fe4df7ffc33693278..b3190a4f174c4321a5a30edf8d23398832f99558 100644 --- a/Sim/Computation/DepthprobeComputation.h +++ b/Sim/Computation/DepthprobeComputation.h @@ -33,14 +33,10 @@ class DepthprobeComputation : public IComputation { public: DepthprobeComputation(const ReSample& re_sample, const SimulationOptions& options, - ProgressHandler& progress, DepthprobeElementIter begin_it, - DepthprobeElementIter end_it); + ProgressHandler& progress); ~DepthprobeComputation() override; - void runProtected() override; - -private: - DepthprobeElementIter m_begin_it, m_end_it; + void run(DepthprobeElement& ele); }; #endif // BORNAGAIN_SIM_COMPUTATION_DEPTHPROBECOMPUTATION_H diff --git a/Sim/Computation/IComputation.h b/Sim/Computation/IComputation.h index 754c6fe568a586697fc93cde113bbc1efc7ba503..41a5d3388aa5d0f40de2aca3ec389bd8a70328bb 100644 --- a/Sim/Computation/IComputation.h +++ b/Sim/Computation/IComputation.h @@ -34,7 +34,7 @@ public: virtual ~IComputation(); //! Runs computation. May throw. - virtual void runProtected() = 0; + virtual void runProtected() {} protected: void stepProgress() const; diff --git a/Sim/Simulation/DepthprobeSimulation.cpp b/Sim/Simulation/DepthprobeSimulation.cpp index 24b8d2feed6f5921a76a6a24dc0439726dd48769..48f590f668d57bb5c1cd0700dcf5afaf28eb1655 100644 --- a/Sim/Simulation/DepthprobeSimulation.cpp +++ b/Sim/Simulation/DepthprobeSimulation.cpp @@ -139,9 +139,8 @@ void DepthprobeSimulation::initElementVector() void DepthprobeSimulation::runComputation(const ReSample& re_sample, size_t iElement) { - const auto& begin = m_depth_eles.begin() + static_cast<long>(iElement); - DepthprobeComputation(re_sample, options(), progress(), begin, begin + static_cast<long>(1)) - .runProtected(); + DepthprobeElement& ele = *(m_depth_eles.begin() + static_cast<long>(iElement)); + DepthprobeComputation(re_sample, options(), progress()).run(ele); } void DepthprobeSimulation::normalize(size_t start, size_t n_elements)