Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions flow360/component/simulation/outputs/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from flow360.component.simulation.validation.validation_utils import (
check_deleted_surface_in_entity_list,
)
from flow360.log import log


class UserDefinedField(Flow360BaseModel):
Expand Down Expand Up @@ -327,6 +328,19 @@ def ensure_surface_existence(cls, value):
"""Ensure all boundaries will be present after mesher"""
return check_deleted_surface_in_entity_list(value)

@pd.model_validator(mode="after")
def ensure_write_single_file_supported(self):
"""Ensure write_single_file is supported for chosen output format"""
if self.write_single_file:
if self.output_format == "paraview":
raise ValueError("write_single_file is only supported for Tecplot output format.")
if self.output_format == "both":
log.warning(
"write_single_file is only supported for Tecplot output format. "
+ "Paraview files will be still saved separately."
)
return self


class TimeAverageSurfaceOutput(SurfaceOutput):
"""
Expand Down
27 changes: 27 additions & 0 deletions tests/simulation/params/test_validators_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,30 @@ def test_output_frequency_settings_in_steady_simulation():
assert err["type"] == exp_err["type"]
assert err["ctx"]["relevant_for"] == exp_err["ctx"]["relevant_for"]
assert err["msg"] == exp_err["msg"]


def test_surface_output_write_single_file_validator():
with pytest.raises(
ValueError,
match=re.escape("write_single_file is only supported for Tecplot output format."),
):
SurfaceOutput(
write_single_file=True,
entities=[Surface(name="noSlipWall")],
output_fields=["Cp"],
output_format="paraview",
)

SurfaceOutput(
write_single_file=True,
entities=[Surface(name="noSlipWall")],
output_fields=["Cp"],
output_format="tecplot",
)

SurfaceOutput(
write_single_file=True,
entities=[Surface(name="noSlipWall")],
output_fields=["Cp"],
output_format="both",
)
4 changes: 4 additions & 0 deletions tests/simulation/params/test_validators_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def surface_output_with_wall_metric():
name="surface",
surfaces=[Surface(name="noSlipWall")],
write_single_file=True,
output_format="tecplot",
output_fields=["wallFunctionMetric"],
)
return surface_output
Expand All @@ -149,6 +150,7 @@ def surface_output_with_low_mach_precond():
name="surface",
surfaces=[Surface(name="noSlipWall")],
write_single_file=True,
output_format="tecplot",
output_fields=["lowMachPreconditionerSensor"],
)
return surface_output
Expand All @@ -160,6 +162,7 @@ def surface_output_with_numerical_dissipation():
name="surface",
surfaces=[Surface(name="noSlipWall")],
write_single_file=True,
output_format="tecplot",
output_fields=["numericalDissipationFactor"],
)
return surface_output
Expand Down Expand Up @@ -462,6 +465,7 @@ def test_cht_solver_settings_validator(
name="surface",
surfaces=[Surface(name="noSlipWall")],
write_single_file=True,
output_format="tecplot",
output_fields=["residualHeatSolver"],
)

Expand Down
1 change: 1 addition & 0 deletions tests/simulation/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ def test_solver_translation():
name="surface",
surfaces=[Surface(name="noSlipWall")],
write_single_file=True,
output_format="tecplot",
output_fields=["residualHeatSolver"],
)
water = Water(
Expand Down