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

[Feature] Replace python funcion with sympy expression #507

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2d95737
add sympy2func
AndPuQing Aug 9, 2023
f8bb795
fix node
AndPuQing Aug 10, 2023
b31a785
fix var name
AndPuQing Aug 10, 2023
d9d30d1
fix implementation
AndPuQing Aug 13, 2023
6877901
Merge branch 'develop' into feature-sympy
HydrogenSulfate Aug 23, 2023
2ccc9f5
add sympy to func module
HydrogenSulfate Aug 24, 2023
bb9d71c
add type hint and clean code
HydrogenSulfate Aug 24, 2023
8783ec9
update unitest for N-S equation with sympy-base 'nu'
HydrogenSulfate Aug 25, 2023
6f376b6
delete redundant sympy2func.py
HydrogenSulfate Aug 25, 2023
cfa853f
remove sympy to function code from expression.py to sym_to_func.py
HydrogenSulfate Aug 25, 2023
62e9855
update type hint in expression
HydrogenSulfate Aug 26, 2023
fee4553
update code
HydrogenSulfate Aug 26, 2023
1b7642e
update code
HydrogenSulfate Aug 26, 2023
1538f0d
update code
HydrogenSulfate Aug 26, 2023
36e48e5
refine sym_to_func.py
HydrogenSulfate Aug 26, 2023
d32fd84
replace sympy PDE for biharmonic and laplace
HydrogenSulfate Aug 26, 2023
4e61fa5
refine sym_to_func.py
HydrogenSulfate Aug 27, 2023
4baf466
fix bug in _cvt_to_key
HydrogenSulfate Aug 27, 2023
ba2a5c2
refine sym_to_func and expression code
HydrogenSulfate Aug 27, 2023
f057eec
add euler_beam static code(WIP, can not running, to be debug)
HydrogenSulfate Aug 27, 2023
ffd6b27
wip code
HydrogenSulfate Aug 28, 2023
0809194
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Aug 28, 2023
b0d1df1
temporary code(need to be refined)
HydrogenSulfate Aug 28, 2023
2fa8a8b
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Sep 6, 2023
b2a4509
update solver code
HydrogenSulfate Sep 6, 2023
13d6ff6
replace more pdes with sympy
HydrogenSulfate Sep 6, 2023
ffd3a93
simplify code in solver
HydrogenSulfate Sep 6, 2023
256f31a
update code
HydrogenSulfate Sep 7, 2023
3a870d9
rename 'normal_dot_vel' to 'normal_dot_vec'
HydrogenSulfate Sep 7, 2023
08e92d3
fix bug
HydrogenSulfate Sep 7, 2023
c2373ca
update unitest
HydrogenSulfate Sep 7, 2023
051dcd6
remove redundant unitest
HydrogenSulfate Sep 7, 2023
2eacfea
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Sep 7, 2023
c7eea1b
remove unnecessary code
HydrogenSulfate Sep 7, 2023
615fefb
remove unnecessary more code
HydrogenSulfate Sep 7, 2023
e096ea2
use DETACH_FUNC_NAME instead of 'detach'
HydrogenSulfate Sep 7, 2023
cb16107
add derivatives for sdf function
HydrogenSulfate Sep 7, 2023
899a2d2
replace .diff.diff with .diff(, 2)
HydrogenSulfate Sep 10, 2023
640c080
support exporting expression to .dot and .png file for visualizing an…
HydrogenSulfate Sep 10, 2023
16aae52
remove compute_sdf_derivatives for next PR
HydrogenSulfate Sep 10, 2023
9b46410
refine docstring of ppsci/data/dataset/array_dataset.py
HydrogenSulfate Sep 10, 2023
f179ec1
remove sdf_derivatives code in geometry for next PR
HydrogenSulfate Sep 10, 2023
2e37bca
remove print code in solver
HydrogenSulfate Sep 10, 2023
6ecb31b
rename sympy_to_function to lambdify and add it in ppsci.*
HydrogenSulfate Sep 10, 2023
0a88a08
rename for test files
HydrogenSulfate Sep 11, 2023
18a1638
rename sym_to_func.py to symbolic.py
HydrogenSulfate Sep 12, 2023
8ccf858
update linear_init_ and conv_init_ to kaiming style
HydrogenSulfate Sep 12, 2023
978cdfc
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Sep 12, 2023
a319e99
refine probability document
HydrogenSulfate Sep 12, 2023
be67fb4
change list to tuple
HydrogenSulfate Sep 12, 2023
eecc5e9
update docstrings of equations
HydrogenSulfate Sep 13, 2023
cb7f777
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Sep 13, 2023
59bc990
Merge branch 'develop' into cvt_pyfunc_to_sym
HydrogenSulfate Sep 13, 2023
c0228f0
larger atol to 1e-7 for test_linear_elasticity
HydrogenSulfate Sep 13, 2023
408e378
fix seed to 42 for test_linear_elasticity
HydrogenSulfate Sep 13, 2023
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
Prev Previous commit
Next Next commit
update docstrings of equations
  • Loading branch information
HydrogenSulfate committed Sep 13, 2023
commit eecc5e9d3f1a984c8ca939fae14f4ae2cb4ea319
11 changes: 7 additions & 4 deletions ppsci/equation/pde/biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from typing import Optional
from typing import Tuple
from typing import Union

from ppsci.equation.pde import base

Expand All @@ -29,8 +30,10 @@ class Biharmonic(base.PDE):

Args:
dim (int): Dimension of equation.
q (float): Load.
D (float): Rigidity.
q (Union[float, str]): Load.
D (Union[float, str]): Rigidity.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand All @@ -40,8 +43,8 @@ class Biharmonic(base.PDE):
def __init__(
self,
dim: int,
q: float,
D: float,
q: Union[float, str],
D: Union[float, str],
detach_keys: Optional[Tuple[str, ...]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新docstring, 检查类型提示

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

):
super().__init__()
Expand Down
2 changes: 2 additions & 0 deletions ppsci/equation/pde/laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Laplace(base.PDE):

Args:
dim (int): Dimension of equation.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand Down
23 changes: 13 additions & 10 deletions ppsci/equation/pde/linear_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from typing import Optional
from typing import Tuple
from typing import Union

import sympy as sp

Expand All @@ -38,13 +39,15 @@ class LinearElasticity(base.PDE):
$$

Args:
E (Optional[float]): The Young's modulus. Defaults to None.
nu (Optional[float]): The Poisson's ratio. Defaults to None.
lambda_ (Optional[float]): Lamé's first parameter. Defaults to None.
mu (Optional[float]): Lamé's second parameter (shear modulus). Defaults to None.
rho (float, optional): Mass density. Defaults to 1.
E (Optional[Union[float, str]]): The Young's modulus. Defaults to None.
nu (Optional[Union[float, str]]): The Poisson's ratio. Defaults to None.
lambda_ (Optional[Union[float, str]]): Lamé's first parameter. Defaults to None.
mu (Optional[Union[float, str]]): Lamé's second parameter (shear modulus). Defaults to None.
rho (Union[float, str], optional): Mass density. Defaults to 1.
dim (int, optional): Dimension of the linear elasticity (2 or 3). Defaults to 3.
time (bool, optional): Whether contains time data. Defaults to False.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand All @@ -55,11 +58,11 @@ class LinearElasticity(base.PDE):

def __init__(
self,
E: Optional[float] = None,
nu: Optional[float] = None,
lambda_: Optional[float] = None,
mu: Optional[float] = None,
rho: float = 1,
E: Optional[Union[float, str]] = None,
nu: Optional[Union[float, str]] = None,
lambda_: Optional[Union[float, str]] = None,
mu: Optional[Union[float, str]] = None,
rho: Union[float, str] = 1,
dim: int = 3,
time: bool = False,
detach_keys: Optional[Tuple[str, ...]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新docstring

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Expand Down
22 changes: 12 additions & 10 deletions ppsci/equation/pde/navier_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from __future__ import annotations

from typing import Callable
from typing import Optional
from typing import Tuple
from typing import Union
Expand Down Expand Up @@ -55,10 +54,12 @@ class NavierStokes(base.PDE):
$$

Args:
nu (Union[float, Callable]): Dynamic viscosity.
rho (float): Density.
nu (Union[float, str]): Dynamic viscosity.
rho (Union[float, str]): Density.
dim (int): Dimension of equation.
time (bool): Whether the euqation is time-dependent.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand All @@ -67,31 +68,32 @@ class NavierStokes(base.PDE):

def __init__(
self,
nu: Union[float, Callable],
rho: float,
nu: Union[float, str],
rho: Union[float, str],
dim: int,
time: bool,
detach_keys: Optional[Tuple[str, ...]] = None,
):
super().__init__()
self.detach_keys = detach_keys
self.dim = dim
self.time = time

t, x, y, z = self.create_symbols("t x y z")
invars = (x, y)
if time:
invars = (t,) + invars
if dim == 3:
invars += (z,)

self.nu = nu
self.rho = rho
self.dim = dim
self.time = time

if isinstance(nu, str):
nu = self.create_function(nu, invars)
if isinstance(rho, str):
rho = self.create_function(rho, invars)

self.nu = nu
self.rho = rho

u = self.create_function("u", invars)
v = self.create_function("v", invars)
w = self.create_function("w", invars) if dim == 3 else sp.Number(0)
Expand Down
4 changes: 3 additions & 1 deletion ppsci/equation/pde/normal_dot_vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class NormalDotVec(base.PDE):
Args:
vec_keys (Tuple[str, ...]): Keys for vectors, such as ("u", "v", "w") for
velocity vector.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand All @@ -49,7 +51,7 @@ def __init__(
normals = self.create_symbols("normal_x normal_y normal_z")

normal_dot_vec = 0
for (vec, normal) in zip(vec_vars, normals):
for (normal, vec) in zip(normals, vec_vars):
normal_dot_vec += normal * vec

self.add_equation("normal_dot_vec", normal_dot_vec)
2 changes: 2 additions & 0 deletions ppsci/equation/pde/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Poisson(base.PDE):

Args:
dim (int): Dimension of equation.
detach_keys(Optional[Tuple[str, ...]]): Keys used for detach during computing.
Defaults to None.

Examples:
>>> import ppsci
Expand Down