Skip to content

Commit

Permalink
Merge pull request #22 from finsberg/formatting
Browse files Browse the repository at this point in the history
Update hooks and build docs settings
  • Loading branch information
finsberg authored Jun 18, 2024
2 parents 228002c + d881d89 commit 24c8a22
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 140 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ jobs:

build:
runs-on: ubuntu-22.04
container: ghcr.io/fenics/dolfinx/lab:nightly
container: ghcr.io/fenics/dolfinx/lab:v0.8.0
env:
PUBLISH_DIR: ./_build/html
DISPLAY: ":99.0"
PYVISTA_TRAME_SERVER_PROXY_PREFIX: "/proxy/"
PYVISTA_TRAME_SERVER_PROXY_ENABLED: "True"
PYVISTA_OFF_SCREEN: false
Expand Down
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ repos:
- id: debug-statements
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.278'
rev: 'v0.3.7'
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
exclude: 'demos/.*.py$'


- repo: https://github.com/asottile/add-trailing-comma
Expand Down
27 changes: 12 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# Use github pages for docker image
FROM ghcr.io/finsberg/fenicsx-pulse:v0.1.5
# We choose ubuntu 22.04 as our base docker image
FROM ghcr.io/fenics/dolfinx/dolfinx:v0.8.0

# Create user with a home directory
ARG NB_USER
ARG NB_UID=1000
ENV USER ${NB_USER}
ENV HOME /home/${NB_USER}
ENV PYVISTA_JUPYTER_BACKEND="html"

# Copy current directory
WORKDIR ${HOME}
COPY . ${HOME}
# Requirements for pyvista
RUN apt-get update && apt-get install -y libgl1-mesa-glx libxrender1 xvfb nodejs

# Change ownership of home directory
USER root
RUN chown -R ${NB_UID} ${HOME}
COPY . /repo
WORKDIR /repo

USER ${NB_USER}
ENTRYPOINT []
ARG TARGETPLATFORM
RUN echo "Building for $TARGETPLATFORM"
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then python3 -m pip install "https://github.com/finsberg/vtk-aarch64/releases/download/vtk-9.2.6-cp310/vtk-9.2.6.dev0-cp310-cp310-linux_aarch64.whl"; fi

RUN python3 -m pip install ".[docs]"
6 changes: 3 additions & 3 deletions demo/unit_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#
# First let us do the necessary imports

import dolfinx
import numpy as np
import fenicsx_pulse
from mpi4py import MPI
from petsc4py import PETSc

import dolfinx
import fenicsx_pulse
import numpy as np

# Then we can create unit cube mesh

Expand Down
24 changes: 0 additions & 24 deletions docker/Dockerfile

This file was deleted.

60 changes: 42 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ dev = [
docs = [
"jupyter-book",
"jupytext",
"pyvista"
"jupyter",
"cardiac-geometriesx",
"pyvista[all]>=0.43.0",
"trame-vuetify",
"ipywidgets",
]

all = [
Expand All @@ -46,23 +50,8 @@ testpaths = [
"tests"
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"pass",
"raise NotImplementedError",
"def __str__"
]

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F"]
ignore = ["E402", "E741", "E731"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
Expand All @@ -85,17 +74,52 @@ exclude = [
"dist",
"node_modules",
"venv",
"demos",
]

# Same as Black.
line-length = 100

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.mccabe]

[tool.ruff.lint]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F", "I"]
ignore = ["E402", "E741", "E743", "E731"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "I"]
unfixable = []

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10


[tool.ruff.lint.isort]
known-first-party = ["cardiac_geometries"]
known-third-party = [
"basix",
"dolfinx",
"ffcx",
"ufl",
"gmsh",
"numpy",
"pytest",
]
section-order = [
"future",
"standard-library",
"mpi",
"third-party",
"first-party",
"local-folder",
]
[tool.ruff.lint.isort.sections]
"mpi" = ["mpi4py", "petsc4py"]
37 changes: 20 additions & 17 deletions src/fenicsx_pulse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Top-level package for fenicsx_pulse."""

from importlib.metadata import metadata

meta = metadata("fenicsx_pulse")
Expand All @@ -8,26 +9,28 @@
__email__ = meta["Author-email"]
__program_name__ = meta["Name"]

from . import kinematics
from . import invariants
from . import material_model
from .material_model import HyperElasticMaterial
from . import compressibility
from .compressibility import Compressible, Incompressible
from . import exceptions
from . import cardiac_model
from .cardiac_model import CardiacModel
from . import active_model
from . import active_stress
from . import (
active_model,
active_stress,
boundary_conditions,
cardiac_model,
compressibility,
exceptions,
geometry,
invariants,
kinematics,
material_model,
mechanicsproblem,
)
from .active_stress import ActiveStress
from . import geometry
from .boundary_conditions import BoundaryConditions, NeumannBC, RobinBC
from .cardiac_model import CardiacModel
from .compressibility import Compressible, Incompressible
from .geometry import Geometry, Marker
from . import boundary_conditions
from .boundary_conditions import NeumannBC, RobinBC, BoundaryConditions
from . import mechanicsproblem
from .mechanicsproblem import MechanicsProblem
from .linear_elastic import LinearElastic
from .holzapfelogden import HolzapfelOgden
from .linear_elastic import LinearElastic
from .material_model import HyperElasticMaterial
from .mechanicsproblem import MechanicsProblem

__all__ = [
"kinematics",
Expand Down
9 changes: 6 additions & 3 deletions src/fenicsx_pulse/active_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ class ActiveStress(ActiveModel):
activation: dolfinx.fem.Function | dolfinx.fem.Constant = None
s0: dolfinx.fem.Function | dolfinx.fem.Constant | None = None
n0: dolfinx.fem.Function | dolfinx.fem.Constant | None = None
T_ref: dolfinx.fem.Constant = 1.0
eta: dolfinx.fem.Constant = 0.0
T_ref: dolfinx.fem.Constant = dolfinx.default_scalar_type(1.0)
eta: dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
isotropy: ActiveStressModels = ActiveStressModels.transversely

def __post_init__(self) -> None:
if self.activation is None:
self.activation = dolfinx.fem.Constant(self.f0.ufl_domain(), 0.0)
self.activation = dolfinx.fem.Constant(
self.f0.ufl_domain(),
dolfinx.default_scalar_type(0.0),
)

self.T_ref = dolfinx.fem.Constant(self.f0.ufl_domain(), self.T_ref)
self.eta = dolfinx.fem.Constant(self.f0.ufl_domain(), self.eta)
Expand Down
4 changes: 1 addition & 3 deletions src/fenicsx_pulse/boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ class BoundaryConditions(typing.NamedTuple):
]
] = ()
robin: typing.Sequence[RobinBC] = ()
body_force: typing.Sequence[
float | dolfinx.fem.Constant | dolfinx.fem.Function
] = ()
body_force: typing.Sequence[float | dolfinx.fem.Constant | dolfinx.fem.Function] = ()
3 changes: 1 addition & 2 deletions src/fenicsx_pulse/compressibility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
from dataclasses import dataclass
from dataclasses import field
from dataclasses import dataclass, field

import dolfinx
import ufl
Expand Down
3 changes: 2 additions & 1 deletion src/fenicsx_pulse/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import operator
from dataclasses import dataclass

from mpi4py import MPI

import dolfinx
import numpy as np
from mpi4py import MPI


def check_value_greater_than(
Expand Down
15 changes: 3 additions & 12 deletions src/fenicsx_pulse/geometry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing
from dataclasses import dataclass
from dataclasses import field
from dataclasses import dataclass, field
from pathlib import Path
from typing import NamedTuple

Expand Down Expand Up @@ -43,16 +42,8 @@ def __post_init__(self) -> None:
self._facet_indices = hstack(facet_indices)
self._facet_markers = hstack(facet_markers)
self._sorted_facets = np.argsort(self._facet_indices)
entities = (
[]
if len(self._sorted_facets) == 0
else self._facet_indices[self._sorted_facets]
)
values = (
[]
if len(self._sorted_facets) == 0
else self._facet_markers[self._sorted_facets]
)
entities = [] if len(self._sorted_facets) == 0 else self._facet_indices[self._sorted_facets]
values = [] if len(self._sorted_facets) == 0 else self._facet_markers[self._sorted_facets]
self.facet_tags = dolfinx.mesh.meshtags(
self.mesh,
self.facet_dimension,
Expand Down
34 changes: 13 additions & 21 deletions src/fenicsx_pulse/holzapfelogden.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import typing
from dataclasses import dataclass
from dataclasses import field
from dataclasses import dataclass, field
from functools import partial

import dolfinx
import numpy as np
import ufl

from . import exceptions
from . import functions
from . import invariants
from . import exceptions, functions, invariants
from .material_model import HyperElasticMaterial


Expand Down Expand Up @@ -85,16 +82,17 @@ class HolzapfelOgden(HyperElasticMaterial):
3445-3475.
"""

f0: dolfinx.fem.Function | dolfinx.fem.Constant | None = None
s0: dolfinx.fem.Function | dolfinx.fem.Constant | None = None
a: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
b: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
a_f: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
b_f: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
a_s: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
b_s: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
a_fs: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
b_fs: float | dolfinx.fem.Function | dolfinx.fem.Constant = 0.0
a: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
b: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
a_f: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
b_f: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
a_s: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
b_s: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
a_fs: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
b_fs: float | dolfinx.fem.Function | dolfinx.fem.Constant = dolfinx.default_scalar_type(0.0)
use_subplus: bool = field(default=True, repr=False)
use_heaviside: bool = field(default=True, repr=False)

Expand Down Expand Up @@ -163,9 +161,7 @@ def __post_init__(self):
def _resolve_W1(self):
if exceptions.check_value_greater_than(self.a, 1e-10):
if exceptions.check_value_greater_than(self.b, 1e-10):
return lambda I1: (self.a / (2.0 * self.b)) * (
ufl.exp(self.b * (I1 - 3)) - 1.0
)
return lambda I1: (self.a / (2.0 * self.b)) * (ufl.exp(self.b * (I1 - 3)) - 1.0)
else:
return lambda I1: (self.a / 2.0) * (I1 - 3)
else:
Expand Down Expand Up @@ -200,11 +196,7 @@ def _resolve_W8fs(self):
model=type(self).__name__,
)
if exceptions.check_value_greater_than(self.b_fs, 1e-10):
return (
lambda I8: self.a_fs
/ (2.0 * self.b_fs)
* (ufl.exp(self.b_fs * I8**2) - 1.0)
)
return lambda I8: self.a_fs / (2.0 * self.b_fs) * (ufl.exp(self.b_fs * I8**2) - 1.0)
else:
return lambda I8: self.a_fs / 2.0 * I8**2
else:
Expand Down
Loading

0 comments on commit 24c8a22

Please sign in to comment.