1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Device/Beam/Beam.cpp
//! @brief Implements class Beam.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "Device/Beam/Beam.h"
#include "Base/Spin/SpinMatrix.h"
#include "Base/Util/Assert.h"
#include "Base/Vector/GisasDirection.h"
#include "Device/Beam/IFootprint.h"
#include <numbers>
using std::numbers::pi;
//... Constructors, destructors:
Beam::Beam(double intensity, double wavelength, double alpha, double phi)
: m_intensity(intensity)
, m_wavelength(wavelength)
, m_alpha(alpha)
, m_phi(phi)
{
precompute();
}
Beam::~Beam() = default;
Beam* Beam::clone() const
{
auto* result = new Beam(m_intensity, m_wavelength, m_alpha, m_phi);
if (m_footprint)
result->m_footprint.reset(m_footprint->clone());
result->m_polarization = m_polarization;
return result;
}
//... Getters:
std::vector<const INode*> Beam::nodeChildren() const
{
if (m_footprint)
return {m_footprint.get()};
return {};
}
SpinMatrix Beam::polMatrix() const
{
return SpinMatrix::FromBlochVector(m_polarization);
}
//... Setters:
void Beam::setIntensity(double intensity)
{
m_intensity = intensity;
precompute();
}
void Beam::setWavelength(double wavelength)
{
if (wavelength <= 0)
throw std::runtime_error("Wavelength = " + std::to_string(wavelength)
+ " : wavelength must be set to positive value");
m_wavelength = wavelength;
precompute();
}
void Beam::setGrazingAngle(const double alpha)
{
m_alpha = alpha;
precompute();
}
void Beam::setAzimuthalAngle(double value)
{
m_phi = value;
precompute();
}
void Beam::setFootprint(const IFootprint* shape_factor)
{
m_footprint.reset(shape_factor ? shape_factor->clone() : nullptr);
}
//! Sets the polarization density matrix according to the given Bloch vector
void Beam::setPolarization(const R3& polarization)
{
if (polarization.mag() > 1.0)
throw std::runtime_error(
"Beam::setPolarization: "
"The given Bloch vector cannot represent a real physical ensemble");
m_polarization = polarization;
}
//... Private function:
//! To be called whenever wavelength or alpha or phi has changed.
void Beam::precompute()
{
ASSERT(m_intensity >= 0);
ASSERT(m_wavelength >= 0);
ASSERT(m_alpha >= 0);
m_wavenumber = (2 * pi) / m_wavelength;
m_k = vecOfKAlphaPhi(m_wavenumber, -m_alpha, -m_phi);
}
|