Skip to content

Commit

Permalink
Merge branch 'develop' into fix_doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrogenSulfate committed Mar 25, 2024
2 parents 0e6dcba + a9dd9f8 commit f9d29b9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/zh/examples/chip_heat.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $$
$$

<figure markdown>
![domain_chip.pdf](https://paddle-org.bj.bcebos.com/paddlescience/docs/ChipHeat/domain_chip.pdf){ loading=lazy style="height:80%;width:80%" align="center" }
![domain_chip.pdf](https://paddle-org.bj.bcebos.com/paddlescience/docs/ChipHeat/domain_chip.PNG){ loading=lazy style="height:80%;width:80%" align="center" }
<figcaption> 内部具有随机热源分布的 2D 芯片模拟区域,边界上可以为任意的边界条件。</figcaption>
</figure>

Expand Down Expand Up @@ -94,7 +94,7 @@ PI-DeepONet模型,将 DeepONet 和 PINN 方法相结合,是一种结合了
对于芯片热仿真问题,PI-DeepONet 模型可以表示为如图所示的模型结构:

<figure markdown>
![pi_deeponet.pdf](https://paddle-org.bj.bcebos.com/paddlescience/docs/ChipHeat/pi_deeponet.pdf){ loading=lazy style="height:80%;width:80%" align="center" }
![pi_deeponet.pdf](https://paddle-org.bj.bcebos.com/paddlescience/docs/ChipHeat/pi_deeponet.PNG){ loading=lazy style="height:80%;width:80%" align="center" }
</figure>

如图所示,我们一共使用了 3 个分支网络和一个主干网络,分支网络分别输入边界类型指标、随机热源分布 $S(x, y)$ 和边界函数 $Q(x, y)$,主干网络输入二维坐标点坐标信息。每个分支网和主干网均输出 $q$ 维特征向量,通过 Hadamard(逐元素)乘积组合所有这些输出特征,然后将所得向量相加为预测温度场的标量输出。
Expand Down
2 changes: 1 addition & 1 deletion ppsci/data/dataset/era5_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ERA5SampledDataset(io.Dataset):
>>> dataset_size = len(dataset) # doctest: +SKIP
>>> # get the first sample of the data
>>> first_sample = dataset[0] # doctest: +SKIP
>>> print("First sample:", first_sample)
>>> print("First sample:", first_sample) # doctest: +SKIP
"""

def __init__(
Expand Down
76 changes: 76 additions & 0 deletions ppsci/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def from_pymesh(cls, mesh: "pymesh.Mesh") -> "Mesh":
Returns:
Mesh: Instantiated ppsci.geometry.Mesh object.
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP
>>> mesh = ppsci.geometry.Mesh.from_pymesh(box) # doctest: +SKIP
>>> print(mesh.vertices) # doctest: +SKIP
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
"""
# check if pymesh is installed when using Mesh Class
if not checker.dynamic_import_to_globals(["pymesh"]):
Expand Down Expand Up @@ -182,6 +198,40 @@ def translate(self, translation: np.ndarray, relative: bool = True) -> "Mesh":
Returns:
Mesh: Translated Mesh object.
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP
>>> mesh = ppsci.geometry.Mesh(box) # doctest: +SKIP
>>> print(mesh.vertices) # doctest: +SKIP
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
>>> print(mesh.translate((-0.5, 0, 0.5), False).vertices) # the center is moved to the translation vector. # doctest: +SKIP
[[-1. -0.5 0. ]
[ 0. -0.5 0. ]
[ 0. 0.5 0. ]
[-1. 0.5 0. ]
[-1. -0.5 1. ]
[ 0. -0.5 1. ]
[ 0. 0.5 1. ]
[-1. 0.5 1. ]]
>>> print(mesh.translate((-0.5, 0, 0.5), True).vertices) # the translation vector is directly added to the geometry coordinates # doctest: +SKIP
[[-0.5 0. 0.5]
[ 0.5 0. 0.5]
[ 0.5 1. 0.5]
[-0.5 1. 0.5]
[-0.5 0. 1.5]
[ 0.5 0. 1.5]
[ 0.5 1. 1.5]
[-0.5 1. 1.5]]
"""
vertices = np.array(self.vertices, dtype=paddle.get_default_dtype())
faces = np.array(self.faces)
Expand Down Expand Up @@ -221,6 +271,32 @@ def scale(
Returns:
Mesh: Scaled Mesh object.
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1])) # doctest: +SKIP
>>> mesh = ppsci.geometry.Mesh(box) # doctest: +SKIP
>>> print(mesh.vertices) # doctest: +SKIP
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
>>> mesh = mesh.scale(2, (0.25, 0.5, 0.75)) # doctest: +SKIP
>>> print(mesh.vertices) # doctest: +SKIP
[[-0.25 -0.5 -0.75]
[ 1.75 -0.5 -0.75]
[ 1.75 1.5 -0.75]
[-0.25 1.5 -0.75]
[-0.25 -0.5 1.25]
[ 1.75 -0.5 1.25]
[ 1.75 1.5 1.25]
[-0.25 1.5 1.25]]
"""
vertices = np.array(self.vertices, dtype=paddle.get_default_dtype())
faces = np.array(self.faces, dtype=paddle.get_default_dtype())
Expand Down
4 changes: 2 additions & 2 deletions ppsci/utils/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def save_csv_file(
... use_header=True,
... delimiter=",",
... encoding="utf-8",
... )
... ) # doctest: +SKIP
>>> # == test.csv ==
>>> # A,B
Expand Down Expand Up @@ -150,7 +150,7 @@ def save_tecplot_file(
... num_y=3,
... alias_dict={"X": "x", "Y": "y"},
... num_timestamps=2,
... )
... ) # doctest: +SKIP
>>> # == test_t-0.dat ==
>>> # title = "./test_t-0.dat"
>>> # variables = "X", "Y"
Expand Down

0 comments on commit f9d29b9

Please sign in to comment.