Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PPSCI Doc No.35-37】 #846

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion ppsci/equation/pde/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ def __init__(self):
def create_symbols(
symbol_str: str,
) -> Union[sympy.Symbol, Tuple[sympy.Symbol, ...]]:
"""Create symbols
"""create symbolic variables.

Args:
symbol_str (str): String contains symbols, such as "x", "x y z".

Returns:
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)
"""
return sympy.symbols(symbol_str)

Expand All @@ -64,6 +74,17 @@ def create_function(

Returns:
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)
"""
expr = sympy.Function(name)(*invars)

Expand All @@ -79,6 +100,17 @@ def add_equation(self, name: str, equation: Callable):
Args:
name (str): Name of equation
equation (Callable): Computation function for equation.

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
"""
self.equations.update({name: equation})

Expand Down