Commits

Matthew Turk committed e0a257f

Adding derived quantity stuff.

Comments (0)

Files changed (3)

scripts/bulk_velocity.py

+def _BulkVelocity(data):
+    """
+    This function returns the mass-weighted average velocity in the object.
+    """
+    xv = (data["x-velocity"] * data["CellMassMsun"]).sum()
+    yv = (data["y-velocity"] * data["CellMassMsun"]).sum()
+    zv = (data["z-velocity"] * data["CellMassMsun"]).sum()
+    w = data["CellMassMsun"].sum()
+    return xv, yv, zv, w
+def _combBulkVelocity(data, xv, yv, zv, w):
+    w = w.sum()
+    xv = xv.sum()/w
+    yv = yv.sum()/w
+    zv = zv.sum()/w
+    return na.array([xv, yv, zv])
+add_quantity("BulkVelocity", function=_BulkVelocity,
+             combine_function=_combBulkVelocity, n_ret=4)
+

scripts/total_mass.py

+def _TotalMass(data):
+    """
+    This function takes no arguments and returns the sum of cell masses and
+    particle masses in the object.
+    """
+    baryon_mass = data["CellMassMsun"].sum()
+    particle_mass = data["ParticleMassMsun"].sum()
+    return [baryon_mass + particle_mass]
+
+def _combTotalMass(data, total_mass):
+    return total_mass.sum()
+add_quantity("TotalMass", function=_TotalMass,
+             combine_function=_combTotalMass, n_ret=1)
 <<d['scripts/radial_velocity.py|fn|py|pyg|l']>>
 \end{frame}
 
+\mediumsimple{This works for all data objects, but for volume rendering you
+have to be tricky.}
+
+\begin{frame}[t]{Common Field Parameters}
+\smfont{}
+\begin{center}
+\begin{tabular}{l|p{2.5in}}
+\texttt{center} & The center to consider (usually set by data object)\\[9pt]
+\texttt{mu} & The mean-molecular weight to use \\[9pt]
+\texttt{bulk\_velocity} & The x,y,z velocities to subtract off \\[9pt]
+\texttt{height\_vector} & ``Up''\\[9pt]
+\end{tabular}
+\end{center}
+\end{frame}
+
+\bigsimple{Making New Derived Quantities}
+
+\begin{frame}[t]{Derived Quantity Process}
+\vspace{1in}
+\begin{itemize}
+\item Divide into one or more work chunks 
+\item Process work chunks
+\item Combine results
+\item Return results
+\end{itemize}
+\end{frame}
+
+\mediumsimple{This allows for transparent parallelization}
+
+\begin{frame}[t]{How to write one?}
+\vspace{1in}
+\begin{enumerate}
+\item Construct a single-object reduction function
+\item Construct a multiple-result reduction function
+\item \texttt{add\_quantity}, specifying the number of intermediate return
+values.
+\end{enumerate}
+\end{frame}
+
+\begin{frame}[fragile, t]{Example: Total mass}
+\tiny
+<<d['scripts/total_mass.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Example: Bulk Velocity}
+\tiny
+<<d['scripts/bulk_velocity.py|fn|pyg|l']>>
+\end{frame}
+
+\begin{frame}[fragile, t]{Common Pitfalls}
+\vspace{1in}
+\begin{itemize}
+\item Array shapes in the combine function
+\item Round-off error
+\item Field preloading
+\end{itemize}
+\end{frame}
+
+\bigsimple{Thank you!}
+
 \end{document}