We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Expose the set_contained option through the C-API
In Cardinal, we're setting the temperatures of pebbles (which are filled with many cells representing TRISOs, etc.) by calling `cell->set_temperature(T, instance, true /* set_contained */)`. Unfortunately, the `runtime_error`s thrown by OpenMC in this function do not get routed through MOOSE, so if OpenMC encounters an error, all that shows up on the MOOSE side is an unhelpful `MPI_Abort`. 

For instance, if we try to set a temperature of `0` to an OpenMC cell, but don't have data at that temperature, we get this error message:

```
Time Step 1, time = 1, dt = 1
Sending temperature to OpenMC...
application called MPI_Abort(MPI_COMM_WORLD, 1) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=1
```

even though OpenMC internally is throwing an exception with a helpful message:

*in Cell::set_temperature*:
```
      throw std::runtime_error{"Temperature is below minimum temperature at "
        "which data is available."};
```

Because the `openmc_cell_set_temperature` function _does_ catch this exception and saves the error message, I'd like to use `openmc_cell_set_temperature`. *But*, the interface right now does not let you control the `set_contained` parameter.

### Desired Change

Allow `openmc_cell_set_temperature` to control the `set_contained` parameter so that we can catch exceptions for cell temperatures in MOOSE.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `openmc/lib/cell.py`
Content:
```
1 import sys
2 
3 from collections.abc import Mapping, Iterable
4 from ctypes import c_int, c_int32, c_double, c_char_p, POINTER
5 from weakref import WeakValueDictionary
6 
7 import numpy as np
8 
9 from ..exceptions import AllocationError, InvalidIDError
10 from . import _dll
11 from .core import _FortranObjectWithID
12 from .error import _error_handler
13 from .material import Material
14 
15 __all__ = ['Cell', 'cells']
16 
17 # Cell functions
18 _dll.openmc_extend_cells.argtypes = [c_int32, POINTER(c_int32), POINTER(c_int32)]
19 _dll.openmc_extend_cells.restype = c_int
20 _dll.openmc_extend_cells.errcheck = _error_handler
21 _dll.openmc_cell_get_id.argtypes = [c_int32, POINTER(c_int32)]
22 _dll.openmc_cell_get_id.restype = c_int
23 _dll.openmc_cell_get_id.errcheck = _error_handler
24 _dll.openmc_cell_get_fill.argtypes = [
25     c_int32, POINTER(c_int), POINTER(POINTER(c_int32)), POINTER(c_int32)]
26 _dll.openmc_cell_get_fill.restype = c_int
27 _dll.openmc_cell_get_fill.errcheck = _error_handler
28 _dll.openmc_cell_get_temperature.argtypes = [
29     c_int32, POINTER(c_int32), POINTER(c_double)]
30 _dll.openmc_cell_get_temperature.restype = c_int
31 _dll.openmc_cell_get_temperature.errcheck = _error_handler
32 _dll.openmc_cell_get_name.argtypes = [c_int32, POINTER(c_char_p)]
33 _dll.openmc_cell_get_name.restype = c_int
34 _dll.openmc_cell_get_name.errcheck = _error_handler
35 _dll.openmc_cell_set_name.argtypes = [c_int32, c_char_p]
36 _dll.openmc_cell_set_name.restype = c_int
37 _dll.openmc_cell_set_name.errcheck = _error_handler
38 _dll.openmc_cell_set_fill.argtypes = [
39     c_int32, c_int, c_int32, POINTER(c_int32)]
40 _dll.openmc_cell_set_fill.restype = c_int
41 _dll.openmc_cell_set_fill.errcheck = _error_handler
42 _dll.openmc_cell_set_id.argtypes = [c_int32, c_int32]
43 _dll.openmc_cell_set_id.restype = c_int
44 _dll.openmc_cell_set_id.errcheck = _error_handler
45 _dll.openmc_cell_set_temperature.argtypes = [
46     c_int32, c_double, POINTER(c_int32)]
47 _dll.openmc_cell_set_temperature.restype = c_int
48 _dll.openmc_cell_set_temperature.errcheck = _error_handler
49 _dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]
50 _dll.openmc_get_cell_index.restype = c_int
51 _dll.openmc_get_cell_index.errcheck = _error_handler
52 _dll.cells_size.restype = c_int
53 _dll.openmc_cell_bounding_box.argtypes = [c_int,
54                                           POINTER(c_double),
55                                           POINTER(c_double)]
56 _dll.openmc_cell_bounding_box.restype = c_int
57 _dll.openmc_cell_bounding_box.errcheck = _error_handler
58 
59 
60 class Cell(_FortranObjectWithID):
61     """Cell stored internally.
62 
63     This class exposes a cell that is stored internally in the OpenMC
64     library. To obtain a view of a cell with a given ID, use the
65     :data:`openmc.lib.cells` mapping.
66 
67     Parameters
68     ----------
69     index : int
70          Index in the `cells` array.
71 
72     Attributes
73     ----------
74     id : int
75         ID of the cell
76 
77     """
78     __instances = WeakValueDictionary()
79 
80     def __new__(cls, uid=None, new=True, index=None):
81         mapping = cells
82         if index is None:
83             if new:
84                 # Determine ID to assign
85                 if uid is None:
86                     uid = max(mapping, default=0) + 1
87                 else:
88                     if uid in mapping:
89                         raise AllocationError('A cell with ID={} has already '
90                                               'been allocated.'.format(uid))
91 
92                 index = c_int32()
93                 _dll.openmc_extend_cells(1, index, None)
94                 index = index.value
95             else:
96                 index = mapping[uid]._index
97 
98         if index not in cls.__instances:
99             instance = super().__new__(cls)
100             instance._index = index
101             if uid is not None:
102                 instance.id = uid
103             cls.__instances[index] = instance
104 
105         return cls.__instances[index]
106 
107     @property
108     def id(self):
109         cell_id = c_int32()
110         _dll.openmc_cell_get_id(self._index, cell_id)
111         return cell_id.value
112 
113     @id.setter
114     def id(self, cell_id):
115         _dll.openmc_cell_set_id(self._index, cell_id)
116 
117     @property
118     def name(self):
119         name = c_char_p()
120         _dll.openmc_cell_get_name(self._index, name)
121         return name.value.decode()
122 
123     @name.setter
124     def name(self, name):
125         name_ptr = c_char_p(name.encode())
126         _dll.openmc_cell_set_name(self._index, name_ptr)
127 
128     @property
129     def fill(self):
130         fill_type = c_int()
131         indices = POINTER(c_int32)()
132         n = c_int32()
133         _dll.openmc_cell_get_fill(self._index, fill_type, indices, n)
134         if fill_type.value == 0:
135             if n.value > 1:
136                 return [Material(index=i) for i in indices[:n.value]]
137             else:
138                 index = indices[0]
139                 return Material(index=index)
140         else:
141             raise NotImplementedError
142 
143     @fill.setter
144     def fill(self, fill):
145         if isinstance(fill, Iterable):
146             n = len(fill)
147             indices = (c_int32*n)(*(m._index if m is not None else -1
148                                     for m in fill))
149             _dll.openmc_cell_set_fill(self._index, 0, n, indices)
150         elif isinstance(fill, Material):
151             indices = (c_int32*1)(fill._index)
152             _dll.openmc_cell_set_fill(self._index, 0, 1, indices)
153         elif fill is None:
154             indices = (c_int32*1)(-1)
155             _dll.openmc_cell_set_fill(self._index, 0, 1, indices)
156 
157     def get_temperature(self, instance=None):
158         """Get the temperature of a cell
159 
160         Parameters
161         ----------
162         instance: int or None
163             Which instance of the cell
164 
165         """
166 
167         if instance is not None:
168             instance = c_int32(instance)
169 
170         T = c_double()
171         _dll.openmc_cell_get_temperature(self._index, instance, T)
172         return T.value
173 
174     def set_temperature(self, T, instance=None):
175         """Set the temperature of a cell
176 
177         Parameters
178         ----------
179         T : float
180             Temperature in K
181         instance : int or None
182             Which instance of the cell
183 
184         """
185 
186         if instance is not None:
187             instance = c_int32(instance)
188 
189         _dll.openmc_cell_set_temperature(self._index, T, instance)
190 
191     @property
192     def bounding_box(self):
193         inf = sys.float_info.max
194         llc = np.zeros(3)
195         urc = np.zeros(3)
196         _dll.openmc_cell_bounding_box(self._index,
197                                  llc.ctypes.data_as(POINTER(c_double)),
198                                  urc.ctypes.data_as(POINTER(c_double)))
199         llc[llc == inf] = np.inf
200         urc[urc == inf] = np.inf
201         llc[llc == -inf] = -np.inf
202         urc[urc == -inf] = -np.inf
203 
204         return llc, urc
205 
206 class _CellMapping(Mapping):
207     def __getitem__(self, key):
208         index = c_int32()
209         try:
210             _dll.openmc_get_cell_index(key, index)
211         except (AllocationError, InvalidIDError) as e:
212             # __contains__ expects a KeyError to work correctly
213             raise KeyError(str(e))
214         return Cell(index=index.value)
215 
216     def __iter__(self):
217         for i in range(len(self)):
218             yield Cell(index=i).id
219 
220     def __len__(self):
221         return _dll.cells_size()
222 
223     def __repr__(self):
224         return repr(dict(self))
225 
226 cells = _CellMapping()
227
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/openmc/lib/cell.py b/openmc/lib/cell.py
--- a/openmc/lib/cell.py
+++ b/openmc/lib/cell.py
@@ -1,7 +1,7 @@
 import sys
 
 from collections.abc import Mapping, Iterable
-from ctypes import c_int, c_int32, c_double, c_char_p, POINTER
+from ctypes import c_int, c_int32, c_double, c_char_p, POINTER, c_bool
 from weakref import WeakValueDictionary
 
 import numpy as np
@@ -43,7 +43,7 @@
 _dll.openmc_cell_set_id.restype = c_int
 _dll.openmc_cell_set_id.errcheck = _error_handler
 _dll.openmc_cell_set_temperature.argtypes = [
-    c_int32, c_double, POINTER(c_int32)]
+    c_int32, c_double, POINTER(c_int32), c_bool]
 _dll.openmc_cell_set_temperature.restype = c_int
 _dll.openmc_cell_set_temperature.errcheck = _error_handler
 _dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]
@@ -171,7 +171,7 @@
         _dll.openmc_cell_get_temperature(self._index, instance, T)
         return T.value
 
-    def set_temperature(self, T, instance=None):
+    def set_temperature(self, T, instance=None, set_contained=False):
         """Set the temperature of a cell
 
         Parameters
@@ -180,13 +180,16 @@
             Temperature in K
         instance : int or None
             Which instance of the cell
+        set_contained: bool
+            If cell is not filled by a material, whether to set the temperature of
+            all filled cells
 
         """
 
         if instance is not None:
             instance = c_int32(instance)
 
-        _dll.openmc_cell_set_temperature(self._index, T, instance)
+        _dll.openmc_cell_set_temperature(self._index, T, instance, set_contained)
 
     @property
     def bounding_box(self):

{"golden_diff": "diff --git a/openmc/lib/cell.py b/openmc/lib/cell.py\n--- a/openmc/lib/cell.py\n+++ b/openmc/lib/cell.py\n@@ -1,7 +1,7 @@\n import sys\n \n from collections.abc import Mapping, Iterable\n-from ctypes import c_int, c_int32, c_double, c_char_p, POINTER\n+from ctypes import c_int, c_int32, c_double, c_char_p, POINTER, c_bool\n from weakref import WeakValueDictionary\n \n import numpy as np\n@@ -43,7 +43,7 @@\n _dll.openmc_cell_set_id.restype = c_int\n _dll.openmc_cell_set_id.errcheck = _error_handler\n _dll.openmc_cell_set_temperature.argtypes = [\n-    c_int32, c_double, POINTER(c_int32)]\n+    c_int32, c_double, POINTER(c_int32), c_bool]\n _dll.openmc_cell_set_temperature.restype = c_int\n _dll.openmc_cell_set_temperature.errcheck = _error_handler\n _dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]\n@@ -171,7 +171,7 @@\n         _dll.openmc_cell_get_temperature(self._index, instance, T)\n         return T.value\n \n-    def set_temperature(self, T, instance=None):\n+    def set_temperature(self, T, instance=None, set_contained=False):\n         \"\"\"Set the temperature of a cell\n \n         Parameters\n@@ -180,13 +180,16 @@\n             Temperature in K\n         instance : int or None\n             Which instance of the cell\n+        set_contained: bool\n+            If cell is not filled by a material, whether to set the temperature of\n+            all filled cells\n \n         \"\"\"\n \n         if instance is not None:\n             instance = c_int32(instance)\n \n-        _dll.openmc_cell_set_temperature(self._index, T, instance)\n+        _dll.openmc_cell_set_temperature(self._index, T, instance, set_contained)\n \n     @property\n     def bounding_box(self):\n", "issue": "Expose the set_contained option through the C-API\nIn Cardinal, we're setting the temperatures of pebbles (which are filled with many cells representing TRISOs, etc.) by calling `cell->set_temperature(T, instance, true /* set_contained */)`. Unfortunately, the `runtime_error`s thrown by OpenMC in this function do not get routed through MOOSE, so if OpenMC encounters an error, all that shows up on the MOOSE side is an unhelpful `MPI_Abort`. \r\n\r\nFor instance, if we try to set a temperature of `0` to an OpenMC cell, but don't have data at that temperature, we get this error message:\r\n\r\n```\r\nTime Step 1, time = 1, dt = 1\r\nSending temperature to OpenMC...\r\napplication called MPI_Abort(MPI_COMM_WORLD, 1) - process 0\r\n[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=1\r\n```\r\n\r\neven though OpenMC internally is throwing an exception with a helpful message:\r\n\r\n*in Cell::set_temperature*:\r\n```\r\n      throw std::runtime_error{\"Temperature is below minimum temperature at \"\r\n        \"which data is available.\"};\r\n```\r\n\r\nBecause the `openmc_cell_set_temperature` function _does_ catch this exception and saves the error message, I'd like to use `openmc_cell_set_temperature`. *But*, the interface right now does not let you control the `set_contained` parameter.\r\n\r\n### Desired Change\r\n\r\nAllow `openmc_cell_set_temperature` to control the `set_contained` parameter so that we can catch exceptions for cell temperatures in MOOSE.\n", "before_files": [{"content": "import sys\n\nfrom collections.abc import Mapping, Iterable\nfrom ctypes import c_int, c_int32, c_double, c_char_p, POINTER\nfrom weakref import WeakValueDictionary\n\nimport numpy as np\n\nfrom ..exceptions import AllocationError, InvalidIDError\nfrom . import _dll\nfrom .core import _FortranObjectWithID\nfrom .error import _error_handler\nfrom .material import Material\n\n__all__ = ['Cell', 'cells']\n\n# Cell functions\n_dll.openmc_extend_cells.argtypes = [c_int32, POINTER(c_int32), POINTER(c_int32)]\n_dll.openmc_extend_cells.restype = c_int\n_dll.openmc_extend_cells.errcheck = _error_handler\n_dll.openmc_cell_get_id.argtypes = [c_int32, POINTER(c_int32)]\n_dll.openmc_cell_get_id.restype = c_int\n_dll.openmc_cell_get_id.errcheck = _error_handler\n_dll.openmc_cell_get_fill.argtypes = [\n    c_int32, POINTER(c_int), POINTER(POINTER(c_int32)), POINTER(c_int32)]\n_dll.openmc_cell_get_fill.restype = c_int\n_dll.openmc_cell_get_fill.errcheck = _error_handler\n_dll.openmc_cell_get_temperature.argtypes = [\n    c_int32, POINTER(c_int32), POINTER(c_double)]\n_dll.openmc_cell_get_temperature.restype = c_int\n_dll.openmc_cell_get_temperature.errcheck = _error_handler\n_dll.openmc_cell_get_name.argtypes = [c_int32, POINTER(c_char_p)]\n_dll.openmc_cell_get_name.restype = c_int\n_dll.openmc_cell_get_name.errcheck = _error_handler\n_dll.openmc_cell_set_name.argtypes = [c_int32, c_char_p]\n_dll.openmc_cell_set_name.restype = c_int\n_dll.openmc_cell_set_name.errcheck = _error_handler\n_dll.openmc_cell_set_fill.argtypes = [\n    c_int32, c_int, c_int32, POINTER(c_int32)]\n_dll.openmc_cell_set_fill.restype = c_int\n_dll.openmc_cell_set_fill.errcheck = _error_handler\n_dll.openmc_cell_set_id.argtypes = [c_int32, c_int32]\n_dll.openmc_cell_set_id.restype = c_int\n_dll.openmc_cell_set_id.errcheck = _error_handler\n_dll.openmc_cell_set_temperature.argtypes = [\n    c_int32, c_double, POINTER(c_int32)]\n_dll.openmc_cell_set_temperature.restype = c_int\n_dll.openmc_cell_set_temperature.errcheck = _error_handler\n_dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]\n_dll.openmc_get_cell_index.restype = c_int\n_dll.openmc_get_cell_index.errcheck = _error_handler\n_dll.cells_size.restype = c_int\n_dll.openmc_cell_bounding_box.argtypes = [c_int,\n                                          POINTER(c_double),\n                                          POINTER(c_double)]\n_dll.openmc_cell_bounding_box.restype = c_int\n_dll.openmc_cell_bounding_box.errcheck = _error_handler\n\n\nclass Cell(_FortranObjectWithID):\n    \"\"\"Cell stored internally.\n\n    This class exposes a cell that is stored internally in the OpenMC\n    library. To obtain a view of a cell with a given ID, use the\n    :data:`openmc.lib.cells` mapping.\n\n    Parameters\n    ----------\n    index : int\n         Index in the `cells` array.\n\n    Attributes\n    ----------\n    id : int\n        ID of the cell\n\n    \"\"\"\n    __instances = WeakValueDictionary()\n\n    def __new__(cls, uid=None, new=True, index=None):\n        mapping = cells\n        if index is None:\n            if new:\n                # Determine ID to assign\n                if uid is None:\n                    uid = max(mapping, default=0) + 1\n                else:\n                    if uid in mapping:\n                        raise AllocationError('A cell with ID={} has already '\n                                              'been allocated.'.format(uid))\n\n                index = c_int32()\n                _dll.openmc_extend_cells(1, index, None)\n                index = index.value\n            else:\n                index = mapping[uid]._index\n\n        if index not in cls.__instances:\n            instance = super().__new__(cls)\n            instance._index = index\n            if uid is not None:\n                instance.id = uid\n            cls.__instances[index] = instance\n\n        return cls.__instances[index]\n\n    @property\n    def id(self):\n        cell_id = c_int32()\n        _dll.openmc_cell_get_id(self._index, cell_id)\n        return cell_id.value\n\n    @id.setter\n    def id(self, cell_id):\n        _dll.openmc_cell_set_id(self._index, cell_id)\n\n    @property\n    def name(self):\n        name = c_char_p()\n        _dll.openmc_cell_get_name(self._index, name)\n        return name.value.decode()\n\n    @name.setter\n    def name(self, name):\n        name_ptr = c_char_p(name.encode())\n        _dll.openmc_cell_set_name(self._index, name_ptr)\n\n    @property\n    def fill(self):\n        fill_type = c_int()\n        indices = POINTER(c_int32)()\n        n = c_int32()\n        _dll.openmc_cell_get_fill(self._index, fill_type, indices, n)\n        if fill_type.value == 0:\n            if n.value > 1:\n                return [Material(index=i) for i in indices[:n.value]]\n            else:\n                index = indices[0]\n                return Material(index=index)\n        else:\n            raise NotImplementedError\n\n    @fill.setter\n    def fill(self, fill):\n        if isinstance(fill, Iterable):\n            n = len(fill)\n            indices = (c_int32*n)(*(m._index if m is not None else -1\n                                    for m in fill))\n            _dll.openmc_cell_set_fill(self._index, 0, n, indices)\n        elif isinstance(fill, Material):\n            indices = (c_int32*1)(fill._index)\n            _dll.openmc_cell_set_fill(self._index, 0, 1, indices)\n        elif fill is None:\n            indices = (c_int32*1)(-1)\n            _dll.openmc_cell_set_fill(self._index, 0, 1, indices)\n\n    def get_temperature(self, instance=None):\n        \"\"\"Get the temperature of a cell\n\n        Parameters\n        ----------\n        instance: int or None\n            Which instance of the cell\n\n        \"\"\"\n\n        if instance is not None:\n            instance = c_int32(instance)\n\n        T = c_double()\n        _dll.openmc_cell_get_temperature(self._index, instance, T)\n        return T.value\n\n    def set_temperature(self, T, instance=None):\n        \"\"\"Set the temperature of a cell\n\n        Parameters\n        ----------\n        T : float\n            Temperature in K\n        instance : int or None\n            Which instance of the cell\n\n        \"\"\"\n\n        if instance is not None:\n            instance = c_int32(instance)\n\n        _dll.openmc_cell_set_temperature(self._index, T, instance)\n\n    @property\n    def bounding_box(self):\n        inf = sys.float_info.max\n        llc = np.zeros(3)\n        urc = np.zeros(3)\n        _dll.openmc_cell_bounding_box(self._index,\n                                 llc.ctypes.data_as(POINTER(c_double)),\n                                 urc.ctypes.data_as(POINTER(c_double)))\n        llc[llc == inf] = np.inf\n        urc[urc == inf] = np.inf\n        llc[llc == -inf] = -np.inf\n        urc[urc == -inf] = -np.inf\n\n        return llc, urc\n\nclass _CellMapping(Mapping):\n    def __getitem__(self, key):\n        index = c_int32()\n        try:\n            _dll.openmc_get_cell_index(key, index)\n        except (AllocationError, InvalidIDError) as e:\n            # __contains__ expects a KeyError to work correctly\n            raise KeyError(str(e))\n        return Cell(index=index.value)\n\n    def __iter__(self):\n        for i in range(len(self)):\n            yield Cell(index=i).id\n\n    def __len__(self):\n        return _dll.cells_size()\n\n    def __repr__(self):\n        return repr(dict(self))\n\ncells = _CellMapping()\n", "path": "openmc/lib/cell.py"}], "after_files": [{"content": "import sys\n\nfrom collections.abc import Mapping, Iterable\nfrom ctypes import c_int, c_int32, c_double, c_char_p, POINTER, c_bool\nfrom weakref import WeakValueDictionary\n\nimport numpy as np\n\nfrom ..exceptions import AllocationError, InvalidIDError\nfrom . import _dll\nfrom .core import _FortranObjectWithID\nfrom .error import _error_handler\nfrom .material import Material\n\n__all__ = ['Cell', 'cells']\n\n# Cell functions\n_dll.openmc_extend_cells.argtypes = [c_int32, POINTER(c_int32), POINTER(c_int32)]\n_dll.openmc_extend_cells.restype = c_int\n_dll.openmc_extend_cells.errcheck = _error_handler\n_dll.openmc_cell_get_id.argtypes = [c_int32, POINTER(c_int32)]\n_dll.openmc_cell_get_id.restype = c_int\n_dll.openmc_cell_get_id.errcheck = _error_handler\n_dll.openmc_cell_get_fill.argtypes = [\n    c_int32, POINTER(c_int), POINTER(POINTER(c_int32)), POINTER(c_int32)]\n_dll.openmc_cell_get_fill.restype = c_int\n_dll.openmc_cell_get_fill.errcheck = _error_handler\n_dll.openmc_cell_get_temperature.argtypes = [\n    c_int32, POINTER(c_int32), POINTER(c_double)]\n_dll.openmc_cell_get_temperature.restype = c_int\n_dll.openmc_cell_get_temperature.errcheck = _error_handler\n_dll.openmc_cell_get_name.argtypes = [c_int32, POINTER(c_char_p)]\n_dll.openmc_cell_get_name.restype = c_int\n_dll.openmc_cell_get_name.errcheck = _error_handler\n_dll.openmc_cell_set_name.argtypes = [c_int32, c_char_p]\n_dll.openmc_cell_set_name.restype = c_int\n_dll.openmc_cell_set_name.errcheck = _error_handler\n_dll.openmc_cell_set_fill.argtypes = [\n    c_int32, c_int, c_int32, POINTER(c_int32)]\n_dll.openmc_cell_set_fill.restype = c_int\n_dll.openmc_cell_set_fill.errcheck = _error_handler\n_dll.openmc_cell_set_id.argtypes = [c_int32, c_int32]\n_dll.openmc_cell_set_id.restype = c_int\n_dll.openmc_cell_set_id.errcheck = _error_handler\n_dll.openmc_cell_set_temperature.argtypes = [\n    c_int32, c_double, POINTER(c_int32), c_bool]\n_dll.openmc_cell_set_temperature.restype = c_int\n_dll.openmc_cell_set_temperature.errcheck = _error_handler\n_dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]\n_dll.openmc_get_cell_index.restype = c_int\n_dll.openmc_get_cell_index.errcheck = _error_handler\n_dll.cells_size.restype = c_int\n_dll.openmc_cell_bounding_box.argtypes = [c_int,\n                                          POINTER(c_double),\n                                          POINTER(c_double)]\n_dll.openmc_cell_bounding_box.restype = c_int\n_dll.openmc_cell_bounding_box.errcheck = _error_handler\n\n\nclass Cell(_FortranObjectWithID):\n    \"\"\"Cell stored internally.\n\n    This class exposes a cell that is stored internally in the OpenMC\n    library. To obtain a view of a cell with a given ID, use the\n    :data:`openmc.lib.cells` mapping.\n\n    Parameters\n    ----------\n    index : int\n         Index in the `cells` array.\n\n    Attributes\n    ----------\n    id : int\n        ID of the cell\n\n    \"\"\"\n    __instances = WeakValueDictionary()\n\n    def __new__(cls, uid=None, new=True, index=None):\n        mapping = cells\n        if index is None:\n            if new:\n                # Determine ID to assign\n                if uid is None:\n                    uid = max(mapping, default=0) + 1\n                else:\n                    if uid in mapping:\n                        raise AllocationError('A cell with ID={} has already '\n                                              'been allocated.'.format(uid))\n\n                index = c_int32()\n                _dll.openmc_extend_cells(1, index, None)\n                index = index.value\n            else:\n                index = mapping[uid]._index\n\n        if index not in cls.__instances:\n            instance = super().__new__(cls)\n            instance._index = index\n            if uid is not None:\n                instance.id = uid\n            cls.__instances[index] = instance\n\n        return cls.__instances[index]\n\n    @property\n    def id(self):\n        cell_id = c_int32()\n        _dll.openmc_cell_get_id(self._index, cell_id)\n        return cell_id.value\n\n    @id.setter\n    def id(self, cell_id):\n        _dll.openmc_cell_set_id(self._index, cell_id)\n\n    @property\n    def name(self):\n        name = c_char_p()\n        _dll.openmc_cell_get_name(self._index, name)\n        return name.value.decode()\n\n    @name.setter\n    def name(self, name):\n        name_ptr = c_char_p(name.encode())\n        _dll.openmc_cell_set_name(self._index, name_ptr)\n\n    @property\n    def fill(self):\n        fill_type = c_int()\n        indices = POINTER(c_int32)()\n        n = c_int32()\n        _dll.openmc_cell_get_fill(self._index, fill_type, indices, n)\n        if fill_type.value == 0:\n            if n.value > 1:\n                return [Material(index=i) for i in indices[:n.value]]\n            else:\n                index = indices[0]\n                return Material(index=index)\n        else:\n            raise NotImplementedError\n\n    @fill.setter\n    def fill(self, fill):\n        if isinstance(fill, Iterable):\n            n = len(fill)\n            indices = (c_int32*n)(*(m._index if m is not None else -1\n                                    for m in fill))\n            _dll.openmc_cell_set_fill(self._index, 0, n, indices)\n        elif isinstance(fill, Material):\n            indices = (c_int32*1)(fill._index)\n            _dll.openmc_cell_set_fill(self._index, 0, 1, indices)\n        elif fill is None:\n            indices = (c_int32*1)(-1)\n            _dll.openmc_cell_set_fill(self._index, 0, 1, indices)\n\n    def get_temperature(self, instance=None):\n        \"\"\"Get the temperature of a cell\n\n        Parameters\n        ----------\n        instance: int or None\n            Which instance of the cell\n\n        \"\"\"\n\n        if instance is not None:\n            instance = c_int32(instance)\n\n        T = c_double()\n        _dll.openmc_cell_get_temperature(self._index, instance, T)\n        return T.value\n\n    def set_temperature(self, T, instance=None, set_contained=False):\n        \"\"\"Set the temperature of a cell\n\n        Parameters\n        ----------\n        T : float\n            Temperature in K\n        instance : int or None\n            Which instance of the cell\n        set_contained: bool\n            If cell is not filled by a material, whether to set the temperature of\n            all filled cells\n\n        \"\"\"\n\n        if instance is not None:\n            instance = c_int32(instance)\n\n        _dll.openmc_cell_set_temperature(self._index, T, instance, set_contained)\n\n    @property\n    def bounding_box(self):\n        inf = sys.float_info.max\n        llc = np.zeros(3)\n        urc = np.zeros(3)\n        _dll.openmc_cell_bounding_box(self._index,\n                                 llc.ctypes.data_as(POINTER(c_double)),\n                                 urc.ctypes.data_as(POINTER(c_double)))\n        llc[llc == inf] = np.inf\n        urc[urc == inf] = np.inf\n        llc[llc == -inf] = -np.inf\n        urc[urc == -inf] = -np.inf\n\n        return llc, urc\n\nclass _CellMapping(Mapping):\n    def __getitem__(self, key):\n        index = c_int32()\n        try:\n            _dll.openmc_get_cell_index(key, index)\n        except (AllocationError, InvalidIDError) as e:\n            # __contains__ expects a KeyError to work correctly\n            raise KeyError(str(e))\n        return Cell(index=index.value)\n\n    def __iter__(self):\n        for i in range(len(self)):\n            yield Cell(index=i).id\n\n    def __len__(self):\n        return _dll.cells_size()\n\n    def __repr__(self):\n        return repr(dict(self))\n\ncells = _CellMapping()\n", "path": "openmc/lib/cell.py"}]}