Read about our upcoming Code of Conduct on this issue

Commit 2a891147 authored by Ashwin V. Mohanan's avatar Ashwin V. Mohanan
Browse files

Add a script to demonstrate different Burgers solvers

Following up on #83
parent 860cc9ebb811
Pipeline #22793 passed with stage
in 15 minutes and 32 seconds
#!/usr/bin/env python
"""Simulate Burgers equation with a sine-wave as an initial condition.
- A stark difference in the final energy is observed between the convective and
skew symmetric Burgers solver is evident a nx=101 is chosen.
- 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.
.. seealso:
import click
import numpy as np
import matplotlib.pyplot as plt
def solve(Simul, coef_dealiasing):
def solve(Simul, nx, coef_dealiasing):
params = Simul.create_default_params()
params.output.sub_directory = "bench_skew_sym"
params.output.periods_save.phys_fields = 1.0
params.short_name_type_run = f"test_coef_dealias={coef_dealiasing:.2f}"
params.oper.Lx = 2 * np.pi
params.oper.nx = 128
params.oper.nx = nx
params.oper.coef_dealiasing = coef_dealiasing
params.nu_2 = 0.0
params.time_stepping.USE_CFL = False
......@@ -47,14 +60,15 @@ def solve(Simul, coef_dealiasing):
@click.option("--solver", type=click.Choice(["conv", "skew_sym"]))
@click.option("--nx", type=int, default=101)
@click.option("--dealias/--no-dealias", type=bool, default=False)
def run(solver, dealias):
def run(solver, nx, dealias):
if solver == "conv":
from fluidsim.solvers.burgers1d.solver import Simul
from fluidsim.solvers.burgers1d.skew_sym.solver import Simul
solve(Simul, 2./3 if dealias else 1.0)
solve(Simul, nx, 2./3 if dealias else 1.0)
if __name__ == "__main__":
......@@ -10,10 +10,21 @@ Provides:
from fluidsim.base.setofvariables import SetOfVariables
from ..solver import Simul as SimulBurgers
from ..solver import Simul as SimulBurgers, InfoSolver as InfoSolverBurgers
class InfoSolver(InfoSolverBurgers):
def _init_root(self):
package = "fluidsim.solvers.burgers1d.skew_sym"
self.module_name = package + ".solver"
self.class_name = "Simul"
self.short_name = "BurgersSkewSym1D"
class Simul(SimulBurgers):
InfoSolver = InfoSolver
def tendencies_nonlin(self, state_spect=None, old=None):
......@@ -43,7 +43,7 @@ class InfoSolver(InfoSolverPseudoSpectral):
package = "fluidsim.solvers.burgers1d"
self.module_name = package + ".solver"
self.class_name = "Simul"
self.short_name = "AD1D"
self.short_name = "Burgers1D"
classes = self.classes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment