Commit 015b5cf5 by Ashwin V. Mohanan

### Improve diagnostics, set oddball mode to zero in Burgers

parent 166cbf9bbdfd
Pipeline #22795 passed with stage
in 16 minutes and 47 seconds
 ... ... @@ -8,6 +8,13 @@ Notes - This contrast is less evident if nx=64, 128 etc. which is indeed puzzling. - As suggested in the reference below the foolproof solution is to apply dealiasing which guarantees energy conservation. - The time scheme also plays a role in influencing the final energy, but is less (?) likely to affect aliasing errors directly. - It seems that the oddball mode was not set to zero in FluidSim, but this is perhaps not a big problem since we always use some dealiasing? Examples -------- .. seealso: https://kth-nek5000.github.io/kthNekBook/_notebooks/burgers.html ... ... @@ -17,7 +24,7 @@ import numpy as np import matplotlib.pyplot as plt def solve(Simul, nx, coef_dealiasing): def solve(Simul, nx, time_scheme, coef_dealiasing): params = Simul.create_default_params() params.output.sub_directory = "bench_skew_sym" ... ... @@ -29,8 +36,8 @@ def solve(Simul, nx, coef_dealiasing): params.nu_2 = 0.0 params.time_stepping.USE_CFL = False params.time_stepping.deltat0 = 1e-2 params.time_stepping.t_end = 1.0 params.time_stepping.type_time_scheme = "RK2" params.time_stepping.t_end = 1.1 params.time_stepping.type_time_scheme = time_scheme params.init_fields.type = "in_script" params.output.periods_print.print_stdout = 0.5 ... ... @@ -43,33 +50,62 @@ def solve(Simul, nx, coef_dealiasing): u = np.sin(x) u_fft = sim.oper.fft(u) # Set "oddball mode" to zero u_fft[sim.oper.nkx-1] = 0. sim.state.init_statephys_from(u=u) sim.state.init_statespect_from(u_fft=u_fft) E_initial = sim.output.compute_energy() # Plot once sim.output.init_with_initialized_state() sim.output.phys_fields.plot(field="u") ax = plt.gca() ax.grid() ax.set(xlim=(0, Lx)) sim.time_stepping.start() E_final = sim.output.compute_energy() print("Final Energy / Initial Energy =", E_final / E_initial) ax.plot(x, sim.state.state_phys.get_var("u")) plt.show() @click.command() @click.option("--solver", type=click.Choice(["conv", "skew_sym"])) @click.option("--nx", type=int, default=101) @click.option("--nx", type=int, default=128) @click.option("--ts", type=click.Choice(["Euler", "RK2", "RK4"]), default="Euler") @click.option("--dealias/--no-dealias", type=bool, default=False) def run(solver, nx, dealias): def run(solver, nx, ts, dealias): """Execute Burgers solvers. Compare the following runs: \b # No dealiasing >>> ./run.py --nx 128 --solver conv >>> ./run.py --nx 128 --solver skew_sym \b # With dealiasing >>> ./run.py --nx 192 --dealias --solver conv >>> ./run.py --nx 192 --dealias --solver skew_sym """ if solver == "conv": from fluidsim.solvers.burgers1d.solver import Simul else: from fluidsim.solvers.burgers1d.skew_sym.solver import Simul solve(Simul, nx, 2./3 if dealias else 1.0) solve(Simul, nx, ts, 2. / 3 if dealias else 1.0) if __name__ == "__main__": params = { "figure.figsize": (14, 5), "grid.alpha": 0.6, } plt.rcParams.update(params) run()
 ... ... @@ -58,4 +58,6 @@ class Simul(SimulBurgers): f_fft[:] += f_fft_cons self.oper.dealiasing(f_fft) # Set "oddball mode" to zero f_fft[self.oper.nkx-1] = 0. return tendencies_fft
 ... ... @@ -89,6 +89,8 @@ class Simul(SimulBasePseudoSpectral): f_fft = tendencies_fft.get_var("u_fft") self.oper.fft_as_arg(f_signal, f_fft) self.oper.dealiasing(f_fft) # Set "oddball mode" to zero f_fft[self.oper.nkx-1] = 0. return tendencies_fft ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!