10fb1909eSJames Wright# Auxiliary Functionality 20fb1909eSJames WrightThis section documents functionality that is not apart of the core PDE solver, but is used for other miscellaneous tasks, such as statistics collection or in-situ machine learning. 30fb1909eSJames Wright 40fb1909eSJames Wright(aux-statistics)= 50fb1909eSJames Wright## Statistics Collection 60fb1909eSJames WrightFor scale-resolving simulations (such as LES and DNS), statistics for a simulation are more often useful than time-instantaneous snapshots of the simulation itself. 70fb1909eSJames WrightTo make this process more computationally efficient, averaging in the spanwise direction, if physically correct, can help reduce the amount of simulation time needed to get converged statistics. 80fb1909eSJames Wright 90fb1909eSJames WrightFirst, let's more precisely define what we mean by spanwise average. 100fb1909eSJames WrightDenote $\langle \phi \rangle$ as the Reynolds average of $\phi$, which in this case would be a average over the spanwise direction and time: 110fb1909eSJames Wright 120fb1909eSJames Wright$$ 130fb1909eSJames Wright\langle \phi \rangle(x,y) = \frac{1}{L_z + (T_f - T_0)}\int_0^{L_z} \int_{T_0}^{T_f} \phi(x, y, z, t) \mathrm{d}t \mathrm{d}z 140fb1909eSJames Wright$$ 150fb1909eSJames Wright 160fb1909eSJames Wrightwhere $z$ is the spanwise direction, the domain has size $[0, L_z]$ in the spanwise direction, and $[T_0, T_f]$ is the range of time being averaged over. 170fb1909eSJames WrightNote that here and in the code, **we assume the spanwise direction to be in the $z$ direction**. 180fb1909eSJames Wright 190fb1909eSJames WrightTo discuss the details of the implementation we'll first discuss the spanwise integral, then the temporal integral, and lastly the statistics themselves. 200fb1909eSJames Wright 210fb1909eSJames Wright### Spanwise Integral 220fb1909eSJames WrightThe function $\langle \phi \rangle (x,y)$ is represented on a 2-D finite element grid, taken from the full domain mesh itself. 230fb1909eSJames WrightIf isoperiodicity is set, the periodic face is extracted as the spanwise statistics mesh. 240fb1909eSJames WrightOtherwise the negative z face is used. 250fb1909eSJames WrightWe'll refer to this mesh as the *parent grid*, as for every "parent" point in the parent grid, there are many "child" points in the full domain. 260fb1909eSJames WrightDefine a function space on the parent grid as $\mathcal{V}_p^\mathrm{parent} = \{ \bm v(\bm x) \in H^{1}(\Omega_e^\mathrm{parent}) \,|\, \bm v(\bm x_e(\bm X)) \in P_p(\bm{I}), e=1,\ldots,N_e \}$. 270fb1909eSJames WrightWe enforce that the order of the parent FEM space is equal to the full domain's order. 280fb1909eSJames Wright 290fb1909eSJames WrightMany statistics are the product of 2 or more solution functions, which results in functions of degree higher than the parent FEM space, $\mathcal{V}_p^\mathrm{parent}$. 300fb1909eSJames WrightTo represent these higher-order functions on the parent FEM space, we perform an $L^2$ projection. 310fb1909eSJames WrightDefine the spanwise averaged function as: 320fb1909eSJames Wright 330fb1909eSJames Wright$$ 340fb1909eSJames Wright\langle \phi \rangle_z(x,y,t) = \frac{1}{L_z} \int_0^{L_z} \phi(x, y, z, t) \mathrm{d}z 350fb1909eSJames Wright$$ 360fb1909eSJames Wright 370fb1909eSJames Wrightwhere the function $\phi$ may be the product of multiple solution functions and $\langle \phi \rangle_z$ denotes the spanwise average. 380fb1909eSJames WrightThe projection of a function $u$ onto the parent FEM space would look like: 390fb1909eSJames Wright 400fb1909eSJames Wright$$ 410fb1909eSJames Wright\bm M u_N = \int_0^{L_x} \int_0^{L_y} u \psi^\mathrm{parent}_N \mathrm{d}y \mathrm{d}x 420fb1909eSJames Wright$$ 430fb1909eSJames Wrightwhere $\bm M$ is the mass matrix for $\mathcal{V}_p^\mathrm{parent}$, $u_N$ the coefficients of the projected function, and $\psi^\mathrm{parent}_N$ the basis functions of the parent FEM space. 440fb1909eSJames WrightSubstituting the spanwise average of $\phi$ for $u$, we get: 450fb1909eSJames Wright 460fb1909eSJames Wright$$ 470fb1909eSJames Wright\bm M [\langle \phi \rangle_z]_N = \int_0^{L_x} \int_0^{L_y} \left [\frac{1}{L_z} \int_0^{L_z} \phi(x,y,z,t) \mathrm{d}z \right ] \psi^\mathrm{parent}_N(x,y) \mathrm{d}y \mathrm{d}x 480fb1909eSJames Wright$$ 490fb1909eSJames Wright 500fb1909eSJames WrightThe triple integral in the right hand side is just an integral over the full domain 510fb1909eSJames Wright 520fb1909eSJames Wright$$ 530fb1909eSJames Wright\bm M [\langle \phi \rangle_z]_N = \frac{1}{L_z} \int_\Omega \phi(x,y,z,t) \psi^\mathrm{parent}_N(x,y) \mathrm{d}\Omega 540fb1909eSJames Wright$$ 550fb1909eSJames Wright 560fb1909eSJames WrightWe need to evaluate $\psi^\mathrm{parent}_N$ at quadrature points in the full domain. 570fb1909eSJames WrightTo do this efficiently, **we assume and exploit the full domain grid to be a tensor product in the spanwise direction**. 580fb1909eSJames WrightThis assumption means quadrature points in the full domain have the same $(x,y)$ coordinate location as quadrature points in the parent domain. 590fb1909eSJames WrightThis also allows the use of the full domain quadrature weights for the triple integral. 600fb1909eSJames Wright 610fb1909eSJames Wright### Temporal Integral/Averaging 620fb1909eSJames WrightTo calculate the temporal integral, we do a running average using left-rectangle rule. 630fb1909eSJames WrightAt the beginning of each simulation, the time integral of a statistic is set to 0, $\overline{\phi} = 0$. 640fb1909eSJames WrightPeriodically, the integral is updated using left-rectangle rule: 650fb1909eSJames Wright 660fb1909eSJames Wright$$\overline{\phi}_\mathrm{new} = \overline{\phi}_{\mathrm{old}} + \phi(t_\mathrm{new}) \Delta T$$ 670fb1909eSJames Wrightwhere $\phi(t_\mathrm{new})$ is the statistic at the current time and $\Delta T$ is the time since the last update. 680fb1909eSJames WrightWhen stats are written out to file, this running sum is then divided by $T_f - T_0$ to get the time average. 690fb1909eSJames Wright 700fb1909eSJames WrightWith this method of calculating the running time average, we can plug this into the $L^2$ projection of the spanwise integral: 710fb1909eSJames Wright 720fb1909eSJames Wright$$ 730fb1909eSJames Wright\bm M [\langle \phi \rangle]_N = \frac{1}{L_z + (T_f - T_0)} \int_\Omega \int_{T_0}^{T_f} \phi(x,y,z,t) \psi^\mathrm{parent}_N \mathrm{d}t \mathrm{d}\Omega 740fb1909eSJames Wright$$ 750fb1909eSJames Wrightwhere the integral $\int_{T_0}^{T_f} \phi(x,y,z,t) \mathrm{d}t$ is calculated on a running basis. 760fb1909eSJames Wright 770fb1909eSJames Wright 780fb1909eSJames Wright### Running 79b30619f6SJames WrightThe commandline options below are given for each `<statsname>` depending on the statistics being collected. 80b30619f6SJames WrightFor example, the turbulent statistics use `turbulence`. 81b30619f6SJames Wright 820fb1909eSJames WrightAs the simulation runs, it takes a running time average of the statistics at the full domain quadrature points. 83b30619f6SJames WrightThis running average is only updated at the interval specified by `-ts_monitor_spanstats_<statsname>_collect_interval` as number of timesteps. 84b30619f6SJames WrightThe $L^2$ projection problem is only solved when statistics are written to file, which is controlled by `-ts_monitor_spanstats_<statsname>_interval`. 850fb1909eSJames WrightNote that the averaging is not reset after each file write. 860fb1909eSJames WrightThe average is always over the bounds $[T_0, T_f]$, where $T_f$ in this case would be the time the file was written at and $T_0$ is the solution time at the beginning of the run. 870fb1909eSJames Wright 880fb1909eSJames Wright:::{list-table} Spanwise Turbulent Statistics Runtime Options 890fb1909eSJames Wright:header-rows: 1 900fb1909eSJames Wright 910fb1909eSJames Wright* - Option 920fb1909eSJames Wright - Description 930fb1909eSJames Wright - Default value 940fb1909eSJames Wright 95b30619f6SJames Wright* - `-ts_monitor_spanstats_<statsname>` 9678c5b8e5SJames Wright - Sets the `PetscViewer` for the statistics file writing, such as `cgns:output-%d.cgns` (requires PETSc `--download-cgns`). Also turns the statistics collection on. 970fb1909eSJames Wright - 980fb1909eSJames Wright 99b30619f6SJames Wright* - `-ts_monitor_spanstats_<statsname>_collect_interval` 100b30619f6SJames Wright - Number of timesteps between statistics collection 101b30619f6SJames Wright - `1` 102b30619f6SJames Wright 103b30619f6SJames Wright* - `-ts_monitor_spanstats_<statsname>_interval` 1040fb1909eSJames Wright - Number of timesteps between statistics file writing (`-1` means only at end of run) 1050fb1909eSJames Wright - `-1` 1060fb1909eSJames Wright 107b30619f6SJames Wright* - `-ts_monitor_spanstats_<statsname>_cgns_batch_size` 1080fb1909eSJames Wright - Number of frames written per CGNS file if the CGNS file name includes a format specifier (`%d`). 1090fb1909eSJames Wright - `20` 1100fb1909eSJames Wright::: 1110fb1909eSJames Wright 1120fb1909eSJames Wright### Turbulent Statistics 1130fb1909eSJames Wright 114b30619f6SJames WrightThe commandline prefix `turbulence` (e.g. `-ts_monitor_spanstats_turbulence`) obtains statistics that are relevant to turbulent flow. 1150fb1909eSJames WrightThe terms collected are listed below, with the mathematical definition on the left and the label (present in CGNS output files) is on the right. 1160fb1909eSJames Wright 1170fb1909eSJames Wright| Math | Label | 1180fb1909eSJames Wright| ----------------- | -------- | 119b30619f6SJames Wright| $\mean{\rho}$ | MeanDensity | 120b30619f6SJames Wright| $\mean{p}$ | MeanPressure | 121b30619f6SJames Wright| $\mean{p^2}$ | MeanPressureSquared | 122b30619f6SJames Wright| $\mean{p u_i}$ | MeanPressureVelocity[$i$] | 123b30619f6SJames Wright| $\mean{\rho T}$ | MeanDensityTemperature | 124b30619f6SJames Wright| $\mean{\rho T u_i}$ | MeanDensityTemperatureFlux[$i$] | 125b30619f6SJames Wright| $\mean{\rho u_i}$ | MeanMomentum[$i$] | 126b30619f6SJames Wright| $\mean{\rho u_i u_j}$ | MeanMomentumFlux[$ij$] | 127b30619f6SJames Wright| $\mean{u_i}$ | MeanVelocity[$i$] | 1280fb1909eSJames Wright 129b30619f6SJames Wrightwhere [$i$] are suffixes to the labels. So $\mean{\rho u_x u_y}$ would correspond to MeanMomentumFluxXY. 1300fb1909eSJames WrightThis naming convention is chosen to align with the CGNS standard naming style. 1310fb1909eSJames Wright 1320fb1909eSJames WrightTo get second-order statistics from these terms, simply use the identity: 1330fb1909eSJames Wright 1340fb1909eSJames Wright$$ 135b30619f6SJames Wright\mean{\phi' \theta'} = \mean{\phi \theta \rangle - \langle \phi} \mean{\theta} 1360fb1909eSJames Wright$$ 1370fb1909eSJames Wright 138b30619f6SJames Wright### Numerics ($\mathrm{Pe}$, $\mathrm{CFL}$) 139b30619f6SJames Wright 140b30619f6SJames WrightThe commandline prefix `cflpe` (e.g. `-ts_monitor_spanstats_cflpe`) obtains statistics for CFL and Péclet number. 141b30619f6SJames WrightThese quantities have agreed-upon definitions for 1D, but in multiple dimensions their definitions depend on the definition of the grid length. 142b30619f6SJames WrightHere, we define them as 143b30619f6SJames Wright 144b30619f6SJames Wright$$ 145b30619f6SJames Wright\Pe = \frac{\sqrt{\gbar{jk}^{-1} u_j u_k}}{\kappa} 146b30619f6SJames Wright$$ 147b30619f6SJames Wright 148b30619f6SJames Wrightand 149b30619f6SJames Wright 150b30619f6SJames Wright$$ 151b30619f6SJames Wright\CFL = \dt\sqrt{\gbar{jk} u_j u_k} 152b30619f6SJames Wright$$ 153b30619f6SJames Wright 154b30619f6SJames Wrightwhere $u_j$ is the (advection) velocity, $\kappa$ is the diffusion coefficient, $\gbar{jk}$ is the scaled element metric tensor. 155b30619f6SJames WrightNote that these quantities do *not* account for the polynomial order of an element. 156b30619f6SJames WrightThe following statistics are computed: 157b30619f6SJames Wright 158b30619f6SJames Wright| Math | Label | 159b30619f6SJames Wright| ----------------- | -------- | 160b30619f6SJames Wright| $\mean{\CFL}$ | MeanCFL | 161b30619f6SJames Wright| $\mean{\CFL^2}$ | MeanCFLSquared | 162b30619f6SJames Wright| $\mean{\CFL^3}$ | MeanCFLCubed | 163b30619f6SJames Wright| $\mean{\Pe}$ | MeanPe | 164b30619f6SJames Wright| $\mean{\Pe^2}$ | MeanPeSquared | 165b30619f6SJames Wright| $\mean{\Pe^3}$ | MeanPeCubed | 166b30619f6SJames Wright 1670fb1909eSJames Wright(aux-differential-filtering)= 1680fb1909eSJames Wright## Differential Filtering 1690fb1909eSJames Wright 1700fb1909eSJames WrightThere is the option to filter the solution field using differential filtering. 1710fb1909eSJames WrightThis was first proposed in {cite}`germanoDiffFilterLES1986`, using an inverse Hemholtz operator. 1720fb1909eSJames WrightThe strong form of the differential equation is 1730fb1909eSJames Wright 1740fb1909eSJames Wright$$ 1750fb1909eSJames Wright\overline{\phi} - \nabla \cdot (\beta (\bm{D}\bm{\Delta})^2 \nabla \overline{\phi} ) = \phi 1760fb1909eSJames Wright$$ 1770fb1909eSJames Wright 1780fb1909eSJames Wrightfor $\phi$ the scalar solution field we want to filter, $\overline \phi$ the filtered scalar solution field, $\bm{\Delta} \in \mathbb{R}^{3 \times 3}$ a symmetric positive-definite rank 2 tensor defining the width of the filter, $\bm{D}$ is the filter width scaling tensor (also a rank 2 SPD tensor), and $\beta$ is a kernel scaling factor on the filter tensor. 1790fb1909eSJames WrightThis admits the weak form: 1800fb1909eSJames Wright 1810fb1909eSJames Wright$$ 1820fb1909eSJames Wright\int_\Omega \left( v \overline \phi + \beta \nabla v \cdot (\bm{D}\bm{\Delta})^2 \nabla \overline \phi \right) \,d\Omega 1830fb1909eSJames Wright- \cancel{\int_{\partial \Omega} \beta v \nabla \overline \phi \cdot (\bm{D}\bm{\Delta})^2 \bm{\hat{n}} \,d\partial\Omega} = 1840fb1909eSJames Wright\int_\Omega v \phi \, , \; \forall v \in \mathcal{V}_p 1850fb1909eSJames Wright$$ 1860fb1909eSJames Wright 1870fb1909eSJames WrightThe boundary integral resulting from integration-by-parts is crossed out, as we assume that $(\bm{D}\bm{\Delta})^2 = \bm{0} \Leftrightarrow \overline \phi = \phi$ at boundaries (this is reasonable at walls, but for convenience elsewhere). 1880fb1909eSJames Wright 1890fb1909eSJames Wright### Filter Width Tensor, Δ 1900fb1909eSJames WrightFor homogenous filtering, $\bm{\Delta}$ is defined as the identity matrix. 1910fb1909eSJames Wright 1920fb1909eSJames Wright:::{note} 1930fb1909eSJames WrightIt is common to denote a filter width dimensioned relative to the radial distance of the filter kernel. 1940fb1909eSJames WrightNote here we use the filter *diameter* instead, as that feels more natural (albeit mathematically less convenient). 1950fb1909eSJames WrightFor example, under this definition a box filter would be defined as: 1960fb1909eSJames Wright 1970fb1909eSJames Wright$$ 1980fb1909eSJames WrightB(\Delta; \bm{r}) = 1990fb1909eSJames Wright\begin{cases} 2000fb1909eSJames Wright1 & \Vert \bm{r} \Vert \leq \Delta/2 \\ 2010fb1909eSJames Wright0 & \Vert \bm{r} \Vert > \Delta/2 2020fb1909eSJames Wright\end{cases} 2030fb1909eSJames Wright$$ 2040fb1909eSJames Wright::: 2050fb1909eSJames Wright 2060fb1909eSJames WrightFor inhomogeneous anisotropic filtering, we use the finite element grid itself to define $\bm{\Delta}$. 2070fb1909eSJames WrightThis is set via `-diff_filter_grid_based_width`. 2080fb1909eSJames WrightSpecifically, we use the filter width tensor defined in {cite}`prakashDDSGSAnisotropic2022`. 2090fb1909eSJames WrightFor finite element grids, the filter width tensor is most conveniently defined by $\bm{\Delta} = \bm{g}^{-1/2}$ where $\bm g = \nabla_{\bm x} \bm{X} \cdot \nabla_{\bm x} \bm{X}$ is the metric tensor. 2100fb1909eSJames Wright 2110fb1909eSJames Wright### Filter Width Scaling Tensor, $\bm{D}$ 2120fb1909eSJames WrightThe filter width tensor $\bm{\Delta}$, be it defined from grid based sources or just the homogenous filtering, can be scaled anisotropically. 2130fb1909eSJames WrightThe coefficients for that anisotropic scaling are given by `-diff_filter_width_scaling`, denoted here by $c_1, c_2, c_3$. 2140fb1909eSJames WrightThe definition for $\bm{D}$ then becomes 2150fb1909eSJames Wright 2160fb1909eSJames Wright$$ 2170fb1909eSJames Wright\bm{D} = 2180fb1909eSJames Wright\begin{bmatrix} 2190fb1909eSJames Wright c_1 & 0 & 0 \\ 2200fb1909eSJames Wright 0 & c_2 & 0 \\ 2210fb1909eSJames Wright 0 & 0 & c_3 \\ 2220fb1909eSJames Wright\end{bmatrix} 2230fb1909eSJames Wright$$ 2240fb1909eSJames Wright 2250fb1909eSJames WrightIn the case of $\bm{\Delta}$ being defined as homogenous, $\bm{D}\bm{\Delta}$ means that $\bm{D}$ effectively sets the filter width. 2260fb1909eSJames Wright 2270fb1909eSJames WrightThe filtering at the wall may also be damped, to smoothly meet the $\overline \phi = \phi$ boundary condition at the wall. 2280fb1909eSJames WrightThe selected damping function for this is the van Driest function {cite}`vandriestWallDamping1956`: 2290fb1909eSJames Wright 2300fb1909eSJames Wright$$ 2310fb1909eSJames Wright\zeta = 1 - \exp\left(-\frac{y^+}{A^+}\right) 2320fb1909eSJames Wright$$ 2330fb1909eSJames Wright 2340fb1909eSJames Wrightwhere $y^+$ is the wall-friction scaled wall-distance ($y^+ = y u_\tau / \nu = y/\delta_\nu$), $A^+$ is some wall-friction scaled scale factor, and $\zeta$ is the damping coefficient. 2350fb1909eSJames WrightFor this implementation, we assume that $\delta_\nu$ is constant across the wall and is defined by `-diff_filter_friction_length`. 2360fb1909eSJames Wright$A^+$ is defined by `-diff_filter_damping_constant`. 2370fb1909eSJames Wright 2380fb1909eSJames WrightTo apply this scalar damping coefficient to the filter width tensor, we construct the wall-damping tensor from it. 2390fb1909eSJames WrightThe construction implemented currently limits damping in the wall parallel directions to be no less than the original filter width defined by $\bm{\Delta}$. 2400fb1909eSJames WrightThe wall-normal filter width is allowed to be damped to a zero filter width. 2410fb1909eSJames WrightIt is currently assumed that the second component of the filter width tensor is in the wall-normal direction. 2420fb1909eSJames WrightUnder these assumptions, $\bm{D}$ then becomes: 2430fb1909eSJames Wright 2440fb1909eSJames Wright$$ 2450fb1909eSJames Wright\bm{D} = 2460fb1909eSJames Wright\begin{bmatrix} 2470fb1909eSJames Wright \max(1, \zeta c_1) & 0 & 0 \\ 2480fb1909eSJames Wright 0 & \zeta c_2 & 0 \\ 2490fb1909eSJames Wright 0 & 0 & \max(1, \zeta c_3) \\ 2500fb1909eSJames Wright\end{bmatrix} 2510fb1909eSJames Wright$$ 2520fb1909eSJames Wright 2530fb1909eSJames Wright### Filter Kernel Scaling, β 2540fb1909eSJames WrightWhile we define $\bm{D}\bm{\Delta}$ to be of a certain physical filter width, the actual width of the implied filter kernel is quite larger than "normal" kernels. 2550fb1909eSJames WrightTo account for this, we use $\beta$ to scale the filter tensor to the appropriate size, as is done in {cite}`bullExplicitFilteringExact2016`. 2560fb1909eSJames WrightTo match the "size" of a normal kernel to our differential kernel, we attempt to have them match second order moments with respect to the prescribed filter width. 2570fb1909eSJames WrightTo match the box and Gaussian filters "sizes", we use $\beta = 1/10$ and $\beta = 1/6$, respectively. 2580fb1909eSJames Wright$\beta$ can be set via `-diff_filter_kernel_scaling`. 2590fb1909eSJames Wright 2600fb1909eSJames Wright### Runtime Options 2610fb1909eSJames Wright 2620fb1909eSJames Wright:::{list-table} Differential Filtering Runtime Options 2630fb1909eSJames Wright:header-rows: 1 2640fb1909eSJames Wright 2650fb1909eSJames Wright* - Option 2660fb1909eSJames Wright - Description 2670fb1909eSJames Wright - Default value 2680fb1909eSJames Wright - Unit 2690fb1909eSJames Wright 2700fb1909eSJames Wright* - `-diff_filter_monitor` 2710fb1909eSJames Wright - Enable differential filter TSMonitor 2720fb1909eSJames Wright - `false` 2730fb1909eSJames Wright - boolean 2740fb1909eSJames Wright 2750fb1909eSJames Wright* - `-diff_filter_grid_based_width` 2760fb1909eSJames Wright - Use filter width based on the grid size 2770fb1909eSJames Wright - `false` 2780fb1909eSJames Wright - boolean 2790fb1909eSJames Wright 2800fb1909eSJames Wright* - `-diff_filter_width_scaling` 2810fb1909eSJames Wright - Anisotropic scaling for filter width in wall-aligned coordinates (snz) 2820fb1909eSJames Wright - `1,1,1` 2830fb1909eSJames Wright - `m` 2840fb1909eSJames Wright 2850fb1909eSJames Wright* - `-diff_filter_kernel_scaling` 2860fb1909eSJames Wright - Scaling to make differential kernel size equivalent to other filter kernels 2870fb1909eSJames Wright - `0.1` 2880fb1909eSJames Wright - `m^2` 2890fb1909eSJames Wright 2900fb1909eSJames Wright* - `-diff_filter_wall_damping_function` 2910fb1909eSJames Wright - Damping function to use at the wall for anisotropic filtering (`none`, `van_driest`) 2920fb1909eSJames Wright - `none` 2930fb1909eSJames Wright - string 2940fb1909eSJames Wright 2950fb1909eSJames Wright* - `-diff_filter_wall_damping_constant` 2960fb1909eSJames Wright - Constant for the wall-damping function. $A^+$ for `van_driest` damping function. 2970fb1909eSJames Wright - 25 2980fb1909eSJames Wright - 2990fb1909eSJames Wright 3000fb1909eSJames Wright* - `-diff_filter_friction_length` 3010fb1909eSJames Wright - Friction length associated with the flow, $\delta_\nu$. Used in wall-damping functions 3020fb1909eSJames Wright - 0 3030fb1909eSJames Wright - `m` 3040fb1909eSJames Wright::: 3050fb1909eSJames Wright 306*8fc6ab98SJames Wright(aux-smartsim)= 307*8fc6ab98SJames Wright## *In Situ* Data Analysis - SmartSim 308*8fc6ab98SJames WrightData-analysis, including training of machine-learning models, normally uses *a priori* (already gathered) data stored on disk. 3090fb1909eSJames WrightThis is computationally inefficient, particularly as the scale of the problem grows and the data that is saved to disk reduces to a small percentage of the total data generated by a simulation. 310*8fc6ab98SJames WrightOne way of working around this is to perform whatever data analysis while the simulation is actively running. 311*8fc6ab98SJames WrightThis is known as *in situ* (in place) data analysis. 3120fb1909eSJames Wright 313*8fc6ab98SJames WrightHONEE can facilitate *in situ* data analysis using [SmartSim](https://www.craylabs.org/docs/overview.html). 314*8fc6ab98SJames WrightHONEE will periodically place data into an in-memory database and a separate process can then read data from this database and perform analysis on it. 315*8fc6ab98SJames WrightSmartSim is responsible for orchestrating the running of HONEE and the data-analysis processes. 3160fb1909eSJames WrightThe database used by SmartSim is [Redis](https://redis.com/modules/redis-ai/) and the library to connect to the database is called [SmartRedis](https://www.craylabs.org/docs/smartredis.html). 3170fb1909eSJames WrightMore information about how to utilize this code in a SmartSim configuration can be found on [SmartSim's website](https://www.craylabs.org/docs/overview.html). 318*8fc6ab98SJames WrightWhile the primary intention of SmartSim is to enable machine learning interaction with normal HPC applications, any data-analysis process can be used e.g. data-compression, post-processing, etc. 3190fb1909eSJames Wright 320*8fc6ab98SJames WrightTo use HONEE in a SmartSim *in situ* setup, HONEE must be built with SmartRedis enabled. 3210fb1909eSJames WrightThis is done by specifying the installation directory of SmartRedis using the `SMARTREDIS_DIR` environment variable when building: 3220fb1909eSJames Wright 3230fb1909eSJames Wright``` 3240fb1909eSJames Wrightmake SMARTREDIS_DIR=~/software/smartredis/install 3250fb1909eSJames Wright``` 3260fb1909eSJames Wright 327*8fc6ab98SJames WrightSmartSim has the option of having the database either be colocated with the compute hardware or be located on separate nodes of a compute cluster. 328*8fc6ab98SJames WrightThis is controlled by the SmartSim, but HONEE needs to know how many MPI ranks per database there are. 329*8fc6ab98SJames WrightThis is set by `-smartsim_collocated_num_ranks`. 330*8fc6ab98SJames Wright 331*8fc6ab98SJames Wright### Runtime Options 332*8fc6ab98SJames Wright:::{list-table} SmartSim Runtime Options 333*8fc6ab98SJames Wright:header-rows: 1 334*8fc6ab98SJames Wright 335*8fc6ab98SJames Wright* - Option 336*8fc6ab98SJames Wright - Description 337*8fc6ab98SJames Wright - Default value 338*8fc6ab98SJames Wright - Unit 339*8fc6ab98SJames Wright 340*8fc6ab98SJames Wright* - `-smartsim_collocated_num_ranks` 341*8fc6ab98SJames Wright - Number of MPI ranks associated with each collocated database (i.e. ranks per node) 342*8fc6ab98SJames Wright - `1` 343*8fc6ab98SJames Wright - 344*8fc6ab98SJames Wright::: 345*8fc6ab98SJames Wright 346*8fc6ab98SJames Wright### Solution Data-Analysis 347*8fc6ab98SJames Wright 348*8fc6ab98SJames WrightThe most basic functionality for *in situ* data analysis is to simply place the solution vector into the database. 349*8fc6ab98SJames WrightThe solution vector added includes all periodic and strong boundaries, i.e. it includes the entire grid of the problem. 350*8fc6ab98SJames WrightThis is enabled using the `-ts_monitor_smartsim_solution` flag. 351*8fc6ab98SJames Wright 352*8fc6ab98SJames Wright#### Runtime Options 353*8fc6ab98SJames Wright:::{list-table} *In Situ* Machine-Learning Training Runtime Options 354*8fc6ab98SJames Wright:header-rows: 1 355*8fc6ab98SJames Wright 356*8fc6ab98SJames Wright* - Option 357*8fc6ab98SJames Wright - Description 358*8fc6ab98SJames Wright - Default value 359*8fc6ab98SJames Wright - Unit 360*8fc6ab98SJames Wright 361*8fc6ab98SJames Wright* - `-ts_monitor_smartsim_solution` 362*8fc6ab98SJames Wright - Place solution data into the smartsim database 363*8fc6ab98SJames Wright - 364*8fc6ab98SJames Wright - 365*8fc6ab98SJames Wright 366*8fc6ab98SJames Wright* - `-ts_monitor_smartsim_solution_interval` 367*8fc6ab98SJames Wright - Number of timesteps between writing solution data into SmartRedis database 368*8fc6ab98SJames Wright - `1` 369*8fc6ab98SJames Wright - 370*8fc6ab98SJames Wright 371*8fc6ab98SJames Wright* - `-ts_monitor_smartsim_solution_overwrite_data` 372*8fc6ab98SJames Wright - Whether new solution data should overwrite old data on database 373*8fc6ab98SJames Wright - `true` 374*8fc6ab98SJames Wright - boolean 375*8fc6ab98SJames Wright::: 376*8fc6ab98SJames Wright 377*8fc6ab98SJames Wright(aux-in-situ-ml)= 3780fb1909eSJames Wright### SGS Data-Driven Model *In Situ* Training 3790fb1909eSJames WrightCurrently the code is only setup to do *in situ* training for the SGS data-driven model. 3800fb1909eSJames WrightTraining data is split into the model inputs and outputs. 381*8fc6ab98SJames WrightThe model inputs are calculated as the same model inputs in the SGS Data-Driven model described in {ref}`sgs-dd-model`. 3820fb1909eSJames WrightThe model outputs (or targets in the case of training) are the subgrid stresses. 3830fb1909eSJames WrightBoth the inputs and outputs are computed from a filtered velocity field, which is calculated via {ref}`aux-differential-filtering`. 3840fb1909eSJames WrightThe settings for the differential filtering used during training are described in {ref}`aux-differential-filtering`. 3850fb1909eSJames WrightThe training will create multiple sets of data per each filter width defined in `-sgs_train_filter_widths`. 3860fb1909eSJames WrightThose scalar filter widths correspond to the scaling correspond to $\bm{D} = c \bm{I}$, where $c$ is the scalar filter width. 3870fb1909eSJames Wright 3880fb1909eSJames WrightThe SGS *in situ* training can be enabled using the `-sgs_train_enable` flag. 3890fb1909eSJames WrightData can be processed and placed into the database periodically. 3900fb1909eSJames WrightThe interval between is controlled by `-sgs_train_write_data_interval`. 3910fb1909eSJames WrightThere's also the choice of whether to add new training data on each database write or to overwrite the old data with new data. 3920fb1909eSJames WrightThis is controlled by `-sgs_train_overwrite_data`. 3930fb1909eSJames Wright 3940fb1909eSJames WrightThe database may also be located on the same node as a MPI rank (collocated) or located on a separate node (distributed). 3950fb1909eSJames WrightIt's necessary to know how many ranks are associated with each collocated database, which is set by `-smartsim_collocated_database_num_ranks`. 3960fb1909eSJames Wright 397*8fc6ab98SJames Wright#### Runtime Options 3980fb1909eSJames Wright:::{list-table} *In Situ* Machine-Learning Training Runtime Options 3990fb1909eSJames Wright:header-rows: 1 4000fb1909eSJames Wright 4010fb1909eSJames Wright* - Option 4020fb1909eSJames Wright - Description 4030fb1909eSJames Wright - Default value 4040fb1909eSJames Wright - Unit 4050fb1909eSJames Wright 4060fb1909eSJames Wright* - `-sgs_train_enable` 4070fb1909eSJames Wright - Whether to enable *in situ* training of data-driven SGS model. Require building with SmartRedis. 4080fb1909eSJames Wright - `false` 4090fb1909eSJames Wright - boolean 4100fb1909eSJames Wright 4110fb1909eSJames Wright* - `-sgs_train_write_data_interval` 4120fb1909eSJames Wright - Number of timesteps between writing training data into SmartRedis database 4130fb1909eSJames Wright - `1` 4140fb1909eSJames Wright - 4150fb1909eSJames Wright 4160fb1909eSJames Wright* - `-sgs_train_overwrite_data` 4170fb1909eSJames Wright - Whether new training data should overwrite old data on database 4180fb1909eSJames Wright - `true` 4190fb1909eSJames Wright - boolean 4200fb1909eSJames Wright 4210fb1909eSJames Wright* - `-sgs_train_filter_widths` 4220fb1909eSJames Wright - List of scalar values for different filter widths to calculate for training data 4230fb1909eSJames Wright - 4240fb1909eSJames Wright - `m` 4250fb1909eSJames Wright::: 426