[Yt-svn] yt: 2 new changesets
hg at spacepope.org
hg at spacepope.org
Wed Jul 28 09:55:34 PDT 2010
hg Repository: yt
details: yt/rev/39ce53f35dd4
changeset: 1888:39ce53f35dd4
user: Matthew Turk <matthewturk at gmail.com>
date:
Wed Jul 28 08:37:05 2010 -0700
description:
Added FLASH structures, most/all of which were copied from Chombo
hg Repository: yt
details: yt/rev/5fa444f2d48d
changeset: 1889:5fa444f2d48d
user: Matthew Turk <matthewturk at gmail.com>
date:
Wed Jul 28 09:55:29 2010 -0700
description:
FLASH works in a primitive fashion; slices work and the grids exist
diffstat:
yt/lagos/BaseGridType.py | 10 +++++
yt/lagos/DataReadingFuncs.py | 17 ++++++++
yt/lagos/HierarchyType.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++
yt/lagos/OutputTypes.py | 82 +++++++++++++++++++++++++++++++++++++++++
yt/lagos/__init__.py | 1 +
yt/mods.py | 8 ++-
6 files changed, 209 insertions(+), 3 deletions(-)
diffs (265 lines):
diff -r 95375c341450 -r 5fa444f2d48d yt/lagos/BaseGridType.py
--- a/yt/lagos/BaseGridType.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/lagos/BaseGridType.py Wed Jul 28 09:55:29 2010 -0700
@@ -705,3 +705,13 @@
def __repr__(self):
return "TigerGrid_%04i (%s)" % (self.id, self.ActiveDimensions)
+
+class FLASHGrid(AMRGridPatch):
+ _id_offset = 1
+ #__slots__ = ["_level_id", "stop_index"]
+ def __init__(self, id, hierarchy, level):
+ AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename,
+ hierarchy = hierarchy)
+ self.Parent = None
+ self.Children = []
+ self.Level = level
diff -r 95375c341450 -r 5fa444f2d48d yt/lagos/DataReadingFuncs.py
--- a/yt/lagos/DataReadingFuncs.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/lagos/DataReadingFuncs.py Wed Jul 28 09:55:29 2010 -0700
@@ -499,3 +499,20 @@
SS[axis] = 1
data = au.read_tiger_section(fn, LD, SS, RS).astype("float64")
return data
+
+class IOHandlerFLASH(BaseIOHandler):
+ _data_style = "flash_hdf5"
+
+ def __init__(self, *args, **kwargs):
+ BaseIOHandler.__init__(self, *args, **kwargs)
+
+ def _read_data_set(self, grid, field):
+ f = h5py.File(grid.pf.parameter_filename, "r")
+ return f["/%s" % field][grid.id - grid._id_offset,:,:,:]
+
+ def _read_data_slice(self, grid, field, axis, coord):
+ sl = [slice(None), slice(None), slice(None)]
+ sl[axis] = slice(coord, coord + 1)
+ f = h5py.File(grid.pf.parameter_filename, "r")
+ dd = f["/%s" % field][grid.id - grid._id_offset][sl].transpose()
+ return dd
diff -r 95375c341450 -r 5fa444f2d48d yt/lagos/HierarchyType.py
--- a/yt/lagos/HierarchyType.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/lagos/HierarchyType.py Wed Jul 28 09:55:29 2010 -0700
@@ -1412,3 +1412,97 @@
def _setup_derived_fields(self):
self.derived_field_list = []
+
+class FLASHHierarchy(AMRHierarchy):
+
+ grid = FLASHGrid
+ _handle = None
+
+ def __init__(self,pf,data_style='chombo_hdf5'):
+ self.data_style = data_style
+ self.field_info = FLASHFieldContainer()
+ self.field_indexes = {}
+ self.parameter_file = weakref.proxy(pf)
+ # for now, the hierarchy file is the parameter file!
+ self.hierarchy_filename = self.parameter_file.parameter_filename
+ self.directory = os.path.dirname(self.hierarchy_filename)
+ self._handle = h5py.File(self.hierarchy_filename)
+
+ self.float_type = na.float64
+ AMRHierarchy.__init__(self,pf,data_style)
+
+ self._handle.close()
+ self._handle = None
+
+ def _initialize_data_storage(self):
+ pass
+
+ def _detect_fields(self):
+ ncomp = self._handle["/unknown names"].shape[0]
+ self.field_list = [s.strip() for s in self._handle["/unknown names"][:].flat]
+
+ def _setup_classes(self):
+ dd = self._get_data_reader_dict()
+ AMRHierarchy._setup_classes(self, dd)
+ self.object_types.sort()
+
+ def _count_grids(self):
+ self.num_grids = self.parameter_file._find_parameter(
+ "integer", "globalnumblocks", True, self._handle)
+
+ def _parse_hierarchy(self):
+ f = self._handle # shortcut
+ pf = self.parameter_file # shortcut
+
+ self.grid_left_edge[:] = f["/bounding box"][:,:,0]
+ self.grid_right_edge[:] = f["/bounding box"][:,:,1]
+ # Move this to the parameter file
+ nxb = pf._find_parameter("integer", "nxb", True, f)
+ nyb = pf._find_parameter("integer", "nyb", True, f)
+ nzb = pf._find_parameter("integer", "nzb", True, f)
+ self.grid_dimensions[:] *= (nxb, nyb, nzb)
+ # particle count will need to be fixed somehow:
+ # by getting access to the particle file we can get the number of
+ # particles in each brick. but how do we handle accessing the
+ # particle file?
+
+ # This will become redundant, as _prepare_grid will reset it to its
+ # current value. Note that FLASH uses 1-based indexing for refinement
+ # levels, but we do not, so we reduce the level by 1.
+ self.grid_levels[:] = f["/refine level"][:][:,None] - 1
+ g = [self.grid(i+1, self, self.grid_levels[i])
+ for i in xrange(self.num_grids)]
+ self.grids = na.array(g, dtype='object')
+
+
+ def _populate_grid_objects(self):
+ # We only handle 3D data, so offset is 7 (nfaces+1)
+ offset = 7
+ ii = na.argsort(self.grid_levels.flat)
+ gid = self._handle["/gid"][:]
+ for g in self.grids[ii].flat:
+ gi = g.id - g._id_offset
+ # FLASH uses 1-indexed group info
+ g.Children = [self.grids[i - 1] for i in gid[gi,7:] if i > -1]
+ for g1 in g.Children:
+ g1.Parent = g
+ g._prepare_grid()
+ g._setup_dx()
+ self.max_level = self.grid_levels.max()
+
+ def _setup_unknown_fields(self):
+ for field in self.field_list:
+ if field in self.parameter_file.field_info: continue
+ mylog.info("Adding %s to list of fields", field)
+ cf = None
+ if self.parameter_file.has_key(field):
+ def external_wrapper(f):
+ def _convert_function(data):
+ return data.convert(f)
+ return _convert_function
+ cf = external_wrapper(field)
+ add_field(field, lambda a, b: None,
+ convert_function=cf, take_log=False)
+
+ def _setup_derived_fields(self):
+ self.derived_field_list = []
diff -r 95375c341450 -r 5fa444f2d48d yt/lagos/OutputTypes.py
--- a/yt/lagos/OutputTypes.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/lagos/OutputTypes.py Wed Jul 28 09:55:29 2010 -0700
@@ -790,3 +790,85 @@
@classmethod
def _is_valid(self, *args, **kwargs):
return os.path.exists(args[0] + "rhob")
+
+class FLASHStaticOutput(StaticOutput):
+ _hierarchy_class = FLASHHierarchy
+ _fieldinfo_class = FLASHFieldContainer
+ _handle = None
+
+ def __init__(self, filename, data_style='flash_hdf5',
+ storage_filename = None):
+ StaticOutput.__init__(self, filename, data_style)
+ self.storage_filename = storage_filename
+
+ self.field_info = self._fieldinfo_class()
+ # hardcoded for now
+ self.parameters["InitialTime"] = 0.0
+ # These should be explicitly obtained from the file, but for now that
+ # will wait until a reorganization of the source tree and better
+ # generalization.
+ self.parameters["TopGridRank"] = 3
+ self.parameters["RefineBy"] = 2
+ self.parameters["HydroMethod"] = 'flash' # always PPM DE
+ self.parameters["Time"] = 1. # default unit is 1...
+
+ def _set_units(self):
+ """
+ Generates the conversion to various physical _units based on the parameter file
+ """
+ self.units = {}
+ self.time_units = {}
+ if len(self.parameters) == 0:
+ self._parse_parameter_file()
+ self._setup_nounits_units()
+ self.conversion_factors = defaultdict(lambda: 1.0)
+ self.time_units['1'] = 1
+ self.units['1'] = 1.0
+ self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max()
+ seconds = 1 #self["Time"]
+ self.time_units['years'] = seconds / (365*3600*24.0)
+ self.time_units['days'] = seconds / (3600*24.0)
+ for key in yt2orionFieldsDict:
+ self.conversion_factors[key] = 1.0
+
+ def _setup_nounits_units(self):
+ z = 0
+ mylog.warning("Setting 1.0 in code units to be 1.0 cm")
+ if not self.has_key("TimeUnits"):
+ mylog.warning("No time units. Setting 1.0 = 1 second.")
+ self.conversion_factors["Time"] = 1.0
+ for unit in mpc_conversion.keys():
+ self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"]
+
+ def _find_parameter(self, ptype, pname, scalar = False, handle = None):
+ # We're going to implement handle caching eventually
+ if handle is None: handle = self._handle
+ if handle is None:
+ handle = h5py.File(self.parameter_filename, "r")
+ nn = "/%s %s" % (ptype,
+ {False: "runtime parameters", True: "scalars"}[scalar])
+ for tpname, pval in handle[nn][:]:
+ if tpname.strip() == pname:
+ return pval
+ raise KeyError(pname)
+
+ def _parse_parameter_file(self):
+ self.parameters["CurrentTimeIdentifier"] = \
+ int(os.stat(self.parameter_filename)[ST_CTIME])
+ self._handle = h5py.File(self.parameter_filename, "r")
+ self.parameters["DomainLeftEdge"] = na.array(
+ [self._find_parameter("real", "%smin" % ax) for ax in 'xyz'])
+ self.parameters["DomainRightEdge"] = na.array(
+ [self._find_parameter("real", "%smax" % ax) for ax in 'xyz'])
+ self._handle.close()
+
+ @classmethod
+ def _is_valid(self, *args, **kwargs):
+ try:
+ fileh = h5py.File(args[0],'r')
+ if "real runtime parameters" in fileh["/"].keys():
+ return True
+ except:
+ pass
+ return False
+
diff -r 95375c341450 -r 5fa444f2d48d yt/lagos/__init__.py
--- a/yt/lagos/__init__.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/lagos/__init__.py Wed Jul 28 09:55:29 2010 -0700
@@ -76,6 +76,7 @@
from EnzoFields import *
from OrionFields import *
from ChomboFields import *
+from FLASHFields import *
fieldInfo = EnzoFieldInfo
# NOT the same as fieldInfo.add_field
diff -r 95375c341450 -r 5fa444f2d48d yt/mods.py
--- a/yt/mods.py Sun Jul 25 20:22:10 2010 -0700
+++ b/yt/mods.py Wed Jul 28 09:55:29 2010 -0700
@@ -39,14 +39,16 @@
from performance_counters import yt_counters, time_function
# Now individual component imports from lagos
-from yt.lagos import EnzoStaticOutput, \
+from yt.lagos import \
+ EnzoStaticOutput, OrionStaticOutput, TigerStaticOutput, \
+ FLASHStaticOutput, \
BinnedProfile1D, BinnedProfile2D, BinnedProfile3D, \
derived_field, \
add_field, FieldInfo, EnzoFieldInfo, Enzo2DFieldInfo, OrionFieldInfo, \
- GadgetFieldInfo, TigerFieldInfo, \
+ GadgetFieldInfo, TigerFieldInfo, ChomboFieldInfo, FLASHFieldInfo, \
Clump, write_clump_hierarchy, find_clumps, write_clumps, \
get_lowest_clumps, \
- OrionStaticOutput, HaloFinder, HOPHaloFinder, FOFHaloFinder, parallelHF, \
+ HaloFinder, HOPHaloFinder, FOFHaloFinder, parallelHF, \
axis_names, x_dict, y_dict, TwoPointFunctions, FcnSet
# This is a temporary solution -- in the future, we will allow the user to
More information about the yt-svn
mailing list