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]

Bases: SpecificForcing

Specific forcing for pseudo-spectra solvers

compute()[source]

compute the forcing.

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

Bases: SpecificForcingPseudoSpectralSimple

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

Inheritance diagram of InScriptForcingPseudoSpectral
compute_forcing_fft_each_time()[source]

Compute the coarse forcing in Fourier space

compute_forcing_each_time()[source]

Compute the coarse forcing in real space

monkeypatch_compute_forcing_fft_each_time(func)[source]

Replace the method by a user-defined method

monkeypatch_compute_forcing_each_time(func)[source]

Replace the method by a user-defined method

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

Bases: SpecificForcing

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 indicating shape of the forcing array.

shape: array-like

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

put_forcingc_in_forcing()[source]

Copy data from self.fstate_coarse.state_spect into forcing_fft.

verify_injection_rate()[source]

Verify injection rate.

verify_injection_rate_coarse(var_fft=None)[source]

Verify injection rate.

compute()[source]

compute a forcing normalize with a 2nd degree eq.

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

Bases: SpecificForcingPseudoSpectralCoarse

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

Inheritance diagram of InScriptForcingPseudoSpectralCoarse
compute_forcingc_fft_each_time()[source]

Compute the coarse forcing in Fourier space

compute_forcingc_each_time()[source]

Compute the coarse forcing in real space

monkeypatch_compute_forcingc_fft_each_time(func)[source]

Replace the method by a user-defined method

monkeypatch_compute_forcingc_each_time(func)[source]

Replace the method by a user-defined method

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

Bases: SpecificForcingPseudoSpectralCoarse

Specific forcing normalized to keep constant injection

Inheritance diagram of NormalizedForcing
classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

compute()[source]

compute a forcing normalize with a 2nd degree eq.

normalize_forcingc(fa_fft, a_fft, key_forced=None)[source]

Normalize the coarse forcing

normalize_forcingc_part_k(fvc_fft, vc_fft, key_forced=None)[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(fvc_fft, vc_fft, key_forced=None)[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(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]

Bases: SpecificForcingPseudoSpectralCoarse

Specific forcing proportional to the forced variable

Inheritance diagram of Proportional
compute()[source]

compute a forcing normalize with a 2nd degree eq.

forcingc_raw_each_time(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]

Bases: NormalizedForcing

Random normalized forcing

Inheritance diagram of RandomSimplePseudoSpectral
classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

compute_forcingc_raw()[source]

Random coarse forcing.

To be called only with proc 0.

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

Bases: RandomSimplePseudoSpectral

Time correlated random normalized forcing

Inheritance diagram of TimeCorrelatedRandomPseudoSpectral
classmethod _complete_params_with_default(params)[source]

This static method is used to complete the params container.

forcingc_raw_each_time(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()[source]

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

Classes

InScriptForcingPseudoSpectral(sim)

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

InScriptForcingPseudoSpectralCoarse(sim)

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

NormalizedForcing(sim)

Specific forcing normalized to keep constant injection

Proportional(sim)

Specific forcing proportional to the forced variable

RandomSimplePseudoSpectral(sim)

Random normalized forcing

SpecificForcing(sim)

Base class for specific forcing

SpecificForcingPseudoSpectralCoarse(sim)

Specific forcing for pseudo-spectra solvers

SpecificForcingPseudoSpectralSimple(sim)

Specific forcing for pseudo-spectra solvers

TimeCorrelatedRandomPseudoSpectral(sim)

Time correlated random normalized forcing