def calculate_omega( u, optimal_linear_weights=OPTIMAL_SMOOTH_WEIGHTS, epsilon=1e-6, p=2, ): """Calculate linear weights for the three polynomial reconstructions.""" # see Equation (6) in ref [1] indicator_kj = calculate_smoothness_indicators(u) # p=2 is used by ref. [2] alpha_kj = (np.array(optimal_linear_weights)[:, np.newaxis] / (epsilon + indicator_kj)**p) omega_kj = alpha_kj / duckarray.sum(alpha_kj, axis=-2, keepdims=True) return omega_kj
def __call__(self, t: float) -> np.ndarray: spatial_phase = (2 * np.pi * self.k * self.grid.reference_x / self.grid.period) signals = duckarray.sin(self.omega * t + spatial_phase + self.phi) reference_forcing = duckarray.sum(self.a * signals, axis=0) return self.grid.resample(reference_forcing)
def reconstruct_left(u): """Reconstruct u at +1/2 cells with a left-biased stencil.""" coefficients = left_coefficients(u) u_all = duckarray.stack( [duckarray.roll(u, i, axis=-1) for i in [2, 1, 0, -1, -2]], axis=-1) return duckarray.sum(coefficients * u_all, axis=-1)