Skip to content

Commit

Permalink
fixed: one_of validator and added refinement_factor
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-flexcompute committed Aug 18, 2023
1 parent e67b318 commit 5b7588d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
4 changes: 3 additions & 1 deletion flow360/component/flow360_params/params_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def one_of(cls, values):
"""root validator for require one of"""
if cls.Config.require_one_of:
set_values = [key for key, v in values.items() if v is not None]
intersection = list(set(set_values) & set(cls.Config.require_one_of))
aliases = [cls._get_field_alias(field_name=name) for name in cls.Config.require_one_of]
aliases = [item for item in aliases if item is not None]
intersection = list(set(set_values) & set(cls.Config.require_one_of + aliases))
if len(intersection) == 0:
raise ConfigError(f"One of {cls.Config.require_one_of} is required.")
return values
Expand Down
1 change: 1 addition & 0 deletions flow360/component/meshing/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class VolumeMeshingParams(Flow360BaseModel):
"""

volume: Volume = pd.Field()
refinement_factor: Optional[PositiveFloat] = pd.Field(alias="refinementFactor")
farfield: Optional[Farfield] = pd.Field()
refinement: Optional[List[Union[BoxRefinement, CylinderRefinement]]] = pd.Field()
rotor_disks: Optional[List[RotorDisk]] = pd.Field(alias="rotorDisks")
Expand Down
2 changes: 1 addition & 1 deletion flow360/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
version
"""
__version__ = "0.2.0b11"
__version__ = "0.2.0b12"
2 changes: 1 addition & 1 deletion tests/test_flow360.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "0.2.0b11"
assert __version__ == "0.2.0b12"
17 changes: 16 additions & 1 deletion tests/test_flow360_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ def test_sliding_interface():

assert si

si = SlidingInterface.parse_raw(
"""
{
"stationaryPatches" : ["farField/rotationInterface"],
"rotatingPatches" : ["innerRotating/rotationInterface"],
"axisOfRotation" : [0,0,-1],
"centerOfRotation" : [0,0,0],
"omegaRadians" : 1.84691e-01,
"volumeName" : ["innerRotating"]
}
"""
)

assert si

si = SlidingInterface(
center=(0, 0, 0),
axis=(0, 0, 1),
Expand All @@ -314,7 +329,7 @@ def test_sliding_interface():
stationary_patches=["patch1"],
rotating_patches=["patch2"],
volume_name=[0, 1],
omega=1,
omegaRadians=1,
rpm=1,
)

Expand Down
43 changes: 42 additions & 1 deletion tests/test_meshing_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from flow360.component.meshing.params import (
Aniso,
BoxRefinement,
CylinderRefinement,
Edges,
Face,
Faces,
ProjectAniso,
RotorDisk,
SurfaceMeshingParams,
Volume,
VolumeMeshingParams,
)
from flow360.exceptions import ValidationError
Expand Down Expand Up @@ -148,7 +151,7 @@ def test_surface_meshing_params():
compare_to_ref(params, "ref/meshing_params/ref.yaml")


def test_volume_meshing_params():
def test_volume_meshing_params_from_obj():
params = VolumeMeshingParams.parse_obj(
{
"volume": {"firstLayerThickness": 1e-3},
Expand Down Expand Up @@ -246,3 +249,41 @@ def test_volume_meshing_sliding_interfaces():
}
)
print(params)


def test_volume_meshing_params():
box_refinement_left = BoxRefinement(
center=(3.6, -5, 0),
axis_of_rotation=(0.06052275, -0.96836405, 0),
angle_of_rotation=76,
size=(2, 2, 0.5),
spacing=0.1,
)
box_refinement_right = box_refinement_left.copy(update={"center": (3.6, 5, 0)})

rotor_disk_left = RotorDisk(
innerRadius=0.0,
outerRadius=2,
thickness=0.42,
axisThrust=(-0.96836405, -0.06052275, 0.24209101),
center=(3.6, -5, 0),
spacingAxial=0.03,
spacingRadial=0.09,
spacingCircumferential=0.09,
)
rotor_disk_right = rotor_disk_left.copy(update={"center": (3.6, 5, 0)})

params = VolumeMeshingParams(
refinement_factor=1,
volume=Volume(first_layer_thickness=1e-5),
refinement=[
box_refinement_left,
box_refinement_right,
BoxRefinement(center=(10, 0, 0), size=(20, 15, 10), spacing=1),
CylinderRefinement(
radius=0.75, length=11, spacing=0.2, axis=(1, 0, 0), center=(5, 0, 0)
),
],
rotor_disks=[rotor_disk_left, rotor_disk_right],
)
assert params

0 comments on commit 5b7588d

Please sign in to comment.