Repository navigation
Expand file tree
/
Copy pathdagmc.h
More file actions
224 lines (169 loc) · 8.38 KB
/
Copy pathdagmc.h
File metadata and controls
224 lines (169 loc) · 8.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifndef OPENMC_DAGMC_H
#define OPENMC_DAGMC_H
// always include the XML interface header
#include "openmc/xml_interface.h"
//==============================================================================
// Functions that are always defined
//==============================================================================
namespace openmc {
void read_dagmc_universes(pugi::xml_node node);
void check_dagmc_root_univ();
} // namespace openmc
#ifdef OPENMC_DAGMC_ENABLED
#include "DagMC.hpp"
#include "dagmcmetadata.hpp"
#include "openmc/cell.h"
#include "openmc/particle.h"
#include "openmc/position.h"
#include "openmc/surface.h"
#include "openmc/vector.h"
#include <memory> // for shared_ptr, unique_ptr
#include <string>
#include <unordered_map>
#include <utility> // for pair
class UWUW;
namespace openmc {
class DAGSurface : public Surface {
public:
DAGSurface(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx);
moab::EntityHandle mesh_handle() const;
double evaluate(Position r) const override;
double distance(Position r, Direction u, bool coincident) const override;
Direction normal(Position r) const override;
Direction reflect(
Position r, Direction u, GeometryState* p = nullptr) const override;
inline void to_hdf5_inner(hid_t group_id) const override {};
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
// Accessor methods
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
int32_t dag_index() const { return dag_index_; }
private:
std::shared_ptr<moab::DagMC> dagmc_ptr_; //!< Pointer to DagMC instance
int32_t dag_index_; //!< DagMC index of surface
};
class DAGCell : public Cell {
public:
DAGCell(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx);
moab::EntityHandle mesh_handle() const;
bool contains(Position r, Direction u, int32_t on_surface) const override;
std::pair<double, int32_t> distance(Position r, Direction u,
int32_t on_surface, GeometryState* p) const override;
BoundingBox bounding_box() const override;
void to_hdf5_inner(hid_t group_id) const override;
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
// Accessor methods
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
int32_t dag_index() const { return dag_index_; }
private:
std::shared_ptr<moab::DagMC> dagmc_ptr_; //!< Pointer to DagMC instance
int32_t dag_index_; //!< DagMC index of cell
};
class DAGUniverse : public Universe {
public:
using MaterialOverrides = std::unordered_map<int32_t, vector<int32_t>>;
using TemperatureOverrides = std::unordered_map<int32_t, vector<double>>;
using DensityOverrides = std::unordered_map<int32_t, vector<double>>;
explicit DAGUniverse(pugi::xml_node node);
//! Create a new DAGMC universe
//! \param[in] filename Name of the DAGMC file
//! \param[in] auto_geom_ids Whether or not to automatically assign cell and
//! surface IDs \param[in] auto_mat_ids Whether or not to automatically assign
//! material IDs \param[in] length_multiplier Multiplicative factor applied to
//! geometry coordinates
explicit DAGUniverse(const std::string& filename, bool auto_geom_ids = false,
bool auto_mat_ids = false, double length_multiplier = 1.0);
//! Alternative DAGMC universe constructor for external DAGMC instance
explicit DAGUniverse(std::shared_ptr<moab::DagMC> external_dagmc_ptr,
const std::string& filename = "", bool auto_geom_ids = false,
bool auto_mat_ids = false, double length_multiplier = 1.0);
//! Initialize the DAGMC accel. data structures, indices, material
//! assignments, etc.
void initialize();
void initialize(const MaterialOverrides& material_overrides,
const TemperatureOverrides& temperature_overrides,
const DensityOverrides& density_overrides = {});
//! Reads UWUW materials and returns an ID map
void read_uwuw_materials();
//! Indicates whether or not UWUW materials are present
//! \return True if UWUW materials are present, False if not
bool uses_uwuw() const;
//! Returns the index to the implicit complement's index in OpenMC for this
//! DAGMC universe
int32_t implicit_complement_idx() const;
//! Transform UWUW materials into an OpenMC-readable XML format
//! \return A string representing a materials.xml file of the UWUW materials
//! in this universe
std::string get_uwuw_materials_xml() const;
//! Writes the UWUW material file to XML (for debugging purposes)
void write_uwuw_materials_xml(
const std::string& outfile = "uwuw_materials.xml") const;
//! Assign a material to a cell from uwuw material library
//! \param[in] vol_handle The DAGMC material assignment string
//! \param[in] c The OpenMC cell to which the material is assigned
void uwuw_assign_material(
moab::EntityHandle vol_handle, std::unique_ptr<DAGCell>& c) const;
//! Assign a material to a cell based
//! \param[in] mat_string The DAGMC material assignment string
//! \param[in] c The OpenMC cell to which the material is assigned
void legacy_assign_material(
std::string mat_string, std::unique_ptr<DAGCell>& c) const;
//! Assign a material overriding normal assignement to a cell
//! \param[in] c The OpenMC cell to which the material is assigned
void override_assign_material(std::unique_ptr<DAGCell>& c,
const MaterialOverrides& material_overrides) const;
//! Return the index into the model cells vector for a given DAGMC volume
//! handle in the universe
//! \param[in] vol MOAB handle to the DAGMC volume set
int32_t cell_index(moab::EntityHandle vol) const;
//! Return the index into the model surfaces vector for a given DAGMC surface
//! handle in the universe
//! \param[in] surf MOAB handle to the DAGMC surface set
int32_t surface_index(moab::EntityHandle surf) const;
//! Generate a string representing the ranges of IDs present in the DAGMC
//! model. Contiguous chunks of IDs are represented as a range (i.e. 1-10). If
//! there is a single ID a chunk, it will be represented as a single number
//! (i.e. 2, 4, 6, 8). \param[in] dim Dimension of the entities \return A
//! string of the ID ranges for entities of dimension \p dim
std::string dagmc_ids_for_dim(int dim) const;
bool find_cell(GeometryState& p) const override;
void to_hdf5(hid_t universes_group) const override;
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
// Data Members
std::shared_ptr<moab::DagMC>
dagmc_instance_; //!< DAGMC Instance for this universe
int32_t cell_idx_offset_; //!< An offset to the start of the cells in this
//!< universe in OpenMC's cell vector
int32_t surf_idx_offset_; //!< An offset to the start of the surfaces in this
//!< universe in OpenMC's surface vector
// Accessors
moab::DagMC* dagmc_ptr() const { return dagmc_instance_.get(); }
bool has_graveyard() const { return has_graveyard_; }
private:
void set_id(); //!< Deduce the universe id from model::universes
void init_dagmc(); //!< Create and initialise DAGMC pointer
void init_metadata(); //!< Create and initialise dagmcMetaData pointer
void init_geometry(const MaterialOverrides& material_overrides,
const TemperatureOverrides& temperature_overrides,
const DensityOverrides& density_overrides);
std::string
filename_; //!< Name of the DAGMC file used to create this universe
std::shared_ptr<UWUW>
uwuw_; //!< Pointer to the UWUW instance for this universe
std::unique_ptr<dagmcMetaData> dmd_ptr; //! Pointer to DAGMC metadata object
bool adjust_geometry_ids_; //!< Indicates whether or not to automatically
//!< generate new cell and surface IDs for the
//!< universe
bool adjust_material_ids_; //!< Indicates whether or not to automatically
//!< generate new material IDs for the universe
double length_multiplier_ {
1.0}; //!< Multiplicative factor applied to geometry coordinates
bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard"
//!< volume
};
//==============================================================================
// Non-member functions
//==============================================================================
int32_t next_cell(int32_t surf, int32_t curr_cell, int32_t univ);
} // namespace openmc
#endif // OPENMC_DAGMC_ENABLED
#endif // OPENMC_DAGMC_H