|
| 1 | +import pytest |
| 2 | + |
| 3 | +import flow360.component.simulation.units as u |
| 4 | +from flow360.component.simulation.primitives import Cylinder |
| 5 | +from flow360.component.simulation.services import clear_context |
| 6 | +from flow360.component.simulation.translator.solver_translator import get_solver_json |
| 7 | +from flow360.component.simulation.unit_system import imperial_unit_system |
| 8 | +from tests.simulation.translator.utils.xv15_bet_disk_helper import ( |
| 9 | + createBETDiskSteady, |
| 10 | + createBETDiskUnsteady, |
| 11 | + createSteadyTimeStepping, |
| 12 | +) |
| 13 | +from tests.simulation.translator.utils.xv15BETDisk_param_generator import ( |
| 14 | + create_param_base, |
| 15 | + createUnsteadyTimeStepping, |
| 16 | +) |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(autouse=True) |
| 20 | +def reset_context(): |
| 21 | + """Clear user variables from the context.""" |
| 22 | + clear_context() |
| 23 | + |
| 24 | + |
| 25 | +def _create_test_cylinder(): |
| 26 | + return Cylinder( |
| 27 | + name="bet_zone", |
| 28 | + center=(0, 0, 0) * u.inch, |
| 29 | + axis=[0, 0, 1], |
| 30 | + outer_radius=150 * u.inch, |
| 31 | + height=15 * u.inch, |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +def test_betdisk_unsteady_excludes_internal_fields(): |
| 36 | + rpm = 588.50450 |
| 37 | + params = create_param_base() |
| 38 | + bet_disk = createBETDiskUnsteady( |
| 39 | + cylinder_entity=_create_test_cylinder(), pitch_in_degree=10, rpm=rpm |
| 40 | + ) |
| 41 | + params.models.append(bet_disk) |
| 42 | + params.time_stepping = createUnsteadyTimeStepping(rpm) |
| 43 | + |
| 44 | + translated = get_solver_json(params, mesh_unit=1 * u.inch) |
| 45 | + assert "BETDisks" in translated and len(translated["BETDisks"]) > 0 |
| 46 | + bet_item = translated["BETDisks"][0] |
| 47 | + |
| 48 | + assert "initialBladeDirection" in bet_item |
| 49 | + assert "bladeLineChord" in bet_item |
| 50 | + |
| 51 | + |
| 52 | +def test_betdisk_steady_excludes_internal_fields(): |
| 53 | + rpm = 588.50450 |
| 54 | + params = create_param_base() |
| 55 | + bet_disk = createBETDiskSteady( |
| 56 | + cylinder_entity=_create_test_cylinder(), pitch_in_degree=10, rpm=rpm |
| 57 | + ) |
| 58 | + bet_disk = bet_disk.model_copy( |
| 59 | + update={ |
| 60 | + "blade_line_chord": 25 * u.inch, |
| 61 | + "initial_blade_direction": (1, 0, 0), |
| 62 | + } |
| 63 | + ) |
| 64 | + params.models.append(bet_disk) |
| 65 | + params.time_stepping = createSteadyTimeStepping() |
| 66 | + |
| 67 | + translated = get_solver_json(params, mesh_unit=1 * u.inch) |
| 68 | + assert "BETDisks" in translated and len(translated["BETDisks"]) > 0 |
| 69 | + bet_item = translated["BETDisks"][0] |
| 70 | + |
| 71 | + assert "initialBladeDirection" not in bet_item |
| 72 | + assert "bladeLineChord" in bet_item and bet_item["bladeLineChord"] == 0 |
0 commit comments