From c910b8f8b61d18eabf0c3fd1fa89c41e5d971773 Mon Sep 17 00:00:00 2001 From: Jeff Candy Date: Thu, 12 Sep 2024 19:44:37 -0700 Subject: [PATCH] Command-line time-averaging function --- cgyro/bin/cgyro_converge | 34 ++++++++++++++++++++++++++++++++++ f2py/pygacode/cgyro/data.py | 4 ++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 cgyro/bin/cgyro_converge diff --git a/cgyro/bin/cgyro_converge b/cgyro/bin/cgyro_converge new file mode 100755 index 000000000..3d547a423 --- /dev/null +++ b/cgyro/bin/cgyro_converge @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import numpy as np + +from pygacode.cgyro import data +from pygacode.gacodefuncs import * + +# read minimal data for setup +sim = data.cgyrodata('./',fast=True,silent=True) + +t = sim.t +ns = sim.n_species + +# read bin.cgyro.ky_flux +sim.getflux() + +# select field=0,moment=1, and sum over kx +field=0 ; moment=1 +y = np.sum(sim.ky_flux[:,moment,field,:,:],axis=1) + +# averaging (note that time_average function is fast/optimized) +w='0.5' +imin,imax=time_index(t,w) +for ispec in range(ns): + ave = time_average(y[ispec,:],t,imin,imax) + print(ave) + +w='0.75' +imin,imax=time_index(t,w) +for ispec in range(ns): + ave = time_average(y[ispec,:],t,imin,imax) + print(ave) + + diff --git a/f2py/pygacode/cgyro/data.py b/f2py/pygacode/cgyro/data.py index 05ad1d423..721a38b79 100644 --- a/f2py/pygacode/cgyro/data.py +++ b/f2py/pygacode/cgyro/data.py @@ -13,13 +13,13 @@ class cgyrodata: # constructor reads in basic (not all) simulation data - def __init__(self,sim_directory,silent=False): + def __init__(self,sim_directory,silent=False,fast=False): self.silent = silent self.dir = sim_directory hastime = self.gettime() self.getgrid() - if hastime: + if hastime and not fast: self.getdata() # standard routine to read binary or ASCII data