Skip to content

Commit 4a34230

Browse files
authored
Merge pull request #7 from LIBRA-project/refactoring
Refactoring
2 parents eb2a429 + f02586e commit 4a34230

15 files changed

Lines changed: 1327 additions & 626 deletions

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
- name: Run tests
2828
shell: bash -l {0}
2929
run: |
30-
python -m pytest test
30+
python -m pytest test --cov src/sparging --cov-report xml
3131
32-
# - name: Upload to codecov
33-
# uses: codecov/codecov-action@v4
34-
# with:
35-
# token: ${{ secrets.CODECOV_TOKEN }}
36-
# files: ./coverage.xml
32+
- name: Upload to codecov
33+
uses: codecov/codecov-action@v4
34+
with:
35+
token: ${{ secrets.CODECOV_TOKEN }}
36+
files: ./coverage.xml

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ cover/
5656
*.pot
5757

5858
# Django stuff:
59-
*.log
6059
local_settings.py
6160
db.sqlite3
6261
db.sqlite3-journal
@@ -211,5 +210,6 @@ __marimo__/
211210
*.csv
212211
mwe.py
213212
*.json
213+
!standard_input.json
214214
*.ipynb
215215
*.code-workspace

example2.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from sparging.config import ureg
2+
from sparging import all_correlations
3+
from sparging import animation
4+
from sparging.model import Simulation
5+
from sparging.inputs import (
6+
ColumnGeometry,
7+
BreederMaterial,
8+
OperatingParameters,
9+
SpargingParameters,
10+
SimulationInput,
11+
)
12+
import logging
13+
from typing import TYPE_CHECKING
14+
15+
if TYPE_CHECKING:
16+
import pint
17+
18+
logger = logging.getLogger(__name__)
19+
logging.basicConfig(level=logging.WARNING)
20+
21+
22+
geom = ColumnGeometry(
23+
area=0.2 * ureg.m**2,
24+
height=1.0 * ureg.m,
25+
nozzle_diameter=0.001 * ureg.m,
26+
nb_nozzle=10 * ureg.dimensionless,
27+
)
28+
29+
flibe = BreederMaterial(
30+
name="FLiBe",
31+
)
32+
33+
operating_params = OperatingParameters(
34+
temperature=600 * ureg.celsius,
35+
P_top=1 * ureg.atm,
36+
flow_g_mol=400 * ureg.sccm,
37+
tbr=0.1 * ureg("triton / neutron"),
38+
n_gen_rate=1e9 * ureg("neutron / s"),
39+
)
40+
41+
sparging_params = SpargingParameters(
42+
h_l=all_correlations("h_l_briggs"),
43+
)
44+
45+
46+
# class method from_parameters that takes in objects like ColumnGeometry, BreederMaterial, OperatingParameters and returns a SimulationInput object with the appropriate correlations for the given parameters. This method should be able to handle cases where some of the parameters are already provided as correlations and should not overwrite them.
47+
my_input = SimulationInput.from_parameters(
48+
geom, flibe, operating_params, sparging_params
49+
)
50+
logger.info(my_input)
51+
52+
53+
def profile_source_T(z: pint.Quantity):
54+
import numpy as np
55+
56+
# return np.sin(np.pi / (1 * ureg.m) * z)
57+
return 0.5 * (1 + np.cos(0.5 * np.pi / (1 * ureg.m) * z))
58+
59+
60+
my_simulation = Simulation(
61+
my_input,
62+
t_final=3 * ureg.days,
63+
signal_irr=lambda t: 1 if t < 12 * ureg.hour else 0,
64+
signal_sparging=lambda t: 1,
65+
)
66+
output = my_simulation.solve()
67+
68+
# # save output to file
69+
# output.profiles_to_csv(f"output_{tank_height}m.csv")
70+
71+
# # plot results
72+
# from sparging import plotting
73+
# plotting.plot_animation(output)
74+
75+
76+
animation.create_animation(output, show_activity=True)

main.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ addopts = "-v"
5050

5151
[tool.setuptools.package-data]
5252
sparging = ["*.yaml", "*.yml"]
53+
54+
[tool.coverage.run]
55+
source = ["src/sparging"]
56+
omit = [
57+
"src/sparging/animation.py"
58+
]

src/sparging/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
libra_sparging: A finite element model for sparging processes using FEniCSx/DOLFINX.
33
"""
44

5-
from .config import ureg, const_R, const_g, VERBOSE
5+
from .config import ureg, const_R, const_g
66
from .model import SimulationResults
77
from .animation import ConcentrationAnimator
8-
from .helpers import *
9-
from .correlations import *
8+
from .correlations import all_correlations, CorrelationGroup, Correlation
109

1110
__all__ = [
1211
"SimulationInput",
@@ -15,5 +14,4 @@
1514
"ureg",
1615
"const_R",
1716
"const_g",
18-
"VERBOSE",
1917
]

src/sparging/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from pint import UnitRegistry
22
import scipy.constants as const
33

4-
VERBOSE = False
5-
64
ureg = UnitRegistry(
75
autoconvert_offset_to_baseunit=True
86
) # to deal with offset units (eg: degree celsius)

0 commit comments

Comments
 (0)