Skip to content

Commit

Permalink
Added PointValue class
Browse files Browse the repository at this point in the history
  • Loading branch information
KulaginVladimir committed Nov 28, 2023
1 parent d6651c2 commit bf943af
Show file tree
Hide file tree
Showing 4 changed files with 58 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
19 changes: 19 additions & 0 deletions festim/exports/derived_quantities/point_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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, list): the point coordinates
"""

def __init__(self, field: str or int, x: float or list) -> None:
super().__init__(field)
self.x = x
self.title = "{} value at {}".format(field, x)

def compute(self):
"""The value at the point"""
return self.function(self.x)
34 changes: 34 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,34 @@
from festim import PointValue
import fenics as f
import pytest


def test_title_H():
x = 1
field = "solute"
my_value = PointValue(field, x)
assert my_value.title == "{} value at {}".format(field, x)


def test_title_T():
x = 1
field = "T"
my_value = PointValue(field, x)
assert my_value.title == "{} value at {}".format(field, x)


class TestCompute:
mesh = f.UnitIntervalMesh(10)
V = f.FunctionSpace(mesh, "P", 1)

c = f.interpolate(f.Expression("x[0]", degree=1), V)

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

def test_minimum(self):
expected = self.c(self.x)

produced = self.my_value.compute()
assert produced == expected

0 comments on commit bf943af

Please sign in to comment.