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
4 changes: 4 additions & 0 deletions bird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from bird.version import __version__

# Marks __version__ as an intentional re-export (read by setuptools as
# bird.__version__); does not restrict attribute access to the module.
__all__ = ["__version__"]

BIRD_DIR = os.path.dirname(os.path.realpath(__file__))
BIRD_CASE_DIR = os.path.join(BIRD_DIR, "../tutorial_cases")
BIRD_CONST_DIR = os.path.join(BIRD_DIR, "constants")
Expand Down
11 changes: 0 additions & 11 deletions bird/meshing/block_cyl_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ def assemble_mesh(input_file, geom_dict):
raise ValueError(f"unknown input file ({input_file}) extension")
R = geom_dict["R"]
L = geom_dict["L"]
N1 = len(R)
N2 = len(L) - 1
CW = []
mCW = []
C1 = []
Expand Down Expand Up @@ -313,16 +311,12 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):
BoundaryNames = geom_dict["names"]
BoundaryType = geom_dict["types"]
BoundaryRmin = geom_dict["rmin"]
BoundaryRmax = geom_dict["rmax"]
BoundaryLmin = geom_dict["lmin"]
BoundaryLmax = geom_dict["lmax"]

NR = mesh_dict["NR"]
NS = mesh_dict["NS"]
NVert = mesh_dict["NVert"]
gradR = mesh_dict["gradR"]
gradR_l = mesh_dict["gradR_l"]
gradR_r = mesh_dict["gradR_r"]
gradVert = mesh_dict["gradVert"]
CW = mesh_dict["CW"]
mCW = mesh_dict["mCW"]
Expand Down Expand Up @@ -420,8 +414,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):
# gradingR = 1
# if il==N2-1:
# gradingVert = outletGrading
gradingR_l = gradR_l[ir]
gradingR_r = gradR_r[ir]
gradingVert = gradVert[il]
gradingR = gradR[ir]
# Am I a wall
Expand Down Expand Up @@ -528,7 +520,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):
boundType = BoundaryType[i][ibound]
if boundType == "lateral":
rminInd = BoundaryRmin[i][ibound]
rmaxInd = BoundaryRmax[i][ibound]
lInd = BoundaryLmin[i][ibound]
i1 = rminInd * (4 * (N2 + 1)) + 4 * lInd # bottom
i2 = i1 - 4 # top
Expand All @@ -540,7 +531,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):

elif boundType == "top":
lminInd = BoundaryLmin[i][ibound]
lmaxInd = BoundaryLmax[i][ibound]
rInd = BoundaryRmin[i][ibound]
if rInd > 0:
i1 = 4 * (N2 + 1) * (rInd - 1) + 4 * lminInd # right
Expand All @@ -556,7 +546,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):

elif boundType == "bottom":
lminInd = BoundaryLmin[i][ibound]
lmaxInd = BoundaryLmax[i][ibound]
rInd = BoundaryRmin[i][ibound]
i1 = 4 * (N2 + 1) * (rInd - 1) + 4 * lminInd # right
i2 = i1 + 4 * (N2 + 1) # left
Expand Down
3 changes: 0 additions & 3 deletions bird/meshing/block_rect_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def write_vertices(outfile, lengths, nboxes):
def write_blocks(outfile, blockids, lengths, nboxes, points_per_len):
nx = nboxes[0]
ny = nboxes[1]
nz = nboxes[2]

idarray = np.zeros(8, dtype=int)
mesharray = np.zeros(3, dtype=int)
Expand Down Expand Up @@ -93,7 +92,6 @@ def make_fluid_blocks_from_corner(corners):
assert isinstance(corners, list)
fluid_blocks = []
for multi_block in corners:
n_end_block = len(multi_block)
for iend, end_block in enumerate(multi_block):
# Add blocks that connect end points
if iend == 0:
Expand Down Expand Up @@ -222,7 +220,6 @@ def from_block_rect_to_seg(input_geom_dict, rescale=True):
)
vec_conn = segments[iseg]["end"] - segments[iseg]["start"]
segments[iseg]["conn"] = vec_conn
norm_vec_conn = np.linalg.norm(vec_conn)
segments[iseg]["normal_dir"] = int(np.nonzero(vec_conn)[0][0])
if segments[iseg]["normal_dir"] == 0:
segments[iseg]["max_rad"] = (blocksize_y + blocksize_z) / 4
Expand Down
4 changes: 0 additions & 4 deletions bird/meshing/stirred_tank_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def get_globalindex_of(splti, ci, zi, react):
centeroffset = react.centeroffset
polyoffset = react.polyoffset
nsplits = react.nsplits
hub_circ = react.hub_circ
tank_circ = react.tank_circ

# also works for ci=-1
global_id = (
Expand Down Expand Up @@ -173,8 +171,6 @@ def write_edges(outfile, react):
for zi in range(nsections):
outfile.write("\n//section " + str(zi) + "\n")

offset = 1 + nsplits # one for center and nsplits for polygon

outfile.write("\n//circles\n")
for ci in range(ncirc):
outfile.write("\n//circle " + str(ci) + "\n")
Expand Down
5 changes: 1 addition & 4 deletions bird/postprocess/conditional_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def compute_cond_mean(
):
time_float_sorted, time_str_sorted = get_case_times(case_folder)
cell_centers, _ = read_cell_centers(case_folder)
nCells = len(cell_centers)
assert len(diff_val_list) == len(diff_name_list)
window_ave = min(window_ave, len(time_str_sorted))

Expand All @@ -38,11 +37,9 @@ def compute_cond_mean(
field_file.append(
os.path.join(case_folder, time_folder, field_name)
)

for filename, name in zip(field_file, field_name_list):
val_dict = {}
field_tmp, _ = read_field(
case_folder, time_folder, field_name=field_name
case_folder, time_folder, field_name=name
)
vert_axis, field_cond_tmp = conditional_average(
cell_centers[:, vert_ind], field_tmp, nbins=n_bins
Expand Down
5 changes: 2 additions & 3 deletions bird/postprocess/early_pred.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


def plotAllEarly(data_dict, color_files=None, chop=False, extrap=False):
fig = plt.figure()
plt.figure()
for idat, datf in enumerate(data_dict):
if color_files is not None:
color = color_files[idat]
Expand Down Expand Up @@ -56,14 +56,13 @@ def plotAllEarly(data_dict, color_files=None, chop=False, extrap=False):


def plotAllEarly_uq(data_dict, color_files=None):
fig = plt.figure()
plt.figure()
for idat, datf in enumerate(data_dict):
color = color_files[idat]
text = data_dict[datf]["textrap"]
t = data_dict[datf]["t"]
y = data_dict[datf]["y"] * 100
med_real = data_dict[datf]["med_real"] * 100
mean_real = data_dict[datf]["mean_real"] * 100
std16_real = data_dict[datf]["std16_real"] * 100
std84_real = data_dict[datf]["std84_real"] * 100

Expand Down
5 changes: 2 additions & 3 deletions bird/postprocess/kla_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ def post_cal(
"""
np_hmc_samples = hmc_samples_2_np_samples(hmc_samples)
labels_np = ["cstar", "kla", "sigma"]
nsamples = np_hmc_samples.shape[0]
labels = list(hmc_samples.keys())
nparams = len(labels)

Expand All @@ -322,7 +321,7 @@ def post_cal(
p10_real = pred_dict["p10_pred"]
p90_real = pred_dict["p90_pred"]

fig = plt.figure()
plt.figure()
plt.plot(
time_obs, mean_real, color="k", linewidth=3, label="mean predictions"
)
Expand Down Expand Up @@ -367,6 +366,6 @@ def print_res_dict(res_dict: dict) -> None:
if bs:
logger.info(f"\tkla = {kla*3600:.4g} +/- {kla_err*3600:.4g} [h-1]")
logger.info(f"\tcstar = {cs:.4g} +/- {cs_err:.4g} [mol/m3]")
logger.info(f"Without data bootstrap")
logger.info("Without data bootstrap")
logger.info(f"\tkla = {kla_nb*3600:.4g} +/- {kla_err_nb*3600:.4g} [h-1]")
logger.info(f"\tcstar = {cs_nb:.4g} +/- {cs_err_nb:.4g} [mol/m3]")
9 changes: 9 additions & 0 deletions bird/postprocess/post_quantities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@
"sherwood",
"weber",
]

# Private cell-selection helpers re-exported for the test suite (imported by tests/).
__all__ += [
"_field_filter",
"_get_ind_gas",
"_get_ind_liq",
"_get_ind_slice",
"_weighted_average",
]
14 changes: 7 additions & 7 deletions bird/preprocess/dynamic_mixer/io_fvModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def write_preamble(output_folder):
f.write("\t\tconst volVectorField& UL =\n")
f.write('\t\t\tmesh().lookupObject<volVectorField>("U.liquid");\n')
f.write("\t\tdouble pi=3.141592654;\n")
f.write(f"\t\tdouble source_pt_x;\n")
f.write(f"\t\tdouble source_pt_y;\n")
f.write(f"\t\tdouble source_pt_z;\n")
f.write(f"\t\tdouble disk_rad;\n")
f.write("\t\tdouble source_pt_x;\n")
f.write("\t\tdouble source_pt_y;\n")
f.write("\t\tdouble source_pt_z;\n")
f.write("\t\tdouble disk_rad;\n")
f.write("\t\tdouble disk_area;\n")
f.write(f"\t\tdouble power;\n")
f.write(f"\t\tdouble smear_factor;\n")
f.write(f"\t\tdouble startTime;\n")
f.write("\t\tdouble power;\n")
f.write("\t\tdouble smear_factor;\n")
f.write("\t\tdouble startTime;\n")


def write_mixer(mixer, output_folder):
Expand Down
18 changes: 9 additions & 9 deletions bird/preprocess/json_gen/generate_designs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,29 +152,29 @@ def write_script_start(filename, n):
for i in range(n):
sim_folder = id2simfolder(i)
f.write(f"cd {sim_folder}\n")
f.write(f"sbatch script\n")
f.write(f"cd ..\n")
f.write("sbatch script\n")
f.write("cd ..\n")


def write_script_post(filename, n):
with open(filename, "w+") as f:
for i in range(n):
sim_folder = id2simfolder(i)
f.write(f"cd {sim_folder}\n")
f.write(f"sbatch script_post\n")
f.write(f"cd ..\n")
f.write("sbatch script_post\n")
f.write("cd ..\n")


def write_prep(filename, n):
with open(filename, "w+") as f:
f.write("prep () {\n")
f.write(f"\tcd $1\n")
f.write(f"\treconstructPar -newTimes\n")
f.write(f"\tcd ..\n")
f.write("\tcd $1\n")
f.write("\treconstructPar -newTimes\n")
f.write("\tcd ..\n")
f.write("}\n")
f.write(f"\n")
f.write("\n")
f.write(
f"source /projects/gas2fuels/ofoam_cray_mpich/OpenFOAM-dev/etc/bashrc\n"
"source /projects/gas2fuels/ofoam_cray_mpich/OpenFOAM-dev/etc/bashrc\n"
)
for i in range(n):
sim_folder = id2simfolder(i)
Expand Down
1 change: 0 additions & 1 deletion bird/preprocess/stl_patch/stl_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def make_circle(radius, center, normal_dir, npts=3):


def make_spider(centerRad, nArms, widthArms, lengthArms, center, normal_dir):
globalArea = 0
if nArms < 2:
error_msg = f"nArms ({nArms}) must be >= 2"
logger.error(error_msg)
Expand Down
11 changes: 11 additions & 0 deletions bird/utilities/ofio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@
"species_name_to_mw",
"write_openfoam_dict",
]

# Helpers
__all__ += [
"_find_header_size",
"_get_mesh_time",
"_get_volume_time",
"_read_mesh",
"_readOF",
"_readOFScal",
"_readOFVec",
]
1 change: 0 additions & 1 deletion bird/utilities/ofio/foam_field_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def _read_meta_data(filename: str, mode: str | None = None) -> dict:
sline = line.split()
for ientry, entry in enumerate(sline):
if ";" in entry:
ind_end = ientry
break
line_cropped = " ".join(sline[2 : ientry + 1])
unif_value = _ofvec2arr(line_cropped.strip(";"))
Expand Down
4 changes: 2 additions & 2 deletions bird/utilities/ofio/global_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def repl(match):
# result = int(result)
cross_referenced_globalVars_dict[key] = result

except Exception as e:
except Exception:
logger.warning(
f"Could not evaluate globalVars expression for {key}: {expr}"
)
Expand Down Expand Up @@ -124,7 +124,7 @@ def repl_direct(match):
# if result.is_integer():
# result = int(result)
cross_referenced_globalVars_dict[key] = result
except Exception as e:
except Exception:
logger.warning(
f"Could not evaluate globalVars expression for {key}: {expr}"
)
Expand Down
2 changes: 1 addition & 1 deletion bird/utilities/ofio/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def read_mu_liquid(
mu_liq = globalVars["muMixLiq"]
if mu_liq is None:
logger.error(
f"Liquid viscosity is not constant, yet could not find thermo:mu.liquid"
"Liquid viscosity is not constant, yet could not find thermo:mu.liquid"
)
raise FileNotFoundError(err)
else:
Expand Down
47 changes: 43 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run_cleanup(session: nox.Session) -> None:
@nox.session(name="linter", python=False)
def run_lint(session: nox.Session) -> None:
"""
Run black and isort with the github config file
Run black and isort, then pyflakes on the bird library

"""

Expand All @@ -59,9 +59,6 @@ def run_lint(session: nox.Session) -> None:
"black",
"--line-length",
"79",
# Target the OLDEST python supported in pyproject.toml, not the newest.
# This flag tells black which syntax it may emit, so targeting py314
# let it rewrite `except (A, B):` into py3.14-only `except A, B:`
"--target-version",
"py311",
"--exclude",
Expand Down Expand Up @@ -97,6 +94,48 @@ def run_lint(session: nox.Session) -> None:
session.run(*black_command)
session.run(*isort_command)

run_pyflakes(session)


@nox.session(name="pyflakes", python=False)
def run_pyflakes(session: nox.Session) -> None:
"""
Run pyflakes on the bird library only
"""

session.run("pip", "install", "--upgrade", "--quiet", "pyflakes")

output = session.run(
"pyflakes",
"bird",
external=True,
silent=True,
success_codes=[0, 1],
)

ignored_messages = (
"unable to detect undefined names",
"may be undefined, or defined from star imports",
)
# Script-only subtrees under bird/
excluded_paths = (
"bird/preprocess/data_case_gen/",
"bird/preprocess/inhomogeneousBC/",
"bird/postprocess/SA_optimization/",
"bird/postprocess/computeQoI/",
)

problems = [
line
for line in (output or "").splitlines()
if line.strip()
and not any(msg in line for msg in ignored_messages)
and not any(path in line for path in excluded_paths)
]

if problems:
session.error("pyflakes found issues:\n" + "\n".join(problems))


@nox.session(name="spell", python=False)
@nox.session(name="codespell", python=False)
Expand Down
Loading
Loading