# fluidsim.base.forcing.specific¶

## Forcing schemes (fluidsim.base.forcing.specific)¶

Provides:

class fluidsim.base.forcing.specific.SpecificForcing(sim)[source]

Bases: object

Base class for specific forcing

class fluidsim.base.forcing.specific.SpecificForcingPseudoSpectralSimple(sim)[source]

Specific forcing for pseudo-spectra solvers

compute(self)[source]

compute the forcing.

class fluidsim.base.forcing.specific.InScriptForcingPseudoSpectral(sim)[source]

Forcing maker for forcing defined by the user in the launching script

compute_forcing_fft_each_time(self)[source]

Compute the coarse forcing in Fourier space

compute_forcing_each_time(self)[source]

Compute the coarse forcing in real space

monkeypatch_compute_forcing_fft_each_time(self, func)[source]

Replace the method by a user-defined method

monkeypatch_compute_forcing_each_time(self, func)[source]

Replace the method by a user-defined method

class fluidsim.base.forcing.specific.SpecificForcingPseudoSpectralCoarse(sim)[source]

Specific forcing for pseudo-spectra solvers

static _check_forcing_shape(shape_forcing, shape)[source]

Check if shape of the forcing array exceeds the shape of the global array.

Parameters
shape_forcing: array-like

A single-element array containing index of largest forcing wavenumber or a tuple indincating shape of the forcing array.

shape: array-like

A tuple indicating the shape of an array or Operators instance.

put_forcingc_in_forcing(self)[source]

Copy data from self.fstate_coarse.state_spect into forcing_fft.

verify_injection_rate(self)[source]

Verify injection rate.

verify_injection_rate_coarse(self, var_fft=None)[source]

Verify injection rate.

compute(self)[source]

compute a forcing normalize with a 2nd degree eq.

class fluidsim.base.forcing.specific.InScriptForcingPseudoSpectralCoarse(sim)[source]

Forcing maker for forcing defined by the user in the launching script

compute_forcingc_fft_each_time(self)[source]

Compute the coarse forcing in Fourier space

compute_forcingc_each_time(self)[source]

Compute the coarse forcing in real space

monkeypatch_compute_forcingc_fft_each_time(self, func)[source]

Replace the method by a user-defined method

monkeypatch_compute_forcingc_each_time(self, func)[source]

Replace the method by a user-defined method

class fluidsim.base.forcing.specific.NormalizedForcing(sim)[source]

Specific forcing normalized to keep constant injection

classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

compute(self)[source]

compute a forcing normalize with a 2nd degree eq.

normalize_forcingc(self, fvc_fft, vc_fft)[source]

Normalize the coarse forcing

normalize_forcingc_part_k(self, fvc_fft, vc_fft)[source]

Modify the array fvc_fft to fixe the injection rate.

To be called only with proc 0.

Parameters
fvc_fftndarray

The non-normalized forcing at the coarse resolution.

vc_fftndarray

The forced variable at the coarse resolution.

normalize_forcingc_2nd_degree_eq(self, fvc_fft, vc_fft)[source]

Modify the array fvc_fft to fixe the injection rate.

To be called only with proc 0.

We consider that we force a variable $$\hat\alpha$$ with a forcing $$\hat f$$.

$\partial_t \hat\alpha = \hat f$

We want to normalize the forcing $$\hat f$$ such that the average over the time step of the injection of a quadratic quantity be equal to self.forcing_rate ($$P$$). Let’s consider that the time step starts at $$t=0$$ and that the time increment is $$\delta t$$.

For simplicity, we first consider that the quadratic quantity is the quadratic quantity of the forced variable $$\hat\alpha$$. Note that this function supports other quadratic quantities (for details, read the code). The average of the injection rate over the time step is:

$P = \int_0^{\delta t} \frac{dt}{\delta t} \sum_{\mathbf k} \partial_t \frac{|\hat\alpha^2|}{2} = \int_0^{\delta t} \frac{dt}{\delta t} \sum_{\mathbf k} \hat\alpha^* \hat f$

We compute an approximation at first order in $$\delta t$$ so that we can normalize the forcing such that the value given by this approximation is constant for all time steps. For each time step, the forcing $$\hat f$$ is constant in time. At first order in $$\delta t$$, we have during the time step:

$\hat\alpha(t) \simeq \hat\alpha(0) + \hat f t$

and we get

$P \simeq \hat f \int_0^{\delta t} \frac{dt}{\delta t} \sum_{\mathbf k} (\hat\alpha(0)^* + \hat f^* t) = \sum_{\mathbf k} \hat\alpha(0)^* \hat f + \sum_{\mathbf k} \frac{|\hat f|^2}{2} \delta t$

The final forcing $$\hat f$$ is proportional to the “random” forcing $$\hat f_r$$:

$\hat f = R \hat f_r$

We solve a second-order equation to get the value of the coefficient $$R$$:

$\left(\sum_{\mathbf k} \frac{|\hat f_r|^2}{2} \delta t\right) R^2 + \left(\sum_{\mathbf k} \hat\alpha(0)^* \hat f_r\right) R - P = 0$
Parameters
fvc_fftndarray

The non-normalized forcing at the coarse resolution.

vc_fftndarray

The forced variable at the coarse resolution.

coef_normalization_from_abc(self, a, b, c)[source]

Compute the roots of a quadratic equation

Compute the roots given the coefficients a, b and c. Then, select one of the roots based on a criteria and return it.

Notes

Set params.forcing.normalized.which_root to choose the root with:

• minabs : minimum absolute value

• first : root with positive sign before discriminant

• second : root with negative sign before discriminant

• positive : positive root

class fluidsim.base.forcing.specific.Proportional(sim)[source]

Specific forcing proportional to the forced variable

compute(self)[source]

compute a forcing normalize with a 2nd degree eq.

forcingc_raw_each_time(self, vc_fft)[source]

Modify the array fvc_fft to fixe the injection rate.

varcndarray

a variable at the coarse resolution.

To be called only with proc 0.

class fluidsim.base.forcing.specific.RandomSimplePseudoSpectral(sim)[source]

Random normalized forcing

classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

compute_forcingc_raw(self)[source]

Random coarse forcing.

To be called only with proc 0.

class fluidsim.base.forcing.specific.TimeCorrelatedRandomPseudoSpectral(sim)[source]

Time correlated random normalized forcing

classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

forcingc_raw_each_time(self, a_fft)[source]

Return a coarse forcing as a linear combination of 2 random arrays

Compute the new random coarse forcing arrays when necessary.

forcingc_from_f0f1(self)[source]

Return a coarse forcing as a linear combination of 2 random arrays

Classes

 Forcing maker for forcing defined by the user in the launching script Forcing maker for forcing defined by the user in the launching script Specific forcing normalized to keep constant injection Specific forcing proportional to the forced variable Random normalized forcing Base class for specific forcing Specific forcing for pseudo-spectra solvers Specific forcing for pseudo-spectra solvers Time correlated random normalized forcing