BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ISampleNode.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Scattering/ISampleNode.cpp
6 //! @brief Implements interface ISampleNode.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
18 #include <algorithm>
19 #include <sstream>
20 
21 ISampleNode::ISampleNode(const NodeMeta& meta, const std::vector<double>& PValues)
22  : INode(meta, PValues)
23 {
24 }
25 
26 std::vector<const Material*> ISampleNode::containedMaterials() const
27 {
28  std::vector<const Material*> result;
29  if (const Material* p_material = material())
30  result.push_back(p_material);
31  for (const auto* child : getChildren()) {
32  if (const ISampleNode* sample = dynamic_cast<const ISampleNode*>(child)) {
33  for (const Material* p_material : sample->containedMaterials())
34  result.push_back(p_material);
35  }
36  }
37  return result;
38 }
39 
41 {
42  const auto materials = containedMaterials();
43  return std::any_of(materials.cbegin(), materials.cend(),
44  [](const Material* mat) { return mat->isMagneticMaterial(); });
45 }
Defines interface class ISampleNode.
Defines and implements class Material.
Defines class ParameterPool.
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
virtual std::vector< const INode * > getChildren() const
Returns a vector of children.
Definition: INode.cpp:63
Abstract base class for sample components and properties related to scattering.
Definition: ISampleNode.h:28
std::vector< const Material * > containedMaterials() const
Returns set of unique materials contained in this ISampleNode.
Definition: ISampleNode.cpp:26
bool isMagnetic() const
Returns true if there is any magnetic material in this ISampleNode.
Definition: ISampleNode.cpp:40
virtual const Material * material() const
Returns nullptr, unless overwritten to return a specific material.
Definition: ISampleNode.h:37
ISampleNode()=default
A wrapper for underlying material implementation.
Definition: Material.h:29
Metadata of one model node.
Definition: INode.h:38