mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Changes in data/grid.py from PullRequest Inc. review
This commit is contained in:
parent
75f84c82f2
commit
72f2855553
1 changed files with 6 additions and 0 deletions
|
|
@ -37,12 +37,18 @@ def linearize(x, f, tolerance=0.001):
|
|||
y_stack.insert(0, f(x[i + 1]))
|
||||
|
||||
while True:
|
||||
# Get the bounding points currently on the stack
|
||||
x_high, x_low = x_stack[-2:]
|
||||
y_high, y_low = y_stack[-2:]
|
||||
|
||||
# Evaluate the function at the midpoint
|
||||
x_mid = 0.5*(x_low + x_high)
|
||||
y_mid = f(x_mid)
|
||||
|
||||
# Linearly interpolate between the bounding points
|
||||
y_interp = y_low + (y_high - y_low)/(x_high - x_low)*(x_mid - x_low)
|
||||
|
||||
# Check the error on the interpolated point and compare to tolerance
|
||||
error = abs((y_interp - y_mid)/y_mid)
|
||||
if error > tolerance:
|
||||
x_stack.insert(-1, x_mid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue