mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Replacing endf c functions with package (#3101)
This commit is contained in:
parent
346f751deb
commit
3ef54ec349
5 changed files with 3 additions and 75 deletions
|
|
@ -1,8 +0,0 @@
|
|||
# cython: c_string_type=str, c_string_encoding=ascii
|
||||
|
||||
cdef extern from "endf.c":
|
||||
double cfloat_endf(const char* buffer, int n)
|
||||
|
||||
def float_endf(s):
|
||||
cdef const char* c_string = s
|
||||
return cfloat_endf(c_string, len(s))
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
//! Convert string representation of a floating point number into a double
|
||||
//
|
||||
//! This function handles converting floating point numbers from an ENDF 11
|
||||
//! character field into a double, covering all the corner cases. Floating point
|
||||
//! numbers are allowed to contain whitespace (which is ignored). Also, in
|
||||
//! exponential notation, it allows the 'e' to be omitted. A field containing
|
||||
//! only whitespace is to be interpreted as a zero.
|
||||
//
|
||||
//! \param buffer character input from an ENDF file
|
||||
//! \param n Length of character input
|
||||
//! \return Floating point number
|
||||
|
||||
double cfloat_endf(const char* buffer, int n)
|
||||
{
|
||||
char arr[13]; // 11 characters plus e and a null terminator
|
||||
int j = 0; // current position in arr
|
||||
int found_significand = 0;
|
||||
int found_exponent = 0;
|
||||
|
||||
// limit n to 11 characters
|
||||
n = n > 11 ? 11 : n;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
char c = buffer[i];
|
||||
|
||||
// Skip whitespace characters
|
||||
if (c == ' ') continue;
|
||||
|
||||
if (found_significand) {
|
||||
if (!found_exponent) {
|
||||
if (c == '+' || c == '-') {
|
||||
// In the case that we encounter +/- and we haven't yet encountered
|
||||
// e/E, we manually add it
|
||||
arr[j++] = 'e';
|
||||
found_exponent = 1;
|
||||
|
||||
} else if (c == 'e' || c == 'E' || c == 'd' || c == 'D') {
|
||||
arr[j++] = 'e';
|
||||
found_exponent = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (c == '.' || (c >= '0' && c <= '9')) {
|
||||
found_significand = 1;
|
||||
}
|
||||
|
||||
// Copy character
|
||||
arr[j++] = c;
|
||||
}
|
||||
|
||||
// Done copying. Add null terminator and convert to double
|
||||
arr[j] = '\0';
|
||||
return atof(arr);
|
||||
}
|
||||
|
|
@ -14,11 +14,7 @@ import numpy as np
|
|||
|
||||
from .data import gnds_name
|
||||
from .function import Tabulated1D
|
||||
try:
|
||||
from ._endf import float_endf
|
||||
_CYTHON = True
|
||||
except ImportError:
|
||||
_CYTHON = False
|
||||
from endf.records import float_endf
|
||||
|
||||
|
||||
_LIBRARY = {0: 'ENDF/B', 1: 'ENDF/A', 2: 'JEFF', 3: 'EFF',
|
||||
|
|
@ -91,10 +87,6 @@ def py_float_endf(s):
|
|||
return float(ENDF_FLOAT_RE.sub(r'\1e\2\3', s))
|
||||
|
||||
|
||||
if not _CYTHON:
|
||||
float_endf = py_float_endf
|
||||
|
||||
|
||||
def int_endf(s):
|
||||
"""Convert string of integer number in ENDF to int.
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ dependencies = [
|
|||
"lxml",
|
||||
"uncertainties",
|
||||
"setuptools",
|
||||
"endf",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -6,7 +6,7 @@ from Cython.Build import cythonize
|
|||
|
||||
|
||||
kwargs = {
|
||||
# Cython is used to add resonance reconstruction and fast float_endf
|
||||
# Cython is used to add resonance reconstruction
|
||||
'ext_modules': cythonize('openmc/data/*.pyx'),
|
||||
'include_dirs': [np.get_include()]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue