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
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
112 changes: 112 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
31 changes: 0 additions & 31 deletions example_reading_scenario_file.py

This file was deleted.

38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions simple_mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/hisp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .helpers import PulsedSource, Scenario

from .h_transport_class import CustomProblem
File renamed without changes.
File renamed without changes.
Empty file added test/__init__.py
Empty file.
File renamed without changes.
55 changes: 55 additions & 0 deletions test/test_scenario.py
Original file line number Diff line number Diff line change
@@ -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()