From 9c2cdb46807fb7e452168c0c2a7fc973e94f59b5 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Mon, 8 Nov 2021 14:19:06 +0000 Subject: [PATCH] added new discrete gridtype fixed issues with grid spacings --- binarycpython/utils/grid.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 4fc3e4a0a..ea5445b27 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -2396,16 +2396,11 @@ class Population: or grid_variable["gridtype"] == "right edge" ): offset = -1 - if (grid_variable["gridtype"] == "right" - or grid_variable["gridtype"] == "right edge"): - start = 0 - else: - start = 0 - elif grid_variable["gridtype"] == "discrete": # discrete variables sample all the points offset = 0 - start = 0 + + start = 0 # for loop over the variable if vb: @@ -2491,9 +2486,8 @@ class Population: self._add_code("\n") # calculate phase volume - if(grid_variable["gridtype"] == "discrete" or grid_variable["dphasevol"] == -1): - # no phase volume required for discrete calculations - # so set it to 1.0 + if(grid_variable["dphasevol"] == -1): + # no phase volume required so set it to 1.0 self._add_code("dphasevol_{name} = 1.0 # 666\n".format(name=grid_variable["name"])) elif(grid_variable["gridtype"] == "right" or @@ -2503,8 +2497,15 @@ class Population: "dphasevol_{name} = (sampled_values_{name}[{name}_this_index] - sampled_values_{name}[{name}_prev_index])".format(name=grid_variable["name"]) + "\n" ) + elif grid_variable["gridtype"] == "discrete": + # discrete might have next defined, use it if we can, + # otherwise use prev + self._add_code( + "dphasevol_{name} = (sampled_values_{name}[{name}_next_index] - sampled_values_{name}[{name}_this_index]) if {name}_next_index else (sampled_values_{name}[{name}_this_index] - sampled_values_{name}[{name}_prev_index])".format(name=grid_variable["name"]) + + "\n" + ) else: - # left or centred always have this and next defined + # left and centred always have this and next defined self._add_code( "dphasevol_{name} = (sampled_values_{name}[{name}_next_index] - sampled_values_{name}[{name}_this_index])".format(name=grid_variable["name"]) + "\n" -- GitLab