[yt-svn] commit/yt-3.0: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Sep 25 14:17:37 PDT 2013
4 new commits in yt-3.0:
https://bitbucket.org/yt_analysis/yt-3.0/commits/1bdb0dc7c976/
Changeset: 1bdb0dc7c976
Branch: yt-3.0
User: MatthewTurk
Date: 2013-09-20 21:48:39
Summary: Adding a load_hexahedral_mesh to the Stream object.
Affected #: 4 files
diff -r 041fa69088987f233490ad884f8a53307ffee8f2 -r 1bdb0dc7c9763f91ddde87adf4cb9787c7e933f3 yt/frontends/stream/api.py
--- a/yt/frontends/stream/api.py
+++ b/yt/frontends/stream/api.py
@@ -21,6 +21,7 @@
load_uniform_grid, \
load_amr_grids, \
load_particles, \
+ load_hexahedral_mesh, \
refine_amr
from .fields import \
diff -r 041fa69088987f233490ad884f8a53307ffee8f2 -r 1bdb0dc7c9763f91ddde87adf4cb9787c7e933f3 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -26,6 +26,8 @@
GridGeometryHandler
from yt.geometry.particle_geometry_handler import \
ParticleGeometryHandler
+from yt.geometry.unstructured_mesh_handler import \
+ UnstructuredGeometryHandler
from yt.data_objects.static_output import \
StaticOutput
from yt.utilities.logger import ytLogger as mylog
@@ -41,6 +43,8 @@
FlaggingGrid
from yt.frontends.sph.data_structures import \
ParticleFile
+from yt.data_objects.unstructured_mesh import \
+ SemiStructuredMesh
from .fields import \
StreamFieldInfo, \
@@ -829,3 +833,127 @@
return spf
+class StreamHexahedralMesh(SemiStructuredMesh):
+ _connectivity_length = 8
+ _index_offset = 1
+
+class StreamHexahedralHierarchy(UnstructuredGeometryHandler):
+
+ def __init__(self, pf, data_style = None):
+ self.stream_handler = pf.stream_handler
+ super(StreamHexahedralHierarchy, self).__init__(pf, data_style)
+
+ def _initialize_mesh(self):
+ coords = self.stream_handler.fields.pop('coordinates')
+ connec = self.stream_handler.fields.pop('connectivity')
+ self.meshes = [StreamHexahedralMesh(0,
+ self.hierarchy_filename, connec, coords, self)]
+
+ def _setup_data_io(self):
+ if self.stream_handler.io is not None:
+ self.io = self.stream_handler.io
+ else:
+ self.io = io_registry[self.data_style](self.stream_handler)
+
+ def _detect_fields(self):
+ self.field_list = list(set(self.stream_handler.get_fields()))
+
+class StreamHexahedralStaticOutput(StreamStaticOutput):
+ _hierarchy_class = StreamHexahedralHierarchy
+ _fieldinfo_fallback = StreamFieldInfo
+ _fieldinfo_known = KnownStreamFields
+ _data_style = "stream_hexahedral"
+
+def load_hexahedral_mesh(data, connectivity, coordinates,
+ sim_unit_to_cm, bbox=None,
+ sim_time=0.0, periodicity=(True, True, True)):
+ r"""Load a hexahedral mesh of data into yt as a
+ :class:`~yt.frontends.stream.data_structures.StreamHandler`.
+
+ This should allow a semistructured grid of data to be loaded directly into
+ yt and analyzed as would any others. This comes with several caveats:
+ * Units will be incorrect unless the data has already been converted to
+ cgs.
+ * Some functions may behave oddly, and parallelism will be
+ disappointing or non-existent in most cases.
+ * Particles may be difficult to integrate.
+
+ Particle fields are detected as one-dimensional fields. The number of particles
+ is set by the "number_of_particles" key in data.
+
+ Parameters
+ ----------
+ data : dict
+ This is a dict of numpy arrays, where the keys are the field names.
+ There must only be one.
+ connectivity : array_like
+ This should be of size (N,8) where N is the number of zones.
+ coordinates : array_like
+ This should be of size (M,3) where M is the number of vertices
+ indicated in the connectivity matrix.
+ domain_dimensions : array_like
+ This is the domain dimensions of the grid
+ sim_unit_to_cm : float
+ Conversion factor from simulation units to centimeters
+ bbox : array_like (xdim:zdim, LE:RE), optional
+ Size of computational domain in units sim_unit_to_cm
+ sim_time : float, optional
+ The simulation time in seconds
+ periodicity : tuple of booleans
+ Determines whether the data will be treated as periodic along
+ each axis
+
+ """
+
+ domain_dimensions = np.ones(3, "int32") * 2
+ nprocs = 1
+ if bbox is None:
+ bbox = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]], 'float64')
+ domain_left_edge = np.array(bbox[:, 0], 'float64')
+ domain_right_edge = np.array(bbox[:, 1], 'float64')
+ grid_levels = np.zeros(nprocs, dtype='int32').reshape((nprocs,1))
+
+ sfh = StreamDictFieldHandler()
+
+ particle_types = set_particle_types(data)
+
+ sfh.update({'connectivity': connectivity,
+ 'coordinates': coordinates,
+ 0: data})
+ grid_left_edges = domain_left_edge
+ grid_right_edges = domain_right_edge
+ grid_dimensions = domain_dimensions.reshape(nprocs,3).astype("int32")
+
+ # I'm not sure we need any of this.
+ handler = StreamHandler(
+ grid_left_edges,
+ grid_right_edges,
+ grid_dimensions,
+ grid_levels,
+ -np.ones(nprocs, dtype='int64'),
+ np.zeros(nprocs, dtype='int64').reshape(nprocs,1), # Temporary
+ np.zeros(nprocs).reshape((nprocs,1)),
+ sfh,
+ particle_types=particle_types,
+ periodicity=periodicity
+ )
+
+ handler.name = "HexahedralMeshData"
+ handler.domain_left_edge = domain_left_edge
+ handler.domain_right_edge = domain_right_edge
+ handler.refine_by = 2
+ handler.dimensionality = 3
+ handler.domain_dimensions = domain_dimensions
+ handler.simulation_time = sim_time
+ handler.cosmology_simulation = 0
+
+ spf = StreamHexahedralStaticOutput(handler)
+ spf.units["cm"] = sim_unit_to_cm
+ spf.units['1'] = 1.0
+ spf.units["unitary"] = 1.0
+ box_in_mpc = sim_unit_to_cm / mpc_conversion['cm']
+ for unit in mpc_conversion.keys():
+ spf.units[unit] = mpc_conversion[unit] * box_in_mpc
+
+ return spf
+
diff -r 041fa69088987f233490ad884f8a53307ffee8f2 -r 1bdb0dc7c9763f91ddde87adf4cb9787c7e933f3 yt/frontends/stream/io.py
--- a/yt/frontends/stream/io.py
+++ b/yt/frontends/stream/io.py
@@ -199,3 +199,32 @@
def _identify_fields(self, data_file):
return [ ("all", k) for k in self.fields[data_file.filename].keys()]
+
+class IOHandlerStreamHexahedral(BaseIOHandler):
+ _data_style = "stream_hexahedral"
+
+ def __init__(self, stream_handler):
+ self.fields = stream_handler.fields
+ BaseIOHandler.__init__(self)
+
+ def _read_fluid_selection(self, chunks, selector, fields, size):
+ chunks = list(chunks)
+ assert(len(chunks) == 1)
+ chunk = chunks[0]
+ rv = {}
+ for field in fields:
+ ftype, fname = field
+ rv[field] = np.empty(size, dtype="float64")
+ ngrids = sum(len(chunk.objs) for chunk in chunks)
+ mylog.debug("Reading %s cells of %s fields in %s blocks",
+ size, [fname for ftype, fname in fields], ngrids)
+ for field in fields:
+ ind = 0
+ ftype, fname = field
+ for chunk in chunks:
+ for g in chunk.objs:
+ ds = self.fields[g.mesh_id].get(field, None)
+ if ds is None:
+ ds = self.fields[g.mesh_id][fname]
+ ind += g.select(selector, ds, rv[field], ind) # caches
+ return rv
diff -r 041fa69088987f233490ad884f8a53307ffee8f2 -r 1bdb0dc7c9763f91ddde87adf4cb9787c7e933f3 yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -114,7 +114,7 @@
from yt.frontends.stream.api import \
StreamStaticOutput, StreamFieldInfo, add_stream_field, \
StreamHandler, load_uniform_grid, load_amr_grids, \
- load_particles
+ load_particles, load_hexahedral_mesh
from yt.frontends.sph.api import \
OWLSStaticOutput, OWLSFieldInfo, add_owls_field, \
https://bitbucket.org/yt_analysis/yt-3.0/commits/e779c178190b/
Changeset: e779c178190b
Branch: yt-3.0
User: MatthewTurk
Date: 2013-09-20 21:49:42
Summary: Fixing off-by-one.
Affected #: 1 file
diff -r 1bdb0dc7c9763f91ddde87adf4cb9787c7e933f3 -r e779c178190b4d335b8da2f49e6249c4827f22d1 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -835,7 +835,7 @@
class StreamHexahedralMesh(SemiStructuredMesh):
_connectivity_length = 8
- _index_offset = 1
+ _index_offset = 0
class StreamHexahedralHierarchy(UnstructuredGeometryHandler):
https://bitbucket.org/yt_analysis/yt-3.0/commits/e8dcc5f4f2ad/
Changeset: e8dcc5f4f2ad
Branch: yt-3.0
User: MatthewTurk
Date: 2013-09-23 17:52:22
Summary: Adding tests for the hexahedral mesh, as well as Anthony's connectivity func.
Affected #: 2 files
diff -r e779c178190b4d335b8da2f49e6249c4827f22d1 -r e8dcc5f4f2adec6e3679447e356bc23a8ad7f0e4 yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -16,6 +16,7 @@
import weakref
import numpy as np
import uuid
+from itertools import chain, product
from yt.utilities.io_handler import io_registry
from yt.funcs import *
@@ -833,6 +834,23 @@
return spf
+def hexahedral_connectivity(xgrid, ygrid, zgrid):
+ nx = len(xgrid)
+ ny = len(ygrid)
+ nz = len(zgrid)
+ coords = np.fromiter(chain.from_iterable(product(xgrid, ygrid, zgrid)),
+ dtype=np.float64, count = nx*ny*nz*3)
+ coords.shape = (nx*ny*nz, 3)
+ cis = np.fromiter(chain.from_iterable(product([0,1], [0,1], [0,1])),
+ dtype=np.int64, count = 8*3)
+ cis.shape = (8, 3)
+ cycle = np.fromiter(chain.from_iterable(product(*map(range, (nx-1, ny-1, nz-1)))),
+ dtype=np.int64, count = (nx-1)*(ny-1)*(nz-1)*3)
+ cycle.shape = ((nx-1)*(ny-1)*(nz-1), 3)
+ off = cis + cycle[:, np.newaxis]
+ connectivity = ((off[:,:,0] * ny) + off[:,:,1]) * nz + off[:,:,2]
+ return coords, connectivity
+
class StreamHexahedralMesh(SemiStructuredMesh):
_connectivity_length = 8
_index_offset = 0
@@ -891,8 +909,6 @@
coordinates : array_like
This should be of size (M,3) where M is the number of vertices
indicated in the connectivity matrix.
- domain_dimensions : array_like
- This is the domain dimensions of the grid
sim_unit_to_cm : float
Conversion factor from simulation units to centimeters
bbox : array_like (xdim:zdim, LE:RE), optional
diff -r e779c178190b4d335b8da2f49e6249c4827f22d1 -r e8dcc5f4f2adec6e3679447e356bc23a8ad7f0e4 yt/frontends/stream/tests/test_stream_hexahedral.py
--- /dev/null
+++ b/yt/frontends/stream/tests/test_stream_hexahedral.py
@@ -0,0 +1,56 @@
+import numpy as np
+from yt.mods import *
+from yt.testing import *
+from yt.frontends.stream.api import \
+ load_hexahedral_mesh, load_uniform_grid
+from yt.frontends.stream.data_structures import \
+ hexahedral_connectivity
+
+def setup() :
+ pass
+
+# Field information
+
+def test_stream_hexahedral() :
+ np.random.seed(0x4d3d3d3)
+ Nx, Ny, Nz = 32, 18, 24
+ # Note what we're doing here -- we are creating a randomly spaced mesh, but
+ # because of how the accumulate operation works, we also reset the leftmost
+ # cell boundary to 0.0.
+ cell_x = np.random.random(Nx+1)
+ cell_x /= cell_x.sum()
+ cell_x = np.add.accumulate(cell_x)
+ cell_x[0] = 0.0
+
+ cell_y = np.random.random(Ny+1)
+ cell_y /= cell_y.sum()
+ cell_y = np.add.accumulate(cell_y)
+ cell_y[0] = 0.0
+
+ cell_z = np.random.random(Nz+1)
+ cell_z /= cell_z.sum()
+ cell_z = np.add.accumulate(cell_z)
+ cell_z[0] = 0.0
+
+ coords, conn = hexahedral_connectivity(cell_x, cell_y, cell_z)
+ data = {'random_field': np.random.random(Nx*Ny*Nz)}
+ bbox = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ])
+ ds = load_hexahedral_mesh(data, conn, coords, bbox)
+ dd = ds.h.all_data()
+ #raise RuntimeError
+ yield assert_almost_equal, dd["CellVolumeCode"].sum(dtype="float64"), 1.0
+ yield assert_equal, dd["Ones"].size, Nx * Ny * Nz
+ # Now we try it with a standard mesh
+ cell_x = np.linspace(0.0, 1.0, Nx+1)
+ cell_y = np.linspace(0.0, 1.0, Ny+1)
+ cell_z = np.linspace(0.0, 1.0, Nz+1)
+ coords, conn = hexahedral_connectivity(cell_x, cell_y, cell_z)
+ data = {'random_field': np.random.random(Nx*Ny*Nz)}
+ bbox = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ])
+ ds = load_hexahedral_mesh(data, conn, coords, bbox)
+ dd = ds.h.all_data()
+ yield assert_almost_equal, dd["CellVolumeCode"].sum(dtype="float64"), 1.0
+ yield assert_equal, dd["Ones"].size, Nx * Ny * Nz
+ yield assert_almost_equal, dd["dx"], 1.0/Nx
+ yield assert_almost_equal, dd["dy"], 1.0/Ny
+ yield assert_almost_equal, dd["dz"], 1.0/Nz
https://bitbucket.org/yt_analysis/yt-3.0/commits/2176d83193f2/
Changeset: 2176d83193f2
Branch: yt-3.0
User: samskillman
Date: 2013-09-25 23:17:31
Summary: Merged in MatthewTurk/yt-3.0 (pull request #97)
Adding load_hexahedral_mesh to Stream frontend
Affected #: 5 files
diff -r 08d537fcc7133a7203c2d418218bc928c13ae08b -r 2176d83193f2471755399d84ad03894f3ac2da1c yt/frontends/stream/api.py
--- a/yt/frontends/stream/api.py
+++ b/yt/frontends/stream/api.py
@@ -21,6 +21,7 @@
load_uniform_grid, \
load_amr_grids, \
load_particles, \
+ load_hexahedral_mesh, \
refine_amr
from .fields import \
diff -r 08d537fcc7133a7203c2d418218bc928c13ae08b -r 2176d83193f2471755399d84ad03894f3ac2da1c yt/frontends/stream/data_structures.py
--- a/yt/frontends/stream/data_structures.py
+++ b/yt/frontends/stream/data_structures.py
@@ -16,6 +16,7 @@
import weakref
import numpy as np
import uuid
+from itertools import chain, product
from yt.utilities.io_handler import io_registry
from yt.funcs import *
@@ -26,6 +27,8 @@
GridGeometryHandler
from yt.geometry.particle_geometry_handler import \
ParticleGeometryHandler
+from yt.geometry.unstructured_mesh_handler import \
+ UnstructuredGeometryHandler
from yt.data_objects.static_output import \
StaticOutput
from yt.utilities.logger import ytLogger as mylog
@@ -41,6 +44,8 @@
FlaggingGrid
from yt.frontends.sph.data_structures import \
ParticleFile
+from yt.data_objects.unstructured_mesh import \
+ SemiStructuredMesh
from .fields import \
StreamFieldInfo, \
@@ -829,3 +834,142 @@
return spf
+def hexahedral_connectivity(xgrid, ygrid, zgrid):
+ nx = len(xgrid)
+ ny = len(ygrid)
+ nz = len(zgrid)
+ coords = np.fromiter(chain.from_iterable(product(xgrid, ygrid, zgrid)),
+ dtype=np.float64, count = nx*ny*nz*3)
+ coords.shape = (nx*ny*nz, 3)
+ cis = np.fromiter(chain.from_iterable(product([0,1], [0,1], [0,1])),
+ dtype=np.int64, count = 8*3)
+ cis.shape = (8, 3)
+ cycle = np.fromiter(chain.from_iterable(product(*map(range, (nx-1, ny-1, nz-1)))),
+ dtype=np.int64, count = (nx-1)*(ny-1)*(nz-1)*3)
+ cycle.shape = ((nx-1)*(ny-1)*(nz-1), 3)
+ off = cis + cycle[:, np.newaxis]
+ connectivity = ((off[:,:,0] * ny) + off[:,:,1]) * nz + off[:,:,2]
+ return coords, connectivity
+
+class StreamHexahedralMesh(SemiStructuredMesh):
+ _connectivity_length = 8
+ _index_offset = 0
+
+class StreamHexahedralHierarchy(UnstructuredGeometryHandler):
+
+ def __init__(self, pf, data_style = None):
+ self.stream_handler = pf.stream_handler
+ super(StreamHexahedralHierarchy, self).__init__(pf, data_style)
+
+ def _initialize_mesh(self):
+ coords = self.stream_handler.fields.pop('coordinates')
+ connec = self.stream_handler.fields.pop('connectivity')
+ self.meshes = [StreamHexahedralMesh(0,
+ self.hierarchy_filename, connec, coords, self)]
+
+ def _setup_data_io(self):
+ if self.stream_handler.io is not None:
+ self.io = self.stream_handler.io
+ else:
+ self.io = io_registry[self.data_style](self.stream_handler)
+
+ def _detect_fields(self):
+ self.field_list = list(set(self.stream_handler.get_fields()))
+
+class StreamHexahedralStaticOutput(StreamStaticOutput):
+ _hierarchy_class = StreamHexahedralHierarchy
+ _fieldinfo_fallback = StreamFieldInfo
+ _fieldinfo_known = KnownStreamFields
+ _data_style = "stream_hexahedral"
+
+def load_hexahedral_mesh(data, connectivity, coordinates,
+ sim_unit_to_cm, bbox=None,
+ sim_time=0.0, periodicity=(True, True, True)):
+ r"""Load a hexahedral mesh of data into yt as a
+ :class:`~yt.frontends.stream.data_structures.StreamHandler`.
+
+ This should allow a semistructured grid of data to be loaded directly into
+ yt and analyzed as would any others. This comes with several caveats:
+ * Units will be incorrect unless the data has already been converted to
+ cgs.
+ * Some functions may behave oddly, and parallelism will be
+ disappointing or non-existent in most cases.
+ * Particles may be difficult to integrate.
+
+ Particle fields are detected as one-dimensional fields. The number of particles
+ is set by the "number_of_particles" key in data.
+
+ Parameters
+ ----------
+ data : dict
+ This is a dict of numpy arrays, where the keys are the field names.
+ There must only be one.
+ connectivity : array_like
+ This should be of size (N,8) where N is the number of zones.
+ coordinates : array_like
+ This should be of size (M,3) where M is the number of vertices
+ indicated in the connectivity matrix.
+ sim_unit_to_cm : float
+ Conversion factor from simulation units to centimeters
+ bbox : array_like (xdim:zdim, LE:RE), optional
+ Size of computational domain in units sim_unit_to_cm
+ sim_time : float, optional
+ The simulation time in seconds
+ periodicity : tuple of booleans
+ Determines whether the data will be treated as periodic along
+ each axis
+
+ """
+
+ domain_dimensions = np.ones(3, "int32") * 2
+ nprocs = 1
+ if bbox is None:
+ bbox = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]], 'float64')
+ domain_left_edge = np.array(bbox[:, 0], 'float64')
+ domain_right_edge = np.array(bbox[:, 1], 'float64')
+ grid_levels = np.zeros(nprocs, dtype='int32').reshape((nprocs,1))
+
+ sfh = StreamDictFieldHandler()
+
+ particle_types = set_particle_types(data)
+
+ sfh.update({'connectivity': connectivity,
+ 'coordinates': coordinates,
+ 0: data})
+ grid_left_edges = domain_left_edge
+ grid_right_edges = domain_right_edge
+ grid_dimensions = domain_dimensions.reshape(nprocs,3).astype("int32")
+
+ # I'm not sure we need any of this.
+ handler = StreamHandler(
+ grid_left_edges,
+ grid_right_edges,
+ grid_dimensions,
+ grid_levels,
+ -np.ones(nprocs, dtype='int64'),
+ np.zeros(nprocs, dtype='int64').reshape(nprocs,1), # Temporary
+ np.zeros(nprocs).reshape((nprocs,1)),
+ sfh,
+ particle_types=particle_types,
+ periodicity=periodicity
+ )
+
+ handler.name = "HexahedralMeshData"
+ handler.domain_left_edge = domain_left_edge
+ handler.domain_right_edge = domain_right_edge
+ handler.refine_by = 2
+ handler.dimensionality = 3
+ handler.domain_dimensions = domain_dimensions
+ handler.simulation_time = sim_time
+ handler.cosmology_simulation = 0
+
+ spf = StreamHexahedralStaticOutput(handler)
+ spf.units["cm"] = sim_unit_to_cm
+ spf.units['1'] = 1.0
+ spf.units["unitary"] = 1.0
+ box_in_mpc = sim_unit_to_cm / mpc_conversion['cm']
+ for unit in mpc_conversion.keys():
+ spf.units[unit] = mpc_conversion[unit] * box_in_mpc
+
+ return spf
+
diff -r 08d537fcc7133a7203c2d418218bc928c13ae08b -r 2176d83193f2471755399d84ad03894f3ac2da1c yt/frontends/stream/io.py
--- a/yt/frontends/stream/io.py
+++ b/yt/frontends/stream/io.py
@@ -199,3 +199,32 @@
def _identify_fields(self, data_file):
return [ ("all", k) for k in self.fields[data_file.filename].keys()]
+
+class IOHandlerStreamHexahedral(BaseIOHandler):
+ _data_style = "stream_hexahedral"
+
+ def __init__(self, stream_handler):
+ self.fields = stream_handler.fields
+ BaseIOHandler.__init__(self)
+
+ def _read_fluid_selection(self, chunks, selector, fields, size):
+ chunks = list(chunks)
+ assert(len(chunks) == 1)
+ chunk = chunks[0]
+ rv = {}
+ for field in fields:
+ ftype, fname = field
+ rv[field] = np.empty(size, dtype="float64")
+ ngrids = sum(len(chunk.objs) for chunk in chunks)
+ mylog.debug("Reading %s cells of %s fields in %s blocks",
+ size, [fname for ftype, fname in fields], ngrids)
+ for field in fields:
+ ind = 0
+ ftype, fname = field
+ for chunk in chunks:
+ for g in chunk.objs:
+ ds = self.fields[g.mesh_id].get(field, None)
+ if ds is None:
+ ds = self.fields[g.mesh_id][fname]
+ ind += g.select(selector, ds, rv[field], ind) # caches
+ return rv
diff -r 08d537fcc7133a7203c2d418218bc928c13ae08b -r 2176d83193f2471755399d84ad03894f3ac2da1c yt/frontends/stream/tests/test_stream_hexahedral.py
--- /dev/null
+++ b/yt/frontends/stream/tests/test_stream_hexahedral.py
@@ -0,0 +1,56 @@
+import numpy as np
+from yt.mods import *
+from yt.testing import *
+from yt.frontends.stream.api import \
+ load_hexahedral_mesh, load_uniform_grid
+from yt.frontends.stream.data_structures import \
+ hexahedral_connectivity
+
+def setup() :
+ pass
+
+# Field information
+
+def test_stream_hexahedral() :
+ np.random.seed(0x4d3d3d3)
+ Nx, Ny, Nz = 32, 18, 24
+ # Note what we're doing here -- we are creating a randomly spaced mesh, but
+ # because of how the accumulate operation works, we also reset the leftmost
+ # cell boundary to 0.0.
+ cell_x = np.random.random(Nx+1)
+ cell_x /= cell_x.sum()
+ cell_x = np.add.accumulate(cell_x)
+ cell_x[0] = 0.0
+
+ cell_y = np.random.random(Ny+1)
+ cell_y /= cell_y.sum()
+ cell_y = np.add.accumulate(cell_y)
+ cell_y[0] = 0.0
+
+ cell_z = np.random.random(Nz+1)
+ cell_z /= cell_z.sum()
+ cell_z = np.add.accumulate(cell_z)
+ cell_z[0] = 0.0
+
+ coords, conn = hexahedral_connectivity(cell_x, cell_y, cell_z)
+ data = {'random_field': np.random.random(Nx*Ny*Nz)}
+ bbox = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ])
+ ds = load_hexahedral_mesh(data, conn, coords, bbox)
+ dd = ds.h.all_data()
+ #raise RuntimeError
+ yield assert_almost_equal, dd["CellVolumeCode"].sum(dtype="float64"), 1.0
+ yield assert_equal, dd["Ones"].size, Nx * Ny * Nz
+ # Now we try it with a standard mesh
+ cell_x = np.linspace(0.0, 1.0, Nx+1)
+ cell_y = np.linspace(0.0, 1.0, Ny+1)
+ cell_z = np.linspace(0.0, 1.0, Nz+1)
+ coords, conn = hexahedral_connectivity(cell_x, cell_y, cell_z)
+ data = {'random_field': np.random.random(Nx*Ny*Nz)}
+ bbox = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0] ])
+ ds = load_hexahedral_mesh(data, conn, coords, bbox)
+ dd = ds.h.all_data()
+ yield assert_almost_equal, dd["CellVolumeCode"].sum(dtype="float64"), 1.0
+ yield assert_equal, dd["Ones"].size, Nx * Ny * Nz
+ yield assert_almost_equal, dd["dx"], 1.0/Nx
+ yield assert_almost_equal, dd["dy"], 1.0/Ny
+ yield assert_almost_equal, dd["dz"], 1.0/Nz
diff -r 08d537fcc7133a7203c2d418218bc928c13ae08b -r 2176d83193f2471755399d84ad03894f3ac2da1c yt/mods.py
--- a/yt/mods.py
+++ b/yt/mods.py
@@ -114,7 +114,7 @@
from yt.frontends.stream.api import \
StreamStaticOutput, StreamFieldInfo, add_stream_field, \
StreamHandler, load_uniform_grid, load_amr_grids, \
- load_particles
+ load_particles, load_hexahedral_mesh
from yt.frontends.sph.api import \
OWLSStaticOutput, OWLSFieldInfo, add_owls_field, \
Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list