[Yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Feb 24 22:29:39 PST 2011
2 new changesets in yt:
http://bitbucket.org/yt_analysis/yt/changeset/9f769234f317/
changeset: r3771:9f769234f317
branch: yt
user: samskillman
date: 2011-02-25 07:27:30
summary: Cleaning up Streamlines. Also note the name change from StreamLines
to Streamlines. This commit comes with better docstrings, and some
better behaving integrations. Also added new _mpi_cat_na_array
function that uses mpi4py's built in type and shape inference.
affected #: 3 files (2.2 KB)
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py Thu Feb 24 18:33:59 2011 -0800
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py Thu Feb 24 23:27:30 2011 -0700
@@ -1056,6 +1056,19 @@
return data
@parallel_passthrough
+ def _mpi_cat_na_array(self,data):
+ self._barrier()
+ comm = MPI.COMM_WORLD
+ if comm.rank == 0:
+ for i in range(1,comm.size):
+ buf = comm.recv(source=i, tag=0)
+ data = na.concatenate([data,buf])
+ else:
+ comm.send(data, 0, tag = 0)
+ data = comm.bcast(data, root=0)
+ return data
+
+ @parallel_passthrough
def _mpi_catarray(self, data):
if data is None:
ncols = -1
--- a/yt/visualization/api.py Thu Feb 24 18:33:59 2011 -0800
+++ b/yt/visualization/api.py Thu Feb 24 23:27:30 2011 -0700
@@ -57,4 +57,4 @@
plot_type_registry
from streamlines import \
- StreamLines
+ Streamlines
--- a/yt/visualization/streamlines.py Thu Feb 24 18:33:59 2011 -0800
+++ b/yt/visualization/streamlines.py Thu Feb 24 23:27:30 2011 -0700
@@ -1,38 +1,88 @@
+"""
+Import the components of the volume rendering extension
+
+Author: Samuel Skillman <samskillman at gmail.com>
+Affiliation: University of Colorado
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 Samuel Skillman. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
import numpy as na
from yt.funcs import *
from yt.utilities.parallel_tools.parallel_analysis_interface import \
- ParallelAnalysisInterface
+ ParallelAnalysisInterface, parallel_passthrough
from yt.utilities.amr_kdtree.api import AMRKDTree
-from yt.config import ytcfg
-my_rank = ytcfg.getint("yt", "__parallel_rank")
-nprocs = ytcfg.getint("yt", "__parallel_size")
-
-class StreamLines(ParallelAnalysisInterface):
+class Streamlines(ParallelAnalysisInterface):
r"""A collection of streamlines that flow through the volume
- Examples
- --------
+ The Streamlines object contains a collection of streamlines
+ defined as paths that are parallel to a specified vector field.
- >>> c = na.array([0.5]*3)
- >>> c = na.array([0.5]*3)
- >>> N = 100
- >>> scale = 1.0
- >>> pos_dx = na.random.random((N,3))*scale-scale/2.
- >>> pos = c+pos_dx
+ Parameters
+ ----------
+ pf : `~yt.lagos.StaticOutput`
+ This is the parameter file to streamline
+ pos : array_like
+ An array of initial starting positions of the streamlines.
+ xfield: field
+ The x component of the vector field to be streamlined.
+ yfield: field
+ The y component of the vector field to be streamlined.
+ zfield: field
+ The z component of the vector field to be streamlined.
+ volume : `yt.extensions.volume_rendering.HomogenizedVolume`, optional
+ The volume to be streamlined. Can be specified for
+ finer-grained control, but otherwise will be automatically
+ generated. At this point it must use the AMRKDTree.
+ Default: None
+ dx : float, optional
+ Optionally specify the step size during the integration.
+ Default: minimum dx
+ length : float, optional
+ Optionally specify the length of integration.
+ Default: na.max(self.pf.domain_right_edge-self.pf.domain_left_edge)
+
+ Examples
+ --------
+ >>> from yt.mods import *
+ >>> from yt.visualization.api import Streamlines
+ >>> pf = load('DD1701') # Load pf
- >>> streamlines = StreamLines(pf,pos,'x-velocity', 'y-velocity', 'z-velocity', length=1.0)
- >>> streamlines.integrate_through_volume()
-
- >>> import matplotlib.pylab as pl
- >>> from mpl_toolkits.mplot3d import Axes3D
- >>> fig=pl.figure()
- >>> ax = Axes3D(fig)
- >>> for stream in streamlines.streamlines:
- >>> stream = stream[na.all(stream != 0.0, axis=1)]
- >>> ax.plot3D(stream[:,0], stream[:,1], stream[:,2], alpha=0.1)
- >>> pl.savefig('streamlines.png')
- """
+ >>> c = na.array([0.5]*3)
+ >>> N = 100
+ >>> scale = 1.0
+ >>> pos_dx = na.random.random((N,3))*scale-scale/2.
+ >>> pos = c+pos_dx
+
+ >>> streamlines = Streamlines(pf,pos,'x-velocity', 'y-velocity', 'z-velocity', length=1.0)
+ >>> streamlines.integrate_through_volume()
+
+ >>> import matplotlib.pylab as pl
+ >>> from mpl_toolkits.mplot3d import Axes3D
+ >>> fig=pl.figure()
+ >>> ax = Axes3D(fig)
+ >>> for stream in streamlines.streamlines:
+ >>> stream = stream[na.all(stream != 0.0, axis=1)]
+ >>> ax.plot3D(stream[:,0], stream[:,1], stream[:,2], alpha=0.1)
+ >>> pl.savefig('streamlines.png')
+ """
def __init__(self, pf, positions, xfield, yfield, zfield, volume=None,
dx=None, length=None):
self.pf = pf
@@ -55,15 +105,11 @@
self.streamlines = na.zeros((self.N,self.steps,3), dtype='float64')
def integrate_through_volume(self):
- my_count = 0
- # Initialize streamlines
- for i in range(self.N):
- if i%nprocs != my_rank:
- continue
- self.streamlines[my_count,0,:] = self.start_positions[i]
- my_count+=1
- self.streamlines = self.streamlines[:my_count,:,:]
-
+ nprocs = self._mpi_get_size()
+ my_rank = self._mpi_get_rank()
+ self.streamlines = self.streamlines[my_rank::nprocs]
+ self.streamlines[:,0,:] = self.start_positions[my_rank::nprocs]
+
pbar = get_pbar("Streamlining", self.N)
for i,stream in enumerate(self.streamlines):
step = self.steps
@@ -72,21 +118,19 @@
step = self._integrate_through_brick(this_brick, stream, step)
pbar.update(i)
pbar.finish()
+
+ self._finalize_parallel(None)
- self._finalize_parallel()
-
- def _finalize_parallel(self):
- if nprocs <= 1: return
- self.streamlines = self._mpi_cat2d_double_array([
- self.streamlines, [self.N,self.steps,3]])
-
+ @parallel_passthrough
+ def _finalize_parallel(self,data):
+ self.streamlines = self._mpi_cat_na_array(self.streamlines)
+
def _integrate_through_brick(self, node, stream, step, periodic=False):
- my_dx = node.grid.dds[0]
while (step > 1):
self.volume.get_brick_data(node)
brick = node.brick
stream[-step+1] = stream[-step]
- brick.integrate_streamline(stream[-step+1], my_dx)
+ brick.integrate_streamline(stream[-step+1], self.dx)
if na.any(stream[-step+1,:] <= self.pf.domain_left_edge) | \
na.any(stream[-step+1,:] >= self.pf.domain_right_edge):
return 0
http://bitbucket.org/yt_analysis/yt/changeset/5826af92a51a/
changeset: r3772:5826af92a51a
branch: yt
user: samskillman
date: 2011-02-25 07:29:10
summary: removing _mpi_cat2d_double_array.
affected #: 1 file (868 bytes)
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py Thu Feb 24 23:27:30 2011 -0700
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py Thu Feb 24 23:29:10 2011 -0700
@@ -610,26 +610,6 @@
return (data, final)
@parallel_passthrough
- def _mpi_cat2d_double_array(self, data):
- self._barrier()
- data, final_shape = data
- if MPI.COMM_WORLD.rank == 0:
- new_array = na.zeros(final_shape,dtype='float64')
- new_array[0:data.shape[0],:,:] = data[:]
- rows_filled = data.shape[0]
- for i in range(1, MPI.COMM_WORLD.size):
- new_rows = MPI.COMM_WORLD.recv(source=i, tag=0)
- new_array[rows_filled:rows_filled+new_rows,:,:] = _recv_array(
- source=i, tag=0).reshape((new_rows, final_shape[1], final_shape[2]))
- rows_filled += new_rows
- data = new_array
- else:
- MPI.COMM_WORLD.send(data.shape[0], 0, 0)
- _send_array(data.ravel(), dest=0, tag=0)
- data = MPI.COMM_WORLD.bcast(data)
- return data
-
- @parallel_passthrough
def _mpi_catdict(self, data):
field_keys = data.keys()
field_keys.sort()
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
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