class ScalarField: """A scalar field defined by a regular grid and values""" def __init__(self, values, step_vector, nsteps, origin=np.zeros(3), name="scalar field"): """[summary] Parameters ---------- values : numpy array nodes values of regular grid step_vector : numpy array step vector for x,y,z step nsteps : numpy array number of steps name : string, optional name of the feature for the visualisation """ self.values = values self.grid = StructuredGrid(origin, nsteps, step_vector) self.name = name @property def nodes(self): return self.grid.nodes def evaluate_value(self, xyz): """Evaluate the scalar field at locations Parameters ---------- xyz : numpy array locations in real coordinates Returns ------- numpy array interpolated values """ v = self.grid.evaluate_value(xyz, self.values) return v def min(self): return np.min(self.values) def max(self): return np.max(self.values) # 14
def test_evaluate_value(): grid = StructuredGrid() grid.update_property('X', grid.nodes[:, 0]) assert np.sum(grid.barycentre()[:, 0] - grid.evaluate_value(grid.barycentre(), 'X')) == 0
def test_evaluate_value(): grid = StructuredGrid() assert ( np.sum(grid.barycentre[:, 0] - grid.evaluate_value(grid.barycentre, grid.nodes[:, 0])) == 0)