Mantid
Loading...
Searching...
No Matches
Material.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidKernel/Atom.h"
11#include <boost/python/class.hpp>
12#include <boost/python/copy_const_reference.hpp>
13#include <boost/python/list.hpp>
14#include <boost/python/make_function.hpp>
15#include <boost/python/register_ptr_to_python.hpp>
16#include <boost/python/tuple.hpp>
17#include <numeric>
18
21using namespace boost::python;
22
24
25namespace {
31tuple chemicalFormula(const Material &self) {
32 list atoms, numberAtoms;
33 for (const auto &formulaUnit : self.chemicalFormula()) {
34 atoms.append(formulaUnit.atom);
35 numberAtoms.append(formulaUnit.multiplicity);
36 }
37 return make_tuple(atoms, numberAtoms);
38}
39
40bool toBool(const Material &self) {
41 return (self.cohScatterXSection() != 0.) || (self.incohScatterXSection() != 0.) ||
42 (self.totalScatterXSection() != 0.) || (self.absorbXSection() != 0.) || (self.cohScatterLength() != 0.) ||
43 (self.incohScatterLength() != 0.) || (self.totalScatterLength() != 0.) ||
44 (self.cohScatterLengthReal() != 0.) || (self.cohScatterLengthImg() != 0.) ||
45 (self.incohScatterLengthReal() != 0.) || (self.incohScatterLengthImg() != 0.) ||
46 (self.cohScatterLengthSqrd() != 0.) || (self.incohScatterLengthSqrd() != 0.) ||
47 (self.totalScatterLengthSqrd() != 0.);
48}
49
55double relativeMolecularMass(const Material &self) {
56 const auto &formula = self.chemicalFormula();
57 return std::accumulate(formula.cbegin(), formula.cend(), 0., [](double sum, const auto &formulaUnit) {
58 return sum + formulaUnit.atom->mass * formulaUnit.multiplicity;
59 });
60}
61} // namespace
62
64 register_ptr_to_python<Material *>();
65 register_ptr_to_python<std::shared_ptr<Material>>();
66
67 class_<Material>("Material", no_init)
68 .def("name", &Material::name, arg("self"), return_value_policy<copy_const_reference>(), "Name of the material")
69 .add_property("numberDensity", make_function(&Material::numberDensity), "Number density in atoms per A^-3")
70 .add_property("numberDensityEffective", make_function(&Material::numberDensityEffective),
71 "Effective number density in atoms per A^-3")
72 .add_property("packingFraction", make_function(&Material::packingFraction),
73 "Packing fraction as a number, ideally, 0 to 1")
74 .add_property("temperature", make_function(&Material::temperature), "Temperature")
75 .add_property("pressure", make_function(&Material::pressure), "Pressure")
76 .add_property("totalAtoms", make_function(&Material::totalAtoms), "Total number of atoms")
77 .def("__bool__", &toBool, "Returns True if any of the scattering values are non-zero")
78 .def("cohScatterXSection", (double (Material::*)() const)(&Material::cohScatterXSection), (arg("self")),
79 "Coherent Scattering Cross-Section for the given wavelength in "
80 "barns")
81 .def("incohScatterXSection", (double (Material::*)() const)(&Material::incohScatterXSection), (arg("self")),
82 "Incoherent Scattering Cross-Section for the given wavelength in "
83 "barns")
84 .def("totalScatterXSection", (double (Material::*)() const)(&Material::totalScatterXSection), (arg("self")),
85 "Total Scattering Cross-Section for the given wavelength in barns")
86 .def("absorbXSection", (double (Material::*)(double) const)(&Material::absorbXSection),
87 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
88 "Absorption Cross-Section for the given wavelength in barns")
89 .def("cohScatterLength", (double (Material::*)(double) const)(&Material::cohScatterLength),
90 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
91 "Coherent Scattering Length for the given wavelength in fm")
92 .def("incohScatterLength", (double (Material::*)(double) const)(&Material::incohScatterLength),
93 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
94 "Incoherent Scattering Length for the given wavelength in fm")
95 .def("totalScatterLength", (double (Material::*)(double) const)(&Material::totalScatterLength),
96 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
97 "Total Scattering Length for the given wavelength in fm")
98 .def("cohScatterLengthReal", (double (Material::*)(double) const)(&Material::cohScatterLengthReal),
99 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
100 "Real part of Coherent Scattering Length for the given wavelength "
101 "in fm")
102 .def("cohScatterLengthImg", (double (Material::*)(double) const)(&Material::cohScatterLengthImg),
103 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
104 "Imaginary part of Coherent Scattering Length for the given "
105 "wavelength "
106 "in fm")
107 .def("incohScatterLengthReal", (double (Material::*)(double) const)(&Material::incohScatterLengthReal),
108 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
109 "Real part of Incoherent Scattering Length for the given wavelength "
110 "in fm")
111 .def("incohScatterLengthImg", (double (Material::*)(double) const)(&Material::incohScatterLengthImg),
112 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
113 "Imaginary part of Incoherent Scattering Length for the given "
114 "wavelength "
115 "in fm")
116
117 .def("cohScatterLengthSqrd", (double (Material::*)(double) const)(&Material::cohScatterLengthSqrd),
118 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
119 "Coherent Scattering Length Squared <b>^2 for the given wavelength "
120 "in fm^2")
121 .def("incohScatterLengthSqrd", (double (Material::*)(double) const)(&Material::incohScatterLengthSqrd),
122 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
123 "Incoherent Scattering Length Squared <b>^2 for the given "
124 "wavelength in fm^2")
125 .def("totalScatterLengthSqrd", (double (Material::*)(double) const)(&Material::totalScatterLengthSqrd),
126 (arg("self"), arg("lambda") = static_cast<double>(NeutronAtom::ReferenceLambda)),
127 "Total Scattering Length Squared <b^2> for the given wavelength in "
128 "fm^2")
129 .def("chemicalFormula", &chemicalFormula, arg("self"),
130 "Chemical formula as a tuple of two lists: the first one contains "
131 "the Atom object the second their multiplicities within the "
132 "formula.")
133 .def("relativeMolecularMass", &relativeMolecularMass, arg("self"), "Relative Molecular Mass");
134}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
void export_Material()
Definition: Material.cpp:63
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
Definition: Material.h:50
const Material::ChemicalFormula & chemicalFormula() const
Definition: Material.cpp:183
double packingFraction() const
Get the packing fraction.
Definition: Material.cpp:202
double cohScatterLengthReal(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the coherent scattering length for a given wavelength in fm.
Definition: Material.cpp:349
double incohScatterLengthSqrd(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the incoherent length squared, , for a given wavelength in .
Definition: Material.cpp:465
double incohScatterLength(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the incoherent length for a given wavelength in fm.
Definition: Material.cpp:339
double temperature() const
Get the temperature.
Definition: Material.cpp:215
double cohScatterLength(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the coherent scattering length for a given wavelength in fm.
Definition: Material.cpp:328
double cohScatterLengthSqrd(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the coherent scattering length squared, , for a given wavelength in .
Definition: Material.cpp:442
double cohScatterLengthImg(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the coherent scattering length for a given wavelength in fm.
Definition: Material.cpp:369
double numberDensity() const
Get the number density.
Definition: Material.cpp:189
double incohScatterLengthReal(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the incoherent length for a given wavelength in fm.
Definition: Material.cpp:390
double totalAtoms() const
The total number of atoms in the formula.
Definition: Material.cpp:209
double cohScatterXSection() const
Get the coherent scattering cross section for a given wavelength in barns.
Definition: Material.cpp:228
double totalScatterLength(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Return the total scattering length for a given wavelength in fm.
Definition: Material.cpp:432
double absorbXSection(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the absorption cross section at a given wavelength in barns.
Definition: Material.cpp:260
const std::string & name() const
Returns the name of the material.
Definition: Material.cpp:181
double numberDensityEffective() const
Get the effective number density.
Definition: Material.cpp:195
double incohScatterXSection() const
Get the incoherent cross section for a given wavelength in barns.
Definition: Material.cpp:240
double pressure() const
Get the pressure.
Definition: Material.cpp:221
double incohScatterLengthImg(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Get the incoherent length for a given wavelength in fm.
Definition: Material.cpp:411
double totalScatterXSection() const
Return the total scattering cross section for a given wavelength in barns.
Definition: Material.cpp:252
double totalScatterLengthSqrd(const double lambda=PhysicalConstants::NeutronAtom::ReferenceLambda) const
Return the total scattering length squared, , for a given wavelength in .
Definition: Material.cpp:475
Structure to store neutronic scattering information for the various elements.
Definition: NeutronAtom.h:22
static const double ReferenceLambda
The reference wavelength value for absorption cross sections.
Definition: NeutronAtom.h:25