Skip to content

Commit bd78347

Browse files
fix(): No member error when dealing with GenericReferenceCondition while computing force coefficients. (#1684)
1 parent 5c07053 commit bd78347

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

flow360/component/simulation/simulation_params.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,14 @@ def reference_velocity(self) -> VelocityType:
745745
So we need to find the `reference velocity`.
746746
`reference_velocity_magnitude` takes precedence, consistent with how "velocityScale" is computed.
747747
"""
748-
# pylint:disable=no-member
749-
if self.operating_condition.reference_velocity_magnitude is not None:
750-
reference_velocity = (self.operating_condition.reference_velocity_magnitude).to("m/s")
748+
# NOTE: GenericReferenceCondition does not define `reference_velocity_magnitude`.
749+
# For GenericReferenceCondition, reference velocity is just `velocity_magnitude`.
750+
reference_velocity_magnitude = getattr(
751+
self.operating_condition, "reference_velocity_magnitude", None
752+
)
753+
# pylint: disable=no-member
754+
if reference_velocity_magnitude is not None:
755+
reference_velocity = reference_velocity_magnitude.to("m/s")
751756
elif self.operating_condition.type_name == "LiquidOperatingCondition":
752757
reference_velocity = self.base_velocity.to("m/s") * LIQUID_IMAGINARY_FREESTREAM_MACH
753758
else:

tests/simulation/results_processing/test_porous_medium_coefficients.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,65 @@ def test_porous_medium_simple_coefficients():
100100
assert np.isclose(CM[0] / CM[2], 2.0, rtol=1e-6, atol=1e-12)
101101

102102

103+
def test_porous_medium_simple_coefficients_with_generic_reference_condition():
104+
# Prepare a simple porous medium CSV with one timestep
105+
csv_path = os.path.join(
106+
os.path.dirname(__file__),
107+
os.path.pardir,
108+
"data",
109+
"coeff_simple",
110+
"results",
111+
"porous_media_output_v2.csv",
112+
)
113+
csv_path = os.path.abspath(csv_path)
114+
115+
# Generic reference condition has no alpha/beta. In coefficient computations we assume:
116+
# lift direction = (0, 0, 1), drag direction = (1, 0, 0)
117+
with fl.SI_unit_system:
118+
params = fl.SimulationParams(
119+
reference_geometry=fl.ReferenceGeometry(
120+
moment_center=(0, 0, 0) * fl.u.m,
121+
moment_length=1 * fl.u.m,
122+
area=2.0 * fl.u.m**2,
123+
),
124+
operating_condition=fl.GenericReferenceCondition(
125+
velocity_magnitude=10 * fl.u.m / fl.u.s
126+
),
127+
models=[
128+
fl.PorousMedium(
129+
entities=[
130+
fl.Box.from_principal_axes(
131+
name="porous_zone",
132+
axes=[(1, 0, 0), (0, 1, 0)],
133+
center=(0, 0, 0) * fl.u.m,
134+
size=(0.2, 0.3, 2) * fl.u.m,
135+
)
136+
],
137+
darcy_coefficient=(1e6, 0, 0) / fl.u.m**2,
138+
forchheimer_coefficient=(1, 0, 0) / fl.u.m,
139+
)
140+
],
141+
private_attribute_asset_cache=AssetCache(project_length_unit=1 * fl.u.m),
142+
)
143+
144+
model = PorousMediumResultCSVModel()
145+
model.load_from_local(csv_path)
146+
coeffs = model.compute_coefficients(params=params)
147+
148+
data = coeffs.as_dict()
149+
CF = np.array(
150+
[data["zone_0_CFx"][0], data["zone_0_CFy"][0], data["zone_0_CFz"][0]], dtype=float
151+
)
152+
153+
# Drag/lift projections use default axes for GenericReferenceCondition
154+
drag_dir = np.array([1.0, 0.0, 0.0], dtype=float)
155+
lift_dir = np.array([0.0, 0.0, 1.0], dtype=float)
156+
CD = float(data["zone_0_CD"][0])
157+
CL = float(data["zone_0_CL"][0])
158+
assert np.isclose(CD, float(np.dot(CF, drag_dir)), rtol=1e-6, atol=1e-12)
159+
assert np.isclose(CL, float(np.dot(CF, lift_dir)), rtol=1e-6, atol=1e-12)
160+
161+
103162
def test_porous_medium_real_case_coefficients():
104163
"""
105164
Test PorousMedium coefficient computation with real case data.

0 commit comments

Comments
 (0)