Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support the mix of Point and PointArray in ProbeOutput and SurfaceProbeOutput #640

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 0 additions & 12 deletions flow360/component/simulation/outputs/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,6 @@ def load_point_location_from_file(cls, file_path: str):
"""Load probe point locations from a file. (Not implemented yet)"""
raise NotImplementedError("Not implemented yet.")

@pd.field_validator("entities", mode="after")
@classmethod
def check_unique_probe_type(cls, value):
"""Check to ensure every entity has the same type"""
return _check_unique_probe_type(value, "ProbeOutput")


class SurfaceProbeOutput(Flow360BaseModel):
"""
Expand Down Expand Up @@ -561,12 +555,6 @@ class SurfaceProbeOutput(Flow360BaseModel):
)
output_type: Literal["SurfaceProbeOutput"] = pd.Field("SurfaceProbeOutput", frozen=True)

@pd.field_validator("entities", mode="after")
@classmethod
def check_unique_probe_type(cls, value):
"""Check to ensure every entity has the same type"""
return _check_unique_probe_type(value, "SurfaceProbeOutput")


class SurfaceSliceOutput(_AnimationAndFileFormatSettings):
"""
Expand Down
56 changes: 35 additions & 21 deletions flow360/component/simulation/translator/solver_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Rotation,
Solid,
)
from flow360.component.simulation.outputs.output_entities import PointArray
from flow360.component.simulation.outputs.output_entities import Point, PointArray
from flow360.component.simulation.outputs.outputs import (
AeroAcousticOutput,
Isosurface,
Expand Down Expand Up @@ -271,32 +271,46 @@ def inject_isosurface_info(entity: Isosurface):

def inject_probe_info(entity: EntityList):
"""inject entity info"""
if isinstance(entity.stored_entities[0], PointArray):
return {
"start": [item.start.value.tolist() for item in entity.stored_entities],
"end": [item.end.value.tolist() for item in entity.stored_entities],
"numberOfPoints": [item.number_of_points for item in entity.stored_entities],
"type": "lineProbe",
}
return {
"monitorLocations": [item.location.value.tolist() for item in entity.stored_entities],
"type": "probe",

translated_entity_dict = {
"start": [],
"end": [],
"numberOfPoints": [],
"type": "lineProbe",
}
for item in entity.stored_entities:
if isinstance(item, PointArray):
translated_entity_dict["start"].append(item.start.value.tolist())
translated_entity_dict["end"].append(item.end.value.tolist())
translated_entity_dict["numberOfPoints"].append(item.number_of_points)
if isinstance(item, Point):
translated_entity_dict["start"].append(item.location.value.tolist())
translated_entity_dict["end"].append(item.location.value.tolist())
translated_entity_dict["numberOfPoints"].append(1)

return translated_entity_dict


def inject_surface_probe_info(entity: EntityList):
"""inject entity info"""
if isinstance(entity.stored_entities[0], PointArray):
return {
"start": [item.start.value.tolist() for item in entity.stored_entities],
"end": [item.end.value.tolist() for item in entity.stored_entities],
"numberOfPoints": [item.number_of_points for item in entity.stored_entities],
"type": "lineProbe",
}
return {
"monitorLocations": [item.location.value.tolist() for item in entity.stored_entities],
"type": "surfaceProbe",

translated_entity_dict = {
"start": [],
"end": [],
"numberOfPoints": [],
"type": "lineProbe",
}
for item in entity.stored_entities:
if isinstance(item, PointArray):
translated_entity_dict["start"].append(item.start.value.tolist())
translated_entity_dict["end"].append(item.end.value.tolist())
translated_entity_dict["numberOfPoints"].append(item.number_of_points)
if isinstance(item, Point):
translated_entity_dict["start"].append(item.location.value.tolist())
translated_entity_dict["end"].append(item.location.value.tolist())
translated_entity_dict["numberOfPoints"].append(1)

return translated_entity_dict


def inject_surface_list_info(entity: EntityList):
Expand Down
84 changes: 66 additions & 18 deletions tests/simulation/translator/test_output_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,21 @@ def probe_output_config():
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"monitorLocations": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"start": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"end": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"numberOfPoints": [1, 1],
"outputFields": ["primitiveVars", "Cp"],
"type": "probe",
"type": "lineProbe",
},
"prb 12": {
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"monitorLocations": [[10e-2, 10.02e-2, 10.03e-2]],
"start": [[10e-2, 10.02e-2, 10.03e-2]],
"end": [[10e-2, 10.02e-2, 10.03e-2]],
"numberOfPoints": [1],
"outputFields": ["primitiveVars", "Cp"],
"type": "probe",
"type": "lineProbe",
},
"prb average": {
"animationFrequency": 1,
Expand All @@ -440,9 +444,11 @@ def probe_output_config():
"animationFrequencyTimeAverageOffset": 0,
"startAverageIntegrationStep": -1,
"computeTimeAverages": True,
"monitorLocations": [[10e-2, 10.02e-2, 10.03e-2]],
"start": [[10e-2, 10.02e-2, 10.03e-2]],
"end": [[10e-2, 10.02e-2, 10.03e-2]],
"numberOfPoints": [1],
"outputFields": ["primitiveVars", "Cp", "T"],
"type": "probe",
"type": "lineProbe",
},
},
"outputFields": [],
Expand Down Expand Up @@ -486,6 +492,22 @@ def probe_output_with_point_array():
],
output_fields=["primitiveVars", "Cp"],
),
ProbeOutput(
name="prb mix",
entities=[
Point(
name="124",
location=[1, 1.02, 0.03] * u.cm,
),
PointArray(
name="Line 1",
start=[0.1, 0.2, 0.3] * u.m,
end=[1.1, 1.2, 1.3] * u.m,
number_of_points=5,
),
],
output_fields=["primitiveVars", "Cp"],
),
],
{
"monitors": {
Expand All @@ -500,12 +522,24 @@ def probe_output_with_point_array():
"type": "lineProbe",
},
"prb point": {
"monitorLocations": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"start": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"end": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"numberOfPoints": [1, 1],
"outputFields": ["primitiveVars", "Cp"],
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"type": "probe",
"type": "lineProbe",
},
"prb mix": {
"start": [[1e-2, 1.02e-2, 0.0003], [0.1, 0.2, 0.3]],
"end": [[1e-2, 1.02e-2, 0.0003], [1.1, 1.2, 1.3]],
"numberOfPoints": [1, 5],
"outputFields": ["primitiveVars", "Cp"],
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"type": "lineProbe",
},
},
"outputFields": [],
Expand Down Expand Up @@ -617,8 +651,10 @@ def test_surface_probe_output():
"computeTimeAverages": False,
"outputFields": ["Cp", "Cf"],
"surfacePatches": ["zoneA/surface1", "zoneA/surface2"],
"monitorLocations": [[1e-2, 1.02e-2, 0.0003], [2.0, 1.01, 0.03]],
"type": "surfaceProbe",
"start": [[1e-2, 1.02e-2, 0.0003], [2.0, 1.01, 0.03]],
"end": [[1e-2, 1.02e-2, 0.0003], [2.0, 1.01, 0.03]],
"numberOfPoints": [1, 1],
"type": "lineProbe",
},
"SP-2": {
"animationFrequency": 1,
Expand All @@ -629,12 +665,18 @@ def test_surface_probe_output():
"computeTimeAverages": True,
"outputFields": ["Mach", "primitiveVars", "yPlus"],
"surfacePatches": ["zoneB/surface1", "zoneB/surface2"],
"monitorLocations": [
"start": [
[1e-2, 1.02e-2, 0.0003],
[2.0, 1.01, 0.03],
[3.0, 1.02, 0.03],
],
"type": "surfaceProbe",
"end": [
[1e-2, 1.02e-2, 0.0003],
[2.0, 1.01, 0.03],
[3.0, 1.02, 0.03],
],
"numberOfPoints": [1, 1, 1],
"type": "lineProbe",
},
"SP-3": {
"animationFrequency": 1,
Expand Down Expand Up @@ -725,9 +767,11 @@ def test_monitor_output(
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"monitorLocations": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"start": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"end": [[1e-2, 1.02e-2, 0.0003], [0.0001, 0.02, 0.03]],
"numberOfPoints": [1, 1],
"outputFields": ["primitiveVars", "Cp"],
"type": "probe",
"type": "lineProbe",
},
"prb 110": {
"animationFrequency": 1,
Expand All @@ -741,9 +785,11 @@ def test_monitor_output(
"animationFrequency": 1,
"animationFrequencyOffset": 0,
"computeTimeAverages": False,
"monitorLocations": [[10e-2, 10.02e-2, 10.03e-2]],
"start": [[10e-2, 10.02e-2, 10.03e-2]],
"end": [[10e-2, 10.02e-2, 10.03e-2]],
"numberOfPoints": [1],
"outputFields": ["primitiveVars", "Cp"],
"type": "probe",
"type": "lineProbe",
},
"prb 122": {
"animationFrequency": 1,
Expand All @@ -760,9 +806,11 @@ def test_monitor_output(
"animationFrequencyTimeAverageOffset": 0,
"startAverageIntegrationStep": -1,
"computeTimeAverages": True,
"monitorLocations": [[10e-2, 10.02e-2, 10.03e-2]],
"start": [[10e-2, 10.02e-2, 10.03e-2]],
"end": [[10e-2, 10.02e-2, 10.03e-2]],
"numberOfPoints": [1],
"outputFields": ["primitiveVars", "Cp", "T"],
"type": "probe",
"type": "lineProbe",
},
},
"outputFields": [],
Expand Down
Loading