Skip to content

Commit

Permalink
standardised import statements in dycore.physics and dycore.utils #25
Browse files Browse the repository at this point in the history
tested; runs
  • Loading branch information
ray-chew committed Mar 23, 2024
1 parent 9342503 commit 6648cc5
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 208 deletions.
14 changes: 0 additions & 14 deletions docs/source/apis/src.dycore.discretisation.time_update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,13 @@

.. autosummary::

colored
data_init
deepcopy
do
euler_backward_non_advective_expl_part
euler_backward_non_advective_impl_part
euler_forward_non_advective





.. rubric:: Classes

.. autosummary::

ElemSpaceDiscr
Grid
NodeSpaceDiscr
read_input




Expand Down
29 changes: 29 additions & 0 deletions docs/source/apis/src.dycore.physics.gas_dynamics.cfl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
src.dycore.physics.gas\_dynamics.cfl
====================================

.. automodule:: src.dycore.physics.gas_dynamics.cfl







.. rubric:: Functions

.. autosummary::

dynamic_timestep













3 changes: 1 addition & 2 deletions docs/source/apis/src.dycore.physics.gas_dynamics.eos.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src.dycore.physics.gas\_dynamics.eos
src.dycore.physics.gas\_dynamics.eos
====================================

.. automodule:: src.dycore.physics.gas_dynamics.eos
Expand All @@ -18,7 +18,6 @@
is_nonhydrostatic
nonhydrostasy
rhoe
set_ghostcells_p2
synchronise_variables


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src.dycore.physics.gas\_dynamics.explicit
src.dycore.physics.gas\_dynamics.explicit
=========================================

.. automodule:: src.dycore.physics.gas_dynamics.explicit
Expand All @@ -16,9 +16,6 @@
advect
advect_rk
explicit_step_and_flux
hll_solver
recovery
set_explicit_boundary_data



Expand Down
29 changes: 0 additions & 29 deletions docs/source/apis/src.dycore.physics.gas_dynamics.gas_dynamics.rst

This file was deleted.

12 changes: 2 additions & 10 deletions docs/source/apis/src.dycore.physics.gas_dynamics.recovery.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src.dycore.physics.gas\_dynamics.recovery
src.dycore.physics.gas\_dynamics.recovery
=========================================

.. automodule:: src.dycore.physics.gas_dynamics.recovery
Expand All @@ -13,23 +13,15 @@

.. autosummary::

do
get_conservatives
limiters
recovery
slopes





.. rubric:: Classes

.. autosummary::

Characters
LimiterType
States




Expand Down
4 changes: 2 additions & 2 deletions docs/source/apis/src.dycore.physics.gas_dynamics.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src.dycore.physics.gas\_dynamics
src.dycore.physics.gas\_dynamics
================================

.. automodule:: src.dycore.physics.gas_dynamics
Expand Down Expand Up @@ -27,9 +27,9 @@ src.dycore.physics.gas\_dynamics
:toctree:
:recursive:

src.dycore.physics.gas_dynamics.cfl
src.dycore.physics.gas_dynamics.eos
src.dycore.physics.gas_dynamics.explicit
src.dycore.physics.gas_dynamics.gas_dynamics
src.dycore.physics.gas_dynamics.numerical_flux
src.dycore.physics.gas_dynamics.recovery
src.dycore.physics.gas_dynamics.thermodynamic
Expand Down
2 changes: 0 additions & 2 deletions docs/source/apis/src.dycore.physics.hydrostatics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
hydrostatic_initial_pressure
hydrostatic_state
loop_over_array
set_ghostcells_p2
set_ghostnodes_p2



Expand Down
9 changes: 0 additions & 9 deletions docs/source/apis/src.dycore.physics.low_mach.laplacian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

.. autosummary::

jit
lap2D
lap2D_5pt
lap2D_exner
Expand All @@ -23,7 +22,6 @@
lap3D
lapHS
lapVS
njit
periodic
precon_diag_prepare
stencil_27pt
Expand All @@ -38,13 +36,6 @@



.. rubric:: Classes

.. autosummary::

BdryType
prange




Expand Down
1 change: 0 additions & 1 deletion docs/source/apis/src.dycore.physics.low_mach.mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
.. autosummary::

MPV
States



Expand Down
12 changes: 0 additions & 12 deletions docs/source/apis/src.dycore.physics.low_mach.second_projection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,17 @@

.. autosummary::

bicgstab
correction_nodes
divergence_nodes
euler_backward_non_advective_expl_part
euler_backward_non_advective_impl_part
euler_forward_non_advective
grad_nodes
grad_nodes_fft
jit
multiply_inverse_coriolis
operator_coefficients_nodes
precon_diag_prepare
rhs_from_p_old
scale_wall_node_values
set_explicit_boundary_data
set_ghostnodes_p2
stencil_27pt
stencil_9pt_numba_test
stencil_hs
stencil_vs



Expand All @@ -42,9 +33,6 @@

.. autosummary::

BdryType
LinearOperator
product
solver_counter


Expand Down
4 changes: 2 additions & 2 deletions src/dycore/physics/gas_dynamics/eos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from dycore.utils.boundary import set_ghostcells_p2
import dycore.utils.boundary as bdry

def nonhydrostasy(ud,t,step):
if step >= 0:
Expand Down Expand Up @@ -79,4 +79,4 @@ def synchronise_variables(mpv, Sol, elem, node, ud, th):
p2bg = np.repeat(p2bg, elem.icx,axis=0)
mpv.p2_cells = scale_factor * Sol.rhoY**th.gm1 - p2bg

set_ghostcells_p2(mpv.p2_cells, elem, ud)
bdry.set_ghostcells_p2(mpv.p2_cells, elem, ud)
21 changes: 10 additions & 11 deletions src/dycore/physics/gas_dynamics/explicit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from dycore.utils.boundary import set_explicit_boundary_data
from dycore.physics.gas_dynamics.recovery import recovery
from dycore.physics.gas_dynamics.numerical_flux import hll_solver
import dycore.utils.boundary as bdry
import dycore.physics.gas_dynamics.recovery as gd_recovery
import dycore.physics.gas_dynamics.numerical_flux as gd_flux

def advect(Sol, flux, dt, elem, odd, ud, th, mpv, node, label, writer = None):
"""
Expand Down Expand Up @@ -70,7 +69,7 @@ def advect(Sol, flux, dt, elem, odd, ud, th, mpv, node, label, writer = None):

# Sol.rhoX += Sol.rho * mpv.HydroState.S0

set_explicit_boundary_data(Sol, elem, ud, th, mpv)
bdry.set_explicit_boundary_data(Sol, elem, ud, th, mpv)



Expand Down Expand Up @@ -108,11 +107,11 @@ def explicit_step_and_flux(Sol, flux, lmbda, elem, split_step, stage, ud, th, mp
:py:class:`management.variable.States`
`flux` data container.
"""
set_explicit_boundary_data(Sol, elem, ud, th, mpv, step=split_step)
bdry.set_explicit_boundary_data(Sol, elem, ud, th, mpv, step=split_step)

Lefts, Rights = recovery(Sol, flux, lmbda, ud, th, elem, split_step, tag)
Lefts, Rights = gd_recovery.do(Sol, flux, lmbda, ud, th, elem, split_step, tag)

# Lefts, Rights, u, Diffs, Ampls, Slopes = recovery(Sol, flux, lmbda, ud, th, elem, split_step, tag)
# Lefts, Rights, u, Diffs, Ampls, Slopes = gd_recovery.do(Sol, flux, lmbda, ud, th, elem, split_step, tag)

# if writer is not None:
# writer[0].write_all(Sol,mpv,elem,writer[1],th,str(writer[2])+'_split_%i' %split_step)
Expand Down Expand Up @@ -146,7 +145,7 @@ def explicit_step_and_flux(Sol, flux, lmbda, elem, split_step, stage, ud, th, mp
# skipped check_flux_bcs for now; first debug other functions
# check_flux_bcs(Lefts, Rights, elem, split_step, ud)

flux = hll_solver(flux,Lefts,Rights,Sol, lmbda, ud, th)
flux = gd_flux.hll_solver(flux,Lefts,Rights,Sol, lmbda, ud, th)

ndim = elem.ndim
left_idx, right_idx = [slice(None)] * ndim, [slice(None)] * ndim
Expand All @@ -162,7 +161,7 @@ def explicit_step_and_flux(Sol, flux, lmbda, elem, split_step, stage, ud, th, mp
Sol.rhoX += lmbda * (flux.rhoX[left_idx] - flux.rhoX[right_idx])
Sol.rhoY += lmbda * (flux.rhoY[left_idx] - flux.rhoY[right_idx])

set_explicit_boundary_data(Sol, elem, ud, th, mpv, step=split_step)
bdry.set_explicit_boundary_data(Sol, elem, ud, th, mpv, step=split_step)

if tag == 'rk':
return flux
Expand Down Expand Up @@ -234,7 +233,7 @@ def advect_rk(Sol, flux, dt, elem, odd, ud, th, mpv, node, label, writer = None)
updt = lmbda * (flux[dim].rhoX[left_idx] - flux[dim].rhoX[right_idx])
setattr(Sol, 'pwchi', updt)

set_explicit_boundary_data(Sol, elem, ud, th, mpv)
bdry.set_explicit_boundary_data(Sol, elem, ud, th, mpv)

# stage = 1
# for split in range(ndim):
Expand Down
10 changes: 5 additions & 5 deletions src/dycore/physics/gas_dynamics/numerical_flux.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import numpy as np
from scipy import signal
import scipy as sp

def recompute_advective_fluxes(flux, Sol, *args, **kwargs):
"""
Expand Down Expand Up @@ -30,19 +30,19 @@ def recompute_advective_fluxes(flux, Sol, *args, **kwargs):
kernel_w = np.swapaxes(kernel_u,2,0)

rhoYw = Sol.rhoY * Sol.rhow / Sol.rho
flux[2].rhoY[inner_idx] = signal.fftconvolve(rhoYw, kernel_w, mode='valid') / kernel_w.sum()
flux[2].rhoY[inner_idx] = sp.signal.fftconvolve(rhoYw, kernel_w, mode='valid') / kernel_w.sum()
else:
assert 0, "Unsupported dimension in recompute_advective_flux"

rhoYu = kwargs.get('u',Sol.rhoY * Sol.rhou / Sol.rho)

flux[0].rhoY[inner_idx] = np.moveaxis(signal.fftconvolve(rhoYu, kernel_u, mode='valid') / kernel_u.sum(), 0, -1)
flux[0].rhoY[inner_idx] = np.moveaxis(sp.signal.fftconvolve(rhoYu, kernel_u, mode='valid') / kernel_u.sum(), 0, -1)

rhoYv = kwargs.get('v',Sol.rhoY * Sol.rhov / Sol.rho)
if ndim == 2:
flux[1].rhoY[inner_idx] = signal.fftconvolve(rhoYv, kernel_v, mode='valid') / kernel_v.sum()
flux[1].rhoY[inner_idx] = sp.signal.fftconvolve(rhoYv, kernel_v, mode='valid') / kernel_v.sum()
elif ndim == 3:
flux[1].rhoY[inner_idx] = np.moveaxis(signal.fftconvolve(rhoYv, kernel_v, mode='valid') / kernel_v.sum(), -1,0)
flux[1].rhoY[inner_idx] = np.moveaxis(sp.signal.fftconvolve(rhoYv, kernel_v, mode='valid') / kernel_v.sum(), -1,0)
# flux[1].rhoY[...,-1] = 0.

def hll_solver(flux, Lefts, Rights, Sol, lmbda, ud, th):
Expand Down
Loading

0 comments on commit 6648cc5

Please sign in to comment.