Skip to content

Commit dff2e5b

Browse files
Add geometry refinement and other GAI related options (#1355)
* Add geometry refinement and other GAI related options * Fix formatting * Added geometry refinement explicit cast * Fix some comments * Fix black * Address more comments * Finish adding unit tests * Fix lint and isort * Address comments * Fix json reference unit test failures --------- Co-authored-by: Ben <106089368+benflexcompute@users.noreply.github.com>
1 parent 82c5916 commit dff2e5b

File tree

15 files changed

+124
-21
lines changed

15 files changed

+124
-21
lines changed

flow360/cloud/flow360_requests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class _Resource(Flow360RequestsV2):
160160

161161
class NewReportRequest(Flow360RequestsV2):
162162
"New report request"
163+
163164
name: str
164165
resources: List[_Resource]
165166
config_json: str

flow360/cloud/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""utils for cloud operations
2-
"""
1+
"""utils for cloud operations"""
32

43
from enum import Enum
54

flow360/component/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Constants file
2-
"""
1+
"""Constants file"""
32

43

54
# pylint: disable=invalid-name,too-few-public-methods

flow360/component/interfaces.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""webAPI interface definitions
2-
"""
1+
"""webAPI interface definitions"""
32

43
from typing import Union
54

flow360/component/simulation/meshing_param/face_params.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,47 @@ def ensure_surface_existence(cls, value):
4646
return check_deleted_surface_in_entity_list(value)
4747

4848

49+
class GeometryRefinement(Flow360BaseModel):
50+
"""
51+
Setting for refining surface elements for given `Surface`.
52+
53+
Example
54+
-------
55+
56+
>>> fl.GeometryRefinement(
57+
... faces=[geometry["face1"], geometry["face2"]],
58+
... geometry_accuracy=0.001*fl.u.m
59+
... )
60+
61+
====
62+
"""
63+
64+
name: Optional[str] = pd.Field("Surface refinement")
65+
refinement_type: Literal["GeometryRefinement"] = pd.Field("GeometryRefinement", frozen=True)
66+
entities: EntityList[Surface] = pd.Field(alias="faces")
67+
# pylint: disable=no-member
68+
69+
geometry_accuracy: LengthType.Positive = pd.Field(
70+
description="The smallest length scale that will be resolved accurately by the surface meshing process. "
71+
)
72+
73+
@pd.field_validator("entities", mode="after")
74+
@classmethod
75+
def ensure_surface_existence(cls, value):
76+
"""Ensure all boundaries will be present after mesher"""
77+
return check_deleted_surface_in_entity_list(value)
78+
79+
@pd.model_validator(mode="after")
80+
def ensure_geometry_ai(self):
81+
"""Ensure feature is only activated with geometry AI enabled."""
82+
validation_info = get_validation_info()
83+
if validation_info is None:
84+
return self
85+
if not validation_info.use_geometry_AI:
86+
raise ValueError("GeometryRefinement is only supported by geometry AI.")
87+
return self
88+
89+
4990
class PassiveSpacing(Flow360BaseModel):
5091
"""
5192
Passively control the mesh spacing either through adjecent `Surface`'s meshing

flow360/component/simulation/meshing_param/params.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from flow360.component.simulation.meshing_param.edge_params import SurfaceEdgeRefinement
1212
from flow360.component.simulation.meshing_param.face_params import (
1313
BoundaryLayer,
14+
GeometryRefinement,
1415
PassiveSpacing,
1516
SurfaceRefinement,
1617
)
@@ -35,6 +36,7 @@
3536
Union[
3637
SurfaceEdgeRefinement,
3738
SurfaceRefinement,
39+
GeometryRefinement,
3840
BoundaryLayer,
3941
PassiveSpacing,
4042
UniformRefinement,
@@ -70,7 +72,8 @@ class MeshingDefaults(Flow360BaseModel):
7072
geometry_accuracy: Optional[LengthType.Positive] = pd.Field(
7173
None,
7274
description="The smallest length scale that will be resolved accurately by the surface meshing process. "
73-
"This parameter is only valid when using geometry AI.",
75+
"This parameter is only valid when using geometry AI."
76+
"It can be overridden with class: ~flow360.GeometryRefinement.",
7477
)
7578

7679
##:: Default surface edge settings
@@ -105,7 +108,7 @@ class MeshingDefaults(Flow360BaseModel):
105108
" This is only supported by the beta mesher and can not be overridden per face.",
106109
)
107110

108-
planar_face_tolerance: pd.NonNegativeFloat = pd.Field(
111+
planar_face_tolerance: Optional[pd.NonNegativeFloat] = pd.Field(
109112
DEFAULT_PLANAR_FACE_TOLERANCE,
110113
description="Tolerance used for detecting planar faces in the input surface mesh / geometry"
111114
" that need to be remeshed, such as symmetry planes."
@@ -121,7 +124,21 @@ class MeshingDefaults(Flow360BaseModel):
121124
" This can be overridden with :class:`~flow360.SurfaceRefinement`.",
122125
context=SURFACE_MESH,
123126
)
124-
curvature_resolution_angle: AngleType.Positive = ContextField(
127+
128+
surface_max_aspect_ratio: Optional[pd.PositiveFloat] = ConditionalField(
129+
10.0,
130+
description="Maximum aspect ratio for surface cells for the GAI surface mesher."
131+
" This cannot be overridden per face",
132+
context=SURFACE_MESH,
133+
)
134+
135+
surface_max_adaptation_iterations: Optional[pd.NonNegativeInt] = ConditionalField(
136+
50,
137+
description="Maximum adaptation iterations for the GAI surface mesher.",
138+
context=SURFACE_MESH,
139+
)
140+
141+
curvature_resolution_angle: Optional[AngleType.Positive] = ContextField(
125142
12 * u.deg,
126143
description=(
127144
"Default maximum angular deviation in degrees. This value will restrict:"
@@ -161,6 +178,24 @@ def invalid_geometry_accuracy(cls, value):
161178
raise ValueError("Geometry accuracy is required when geometry AI is used.")
162179
return value
163180

181+
@pd.field_validator(
182+
"surface_max_aspect_ratio", "surface_max_adaptation_iterations", mode="after"
183+
)
184+
@classmethod
185+
def invalid_geometry_ai_features(cls, value, info):
186+
"""Ensure surface max aspect ratio is not specified when GAI is not used"""
187+
validation_info = get_validation_info()
188+
189+
if validation_info is None:
190+
return value
191+
192+
# pylint: disable=unsubscriptable-object
193+
default_value = cls.model_fields[info.field_name].default
194+
if value != default_value and not validation_info.use_geometry_AI:
195+
raise ValueError(f"{info.field_name} is only supported when geometry AI is used.")
196+
197+
return value
198+
164199

165200
class MeshingParams(Flow360BaseModel):
166201
"""
@@ -200,6 +235,7 @@ class MeshingParams(Flow360BaseModel):
200235
+ "and first layer thickness will be adjusted to generate `r`-times"
201236
+ " finer mesh where r is the refinement_factor value.",
202237
)
238+
203239
gap_treatment_strength: Optional[float] = ContextField(
204240
default=0,
205241
ge=0,

flow360/component/simulation/models/solver_numerics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contains basic components(solvers) that composes the `volume` type models.
33
Each volume model represents a physical phenomena that require a combination of solver features to model.
44
5-
E.g.
5+
E.g.
66
NavierStokes, turbulence and transition composes FluidDynamics `volume` type
77
88
"""

flow360/component/simulation/operating_condition/atmosphere_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
""" U.S. STANDARD ATMOSPHERE 1976
1+
"""U.S. STANDARD ATMOSPHERE 1976
22
# https://www.ngdc.noaa.gov/stp/space-weather/online-publications/miscellaneous/us-standard-atmosphere-1976/us-standard-atmosphere_st76-1562_noaa.pdf
33
Source: design 360
4-
"""
4+
"""
55

66
from math import exp
77

flow360/component/simulation/primitives.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ class GeometryBodyGroup(EntityBase):
166166
transformation: Transformation = pd.Field(
167167
Transformation(), description="The transformation performed on the body group"
168168
)
169+
mesh_exterior: bool = pd.Field(
170+
True,
171+
description="Option to define whether to mesh exterior or interior of body group in geometry AI."
172+
"Note that this is a beta feature and the interface might change in future releases.",
173+
)
169174

170175

171176
class _VolumeEntityBase(EntityBase, metaclass=ABCMeta):

flow360/component/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Defines 'types' that various fields can be """
1+
"""Defines 'types' that various fields can be"""
22

33
from typing import List, Optional, Tuple
44

0 commit comments

Comments
 (0)