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
15 changes: 9 additions & 6 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ jobs:
python-version: '3.10'
cache: 'pip'

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
python -m pip install --upgrade pip
pip install -e .
pip install -e .
pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints

- name: Build documentation
Expand Down
41 changes: 25 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,22 @@ jobs:
with:
python-version: ${{matrix.python-version}}

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
pip install --upgrade pip
pip install .
pip install .
pip install pytest

- name: Test
Expand All @@ -102,17 +105,20 @@ jobs:
with:
python-version: ${{matrix.python-version}}

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
pip install --upgrade pip
pip install nrel-bird
pip install pytest
Expand Down Expand Up @@ -141,17 +147,20 @@ jobs:
with:
openfoam-version: 9

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
pip install --upgrade pip
pip install .

Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ jobs:
python-version: '3.13'
cache: 'pip'

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
pip install --upgrade pip
pip install pytest
pip install pytest-cov
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ jobs:
with:
python-version: '3.10'
cache: 'pip'
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3

- name: Set up micromamba
uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test-env
python-version: ${{matrix.python-version}}
environment-name: test-env
create-args: >-
python=${{ matrix.python-version }}
channels: conda-forge
channel-priority: strict
cache-downloads: true
cache-env: true

- name: Install dependencies
run: |
conda install -y -c conda-forge paraview
micromamba install --yes -n test-env -c conda-forge paraview
pip install --upgrade pip
pip install -e .
pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints
Expand Down
4 changes: 2 additions & 2 deletions applications/write_stl_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

if args.verbose:
# plot
from bird.utilities.stl_plotting import plotSTL, plt, pretty_labels
from bird.utilities.stl_plotting import plot_stl, plt, pretty_labels

axes = plotSTL("inlets.stl")
axes = plot_stl("inlets.stl")
pretty_labels("x", "y", zlabel="z", fontsize=14, ax=axes)
plt.show()
5 changes: 3 additions & 2 deletions bird/calibration/param_nn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import time
from pathlib import Path

import joblib
import numpy as np
Expand Down Expand Up @@ -306,8 +307,8 @@ def load(self, weight_file):
self.model.load_weights(weight_file)

def prepareLog(self):
os.makedirs(self.model_folder, exist_ok=True)
os.makedirs(self.log_loss_folder, exist_ok=True)
Path(self.model_folder).mkdir(parents=True, exist_ok=True)
Path(self.log_loss_folder).mkdir(parents=True, exist_ok=True)
try:
os.remove(os.path.join(self.log_loss_folder, "log.csv"))
except FileNotFoundError as err:
Expand Down
4 changes: 1 addition & 3 deletions bird/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class ConditionalFormatter(logging.Formatter):
def format(self, record):
"""Change how to log if it is an INFO or a WARNING/ERROR"""
if record.levelno >= logging.WARNING:
self._style._fmt = (
"%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
self._style._fmt = "%(asctime)s [%(levelname)s] bird: %(message)s"
else:
self._style._fmt = "%(asctime)s [%(levelname)s] bird: %(message)s"
return super().format(record)
Expand Down
66 changes: 19 additions & 47 deletions bird/meshing/_mesh_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from bird import logger
from bird.utilities.mathtools import bissection


def make_walls_from_topo(topo_dict: dict) -> dict:
Expand Down Expand Up @@ -70,8 +71,8 @@ def make_bound_from_topo(topo_dict):
}


def stretch_fun(G, N1):
result = (1.0 - G) / (G * (1 - np.power(G, 1.0 / N1)))
def stretch_fun(G, N):
result = (1.0 - G) / (G * (1 - np.power(G, 1.0 / N)))
return result


Expand All @@ -80,29 +81,6 @@ def stretch_fun(G, N1):
# return result


def bissection(val, stretch_fun, N1):
Gmin = 0.00001
Gmax = 1000000
resultmin = stretch_fun(Gmin, N1) - val
resultmax = stretch_fun(Gmax, N1) - val
if resultmin * resultmax > 0:
error_msg = "Initial bounds of grading do not encompass the solution"
logger.error(error_msg)
raise ValueError(error_msg)

for i in range(1000):
Gmid = 0.5 * (Gmax + Gmin)
resultmid = stretch_fun(Gmid, N1) - val
if resultmid * resultmax < 0:
Gmin = Gmid
resultmin = resultmid
else:
Gmax = Gmid
resultmax = resultmid

return Gmid


def is_wall(l_wall: list[int], r_wall: list[int], ir: int, il: int) -> int:
"""
Is the present block a wall (not meshed)
Expand Down Expand Up @@ -223,19 +201,17 @@ def verticalCoarsening(
raise ValueError(error_msg)

if ratio_dir[ind] == "+":
gradVert[ind] = 1.0 / bissection(
length / deltaE, stretch_fun, NVert[ind]
)
nl_func = lambda x: stretch_fun(x, NVert[ind])
gradVert[ind] = 1.0 / bissection(length / deltaE, nl_func)
iterate = False
origNVert = NVert[ind]
while gradVert[ind] < 1 and NVert[ind] > 1:
iterate = True
NVert[ind] = max(
int(round(min(0.99 * NVert[ind], NVert[ind] - 1))), 1
)
gradVert[ind] = 1.0 / bissection(
length / deltaE, stretch_fun, NVert[ind]
)
nl_func = lambda x: stretch_fun(x, NVert[ind])
gradVert[ind] = 1.0 / bissection(length / deltaE, nl_func)
if iterate:
logger.warning(
f"reduced NVert[{ind}] from {origNVert} to {NVert[ind]}"
Expand All @@ -245,9 +221,8 @@ def verticalCoarsening(

elif ratio_dir[ind] == "-":
deltaE = block_cell_minus_length[ind - 1]
gradVert[ind] = bissection(
length / deltaE, stretch_fun, NVert[ind]
)
nl_func = lambda x: stretch_fun(x, NVert[ind])
gradVert[ind] = bissection(length / deltaE, nl_func)

iterate = False
origNVert = NVert[ind]
Expand All @@ -256,9 +231,8 @@ def verticalCoarsening(
NVert[ind] = max(
int(round(min(0.99 * NVert[ind], NVert[ind] - 1))), 1
)
gradVert[ind] = bissection(
length / deltaE, stretch_fun, NVert[ind]
)
nl_func = lambda x: stretch_fun(x, NVert[ind])
gradVert[ind] = bissection(length / deltaE, nl_func)
if iterate:
logger.warning(
f"reduced NVert[{ind}] from {origNVert} to {NVert[ind]}"
Expand Down Expand Up @@ -337,19 +311,17 @@ def radialCoarsening(
raise ValueError(error_msg)

if ratio_dir[ind] == "+":
gradR[ind] = 1.0 / bissection(
length / deltaE, stretch_fun, NR[ind]
)
nl_func = lambda x: stretch_fun(x, NR[ind])
gradR[ind] = 1.0 / bissection(length / deltaE, nl_func)
iterate = False
origNR = NR[ind]
while gradR[ind] < 1 and NR[ind] > 1:
iterate = True
NR[ind] = max(
int(round(min(0.99 * NR[ind], NR[ind] - 1))), 1
)
gradR[ind] = 1.0 / bissection(
length / deltaE, stretch_fun, NR[ind]
)
nl_func = lambda x: stretch_fun(x, NR[ind])
gradR[ind] = 1.0 / bissection(length / deltaE, nl_func)
if iterate:
logger.warning(
f"reduced NR[{ind}] from {origNR} to {NR[ind]}"
Expand All @@ -359,15 +331,15 @@ def radialCoarsening(

elif ratio_dir[ind] == "-":
deltaE = block_cell_minus_length[ind - 1]
gradR[ind] = bissection(length / deltaE, stretch_fun, NR[ind])
nl_func = lambda x: stretch_fun(x, NR[ind])
gradR[ind] = bissection(length / deltaE, nl_func)
iterate = False
origNR = NR[ind]
while gradR[ind] > 1 and NR[ind] > 1:
iterate = True
NR[ind] = max(int(round(min(0.99 * NR[ind], -1))), 1)
gradR[ind] = bissection(
length / deltaE, stretch_fun, NR[ind]
)
nl_func = lambda x: stretch_fun(x, NR[ind])
gradR[ind] = bissection(length / deltaE, nl_func)
if iterate:
logger.warning(
f"reduced NR[{ind}] from {origNR} to {NR[ind]}"
Expand Down
9 changes: 0 additions & 9 deletions bird/meshing/block_cyl_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,3 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict):

fw.close()


def main(input_file, topo_file, output_folder):
geom_dict = assemble_geom(input_file, topo_file)
mesh_dict = assemble_mesh(input_file, geom_dict)
writeBlockMeshDict(output_folder, geom_dict, mesh_dict)


if __name__ == "__main__":
main()
14 changes: 3 additions & 11 deletions bird/postprocess/early_pred.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def multi_data_load(data_root, tmax=600, data_files=None, color_files=None):
A = np.loadtxt(filename)
data_dict[datf] = {}
data_dict[datf]["t"] = A[:, 0]
data_dict[datf]["y"] = A[:, 5] / (A[:, 4] * 16 / 44 + A[:, 5])
data_dict[datf]["y"] = A[:, 5] / np.clip(
(A[:, 4] * 16 / 44 + A[:, 5]), a_min=1e-12, a_max=None
)
# chop data before increase and right after t=10s
increase_ind_arr = np.argwhere(np.diff(data_dict[datf]["y"]) > 0)
increase_ind = increase_ind_arr[
Expand Down Expand Up @@ -264,13 +266,3 @@ def bayes_fit(data_dict, num_warmup=1000, num_samples=500):

return data_dict


if __name__ == "__main__":
from bird import BIRD_EARLY_PRED_DATA_DIR

data_dict, color_files = multi_data_load(BIRD_EARLY_PRED_DATA_DIR)
data_dict = fit_and_ext(data_dict)
plotAllEarly(data_dict, color_files=color_files, chop=True, extrap=True)
bayes_fit(data_dict)
plotAllEarly_uq(data_dict, color_files=color_files)
plt.show()
4 changes: 0 additions & 4 deletions bird/postprocess/kla_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,3 @@ def print_res_dict(res_dict: dict) -> None:
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]")


if __name__ == "__main__":
res_dict = compute_kla("data_kla/volume_avg.dat", time_ind=0, conc_ind=1)
print_res_dict(res_dict)
Loading
Loading