Skip to content

Commit

Permalink
Merge pull request #27 from matt-frey/domain-averaged
Browse files Browse the repository at this point in the history
Calculate domain-averaged kinetic energy, potential energy and enstrophy
  • Loading branch information
matt-frey authored Dec 4, 2022
2 parents 6217fc6 + 4e56705 commit 7ce2372
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 44 deletions.
11 changes: 0 additions & 11 deletions plotting/plot_grid_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@
t, ke, en = np.loadtxt(os.path.join(fpath, 'beltrami_' + str(grid) + '_ecomp.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3

# calculate mean KE and mean EN
ke *= voli
en *= voli

#print("initial <KE>", ke[0])
#print("initial <EN>", en[0])

Expand Down Expand Up @@ -115,11 +109,6 @@
os.path.join(fpath, 'beltrami_' + str(grid) + '_vorticity.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3

# calculate mean KE and mean EN
en *= voli

maxen[i] = en.max()
vmax[i] = vormax.max()

Expand Down
6 changes: 0 additions & 6 deletions plotting/plot_ke_en_varying_grid_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
t, ke, en = np.loadtxt(os.path.join(fpath, 'beltrami_' + str(grid) + '_ecomp.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3

# calculate mean KE and mean EN
ke *= voli
en *= voli

#print("initial <KE>", ke[0])
#print("initial <EN>", en[0])

Expand Down
6 changes: 0 additions & 6 deletions plotting/plot_ke_en_varying_prediss.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
t, ke, en = np.loadtxt(os.path.join(fpath, 'beltrami_' + str(grid) + '_' + pred + '_ecomp.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3

# calculate mean KE and mean EN
ke *= voli
en *= voli

#print("initial <KE>", ke[0])
#print("initial <EN>", en[0])

Expand Down
3 changes: 0 additions & 3 deletions plotting/plot_ke_with_volume_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def add_inset(ax, bounds, t, ke, step):
t, ke, en = np.loadtxt(os.path.join(filepath, 'beltrami_' + str(grid) + '_ecomp.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3
ke = ke * voli

# calculate mean KE and mean EN
ax.plot(t, ke, color='blue', linewidth=1.0)
ax.set_xlabel(r'time, $t$')
Expand Down
5 changes: 0 additions & 5 deletions plotting/plot_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
_, vormax, _, _, _, _, _ = np.loadtxt(os.path.join(fpath, 'beltrami_' + str(grid) + '_vorticity.asc'),
skiprows=1, unpack=True)

voli = 1.0 / np.pi ** 3

# calculate mean KE and mean EN
en *= voli

maxen[i] = en.max()
vmax[i] = vormax.max()

Expand Down
12 changes: 6 additions & 6 deletions src/fields/field_diagnostics_netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ subroutine create_netcdf_field_stats_file(basename, overwrite)
call define_netcdf_dataset( &
ncid=ncid, &
name='ke', &
long_name='kinetic energy', &
long_name='domain-averaged kinetic energy', &
std_name='', &
unit='m^5/s^2', &
unit='m^2/s^2', &
dtype=NF90_DOUBLE, &
dimids=(/t_dim_id/), &
varid=ke_id)

call define_netcdf_dataset( &
ncid=ncid, &
name='en', &
long_name='enstrophy', &
long_name='domain-averaged enstrophy', &
std_name='', &
unit='m^3/s^2', &
unit='1/s^2', &
dtype=NF90_DOUBLE, &
dimids=(/t_dim_id/), &
varid=en_id)
Expand All @@ -99,9 +99,9 @@ subroutine create_netcdf_field_stats_file(basename, overwrite)
call define_netcdf_dataset( &
ncid=ncid, &
name='pe', &
long_name='potential energy', &
long_name='domain-averaged potential energy', &
std_name='', &
unit='m^5/s^2', &
unit='m^2/s^2', &
dtype=NF90_DOUBLE, &
dimids=(/t_dim_id/), &
varid=pe_id)
Expand Down
19 changes: 12 additions & 7 deletions src/fields/fields.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! and functions.
! =============================================================================
module fields
use parameters, only : nx, ny, nz, vcell, ncelli, dx, lower, extent, ngrid
use parameters, only : nx, ny, nz, vcell, ncelli, dx, lower, extent, ngrid, vdomaini
use constants, only : zero, f12, f14, one, two
use merge_sort
use inversion_utils, only : fftxys2p, diffx, diffy, central_diffz &
Expand Down Expand Up @@ -115,9 +115,13 @@ subroutine calculate_peref
zmean = zmean + gam * two * vcell
peref = peref - b(k) * vcell * zmean
enddo

! divide by domain volume to get domain-averaged peref
peref = peref * vdomaini
#endif
end subroutine calculate_peref

! domain-averaged potential energy
function get_potential_energy() result(pe)
double precision :: pe
#ifdef ENABLE_BUOYANCY
Expand All @@ -135,14 +139,13 @@ function get_potential_energy() result(pe)
enddo
enddo

pe = pe * vcell

pe = pe - peref
pe = pe * ncelli - peref
#else
pe = zero
#endif
end function get_potential_energy

! domain-averaged kinetic energy
function get_kinetic_energy() result(ke)
double precision :: ke

Expand All @@ -156,10 +159,11 @@ function get_kinetic_energy() result(ke)
+ vel(nz, :, :, 2) ** 2 &
+ vel(nz, :, :, 3) ** 2)

ke = ke * vcell
ke = ke * ncelli

end function get_kinetic_energy

! domain-averaged enstrophy
function get_enstrophy() result(en)
double precision :: en

Expand All @@ -173,11 +177,12 @@ function get_enstrophy() result(en)
+ vor(nz, :, :, 2) ** 2 &
+ vor(nz, :, :, 3) ** 2)

en = en * vcell
en = en * ncelli

end function get_enstrophy

#ifdef ENABLE_BUOYANCY
! domain-averaged grad(b) integral
function get_gradb_integral() result(enb)
double precision :: enb
double precision :: ds(0:nz, 0:nx-1, 0:ny-1)
Expand Down Expand Up @@ -207,7 +212,7 @@ function get_gradb_integral() result(enb)
+ f12 * sum(mag(0, :, :)) &
+ f12 * sum(mag(nz, :, :))

enb = enb * vcell
enb = enb * ncelli

end function get_gradb_integral
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/utils/parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module parameters
! domain size
double precision :: extent(3)

double precision :: vdomaini

! domain centre
double precision :: center(3)

Expand Down Expand Up @@ -87,6 +89,8 @@ subroutine update_parameters
endif
endif

vdomaini = one / product(extent)

vcell = product(dx)
vcelli = one / vcell

Expand Down

0 comments on commit 7ce2372

Please sign in to comment.