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)
import numpy as np # arrays are treated as numpy arrays
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(comp):
def run(comp,uns):
ok,time=uns.getValueF("time")
......@@ -21,65 +47,84 @@ def run(comp):
#get Ids
ok,id = uns.getArrayI(comp,"id")
#return time,id
return time,id[id.argsort()]
#return status, pos,vel,mass,rho,hsml,ienerg,Id
# <codecell>
#return time,id(soretd),indexes
return time,id[id.argsort()],id.argsort()
# -----------------------------------------------------
# M A I N P R O G R A M
# -----------------------------------------------------
simname="mdf001"
#simname="/home/jcl/list.test"
components="gas"
times="all"
verbose=False
# Create a UNSIO object
uns = CunsIn(simname,components,times,verbose)
bits="I" # select properties, "" means all
# <codecell>
comp="gas"
first=True
outf="/home/jcl/gas_life.txt" # output file name
fo = open(outf, "w") # open file for writing
while (uns.nextFrame(bits)): # loop while there is something to read
time,ids=run(comp) # call "run" functionwhich returns time and array of Ids
print time
if first: #The first time....
time_last=time # save current time
ids_ref=np.copy(ids) # make a copy of ids array into ids_ref array
#print ids_ref
first=False
else: #all the other time
#print ids
print ids_ref.size,ids.size
inter=np.in1d(ids_ref,ids) # compute intersection of ird_ref and new id array
#print inter
idfinal=ids_ref[inter==False] # create an array if particles which have vanished into stars
#print "idfinal:",idfinal
fo.write("%f %d\n"%(time_last,idfinal.size)) # write into file, time and #partciles which ended their gas life
fo.write("\n".join(map(str, idfinal))) # write into file, particles ID which ended their gas life
ids_ref=ids_ref[inter==True] # create new ID_ref, ie particles whixh are still gas
if (idfinal.size>1):
fo.write("\n")
print "time [%f] ids_ref [%d] end of life[%d]:"%(time_last,ids_ref.size,idfinal.size)
time_last=time # save last time
def compute(simname,out):
simname="mdf001"
#simname="/home/jcl/list.test"
components="gas"
times="all"
verbose=False
# Create a UNSIO object
uns = CunsIn(simname,components,times,verbose)
bits="I" # select properties, "" means all
# <codecell>
sim_name=uns.getFileName()
comp="gas"
first=True
fo = open(out, "w") # open file for writing
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
print time
if first: #The first time....
time_last=time # save current time
ids_ref=np.copy(ids) # make a copy of ids array into ids_ref array
index_ref=np.copy(index) # make a copy of index array into index_ref array
#print ids_ref
first=False
fo.write("%s\n"%(sim_name)) # write simulation nam or filename
else: #all the other time
#print ids
print "ref size :",ids_ref.size, index_ref.size
print "new size :",ids.size, index.size
inter=np.in1d(ids_ref,ids) # compute intersection of ird_ref and new id array
#print inter
idfinal=ids_ref[inter==False] # create an array if particles which have vanished into stars
#print "idfinal:",idfinal
fo.write("%f %d %s\n"%(time_last,idfinal.size,uns.getFileName())) # write into file, time and #partciles which ended their gas life
#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