Skip to content

Commit

Permalink
Merge pull request #10 from daviddritschel/add-timer
Browse files Browse the repository at this point in the history
Add timer module + update Python script
  • Loading branch information
matt-frey authored Feb 1, 2022
2 parents 1e6366f + 8f1555a commit 84f0c9f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
40 changes: 36 additions & 4 deletions scripts/write_h5.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#!/usr/bin/env python

import argparse
import h5py
import numpy as np
import os
from ps_config import nx, ny, ellx, ymin, ymax

ev_dir = ''
saveas = ''

try:
parser = argparse.ArgumentParser(description="Generate H5 output file.")

required = parser.add_argument_group('required arguments')

parser.add_argument("--evolution-dir",
type=str,
required=True,
help="evolution directory")

parser.add_argument("--saveas",
type=str,
required=True,
help="name of file to be saved")

args = parser.parse_args()

ev_dir = args.evolution_dir
saveas = args.saveas
except Exception as ex:
print(ex)

print("Parameters from parameters.f90:")
print("nx = ", nx)
print("ny = ", ny)
Expand All @@ -14,7 +40,7 @@

#-----------------------------------------------------------------
# Open ene.asc file in one directory to get time between frames:
in_file=open('evolution/ecomp.asc','r')
in_file=open(os.path.join(ev_dir, 'ecomp.asc'),'r')
time, ekin, epot, etot = np.loadtxt(in_file,dtype=float,unpack=True)
in_file.close()
nt = len(time)
Expand All @@ -26,9 +52,13 @@

N = nx * (ny + 1)

h5file = h5py.File('ps_fields.hdf5', 'w')
h5file = h5py.File(saveas + '.hdf5', 'w')

dt = h5py.string_dtype('ascii', 6)

h5file.attrs['nsteps'] = nt
h5file.attrs.create("output_type", r"fields", dtype=dt, shape=1)

h5file.attrs['nsteps'] = [nt]

box = h5file.create_group('box')
box.attrs['extent'] = (ellx, ymax - ymin)
Expand All @@ -38,8 +68,10 @@
for frame in range(nt):
group = h5file.create_group('step#' + str(frame).zfill(10))

group.attrs['t'] = time[frame]

for field in ['bb', 'zz']:
fname = os.path.join('evolution', field + '.r4')
fname = os.path.join(ev_dir, field + '.r4')

in_file = open(fname,'r')
raw_array = np.fromfile(in_file,dtype=np.float32)
Expand Down
5 changes: 3 additions & 2 deletions src/constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module constants
!Include all modifiable parameters for use below:
use parameters

! Contains all the non-modifiable parameters as well as all
! Contains all the non-modifiable parameters as well as all
! quantities which never change throughout a simulation
! for the suite of ps f90 codes.

Expand All @@ -13,13 +13,14 @@ module constants
!Grid dimensions used in write statements:
integer,parameter:: ngridp=nx*(ny+1),nbytes=4*(ngridp+1)

!Generic double precision numerical constants:
!Generic double precision numerical constants:
double precision,parameter:: zero=0.d0,one=1.d0,two=2.d0
double precision,parameter:: three=3.d0,four=4.d0
double precision,parameter:: f12=one/two,f14=one/four
double precision,parameter:: f13=one/three,f23=two/three
double precision,parameter:: pi=3.14159265358979d0,twopi=two*pi
double precision,parameter:: small=1.d-12
double precision,parameter:: hundred=100.0d0

!Domain lengths and inverses:
double precision,parameter:: xmax=ellx/two,xmin=-xmax
Expand Down
5 changes: 3 additions & 2 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ sourcedir = .
installdir = ../bin

# Set main source and object files:
sources = $(sourcedir)/parameters.f90 $(sourcedir)/constants.f90 $(sourcedir)/spectral.f90 #Main f90 sources
objects = parameters.o constants.o spectral.o #Main .o files
sources = $(sourcedir)/parameters.f90 $(sourcedir)/constants.f90 $(sourcedir)/timer.f90 $(sourcedir)/spectral.f90
#Main f90 sources
objects = parameters.o constants.o timer.o spectral.o #Main .o files

# Set location of fft library:
fft_lib = stafft/stafft.f90 stafft/sta2dfft.f90
Expand Down
13 changes: 13 additions & 0 deletions src/strat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ program strat
!Import contants, parameters and common arrays:
use constants
use spectral
use timer

implicit none

Expand All @@ -53,18 +54,27 @@ program strat
!Logical for use in saving data:
logical:: gsave

integer :: ps_timer, advance_timer

call register_timer('ps', ps_timer)
call register_timer('advance', advance_timer)

call start_timer(ps_timer)

!---------------------------------------------------------
!Define fixed arrays and constants and read initial data:
call initialise

!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
call start_timer(advance_timer)
!Start the time loop:
do while (t < tsim)

!Advect flow from time t to t + dt:
call advance

enddo
call stop_timer(advance_timer)
!End of time loop
!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Expand All @@ -78,6 +88,9 @@ program strat
!Close all files:
call finalise

call stop_timer(ps_timer)

call print_timer

!Internal subroutine definitions (inherit global variables):
!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Expand Down

0 comments on commit 84f0c9f

Please sign in to comment.