Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import flow360 as fl
from flow360.examples import ObliqueChannel

ObliqueChannel.get_files()

project = fl.Project.from_volume_mesh(
ObliqueChannel.mesh_filename, name="Cartesian channel mesh",
)

volume_mesh = project.volume_mesh

with fl.SI_unit_system:
op = fl.GenericReferenceCondition.from_mach(
mach=0.3,
)
massFlowRate = fl.UserVariable(
name="MassFluxProjected",
value=-1
* fl.solution.density
* fl.math.dot(fl.solution.velocity, fl.solution.node_unit_normal),
)
massFlowRateIntegral = fl.SurfaceIntegralOutput(
name="MassFluxIntegral",
output_fields=[massFlowRate],
surfaces=volume_mesh["VOLUME/LEFT"],
)
params = fl.SimulationParams(
operating_condition=op,
models=[
fl.Fluid(
navier_stokes_solver=fl.NavierStokesSolver(absolute_tolerance=1e-10),
turbulence_model_solver=fl.NoneSolver(),
),
fl.Inflow(
entities=[volume_mesh["VOLUME/LEFT"]],
total_temperature=op.thermal_state.temperature * 1.018,
velocity_direction=(1.0, 0.0, 0.0),
spec=fl.MassFlowRate(
value=op.velocity_magnitude * op.thermal_state.density * (0.2 * fl.u.m**2)
),
),
fl.Outflow(
entities=[volume_mesh["VOLUME/RIGHT"]],
spec=fl.Pressure(op.thermal_state.pressure),
),
fl.SlipWall(
entities=[
volume_mesh["VOLUME/FRONT"],
volume_mesh["VOLUME/BACK"],
volume_mesh["VOLUME/TOP"],
volume_mesh["VOLUME/BOTTOM"],
]
),
],
time_stepping=fl.Steady(),
outputs=[
fl.VolumeOutput(
output_format="paraview",
output_fields=["primitiveVars"],
),
fl.SurfaceOutput(
output_fields=[
fl.solution.velocity,
fl.solution.Cp,
],
surfaces=[
fl.ImportedSurface(
name="normal", file_name=ObliqueChannel.extra["rectangle_normal"]
),
fl.ImportedSurface(
name="oblique", file_name=ObliqueChannel.extra["rectangle_oblique"]
),
],
),
fl.SurfaceIntegralOutput(
name="MassFlowRateImportedSurface",
output_fields=[massFlowRate],
surfaces=[
fl.ImportedSurface(
name="normal", file_name=ObliqueChannel.extra["rectangle_normal"]
),
fl.ImportedSurface(
name="oblique", file_name=ObliqueChannel.extra["rectangle_oblique"]
),
],
),
],
)
project.run_case(params, "test_imported_surfaces_field_and_integral")
2 changes: 1 addition & 1 deletion flow360/component/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,8 @@ def _run(

params.pre_submit_summary()

draft.update_simulation_params(params)
upload_imported_surfaces_to_draft(params, draft, fork_from)
draft.update_simulation_params(params)

if draft_only:
# pylint: disable=import-outside-toplevel
Expand Down
7 changes: 7 additions & 0 deletions flow360/component/project_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,10 @@ def upload_imported_surfaces_to_draft(params, draft, parent_case):
if file_basename not in parent_existing_imported_file_basenames:
deduplicated_surface_file_paths_to_import.append(file_path_to_import)
draft.upload_imported_surfaces(deduplicated_surface_file_paths_to_import)

if params is not None and params.outputs is not None:
for output in params.outputs:
if isinstance(output, (SurfaceOutput, SurfaceIntegralOutput)):
for surface in output.entities.stored_entities:
if isinstance(surface, ImportedSurface):
surface.file_name = os.path.basename(surface.file_name)
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)
Loading