def evaluate_at(self, coors, source_vals, strategy='kdtree', close_limit=0.1, cache=None, ret_cells=False, ret_status=False, ret_ref_coors=False, verbose=False): """ Evaluate source DOF values corresponding to the field in the given coordinates using the field interpolation. Parameters ---------- coors : array The coordinates the source values should be interpolated into. source_vals : array The source DOF values corresponding to the field. strategy : str, optional The strategy for finding the elements that contain the coordinates. Only 'kdtree' is supported for the moment. close_limit : float, optional The maximum limit distance of a point from the closest element allowed for extrapolation. cache : Struct, optional To speed up a sequence of evaluations, the field mesh and other data can be cached. Optionally, the cache can also contain the reference element coordinates as `cache.ref_coors`, `cache.cells` and `cache.status`, if the evaluation occurs in the same coordinates repeatedly. In that case the mesh related data are ignored. See :func:`Field.get_evaluate_cache() <sfepy.discrete.fem.fields_base.FEField.get_evaluate_cache()>`. ret_ref_coors : bool, optional If True, return also the found reference element coordinates. ret_status : bool, optional If True, return also the enclosing cell status for each point. ret_cells : bool, optional If True, return also the cell indices the coordinates are in. verbose : bool If False, reduce verbosity. Returns ------- vals : array The interpolated values. If `ret_status` is False, the values where the status is greater than one are set to ``numpy.nan``. ref_coors : array The found reference element coordinates, if `ret_ref_coors` is True. cells : array The cell indices, if `ret_ref_coors` or `ret_cells` or `ret_status` are True. status : array The status, if `ret_ref_coors` or `ret_status` are True, with the following meaning: 0 is success, 1 is extrapolation within `close_limit`, 2 is extrapolation outside `close_limit`, 3 is failure, 4 is failure due to non-convergence of the Newton iteration in tensor product cells. """ output('evaluating in %d points...' % coors.shape[0], verbose=verbose) ref_coors, cells, status = get_ref_coors(self, coors, strategy=strategy, close_limit=close_limit, cache=cache, verbose=verbose) tt = time.clock() ap = self.ap ps = ap.interp.poly_spaces['v'] mtx_i = ps.get_mtx_i() # Interpolate to the reference coordinates. vals = nm.empty((coors.shape[0], source_vals.shape[1]), dtype=source_vals.dtype) evaluate_in_rc(vals, ref_coors, cells, status, source_vals, ap.econn, ps.geometry.coors, ps.nodes, ps.order, mtx_i, 1e-15) output('interpolation: %f s' % (time.clock()-tt),verbose=verbose) output('...done',verbose=verbose) if not ret_status: ii = nm.where(status > 1)[0] vals[ii] = nm.nan if ret_ref_coors: return vals, ref_coors, cells, status elif ret_status: return vals, cells, status elif ret_cells: return vals, cells else: return vals
def evaluate_at(self, coors, source_vals, strategy='kdtree', close_limit=0.1, cache=None, ret_cells=False, ret_status=False, ret_ref_coors=False, verbose=False): """ Evaluate source DOF values corresponding to the field in the given coordinates using the field interpolation. Parameters ---------- coors : array The coordinates the source values should be interpolated into. source_vals : array The source DOF values corresponding to the field. strategy : str, optional The strategy for finding the elements that contain the coordinates. Only 'kdtree' is supported for the moment. close_limit : float, optional The maximum limit distance of a point from the closest element allowed for extrapolation. cache : Struct, optional To speed up a sequence of evaluations, the field mesh, the inverse connectivity of the field mesh and the KDTree instance can be cached as `cache.mesh`, `cache.offsets`, `cache.iconn` and `cache.kdtree`. Optionally, the cache can also contain the reference element coordinates as `cache.ref_coors`, `cache.cells` and `cache.status`, if the evaluation occurs in the same coordinates repeatedly. In that case the KDTree related data are ignored. ret_cells : bool, optional If True, return also the cell indices the coordinates are in. ret_status : bool, optional If True, return also the status for each point: 0 is success, 1 is extrapolation within `close_limit`, 2 is extrapolation outside `close_limit`, 3 is failure. ret_ref_coors : bool, optional If True, return also the found reference element coordinates. verbose : bool If False, reduce verbosity. Returns ------- vals : array The interpolated values. cells : array The cell indices, if `ret_cells` or `ret_status` are True. status : array The status, if `ret_status` is True. """ output('evaluating in %d points...' % coors.shape[0], verbose=verbose) ref_coors, cells, status = get_ref_coors(self, coors, strategy=strategy, close_limit=close_limit, cache=cache, verbose=verbose) tt = time.clock() vertex_coorss, nodess, orders, mtx_is = [], [], [], [] conns = [] for ap in self.aps.itervalues(): ps = ap.interp.poly_spaces['v'] vertex_coorss.append(ps.geometry.coors) nodess.append(ps.nodes) mtx_is.append(ps.get_mtx_i()) orders.append(ps.order) conns.append(ap.econn) orders = nm.array(orders, dtype=nm.int32) # Interpolate to the reference coordinates. vals = nm.empty((coors.shape[0], source_vals.shape[1]), dtype=source_vals.dtype) evaluate_in_rc(vals, ref_coors, cells, status, source_vals, conns, vertex_coorss, nodess, orders, mtx_is, 1e-15) output('interpolation: %f s' % (time.clock()-tt),verbose=verbose) output('...done',verbose=verbose) if ret_ref_coors: return vals, ref_coors, cells, status elif ret_status: return vals, cells, status elif ret_cells: return vals, cells else: return vals
def evaluate_at(self, coors, source_vals, strategy='kdtree', close_limit=0.1, cache=None, ret_cells=False, ret_status=False, ret_ref_coors=False, verbose=True): """ Evaluate source DOF values corresponding to the field in the given coordinates using the field interpolation. Parameters ---------- coors : array The coordinates the source values should be interpolated into. source_vals : array The source DOF values corresponding to the field. strategy : str, optional The strategy for finding the elements that contain the coordinates. Only 'kdtree' is supported for the moment. close_limit : float, optional The maximum limit distance of a point from the closest element allowed for extrapolation. cache : Struct, optional To speed up a sequence of evaluations, the field mesh, the inverse connectivity of the field mesh and the KDTree instance can be cached as `cache.mesh`, `cache.offsets`, `cache.iconn` and `cache.kdtree`. Optionally, the cache can also contain the reference element coordinates as `cache.ref_coors`, `cache.cells` and `cache.status`, if the evaluation occurs in the same coordinates repeatedly. In that case the KDTree related data are ignored. ret_cells : bool, optional If True, return also the cell indices the coordinates are in. ret_status : bool, optional If True, return also the status for each point: 0 is success, 1 is extrapolation within `close_limit`, 2 is extrapolation outside `close_limit`, 3 is failure. ret_ref_coors : bool, optional If True, return also the found reference element coordinates. verbose : bool If False, reduce verbosity. Returns ------- vals : array The interpolated values. cells : array The cell indices, if `ret_cells` or `ret_status` are True. status : array The status, if `ret_status` is True. """ output('evaluating in %d points...' % coors.shape[0], verbose=verbose) ref_coors, cells, status = get_ref_coors(self, coors, strategy=strategy, close_limit=close_limit, cache=cache, verbose=verbose) tt = time.clock() vertex_coorss, nodess, orders, mtx_is = [], [], [], [] conns = [] for ap in self.aps.itervalues(): ps = ap.interp.poly_spaces['v'] vertex_coorss.append(ps.geometry.coors) nodess.append(ps.nodes) mtx_is.append(ps.get_mtx_i()) orders.append(ps.order) conns.append(ap.econn) orders = nm.array(orders, dtype=nm.int32) # Interpolate to the reference coordinates. vals = nm.empty((coors.shape[0], source_vals.shape[1]), dtype=source_vals.dtype) evaluate_in_rc(vals, ref_coors, cells, status, source_vals, conns, vertex_coorss, nodess, orders, mtx_is, 1e-15) output('interpolation: %f s' % (time.clock() - tt), verbose=verbose) output('...done', verbose=verbose) if ret_ref_coors: return vals, ref_coors, cells, status elif ret_status: return vals, cells, status elif ret_cells: return vals, cells else: return vals