forked from festim-dev/FESTIM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6651c2
commit bf943af
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
test/unit/test_exports/test_derived_quantities/test_point_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |