:orphan: .. index:: compute_lambda_grid .. _compute-lambda-grid: .. _compute-lambda-grid-command: ########################### compute lambda/grid command ########################### .. _compute-lambda-grid-kk-command: ############################## compute lambda/grid/kk command ############################## .. _compute-lambda-grid-syntax: ******* Syntax: ******* :: compute ID lambda/grid nrho temp value1 value2 ... - ID is documented in :ref:`compute` command - lambda/grid = style name of this compute command - nrho = compute or fix reference for per-grid number density, prefaced by "c\_" or "f\_" - temp = NULL or compute or fix reference for pre-grid temperature, prefaced by "c\_" or "f\_" - one or more values can be listed - value = *lambda*, *tau*, *knall*, *knx*, *kny*, or *knz* :: *lambda* = calculate mean free path *tau* = calculate mean collision time *knall* = calculate Knudsen number based on cell size in all dimensions *knx* = calculate Knudsen number based on cell size in x dimension *kny* = calculate Knudsen number based on cell size in y dimension *knz* = calculate Knudsen number based on cell size in z dimension .. _compute-lambda-grid-examples: ********* Examples: ********* :: compute 1 lambda/grid c_GR\[\*\] NULL lambda tau compute 1 lambda/grid f_ave\[\*\] f_ave\[3\] lambda knall 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: :: compute 1 grid all species nrho temp fix 1 ave/grid all 10 100 1000 c_1\[\*\] compute 2 lambda/grid f_1\[\*\] f_1\[2\] lambda tau dump 1 grid all 1000 tmp.grid id c_2\[\*\] .. _compute-lambda-grid-descriptio: ************ Description: ************ This command calculates properties related to the gas collision mean free path for each grid cell based on the number density *nrho* and thermal tempearture *temp* of particles in the cell. If the *lambda* value is specified, the mean free path (MFP) of particles between collisions will be computed. If the *tau* value is specified, the mean collision time (MCT) between molecular collisions will be computed. If one or more of the *knall* or *knx* or *kny* or *knz* values are specified, the dimensionless Knudsen number will be calculated, which is the ratio of the MFP to the cell size. For *knall*, the cell size is the average of the three grid cell side lengths (or two cell lengths for a 2d simulation). For *knx*, *kny*, or *knz*, 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 :ref:`adapt_grid` or :ref:`fix adapt/grid` commands, as well as for estimating the optimal timestep size. .. note:: that unlike other computes which calculate per-grid values, this compute does not take a "group-ID" for a grid cell group or a particle :ref:`mixture` ID as an argument. This is because it uses the number density and thermal 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. The results of this compute can be used by different commands in different ways. For example, the values can be output by the :ref:`dump grid` command. Or as indicated above the compute can be used as an argument for the :ref:`adapt_grid` or :ref:`fix adapt` commands, e.g. to trigger grid cell refinement or coarsening based on a mean free path metric. The formula used to calculate the mean free path (lambda) is given in :ref:`(Bird94)` as equation 4.77: .. math:: \lambda = \sum_{p=1}^{s} \frac{n_{p}}{n} \left [ \sum_{q=1}^{s} \left \{ \pi (d_{\rm ref})^2_{pq} n_{q} \left (\frac{(T_{\rm ref})_{pq}}{T} \right )^{\omega_{pq} - 1/2} \left (1+\frac{m_{p}}{m_{q}} \right )^{1/2} \right \} \right ]^{-1} .. important:: Prior to October 2024, a simpler formula was used for the mean free path, also from :ref:`(Bird94)`, equation 4.65: .. math:: \lambda = \left\{ \sqrt{2}\pi D^{2}_{\rm ref} n \left ({(T_{\rm ref})}/{T} \right )^{\omega - 1/2} \right\} ^{-1} The new formula is more accurate as it uses the number densities and VSS parameters of all gas species (sum over *s*) in the system, as opposed to using the total number density and the VSS parameters of only one species. This can make a significant difference for gas mixtures, in particular for reacting flow problems where the composition of the mixture changes significantly over time. The formula used to calculate the mean collision time (tau) is given in :ref:`(Bird94)` as equation 1.38 combined with 4.75: .. math:: \tau = \sum_{p=1}^{s} \frac{n_{p}}{n} \left [ \sum_{q=1}^{s} \left \{ 2(d_{\rm ref})^2_{pq} n_{q} \left (\frac{T}{(T_{\rm ref})_{pq}} \right )^{1 - \omega_{pq}} \left ( \frac{2 \pi k (T_{\rm ref})_{pq}}{m_{r}} \right )^{1/2} \right \} \right ]^{-1} These two formulas are the exact mean free path (MFP) and mean collision time (MCT) for a multi-species mixture, suitable for estimating optimal grid cell sizes and timestep as explained above. The *dref* and *Tref* and *omega* values in the two formulas are collision properties for a pair of species in the flow, subscripted as \*pq\*. Specifically, *dref* is the diameter of molecules of the species pair, *Tref* is the reference temperature, and *omega* is the viscosity temperature-dependence for the species pair. In the two formulas, *n_q* is the number density of species *q* within a grid cell. *T* is the thermal temperature of all particles (all species) in a grid cell. These per-grid values are specified for use by this command as the *nrho* and *temp* arguments in one of these forms: :: c_ID\[\*\] = compute with ID that calculates nrho for each species as an array output f_ID\[\*\] = fix with ID that calculates a time-averaged nrho for each species as an array output :: c_ID = compute with ID that calculates temp for all particles a vector output c_ID\[m\] = compute with ID that calculates temp for all particles as its Mth column of array output f_ID = fix with ID that calculates a time-averaged temp for all particles as a vector output f_ID\[m\] = fix with ID that calculates a time-averaged temp for all particles as its Mth column of array output The *temp* argument can also be specified as NULL, which drops the (Tref/T) and (T/Tref) ratios from the two formulas above. .. note:: for next paragraph: Is it correct that currently, this command requires that you use a compute grid nrho command which calculates nrho for every species in the system, not simply every species in a mixture that the user defines (used as an arg with the compute grid command) ? And this is intentional (for accuracy), not a limitation of the current implementation? .. note:: that because the MFP and MFT formulas require a number density nrho for all species in the system, you should use a :ref:`compute grid` command in this form: :: compute 1 grid all species nrho to reference by this command as c_ID\[\*\]. Or similarly for a :ref:`fix ave/grid` command that takes c_ID\[\*\] as an argument, which is then referenced by this command as f_ID\[\*\]. .. note:: check that this next paragraph is correct about the meaning of T in the 2 formulas. For the compute or fix referenced by the *temp* argument, this is meant in the two formulas to be the aggregate thermal temperature of all the particles in a grid cell. For systems with a zero of small streaming velocity, this can be calculated using this command: :: compute 2 grid all all temp which uses the velocity of each particle to calculate a temperature. For systems with a streaming flow, an appropriate therml temperature can be calculated by the :ref:`compute thermal/grid` thermal/grid command. Its doc page explain that the the center-of-mass velocity for the particles in each grid cell is subtracted from each particle's individual velocity to yield its thermal velocity, from which a thermal temperature is calculated. The corresponding command to use with this compute would be: :: compute 2 thermal/grid all all temp .. note:: that using fixes, rather than computes, for the *nrho* and *temp* arguments will typically result in less noisy MFP and MCT values, due to the time averaging which the :ref:`fix ave/grid` command can perform. .. important:: If the IDs of one or more :ref:`fix ave/grid` commands is used for the *nrho* or *temp* arguments, they only produce output on timesteps that are multiples of their *Nfreq* argument. Thus this compute can only be invoked on those timesteps. .. _compute-lambda-grid-output-info: ************ Output info: ************ If only one output value is specified, this compute outputs a per-grid vector. Otherwise it outputs a per-grid array with two or more columns, in the order the output values were specified. .. 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. The vector or array can be accessed by any command that uses per-grid values from a compute as input. See :ref:`Section 4.4` for an overview of SPARTA output options. The per-grid values for a column of output for *lambda* will be in :ref:`distance units`. A column of output for *tau* will be :ref:`time units`. Columns of output for *knall* or *knx* or *kny* or *knz* will be dimensionless. If the value of *nrho* for a grid cell is 0.0 (no particles), its MFP and MCT will be set to 1.0e20 (infinite length and time). This "infinite" MFP value will also be used for the calculation of Knudsen numbers. Styles with a *kk* 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 :ref:`Accelerating SPARTA` 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. These accelerated styles are part of the KOKKOS package. They are only enabled if SPARTA was built with that package. See the :ref:`Making SPARTA` section for more info. You can specify the accelerated styles explicitly in your input script by including their suffix, or you can use the :ref:`-suffix command-line switch` when you invoke SPARTA, or you can use the :ref:`suffix` command in your input script. See the :ref:`Accelerating SPARTA` section of the manual for more instructions on how to use the accelerated styles effectively. .. _compute-lambda-grid-restrictio: ************* Restrictions: ************* To use this compute, a collision style must be defined via the :ref:`collide` command, which defines properties for the mixture *species*. As explained above, to use this compute with *nrho* or *temp* defined as input from a :ref:`fix ave/grid` command, this compute must only be invoked on timesteps that are multiples of the *Nfreq* argument used by the fix, since those are the steps when it produces output. One or more output values must be specified. The same output value cannot be repeated more than once. The *knz* value cannot but used in a two-dimensional simulation. .. _compute-lambda-grid-related-commands: ***************** Related commands: ***************** :ref:`compute grid`, :ref:`compute thermal/grid`, :ref:`fix ave/grid`, :ref:`dump grid` .. _compute-lambda-grid-default: ******** Default: ******** none .. _Bird94: **(Bird94)** G. A. Bird, Molecular Gas Dynamics and the Direct Simulation of Gas Flows, Clarendon Press, Oxford (1994).