def main(): PARAMS = { "nx": 2**11, "nz": 2**10, "lx": 16.0 / 9.0, "lz": 1.0, "Re": 1e5, "integrator_order": 2, "max_time": 3.0, "final_time": 10, "save_cadence": 0.003, "precision": "single", "spatial_derivative_order": 2, "integrator_order": 2, "integrator": "semi-implicit", "cfl_cutoff": 0.5, } PARAMS["initial_dt"] = 0.05 * PARAMS["lx"] / PARAMS["nx"] params = Parameters(PARAMS) params.save() simulation = Simulation(params, xp) basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP] # Simulation variables w = simulation.make_variable("w", basis_fns) ink = simulation.make_variable("ink", basis_fns) dw = simulation.make_derivative("dw") dink = simulation.make_derivative("dink") psi = simulation.make_variable("psi", basis_fns) ux = simulation.make_variable("ux", basis_fns) uz = simulation.make_variable("uz", basis_fns) simulation.init_laplacian_solver(basis_fns) simulation.config_dump([w, ink], [dw, dink]) simulation.config_save([w]) simulation.config_cfl(ux, uz) simulation.config_scalar_trackers({ "kinetic_energy.npz": partial(calc_kinetic_energy, ux, uz, xp, params), }) # Load initial conditions if params.load_from is not None: simulation.load(params.load_from) else: load_initial_conditions(params, w, ink) total_start = time.time() # Main loop while simulation.is_running(): # SOLVER STARTS HERE calc_velocity_from_vorticity(w, psi, ux, uz, simulation.get_laplacian_solver()) lin_op = 1.0 / params.Re * w.lap() dw[:] = -w.vec_dot_nabla(ux.getp(), uz.getp()) simulation._integrator.integrate(w, dw, lin_op) # lin_op = 1.0/params.Re * ink.lap() # dink[:] = ( # -ink.vec_dot_nabla(ux.getp(), uz.getp()) # ) # simulation._integrator.integrate(ink, dink, lin_op) simulation.end_loop() total_end = time.time() - total_start print(f"Total time: {total_end/3600:.2f} hr") print(f"Total time: {total_end:.2f} s")
def main(): PARAMS = { "nx": 2**10, "nz": 2**10, "lx": 2 * np.pi, "lz": 2 * np.pi, "nu": 0.25, "initial_dt": 1e-3, "precision": "single", "spatial_derivative_order": 2, "integrator_order": 2, "integrator": "semi-implicit", "cfl_cutoff": 0.5, } PARAMS["final_time"] = 1000 * PARAMS["initial_dt"] params = Parameters(PARAMS) params.save() simulation = Simulation(params, xp) basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP] # Simulation variables w = simulation.make_variable("w", basis_fns) dw = simulation.make_derivative("dw") psi = simulation.make_variable("psi", basis_fns) ux = simulation.make_variable("ux", basis_fns) uz = simulation.make_variable("uz", basis_fns) simulation.init_laplacian_solver(basis_fns) simulation.config_dump([w], [dw]) simulation.config_save([w]) simulation.config_cfl(ux, uz) simulation.config_scalar_trackers({ "kinetic_energy.npz": partial(calc_kinetic_energy, ux, uz, xp, params), }) # Load initial conditions if params.load_from is not None: simulation.load(params.load_from) else: load_initial_conditions(params, w) total_start = time.time() # Main loop while simulation.is_running(): # SOLVER STARTS HERE calc_velocity_from_vorticity(w, psi, ux, uz, simulation.get_laplacian_solver()) lin_op = params.nu * w.lap() dw[:] = -w.vec_dot_nabla(ux.getp(), uz.getp()) simulation._integrator.integrate(w, dw, lin_op) simulation.end_loop() final_ke = calc_kinetic_energy(ux, uz, xp, params) initial_ke = simulation._trackers[0]._values[0] viscous_factor = final_ke / initial_ke true_factor = np.exp(-simulation._t) print("abs error = ", abs(viscous_factor - true_factor)) print( "rel error = ", abs(viscous_factor - true_factor) / true_factor * 100, "%", ) total_end = time.time() - total_start print(f"Total time: {total_end/3600:.2f} hr") print(f"Total time: {total_end:.2f} s")
def main(): PARAMS = { "nx": 2**12, "nz": 2**11, "lx": 16.0 / 9, "lz": 1.0, "initial_dt": 1e-4, "cfl_cutoff": 0.5, "Re": 1e6, "S": 1e6, "final_time": 1, "spatial_derivative_order": 2, "integrator_order": 2, "integrator": "semi-implicit", "save_cadence": 0.003, "dump_cadence": 0.1, "precision": "single", } params = Parameters(PARAMS) params.save() simulation = Simulation(params, xp) basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP] # Simulation variables w = simulation.make_variable("w", basis_fns) j = simulation.make_variable("j", basis_fns) dw = simulation.make_derivative("dw") dj = simulation.make_derivative("dj") psi = simulation.make_variable("psi", basis_fns) ux = simulation.make_variable("ux", basis_fns) uz = simulation.make_variable("uz", basis_fns) phi = simulation.make_variable("phi", basis_fns) bx = simulation.make_variable("bx", basis_fns) bz = simulation.make_variable("bz", basis_fns) simulation.init_laplacian_solver(psi._basis_functions) simulation.config_dump([w, j], [dw, dj]) simulation.config_save([j]) simulation.config_cfl(ux, uz) simulation.config_scalar_trackers({ "kinetic_energy.npz": partial(calc_kinetic_energy, ux, uz, xp, params), }) # Load initial conditions if params.load_from is not None: simulation.load(params.load_from) else: load_initial_conditions(params, w, j) total_start = time.time() # Main loop while simulation.is_running(): # SOLVER STARTS HERE calc_velocity_from_vorticity(w, psi, ux, uz, simulation.get_laplacian_solver()) # FIXME - this is not really velocity!! This should be refactored! calc_velocity_from_vorticity(j, phi, bx, bz, simulation.get_laplacian_solver()) lin_op = 1.0 / params.Re * w.lap() dw[:] = -w.vec_dot_nabla(ux.getp(), uz.getp()) + j.vec_dot_nabla( bx.getp(), bz.getp()) simulation._integrator.integrate(w, dw, lin_op) lin_op = 1.0 / params.S * j.lap() dj[:] = -j.vec_dot_nabla(ux.getp(), uz.getp()) + w.vec_dot_nabla( bx.getp(), bz.getp()) simulation._integrator.integrate(j, dj, lin_op) simulation.end_loop() total_end = time.time() - total_start print(f"Total time: {total_end/3600:.2f} hr") print(f"Total time: {total_end:.2f} s")
def main(): PARAMS = { "nx": 2 ** 7, "nz": 2 ** 6, "lx": 16.0 / 9, "lz": 1.0, "initial_dt": 1e-5, "cfl_cutoff": 0.5, "Pr": 1.0, "Ra": 1e6, "final_time": 1e-1, "spatial_derivative_order": 2, "integrator_order": 2, "integrator": "explicit", "save_cadence": 5e-5, "dump_cadence": 1e-1, "discretisation": ["spectral", "fdm"], "precision": "single", } params = Parameters(PARAMS) params.save() simulation = Simulation(params, xp) basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.FDM] # Simulation variables w = simulation.make_variable("w", basis_fns) tmp = simulation.make_variable("tmp", basis_fns) dw = simulation.make_derivative("dw") dtmp = simulation.make_derivative("dtmp") psi = simulation.make_variable("psi", basis_fns) ux = simulation.make_variable("ux", basis_fns) uz = simulation.make_variable("uz", basis_fns) simulation.init_laplacian_solver(psi._basis_functions) simulation.config_dump([w, tmp], [dw, dtmp]) simulation.config_save([tmp]) simulation.config_cfl(ux, uz) simulation.config_scalar_trackers( { "kinetic_energy.npz": partial( calc_kinetic_energy, ux, uz, xp, params ), } ) # Load initial conditions if params.load_from is not None: simulation.load(params.load_from) else: load_initial_conditions(params, w, tmp) total_start = time.time() # Main loop while simulation.is_running(): # SOLVER STARTS HERE calc_velocity_from_vorticity( w, psi, ux, uz, simulation.get_laplacian_solver() ) diffusion_term = params.Pr * w.snabla2() dw[:] = ( -w.vec_dot_nabla(ux.getp(), uz.getp()) - params.Pr * params.Ra * tmp.sddx() ) simulation._integrator.integrate(w, dw, diffusion_term) diffusion_term = tmp.snabla2() dtmp[:] = -tmp.vec_dot_nabla(ux.getp(), uz.getp()) simulation._integrator.integrate(tmp, dtmp, diffusion_term) w[1:, 0] = 0.0 w[1:, -1] = 0.0 psi[1:, 0] = 0.0 psi[1:, -1] = 0.0 psi[0, :] = 0.0 w[0, :] = 0.0 tmp[0, 0] = 1.0 tmp[0, -1] = 0.0 tmp[1:, 0] = 0.0 tmp[1:, -1] = 0.0 simulation.end_loop() total_end = time.time() - total_start print(f"Total time: {total_end/3600:.2f} hr") print(f"Total time: {total_end:.2f} s")
def main(): factor = 0.25 LX = 335.0 * factor LZ = 9.0 / 16 * LX PARAMS = { "nx": 2**9, "nz": 2**8, "lx": LX, "lz": LZ, "initial_dt": 1e-3, "cfl_cutoff": 0.5, "Pr": 7.0, "R0": 1.1, "tau": 1.0 / 3.0, "final_time": 100, "spatial_derivative_order": 2, "integrator_order": 2, "integrator": "semi-implicit", "save_cadence": 0.05, "dump_cadence": 10, "precision": "single", } params = Parameters(PARAMS) params.save() simulation = Simulation(params, xp) basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP] # Simulation variables w = simulation.make_variable("w", basis_fns) tmp = simulation.make_variable("tmp", basis_fns) xi = simulation.make_variable("xi", basis_fns) dw = simulation.make_derivative("dw") dtmp = simulation.make_derivative("dtmp") dxi = simulation.make_derivative("dxi") psi = simulation.make_variable("psi", basis_fns) ux = simulation.make_variable("ux", basis_fns) uz = simulation.make_variable("uz", basis_fns) simulation.init_laplacian_solver(psi._basis_functions) simulation.config_dump([w, tmp, xi], [dw, dtmp, dxi]) simulation.config_save([tmp]) simulation.config_cfl(ux, uz) simulation.config_scalar_trackers({ "kinetic_energy.npz": partial(calc_kinetic_energy, ux, uz, xp, params), "nusselt_number.npz": partial(calc_nusselt_number, tmp, uz, xp, params), }) # Load initial conditions if params.load_from is not None: simulation.load(params.load_from) else: load_initial_conditions(params, w, tmp, xi) total_start = time.time() # Main loop while simulation.is_running(): # SOLVER STARTS HERE calc_velocity_from_vorticity(w, psi, ux, uz, simulation.get_laplacian_solver()) lin_op = params.Pr * w.lap() dw[:] = (-w.vec_dot_nabla(ux.getp(), uz.getp()) + params.Pr * xi.sddx() - params.Pr * tmp.sddx()) simulation._integrator.integrate(w, dw, lin_op) lin_op = tmp.lap() dtmp[:] = -tmp.vec_dot_nabla(ux.getp(), uz.getp()) - uz[:] simulation._integrator.integrate(tmp, dtmp, lin_op) lin_op = params.tau * xi.lap() dxi[:] = -xi.vec_dot_nabla(ux.getp(), uz.getp()) - uz[:] / params.R0 simulation._integrator.integrate(xi, dxi, lin_op) # Remove mean z variation tmp[:, 0] = 0.0 xi[:, 0] = 0.0 simulation.end_loop() total_end = time.time() - total_start print(f"Total time: {total_end/3600:.2f} hr") print(f"Total time: {total_end:.2f} s")