Skip to content
Snippets Groups Projects
Commit 4810963e authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Refactor: MatrixFresnelMap now maintains two caches (in/out) of calculated Fresnel coefficients

parent 166a89fc
No related branches found
No related tags found
No related merge requests found
......@@ -21,23 +21,44 @@
#include "SpecularMagnetic.h"
MatrixFresnelMap::MatrixFresnelMap(const MultiLayer* p_multilayer,
const MultiLayer* p_inverted_multilayer)
const MultiLayer* p_inverted_multilayer)
: mp_multilayer(p_multilayer)
, mp_inverted_multilayer(p_inverted_multilayer)
{}
MatrixFresnelMap::~MatrixFresnelMap()
{}
const ILayerRTCoefficients* MatrixFresnelMap::getOutCoefficients(
const SimulationElement& sim_element, size_t layer_index) const
{
std::vector<MatrixRTCoefficients> coeffs;
SpecularMagnetic::execute(*mp_inverted_multilayer, -sim_element.getMeanKf(), coeffs);
return new MatrixRTCoefficients(coeffs[layer_index]);
MatrixRTCoefficients* result;
kvector_t kvec = -sim_element.getMeanKf();
auto it = m_hash_table_out.find(kvec);
if (it != m_hash_table_out.end())
result = new MatrixRTCoefficients(it->second[layer_index]);
else {
std::vector<MatrixRTCoefficients> coeffs;
SpecularMagnetic::execute(*mp_inverted_multilayer, kvec, coeffs);
result = new MatrixRTCoefficients(coeffs[layer_index]);
m_hash_table_out[kvec] = std::move(coeffs);
}
return result;
}
const ILayerRTCoefficients* MatrixFresnelMap::getInCoefficients(
const SimulationElement& sim_element, size_t layer_index) const
{
std::vector<MatrixRTCoefficients> coeffs;
SpecularMagnetic::execute(*mp_multilayer, sim_element.getKi(), coeffs);
return new MatrixRTCoefficients(coeffs[layer_index]);
MatrixRTCoefficients* result;
kvector_t kvec = sim_element.getKi();
auto it = m_hash_table_in.find(kvec);
if (it != m_hash_table_in.end())
result = new MatrixRTCoefficients(it->second[layer_index]);
else {
std::vector<MatrixRTCoefficients> coeffs;
SpecularMagnetic::execute(*mp_multilayer, kvec, coeffs);
result = new MatrixRTCoefficients(coeffs[layer_index]);
m_hash_table_in[kvec] = std::move(coeffs);
}
return result;
}
......@@ -16,10 +16,13 @@
#ifndef MATRIXFRESNELMAP_H
#define MATRIXFRESNELMAP_H
#include "HashKVector.h"
#include "IFresnelMap.h"
#include <cstddef>
#include <unordered_map>
#include <vector>
class ILayerRTCoefficients;
class MatrixRTCoefficients;
class MultiLayer;
class SimulationElement;
......@@ -30,7 +33,7 @@ class BA_CORE_API_ MatrixFresnelMap : public IFresnelMap
{
public:
MatrixFresnelMap(const MultiLayer* p_multilayer, const MultiLayer* p_inverted_multilayer);
~MatrixFresnelMap() final {}
~MatrixFresnelMap() final;
//! Retrieves the amplitude coefficients for the given angles
const ILayerRTCoefficients* getOutCoefficients(
......@@ -43,6 +46,10 @@ public:
private:
const MultiLayer* mp_multilayer;
const MultiLayer* mp_inverted_multilayer;
mutable std::unordered_map<kvector_t, std::vector<MatrixRTCoefficients>,
HashKVector> m_hash_table_out;
mutable std::unordered_map<kvector_t, std::vector<MatrixRTCoefficients>,
HashKVector> m_hash_table_in;
};
#endif // MATRIXFRESNELMAP_H
......@@ -21,8 +21,8 @@
#include <unordered_map>
#include <vector>
class MultiLayer;
class ILayerRTCoefficients;
class MultiLayer;
class ScalarRTCoefficients;
class SimulationElement;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment