Skip to content

Add TimeAverageIsosurfaceOutput #1182

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions flow360/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
SurfaceOutput,
SurfaceProbeOutput,
SurfaceSliceOutput,
TimeAverageIsosurfaceOutput,
TimeAverageProbeOutput,
TimeAverageSliceOutput,
TimeAverageSurfaceOutput,
Expand Down Expand Up @@ -215,6 +216,7 @@
"SliceOutput",
"TimeAverageSliceOutput",
"IsosurfaceOutput",
"TimeAverageIsosurfaceOutput",
"SurfaceIntegralOutput",
"ProbeOutput",
"SurfaceProbeOutput",
Expand Down
47 changes: 47 additions & 0 deletions flow360/component/simulation/outputs/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,51 @@ class IsosurfaceOutput(_AnimationAndFileFormatSettings):
output_type: Literal["IsosurfaceOutput"] = pd.Field("IsosurfaceOutput", frozen=True)


class TimeAverageIsosurfaceOutput(IsosurfaceOutput):
"""

:class:`TimeAverageIsosurfaceOutput` class for isosurface output settings.

Example
-------

Define the :class:`TimeAverageIsosurfaceOutput` of :code:`qcriterion` on two isosurfaces:

- :code:`TimeAverageIsosurface_T_0.1` is the :class:`Isosurface` with its temperature equals
to 1.5 non-dimensional temperature;
- :code:`TimeAverageIsosurface_p_0.5` is the :class:`Isosurface` with its pressure equals
to 0.5 non-dimensional pressure.

>>> fl.TimeAverageIsosurfaceOutput(
... isosurfaces=[
... fl.Isosurface(
... name="TimeAverageIsosurface_T_0.1",
... iso_value=0.1,
... field="T",
... ),
... fl.Isosurface(
... name="TimeAverageIsosurface_p_0.5",
... iso_value=0.5,
... field="p",
... ),
... ],
... output_fields=["qcriterion"],
... )

====
"""

name: Optional[str] = pd.Field(
"Time Average Isosurface output", description="Name of `TimeAverageIsosurfaceOutput`."
)
start_step: Union[pd.NonNegativeInt, Literal[-1]] = pd.Field(
default=-1, description="Physical time step to start calculating averaging."
)
output_type: Literal["TimeAverageIsosurfaceOutput"] = pd.Field(
"TimeAverageIsosurfaceOutput", frozen=True
)


class SurfaceIntegralOutput(_OutputBase):
"""

Expand Down Expand Up @@ -991,6 +1036,7 @@ class StreamlineOutput(Flow360BaseModel):
SliceOutput,
TimeAverageSliceOutput,
IsosurfaceOutput,
TimeAverageIsosurfaceOutput,
SurfaceIntegralOutput,
ProbeOutput,
SurfaceProbeOutput,
Expand All @@ -1007,6 +1053,7 @@ class StreamlineOutput(Flow360BaseModel):
TimeAverageSurfaceOutput,
TimeAverageVolumeOutput,
TimeAverageSliceOutput,
TimeAverageIsosurfaceOutput,
TimeAverageProbeOutput,
TimeAverageSurfaceProbeOutput,
)
26 changes: 26 additions & 0 deletions flow360/component/simulation/translator/solver_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
SurfaceOutput,
SurfaceProbeOutput,
SurfaceSliceOutput,
TimeAverageIsosurfaceOutput,
TimeAverageProbeOutput,
TimeAverageSliceOutput,
TimeAverageSurfaceOutput,
Expand Down Expand Up @@ -438,6 +439,27 @@ def translate_isosurface_output(
return translated_output


def translate_time_average_isosurface_output(
output_params: list,
injection_function,
):
"""Translate time average isosurface output settings."""
translated_output = init_output_base(
output_params,
TimeAverageIsosurfaceOutput,
has_average_capability=True,
is_average=True,
)
translated_output["isoSurfaces"] = translate_setting_and_apply_to_all_entities(
output_params,
TimeAverageIsosurfaceOutput,
translation_func=translate_output_fields,
to_list=False,
entity_injection_func=injection_function,
)
return translated_output


def translate_surface_slice_output(
output_params: list,
output_class: Union[SurfaceSliceOutput],
Expand Down Expand Up @@ -635,6 +657,10 @@ def translate_output(input_params: SimulationParams, translated: dict):
translated["isoSurfaceOutput"] = translate_isosurface_output(
outputs, inject_isosurface_info
)
if has_instance_in_list(outputs, TimeAverageIsosurfaceOutput):
translated["timeAverageIsoSurfaceOutput"] = translate_time_average_isosurface_output(
outputs, inject_isosurface_info
)

##:: Step5: Get translated["monitorOutput"]
probe_output = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
ProbeOutput,
SliceOutput,
SurfaceOutput,
TimeAverageIsosurfaceOutput,
TimeAverageOutputTypes,
VolumeOutput,
)
from flow360.component.simulation.time_stepping.time_stepping import Steady, Unsteady
from flow360.component.simulation.utils import is_exact_instance
from flow360.component.simulation.validation.validation_context import (
ALL,
CASE,
Expand Down Expand Up @@ -477,6 +479,7 @@ def _check_duplicate_isosurface_names(outputs):
if outputs is None:
return outputs
isosurface_names = []
isosurface_time_avg_names = []
for output in outputs:
if isinstance(output, IsosurfaceOutput):
for entity in output.entities.items:
Expand All @@ -485,9 +488,19 @@ def _check_duplicate_isosurface_names(outputs):
"The name `qcriterion` is reserved for the autovis isosurface from solver, "
"please rename the isosurface."
)
if is_exact_instance(output, IsosurfaceOutput):
for entity in output.entities.items:
if entity.name in isosurface_names:
raise ValueError(
f"Another isosurface with name: `{entity.name}` already exists, please rename the isosurface."
)
isosurface_names.append(entity.name)
if is_exact_instance(output, TimeAverageIsosurfaceOutput):
for entity in output.entities.items:
if entity.name in isosurface_names:
raise ValueError(
"Another time average isosurface with name: "
f"`{entity.name}` already exists, please rename the isosurface."
)
isosurface_time_avg_names.append(entity.name)
return outputs