Skip to content

Commit

Permalink
Add velocity direction validator (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
angranl-flex authored Jan 2, 2025
1 parent 56643f2 commit f245a2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flow360/component/simulation/models/surface_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ class Inflow(BoundaryBaseWithTurbulenceQuantities):
description="Specify the total pressure or the mass flow rate at the `Inflow` boundary.",
)

@pd.model_validator(mode="after")
def _check_velocity_direction_in_subsonic_inflow(self):
"""
Check to ensure velocity_direction can only be specified for Subsonic Inflow Boundary.
"""
if self.velocity_direction and not isinstance(self.spec, TotalPressure):
raise ValueError("The velocity_direction can only be specified for Subsonic Inflow.")
return self


class SlipWall(BoundaryBase):
""":class:`SlipWall` class defines the :code:`SlipWall` boundary condition.
Expand Down
18 changes: 18 additions & 0 deletions tests/simulation/params/test_validators_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from flow360.component.simulation.models.solver_numerics import TransitionModelSolver
from flow360.component.simulation.models.surface_models import (
Freestream,
Inflow,
MassFlowRate,
Periodic,
SlipWall,
Translational,
Expand Down Expand Up @@ -678,3 +680,19 @@ def test_meshing_validator_dual_context():
assert errors[0]["type"] == "missing"
assert errors[0]["ctx"] == {"relevant_for": ["SurfaceMesh", "VolumeMesh"]}
assert errors[0]["loc"] == ("meshing",)


def test_velocity_direction_in_subsonic_inflow():
msg = "The velocity_direction can only be specified for Subsonic Inflow."
with SI_unit_system, pytest.raises(ValueError, match=re.escape(msg)):
entity_surface = Surface(name="Inflow Surface")
SimulationParams(
models=[
Inflow(
velocity_direction=(0, 0, 1),
total_temperature=300 * u.K,
spec=MassFlowRate(value=123 * u.lb / u.s),
surfaces=entity_surface,
)
],
)

0 comments on commit f245a2f

Please # to comment.