MomentGauge.Models.Maxwellian
Contents
MomentGauge.Models.Maxwellian
#
Module Contents#
Classes#
The 1D Maxwell distribution. |
|
The 1D Maxwell distribution. |
|
The 1D Maxwell distribution with Gauge transformation. |
|
The 1D Maxwell distribution with Gauge transformation. |
Attributes#
- class MomentGauge.Models.Maxwellian.Maxwell_Legendre_1D(constant)#
Bases:
MomentGauge.Models.ExpFamilyBase.BaseExpFamilyModel
The 1D Maxwell distribution.
\begin{equation} \begin{split} f_0(\mathbf{u}) &= \exp\left( \beta_0 \phi_0(\mathbf{u}) + \beta_1 \phi_1(\mathbf{u}) + \beta_2 \phi_2(\mathbf{u} ) \right)\\ &= \frac{\rho}{m} \exp\left( \frac{m v_x}{k_B T}\phi_1(\mathbf{u}) -\frac{m}{2 k_B T} \phi_2(\mathbf{u}) - \left(\frac{m v_x^2}{2k_B T}+ \log \left(\frac{2\pi k_B T}{m}\right)^{\frac{3}{2}}\right) \right), \end{split} \end{equation}in which \(\rho\) is the number density, \(m\) is the molecule velocity, \(v_x\) is the flow velocity at the x direction, \(T\) is the temperature, and
\(\phi_0\) (u ) = 1.
\(\phi_1\) (u ) = \(u_x\)
\(\phi_2\) (u ) = \(u_x^2 + u_y^2 + u_z^2\).
- Parameters:
constant (dict) –
dictionary with the following keys
’m’ : float - the mass of particle considered
’kB’ : float - the Boltzmann constant
’n_x’ : int - the order of Gauss Legendre quadrature in x dimension. Required by
MomentGauge.Sampler.QuadratureSampler.Gauss_Legendre_Sampler_Polar3D
’n_r’ : int - the order of Gauss Legendre quadrature in r dimension.
’B_x’ : int - how many blocks are splitted in the x dimension for Gauss Legendre quadrature.
’B_r’ : int - how many blocks are splitted in the r dimension for Gauss Legendre quadrature.
’alpha’: float - the initial step size used in backtracking line search, default = 1. Required by
MomentGauge.Optim.NewtonOptimizer.Newton_Optimizer
’beta’: float - the decreasing factor of the step size used in backtracking line search, default = 0.5
’c’: float - the parameter used in the Armijo’s condiiton, must lies in (0,1), default = 5e-4
’atol’: float - the absolute error tolerance of the Armijo’s condiiton since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 5e-6.
’rtol’: float - the relative error tolerance of the Armijo’s condition since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 1e-5.
’max_iter’: int - the maximal iteration allowed for the Netwon’s method, default = 100
’max_back_tracking_iter’: int - the maximal iteration allowed for the backtracking line search, default = 25
’tol’: float - the tolerance for residual, below which the optimization stops.
’min_step_size’: float - the minimum step size given by back tracking, below which the optimization stops, default = 1e-6.
’reg_hessian’: bool - Regularize the Hessian if the Cholesky decomposition failed. Default = True
’debug’: bool - print debug information if True.
- m#
the mass of particle considered
- Type:
float
- kB#
the Boltzmann constant
- Type:
float
- constant#
dictionary with the keys containing ‘m’ and ‘kB’
- Type:
dict
- suff_statistics(u)#
Compute the value of sufficient statistics at certain \(\mathbf{u}\)
- Parameters:
u (float array of shape (3)) – The 3D sample vector
- Returns:
The array \(\{ \phi_0(\mathbf{u}), \phi_1(\mathbf{u}), \phi_2(\mathbf{u}) \}\)
- Return type:
float array of shape (3)
- natural_paras_to_moments(betas, domain)#
Compute the moments of sufficient statistics given natural parameters`
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The array \(\{ M_0, \cdots, M_M \}\)
- Return type:
float array of shape (M+1)
- moments_to_natural_paras(betas_ini, moments, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the moments of sufficient statistics.
- Parameters:
betas_ini (float array of shape (3)) – A set of proposed natural parameter \(\boldsymbol{\beta}\)
moments (float array of shape (3)) – the target moments that we expect exponential familty with the natural parameter \(\boldsymbol{\beta}\) to have.
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
A tuple containing
beta: float array of shape (M+1) - The natural parameters \(\boldsymbol{\beta}\)
opt_info: tuple - A tuple containing other information of the optimization process
values: float - the optimal value of target_function.
residuals: float - the residual of the optimization.
step: float - the total number of Newton’s step iteration.
bsteps: float - the total number of Backtracking step.
- Return type:
Tuple
- natural_paras_to_custom_moments(betas, domain, statistics, stats_gauge_paras=())#
Compute the moments of custom statistics given natural parameters.
Specific implementation of BaseExpFamilyModel should replace gauge_paras and base_args to explicit arguments.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
statistics (function) –
A float-valued or tensor-valued function \(\phi_{i_1,\cdots,i_k}\) ( u , \(*\) gauge_paras ) with
Parameters:
u : float array of shape (3) - The 3D sample vector \(\mathbf{u}\)
\(*\) gauge_paras : - Arbitrary many extra parameters such as \(\mathbf{g}\). The \(*\) refers to the unpacking operator in python.
Returns:
float or array of arbitrary shape \((d_1,\cdots,d_k)\) – the value of the statistic \(\phi_{i_1,\cdots,i_k}(\mathbf{u},\mathbf{g})\)
stats_gauge_paras (tuple) – A tuple ( para1, para2, … ) containing arbitrary many extra parameters the custom statistics function \(\phi_{i_1,\cdots,i_k}\) required. Defaut is (), an empty tuple.
- Returns:
The moment value \(M_{i_1,\cdots,i_k}(\mathbf{g})\)
- Return type:
float or array of arbitrary shape \((d_1,\cdots,d_k)\)
- natural_paras_to_fluid_properties(betas, domain)#
Compute the fluid properties including number density \(n\), density \(\rho\), flow velocities \(\mathbf{v} = \{v_\alpha, \alpha \in \{x,y,z\}\}\), temperature \(T\), pressure \(p\), stress \(\{\sigma_{\alpha \beta}, \alpha, \beta \in \{x,y,z\}\}\) and heat flux \(\{q_{\alpha}, \alpha \in \{x,y,z\}\}\).
\begin{equation} \begin{split} n &= \frac{\rho}{m}= \int f(\mathbf{u}) d^3 \mathbf{u} \\ v_\alpha &= \frac{1}{n}\int u_\alpha f(\mathbf{u}) d^3 \mathbf{u}\\ p &= n k_B T = \frac{1}{3} \int m c_\alpha c_\alpha f(\mathbf{u}) d^3 \mathbf{u} \\ \sigma_{\alpha\beta} &= \int m c_\alpha c_\beta f(\mathbf{u}) d^3 \mathbf{u} - p \delta_{\alpha\beta} \\ \epsilon &= \frac{3}{2} k_B T = \frac{1}{n}\int \frac{m}{2} \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u} \\ q_\alpha &= \int \frac{m}{2} c_\alpha \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u}; \quad \alpha, \beta \in \{x,y,z\} \end{split} \end{equation}in which \(m\) is the mass of gas molecule.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
Array containing macroscopic quantities \(\{ \rho, n, v_x, v_y, v_z, T, p, \sigma_{xx}, \sigma_{xy}, \sigma_{xz}, \sigma_{yy}, \sigma_{yz}, \sigma_{zz}, q_x, q_y, q_z \}\)
- Return type:
float array of shape (16)
- rhoVT_to_natural_paras(rhoVT, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the density \(\rho\), flow velocity \(v_x\) and temperature \(T\)
- Parameters:
rhoVT (float array of shape (3)) – A float array ( \(\rho\), \(v_x\), \(T\) )
- Returns:
The natural parameters \(\boldsymbol{\beta}\)
- Return type:
float array of shape (3)
- class MomentGauge.Models.Maxwellian.Maxwell_Canonical_Legendre_1D(constant)#
Bases:
Maxwell_Legendre_1D
,MomentGauge.Models.ExpFamilyBase.CanonicalExpFamilyModel
The 1D Maxwell distribution.
\begin{equation} \begin{split} f_0(\mathbf{u}) &= \beta_0 \exp\left( \beta_1 \phi_1(\mathbf{u}) + \beta_2 \phi_2(\mathbf{u} ) - \log Z \right)\\ &= \frac{\rho}{m} \exp\left( \frac{m v_x}{k_B T}\phi_1(\mathbf{u}) -\frac{m}{2 k_B T} \phi_2(\mathbf{u}) - \left(\frac{m v_x^2}{2k_B T}+ \log \left(\frac{2\pi k_B T}{m}\right)^{\frac{3}{2}}\right) \right), \end{split} \end{equation}in which \(\rho\) is the number density, \(m\) is the molecule velocity, \(v_x\) is the flow velocity at the x direction, \(T\) is the temperature, \(Z\) is the partition function, and
\(\phi_0\) (u ) = 1.
\(\phi_1\) (u ) = \(u_x\)
\(\phi_2\) (u ) = \(u_x^2 + u_y^2 + u_z^2\).
- Parameters:
constant (dict) –
dictionary with the following keys
’m’ : float - the mass of particle considered
’kB’ : float - the Boltzmann constant
’n_x’ : int - the order of Gauss Legendre quadrature in x dimension. Required by
MomentGauge.Sampler.QuadratureSampler.Gauss_Legendre_Sampler_Polar3D
’n_r’ : int - the order of Gauss Legendre quadrature in r dimension.
’B_x’ : int - how many blocks are splitted in the x dimension for Gauss Legendre quadrature.
’B_r’ : int - how many blocks are splitted in the r dimension for Gauss Legendre quadrature.
’alpha’: float - the initial step size used in backtracking line search, default = 1. Required by
MomentGauge.Optim.NewtonOptimizer.Newton_Optimizer
’beta’: float - the decreasing factor of the step size used in backtracking line search, default = 0.5
’c’: float - the parameter used in the Armijo’s condiiton, must lies in (0,1), default = 5e-4
’atol’: float - the absolute error tolerance of the Armijo’s condiiton since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 5e-6.
’rtol’: float - the relative error tolerance of the Armijo’s condition since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 1e-5.
’max_iter’: int - the maximal iteration allowed for the Netwon’s method, default = 100
’max_back_tracking_iter’: int - the maximal iteration allowed for the backtracking line search, default = 25
’tol’: float - the tolerance for residual, below which the optimization stops.
’min_step_size’: float - the minimum step size given by back tracking, below which the optimization stops, default = 1e-6.
’reg_hessian’: bool - Regularize the Hessian if the Cholesky decomposition failed. Default = True
’debug’: bool - print debug information if True.
- m#
the mass of particle considered
- Type:
float
- kB#
the Boltzmann constant
- Type:
float
- constant#
dictionary with the keys containing ‘m’ and ‘kB’
- Type:
dict
- rhoVT_to_natural_paras(rhoVT, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the density \(\rho\), flow velocity \(v_x\) and temperature \(T\)
- Parameters:
rhoVT (float array of shape (3)) – A float array ( \(\rho\), \(v_x\), \(T\) )
- Returns:
The natural parameters \(\boldsymbol{\beta}\)
- Return type:
float array of shape (3)
- suff_statistics(u)#
Compute the value of sufficient statistics at certain \(\mathbf{u}\)
- Parameters:
u (float array of shape (3)) – The 3D sample vector
- Returns:
The array \(\{ \phi_0(\mathbf{u}), \phi_1(\mathbf{u}), \phi_2(\mathbf{u}) \}\)
- Return type:
float array of shape (3)
- natural_paras_to_moments(betas, domain)#
Compute the moments of sufficient statistics given natural parameters`
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The array \(\{ M_0, \cdots, M_M \}\)
- Return type:
float array of shape (M+1)
- moments_to_natural_paras(betas_ini, moments, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the moments of sufficient statistics.
- Parameters:
betas_ini (float array of shape (3)) – A set of proposed natural parameter \(\boldsymbol{\beta}\)
moments (float array of shape (3)) – the target moments that we expect exponential familty with the natural parameter \(\boldsymbol{\beta}\) to have.
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
A tuple containing
beta: float array of shape (M+1) - The natural parameters \(\boldsymbol{\beta}\)
opt_info: tuple - A tuple containing other information of the optimization process
values: float - the optimal value of target_function.
residuals: float - the residual of the optimization.
step: float - the total number of Newton’s step iteration.
bsteps: float - the total number of Backtracking step.
- Return type:
Tuple
- natural_paras_to_custom_moments(betas, domain, statistics, stats_gauge_paras=())#
Compute the moments of custom statistics given natural parameters.
Specific implementation of BaseExpFamilyModel should replace gauge_paras and base_args to explicit arguments.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
statistics (function) –
A float-valued or tensor-valued function \(\phi_{i_1,\cdots,i_k}\) ( u , \(*\) gauge_paras ) with
Parameters:
u : float array of shape (3) - The 3D sample vector \(\mathbf{u}\)
\(*\) gauge_paras : - Arbitrary many extra parameters such as \(\mathbf{g}\). The \(*\) refers to the unpacking operator in python.
Returns:
float or array of arbitrary shape \((d_1,\cdots,d_k)\) – the value of the statistic \(\phi_{i_1,\cdots,i_k}(\mathbf{u},\mathbf{g})\)
stats_gauge_paras (tuple) – A tuple ( para1, para2, … ) containing arbitrary many extra parameters the custom statistics function \(\phi_{i_1,\cdots,i_k}\) required. Defaut is (), an empty tuple.
- Returns:
The moment value \(M_{i_1,\cdots,i_k}(\mathbf{g})\)
- Return type:
float or array of arbitrary shape \((d_1,\cdots,d_k)\)
- natural_paras_to_fluid_properties(betas, domain)#
Compute the fluid properties including number density \(n\), density \(\rho\), flow velocities \(\mathbf{v} = \{v_\alpha, \alpha \in \{x,y,z\}\}\), temperature \(T\), pressure \(p\), stress \(\{\sigma_{\alpha \beta}, \alpha, \beta \in \{x,y,z\}\}\) and heat flux \(\{q_{\alpha}, \alpha \in \{x,y,z\}\}\).
\begin{equation} \begin{split} n &= \frac{\rho}{m}= \int f(\mathbf{u}) d^3 \mathbf{u} \\ v_\alpha &= \frac{1}{n}\int u_\alpha f(\mathbf{u}) d^3 \mathbf{u}\\ p &= n k_B T = \frac{1}{3} \int m c_\alpha c_\alpha f(\mathbf{u}) d^3 \mathbf{u} \\ \sigma_{\alpha\beta} &= \int m c_\alpha c_\beta f(\mathbf{u}) d^3 \mathbf{u} - p \delta_{\alpha\beta} \\ \epsilon &= \frac{3}{2} k_B T = \frac{1}{n}\int \frac{m}{2} \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u} \\ q_\alpha &= \int \frac{m}{2} c_\alpha \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u}; \quad \alpha, \beta \in \{x,y,z\} \end{split} \end{equation}in which \(m\) is the mass of gas molecule.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
Array containing macroscopic quantities \(\{ \rho, n, v_x, v_y, v_z, T, p, \sigma_{xx}, \sigma_{xy}, \sigma_{xz}, \sigma_{yy}, \sigma_{yz}, \sigma_{zz}, q_x, q_y, q_z \}\)
- Return type:
float array of shape (16)
- class MomentGauge.Models.Maxwellian.Maxwell_Gauged_Legendre_1D(constant)#
Bases:
MomentGauge.Models.ExpFamilyBase.GaugedExpFamilyModel
,MomentGauge.Models.ExpFamilyBase.BaseExpFamilyModel
The 1D Maxwell distribution with Gauge transformation.
\begin{equation} \begin{split} f_0(\mathbf{u}) &= \exp\left( \beta_0 \phi_0(\mathbf{u},s, w_x) + \beta_1 \phi_1(\mathbf{u},s, w_x) + \beta_2 \phi_2(\mathbf{u} ,s, w_x) \right)\\ \end{split} \end{equation}in which \(\rho\) is the number density, \(m\) is the molecule velocity, \(v_x\) is the flow velocity at the x direction, \(T\) is the temperature, and
Specifically,
\(\phi_0\) (u, \(s, w_x\) ) = 1.
\(\phi_1\) (u, \(s, w_x\) ) = \(\bar{u}_x\)
\(\phi_2\) (u, \(s, w_x\) ) = \(\bar{u}_x^2 + \bar{u}_y^2 + \bar{u}_z^2\).
in which \(\bar{u}_x = \frac{u_x - w_x}{s}\), \(\bar{u}_y = \frac{u_y}{s}\), \(\bar{u}_z = \frac{u_z}{s}\)
- Parameters:
constant (dict) –
dictionary with the following keys
’m’ : float - the mass of particle considered
’kB’ : float - the Boltzmann constant
’n_x’ : int - the order of Gauss Legendre quadrature in x dimension. Required by
MomentGauge.Sampler.QuadratureSampler.Gauss_Legendre_Sampler_Polar3D
’n_r’ : int - the order of Gauss Legendre quadrature in r dimension.
’B_x’ : int - how many blocks are splitted in the x dimension for Gauss Legendre quadrature.
’B_r’ : int - how many blocks are splitted in the r dimension for Gauss Legendre quadrature.
’alpha’: float - the initial step size used in backtracking line search, default = 1. Required by
MomentGauge.Optim.NewtonOptimizer.Newton_Optimizer
’beta’: float - the decreasing factor of the step size used in backtracking line search, default = 0.5
’c’: float - the parameter used in the Armijo’s condiiton, must lies in (0,1), default = 5e-4
’atol’: float - the absolute error tolerance of the Armijo’s condiiton since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 5e-6.
’rtol’: float - the relative error tolerance of the Armijo’s condition since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 1e-5.
’max_iter’: int - the maximal iteration allowed for the Netwon’s method, default = 100
’max_back_tracking_iter’: int - the maximal iteration allowed for the backtracking line search, default = 25
’tol’: float - the tolerance for residual, below which the optimization stops.
’min_step_size’: float - the minimum step size given by back tracking, below which the optimization stops, default = 1e-6.
’reg_hessian’: bool - Regularize the Hessian if the Cholesky decomposition failed. Default = True
’debug’: bool - print debug information if True.
- m#
the mass of particle considered
- Type:
float
- kB#
the Boltzmann constant
- Type:
float
- constant#
dictionary with the keys containing ‘m’ and ‘kB’
- Type:
dict
- suff_statistics(u, gauge_paras)#
Compute the value of sufficient statistics at certain \(\mathbf{u}\)
- Parameters:
u (float array of shape (3)) – The 3D sample vector
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
The array \(\{ \phi_0(\mathbf{u}, s, w_x), \phi_1(\mathbf{u}, s, w_x), \phi_2(\mathbf{u}, s, w_x) \}\)
- Return type:
float array of shape (3)
- natural_paras_to_moments(betas, gauge_paras, domain)#
Compute the moments of sufficient statistics given natural parameters`
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\),:math:w_x).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The array \(\{ M_0, \cdots, M_M \}\)
- Return type:
float array of shape (3)
- moments_to_natural_paras(betas_ini, moments, gauge_paras, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the moments of sufficient statistics.
- Parameters:
betas_ini (float array of shape (3)) – A set of proposed natural parameter \(\boldsymbol{\beta}\)
moments (float array of shape (3)) – the target moments that we expect exponential familty with the natural parameter \(\boldsymbol{\beta}\) to have.
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
A tuple containing
beta: float array of shape (3) - The natural parameters \(\boldsymbol{\beta}\)
opt_info: tuple - A tuple containing other information of the optimization process
values: float - the optimal value of target_function.
residuals: float - the residual of the optimization.
step: float - the total number of Newton’s step iteration.
bsteps: float - the total number of Backtracking step.
- Return type:
Tuple
- natural_paras_to_custom_moments(betas, gauge_paras, domain, statistics, stats_gauge_paras=())#
Compute the moments of custom statistics given natural parameters.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
statistics (function) –
A float-valued or tensor-valued function \(\phi_{i_1,\cdots,i_k}\) ( u , \(*\) gauge_paras ) with
Parameters:
u : float array of shape (3) - The 3D sample vector \(\mathbf{u}\)
\(*\) gauge_paras : - Arbitrary many extra parameters such as \(\mathbf{g}\). The \(*\) refers to the unpacking operator in python.
Returns:
float or array of arbitrary shape \((d_1,\cdots,d_k)\) – the value of the statistic \(\phi_{i_1,\cdots,i_k}(\mathbf{u},\mathbf{g})\)
stats_gauge_paras (tuple) – A tuple ( para1, para2, … ) containing arbitrary many extra parameters the custom statistics function \(\phi_{i_1,\cdots,i_k}\) required. Defaut is (), an empty tuple.
- Returns:
The moment value \(M_{i_1,\cdots,i_k}(\mathbf{g})\)
- Return type:
float or array of arbitrary shape \((d_1,\cdots,d_k)\)
- moments_gauge_transformation(moments, gauge_para2, gauge_para1, domain)#
Gauge transformation for moments of sufficient statistics. The transformation is defined as
\begin{equation} M_i( s', w_x' )= T_{ij}(s', w_x', s, w_x) M_j(s, w_x); \quad i,j = 0, \cdots, 2 \end{equation}which is induced from the gauge transformation \(T_{ij}(\mathbf{g}',\mathbf{g})\) between sufficient statistics \(\phi_i(\mathbf{u},(s, w_x))\) such that
\begin{equation} \phi_i(\mathbf{u}, (s',w_x') )= T_{ij}(s', w_x',s, w_x) \phi_j(\mathbf{u}, (s, w_x)); \quad i,j = 0, \cdots, 2 \end{equation}with \(\phi_i(\mathbf{u},(s, w_x))\) is sufficient statistics parameterized by gauge parameters \((s, w_x)\).
- Parameters:
moments (float array of shape (3)) – the moments \(M_i(s, w_x)\) of sufficient statistics
gauge_para2 (float array of shape (2)) – The array (\(s'\), \(w_x'\)).
gauge_para1 (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
the moments \(M_i(s', w_x')\) of sufficient statistics
- Return type:
float array of shape (3)
- natural_paras_gauge_transformation(betas, gauge_para2, gauge_para1, domain)#
Gauge transformation for natural parameters. The transformation is defined as
\begin{equation} \beta_i( s', w_x' )= T_{ij}^T(s, w_x, s', w_x') \beta_j(s, w_x); \quad i,j = 0, \cdots, 2 \end{equation}which is induced from the gauge transformation \(T_{ij}(\mathbf{g}',\mathbf{g})\) between sufficient statistics \(\phi_i(\mathbf{u},\mathbf{g})\) such that
\begin{equation} \phi_i(\mathbf{u}, (s', w_x') )= T_{ij}(s', w_x',s, w_x) \phi_j(\mathbf{u}, (s, w_x)); \quad i,j = 0, \cdots, 2 \end{equation}with \(\phi_i(\mathbf{u},(s, w_x))\) is sufficient statistics parameterized by gauge parameters \((s, w_x)\).
- Parameters:
betas (float array of shape (3)) – the moments \(\beta_i(s, w_x)\) of sufficient statistics
gauge_para2 (float array of shape (2)) – The array (\(s'\), \(w_x'\)).
gauge_para1 (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
the moments \(\beta_i(s', w_x')\) of sufficient statistics
- Return type:
float array of shape (M+1)
- natural_paras_to_fluid_properties(betas, gauge_paras, domain)#
Compute the fluid properties including number density \(n\), density \(\rho\), flow velocities \(\mathbf{v} = \{v_\alpha, \alpha \in \{x,y,z\}\}\), temperature \(T\), pressure \(p\), stress \(\{\sigma_{\alpha \beta}, \alpha, \beta \in \{x,y,z\}\}\) and heat flux \(\{q_{\alpha}, \alpha \in \{x,y,z\}\}\).
\begin{equation} \begin{split} n &= \frac{\rho}{m}= \int f(\mathbf{u}) d^3 \mathbf{u} \\ v_\alpha &= \frac{1}{n}\int u_\alpha f(\mathbf{u}) d^3 \mathbf{u}\\ p &= n k_B T = \frac{1}{3} \int m c_\alpha c_\alpha f(\mathbf{u}) d^3 \mathbf{u} \\ \sigma_{\alpha\beta} &= \int m c_\alpha c_\beta f(\mathbf{u}) d^3 \mathbf{u} - p \delta_{\alpha\beta} \\ \epsilon &= \frac{3}{2} k_B T = \frac{1}{n}\int \frac{m}{2} \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u} \\ q_\alpha &= \int \frac{m}{2} c_\alpha \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u}; \quad \alpha, \beta \in \{x,y,z\} \end{split} \end{equation}in which \(m\) is the mass of gas molecule.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
Array containing macroscopic quantities \(\{ \rho, n, v_x, v_y, v_z, T, p, \sigma_{xx}, \sigma_{xy}, \sigma_{xz}, \sigma_{yy}, \sigma_{yz}, \sigma_{zz}, q_x, q_y, q_z \}\)
- Return type:
float array of shape (16)
- rhoVT_to_natural_paras(rhoVT, gauge_paras, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the density \(\rho\), flow velocity \(v_x\) and temperature \(T\)
- Parameters:
rhoVT (float array of shape (3)) – A float array ( \(\rho\), \(v_x\), \(T\) )
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The natural parameters \(\boldsymbol{\beta}\)
- Return type:
float array of shape (3)
- standard_gauge_para_from_moments(moments, gauge_paras)#
the standard gauge parameters \(\mathbf{g}\) prefered among all possible gauges.
- Parameters:
moments (float array of shape (3)) – the moments \(M_i(s, w_x)\) of sufficient statistics
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
The gauge parameters (\(s\), \(w_x\)) in the Hermite gauge.
- Return type:
float array of shape (2)
- class MomentGauge.Models.Maxwellian.Maxwell_Canonical_Gauged_Legendre_1D(constant)#
Bases:
Maxwell_Gauged_Legendre_1D
,MomentGauge.Models.ExpFamilyBase.CanonicalExpFamilyModel
The 1D Maxwell distribution with Gauge transformation.
\begin{equation} \begin{split} f_0(\mathbf{u}) &= \beta_0 \exp\left( \beta_1 \phi_1(\mathbf{u},s, w_x) + \beta_2 \phi_2(\mathbf{u} ,s, w_x) - \log Z(s, w_x) \right)\\ \end{split} \end{equation}in which \(\rho\) is the number density, \(m\) is the molecule velocity, \(v_x\) is the flow velocity at the x direction, \(T\) is the temperature, \(Z(s, w_x)\) is the partition function, and
Specifically,
\(\phi_0\) (u, \(s, w_x\) ) = 1.
\(\phi_1\) (u, \(s, w_x\) ) = \(\bar{u}_x\)
\(\phi_2\) (u, \(s, w_x\) ) = \(\bar{u}_x^2 + \bar{u}_y^2 + \bar{u}_z^2\).
in which \(\bar{u}_x = \frac{u_x - w_x}{s}\), \(\bar{u}_y = \frac{u_y}{s}\), \(\bar{u}_z = \frac{u_z}{s}\)
- Parameters:
constant (dict) –
dictionary with the following keys
’m’ : float - the mass of particle considered
’kB’ : float - the Boltzmann constant
’n_x’ : int - the order of Gauss Legendre quadrature in x dimension. Required by
MomentGauge.Sampler.QuadratureSampler.Gauss_Legendre_Sampler_Polar3D
’n_r’ : int - the order of Gauss Legendre quadrature in r dimension.
’B_x’ : int - how many blocks are splitted in the x dimension for Gauss Legendre quadrature.
’B_r’ : int - how many blocks are splitted in the r dimension for Gauss Legendre quadrature.
’alpha’: float - the initial step size used in backtracking line search, default = 1. Required by
MomentGauge.Optim.NewtonOptimizer.Newton_Optimizer
’beta’: float - the decreasing factor of the step size used in backtracking line search, default = 0.5
’c’: float - the parameter used in the Armijo’s condiiton, must lies in (0,1), default = 5e-4
’atol’: float - the absolute error tolerance of the Armijo’s condiiton since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 5e-6.
’rtol’: float - the relative error tolerance of the Armijo’s condition since we use -(atol + rtol*abs(next_value)) instead of 0 to handle single precision numerical error. default = 1e-5.
’max_iter’: int - the maximal iteration allowed for the Netwon’s method, default = 100
’max_back_tracking_iter’: int - the maximal iteration allowed for the backtracking line search, default = 25
’tol’: float - the tolerance for residual, below which the optimization stops.
’min_step_size’: float - the minimum step size given by back tracking, below which the optimization stops, default = 1e-6.
’reg_hessian’: bool - Regularize the Hessian if the Cholesky decomposition failed. Default = True
’debug’: bool - print debug information if True.
- m#
the mass of particle considered
- Type:
float
- kB#
the Boltzmann constant
- Type:
float
- constant#
dictionary with the keys containing ‘m’ and ‘kB’
- Type:
dict
- rhoVT_to_natural_paras(rhoVT, gauge_paras, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the density \(\rho\), flow velocity \(v_x\) and temperature \(T\)
- Parameters:
rhoVT (float array of shape (3)) – A float array ( \(\rho\), \(v_x\), \(T\) )
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The natural parameters \(\boldsymbol{\beta}\)
- Return type:
float array of shape (3)
- suff_statistics(u, gauge_paras)#
Compute the value of sufficient statistics at certain \(\mathbf{u}\)
- Parameters:
u (float array of shape (3)) – The 3D sample vector
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
The array \(\{ \phi_0(\mathbf{u}, s, w_x), \phi_1(\mathbf{u}, s, w_x), \phi_2(\mathbf{u}, s, w_x) \}\)
- Return type:
float array of shape (3)
- natural_paras_to_moments(betas, gauge_paras, domain)#
Compute the moments of sufficient statistics given natural parameters`
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\),:math:w_x).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
The array \(\{ M_0, \cdots, M_M \}\)
- Return type:
float array of shape (3)
- moments_to_natural_paras(betas_ini, moments, gauge_paras, domain)#
Compute the natural parameters \(\boldsymbol{\beta}\) from the moments of sufficient statistics.
- Parameters:
betas_ini (float array of shape (3)) – A set of proposed natural parameter \(\boldsymbol{\beta}\)
moments (float array of shape (3)) – the target moments that we expect exponential familty with the natural parameter \(\boldsymbol{\beta}\) to have.
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
A tuple containing
beta: float array of shape (3) - The natural parameters \(\boldsymbol{\beta}\)
opt_info: tuple - A tuple containing other information of the optimization process
values: float - the optimal value of target_function.
residuals: float - the residual of the optimization.
step: float - the total number of Newton’s step iteration.
bsteps: float - the total number of Backtracking step.
- Return type:
Tuple
- natural_paras_to_custom_moments(betas, gauge_paras, domain, statistics, stats_gauge_paras=())#
Compute the moments of custom statistics given natural parameters.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
statistics (function) –
A float-valued or tensor-valued function \(\phi_{i_1,\cdots,i_k}\) ( u , \(*\) gauge_paras ) with
Parameters:
u : float array of shape (3) - The 3D sample vector \(\mathbf{u}\)
\(*\) gauge_paras : - Arbitrary many extra parameters such as \(\mathbf{g}\). The \(*\) refers to the unpacking operator in python.
Returns:
float or array of arbitrary shape \((d_1,\cdots,d_k)\) – the value of the statistic \(\phi_{i_1,\cdots,i_k}(\mathbf{u},\mathbf{g})\)
stats_gauge_paras (tuple) – A tuple ( para1, para2, … ) containing arbitrary many extra parameters the custom statistics function \(\phi_{i_1,\cdots,i_k}\) required. Defaut is (), an empty tuple.
- Returns:
The moment value \(M_{i_1,\cdots,i_k}(\mathbf{g})\)
- Return type:
float or array of arbitrary shape \((d_1,\cdots,d_k)\)
- moments_gauge_transformation(moments, gauge_para2, gauge_para1, domain)#
Gauge transformation for moments of sufficient statistics. The transformation is defined as
\begin{equation} M_i( s', w_x' )= T_{ij}(s', w_x', s, w_x) M_j(s, w_x); \quad i,j = 0, \cdots, 2 \end{equation}which is induced from the gauge transformation \(T_{ij}(\mathbf{g}',\mathbf{g})\) between sufficient statistics \(\phi_i(\mathbf{u},(s, w_x))\) such that
\begin{equation} \phi_i(\mathbf{u}, (s',w_x') )= T_{ij}(s', w_x',s, w_x) \phi_j(\mathbf{u}, (s, w_x)); \quad i,j = 0, \cdots, 2 \end{equation}with \(\phi_i(\mathbf{u},(s, w_x))\) is sufficient statistics parameterized by gauge parameters \((s, w_x)\).
- Parameters:
moments (float array of shape (3)) – the moments \(M_i(s, w_x)\) of sufficient statistics
gauge_para2 (float array of shape (2)) – The array (\(s'\), \(w_x'\)).
gauge_para1 (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
the moments \(M_i(s', w_x')\) of sufficient statistics
- Return type:
float array of shape (3)
- natural_paras_gauge_transformation(betas, gauge_para2, gauge_para1, domain)#
Gauge transformation for natural parameters. The transformation is defined as
\begin{equation} \beta_i( s', w_x' )= T_{ij}^T(s, w_x, s', w_x') \beta_j(s, w_x); \quad i,j = 0, \cdots, 2 \end{equation}which is induced from the gauge transformation \(T_{ij}(\mathbf{g}',\mathbf{g})\) between sufficient statistics \(\phi_i(\mathbf{u},\mathbf{g})\) such that
\begin{equation} \phi_i(\mathbf{u}, (s', w_x') )= T_{ij}(s', w_x',s, w_x) \phi_j(\mathbf{u}, (s, w_x)); \quad i,j = 0, \cdots, 2 \end{equation}with \(\phi_i(\mathbf{u},(s, w_x))\) is sufficient statistics parameterized by gauge parameters \((s, w_x)\).
- Parameters:
betas (float array of shape (3)) – the moments \(\beta_i(s, w_x)\) of sufficient statistics
gauge_para2 (float array of shape (2)) – The array (\(s'\), \(w_x'\)).
gauge_para1 (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
the moments \(\beta_i(s', w_x')\) of sufficient statistics
- Return type:
float array of shape (M+1)
- natural_paras_to_fluid_properties(betas, gauge_paras, domain)#
Compute the fluid properties including number density \(n\), density \(\rho\), flow velocities \(\mathbf{v} = \{v_\alpha, \alpha \in \{x,y,z\}\}\), temperature \(T\), pressure \(p\), stress \(\{\sigma_{\alpha \beta}, \alpha, \beta \in \{x,y,z\}\}\) and heat flux \(\{q_{\alpha}, \alpha \in \{x,y,z\}\}\).
\begin{equation} \begin{split} n &= \frac{\rho}{m}= \int f(\mathbf{u}) d^3 \mathbf{u} \\ v_\alpha &= \frac{1}{n}\int u_\alpha f(\mathbf{u}) d^3 \mathbf{u}\\ p &= n k_B T = \frac{1}{3} \int m c_\alpha c_\alpha f(\mathbf{u}) d^3 \mathbf{u} \\ \sigma_{\alpha\beta} &= \int m c_\alpha c_\beta f(\mathbf{u}) d^3 \mathbf{u} - p \delta_{\alpha\beta} \\ \epsilon &= \frac{3}{2} k_B T = \frac{1}{n}\int \frac{m}{2} \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u} \\ q_\alpha &= \int \frac{m}{2} c_\alpha \mathbf{c}^2 f(\mathbf{u}) d^3 \mathbf{u}; \quad \alpha, \beta \in \{x,y,z\} \end{split} \end{equation}in which \(m\) is the mass of gas molecule.
- Parameters:
betas (float array of shape (3)) – the natural parameter \(\boldsymbol{\beta}\) of the distribution
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
domain (float array of shape (3)) –
an array (a_x, b_x, b_r), in which
a_x : float - lower integration limit in x dimension for the Legendre quadrature
b_x : float - upper integration limit in x dimension for the Legendre quadrature
b_r : float - upper integration limit in r dimension for the Legendre quadrature
- Returns:
Array containing macroscopic quantities \(\{ \rho, n, v_x, v_y, v_z, T, p, \sigma_{xx}, \sigma_{xy}, \sigma_{xz}, \sigma_{yy}, \sigma_{yz}, \sigma_{zz}, q_x, q_y, q_z \}\)
- Return type:
float array of shape (16)
- standard_gauge_para_from_moments(moments, gauge_paras)#
the standard gauge parameters \(\mathbf{g}\) prefered among all possible gauges.
- Parameters:
moments (float array of shape (3)) – the moments \(M_i(s, w_x)\) of sufficient statistics
gauge_paras (float array of shape (2)) – The array (\(s\), \(w_x\)).
- Returns:
The gauge parameters (\(s\), \(w_x\)) in the Hermite gauge.
- Return type:
float array of shape (2)
- MomentGauge.Models.Maxwellian.constant#