BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationOptions.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/RT/SimulationOptions.cpp
6 //! @brief Implements class SimulationOptions
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 
16 #include <stdexcept>
17 #include <thread>
18 
20  : m_mc_integration(false), m_include_specular(false), m_use_avg_materials(false), m_mc_points(1)
21 {
23 }
24 
26 {
27  return m_mc_integration && m_mc_points > 1;
28 }
29 
30 void SimulationOptions::setMonteCarloIntegration(bool flag, size_t mc_points)
31 {
32  m_mc_integration = flag;
33  m_mc_points = mc_points;
34 }
35 
37 {
38  if (nthreads == 0)
40  else if (nthreads > 0)
41  m_thread_info.n_threads = nthreads;
42  else
44 }
45 
47 {
48  if (m_thread_info.n_threads < 1)
49  throw std::runtime_error("Error in SimulationOptions::getNumberOfThreads: Number of "
50  "threads must be positive");
51  return m_thread_info.n_threads;
52 }
53 
55 {
56  if (nbatches < 1)
57  throw std::runtime_error("Error in SimulationOptions::setNumberOfBatches: Number of "
58  "batches must be positive");
59  m_thread_info.n_batches = nbatches;
60 }
61 
63 {
64  if (m_thread_info.n_batches < 1)
65  throw std::runtime_error("Error in SimulationOptions::getNumberOfBatches: Number of "
66  "batches must be positive");
67  return m_thread_info.n_batches;
68 }
69 
71 {
73  throw std::runtime_error(
74  "Error in SimulationOptions::getCurrentBatch: current batch is out of range");
76 }
77 
79 {
80  return std::thread::hardware_concurrency();
81 }
Defines class SimulationOptions.
ThreadInfo m_thread_info
void setNumberOfBatches(int nbatches)
Sets number of batches to split.
unsigned getNumberOfBatches() const
unsigned getCurrentBatch() const
unsigned getHardwareConcurrency() const
unsigned getNumberOfThreads() const
bool isIntegrate() const
void setNumberOfThreads(int nthreads)
Sets number of threads to use during the simulation (0 - take the default value from the hardware)
void setMonteCarloIntegration(bool flag=true, size_t mc_points=50)
Enables/disables MonetCarlo integration.
unsigned current_batch
Definition: ThreadInfo.h:25
unsigned n_batches
Definition: ThreadInfo.h:24
unsigned n_threads
Definition: ThreadInfo.h:23