BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ScalarFresnelMap Class Reference
Inheritance diagram for ScalarFresnelMap:
Collaboration diagram for ScalarFresnelMap:

Classes

class  Hash2Doubles
 

Public Member Functions

 ScalarFresnelMap (std::unique_ptr< ISpecularStrategy > strategy)
 
 ~ScalarFresnelMap () final
 
 ScalarFresnelMap (const ScalarFresnelMap &other)=delete
 
ScalarFresnelMapoperator= (const ScalarFresnelMap &other)=delete
 
std::unique_ptr< const ILayerRTCoefficientsgetOutCoefficients (const SimulationElement &sim_element, size_t layer_index) const override
 
template<typename T >
std::unique_ptr< const ILayerRTCoefficientsgetInCoefficients (const T &sim_element, size_t layer_index) const
 
virtual void setSlices (const std::vector< Slice > &slices)
 
const std::vector< Slice > & slices () const
 
void disableCaching ()
 

Protected Attributes

std::vector< Slicem_slices
 
bool m_use_cache
 
std::unique_ptr< ISpecularStrategym_Strategy
 

Private Member Functions

std::unique_ptr< const ILayerRTCoefficientsgetCoefficients (const kvector_t &kvec, size_t layer_index) const override
 
const ISpecularStrategy::coeffs_tgetCoefficientsFromCache (kvector_t kvec) const
 

Private Attributes

std::unordered_map< std::pair< double, double >, ISpecularStrategy::coeffs_t, Hash2Doublesm_cache
 

Detailed Description

Implementation of IFresnelMap for scalar valued reflection/transmission coefficients.

Definition at line 32 of file ScalarFresnelMap.h.

Constructor & Destructor Documentation

◆ ScalarFresnelMap() [1/2]

ScalarFresnelMap::ScalarFresnelMap ( std::unique_ptr< ISpecularStrategy strategy)

Definition at line 19 of file ScalarFresnelMap.cpp.

20  : IFresnelMap(std::move(strategy))
21 {
22 }
IFresnelMap(std::unique_ptr< ISpecularStrategy > strategy)
Definition: IFresnelMap.cpp:18

◆ ~ScalarFresnelMap()

ScalarFresnelMap::~ScalarFresnelMap ( )
finaldefault

◆ ScalarFresnelMap() [2/2]

ScalarFresnelMap::ScalarFresnelMap ( const ScalarFresnelMap other)
delete

Member Function Documentation

◆ operator=()

ScalarFresnelMap& ScalarFresnelMap::operator= ( const ScalarFresnelMap other)
delete

◆ getOutCoefficients()

std::unique_ptr< const ILayerRTCoefficients > ScalarFresnelMap::getOutCoefficients ( const SimulationElement sim_element,
size_t  layer_index 
) const
overridevirtual

Retrieves the amplitude coefficients for a (time-reversed) outgoing wavevector.

Implements IFresnelMap.

Definition at line 34 of file ScalarFresnelMap.cpp.

35 {
36  return getCoefficients(-sim_element.getMeanKf(), layer_index);
37 }
std::unique_ptr< const ILayerRTCoefficients > getCoefficients(const kvector_t &kvec, size_t layer_index) const override
kvector_t getMeanKf() const

References getCoefficients(), and SimulationElement::getMeanKf().

Here is the call graph for this function:

◆ getCoefficients()

std::unique_ptr< const ILayerRTCoefficients > ScalarFresnelMap::getCoefficients ( const kvector_t kvec,
size_t  layer_index 
) const
overrideprivatevirtual

Implements IFresnelMap.

Definition at line 40 of file ScalarFresnelMap.cpp.

41 {
42  if (!m_use_cache) {
43  auto coeffs = m_Strategy->Execute(m_slices, kvec);
44  return std::unique_ptr<const ILayerRTCoefficients>(coeffs[layer_index]->clone());
45  }
46  const auto& coef_vector = getCoefficientsFromCache(kvec);
47  return std::unique_ptr<const ILayerRTCoefficients>(coef_vector[layer_index]->clone());
48 }
std::vector< Slice > m_slices
Definition: IFresnelMap.h:57
std::unique_ptr< ISpecularStrategy > m_Strategy
Definition: IFresnelMap.h:60
bool m_use_cache
Definition: IFresnelMap.h:58
const ISpecularStrategy::coeffs_t & getCoefficientsFromCache(kvector_t kvec) const

References getCoefficientsFromCache(), IFresnelMap::m_slices, IFresnelMap::m_Strategy, and IFresnelMap::m_use_cache.

Referenced by getOutCoefficients().

Here is the call graph for this function:

◆ getCoefficientsFromCache()

const ISpecularStrategy::coeffs_t & ScalarFresnelMap::getCoefficientsFromCache ( kvector_t  kvec) const
private

Definition at line 50 of file ScalarFresnelMap.cpp.

51 {
52  std::pair<double, double> k2_theta(kvec.mag2(), kvec.theta());
53  auto it = m_cache.find(k2_theta);
54  if (it == m_cache.end()) {
55  it = m_cache.emplace(k2_theta, m_Strategy->Execute(m_slices, kvec)).first;
56  }
57  return it->second;
58 }
double mag2() const
Returns magnitude squared of the vector.
double theta() const
Returns polar angle.
std::unordered_map< std::pair< double, double >, ISpecularStrategy::coeffs_t, Hash2Doubles > m_cache

References m_cache, IFresnelMap::m_slices, IFresnelMap::m_Strategy, BasicVector3D< T >::mag2(), and BasicVector3D< T >::theta().

Referenced by getCoefficients().

Here is the call graph for this function:

◆ getInCoefficients()

template<typename T >
std::unique_ptr<const ILayerRTCoefficients> IFresnelMap::getInCoefficients ( const T &  sim_element,
size_t  layer_index 
) const
inlineinherited

Retrieves the amplitude coefficients for an incoming wavevector.

Definition at line 41 of file IFresnelMap.h.

43  {
44  return getCoefficients(sim_element.getKi(), layer_index);
45  }
virtual std::unique_ptr< const ILayerRTCoefficients > getCoefficients(const kvector_t &kvec, size_t layer_index) const =0

References IFresnelMap::getCoefficients().

Referenced by DepthProbeComputationTerm::compute(), GISASSpecularComputation::compute(), FormFactorCoherentPart::evaluate(), FormFactorCoherentPart::evaluatePol(), and RoughMultiLayerComputation::get_sum8terms().

Here is the call graph for this function:

◆ setSlices()

void IFresnelMap::setSlices ( const std::vector< Slice > &  slices)
virtualinherited

Reimplemented in MatrixFresnelMap.

Definition at line 23 of file IFresnelMap.cpp.

24 {
25  m_slices = slices;
26 }
const std::vector< Slice > & slices() const
Definition: IFresnelMap.cpp:28

References IFresnelMap::m_slices, and IFresnelMap::slices().

Referenced by MatrixFresnelMap::setSlices().

Here is the call graph for this function:

◆ slices()

const std::vector< Slice > & IFresnelMap::slices ( ) const
inherited

◆ disableCaching()

void IFresnelMap::disableCaching ( )
inherited

Disables caching of previously computed Fresnel coefficients.

Definition at line 35 of file IFresnelMap.cpp.

36 {
37  m_use_cache = false;
38 }

References IFresnelMap::m_use_cache.

Member Data Documentation

◆ m_cache

std::unordered_map<std::pair<double, double>, ISpecularStrategy::coeffs_t, Hash2Doubles> ScalarFresnelMap::m_cache
mutableprivate

Definition at line 56 of file ScalarFresnelMap.h.

Referenced by getCoefficientsFromCache().

◆ m_slices

std::vector<Slice> IFresnelMap::m_slices
protectedinherited

◆ m_use_cache

bool IFresnelMap::m_use_cache
protectedinherited

◆ m_Strategy

std::unique_ptr<ISpecularStrategy> IFresnelMap::m_Strategy
protectedinherited

The documentation for this class was generated from the following files: