-
Notifications
You must be signed in to change notification settings - Fork 129
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
Sink 2d #431
base: develop
Are you sure you want to change the base?
Sink 2d #431
Conversation
Thanks for your contribution! |
examples/bracket/bracket.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个文件先不改
OUTPUT_DIR = ( | ||
"./output" if not args.output_dir else args.output_dir | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 去掉括号
- 文件夹名字:output_heat_sink
"./output" if not args.output_dir else args.output_dir | ||
) | ||
logger.init_logger("ppsci", f"{OUTPUT_DIR}/train.log", "info") | ||
shuffle = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不必要的shuffle变量,删掉
heat_sink = heat_sink + fin | ||
|
||
geo = channel - heat_sink | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删掉冗余换行
equation = ppsci.utils.misc.Prettydefaultdict() | ||
equation["ZeroEquation"] = ppsci.equation.ZeroEquation(0.01, max_distance) | ||
equation["NavierStokes"] = ppsci.equation.NavierStokes(equation["ZeroEquation"].expr, 1.0, 2, False, True) | ||
equation["AdvectionDiffusion"] = ppsci.equation.AdvectionDiffusion("c", diffusivity, 1.0, 0, 2, False) | ||
equation["GradNormal"] = ppsci.equation.GradNormal(grad_var="c", dim=2, time=False) | ||
equation["NormalDotVec"] = ppsci.equation.NormalDotVec(("u", "v")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要使用 Prettydefaultdict
equation = {
"ZeroEquation": ppsci.equation.ZeroEquation(0.01, max_distance),
...
}
ppsci/geometry/geometry.py
Outdated
@@ -63,6 +63,20 @@ def uniform_points(self, n: int, boundary=True): | |||
) | |||
return self.random_points(n) | |||
|
|||
def sdf_func(self, points: np.ndarray) -> np.ndarray: | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise NotImplementedError("Geometry.sdf_func is not implemented")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要去掉sdf_func基类,通过hasattr判断sdf是否计算
ppsci/geometry/geometry.py
Outdated
@@ -95,14 +109,33 @@ def sample_interior(self, n, random="pseudo", criteria=None, evenly=False): | |||
"please check correctness of geometry and given creteria." | |||
) | |||
|
|||
# if sdf_func added, return x_dict and sdf_dict, else, only return the x_dict | |||
# if sdf_fun/sdf_grad/area added, | |||
# return x_dict and sdf_dict/sdf_grad_dict/area_dict, else, only return the x_dict | |||
if hasattr(self, "sdf_func"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在几何都有sdf_func,可以删掉这个判断
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是所有的几何都有sdf_func, 如果不判断,会有部分CI挂掉
ppsci/geometry/geometry.py
Outdated
if hasattr(self, "sdf_func"): | ||
sdf = -self.sdf_func(x) | ||
sdf_dict = misc.convert_to_dict(sdf, ("sdf",)) | ||
else: | ||
sdf_dict = {} | ||
|
||
if hasattr(self, "sdf_gradient"): | ||
print("sdf_grad") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除print
ppsci/geometry/geometry.py
Outdated
def sdf_func(self, points: np.ndarray) -> np.ndarray: | ||
pass | ||
|
||
def sdf_gradient(self, points, delta=(0.0001,)) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> Dict[str, np.ndarray]
ppsci/geometry/geometry.py
Outdated
|
||
def sdf_gradient(self, points, delta=(0.0001,)) -> np.ndarray: | ||
delta = delta * self.ndim | ||
sdf_grad = misc.Prettydefaultdict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
普通字典就行
ppsci/geometry/geometry.py
Outdated
if hasattr(self, "sdf_gradient"): | ||
sdf_grad_dict = self.sdf_gradient(x) | ||
else: | ||
sdf_grad_dict = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删掉判断
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暂时无法删除判断,不是所有几何都需要sdf_gradient
ppsci/geometry/geometry.py
Outdated
if self.ndim == 2: | ||
if (criteria is not None) and (misc.typename(self) == "Line"): | ||
area = self.approx_area(criteria) | ||
elif criteria is None: | ||
area = self.perimeter | ||
else: | ||
raise NotImplementedError("self.approx_area is not implemented") | ||
area_dict = {"area": np.full_like(next(iter(x_dict.values())), area / n)} | ||
return {**x_dict, **normal_dict, **area_dict} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(self, ...):
....
elif isinstance(self, ...):
....
ppsci/geometry/geometry_2d.py
Outdated
np.linalg.norm(np.maximum(dist_from_center, 0), axis=1) | ||
+ np.minimum(np.max(dist_from_center, axis=1), 0) | ||
).reshape(-1, 1) | ||
|
||
def approx_area(self, criteria=None, approx_nr=10000, random="pseudo"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_approximate_area
"""Class for channel geometry (no bounding curves in x-direction for sdf calculation) | ||
|
||
Args: | ||
xmin (Tuple[float, float]): Bottom left corner point, [x0, y0]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]=>()
ppsci/geometry/geometry_2d.py
Outdated
>>> geom = ppsci.geometry.channel((0.0, 0.0), (1.0, 1.0)) | ||
""" | ||
|
||
def __init__(self, xmin, xmax): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加上 type hint
ppsci/utils/reader.py
Outdated
csv_name (str): str type, prefix of the csv file name. | ||
epoch_id (int): int type, the current epoch id. | ||
name (str): str type, the name of the data to be written. | ||
data (dict): type, the data to be written, with string keys and numeric values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dict[str, float]
ppsci/utils/reader.py
Outdated
|
||
Returns: | ||
Dict[str, np.ndarray]: Input coordinates dict, label coordinates dict | ||
""" | ||
input_dict = {var: [] for var in input_keys} | ||
label_dict = {var: [] for var in label_keys} | ||
label_dict = {} if label_keys is None else {var: [] for var in label_keys} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var -> key
ppsci/utils/reader.py
Outdated
for index in time_index: | ||
file = filename_without_timeid + f"{index}.vtu" | ||
if "t" in input_dict: | ||
file = filename_without_timeid + f"{index}.vtu" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.path.join
@@ -153,6 +194,12 @@ def load_vtk_file( | |||
mesh.points[:, i].reshape(n, 1).astype("float32") | |||
) | |||
i += 1 | |||
|
|||
for key in input_dict_patch: | |||
input_dict_patch[key].append(np.array(mesh.point_data[key], "float32")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.asarray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.asarray
?
@@ -61,7 +61,7 @@ class SupervisedValidator(base.Validator): | |||
def __init__( | |||
self, | |||
dataloader_cfg: Dict[str, Any], | |||
loss: loss.Loss, | |||
loss: Optional[loss.Loss] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改回去
PR types
New features, Bug fixes
PR changes
Describe