Skip to content

Commit 3eafa19

Browse files
【PPSCI Doc No.35-37】 (#846)
* docs: add examples for api No.35-37 * Update ppsci/equation/pde/base.py * Update ppsci/equation/pde/base.py * Update ppsci/equation/pde/base.py --------- Co-authored-by: HydrogenSulfate <[email protected]>
1 parent 2fd294c commit 3eafa19

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

ppsci/equation/pde/base.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ def __init__(self):
4343
def create_symbols(
4444
symbol_str: str,
4545
) -> Union[sympy.Symbol, Tuple[sympy.Symbol, ...]]:
46-
"""Create symbols
46+
"""create symbolic variables.
4747
4848
Args:
4949
symbol_str (str): String contains symbols, such as "x", "x y z".
5050
5151
Returns:
5252
Union[sympy.Symbol, Tuple[sympy.Symbol, ...]]: Created symbol(s).
53+
54+
Examples:
55+
>>> import ppsci
56+
>>> pde = ppsci.equation.PDE()
57+
>>> symbol_x = pde.create_symbols('x')
58+
>>> symbols_xyz = pde.create_symbols('x y z')
59+
>>> print(symbol_x)
60+
x
61+
>>> print(symbols_xyz)
62+
(x, y, z)
5363
"""
5464
return sympy.symbols(symbol_str)
5565

@@ -64,6 +74,17 @@ def create_function(
6474
6575
Returns:
6676
sympy.Function: Named sympy function.
77+
78+
Examples:
79+
>>> import ppsci
80+
>>> pde = ppsci.equation.PDE()
81+
>>> x, y, z = pde.create_symbols('x y z')
82+
>>> u = pde.create_function('u', (x, y))
83+
>>> f = pde.create_function('f', (x, y, z))
84+
>>> print(u)
85+
u(x, y)
86+
>>> print(f)
87+
f(x, y, z)
6788
"""
6889
expr = sympy.Function(name)(*invars)
6990

@@ -79,6 +100,17 @@ def add_equation(self, name: str, equation: Callable):
79100
Args:
80101
name (str): Name of equation
81102
equation (Callable): Computation function for equation.
103+
104+
Examples:
105+
>>> import ppsci
106+
>>> import sympy
107+
>>> pde = ppsci.equation.PDE()
108+
>>> x, y = pde.create_symbols('x y')
109+
>>> u = x**2 + y**2
110+
>>> equation = sympy.diff(u, x) + sympy.diff(u, y)
111+
>>> pde.add_equation('linear_pde', equation)
112+
>>> print(pde)
113+
PDE, linear_pde: 2*x + 2*y
82114
"""
83115
self.equations.update({name: equation})
84116

0 commit comments

Comments
 (0)