diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 193479e7..f154d4b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,16 +23,15 @@ jobs: channels: conda-forge environment-file: environment.yml - - name: Run example + - name: install HISP shell: bash -l {0} - run: python simple_mb.py + run: python -m pip install .[test] - - name: Install dependencies + - name: Run tests shell: bash -l {0} run: | - pip install pytest pytest-cov + pytest test/ --cov festim --cov-report xml --cov-report term - - name: Run tests + - name: Run example shell: bash -l {0} - run: | - pytest tests/ --cov festim --cov-report xml --cov-report term + run: python simple_mb.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e9a471c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# version file +**_version.py + +# Input/Output files +*.bp +*.xdmf +*.h5 \ No newline at end of file diff --git a/example_reading_scenario_file.py b/example_reading_scenario_file.py deleted file mode 100644 index f1757378..00000000 --- a/example_reading_scenario_file.py +++ /dev/null @@ -1,31 +0,0 @@ -from helpers import Scenario - -my_scenario = Scenario("scenario.txt") - -print(my_scenario.data) - -import numpy as np - -times = np.linspace(0, my_scenario.get_maximum_time(), 1000) -pulse_types = [] -for t in times: - pulse_type = my_scenario.get_pulse_type(t) - pulse_types.append(pulse_type) - -import matplotlib.pyplot as plt - -# color the line based on the pulse type -color = { - "FP": "red", - "ICWC": "blue", - "RISP": "green", - "GDC": "orange", - "BAKE": "purple", -} - -colors = [color[pulse_type] for pulse_type in pulse_types] - -for i in range(len(times) - 1): - plt.plot(times[i : i + 2], np.ones_like(times[i : i + 2]), c=colors[i]) -# plt.xscale("log") -plt.show() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..49ecce08 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools >= 61", "wheel", "setuptools-scm[toml] >= 7.0.5"] +build-backend = "setuptools.build_meta" + +[project] +authors = [ + { name = "Kaelyn Dunnell" }, + { email = "kaelyn@mit.edu" }, +] +dynamic = ["version"] +name = "HISP" +description = "Hydrogen Inventory Simulations of PFCs" +readme = "README/md" +requires-python = ">=3.9" +license = { file = "LICENSE" } +dependencies = ["h_transport_materials"] +classifiers = [ + "Natural Language :: English", + "Topic :: Scientific/Engineering", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "License :: OSI Approved :: MIT", + "Operating System :: OS Independent", +] + +[project.optional-dependencies] +test = ["pytest >= 5.4.3", "pytest-cov"] + +[project.urls] +Homepage = "https://github.com/RemDelaporteMathurin/FESTIM" +Issues = "https://github.com/RemDelaporteMathurin/FESTIM/issues" + + +[tool.setuptools_scm] +write_to = "src/hisp/_version.py" diff --git a/simple_mb.py b/simple_mb.py index d0a2d329..a95d3f56 100644 --- a/simple_mb.py +++ b/simple_mb.py @@ -10,8 +10,8 @@ import dolfinx.fem as fem import dolfinx -from helpers import PulsedSource, Scenario -from new_h_transport_class import CustomProblem +from hisp.helpers import PulsedSource, Scenario +from hisp import CustomProblem # dolfinx.log.set_log_level(dolfinx.log.LogLevel.INFO) diff --git a/src/hisp/__init__.py b/src/hisp/__init__.py new file mode 100644 index 00000000..391c7d92 --- /dev/null +++ b/src/hisp/__init__.py @@ -0,0 +1,3 @@ +from .helpers import PulsedSource, Scenario + +from .h_transport_class import CustomProblem diff --git a/new_h_transport_class.py b/src/hisp/h_transport_class.py similarity index 100% rename from new_h_transport_class.py rename to src/hisp/h_transport_class.py diff --git a/helpers.py b/src/hisp/helpers.py similarity index 100% rename from helpers.py rename to src/hisp/helpers.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scenario_test.txt b/test/scenario_test.txt similarity index 100% rename from scenario_test.txt rename to test/scenario_test.txt diff --git a/test/test_scenario.py b/test/test_scenario.py new file mode 100644 index 00000000..0b3eee08 --- /dev/null +++ b/test/test_scenario.py @@ -0,0 +1,55 @@ +from hisp.helpers import Scenario +import os +import pytest +import numpy as np +import matplotlib.pyplot as plt + +current_dir = os.path.dirname(__file__) +scenario_path = os.path.join(current_dir, "scenario_test.txt") + + +def test_maximum_time(): + # BUILD + my_scenario = Scenario(scenario_path) + expected_maximum_time = 2 * (455 + 455 + 650 + 1000) + 2 * (36 + 36 + 180 + 1000) + + # RUN + computed_maximum_time = my_scenario.get_maximum_time() + + # TEST + assert computed_maximum_time == expected_maximum_time + + +@pytest.mark.parametrize("t, expected_row", [(0, 0), (6000, 1)]) +def test_get_pulse_row(t, expected_row): + my_scenario = Scenario(scenario_path) + + pulse_row = my_scenario.get_row(t=t) + + assert pulse_row == expected_row + + +def test_reading_a_file(): + my_scenario = Scenario(scenario_path) + + times = np.linspace(0, my_scenario.get_maximum_time(), 1000) + pulse_types = [] + for t in times: + pulse_type = my_scenario.get_pulse_type(t) + pulse_types.append(pulse_type) + + # color the line based on the pulse type + color = { + "FP": "red", + "ICWC": "blue", + "RISP": "green", + "GDC": "orange", + "BAKE": "purple", + } + + colors = [color[pulse_type] for pulse_type in pulse_types] + + for i in range(len(times) - 1): + plt.plot(times[i : i + 2], np.ones_like(times[i : i + 2]), c=colors[i]) + # plt.xscale("log") + # plt.show()