Commit 8ff4d526 authored by jclamber's avatar jclamber
Browse files

gas life in progress

git-svn-id: http://svn.oamp.fr/repos/uns_projects/trunk@90 f264a43e-d52d-4b82-913b-c2bd5215a18a
parent 57ca9f5d
...@@ -10,10 +10,36 @@ from py_unsio import * # import py_unsio package (UNSIO) ...@@ -10,10 +10,36 @@ from py_unsio import * # import py_unsio package (UNSIO)
import numpy as np # arrays are treated as numpy arrays import numpy as np # arrays are treated as numpy arrays
import math import math
import sys, getopt, os.path
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main
def main(argv):
prog = os.path.basename(argv.pop(0)) # program name
file=''
out="gas_life.txt" # output file name
try:
opts,args=getopt.getopt(argv,"hi:o:",["in=","out="])
except getopt.GetoptError:
printHelp(prog,file,out)
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printHelp(prog,file,out)
sys.exit()
elif opt in ("-i", "--in"):
file = arg
elif opt in ("-o", "--out"):
out = arg
compute(file,out)
# ----------------------------------------------------- # -----------------------------------------------------
# Def "run" is a function which loads Ids of particles # Def "run" is a function which loads Ids of particles
def run(comp): def run(comp,uns):
ok,time=uns.getValueF("time") ok,time=uns.getValueF("time")
...@@ -21,65 +47,84 @@ def run(comp): ...@@ -21,65 +47,84 @@ def run(comp):
#get Ids #get Ids
ok,id = uns.getArrayI(comp,"id") ok,id = uns.getArrayI(comp,"id")
#return time,id #return time,id(soretd),indexes
return time,id[id.argsort()] return time,id[id.argsort()],id.argsort()
#return status, pos,vel,mass,rho,hsml,ienerg,Id
# <codecell>
# ----------------------------------------------------- # -----------------------------------------------------
# M A I N P R O G R A M # M A I N P R O G R A M
# ----------------------------------------------------- # -----------------------------------------------------
simname="mdf001"
#simname="/home/jcl/list.test" def compute(simname,out):
components="gas" simname="mdf001"
times="all" #simname="/home/jcl/list.test"
verbose=False components="gas"
times="all"
# Create a UNSIO object verbose=False
uns = CunsIn(simname,components,times,verbose)
bits="I" # select properties, "" means all # Create a UNSIO object
uns = CunsIn(simname,components,times,verbose)
# <codecell> bits="I" # select properties, "" means all
comp="gas" # <codecell>
first=True sim_name=uns.getFileName()
outf="/home/jcl/gas_life.txt" # output file name
comp="gas"
fo = open(outf, "w") # open file for writing first=True
while (uns.nextFrame(bits)): # loop while there is something to read fo = open(out, "w") # open file for writing
time,ids=run(comp) # call "run" functionwhich returns time and array of Ids
print time while (uns.nextFrame(bits)): # loop while there is something to read
time,ids,index=run(comp,uns) # call "run" functionwhich returns time, array of Ids sorted, array of indexes sorted
if first: #The first time.... print time
time_last=time # save current time
ids_ref=np.copy(ids) # make a copy of ids array into ids_ref array if first: #The first time....
#print ids_ref time_last=time # save current time
first=False ids_ref=np.copy(ids) # make a copy of ids array into ids_ref array
else: #all the other time index_ref=np.copy(index) # make a copy of index array into index_ref array
#print ids #print ids_ref
print ids_ref.size,ids.size first=False
inter=np.in1d(ids_ref,ids) # compute intersection of ird_ref and new id array fo.write("%s\n"%(sim_name)) # write simulation nam or filename
#print inter else: #all the other time
idfinal=ids_ref[inter==False] # create an array if particles which have vanished into stars #print ids
#print "idfinal:",idfinal print "ref size :",ids_ref.size, index_ref.size
fo.write("%f %d\n"%(time_last,idfinal.size)) # write into file, time and #partciles which ended their gas life print "new size :",ids.size, index.size
fo.write("\n".join(map(str, idfinal))) # write into file, particles ID which ended their gas life inter=np.in1d(ids_ref,ids) # compute intersection of ird_ref and new id array
ids_ref=ids_ref[inter==True] # create new ID_ref, ie particles whixh are still gas #print inter
if (idfinal.size>1): idfinal=ids_ref[inter==False] # create an array if particles which have vanished into stars
fo.write("\n") #print "idfinal:",idfinal
print "time [%f] ids_ref [%d] end of life[%d]:"%(time_last,ids_ref.size,idfinal.size) fo.write("%f %d %s\n"%(time_last,idfinal.size,uns.getFileName())) # write into file, time and #partciles which ended their gas life
time_last=time # save last time #fo.write("\n".join(map(str, idfinal))) # write into file, particles ID which ended their gas life
for a,b in zip(index_ref[inter==False],idfinal):
fo.write("%d %d\n"%(a,b)) # write into file, particles index, particles ID which ended their gas life
ids_ref=ids_ref[inter==True] # create new ID_ref, ie particles IDs which are still gas
index_ref=index_ref[inter==True] # create new index_ref, ie particles indexes which are still gas
print "time [%f] ids_ref [%d] end of life[%d]:"%(time_last,ids_ref.size,idfinal.size)
time_last=time # save last time
fo.close() # close file fo.close() # close file
print "First must be false, here first = ", first print "First must be false, here first = ", first
print ids.size,ids_ref.size, idfinal.size, time_last
# <codecell>
print ids.size,ids_ref.size, idfinal.size, time_last def printHelp(prog,file,out):
help="""\
------------------------------------
Compute gas particles end of life
------------------------------------
Syntaxe: %s --in <inputfile> --out <outputfile>
Notes :
inputfile : simulation name or list of files [%s]
outfile : output file [%s]
"""
print help % (prog,file,out)
if __name__=='__main__':
main(sys.argv[0:])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment