Equation(方程) 模块¶
ppsci.equation
¶
PDE
¶
Base class for Partial Differential Equation.
Source code in ppsci/equation/pde/base.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
add_equation(name, equation)
¶
Add an equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of equation |
required |
equation |
Callable
|
Computation function for equation. |
required |
Examples:
>>> import ppsci
>>> import sympy
>>> pde = ppsci.equation.PDE()
>>> x, y = pde.create_symbols('x y')
>>> u = x**2 + y**2
>>> equation = sympy.diff(u, x) + sympy.diff(u, y)
>>> pde.add_equation('linear_pde', equation)
>>> print(pde)
PDE
linear_pde: 2*x + 2*y
Source code in ppsci/equation/pde/base.py
create_function(name, invars)
¶
Create named function depending on given invars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Function name. such as "u", "v", and "f". |
required |
invars |
Tuple[Symbol, ...]
|
List of independent variable of function. |
required |
Returns:
Type | Description |
---|---|
Function
|
sympy.Function: Named sympy function. |
Examples:
>>> import ppsci
>>> pde = ppsci.equation.PDE()
>>> x, y, z = pde.create_symbols('x y z')
>>> u = pde.create_function('u', (x, y))
>>> f = pde.create_function('f', (x, y, z))
>>> print(u)
u(x, y)
>>> print(f)
f(x, y, z)
Source code in ppsci/equation/pde/base.py
create_symbols(symbol_str)
staticmethod
¶
Create symbolic variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol_str |
str
|
String contains symbols, such as "x", "x y z". |
required |
Returns:
Type | Description |
---|---|
Union[Symbol, Tuple[Symbol, ...]]
|
Union[sympy.Symbol, Tuple[sympy.Symbol, ...]]: Created symbol(s). |
Examples:
>>> import ppsci
>>> pde = ppsci.equation.PDE()
>>> symbol_x = pde.create_symbols('x')
>>> symbols_xyz = pde.create_symbols('x y z')
>>> print(symbol_x)
x
>>> print(symbols_xyz)
(x, y, z)
Source code in ppsci/equation/pde/base.py
parameters()
¶
Return learnable parameters contained in PDE.
Returns:
Type | Description |
---|---|
List[Tensor]
|
List[Tensor]: A list of learnable parameters. |
Examples:
>>> import ppsci
>>> pde = ppsci.equation.Vibration(2, -4, 0)
>>> print(pde.parameters())
[Parameter containing:
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=False,
-4.), Parameter containing:
Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=False,
0.)]
Source code in ppsci/equation/pde/base.py
set_state_dict(state_dict)
¶
Set state dict from dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
Dict[str, Tensor]
|
The state dict to be set. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]]
|
Tuple[List[str], List[str]]: List of missing_keys and unexpected_keys. Expected to be two empty tuples mostly. |
Examples:
>>> import paddle
>>> import ppsci
>>> paddle.set_default_dtype("float64")
>>> pde = ppsci.equation.Vibration(2, -4, 0)
>>> state = pde.state_dict()
>>> state['0'] = paddle.to_tensor(-3.1)
>>> pde.set_state_dict(state)
([], [])
>>> print(state)
OrderedDict([('0', Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=True,
-3.10000000)), ('1', Parameter containing:
Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False,
0.))])
Source code in ppsci/equation/pde/base.py
state_dict()
¶
Return named learnable parameters in dict.
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
Dict[str, Tensor]: A dict of states(str) and learnable parameters(Tensor). |
Examples:
>>> import ppsci
>>> pde = ppsci.equation.Vibration(2, -4, 0)
>>> print(pde.state_dict())
OrderedDict([('0', Parameter containing:
Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False,
-4.)), ('1', Parameter containing:
Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False,
0.))])
Source code in ppsci/equation/pde/base.py
AllenCahn
¶
Bases: PDE
Class for Allen-Cahn equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eps |
float
|
Represents the characteristicscale of interfacial width, influencing the thickness and dynamics of phase boundaries. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/allen_cahn.py
Biharmonic
¶
Bases: PDE
Class for biharmonic equation with supporting special load.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim |
int
|
Dimension of equation. |
required |
q |
Union[float, str, Basic]
|
Load. |
required |
D |
Union[float, str]
|
Rigidity. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/biharmonic.py
FractionalPoisson
¶
Bases: PDE
(TODO)Docstring of this class will be refined in the future.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
Alpha. |
required |
geom |
Geometry
|
Computation geometry. |
required |
resolution |
Tuple[int, ...]
|
Resolution. |
required |
Examples:
>>> import ppsci
>>> geom_disk = ppsci.geometry.Disk([0, 0], 1)
>>> ALPHA = 0.5
>>> fpde = ppsci.equation.FractionalPoisson(ALPHA, geom_disk, [8, 100])
Source code in ppsci/equation/fpde/fractional_poisson.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
HeatExchanger
¶
Bases: PDE
Class for heat exchanger equation.
where:
- \(T\) is temperature,
- \(q_m\) is mass flow rate,
- \(c_p\) represents specific heat capacity,
- \(v\) denotes flow velocity,
- \(L\) stands for flow length,
- \(\eta_{\mathrm{o}}\) signifies fin surface efficiency,
- \(\alpha\) stands for heat transfer coefficient,
- \(A\) indicates heat transfer area,
- \(M\) represents the mass of the heat transfer structure,
- \(\tau\) correspond to time,
- \(x\) correspond flow direction,
- Subscripts \(\mathrm{h}\), \(\mathrm{c}\), and \(\mathrm{w}\) denote the hot fluid side, cold fluid side, and heat transfer wall, respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha_h |
Union[float, str]
|
\(\frac{(\eta_o\alpha A)_h}{L(c_p)_h}\) |
required |
alpha_c |
Union[float, str]
|
\(\frac{(\eta_o\alpha A)_c}{L(c_p)_c}\) |
required |
v_h |
Union[float, str]
|
\(v_h\) |
required |
v_c |
Union[float, str]
|
\(v_c\) |
required |
w_h |
Union[float, str]
|
\(\frac{(\eta_o\alpha A)_h}{M(c_p)_w}\) |
required |
w_c |
Union[float, str]
|
\(\frac{(\eta_o\alpha A)_c}{M(c_p)_w}\) |
required |
Examples:
Source code in ppsci/equation/pde/heat_exchanger.py
Laplace
¶
Bases: PDE
Class for laplace equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim |
int
|
Dimension of equation. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/laplace.py
LinearElasticity
¶
Bases: PDE
Linear elasticity equations.
Use either (E, nu) or (lambda_, mu) to define the material properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
E |
Optional[Union[float, str]]
|
The Young's modulus. Defaults to None. |
None
|
nu |
Optional[Union[float, str]]
|
The Poisson's ratio. Defaults to None. |
None
|
lambda_ |
Optional[Union[float, str]]
|
Lamé's first parameter. Defaults to None. |
None
|
mu |
Optional[Union[float, str]]
|
Lamé's second parameter (shear modulus). Defaults to None. |
None
|
rho |
Union[float, str]
|
Mass density. Defaults to 1. |
1
|
dim |
int
|
Dimension of the linear elasticity (2 or 3). Defaults to 3. |
3
|
time |
bool
|
Whether contains time data. Defaults to False. |
False
|
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> pde = ppsci.equation.LinearElasticity(
... E=None, nu=None, lambda_=1e4, mu=100, dim=3
... )
Source code in ppsci/equation/pde/linear_elasticity.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
NavierStokes
¶
Bases: PDE
Class for navier-stokes equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu |
Union[float, str]
|
Dynamic viscosity. |
required |
rho |
Union[float, str]
|
Density. |
required |
dim |
int
|
Dimension of equation. |
required |
time |
bool
|
Whether the equation is time-dependent. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/navier_stokes.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
NormalDotVec
¶
Bases: PDE
Normal Dot Vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec_keys |
Tuple[str, ...]
|
Keys for vectors, such as ("u", "v", "w") for velocity vector. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/normal_dot_vec.py
Poisson
¶
Bases: PDE
Class for poisson equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim |
int
|
Dimension of equation. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples:
Source code in ppsci/equation/pde/poisson.py
Vibration
¶
Bases: PDE
Vortex induced vibration equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho |
float
|
Generalized mass. |
required |
k1 |
float
|
Learnable parameter for modal damping. |
required |
k2 |
float
|
Learnable parameter for generalized stiffness. |
required |
Examples:
Source code in ppsci/equation/pde/viv.py
Volterra
¶
Bases: PDE
A second kind of volterra integral equation with Gaussian quadrature algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bound |
float
|
Lower bound |
required |
num_points |
int
|
Sampled points in integral interval. |
required |
quad_deg |
int
|
Number of quadrature. |
required |
kernel_func |
Callable
|
Kernel func |
required |
func |
Callable
|
|
required |
Examples:
>>> import ppsci
>>> import numpy as np
>>> vol_eq = ppsci.equation.Volterra(
... 0, 12, 20, lambda t, s: np.exp(s - t), lambda out: out["u"],
... )
Source code in ppsci/equation/ide/volterra.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
get_quad_points(t)
¶
Scale and transform quad_x from [-1, 1] to range [a, b].
reference: https://en.wikipedia.org/wiki/Gaussian_quadrature#Change_of_interval
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
Tensor
|
Tensor array of upper bounds 't' for integral. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
paddle.Tensor: Transformed points in desired range with shape of [N, Q]. |
Source code in ppsci/equation/ide/volterra.py
NLSMB
¶
Bases: PDE
Class for nonlinear Schrodinger-Maxwell-Bloch equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha_1 |
Union[float, str]
|
Group velocity dispersion. |
required |
alpha_2 |
Union[float, str]
|
Kerr nonlinearity. |
required |
omega_0 |
Union[float, str]
|
The offset of resonance frequency. |
required |
time |
bool
|
Whether the equation is time-dependent. |
required |
detach_keys |
Optional[Tuple[str, ...]]
|
Keys used for detach during computing. Defaults to None. |
None
|
Examples: