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

Sink 2d #431

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open

Sink 2d #431

wants to merge 28 commits into from

Conversation

wangguan1995
Copy link
Contributor

PR types

New features, Bug fixes

PR changes

Describe

  • Add first heat transfer case of 3-fins 2D sink (Advection-Diffusion).
  • Complement and add traits like sdf, geometry, sampling, geometry bool, sdf derivative, symbol function, etc.
  • Important Bug fix for N-S equation.
  • New equations: GradNormal, AdvectionDiffusion, ZeroEquation.
  • Doc will be submit in next PR.

@paddle-bot
Copy link

paddle-bot bot commented Jul 18, 2023

Thanks for your contribution!

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件先不改

Comment on lines 30 to 32
OUTPUT_DIR = (
"./output" if not args.output_dir else args.output_dir
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. 去掉括号
  2. 文件夹名字: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
Copy link
Collaborator

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

删掉冗余换行

Comment on lines 90 to 95
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"))
Copy link
Collaborator

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),
    ...
}

@@ -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
Copy link
Collaborator

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")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要去掉sdf_func基类,通过hasattr判断sdf是否计算

@@ -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"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

现在几何都有sdf_func,可以删掉这个判断

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不是所有的几何都有sdf_func, 如果不判断,会有部分CI挂掉

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

删除print

def sdf_func(self, points: np.ndarray) -> np.ndarray:
pass

def sdf_gradient(self, points, delta=(0.0001,)) -> np.ndarray:
Copy link
Collaborator

Choose a reason for hiding this comment

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

-> Dict[str, np.ndarray]


def sdf_gradient(self, points, delta=(0.0001,)) -> np.ndarray:
delta = delta * self.ndim
sdf_grad = misc.Prettydefaultdict()
Copy link
Collaborator

Choose a reason for hiding this comment

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

普通字典就行

Comment on lines 120 to 123
if hasattr(self, "sdf_gradient"):
sdf_grad_dict = self.sdf_gradient(x)
else:
sdf_grad_dict = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

删掉判断

Copy link
Contributor Author

Choose a reason for hiding this comment

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

暂时无法删除判断,不是所有几何都需要sdf_gradient

Comment on lines 201 to 209
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}
Copy link
Collaborator

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, ...):
    ....

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"):
Copy link
Collaborator

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].
Copy link
Collaborator

Choose a reason for hiding this comment

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

[]=>()

>>> geom = ppsci.geometry.channel((0.0, 0.0), (1.0, 1.0))
"""

def __init__(self, xmin, xmax):
Copy link
Collaborator

Choose a reason for hiding this comment

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

加上 type hint

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dict[str, float]


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}
Copy link
Collaborator

Choose a reason for hiding this comment

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

var -> key

for index in time_index:
file = filename_without_timeid + f"{index}.vtu"
if "t" in input_dict:
file = filename_without_timeid + f"{index}.vtu"
Copy link
Collaborator

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"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

np.asarray

Copy link
Contributor Author

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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

改回去

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants