<HTML>
<CENTER><A HREF = "https://sparta.github.io">SPARTA WWW Site</A> - <A HREF = "Manual.html">SPARTA Documentation</A> - <A HREF = "Section_commands.html#comm">SPARTA Commands</A> 
</CENTER>






<HR>

<H3>compute lambda/grid command 
</H3>
<H3>compute lambda/grid/kk command 
</H3>
<P><B>Syntax:</B>
</P>
<PRE>compute ID lambda/grid nrho temp value1 value2 ... 
</PRE>
<UL><LI>ID is documented in <A HREF = "compute.html">compute</A> command 

<LI>lambda/grid = style name of this compute command 

<LI>nrho = compute or fix for number density, prefaced by "c_" or "f_" 

<LI>temp = NULL or compute or fix column for temperature, prefaced by "c_" or "f_" 

<LI>value = <I>lambda</I> or <I>tau</I> or <I>knall</I> or <I>knx</I> or <I>kny</I> or <I>knz</I> 

<PRE>  <I>lambda</I> = calculate mean free path
  <I>tau</I> = calculate mean collision time
  <I>knall</I> = calculate Knudsen number based on cell size in all dimensions
  <I>knx</I> = calculate Knudsen number based on cell size in x dimension
  <I>kny</I> = calculate Knudsen number based on cell size in y dimension
  <I>knz</I> = calculate Knudsen number based on cell size in z dimension 
</PRE>

</UL>
<P><B>Examples:</B>
</P>
<PRE>compute 1 lambda/grid c_GR[*] NULL lambda tau
compute 1 lambda/grid f_ave[*] f_ave[3] lambda knall 
</PRE>
<P>These commands will dump time averages for the mean free path and mean
collision time for each grid cell to a dump file every 1000 steps:
</P>
<PRE>compute 1 grid species nrho temp
fix 1 ave/grid 10 100 1000 c_1[*]
compute 2 lambda/grid f_1[1] f_1[2] lambda tau
dump 1 grid all 1000 tmp.grid id c_2 
</PRE>
<P><B>Description:</B>
</P>
<P>If the <I>lambda</I> keyword is specified, the mean free path will be
computed. If the <I>tau</I> keyword is specified, the mean collision time
between molecular collisions for each grid cell based on the particles
in that cell will be computed. If one or more of the <I>knall</I> or <I>knx</I>
or <I>kny</I> or <I>knz</I> keywords are specified, the dimensionless Knudsen
number will be calculated, which is the ratio of the mean free path to
the cell size. For <I>knall</I>, the cell size is taken to be the average
of the three grid cell side lengths (or two cell lengths for a 2d
simulation).  For <I>knx</I>, <I>kny</I>, or <I>knz</I>, the cell size is the single
cell side length in the corresponding x,y,z dimension. The Knudsen
number can be useful for estimating the optimal grid cell size when
adapting the grid, e.g.  via the <A HREF = "adapt_grid.html">adapt_grid</A> or <A HREF = "fix_adapt_grid.html">fix
adapt/grid</A> commands, as well as the optimal time
step size.
</P>
<P>Unlike other computes that calculate per grid cell values, this
compute does not take a "group-ID" for a grid cell group as an
argument, nor a particle <A HREF = "mixture.html">mixture</A> ID as an argument.
This is because it uses the number density and temperature calculated
by other computes or fixes as input, and those computes or fixes use
grid group IDs or mixture IDs as part of their computations.
</P>
<P>The results of this compute can be used by different commands in
different ways.  For example, the values can be output by the
<A HREF = "dump.html">dump grid</A> command.
</P>
<HR>

<P>The formula used to calculate the mean free path (lambda) is given in
<A HREF = "#Bird94">(Bird94)</A> as equation 4.77:
</P>
<CENTER><IMG SRC = "Eqs/lambda.jpg">
</CENTER>
<P>NOTE: In October 2024, the formula to compute the mean free path was updated
to the equation above, from <A HREF = "#Bird94">(Bird94)</A>, equation 4.65:
</P>
<CENTER><IMG SRC = "Eqs/lambda_old.jpg">
</CENTER>
<P>The new formula is more accurate as it uses the number densities, 
translational temperatures and VSS parameters of each gases in the
mixture, as opposed to using the flow total number density and the
VSS parameters of only one species.
This will make a significant difference for gas mixtures, in particular
for reacting flow problems where the composition of the mixture changes
significantly in time.
</P>
<P>The formula used to calculate the mean collision time (tau) is given in
<A HREF = "#Bird94">(Bird94)</A> as equation 1.38 combined with 4.75:
</P>
<CENTER><IMG SRC = "Eqs/tau.jpg">
</CENTER>
<P>These are the exact mean free path and mean collision time for a
multi-species mixture, suitable for estimating optimal grid cell sizes
and timestep as explained above.
</P>
<P><I>dref</I> and <I>Tref</I> and <I>omega</I> are collision properties for a pair of
species species in the flow. Specifically, <I>dref</I> is the diameter of
molecules of the species pair, <I>Tref</I> is the reference temperature,
and <I>omega</I> is the viscosity temperature-dependence for the species
pair.
</P>
<P>In the formula above, <I>n</I> is the number density and <I>T</I> is the thermal
temperature of particles in a grid cell.  This compute does not
calculate these quantities itself; instead it uses another compute or
fix to perform the calculation.  This is done by specifying the <I>nrho</I>
and <I>temp</I> arguments like this:
</P>
<PRE>c_ID = compute with ID that calculates temp as a vector output
c_ID[m] = compute with ID that calculates temp as its Mth column of array output
c_ID[*] = compute with ID that calculates nrho as an array output
f_ID[m] = fix with ID that calculates a time-averaged temp as a vector output
f_ID[m] = fix with ID that calculates a time-averaged temp as its Mth column of array output
f_ID[*] = fix with ID that calculates a time-averaged nrho as an array output 
</PRE>
<P>The <I>temp</I> argument can also be specified as NULL, which drops the
(Tref/T) ratio term from the formula above.  That is also effectively
the case if the reference species defines omega = 1/2.  In that case,
the <I>temp</I> argument is ignored, whether it is NULL or not.
</P>
<P>IMPORTANT NOTE: A per species number density array calculated by
either a compute or a fix has to be specified.  The code will
automatically detect the number of species in the mixture to perform
the mean free path and mean collision time calculation.  The
<A HREF = "compute_grid">compute_grid.html</A> command with mixture "species" has to
be invoked to ensure that the number density of all the species in the
mixture is computed.
</P>
<P>Note that if the value of <I>n</I> is 0.0 for a grid cell, its
mean-free-path and mean-collision-time will be set to 1.0e20 (infinite
length and time).
</P>
<P>The <A HREF = "compute_grid">compute_grid.html</A> command can calculate a number
density, using its <I>nrho</I> value.  It can also calculate a temperature
using its <I>temp</I> value.  Note that this temperature is inferred from
the translational kinetic energy of the particles, which is only
appopriate for a mean free path calculation for systems with zero or
small streaming velocities.  For systems with streaming flow, an
appropriate temperature can be calculated by the <A HREF = "compute">compute_thermal_grid.html</A>
thermal/grid command.  The formulas on its
doc page show that the the center-of-mass velocity from the particles
in each grid cell is subtracted from each particle's velocity to yield
a translational thermal velocity, from which a thermal temperature is
calculated.
</P>
<P>The <A HREF = "fix">fix_ave_grid.html</A> ave/grid command can calculate the same
values in a time-averaged sense, assuming it uses these same computes
as input.  Using this fix as input to this compute will thus yield
less noisy values, due to the time averaging.
</P>
<P>Note that the compute or fix (via the compute(s) it uses as input) has to
perform its number density calculation for a subset of
the particles based on the "mixture" it uses.  See the
<A HREF = "mixture">mixture.html</A> command for how a set of species can be
partitioned into groups.
</P>
<P>IMPORTANT NOTE: If the ID of a <A HREF = "fix">fix_ave_grid.html</A> ave/grid
command is used as the <I>nrho</I> or <I>temp</I> argument, it only produces
output on timesteps that are multiples of its <I>Nfreq</I> argument.  Thus
this compute can only be invoked on those timesteps.  For example, if
a <A HREF = "dump">dump.html</A> grid command invokes this compute to write values
to a dump file, it must do so on timesteps that are multiples of
<I>Nfreq</I>.
</P>
<HR>

<P><B>Output info:</B>
</P>
<P>If only one output value is specified, this compute outputs a per-grid
vector. Otherwise outputs a per-grid array with two or more columns,
in the order the output values were specified in the input.
</P>
<P>This compute performs calculations for all flavors of child grid cells
in the simulation, which includes unsplit, cut, split, and sub cells.
See <A HREF = "Section_howto.html#howto_8">Section 6.8</A> of the manual gives
details of how SPARTA defines child, unsplit, split, and sub cells.
Note that cells inside closed surfaces contain no particles.  These
could be unsplit or cut cells (if they have zero flow volume).  Both
of these kinds of cells will compute a zero result for all the
individual values.  Likewise, split cells store no particles and will
produce a zero result.  This is because their sub-cells actually
contain the particles that are geometrically inside the split cell.
</P>
<P>The vector or array can be accessed by any command that uses per-grid
values from a compute as input.  See <A HREF = "Section_howto.html#howto_4">Section
4.4</A> for an overview of SPARTA output
options.
</P>
<P>The per-grid values for the column of output corresponding to <I>lambda</I>
will will be in distance <A HREF = "units">units.html</A>. The column corresponding
to <I>tau</I> will be time distance divided by time <A HREF = "units">units.html</A>.
Columns of corresponding to <I>knall</I> or <I>knx</I> or <I>kny</I> or <I>knz</I> will be
dimensionless.
</P>
<HR>

<P>Styles with a <I>kk</I> suffix are functionally the same as the
corresponding style without the suffix.  They have been optimized to
run faster, depending on your available hardware, as discussed in the
<A HREF = "Section_accelerate.html">Accelerating SPARTA</A> section of the manual.
The accelerated styles take the same arguments and should produce the
same results, except for different random number, round-off and
precision issues.
</P>
<P>These accelerated styles are part of the KOKKOS package. They are only
enabled if SPARTA was built with that package.  See the <A HREF = "Section_start.html#start_3">Making
SPARTA</A> section for more info.
</P>
<P>You can specify the accelerated styles explicitly in your input script
by including their suffix, or you can use the <A HREF = "Section_start.html#start_7">-suffix command-line
switch</A> when you invoke SPARTA, or you can
use the <A HREF = "suffix.html">suffix</A> command in your input script.
</P>
<P>See the <A HREF = "Section_accelerate.html">Accelerating SPARTA</A> section of the
manual for more instructions on how to use the accelerated styles
effectively.
</P>
<HR>

<P><B>Restrictions:</B>
</P>
<P>To use this compute, a collision style must be defined via the
<A HREF = "collide">collide.html</A> command, which defines properties for the
mixture <I>species</I>.
</P>
<P>As explained above, to use this compute with <I>nrho</I> or <I>temp</I> defined
as input from a <A HREF = "fix">fix_ave_grid.html</A> ave/grid command, this compute
must only be invoked on timesteps that are multiples of the <I>Nfreq</I>
argument used by the fix, since those are the steps when it produces
output.
</P>
<P>One or more output values must be specified. The same output value
cannot be repeated more than once. The <I>knz</I> value cannot but used in
a two-dimensional simulation.
</P>
<P><B>Related commands:</B>
</P>
<P><A HREF = "compute_grid.html">compute grid</A>, <A HREF = "compute_thermal/grid.html">compute
thermal/grid</A>, <A HREF = "fix_ave_grid.html">fix
ave/grid</A>, <A HREF = "dump.html">dump grid</A>
</P>
<P><B>Default:</B> none
</P>
<HR>

<A NAME = "Bird94"></A>

<P><B>(Bird94)</B> G. A. Bird, Molecular Gas Dynamics and the Direct
Simulation of Gas Flows, Clarendon Press, Oxford (1994).
</P>
</HTML>
