• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 6950233652

21 Nov 2023 10:22PM UTC coverage: 84.533% (-0.02%) from 84.555%
6950233652

push

github

web-flow
change identity matrix format to csr in cram (#2771)

1 of 1 new or added line in 1 file covered. (100.0%)

63 existing lines in 15 files now uncovered.

47053 of 55662 relevant lines covered (84.53%)

33574935.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/include/openmc/source.h
1
//! \file source.h
2
//! \brief External source distributions
3

4
#ifndef OPENMC_SOURCE_H
5
#define OPENMC_SOURCE_H
6

7
#include <unordered_set>
8

9
#include "pugixml.hpp"
10

11
#include "openmc/distribution_multi.h"
12
#include "openmc/distribution_spatial.h"
13
#include "openmc/memory.h"
14
#include "openmc/particle.h"
15
#include "openmc/vector.h"
16

17
namespace openmc {
18

19
//==============================================================================
20
// Constants
21
//==============================================================================
22

23
// Maximum number of external source spatial resamples to encounter before an
24
// error is thrown.
25
constexpr int EXTSRC_REJECT_THRESHOLD {10000};
26
constexpr double EXTSRC_REJECT_FRACTION {0.05};
27

28
//==============================================================================
29
// Global variables
30
//==============================================================================
31

32
class Source;
33

34
namespace model {
35

36
extern vector<unique_ptr<Source>> external_sources;
37

38
} // namespace model
39

40
//==============================================================================
41
//! Abstract source interface
42
//==============================================================================
43

44
class Source {
45
public:
UNCOV
46
  virtual ~Source() = default;
×
47

×
UNCOV
48
  // Methods that must be implemented
×
49
  virtual SourceSite sample(uint64_t* seed) const = 0;
50

51
  // Methods that can be overridden
52
  virtual double strength() const { return 1.0; }
53
};
UNCOV
54

×
55
//==============================================================================
56
//! Source composed of independent spatial, angle, energy, and time
57
//! distributions
58
//==============================================================================
59

60
class IndependentSource : public Source {
61
public:
62
  // Constructors
63
  IndependentSource(
64
    UPtrSpace space, UPtrAngle angle, UPtrDist energy, UPtrDist time);
65
  explicit IndependentSource(pugi::xml_node node);
66

67
  //! Sample from the external source distribution
68
  //! \param[inout] seed Pseudorandom seed pointer
69
  //! \return Sampled site
70
  SourceSite sample(uint64_t* seed) const override;
71

72
  // Properties
73
  ParticleType particle_type() const { return particle_; }
74
  double strength() const override { return strength_; }
75

76
  // Make observing pointers available
25,133,077✔
77
  SpatialDistribution* space() const { return space_.get(); }
78
  UnitSphereDistribution* angle() const { return angle_.get(); }
79
  Distribution* energy() const { return energy_.get(); }
80
  Distribution* time() const { return time_.get(); }
81

82
private:
83
  // Domain types
84
  enum class DomainType { UNIVERSE, MATERIAL, CELL };
85

86
  // Data members
87
  ParticleType particle_ {ParticleType::neutron}; //!< Type of particle emitted
88
  double strength_ {1.0};                         //!< Source strength
89
  UPtrSpace space_;                               //!< Spatial distribution
90
  UPtrAngle angle_;                               //!< Angular distribution
91
  UPtrDist energy_;                               //!< Energy distribution
92
  UPtrDist time_;                                 //!< Time distribution
93
  DomainType domain_type_;                        //!< Domain type for rejection
94
  std::unordered_set<int32_t> domain_ids_;        //!< Domains to reject from
95
};
96

97
//==============================================================================
98
//! Source composed of particles read from a file
99
//==============================================================================
100

101
class FileSource : public Source {
102
public:
103
  // Constructors
104
  explicit FileSource(std::string path);
105
  explicit FileSource(const vector<SourceSite>& sites) : sites_ {sites} {}
106

107
  // Methods
108
  SourceSite sample(uint64_t* seed) const override;
109

110
private:
111
  vector<SourceSite> sites_; //!< Source sites from a file
112
};
113

114
//==============================================================================
115
//! Wrapper for custom sources that manages opening/closing shared library
116
//==============================================================================
117

118
class CompiledSourceWrapper : public Source {
119
public:
120
  // Constructors, destructors
121
  CompiledSourceWrapper(std::string path, std::string parameters);
122
  ~CompiledSourceWrapper();
123

124
  // Defer implementation to custom source library
125
  SourceSite sample(uint64_t* seed) const override
126
  {
127
    return compiled_source_->sample(seed);
280,000✔
128
  }
129

280,000✔
130
  double strength() const override { return compiled_source_->strength(); }
131

132
private:
280,280✔
133
  void* shared_library_; //!< library from dlopen
134
  unique_ptr<Source> compiled_source_;
135
};
136

137
typedef unique_ptr<Source> create_compiled_source_t(std::string parameters);
138

139
//==============================================================================
140
// Functions
141
//==============================================================================
142

143
//! Initialize source bank from file/distribution
144
extern "C" void initialize_source();
145

146
//! Sample a site from all external source distributions in proportion to their
147
//! source strength
148
//! \param[inout] seed Pseudorandom seed pointer
149
//! \return Sampled source site
150
SourceSite sample_external_source(uint64_t* seed);
151

152
void free_memory_source();
153

154
} // namespace openmc
155

156
#endif // OPENMC_SOURCE_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc