mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
Converting double max to np.inf on the Python side for bounding boxes.
This commit is contained in:
parent
5ad4f94f3a
commit
d5eaa3b5b7
4 changed files with 27 additions and 13 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import sys
|
||||
|
||||
from collections.abc import Mapping, Iterable
|
||||
from ctypes import c_int, c_int32, c_double, c_char_p, POINTER
|
||||
from weakref import WeakValueDictionary
|
||||
|
|
@ -190,11 +192,17 @@ class Cell(_FortranObjectWithID):
|
|||
|
||||
@property
|
||||
def bounding_box(self):
|
||||
inf = sys.float_info.max
|
||||
llc = np.zeros(3)
|
||||
urc = np.zeros(3)
|
||||
_dll.openmc_cell_bounding_box(self._index,
|
||||
llc.ctypes.data_as(POINTER(c_double)),
|
||||
urc.ctypes.data_as(POINTER(c_double)))
|
||||
llc[llc == inf] = np.inf
|
||||
urc[urc == inf] = np.inf
|
||||
llc[llc == -inf] = -np.inf
|
||||
urc[urc == -inf] = -np.inf
|
||||
|
||||
return llc, urc
|
||||
|
||||
class _CellMapping(Mapping):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import sys
|
||||
|
||||
from contextlib import contextmanager
|
||||
from ctypes import (CDLL, c_bool, c_int, c_int32, c_int64, c_double, c_char_p,
|
||||
c_char, POINTER, Structure, c_void_p, create_string_buffer)
|
||||
|
|
@ -81,10 +83,15 @@ _dll.openmc_global_bounding_box.errcheck = _error_handler
|
|||
|
||||
def global_bounding_box():
|
||||
"""Calculate a global bounding box for the model"""
|
||||
inf = sys.float_info.max
|
||||
llc = np.zeros(3)
|
||||
urc = np.zeros(3)
|
||||
_dll.openmc_global_bounding_box(llc.ctypes.data_as(POINTER(c_double)),
|
||||
urc.ctypes.data_as(POINTER(c_double)))
|
||||
llc[llc == inf] = np.inf
|
||||
urc[urc == inf] = np.inf
|
||||
llc[llc == -inf] = -np.inf
|
||||
urc[urc == -inf] = -np.inf
|
||||
|
||||
return llc, urc
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from collections.abc import Mapping
|
||||
import os
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
|
@ -477,10 +476,8 @@ def test_position(capi_init):
|
|||
|
||||
|
||||
def test_global_bounding_box(capi_init):
|
||||
inf = sys.float_info.max
|
||||
|
||||
expected_llc = (-0.63, -0.63, -inf)
|
||||
expected_urc = (0.63, 0.63, inf)
|
||||
expected_llc = (-0.63, -0.63, -np.inf)
|
||||
expected_urc = (0.63, 0.63, np.inf)
|
||||
|
||||
llc, urc = openmc.capi.global_bounding_box()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import sys
|
||||
|
||||
import numpy as np
|
||||
import openmc.capi
|
||||
import pytest
|
||||
|
|
@ -82,13 +80,17 @@ def complex_cell(run_in_tmpdir):
|
|||
|
||||
openmc.capi.finalize()
|
||||
|
||||
inf = sys.float_info.max
|
||||
|
||||
expected_results = ( (1, (( -4., -4., -inf), ( 4., 4., inf))),
|
||||
(2, (( -7., -7., -inf), ( 7., 7., inf))),
|
||||
(3, ((-10., -10., -inf), (10., 10., inf))),
|
||||
(4, ((-10., -10., -inf), (10., 10., inf))),
|
||||
(5, ((-inf, -inf, -inf), (inf, inf, inf))) )
|
||||
expected_results = ( (1, (( -4., -4., -np.inf),
|
||||
( 4., 4., np.inf))),
|
||||
(2, (( -7., -7., -np.inf),
|
||||
( 7., 7., np.inf))),
|
||||
(3, ((-10., -10., -np.inf),
|
||||
( 10., 10., np.inf))),
|
||||
(4, ((-10., -10., -np.inf),
|
||||
( 10., 10., np.inf))),
|
||||
(5, ((-np.inf, -np.inf, -np.inf),
|
||||
( np.inf, np.inf, np.inf))) )
|
||||
@pytest.mark.parametrize("cell_id,expected_box", expected_results)
|
||||
def test_cell_box(cell_id, expected_box):
|
||||
cell_box = openmc.capi.cells[cell_id].bounding_box
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue