BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimulationOptions Class Reference

Description

Collect the different options for simulation.

SimulationOptions.

Definition at line 27 of file SimulationOptions.h.

Collaboration diagram for SimulationOptions:
[legend]

Public Member Functions

 SimulationOptions ()
 
unsigned getCurrentBatch () const
 
unsigned getHardwareConcurrency () const
 
size_t getMcPoints () const
 
unsigned getNumberOfBatches () const
 
unsigned getNumberOfThreads () const
 
bool includeSpecular () const
 
bool isIntegrate () const
 
void setIncludeSpecular (bool include_specular)
 
void setMonteCarloIntegration (bool flag=true, size_t mc_points=50)
 Enables/disables MonetCarlo integration. More...
 
void setNumberOfBatches (int nbatches)
 Sets number of batches to split. More...
 
void setNumberOfThreads (int nthreads)
 Sets number of threads to use during the simulation (0 - take the default value from the hardware) More...
 
void setThreadInfo (const ThreadInfo &thread_info)
 Sets the batch and thread information to be used. More...
 
void setUseAvgMaterials (bool use_avg_materials)
 
bool useAvgMaterials () const
 

Private Attributes

bool m_include_specular
 
bool m_mc_integration
 
size_t m_mc_points
 
ThreadInfo m_thread_info
 
bool m_use_avg_materials
 

Constructor & Destructor Documentation

◆ SimulationOptions()

SimulationOptions::SimulationOptions ( )

Definition at line 22 of file SimulationOptions.cpp.

23  : m_mc_integration(false)
24  , m_include_specular(false)
25  , m_use_avg_materials(false)
26  , m_mc_points(1)
27 {
28  if (const char* env_p = std::getenv("BA_NTHREADS")) {
29  m_thread_info.n_threads = std::stoi(env_p);
30  if (m_thread_info.n_threads > 0)
31  return;
32  }
34 }
ThreadInfo m_thread_info
unsigned getHardwareConcurrency() const
std::string getenv(const std::string &name)
Returns environment variable.
Definition: SysUtils.cpp:32
unsigned n_threads
Definition: ThreadInfo.h:23

References BaseUtils::System::getenv(), getHardwareConcurrency(), m_thread_info, and ThreadInfo::n_threads.

Here is the call graph for this function:

Member Function Documentation

◆ getCurrentBatch()

unsigned SimulationOptions::getCurrentBatch ( ) const

Definition at line 75 of file SimulationOptions.cpp.

76 {
77  unsigned result = m_thread_info.current_batch;
78  ASSERT(result < m_thread_info.n_batches);
79  return result;
80 }
#define ASSERT(condition)
Definition: Assert.h:45
unsigned current_batch
Definition: ThreadInfo.h:25
unsigned n_batches
Definition: ThreadInfo.h:24

References ASSERT, ThreadInfo::current_batch, m_thread_info, and ThreadInfo::n_batches.

◆ getHardwareConcurrency()

unsigned SimulationOptions::getHardwareConcurrency ( ) const

Definition at line 82 of file SimulationOptions.cpp.

83 {
84  return std::thread::hardware_concurrency();
85 }

Referenced by SimulationOptions(), and setNumberOfThreads().

◆ getMcPoints()

size_t SimulationOptions::getMcPoints ( ) const
inline

Definition at line 32 of file SimulationOptions.h.

32 { return m_mc_points; }

References m_mc_points.

Referenced by IInterparticleStrategy::MCIntegratedEvaluate().

◆ getNumberOfBatches()

unsigned SimulationOptions::getNumberOfBatches ( ) const

Definition at line 69 of file SimulationOptions.cpp.

70 {
72  return m_thread_info.n_batches;
73 }

References ASSERT, m_thread_info, and ThreadInfo::n_batches.

◆ getNumberOfThreads()

unsigned SimulationOptions::getNumberOfThreads ( ) const

Definition at line 57 of file SimulationOptions.cpp.

58 {
60  return m_thread_info.n_threads;
61 }

References ASSERT, m_thread_info, and ThreadInfo::n_threads.

◆ includeSpecular()

bool SimulationOptions::includeSpecular ( ) const
inline

Definition at line 59 of file SimulationOptions.h.

59 { return m_include_specular; }

References m_include_specular.

◆ isIntegrate()

bool SimulationOptions::isIntegrate ( ) const

Definition at line 36 of file SimulationOptions.cpp.

37 {
38  return m_mc_integration && m_mc_points > 1;
39 }

References m_mc_integration, and m_mc_points.

Referenced by IInterparticleStrategy::evaluate().

◆ setIncludeSpecular()

void SimulationOptions::setIncludeSpecular ( bool  include_specular)
inline

Definition at line 57 of file SimulationOptions.h.

57 { m_include_specular = include_specular; }

References m_include_specular.

◆ setMonteCarloIntegration()

void SimulationOptions::setMonteCarloIntegration ( bool  flag = true,
size_t  mc_points = 50 
)

Enables/disables MonetCarlo integration.

Parameters
flagIf true, MonteCarlo integration will be used, otherwise analytical calculations
mc_pointsNumber of points for MonteCarlo integrator

Definition at line 41 of file SimulationOptions.cpp.

42 {
43  m_mc_integration = flag;
44  m_mc_points = mc_points;
45 }

References m_mc_integration, and m_mc_points.

◆ setNumberOfBatches()

void SimulationOptions::setNumberOfBatches ( int  nbatches)

Sets number of batches to split.

Definition at line 63 of file SimulationOptions.cpp.

64 {
65  ASSERT(nbatches > 0);
66  m_thread_info.n_batches = nbatches;
67 }

References ASSERT, m_thread_info, and ThreadInfo::n_batches.

◆ setNumberOfThreads()

void SimulationOptions::setNumberOfThreads ( int  nthreads)

Sets number of threads to use during the simulation (0 - take the default value from the hardware)

Definition at line 47 of file SimulationOptions.cpp.

48 {
49  ASSERT(nthreads >= 0);
50  if (nthreads == 0)
52  else
53  m_thread_info.n_threads = nthreads;
55 }

References ASSERT, getHardwareConcurrency(), m_thread_info, and ThreadInfo::n_threads.

Here is the call graph for this function:

◆ setThreadInfo()

void SimulationOptions::setThreadInfo ( const ThreadInfo thread_info)
inline

Sets the batch and thread information to be used.

Definition at line 53 of file SimulationOptions.h.

53 { m_thread_info = thread_info; }

References m_thread_info.

◆ setUseAvgMaterials()

void SimulationOptions::setUseAvgMaterials ( bool  use_avg_materials)
inline

Definition at line 61 of file SimulationOptions.h.

61 { m_use_avg_materials = use_avg_materials; }

References m_use_avg_materials.

Referenced by swigAPI::defaultMaterialProfileLimits(), and swigAPI::materialProfileSLD().

◆ useAvgMaterials()

bool SimulationOptions::useAvgMaterials ( ) const
inline

Definition at line 63 of file SimulationOptions.h.

63 { return m_use_avg_materials; }

References m_use_avg_materials.

Referenced by reSample::make().

Member Data Documentation

◆ m_include_specular

bool SimulationOptions::m_include_specular
private

Definition at line 67 of file SimulationOptions.h.

Referenced by includeSpecular(), and setIncludeSpecular().

◆ m_mc_integration

bool SimulationOptions::m_mc_integration
private

Definition at line 66 of file SimulationOptions.h.

Referenced by isIntegrate(), and setMonteCarloIntegration().

◆ m_mc_points

size_t SimulationOptions::m_mc_points
private

Definition at line 69 of file SimulationOptions.h.

Referenced by getMcPoints(), isIntegrate(), and setMonteCarloIntegration().

◆ m_thread_info

◆ m_use_avg_materials

bool SimulationOptions::m_use_avg_materials
private

Definition at line 68 of file SimulationOptions.h.

Referenced by setUseAvgMaterials(), and useAvgMaterials().


The documentation for this class was generated from the following files: