From 8f1555a7316be577d932f01f353bdfd59ebcd9cc Mon Sep 17 00:00:00 2001 From: Matthias Frey Date: Tue, 1 Feb 2022 15:15:51 +0000 Subject: [PATCH] add timer module + update Python script --- scripts/write_h5.py | 40 ++++++++++++++++++++++++++++++++++++---- src/constants.f90 | 5 +++-- src/makefile | 5 +++-- src/strat.f90 | 13 +++++++++++++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/scripts/write_h5.py b/scripts/write_h5.py index d16ca28..5cbdca7 100755 --- a/scripts/write_h5.py +++ b/scripts/write_h5.py @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/constants.f90 b/src/constants.f90 index 0dc4db6..e0626ad 100644 --- a/src/constants.f90 +++ b/src/constants.f90 @@ -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. @@ -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 diff --git a/src/makefile b/src/makefile index 8cabe10..1cb2d06 100644 --- a/src/makefile +++ b/src/makefile @@ -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 diff --git a/src/strat.f90 b/src/strat.f90 index bde6521..3a1e9cc 100644 --- a/src/strat.f90 +++ b/src/strat.f90 @@ -31,6 +31,7 @@ program strat !Import contants, parameters and common arrays: use constants use spectral +use timer implicit none @@ -53,11 +54,19 @@ 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) @@ -65,6 +74,7 @@ program strat call advance enddo +call stop_timer(advance_timer) !End of time loop !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -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): !::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::