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

openmc-dev / openmc / 16366577751

18 Jul 2025 08:59AM UTC coverage: 85.115% (-0.1%) from 85.251%
16366577751

Pull #3420

github

web-flow
Merge 486047f9a into 659e43af7
Pull Request #3420: Adding material depletion function

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

437 existing lines in 24 files now uncovered.

52652 of 61860 relevant lines covered (85.11%)

36277994.88 hits per line

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

75.59
/openmc/lib/plot.py
1
from ctypes import (c_bool, c_int, c_size_t, c_int32,
11✔
2
                    c_double, Structure, POINTER)
3

4
from . import _dll
11✔
5
from .error import _error_handler
11✔
6

7
import numpy as np
11✔
8

9

10
class _Position(Structure):
11✔
11
    """Definition of an xyz location in space with underlying c-types
12

13
    C-type Attributes
14
    -----------------
15
    x : c_double
16
        Position's x value (default: 0.0)
17
    y : c_double
18
        Position's y value (default: 0.0)
19
    z : c_double
20
        Position's z value (default: 0.0)
21
    """
22
    _fields_ = [('x', c_double),
11✔
23
                ('y', c_double),
24
                ('z', c_double)]
25

26
    def __getitem__(self, idx):
11✔
27
        if idx == 0:
11✔
28
            return self.x
11✔
29
        elif idx == 1:
11✔
30
            return self.y
11✔
31
        elif idx == 2:
11✔
32
            return self.z
11✔
33
        else:
34
            raise IndexError(f"{idx} index is invalid for _Position")
11✔
35

36
    def __setitem__(self, idx, val):
11✔
37
        if idx == 0:
11✔
38
            self.x = val
11✔
39
        elif idx == 1:
11✔
40
            self.y = val
11✔
41
        elif idx == 2:
11✔
42
            self.z = val
11✔
43
        else:
44
            raise IndexError(f"{idx} index is invalid for _Position")
×
45

46
    def __repr__(self):
11✔
47
        return f"({self.x}, {self.y}, {self.z})"
×
48

49

50
class _PlotBase(Structure):
11✔
51
    """A structure defining a 2-D geometry slice with underlying c-types
52

53
    C-Type Attributes
54
    -----------------
55
    origin : openmc.lib.plot._Position
56
        A position defining the origin of the plot.
57
    width_ : openmc.lib.plot._Position
58
        The width of the plot along the x, y, and z axes, respectively
59
    basis_ : c_int
60
        The axes basis of the plot view.
61
    pixels_ : c_size_t[3]
62
        The resolution of the plot in the horizontal and vertical dimensions
63
    level_ : c_int
64
        The universe level for the plot view
65

66
    Attributes
67
    ----------
68
    origin : tuple or list of ndarray
69
        Origin (center) of the plot
70
    width : float
71
        The horizontal dimension of the plot in geometry units (cm)
72
    height : float
73
        The vertical dimension of the plot in geometry units (cm)
74
    basis : string
75
        One of {'xy', 'xz', 'yz'} indicating the horizontal and vertical
76
        axes of the plot.
77
    h_res : int
78
        The horizontal resolution of the plot in pixels
79
    v_res : int
80
        The vertical resolution of the plot in pixels
81
    level : int
82
        The universe level for the plot (default: -1 -> all universes shown)
83
    """
84
    _fields_ = [('origin_', _Position),
11✔
85
                ('width_', _Position),
86
                ('basis_', c_int),
87
                ('pixels_', 3*c_size_t),
88
                ('color_overlaps_', c_bool),
89
                ('level_', c_int)]
90

91
    def __init__(self):
11✔
92
        self.level_ = -1
11✔
93
        self.basis_ = 1
11✔
94
        self.color_overlaps_ = False
11✔
95

96
    @property
11✔
97
    def origin(self):
11✔
UNCOV
98
        return self.origin_
×
99

100
    @origin.setter
11✔
101
    def origin(self, origin):
11✔
102
        self.origin_.x = origin[0]
11✔
103
        self.origin_.y = origin[1]
11✔
104
        self.origin_.z = origin[2]
11✔
105

106
    @property
11✔
107
    def width(self):
11✔
UNCOV
108
        return self.width_.x
×
109

110
    @width.setter
11✔
111
    def width(self, width):
11✔
112
        self.width_.x = width
11✔
113

114
    @property
11✔
115
    def height(self):
11✔
UNCOV
116
        return self.width_.y
×
117

118
    @height.setter
11✔
119
    def height(self, height):
11✔
120
        self.width_.y = height
11✔
121

122
    @property
11✔
123
    def basis(self):
11✔
124
        if self.basis_ == 1:
×
125
            return 'xy'
×
126
        elif self.basis_ == 2:
×
127
            return 'xz'
×
128
        elif self.basis_ == 3:
×
UNCOV
129
            return 'yz'
×
130

UNCOV
131
        raise ValueError(f"Plot basis {self.basis_} is invalid")
×
132

133
    @basis.setter
11✔
134
    def basis(self, basis):
11✔
135
        if isinstance(basis, str):
11✔
136
            valid_bases = ('xy', 'xz', 'yz')
11✔
137
            basis = basis.lower()
11✔
138
            if basis not in valid_bases:
11✔
UNCOV
139
                raise ValueError(f"{basis} is not a valid plot basis.")
×
140

141
            if basis == 'xy':
11✔
142
                self.basis_ = 1
11✔
143
            elif basis == 'xz':
×
144
                self.basis_ = 2
×
145
            elif basis == 'yz':
×
UNCOV
146
                self.basis_ = 3
×
147
            return
11✔
148

149
        if isinstance(basis, int):
×
150
            valid_bases = (1, 2, 3)
×
151
            if basis not in valid_bases:
×
152
                raise ValueError(f"{basis} is not a valid plot basis.")
×
153
            self.basis_ = basis
×
UNCOV
154
            return
×
155

UNCOV
156
        raise ValueError(f"{basis} of type {type(basis)} is an invalid plot basis")
×
157

158
    @property
11✔
159
    def h_res(self):
11✔
160
        return self.pixels_[0]
11✔
161

162
    @h_res.setter
11✔
163
    def h_res(self, h_res):
11✔
164
        self.pixels_[0] = h_res
11✔
165

166
    @property
11✔
167
    def v_res(self):
11✔
168
        return self.pixels_[1]
11✔
169

170
    @v_res.setter
11✔
171
    def v_res(self, v_res):
11✔
172
        self.pixels_[1] = v_res
11✔
173

174
    @property
11✔
175
    def level(self):
11✔
UNCOV
176
        return int(self.level_)
×
177

178
    @level.setter
11✔
179
    def level(self, level):
11✔
180
        self.level_ = level
11✔
181

182
    @property
11✔
183
    def color_overlaps(self):
11✔
UNCOV
184
        return self.color_overlaps_
×
185

186
    @color_overlaps.setter
11✔
187
    def color_overlaps(self, color_overlaps):
11✔
UNCOV
188
        self.color_overlaps_ = color_overlaps
×
189

190
    @property
11✔
191
    def color_overlaps(self):
11✔
UNCOV
192
        return self.color_overlaps_
×
193

194
    @color_overlaps.setter
11✔
195
    def color_overlaps(self, val):
11✔
UNCOV
196
        self.color_overlaps_ = val
×
197

198
    def __repr__(self):
11✔
UNCOV
199
        out_str = ["-----",
×
200
                   "Plot:",
201
                   "-----",
202
                   f"Origin: {self.origin}",
203
                   f"Width: {self.width}",
204
                   f"Height: {self.height}",
205
                   f"Basis: {self.basis}",
206
                   f"HRes: {self.h_res}",
207
                   f"VRes: {self.v_res}",
208
                   f"Color Overlaps: {self.color_overlaps}",
209
                   f"Level: {self.level}"]
UNCOV
210
        return '\n'.join(out_str)
×
211

212

213
_dll.openmc_id_map.argtypes = [POINTER(_PlotBase), POINTER(c_int32)]
11✔
214
_dll.openmc_id_map.restype = c_int
11✔
215
_dll.openmc_id_map.errcheck = _error_handler
11✔
216

217

218
def id_map(plot):
11✔
219
    """
220
    Generate a 2-D map of cell and material IDs. Used for in-memory image
221
    generation.
222

223
    Parameters
224
    ----------
225
    plot : openmc.lib.plot._PlotBase
226
        Object describing the slice of the model to be generated
227

228
    Returns
229
    -------
230
    id_map : numpy.ndarray
231
        A NumPy array with shape (vertical pixels, horizontal pixels, 3) of
232
        OpenMC property ids with dtype int32. The last dimension of the array
233
        contains, in order, cell IDs, cell instances, and material IDs.
234

235
    """
236
    img_data = np.zeros((plot.v_res, plot.h_res, 3),
11✔
237
                        dtype=np.dtype('int32'))
238
    _dll.openmc_id_map(plot, img_data.ctypes.data_as(POINTER(c_int32)))
11✔
239
    return img_data
11✔
240

241

242
_dll.openmc_property_map.argtypes = [POINTER(_PlotBase), POINTER(c_double)]
11✔
243
_dll.openmc_property_map.restype = c_int
11✔
244
_dll.openmc_property_map.errcheck = _error_handler
11✔
245

246

247
def property_map(plot):
11✔
248
    """
249
    Generate a 2-D map of cell temperatures and material densities. Used for
250
    in-memory image generation.
251

252
    Parameters
253
    ----------
254
    plot : openmc.lib.plot._PlotBase
255
        Object describing the slice of the model to be generated
256

257
    Returns
258
    -------
259
    property_map : numpy.ndarray
260
        A NumPy array with shape (vertical pixels, horizontal pixels, 2) of
261
        OpenMC property ids with dtype float
262

263
    """
264
    prop_data = np.zeros((plot.v_res, plot.h_res, 2))
11✔
265
    _dll.openmc_property_map(plot, prop_data.ctypes.data_as(POINTER(c_double)))
11✔
266
    return prop_data
11✔
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