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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Sample/Material/Material.cpp
//! @brief Implements and implements class Material.
//!
//! @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 "Sample/Material/Material.h"
#include "Base/Spin/SpinMatrix.h"
#include "Base/Util/Assert.h"
#include "Base/Vector/WavevectorInfo.h"
#include <cmath>
#include <sstream>
#include <stdexcept>
#include <typeinfo>
Material::Material(std::unique_ptr<IMaterialImpl>&& material_impl)
: m_material_impl(std::move(material_impl))
{
}
Material::Material(const Material& material)
{
ASSERT(!material.isEmpty());
m_material_impl.reset(material.m_material_impl->clone());
}
Material& Material::operator=(const Material& other)
{
if (this == &other)
return *this;
ASSERT(!other.isEmpty());
m_material_impl.reset(other.m_material_impl->clone());
return *this;
}
Material Material::inverted() const
{
std::unique_ptr<IMaterialImpl> material_impl(m_material_impl->inverted());
return {std::move(material_impl)};
}
complex_t Material::refractiveIndex(double wavelength) const
{
return m_material_impl->refractiveIndex(wavelength);
}
complex_t Material::refractiveIndex2(double wavelength) const
{
return m_material_impl->refractiveIndex2(wavelength);
}
bool Material::isScalarMaterial() const
{
return m_material_impl->isScalarMaterial();
}
bool Material::isMagneticMaterial() const
{
return m_material_impl->isMagneticMaterial();
}
std::string Material::materialName() const
{
return m_material_impl->matName();
}
MATERIAL_TYPES Material::typeID() const
{
return m_material_impl->typeID();
}
void Material::checkRefractiveIndex(double wavelength) const
{
const complex_t n = refractiveIndex(wavelength);
if (n.real() < 0.9 || n.real() > 1.1) {
std::stringstream msg;
msg << "Refractive index " << n << " at wavelength " << wavelength
<< " is too far from 1. Invalid material data?";
throw std::runtime_error(msg.str());
}
}
R3 Material::magnetization() const
{
return m_material_impl->magnetization();
}
complex_t Material::refractiveIndex_or_SLD() const
{
return m_material_impl->refractiveIndex_or_SLD();
}
bool Material::isDefaultMaterial() const
{
return refractiveIndex_or_SLD() == complex_t() && isScalarMaterial();
}
bool Material::isEmpty() const
{
return !m_material_impl;
}
complex_t Material::scalarSubtrSLD(const WavevectorInfo& wavevectors) const
{
return m_material_impl->scalarSubtrSLD(wavevectors.vacuumLambda());
}
SpinMatrix Material::polarizedSubtrSLD(const WavevectorInfo& wavevectors) const
{
return m_material_impl->polarizedSubtrSLD(wavevectors);
}
Material Material::rotatedMaterial(const RotMatrix& transform) const // TODO param:=rotation
{
std::unique_ptr<IMaterialImpl> material_impl(m_material_impl->rotatedMaterial(transform));
return {std::move(material_impl)};
}
std::ostream& operator<<(std::ostream& ostr, const Material& m)
{
ostr << m.m_material_impl->print();
return ostr;
}
bool operator==(const Material& left, const Material& right)
{
if (left.materialName() != right.materialName())
return false;
if (left.magnetization() != right.magnetization())
return false;
if (left.refractiveIndex_or_SLD() != right.refractiveIndex_or_SLD())
return false;
if (left.typeID() != right.typeID())
return false;
return true;
}
bool operator!=(const Material& left, const Material& right)
{
return !(left == right);
}
|