Skip to content

Commit

Permalink
Merge pull request #655 from KulaginVladimir/main
Browse files Browse the repository at this point in the history
PointValue class
  • Loading branch information
RemDelaporteMathurin authored Dec 1, 2023
2 parents d6651c2 + d632fc0 commit 6364d46
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/source/api/exports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Exports
:members:
:show-inheritance:

.. autoclass:: PointValue
:members:
:show-inheritance:

.. autoclass:: AverageSurface
:members:
:show-inheritance:
Expand Down
1 change: 1 addition & 0 deletions festim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from .exports.derived_quantities.total_surface import TotalSurface
from .exports.derived_quantities.total_volume import TotalVolume
from .exports.derived_quantities.average_surface import AverageSurface
from .exports.derived_quantities.point_value import PointValue

from .exports.derived_quantities.derived_quantities import DerivedQuantities

Expand Down
22 changes: 22 additions & 0 deletions festim/exports/derived_quantities/point_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from festim import DerivedQuantity


class PointValue(DerivedQuantity):
"""DerivedQuantity relative to a point
Args:
field (str, int): the field ("solute", 0, 1, "T", "retention")
point (int, float, tuple, list): the point coordinates
"""

def __init__(self, field: str or int, x: int or float or tuple or list) -> None:
super().__init__(field)
# make sure x is an iterable
if not hasattr(x, "__iter__"):
x = [x]
self.x = x
self.title = "{} value at {}".format(field, x)

def compute(self):
"""The value at the point"""
return self.function(self.x)
25 changes: 25 additions & 0 deletions test/unit/test_exports/test_derived_quantities/test_point_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from festim import PointValue
import fenics as f
import pytest


@pytest.mark.parametrize("field", ["solute", "T"])
def test_title(field):
x = 1
my_value = PointValue(field, x)
assert my_value.title == "{} value at [{}]".format(field, x)


@pytest.mark.parametrize(
"mesh,x", [(f.UnitIntervalMesh(10), 1), (f.UnitCubeMesh(10, 10, 10), (1, 0, 1))]
)
def test_point_compute(mesh, x):
V = f.FunctionSpace(mesh, "P", 1)
c = f.interpolate(f.Expression("x[0]", degree=1), V)

my_value = PointValue("solute", x)
my_value.function = c

expected = c(x)
produced = my_value.compute()
assert produced == expected

0 comments on commit 6364d46

Please sign in to comment.