BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationOptionsItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Support/Data/SimulationOptionsItem.cpp
6 //! @brief Defines class SimulationOptionsItem
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 <QXmlStreamWriter>
19 #include <thread>
20 
21 namespace {
22 
23 namespace Tags {
24 
25 const QString RunImmediately("RunImmediately");
26 const QString NumberOfThreads("NumberOfThreads");
27 const QString Analytical("Analytical");
28 const QString NumberOfMonteCarloPoints("NumberOfMonteCarloPoints");
29 const QString UseAverageMaterials("UseAverageMaterials");
30 const QString IncludeSpecularPeak("IncludeSpecularPeak");
31 
32 } // namespace Tags
33 
34 } // namespace
35 
36 
38 {
39  m_runImmediately = true;
40  m_numberOfThreads = std::thread::hardware_concurrency();
43  m_useAverageMaterials = false;
44  m_includeSpecularPeak = false;
45 }
46 
48 {
49  return m_numberOfThreads;
50 }
51 
53 {
54  m_numberOfThreads = number;
55 }
56 
58 {
59  return m_runImmediately;
60 }
61 
63 {
64  return !runImmediately();
65 }
66 
68 {
70 }
71 
73 {
75  m_numberOfMonteCarloPoints = numberOfPoints;
76 }
77 
79 {
81 }
82 
84 {
85  return !useAnalytical();
86 }
87 
89 {
91 }
92 
94 {
96 }
97 
98 void SimulationOptionsItem::setUseAverageMaterials(bool useAverageMaterials)
99 {
101 }
102 
104 {
105  return m_useAverageMaterials;
106 }
107 
108 void SimulationOptionsItem::setIncludeSpecularPeak(bool includeSpecularPeak)
109 {
111 }
112 
114 {
115  return m_includeSpecularPeak;
116 }
117 
118 void SimulationOptionsItem::writeContentTo(QXmlStreamWriter* writer) const
119 {
121  GUI::Session::XML::writeAttribute(writer, Tags::RunImmediately, m_runImmediately);
122  GUI::Session::XML::writeAttribute(writer, Tags::NumberOfThreads, m_numberOfThreads);
124  GUI::Session::XML::writeAttribute(writer, Tags::NumberOfMonteCarloPoints,
126  GUI::Session::XML::writeAttribute(writer, Tags::UseAverageMaterials, m_useAverageMaterials);
127  GUI::Session::XML::writeAttribute(writer, Tags::IncludeSpecularPeak, m_includeSpecularPeak);
128 }
129 
130 void SimulationOptionsItem::readContentFrom(QXmlStreamReader* reader)
131 {
132  const int version = reader->attributes().value(GUI::Session::XML::Version).toInt();
133 
134  if (version < 1)
136 
137  if (version > 1)
139 
140  m_runImmediately = GUI::Session::XML::readBoolAttribute(reader, Tags::RunImmediately);
141  m_numberOfThreads = GUI::Session::XML::readUIntAttribute(reader, Tags::NumberOfThreads);
144  GUI::Session::XML::readUIntAttribute(reader, Tags::NumberOfMonteCarloPoints);
145  m_useAverageMaterials = GUI::Session::XML::readBoolAttribute(reader, Tags::UseAverageMaterials);
146  m_includeSpecularPeak = GUI::Session::XML::readBoolAttribute(reader, Tags::IncludeSpecularPeak);
147 }
Defines class DeserializationException.
Defines class SimulationOptionsItem.
Defines.
static DeserializationException tooOld()
static DeserializationException tooNew()
void setRunImmediately(bool runImmediately)
void setUseAverageMaterials(bool useAverageMaterials)
unsigned numberOfThreads() const
void writeContentTo(QXmlStreamWriter *writer) const
void setNumberOfThreads(unsigned n)
void setIncludeSpecularPeak(bool includeSpecularPeak)
void readContentFrom(QXmlStreamReader *reader)
void setUseMonteCarloIntegration(unsigned numberOfPoints)
unsigned numberOfMonteCarloPoints() const
bool readBoolAttribute(QXmlStreamReader *reader, const QString &attributeName)
Definition: UtilXML.cpp:149
constexpr auto Version("Version")
void writeAttribute(QXmlStreamWriter *writer, const QString &attributeName, const QVariant &variant)
Write the variant's value as an attribute.
Definition: UtilXML.cpp:65
unsigned readUIntAttribute(QXmlStreamReader *reader, const QString &attributeName)
Definition: UtilXML.cpp:154
Definition: JobItem.cpp:33