Commit 168fac45 authored by Roland Haas's avatar Roland Haas
Browse files

POWER: rework POWER method to take desired radii and modes as arguments

parent db00a660
...@@ -230,6 +230,22 @@ def angular_momentum(x, q, m, chi1, chi2, LInitNR): ...@@ -230,6 +230,22 @@ def angular_momentum(x, q, m, chi1, chi2, LInitNR):
* x**3.)) * x**3.))
return l - LInitNR return l - LInitNR
def getADMMassFromTwoPunctureBBH(meta_filename):
"""
Determine cutoff frequency of simulation
meta_filename = path to TwoPunctures.bbh
return = initial ADM mass of system
"""
config = configparser.ConfigParser()
config.read(meta_filename)
ADMmass = float(config['metadata']['initial-ADM-energy'])
return ADMmass
def getCutoffFrequencyFromTwoPuncturesBBH(meta_filename): def getCutoffFrequencyFromTwoPuncturesBBH(meta_filename):
""" """
Determine cutoff frequency of simulation Determine cutoff frequency of simulation
...@@ -289,66 +305,46 @@ def getCutoffFrequencyFromTwoPuncturesBBH(meta_filename): ...@@ -289,66 +305,46 @@ def getCutoffFrequencyFromTwoPuncturesBBH(meta_filename):
omCutoff = 0.75 * omGWPN omCutoff = 0.75 * omGWPN
return omCutoff return omCutoff
def getModesInFile(sim_path):
"""
Find all modes and radii in file.
# ----------------------------------------------------------------------------- sim_path = path to simulation main directory
# POWER Method return = radii, modes
# ----------------------------------------------------------------------------- """
def POWER(argv, args):
#Initialize simulation data fn = sorted(glob.glob(sim_path+"/output-????/*/mp_[Pp]si4.h5"))[0]
with h5py.File(fn, "r") as fh:
radii = set()
modes = set()
for dset in fh:
# TODO: extend Multipole to save the radii as attributes and/or
# use a group structure in the hdf5 file
m = re.match(r'l(\d*)_m(-?\d*)_r(\d*\.\d)', dset)
if m:
radius = float(m.group(3))
mode = (int(m.group(1)), int(m.group(2)))
modes.add(mode)
radii.add(radius)
modes = sorted(modes)
radii = sorted(radii)
return radii, modes
if(len(argv) < 2):
print("Pass in the number n of the n innermost detector radii to be used in the extrapolation (optional, default=all) and the simulation folders (e.g., ./power.py 6 ./simulations/J0040_N40 /path/to/my_simulation_folder).")
sys.exit()
elif(os.path.isdir(argv[2])):
radiiUsedForExtrapolation = 7 #use the first n radii available i.e. no radii specified, defaults to 7
paths = argv[2:]
elif(not os.path.isdir(argv[2])): # -----------------------------------------------------------------------------
radiiUsedForExtrapolation = int(argv[2]) #use the first n radii available # POWER Method
if(radiiUsedForExtrapolation < 1 or radiiUsedForExtrapolation > 7): # -----------------------------------------------------------------------------
print("Invalid specified radii number")
sys.exit()
paths = argv[4:]
for sim_path in paths: def POWER(sim_path, radii, modes):
main_dir = sim_path main_dir = sim_path
sim = os.path.split(sim_path)[-1] sim = os.path.split(sim_path)[-1]
simdirs = main_dir+"/output-????/%s/" % (sim) simdirs = main_dir+"/output-????/%s/" % (sim)
f0 = getCutoffFrequencyFromTwoPuncturesBBH(main_dir+"/output-0000/%s/TwoPunctures.bbh" % (sim)) f0 = getCutoffFrequencyFromTwoPuncturesBBH(main_dir+"/output-0000/%s/TwoPunctures.bbh" % (sim))
#Get simulation total mass #Get simulation total mass
ADMMass = None ADMMass = getADMMassFromTwoPunctureBBH(main_dir+"/output-0000/%s/TwoPunctures.bbh" % (sim))
two_punctures_files = sorted(glob.glob(main_dir+"/output-????/%s/TwoPunctures.bbh" % (sim)))
out_files = sorted(glob.glob(main_dir+"/output-????/%s.out" % (sim)))
par_files = sorted(glob.glob(main_dir+"/output-????/%s.par" % (sim)))
if(two_punctures_files):
two_punctures_file = two_punctures_files[0]
with open(two_punctures_file) as file:
contents = file.readlines()
for line in contents:
line_elems = line.split(" ")
if(line_elems[0] == "initial-ADM-energy"):
ADMMass = float(line_elems[-1])
elif(out_files):
out_file = out_files[0]
with open(out_file) as file:
contents = file.readlines()
for line in contents:
m = re.match("INFO \(TwoPunctures\): The total ADM mass is (.*)", line)
if(m):
ADMMass = float(m.group(1))
elif(par_files):
par_file = par_files[0]
print("Not yet implemented")
raise ValueError
else:
print("Cannot determine ADM mass")
raise ValueError
#Create data directories #Create data directories
main_directory = "Extrapolated_Strain" main_directory = "Extrapolated_Strain"
...@@ -358,16 +354,11 @@ def POWER(argv, args): ...@@ -358,16 +354,11 @@ def POWER(argv, args):
if not os.path.exists(sim_dir): if not os.path.exists(sim_dir):
os.makedirs(sim_dir) os.makedirs(sim_dir)
# get translation table from (mode, radius) to dataset name
# TODO: this ought to be handled differently
# TODO: fix this. It will fail if output-0000 does not contain any mp dsets = {}
# output and also will open the output files multiple times fn = sorted(glob.glob(sim_path+"/output-????/*/mp_[Pp]si4.h5"))[0]
fn = sorted(glob.glob(simdirs+"mp_psi4.h5"))[0]
with h5py.File(fn, "r") as fh: with h5py.File(fn, "r") as fh:
# get all radii
radii = set()
modes = set()
dsets = dict()
for dset in fh: for dset in fh:
# TODO: extend Multipole to save the radii as attributes and/or # TODO: extend Multipole to save the radii as attributes and/or
# use a group structure in the hdf5 file # use a group structure in the hdf5 file
...@@ -375,12 +366,10 @@ def POWER(argv, args): ...@@ -375,12 +366,10 @@ def POWER(argv, args):
if m: if m:
radius = float(m.group(3)) radius = float(m.group(3))
mode = (int(m.group(1)), int(m.group(2))) mode = (int(m.group(1)), int(m.group(2)))
modes.add(mode)
radii.add(radius)
dsets[(radius, mode)] = dset dsets[(radius, mode)] = dset
modes = sorted(modes)
radii = sorted(radii)
# FIXME: do not hard code
radiiUsedForExtrapolation = 7
#Get Psi4 #Get Psi4
...@@ -830,7 +819,8 @@ args = parser.parse_args() ...@@ -830,7 +819,8 @@ args = parser.parse_args()
if args.method == "POWER": if args.method == "POWER":
print("Extrapolating with POWER method...") print("Extrapolating with POWER method...")
POWER(sys.argv, args) radii, modes = getModesInFile(args.path)
POWER(args.path, radii, modes)
......
Supports Markdown
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