diff --git a/pyscripts/double.py b/pyscripts/double.py deleted file mode 100755 index d9c2be74..00000000 --- a/pyscripts/double.py +++ /dev/null @@ -1,24 +0,0 @@ -from uedge import * - -def uedouble(): - com.nxleg=2*com.nxleg - com.nxcore=2*com.nxcore - com.nycore=2*com.nycore - com.nysol=2*com.nysol - if com.nxomit > 0: - if com.geometry=="dnbot": - com.nxomit = com.nxleg[0,0]+com.nxcore[0,0] + 2*com.nxxptxx + 1 - else: - com.nxomit=2*(com.nxomit-2*com.nxxptxx) + 2*com.nxxpt # assumes com.nxomit removes 1/2 SOL - if com.nyomitmx == 1: com.nysol = 1 - if grd.kxmesh == 4: - dxgasold=grd.dxgas - alfxold=grd.alfx - grd.alfx=alfxold/2. - grd.dxgas=dxgasold*(exp(grd.alfx)-1)/(exp(alfxold)-1) - grd.nxgas=2*grd.nxgas - bbb.restart=1 - bbb.newgeo=1 - bbb.gengrid=1 - bbb.isnintp=1 - grd.ixdstar = com.nxcore[0,1]+1 diff --git a/pyscripts/osfun.py b/pyscripts/osfun.py deleted file mode 100644 index 0264e1f0..00000000 --- a/pyscripts/osfun.py +++ /dev/null @@ -1,17 +0,0 @@ -def date(): - os.system("date") - -def ls(opts=""): - os.system("ls " + opts) - -def more(fname): - os.system("more " + fname) - -def pwd(): - os.system("pwd") - -def cp(opts=""): - os.system("cp " + opts) - -def mv(opts=""): - os.system("mv " + opts) diff --git a/pyscripts/paws.py b/pyscripts/paws.py deleted file mode 100644 index 72837492..00000000 --- a/pyscripts/paws.py +++ /dev/null @@ -1,2 +0,0 @@ -def paws(): - programPause = raw_input("Press the key to continue...") diff --git a/pyscripts/rdcontdt.py b/pyscripts/rdcontdt.py deleted file mode 100755 index 79773ad3..00000000 --- a/pyscripts/rdcontdt.py +++ /dev/null @@ -1,251 +0,0 @@ -# This file runs a time-dependent case using dtreal. First, obtain a converged -# solution for a (usually small) dtreal; xuedge must report iterm=1 at the end. -# Then adjust control parameters in rdinitdt; read this file, which reads rdinitdt. -# If a mistake is made, to restart this file without a Jacobian evaluation, -# be sure to reset iterm=1 (=> last step was successful) - -# IMPORT UEDGE (assuming starting from ipython before any imports) -from .uedge import * -from .ruthere import * -from .uexec import * -from numpy import zeros - -# IMPORT HDF5 routines for saving solutions below -from .hdf5 import * - -# INITIALIZE PARAMS -- SHOULD BE DONE IN MASTER SCRIPT OR TERMINAL SESSION -# BEFORE INVOKING THIS SCRIPT -uexec("uedge.rdinitdt",returns=globals()) -no = 0;yes = 1 -echo = no - -# Set precisions of floating point output -###import print_options -###print_options.set_float_precision(4) - -# Check if successful time-step exists (bbb.iterm=1) -if (bbb.iterm == 1): - print("Initial successful time-step exists") - bbb.dtreal = bbb.dtreal*bbb.mult_dt #compensates dtreal divided by mult_dt below -else: - print("*---------------------------------------------------------*") - print("Need to take initial step with Jacobian; trying to do here") - print("*---------------------------------------------------------*") - bbb.icntnunk = 0 - bbb.exmain() - ruthere() - bbb.dtreal = bbb.dtreal*bbb.mult_dt #compensates dtreal divided by mult_dt below - -if (bbb.iterm != 1): - print("*--------------------------------------------------------------*") - print("Error: converge an initial time-step first; then retry rdcontdt") - print("*--------------------------------------------------------------*") - exit() - -nx=com.nx;ny=com.ny;nisp=com.nisp;ngsp=com.ngsp;numvar=bbb.numvar -isteon=bbb.isteon -if (i_stor==0): - ni_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1,nisp),"d") # set time storage arrays - up_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1,nisp),"d") - te_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1),"d") - ti_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1),"d") - ng_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1,ngsp),"d") - tg_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1,ngsp),"d") - phi_stor = zeros((bbb.n_stor,nx+1+1,ny+1+1),"d") - tim_stor = zeros((bbb.n_stor),"d") - dtreal_stor = zeros((bbb.n_stor),"d") - nfe_stor = zeros((bbb.n_stor),"l") - dt_stor = (bbb.tstor_e - bbb.tstor_s)/(bbb.n_stor - 1) - -i_stor = max(i_stor,1) # set counter for storage arrays -bbb.dt_tot = max(bbb.dt_tot,0.) -nfe_tot = max(nfe_tot,0) -deldt_0 = bbb.deldt -isdtsf_sav = bbb.isdtsfscal - -if (bbb.ipt==1 and bbb.isteon==1): # set ipt to te(nx,iysptrx+1) if no user value - ipt = bbb.idxte[nx-1,com.iysptrx] #note: ipt is local, bbb.ipt global - -bbb.irev = -1 # forces second branch of irev in ii1 loop below -if (bbb.iterm == 1): # successful initial run with dtreal - bbb.dtreal = bbb.dtreal/bbb.mult_dt # gives same dtreal after irev loop -else: # unsuccessful initial run; reduce dtreal - bbb.dtreal = bbb.dtreal/(3*bbb.mult_dt) # causes dt=dt/mult_dt after irev loop - -if (bbb.initjac == 0): bbb.newgeo=0 -dtreal_sav = bbb.dtreal -bbb.itermx = bbb.itermxrdc -bbb.dtreal = bbb.dtreal/bbb.mult_dt #adjust for mult. to follow; mult_dt in rdinitdt -bbb.dtphi = bbb.rdtphidtr*bbb.dtreal -neq=bbb.neq -svrpkg=bbb.svrpkg.tostring().strip() -# -bbb.ylodt = bbb.yl -bbb.pandf1 (-1, -1, 0, bbb.neq, 1., bbb.yl, bbb.yldot) -fnrm_old = sqrt(sum((bbb.yldot[0:neq]*bbb.sfscal[0:neq])**2)) -if (bbb.initjac == 1): fnrm_old=1.e20 -print("initial fnrm =",fnrm_old) - -for ii1 in range( 1, bbb.ii1max+1): - if (bbb.ismfnkauto==1): bbb.mfnksol = 3 - # adjust the time-step - if (bbb.irev == 0): - # Only used after a dt reduc. success. completes loop ii2 for fixed dt - bbb.dtreal = min(3*bbb.dtreal,bbb.t_stop) #first move forward after reduction - bbb.dtphi = bbb.rdtphidtr*bbb.dtreal - if (bbb.ismfnkauto==1 and bbb.dtreal > bbb.dtmfnk3): bbb.mfnksol = -3 - bbb.deldt = 3*bbb.deldt - else: - # either increase or decrease dtreal; depends on mult_dt - bbb.dtreal = min(bbb.mult_dt*bbb.dtreal,bbb.t_stop) - bbb.dtphi = bbb.rdtphidtr*bbb.dtreal - if (bbb.ismfnkauto==1 and bbb.dtreal > bbb.dtmfnk3): bbb.mfnksol = -3 - bbb.deldt = bbb.mult_dt*bbb.deldt - - bbb.dtreal = min(bbb.dtreal,bbb.dt_max) - bbb.dtphi = bbb.rdtphidtr*bbb.dtreal - if (bbb.ismfnkauto==1 and bbb.dtreal > bbb.dtmfnk3): bbb.mfnksol = -3 - bbb.deldt = min(bbb.deldt,deldt_0) - bbb.deldt = max(bbb.deldt,bbb.deldt_min) - nsteps_nk=1 - print('--------------------------------------------------------------------') - print('--------------------------------------------------------------------') - print(' ') - print('*** Number time-step changes = ',ii1,' New time-step = ', bbb.dtreal) - print('--------------------------------------------------------------------') - - bbb.itermx = bbb.itermxrdc - if (ii1>1 or bbb.initjac==1): # first time calc Jac if initjac=1 - if (bbb.irev == 1): # decrease in bbb.dtreal - if (bbb.numrev < bbb.numrevjmax and \ - bbb.numrfcum < bbb.numrevjmax+bbb.numfwdjmax): #dont recom bbb.jac - bbb.icntnunk = 1 - bbb.numrfcum = bbb.numrfcum + 1 - else: # force bbb.jac calc, reset numrev - bbb.icntnunk = 0 - bbb.numrev = -1 # yields api.zero in next statement - bbb.numrfcum = 0 - bbb.numrev = bbb.numrev + 1 - bbb.numfwd = 0 - else: # increase in bbb.dtreal - if (bbb.numfwd < bbb.numfwdjmax and \ - bbb.numrfcum < bbb.numrevjmax+bbb.numfwdjmax): #dont recomp bbb.jac - bbb.icntnunk = 1 - bbb.numrfcum = bbb.numrfcum + 1 - else: - bbb.icntnunk = 0 #recompute jacobian for increase dt - bbb.numfwd = -1 - bbb.numrfcum = 0 - bbb.numfwd = bbb.numfwd + 1 - bbb.numrev = 0 #bbb.restart counter for dt reversals - bbb.isdtsfscal = isdtsf_sav - bbb.ftol = min(bbb.ftol_dt, 0.01*fnrm_old) - bbb.ftol = max(bbb.ftol, bbb.ftol_min) - exmain() # take a single step at the present bbb.dtreal - ruthere() - if (bbb.iterm == 1): - bbb.dt_tot = bbb.dt_tot + bbb.dtreal - nfe_tot = nfe_tot + bbb.nfe[0,0] - bbb.ylodt = bbb.yl - bbb.pandf1 (-1, -1, 0, bbb.neq, 1., bbb.yl, bbb.yldot) - fnrm_old = sqrt(sum((bbb.yldot[0:neq-1]*bbb.sfscal[0:neq-1])**2)) - if (bbb.dt_tot>=0.9999999*bbb.t_stop or fnrm_old= t_stop **') - print('*****************************************************') - break - - bbb.icntnunk = 1 - bbb.isdtsfscal = 0 - for ii2 in range( 1, bbb.ii2max+1): #take ii2max steps at the present time-step - if (bbb.iterm == 1): - bbb.itermx = bbb.itermxrdc - bbb.ftol = min(bbb.ftol_dt, 0.01*fnrm_old) - bbb.ftol = max(bbb.ftol, bbb.ftol_min) - bbb.exmain() - ruthere() - if (bbb.iterm == 1): - bbb.ylodt = bbb.yl - bbb.pandf1 (-1, -1, 0, bbb.neq, 1., bbb.yl, bbb.yldot) - fnrm_old = sqrt(sum((bbb.yldot[0:neq-1]*bbb.sfscal[0:neq-1])**2)) - print("Total time = ",bbb.dt_tot,"; Timestep = ",bbb.dtreal) - print("variable index ipt = ",ipt, " bbb.yl[ipt] = ",bbb.yl[ipt]) - dtreal_sav = bbb.dtreal - bbb.dt_tot = bbb.dt_tot + bbb.dtreal - nfe_tot = nfe_tot + bbb.nfe[0,0] - hdf5_save(savefn) - if (bbb.dt_tot>=0.999999999999*bbb.t_stop or fnrm_old= t_stop **') - print('*****************************************************') - break - print(" ") -## Store variables if a storage time has been crossed - if (bbb.dt_tot >= dt_stor*i_stor and i_stor<=bbb.n_stor): - i_stor1 = i_stor-1 - ni_stor[i_stor1,:,:,:] = ni - up_stor[i_stor1,:,:,:] = up - te_stor[i_stor1,:,:] = te - ti_stor1[i_stor1,:,:] = ti - ng_stor[i_stor1,:,:,:] = ng - phi_stor1[i_stor1,:,:] = phi - tim_stor[i_stor1] = bbb.dt_tot - nfe_stor[i_stor1] = nfe_tot - dtreal_stor[i_stor1] = bbb.dtreal - i_stor = i_stor + 1 - ## End of storage section - - if (bbb.dt_tot>=bbb.t_stop or fnrm_old ydmax): - itrouble=ii - print("** Fortran index of trouble making equation is:") - print(itrouble+1) - break - print("** Number of variables is:") - print("numvar = ", numvar) - print(" ") - iv_t = (itrouble).__mod__(numvar) + 1 - print("** Troublemaker equation is:") - print("iv_t = ",iv_t) - print(" ") - print("** Troublemaker cell (ix,iy) is:") - print(bbb.igyl[itrouble,]) - print(" ") - print("** Timestep for troublemaker equation:") - print(bbb.dtuse[itrouble]) - print(" ") - print("** yl for troublemaker equation:") - print(bbb.yl[itrouble]) - print(" ") - echo=oldecho - ######## end of idtroub script ############################## - - if (bbb.dtreal < bbb.dt_kill): - print(' ') - print('*************************************') - print('** FAILURE: time-step < dt_kill **') - print('*************************************') - break - bbb.irev = 1 - print('*** Converg. fails for bbb.dtreal; reduce time-step by 3, try again') - print('----------------------------------------------------------------- ') - bbb.dtreal = bbb.dtreal/(3*bbb.mult_dt) - bbb.dtphi = bbb.rdtphidtr*bbb.dtreal - if (bbb.ismfnkauto==1 and bbb.dtreal > bbb.dtmfnk3): bbb.mfnksol = -3 - bbb.deldt = bbb.deldt/(3*bbb.mult_dt) - bbb.iterm = 1 -echo = yes diff --git a/pyscripts/rdinitdt.py b/pyscripts/rdinitdt.py deleted file mode 100755 index db60867c..00000000 --- a/pyscripts/rdinitdt.py +++ /dev/null @@ -1,37 +0,0 @@ -# Setup file to run time-dependently using dtreal -# Change dtreal for starting dt and savefname to change pfb file name -# Once variables are set, read rdrundt to execute a time-dependent run -from uedge import * - -i_stor = 0 -nfe_tot = 0 -savefn = "savedt.hdf5" # name of hdf5 savefile written every timestep - -bbb.rdtphidtr = 1e20 # ratio dtphi/dtreal -bbb.ismfnkauto = 1 # if =1, mfnksol=3 for dtreal 0 -bbb.initjac = 0 # if=1, calc initial Jac upon reading rdcontdt -bbb.numrevjmax = 2 # number of dt reductions before Jac recalculated -bbb.numfwdjmax = 1 # number of dt increases before Jac recalculated -###bbb.ismmaxuc = 1 # =1 for intern calc mmaxu; =0,set mmaxu & dont chng -bbb.irev = -1 # flag to allow reduced dt advance after cutback -bbb.rlx = 0.9 # max. change in variable at each linear iteration -bbb.itermx = 7 # max. number of linear iterations allowed -bbb.tstor_s = 1e-5 # beginning time for storing solution -bbb.tstor_e = 1e-3 # ending time for storing solution -bbb.n_stor = 0 # number of linearly spaced storage points -bbb.ipt = 1 # index of variable; value printed at step - # if ipt not reset from unity, ipt=idxte(nx,iysptrx+1) - diff --git a/pyscripts/ruthere.py b/pyscripts/ruthere.py deleted file mode 100755 index 7b42c2d3..00000000 --- a/pyscripts/ruthere.py +++ /dev/null @@ -1,66 +0,0 @@ -from numpy import * -import time -import signal -import sys - -############################################################################# -# From Dave Grote: -# --- Setup signal handler to capture Control-C -# --- To use, first call arminterrupt(). Then at the place where the interrupt -# --- is allowed, call ruthere(). This will raise a KeyboardInterrupt if -# --- Control-C had been pressed. -# --- When a interrupt request is received, all this handler does is set a -# --- flag to that effect. Then, a subsequent call to ruthere will check -# --- that flag, and if set, raise an exception. This allows a graceful -# --- stop with the current time step completed. -# --- Set the following two in case ruthere is called before arminterrupt. -_defaultcontrolC = signal.getsignal(signal.SIGINT) -_controlCrecieved = False -savetracebacklimit = 0 - -def _handlecontrolC(signum, frame): - global _controlCrecieved - _controlCrecieved = True - -def ruthere(reset=True): - """ -Checks if an interrupt was requested (usually control-C). If so, then raise -an exception. If reset is True, restore the original interrupt handler so that the -calling code does not have to, and so that, if there is an exception, it gets -restored (since the calling code is not returned to). - """ - global _controlCrecieved - global _defaultcontrolC - global savetracebacklimit - if _controlCrecieved: - if reset: - signal.signal(signal.SIGINT, _defaultcontrolC) - _controlCrecieved = False - raise KeyboardInterrupt("Interrupt requested") - -def arminterrupt(): - global _controlCrecieved - global _defaultcontrolC - global savetracebacklimit - _controlCrecieved = False - _defaultcontrolC = signal.getsignal(signal.SIGINT) - try: - savetracebacklimit = sys.tracebacklimit - except: - savetracebacklimit = None - signal.signal(signal.SIGINT, _handlecontrolC) - sys.tracebacklimit = 0 - -def disarminterrupt(): - global _defaultcontrolC - global savetracebacklimit - signal.signal(signal.SIGINT, _defaultcontrolC) - sys.tracebacklimit = savetracebacklimit - - -#========================================================================= - -arminterrupt() - - - diff --git a/pyscripts/uexec.py b/pyscripts/uexec.py deleted file mode 100755 index e5e51522..00000000 --- a/pyscripts/uexec.py +++ /dev/null @@ -1,30 +0,0 @@ - - -import sys -try: - from importlib import reload,import_module -except: - from importlib import import_module - - -import builtins - - -def uexec(mname,returns=globals()): - if mname in sys.modules: - _m = reload(sys.modules[mname]) - else: - _m = import_module(mname) - - # is there an __all__? if so respect it - if "__all__" in _m.__dict__: - names = _m.__dict__["__all__"] - else: - # otherwise we import all names that don't begin with _ - names = [x for x in _m.__dict__ if not x.startswith("_")] - - # now drag them in - for k in names: - #print k,getattr(_m,k) - returns[k] = getattr(_m,k) -