  The accuracy of a large eddy simulation (LES) is determined by the accuracy
of the model used to describe the effect of unresolved scales, the numerical
errors of the resolved scales, and the optimality of the length scale that
separates resolved from unresolved scales (the filter-width, or the
coarse-graining length scale). This paper is focused entirely on the last of
these, proposing a systematic algorithm for identifying the "optimal" spatial
distribution of the coarse-graining length scale and its aspect ratio. The core
idea is that the "optimal" coarse-graining length scale for LES is the largest
length scale for which the LES solution is minimally sensitive to it. This idea
is formulated based on an error indicator that measures the sensitivity of the
solution and a criterion that determines how that error indicator should vary
in space and direction to minimize the overall sensitivity of the solution. The
solution to this optimization problem is that the cell-integrated error
indicator should be equi-distributed; a corollary is that one cannot link the
accuracy in LES to quantities that are not cell-integrated, including the
common belief that LES is accurate whenever 80-90\% of the energy is resolved.
The full method is tested on the wall-resolved LES of turbulent channel flow
and the flow over a backward-facing step, with final length scale fields (or
filter-width fields, or grids) that are close to what is considered "best
practice" in the LES literature. Finally, the derivation of the error indicator
offers an alternative explanation for the success of the dynamic procedure.
