def evaluate(self): f = interpreter.Eval(self.expr) self.interpolate( numpy_op_foo(args=(f, ), op=lambda A: np.linalg.eig(A)[1].T, shape_res=self.shape)) return self
def evaluate(self): f = interpreter.Eval(self.expr) self.interpolate( numpy_op_foo(args=(f, ), op=np.linalg.eigvals, shape_res=self.shape)) return self
def SlidingWindowFilter(Filter, width, series): ''' Collapse a series into a different (shorter) series obtained by applying filter to the chunks of series of given width. ''' assert width > 0 t_buffer, f_buffer = deque(maxlen=width), deque(maxlen=width) series = interpreter.Eval(series) times = series.times nodes = series.nodes filtered_ft_pairs = [] for t, f in zip(times, nodes): t_buffer.append(t) f_buffer.append(f) # Once the deque is full it will 'overflow' from right so then # we have the right view to filter if len(f_buffer) == width: ff = Filter( timeseries.TempSeries(zip(list(f_buffer), list(t_buffer)))) tf = list(t_buffer)[width / 2] # Okay for odd filtered_ft_pairs.append((ff, tf)) return timeseries.TempSeries(filtered_ft_pairs)
def stream(series, f): '''Pipe series through Function f''' series = interpreter.Eval(series) assert series.V.ufl_element() == f.function_space().ufl_element() assert series.V.mesh().id() == f.function_space().mesh().id() for f_ in series: # Get your own iterator f.vector().set_local(f_.vector().get_local()) yield f
def evaluate(self): # first, compute the mean series = interpreter.Eval(self.expr) mean = interpreter.Eval(Mean(series)) # get the square of the field of the mean mean_vector = mean.vector() mvs = as_backend_type(mean_vector).vec() # the mean squared, to be used for computing the RMS mvs.pointwiseMult(mvs, mvs) # now, compute the STD # for this, follow the example of RMS std = self # NOTE: for efficiency we stay away from Interpreter and all is in PETSc layer x = as_backend_type( std.vector()).vec() # PETSc.Vec, stores the final output x.zeroEntries() y = x.copy() # Stores the current working field # Integrate dts = np.diff(series.times) f_vectors = [as_backend_type(f.vector()).vec() for f in series.nodes] for dt, (f0, f1) in zip(dts, zip(f_vectors[:-1], f_vectors[1:])): y.pointwiseMult(f0, f0) # y = f0**2 x.axpy(dt / 2., y) # x += dt / 2 * y y.pointwiseMult(f1, f1) # y = f1**2 x.axpy(dt / 2., y) # x += dt / 2 * y x.axpy( -dt, mvs ) # x += -dt * mvs NOTE: no factor 2, as adding 2 dt / 2 to compensate # Time interval scaling x /= dts.sum() # sqrt x.sqrtabs() return self
def evaluate(self): # Apply simpsons rule series = interpreter.Eval(self.expr) # Functions mean = self x = mean.vector() x.zero() # NOTE: for effiecency we stay away from Interpreter # Int dts = np.diff(series.times) for dt, (f0, f1) in zip(dts, zip(series.nodes[:-1], series.nodes[1:])): x.axpy(dt / 2., f0.vector()) # (f0+f1)*dt/2 x.axpy(dt / 2., f1.vector()) # Time interval scaling x /= dts.sum() return self
def __init__(self, ft_pairs): # NOTE: this is derived from Function just to allow nice # interplay with the interpreter. If there were space time # elements then we could have eval f(t, x) support nodes, times = list(zip(*ft_pairs)) # Checks some necessaru conditions for compatibility of nodes in the series assert check_nodes(nodes) # Optimistically take the function space V = interpreter.Eval(next(iter(nodes))).function_space() # Time interval check dt = np.diff(times) assert (dt > 0).all() self.nodes = nodes self.times = times self.V = V Function.__init__(self, V)
def evaluate(self): # Again by applying simpson series = interpreter.Eval(self.expr) rms = self # NOTE: for efficiency we stay away from Interpreter and all is in PETSc layer x = as_backend_type(rms.vector()).vec() # PETSc.Vec x.zeroEntries() y = x.copy() # Stores fi**2 # Integrate dts = np.diff(series.times) f_vectors = [as_backend_type(f.vector()).vec() for f in series.nodes] for dt, (f0, f1) in zip(dts, zip(f_vectors[:-1], f_vectors[1:])): y.pointwiseMult(f0, f0) # y = f0**2 x.axpy(dt / 2., y) # (f0**2+f1**2)*dt/2 y.pointwiseMult(f1, f1) # y = f1**2 x.axpy(dt / 2., y) # Time interval scaling x /= dts.sum() # sqrt x.sqrtabs() return self