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
15 changes: 14 additions & 1 deletion flow360/component/results/base_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from flow360.component.simulation.models.surface_models import BoundaryBase
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.v1.flow360_params import Flow360Params
from flow360.exceptions import Flow360ValueError
from flow360.exceptions import Flow360TypeError, Flow360ValueError
from flow360.log import log

# pylint: disable=consider-using-with
Expand Down Expand Up @@ -753,3 +753,16 @@ def reload_data(self, filter_physical_steps_only: bool = False, include_time: bo
filter_physical_steps_only=filter_physical_steps_only, include_time=include_time
)
self._filtered_sum()


class LocalResultCSVModel(ResultCSVModel):
"""
CSV Model with no remote file that cannot be downloaded used for locally working with csv data
"""

remote_file_name: Optional[str] = None

def download(
self, to_file: str = None, to_folder: str = ".", overwrite: bool = False, **kwargs
):
raise Flow360TypeError("Cannot download csv from LocalResultCSVModel")
64 changes: 64 additions & 0 deletions flow360/component/results/case_results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Case results module"""

# pylint: disable=too-many-lines

from __future__ import annotations

import re
Expand All @@ -15,6 +17,7 @@
_PHYSICAL_STEP,
_PSEUDO_STEP,
_TIME,
LocalResultCSVModel,
PerEntityResultCSVModel,
ResultBaseModel,
ResultCSVModel,
Expand All @@ -32,6 +35,7 @@
_HEAT_FLUX,
_X,
_Y,
BETDiskCSVHeaderOperation,
DiskCoefficientsComputation,
PorousMediumCoefficientsComputation,
_CFx,
Expand Down Expand Up @@ -815,6 +819,26 @@ def to_base(self, base: str, params: Flow360Params = None):
self.values["ForceUnits"] = bet.force_x.units
self.values["MomentUnits"] = bet.moment_x.units

def format_headers(
self, params: SimulationParams, pattern: str = "$BETName_$CylinderName"
) -> LocalResultCSVModel:
"""
Renames the header entries from Disk{i}_ to based on an input user pattern
such as $BETName_$CylinderName
Parameters
----------
params : SimulationParams
Simulation parameters
pattern : str
Pattern string to rename header entries. Available patterns
[$BETName, $CylinderName, $DiskLocalIndex, $DiskGlobalIndex]
Returns
-------
LocalResultCSVModel
Model containing csv with updated header
"""
return BETDiskCSVHeaderOperation.format_headers(self, params, pattern)

def compute_coefficients(self, params: SimulationParams) -> BETDiskCoefficientsCSVModel:
"""
Compute disk coefficients from BET disk forces and moments.
Expand Down Expand Up @@ -877,6 +901,26 @@ class BETDiskCoefficientsCSVModel(ResultCSVModel):

remote_file_name: str = pd.Field("bet_disk_coefficients_v2.csv", frozen=True)

def format_headers(
self, params: SimulationParams, pattern: str = "$BETName_$CylinderName"
) -> LocalResultCSVModel:
"""
Renames the header entries from Disk{i}_ to based on an input user pattern
such as $BETName_$CylinderName
Parameters
----------
params : SimulationParams
Simulation parameters
pattern : str
Pattern string to rename header entries. Available patterns
[$BETName, $CylinderName, $DiskLocalIndex, $DiskGlobalIndex]
Returns
-------
LocalResultCSVModel
Model containing csv with updated header
"""
return BETDiskCSVHeaderOperation.format_headers(self, params, pattern)


class PorousMediumResultCSVModel(OptionallyDownloadableResultCSVModel):
"""Model for handling porous medium CSV results."""
Expand Down Expand Up @@ -953,3 +997,23 @@ class BETForcesRadialDistributionResultCSVModel(OptionallyDownloadableResultCSVM
CaseDownloadable.BET_FORCES_RADIAL_DISTRIBUTION.value, frozen=True
)
_err_msg = "Case does not have any BET disks."

def format_headers(
self, params: SimulationParams, pattern: str = "$BETName_$CylinderName"
) -> LocalResultCSVModel:
"""
Renames the header entries from Disk{i}_ to based on an input user pattern
such as $BETName_$CylinderName
Parameters
----------
params : SimulationParams
Simulation parameters
pattern : str
Pattern string to rename header entries. Available patterns
[$BETName, $CylinderName, $DiskLocalIndex, $DiskGlobalIndex]
Returns
-------
LocalResultCSVModel
Model containing csv with updated header
"""
return BETDiskCSVHeaderOperation.format_headers(self, params, pattern)
78 changes: 77 additions & 1 deletion flow360/component/results/results_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import numpy as np

from flow360.component.results.base_results import _PHYSICAL_STEP, _PSEUDO_STEP
from flow360.component.results.base_results import (
_PHYSICAL_STEP,
_PSEUDO_STEP,
LocalResultCSVModel,
ResultCSVModel,
)
from flow360.component.simulation.models.volume_models import BETDisk
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.exceptions import Flow360ValueError
from flow360.log import log
Expand Down Expand Up @@ -410,3 +416,73 @@ def compute_coefficients_static(
out[f"{zone_name}_{_CL}"].append(CL_val)

return coefficients_model_class().from_dict(out)


class BETDiskCSVHeaderOperation:
# pylint:disable=too-few-public-methods
"""
Static utilities for renaming BET disk csv output headers to include the name of the BET disk.

This class provides only static methods and should not be instantiated or subclassed.
All methods are self-contained and require explicit parameters.
"""

@staticmethod
def format_headers(
BETCSVModel: ResultCSVModel,
params: SimulationParams,
pattern: str = "$BETName_$CylinderName",
) -> LocalResultCSVModel:
"""
renames the header entries in a BET csv file from Disk{x}_ based on input pattern
$Default option is $BETName_$CylinderName

pattern can take [$BETName, $CylinderName, $DiskLocalIndex, $DiskGlobalIndex]
Parameters
----------
BETCSVModel : ResultCSVModle
Model containing csv entries
params : SimulationParams
Simulation parameters
pattern : str
Pattern string to rename header entries. Available patterns
[$BETName, $CylinderName, $DiskLocalIndex, $DiskGlobalIndex]
Returns
-------
LocalResultCSVModel
Model containing csv with updated header
"""
# pylint:disable=too-many-locals
bet_disks = []
for model in params.models:
if isinstance(model, BETDisk):
bet_disks.append(model)
if not bet_disks:
raise ValueError("No BET Disks in params to rename header.")

csv_data = BETCSVModel.values
new_csv = {}

disk_rename_map = {}

diskCount = 0
for disk in bet_disks:
for disk_local_index, cylinder in enumerate(disk.entities.stored_entities):
new_name = pattern.replace("$BETName", disk.name)
new_name = new_name.replace("$CylinderName", cylinder.name)
new_name = new_name.replace("$DiskLocalIndex", str(disk_local_index))
new_name = new_name.replace("$DiskGlobalIndex", str(diskCount))
disk_rename_map[f"Disk{diskCount}"] = new_name
diskCount = diskCount + 1

for header, values in csv_data.items():
matched = False
for default_prefix, new_prefix in disk_rename_map.items():
if header.startswith(default_prefix):
new_csv[new_prefix + header[len(default_prefix) :]] = values
matched = True
break
if not matched:
new_csv[header] = values
newModel = LocalResultCSVModel().from_dict(new_csv)
return newModel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import flow360 as fl
from flow360.component.results.case_results import BETForcesResultCSVModel
from flow360.component.simulation.framework.param_utils import AssetCache
from flow360.component.simulation.models.volume_models import BETDisk
from flow360.component.simulation.services import ValidationCalledBy, validate_model

from .test_helpers import compute_freestream_direction, compute_lift_direction
Expand Down
Loading