Skip to content

Commit

Permalink
adds a try-catch on bl reinterpolation, for case where nans/infs are …
Browse files Browse the repository at this point in the history
…detected
  • Loading branch information
peterdsharpe committed Feb 28, 2024
1 parent af881ce commit 1cde7b0
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions neuralfoil/gen2_architecture/_basic_data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,52 +192,52 @@ def append_empty_data():
np.flatnonzero(dx > 0)[0]:,
:
]
except IndexError: # If the boundary layer data is too short
except IndexError as e: # If the boundary layer data is too short
print(e)
append_empty_data()
continue

if len(upper_bl_data) <= 4 or len(lower_bl_data) <= 4: # If the boundary layer data is too short
print("BL data too short")
append_empty_data()
continue

def interp(x, xp, fp):
return interpolate.PchipInterpolator(
xp,
fp,
extrapolate=True,
)(x)

interp = lambda x, y: interpolate.PchipInterpolator(x, y, extrapolate=True)(cls.bl_x_points)

training_datas.append(
cls(
airfoil=airfoil.to_kulfan_airfoil(),
alpha=alpha,
Re=Re,
mach=mach,
n_crit=n_crit,
xtr_upper=xtr_upper,
xtr_lower=xtr_lower,
analysis_confidence=1,
af_outputs={
"CL" : xf_output["CL"],
"CD" : xf_output["CD"],
"CM" : xf_output["CM"],
"Top_Xtr": xf_output["Top_Xtr"],
"Bot_Xtr": xf_output["Bot_Xtr"],
},
upper_bl_outputs={
"theta" : interp(upper_bl_data["x"], upper_bl_data["theta"]),
"H" : interp(upper_bl_data["x"], upper_bl_data["H"]),
"ue/vinf": interp(upper_bl_data["x"], upper_bl_data["ue/vinf"]),
},
lower_bl_outputs={
"theta" : interp(lower_bl_data["x"], lower_bl_data["theta"]),
"H" : interp(lower_bl_data["x"], lower_bl_data["H"]),
"ue/vinf": interp(lower_bl_data["x"], lower_bl_data["ue/vinf"]),
},
try:
training_datas.append(
cls(
airfoil=airfoil.to_kulfan_airfoil(),
alpha=alpha,
Re=Re,
mach=mach,
n_crit=n_crit,
xtr_upper=xtr_upper,
xtr_lower=xtr_lower,
analysis_confidence=1,
af_outputs={
"CL" : xf_output["CL"],
"CD" : xf_output["CD"],
"CM" : xf_output["CM"],
"Top_Xtr": xf_output["Top_Xtr"],
"Bot_Xtr": xf_output["Bot_Xtr"],
},
upper_bl_outputs={
"theta" : interp(upper_bl_data["x"], upper_bl_data["theta"]),
"H" : interp(upper_bl_data["x"], upper_bl_data["H"]),
"ue/vinf": interp(upper_bl_data["x"], upper_bl_data["ue/vinf"]),
},
lower_bl_outputs={
"theta" : interp(lower_bl_data["x"], lower_bl_data["theta"]),
"H" : interp(lower_bl_data["x"], lower_bl_data["H"]),
"ue/vinf": interp(lower_bl_data["x"], lower_bl_data["ue/vinf"]),
},
)
)
)
except ValueError as e:
print(e)
append_empty_data()
continue

return training_datas

Expand Down

0 comments on commit 1cde7b0

Please sign in to comment.