Skip to content

Commit 1b14fc3

Browse files
fix for darcy2d
1 parent ab77299 commit 1b14fc3

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

examples/darcy/darcy2d_v2.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,9 @@ def poisson_ref_compute_func(_in):
150150
validator = {residual_validator.name: residual_validator}
151151

152152
# set visualizer(optional)
153-
NPOINT_BC = NPOINT_TOP + NPOINT_BOTTOM + NPOINT_LEFT + NPOINT_RIGHT
154-
vis_interior_points = geom["rect"].sample_interior(NPOINT_PDE, evenly=True)
155-
vis_boundary_points = geom["rect"].sample_boundary(NPOINT_BC, evenly=True)
156-
157153
# manually collate input data for visualization,
158-
# interior+boundary
159-
vis_points = {}
160-
for key in vis_interior_points:
161-
vis_points[key] = np.concatenate(
162-
(vis_interior_points[key], vis_boundary_points[key])
163-
)
164-
154+
NPOINT_BC = NPOINT_TOP + NPOINT_BOTTOM + NPOINT_LEFT + NPOINT_RIGHT
155+
vis_points = geom["rect"].sample_interior(NPOINT_PDE + NPOINT_BC, evenly=True)
165156
visualizer = {
166157
"visulzie_u_v": ppsci.visualize.VisualizerVtu(
167158
vis_points,
@@ -194,6 +185,7 @@ def poisson_ref_compute_func(_in):
194185
solver.visualize()
195186

196187
# directly evaluate pretrained model(optional)
188+
logger.init_logger("ppsci", f"{output_dir}/eval.log", "info")
197189
solver = ppsci.solver.Solver(
198190
model,
199191
constraint,

ppsci/equation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"Laplace",
3131
"NavierStokes",
3232
"NormalDotVec",
33-
"Vibration",
3433
"Poisson",
34+
"Vibration",
3535
"build_equation",
3636
]
3737

ppsci/equation/pde/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
"Laplace",
2727
"NavierStokes",
2828
"NormalDotVec",
29-
"Vibration",
3029
"Poisson",
30+
"Vibration",
3131
]

ppsci/equation/pde/poisson.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ppsci.autodiff import hessian
16+
from ppsci.equation.pde import base
17+
18+
19+
class Poisson(base.PDE):
20+
"""Poisson
21+
22+
Args:
23+
dim (int): Dimension of equation.
24+
25+
Examples:
26+
>>> import ppsci
27+
>>> pde = ppsci.equation.Poisson(2)
28+
"""
29+
30+
def __init__(self, dim: int):
31+
super().__init__()
32+
self.dim = dim
33+
34+
def poisson_compute_func(out):
35+
invars = ("x", "y", "z")[: self.dim]
36+
poisson = 0
37+
for invar in invars:
38+
poisson += hessian(out["p"], out[invar])
39+
return poisson
40+
41+
self.add_equation("poisson", poisson_compute_func)

0 commit comments

Comments
 (0)