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
24 changes: 13 additions & 11 deletions .github/workflows/create-hotfix-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write # To push branches and commit changes
contents: write # To push branches and commit changes
pull-requests: write # To create the pull request

env:
Expand Down Expand Up @@ -114,20 +114,21 @@ jobs:
- name: Create and Process Hotfix Branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
# Read branch pairs and process each one
IFS=' ' read -r -a PAIRS <<< "${{ steps.define_branches.outputs.branch_pairs }}"

for pair in "${PAIRS[@]}"; do
IFS=':' read -r base_branch new_branch <<< "$pair"

echo "Processing hotfix for branch: $base_branch"

# Create and switch to new branch
git checkout "$base_branch"
git pull origin "$base_branch"
git checkout -b "$new_branch"

# Attempt cherry-pick
if ! git cherry-pick ${{ steps.get_commit.outputs.sha }} --empty=keep; then
echo "Cherry-pick encountered conflicts for $base_branch, attempting to resolve..."
Expand All @@ -139,7 +140,7 @@ jobs:
continue # Skip PR creation if no changes after resolution
fi
git cherry-pick --continue

if [ $? -eq 0 ]; then
echo "Successfully resolved conflicts for $base_branch"
had_conflicts="true"
Expand All @@ -166,18 +167,18 @@ jobs:
# Push branch
if git push origin "$new_branch"; then
echo "Successfully pushed branch $new_branch"

# Create PR
PR_NUMBER="${{ github.event.pull_request.number }}"
PR_URL="${{ github.event.pull_request.html_url }}"
PR_AUTHOR="${{ github.event.pull_request.user.login }}"

# Adjust PR title based on the target branch
if [[ "$base_branch" == "main" ]]; then
PR_TITLE="[Hotfix Main]: ${{ github.event.pull_request.title }}"
HOTFIX_PR_TITLE="[Hotfix Main]: $PR_TITLE"
else
base_branch_name=${base_branch#"release-candidate/"}
PR_TITLE="[Hotfix $base_branch_name]: ${{ github.event.pull_request.title }}"
HOTFIX_PR_TITLE="[Hotfix $base_branch_name]: $PR_TITLE"
fi

PR_BODY="Hotfix of PR #${PR_NUMBER} (${PR_URL}) to the \`${base_branch}\` branch.
Expand All @@ -189,9 +190,10 @@ jobs:

### ⚠️ **Note:** This PR had conflicts with the base branch and was resolved automatically. Please review the changes carefully."
fi


# Create PR using gh cli
gh pr create \
--title "$PR_TITLE" \
--title "$HOTFIX_PR_TITLE" \
--body "$PR_BODY" \
--head "$new_branch" \
--base "$base_branch" \
Expand Down
14 changes: 14 additions & 0 deletions flow360/component/simulation/migration/BETDisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import os
from typing import Union

from numpy import sqrt
from pydantic import validate_call
Expand All @@ -15,6 +16,17 @@
from flow360.log import log


def _remove_comments(obj: Union[dict, list]) -> Union[dict, list]:
"""
Recursively return a copy of `obj` with all 'comments' entries removed.
"""
if isinstance(obj, dict):
return {key: _remove_comments(value) for key, value in obj.items() if key != "comments"}
if isinstance(obj, list):
return [_remove_comments(item) for item in obj]
return obj


# pylint: disable=too-many-arguments
def _parse_flow360_bet_disk_dict(
*,
Expand Down Expand Up @@ -42,6 +54,8 @@ def _parse_flow360_bet_disk_dict(
if len(flow360_bet_disk_dict["BETDisks"]) == 0:
raise ValueError("Input file does not contain BETDisk setting.")
flow360_bet_disk_dict = flow360_bet_disk_dict["BETDisks"][0]
# Recursively remove "comments" from the flow360_bet_disk_dict
flow360_bet_disk_dict = _remove_comments(flow360_bet_disk_dict)

specific_heat_ratio = 1.4
gas_constant = 287.0529 * u.m**2 / u.s**2 / u.K # pylint: disable=no-member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

from pydantic import ValidationInfo

from flow360.component.simulation.validation.validation_context import (
TimeSteppingType,
get_validation_info,
)


def _check_bet_disk_initial_blade_direction_and_blade_line_chord(bet_disk):
if bet_disk.blade_line_chord > 0 and bet_disk.initial_blade_direction is None:
Expand Down Expand Up @@ -57,18 +52,6 @@ def _check_bet_disk_duplicate_twists(value, info: ValidationInfo):
return value


def _check_bet_disk_initial_blade_direction(value, info: ValidationInfo):
validation_info = get_validation_info()
if validation_info is None:
return value

if validation_info.time_stepping == TimeSteppingType.UNSTEADY and value is None:
raise ValueError(
"The initial_blade_direction must be specified if performing an unsteady BET Line simulation."
)
return value


def _check_bet_disk_sectional_radius_and_polars(bet_disk):
radiuses = bet_disk.sectional_radiuses
polars = bet_disk.sectional_polars
Expand Down
7 changes: 0 additions & 7 deletions flow360/component/simulation/models/volume_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
_check_bet_disk_alphas_in_order,
_check_bet_disk_duplicate_chords,
_check_bet_disk_duplicate_twists,
_check_bet_disk_initial_blade_direction,
_check_bet_disk_initial_blade_direction_and_blade_line_chord,
_check_bet_disk_sectional_radius_and_polars,
)
Expand Down Expand Up @@ -783,12 +782,6 @@ def check_bet_disk_duplicate_twists(cls, value, info: pd.ValidationInfo):
"""validate duplicates in twists in BET disks"""
return _check_bet_disk_duplicate_twists(value, info)

@pd.field_validator("initial_blade_direction", mode="after")
@classmethod
def invalid_growth_rate(cls, value, info: pd.ValidationInfo):
"""Ensure initial_blade_direction is specified in an unsteady simulation"""
return _check_bet_disk_initial_blade_direction(value, info)

@pd.model_validator(mode="after")
@_validator_append_instance_name
def check_bet_disk_sectional_radius_and_polars(self):
Expand Down
2 changes: 1 addition & 1 deletion flow360/component/simulation/outputs/output_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def get_unit_for_field(field_name: str):
"velocity_x": "velocity_x = primitiveVars[1] * velocityScale;",
"velocity_y": "velocity_y = primitiveVars[2] * velocityScale;",
"velocity_z": "velocity_z = primitiveVars[3] * velocityScale;",
"pressure": "double gamma = 1.4;pressure = (usingLiquidAsMaterial) ? "
"pressure_": "double gamma = 1.4;pressure_ = (usingLiquidAsMaterial) ? "
+ "(primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];",
"wall_shear_stress_magnitude": "wall_shear_stress_magnitude = "
+ "magnitude(wallShearStress) * (velocityScale * velocityScale);",
Expand Down
10 changes: 9 additions & 1 deletion tests/simulation/converter/data/full_flow360.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
5.0,
0
],
"comments": {
"I should be removed": true,
"I should be removed too": true
},
"rotationDirectionRule": "rightHand",
"omega": 0.1417322834645669,
"numberOfBlades": 3,
Expand Down Expand Up @@ -505,7 +509,11 @@
"chords": [
{
"radius": 0.0,
"chord": 0.0
"chord": 0.0,
"comments": {
"I should be removed": true,
"I should be removed too": true
}
},
{
"radius": 0.3429,
Expand Down
6 changes: 5 additions & 1 deletion tests/simulation/converter/data/single_flow360_bet_disk.json
Original file line number Diff line number Diff line change
Expand Up @@ -4855,5 +4855,9 @@
]
}
],
"tipGap": 0.02
"tipGap": 0.02,
"comments": {
"I should be removed": true,
"I should be removed too": true
}
}
14 changes: 3 additions & 11 deletions tests/simulation/outputs/test_output_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,14 @@ def test_generate_field_udf_velocity_magnitude(simulation_params):
assert result == expected


def test_generate_field_pressure_no_unit(simulation_params):
"""Test generating UDF expression for pressure fields."""

result = generate_predefined_udf("pressure", simulation_params)
expected = "double gamma = 1.4;pressure = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];"
assert result == expected


def test_generate_field_udf_pressure(simulation_params):
"""Test generating UDF expression for pressure fields."""

result = generate_predefined_udf("pressure_pa", simulation_params)
expected = (
"double pressure;double gamma = 1.4;"
"pressure = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];"
"pressure_pa = pressure * 141855.01272652458;"
"double pressure_;double gamma = 1.4;"
"pressure_ = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];"
"pressure_pa = pressure_ * 141855.01272652458;"
)
assert result == expected

Expand Down
22 changes: 0 additions & 22 deletions tests/simulation/params/test_validators_bet_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,6 @@ def test_bet_disk_initial_blade_direction_with_bet_name(create_steady_bet_disk):
bet_disk.blade_line_chord = 0.1 * u.inch


def test_bet_disk_initial_blade_direction_with_unsteady_simulation(create_steady_bet_disk):
with u.SI_unit_system:
params = SimulationParams(
models=[create_steady_bet_disk],
time_stepping=Unsteady(
step_size=0.01 * u.s,
steps=120,
),
)

params, errors, _ = services.validate_model(
params_as_dict=params.model_dump(mode="json"),
validated_by=services.ValidationCalledBy.LOCAL,
root_item_type="VolumeMesh",
validation_level="Case",
)
assert len(errors) == 1
assert errors[0]["msg"] == (
"Value error, The initial_blade_direction must be specified if performing an unsteady BET Line simulation."
)


def test_bet_disk_disorder_alphas(create_steady_bet_disk):
bet_disk = create_steady_bet_disk
with pytest.raises(
Expand Down
7 changes: 1 addition & 6 deletions tests/simulation/translator/test_output_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,14 +1344,9 @@ def test_dimensioned_output_fields_translation(vel_in_km_per_hr):
ref = {
"userDefinedFields": [
{"name": "my_field", "expression": "1+1", "from_user_variables": False},
{
"name": "pressure",
"expression": "double gamma = 1.4;pressure = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];",
"from_user_variables": False,
},
{
"name": "pressure_pa",
"expression": "double pressure;double gamma = 1.4;pressure = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];pressure_pa = pressure * 2500000.0;",
"expression": "double pressure_;double gamma = 1.4;pressure_ = (usingLiquidAsMaterial) ? (primitiveVars[4] - 1.0 / gamma) * (velocityScale * velocityScale) : primitiveVars[4];pressure_pa = pressure_ * 2500000.0;",
"from_user_variables": False,
},
{
Expand Down
Loading