forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdagmc.h
178 lines (133 loc) · 6.21 KB
/
dagmc.h
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
#ifndef OPENMC_DAGMC_H
#define OPENMC_DAGMC_H
namespace openmc {
extern "C" const bool DAGMC_ENABLED;
}
// 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 DAGMC
#include "DagMC.hpp"
#include "dagmcmetadata.hpp"
#include "openmc/cell.h"
#include "openmc/particle.h"
#include "openmc/position.h"
#include "openmc/surface.h"
class UWUW;
namespace openmc {
class DAGSurface : public Surface {
public:
DAGSurface(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx);
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, Particle* p) const override;
inline void to_hdf5_inner(hid_t group_id) const override {};
// Accessor methods
const std::shared_ptr<moab::DagMC>& dagmc_ptr() const { return dagmc_ptr_; }
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);
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, Particle* p) const override;
BoundingBox bounding_box() const override;
void to_hdf5_inner(hid_t group_id) const override;
// Accessor methods
const std::shared_ptr<moab::DagMC>& dagmc_ptr() const { return dagmc_ptr_; }
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:
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
explicit DAGUniverse(const std::string& filename, bool auto_geom_ids = false,
bool auto_mat_ids = false);
//! 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);
//! Initialize the DAGMC accel. data structures, indices, material
//! assignments, etc.
void initialize();
//! 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 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;
//! 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(Particle& p) const override;
void to_hdf5(hid_t universes_group) const override;
// 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
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(); //!< Create cells and surfaces from DAGMC entities
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
bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard"
//!< volume
};
//==============================================================================
// Non-member functions
//==============================================================================
int32_t next_cell(
DAGUniverse* dag_univ, DAGCell* cur_cell, DAGSurface* surf_xed);
} // namespace openmc
#endif // DAGMC
#endif // OPENMC_DAGMC_H