Skip to content
Snippets Groups Projects
Commit d3bdc09f authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

make fct local

parent 8d031b2d
No related branches found
No related tags found
1 merge request!154further simplification of ProcessedSample
......@@ -32,14 +32,80 @@
#include "Sample/Specular/SpecularStrategyBuilder.h"
#include <functional>
//! Returns a SliceStack that refines the layer structure of sample,
//! taking into account the average SLD of layer material and particle decoration.
namespace {
SliceStack slicify(const MultiLayer& sample, const SimulationOptions& options)
{
SliceStack result;
if (sample.numberOfLayers() == 0)
return result;
const bool use_slicing = options.useAvgMaterials() && sample.numberOfLayers() > 1;
const auto layer_limits = SampleUtils::Preprocessor::particleRegions(sample, use_slicing);
for (size_t i = 0; i < sample.numberOfLayers(); ++i) {
const Layer* const layer = sample.layer(i);
const size_t N = layer->numberOfSlices();
if (N == 0)
throw std::runtime_error("Cannot process layer with numberOfSlices=0");
const ZLimits& slice_limits = layer_limits[i];
double tl = layer->thickness();
const Material* const material = layer->material();
const LayerRoughness* roughness = SampleUtils::Multilayer::LayerTopRoughness(sample, i);
if (roughness && roughness->getSigma() <= 0)
roughness = nullptr;
// if no slicing is needed, create single slice for the layer
if (!slice_limits.isFinite() || N == 0) {
if (i == sample.numberOfLayers() - 1)
tl = 0.0;
if (i == 0)
result.addTopSlice(tl, *material);
else
result.addSlice(tl, *material, roughness);
continue;
}
const double top = slice_limits.zTop();
const double bottom = slice_limits.zBottom();
// top layer
if (i == 0) {
if (top <= 0)
throw std::runtime_error("ProcessedSample::ProcessedSample: "
"top limit for top layer must be > 0.");
result.addTopSlice(top, *material); // semiinfinite top slice
result.addNSlices(N, top - bottom, *material);
if (bottom > 0)
result.addSlice(bottom, *material);
}
// middle or bottom layer
else {
if (top < 0) {
result.addSlice(-top, *material, roughness);
result.addNSlices(N, top - bottom, *material);
} else {
result.addNSlices(N, top - bottom, *material, roughness);
}
// middle layer
if (i < sample.numberOfLayers() - 1 && bottom > -tl)
result.addSlice(bottom + tl, *material);
// bottom layer
if (i == sample.numberOfLayers() - 1)
result.addSlice(0.0, *material); // semiinfinite bottom slice
}
}
return result;
}
} // namespace
ProcessedSample::ProcessedSample(const MultiLayer& sample, const SimulationOptions& options,
bool forcePolarized)
: m_slices{}
: m_slices{slicify(sample, options)}
, m_polarized{forcePolarized || sample.isMagnetic()}
, m_crossCorrLength{sample.crossCorrLength()}
, m_ext_field{sample.externalField()}
{
initSlices(sample, options); // set m_slices
initBFields(); // set B field in all slices.
initLayouts(sample); // set m_layouts and m_region_map
......@@ -144,67 +210,6 @@ double ProcessedSample::crossCorrSpectralFun(const kvector_t kvec, size_t j, siz
* std::exp(-1 * std::abs(z_j - z_k) / m_crossCorrLength);
}
//! Creates a array of slices with the correct thickness, roughness and material.
//!
//! Sets m_slices (through addSlice).
void ProcessedSample::initSlices(const MultiLayer& sample, const SimulationOptions& options)
{
if (sample.numberOfLayers() == 0)
return;
const bool use_slicing = options.useAvgMaterials() && sample.numberOfLayers() > 1;
const auto layer_limits = SampleUtils::Preprocessor::particleRegions(sample, use_slicing);
for (size_t i = 0; i < sample.numberOfLayers(); ++i) {
const Layer* const layer = sample.layer(i);
const size_t N = layer->numberOfSlices();
if (N == 0)
throw std::runtime_error("Cannot process layer with numberOfSlices=0");
const ZLimits& slice_limits = layer_limits[i];
double tl = layer->thickness();
const Material* const material = layer->material();
const LayerRoughness* roughness = SampleUtils::Multilayer::LayerTopRoughness(sample, i);
if (roughness && roughness->getSigma() <= 0)
roughness = nullptr;
// if no slicing is needed, create single slice for the layer
if (!slice_limits.isFinite() || N == 0) {
if (i == sample.numberOfLayers() - 1)
tl = 0.0;
if (i == 0)
m_slices.addTopSlice(tl, *material);
else
m_slices.addSlice(tl, *material, roughness);
continue;
}
const double top = slice_limits.zTop();
const double bottom = slice_limits.zBottom();
// top layer
if (i == 0) {
if (top <= 0)
throw std::runtime_error("ProcessedSample::ProcessedSample: "
"top limit for top layer must be > 0.");
m_slices.addTopSlice(top, *material); // semiinfinite top slice
m_slices.addNSlices(N, top - bottom, *material);
if (bottom > 0)
m_slices.addSlice(bottom, *material);
}
// middle or bottom layer
else {
if (top < 0) {
m_slices.addSlice(-top, *material, roughness);
m_slices.addNSlices(N, top - bottom, *material);
} else {
m_slices.addNSlices(N, top - bottom, *material, roughness);
}
// middle layer
if (i < sample.numberOfLayers() - 1 && bottom > -tl)
m_slices.addSlice(bottom + tl, *material);
// bottom layer
if (i == sample.numberOfLayers() - 1)
m_slices.addSlice(0.0, *material); // semiinfinite bottom slice
}
}
}
//! Modifies m_region_map.
void ProcessedSample::mergeRegionMap(
......
......@@ -64,7 +64,6 @@ public:
double crossCorrSpectralFun(const kvector_t kvec, size_t j, size_t k) const;
private:
void initSlices(const MultiLayer& sample, const SimulationOptions& options);
void mergeRegionMap(const std::map<size_t, std::vector<HomogeneousRegion>>& region_map);
void initLayouts(const MultiLayer& sample);
void initBFields();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment