PyFinitDiff 2.0.3.post0__py3-none-any.whl → 2.1.2.post0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyFinitDiff/_version.py +2 -2
- PyFinitDiff/finite_difference_1D/boundaries.py +118 -69
- PyFinitDiff/finite_difference_1D/derivative.py +30 -16
- PyFinitDiff/finite_difference_1D/diagonals.py +155 -82
- PyFinitDiff/finite_difference_1D/finite_difference.py +104 -55
- PyFinitDiff/finite_difference_1D/utils.py +37 -19
- PyFinitDiff/finite_difference_2D/boundaries.py +116 -65
- PyFinitDiff/finite_difference_2D/derivative.py +31 -15
- PyFinitDiff/finite_difference_2D/diagonals.py +122 -78
- PyFinitDiff/finite_difference_2D/finite_difference.py +112 -62
- PyFinitDiff/finite_difference_2D/utils.py +47 -26
- PyFinitDiff/triplet.py +312 -33
- {PyFinitDiff-2.0.3.post0.dist-info → PyFinitDiff-2.1.2.post0.dist-info}/METADATA +53 -28
- PyFinitDiff-2.1.2.post0.dist-info/RECORD +26 -0
- {PyFinitDiff-2.0.3.post0.dist-info → PyFinitDiff-2.1.2.post0.dist-info}/WHEEL +1 -1
- PyFinitDiff/tools/__init__.py +0 -0
- PyFinitDiff-2.0.3.post0.dist-info/RECORD +0 -27
- /PyFinitDiff/{tools/directories.py → directories.py} +0 -0
- {PyFinitDiff-2.0.3.post0.dist-info → PyFinitDiff-2.1.2.post0.dist-info}/LICENSE +0 -0
- {PyFinitDiff-2.0.3.post0.dist-info → PyFinitDiff-2.1.2.post0.dist-info}/top_level.txt +0 -0
PyFinitDiff/_version.py
CHANGED
|
@@ -12,5 +12,5 @@ __version__: str
|
|
|
12
12
|
__version_tuple__: VERSION_TUPLE
|
|
13
13
|
version_tuple: VERSION_TUPLE
|
|
14
14
|
|
|
15
|
-
__version__ = version = '2.
|
|
16
|
-
__version_tuple__ = version_tuple = (2,
|
|
15
|
+
__version__ = version = '2.1.2.post0'
|
|
16
|
+
__version_tuple__ = version_tuple = (2, 1, 2)
|
|
@@ -15,15 +15,19 @@ config_dict = ConfigDict(
|
|
|
15
15
|
frozen=False
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
@dataclass(config=config_dict)
|
|
20
19
|
class Boundary:
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
"""
|
|
21
|
+
Class representing a boundary with a specific name, value, and mesh information.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
name : str
|
|
26
|
+
The name of the boundary.
|
|
27
|
+
value : Optional[str]
|
|
28
|
+
The value associated with the boundary, such as 'symmetric', 'anti-symmetric', 'zero', or 'none'.
|
|
29
|
+
mesh_info : object
|
|
30
|
+
The mesh information object containing information about the mesh size and structure.
|
|
27
31
|
"""
|
|
28
32
|
|
|
29
33
|
name: str
|
|
@@ -31,13 +35,18 @@ class Boundary:
|
|
|
31
35
|
mesh_info: object
|
|
32
36
|
|
|
33
37
|
def get_factor(self) -> float:
|
|
34
|
-
"""
|
|
38
|
+
"""
|
|
39
|
+
Get the factor associated with the boundary value.
|
|
35
40
|
|
|
36
|
-
Returns
|
|
37
|
-
|
|
41
|
+
Returns
|
|
42
|
+
-------
|
|
43
|
+
float
|
|
44
|
+
The factor corresponding to the boundary value.
|
|
38
45
|
|
|
39
|
-
Raises
|
|
40
|
-
|
|
46
|
+
Raises
|
|
47
|
+
------
|
|
48
|
+
ValueError
|
|
49
|
+
If the boundary value is unexpected.
|
|
41
50
|
"""
|
|
42
51
|
match self.value:
|
|
43
52
|
case 'symmetric':
|
|
@@ -52,16 +61,23 @@ class Boundary:
|
|
|
52
61
|
raise ValueError(f"Unexpected boundary value: {self.value}")
|
|
53
62
|
|
|
54
63
|
def get_shift_vector(self, offset: int) -> Optional[numpy.ndarray]:
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
"""
|
|
65
|
+
Calculate the shift vector based on the boundary name and offset.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
offset : int
|
|
70
|
+
The offset value to be used in the shift vector calculation.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
Optional[numpy.ndarray]
|
|
75
|
+
The shift vector as a numpy array, or None if the boundary name is 'center'.
|
|
76
|
+
|
|
77
|
+
Raises
|
|
78
|
+
------
|
|
79
|
+
ValueError
|
|
80
|
+
If the boundary name is unexpected.
|
|
65
81
|
"""
|
|
66
82
|
offset = abs(offset)
|
|
67
83
|
|
|
@@ -79,16 +95,21 @@ class Boundary:
|
|
|
79
95
|
case _:
|
|
80
96
|
raise ValueError(f"Unexpected boundary name: {self.name}")
|
|
81
97
|
|
|
82
|
-
|
|
83
98
|
@dataclass(config=config_dict)
|
|
84
99
|
class Boundaries:
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
"""
|
|
101
|
+
Class representing the boundaries with left and right values.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
left : Optional[str]
|
|
106
|
+
Value of the left boundary. Defaults to 'zero'. Must be either 'zero', 'symmetric', or 'anti-symmetric'.
|
|
107
|
+
right : Optional[str]
|
|
108
|
+
Value of the right boundary. Defaults to 'zero'. Must be either 'zero', 'symmetric', or 'anti-symmetric'.
|
|
109
|
+
acceptable_boundary : List[str]
|
|
110
|
+
List of acceptable boundary values.
|
|
111
|
+
all_boundaries : List[str]
|
|
112
|
+
List of all boundary names.
|
|
92
113
|
"""
|
|
93
114
|
left: Optional[str] = 'zero'
|
|
94
115
|
right: Optional[str] = 'zero'
|
|
@@ -97,31 +118,44 @@ class Boundaries:
|
|
|
97
118
|
all_boundaries = ['left', 'right']
|
|
98
119
|
|
|
99
120
|
def __post_init__(self) -> None:
|
|
100
|
-
"""
|
|
121
|
+
"""
|
|
122
|
+
Post-initialization method to assert acceptable boundary values.
|
|
123
|
+
"""
|
|
101
124
|
for boundary in self.all_boundaries:
|
|
102
125
|
self.assert_boundary_acceptable(boundary_string=boundary)
|
|
103
126
|
|
|
104
127
|
def assert_both_boundaries_not_same(self, boundary_0: str, boundary_1: str) -> None:
|
|
105
|
-
"""
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
"""
|
|
129
|
+
Assert that both boundaries are not the same axis symmetries if they are not 'zero'.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
boundary_0 : str
|
|
134
|
+
The first boundary value.
|
|
135
|
+
boundary_1 : str
|
|
136
|
+
The second boundary value.
|
|
137
|
+
|
|
138
|
+
Raises
|
|
139
|
+
------
|
|
140
|
+
ValueError
|
|
141
|
+
If both boundaries are set to the same axis symmetries.
|
|
113
142
|
"""
|
|
114
143
|
if boundary_0 != 'zero' and boundary_1 != 'zero':
|
|
115
144
|
raise ValueError("Same-axis symmetries shouldn't be set on both ends")
|
|
116
145
|
|
|
117
146
|
def assert_boundary_acceptable(self, boundary_string: str) -> None:
|
|
118
|
-
"""
|
|
147
|
+
"""
|
|
148
|
+
Assert that a given boundary value is acceptable.
|
|
119
149
|
|
|
120
|
-
|
|
121
|
-
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
boundary_string : str
|
|
153
|
+
The name of the boundary to check.
|
|
122
154
|
|
|
123
|
-
Raises
|
|
124
|
-
|
|
155
|
+
Raises
|
|
156
|
+
------
|
|
157
|
+
AssertionError
|
|
158
|
+
If the boundary value is not acceptable.
|
|
125
159
|
"""
|
|
126
160
|
boundary_value = getattr(self, boundary_string)
|
|
127
161
|
assert boundary_value in self.acceptable_boundary, (
|
|
@@ -130,24 +164,34 @@ class Boundaries:
|
|
|
130
164
|
)
|
|
131
165
|
|
|
132
166
|
def get_boundary_pairs(self) -> List[Tuple[str, str]]:
|
|
133
|
-
"""
|
|
167
|
+
"""
|
|
168
|
+
Get the pairs of boundaries.
|
|
134
169
|
|
|
135
|
-
Returns
|
|
136
|
-
|
|
170
|
+
Returns
|
|
171
|
+
-------
|
|
172
|
+
List[Tuple[str, str]]
|
|
173
|
+
A list of tuples containing boundary pairs.
|
|
137
174
|
"""
|
|
138
175
|
return [(self.left, self.right)]
|
|
139
176
|
|
|
140
177
|
def get_boundary(self, name: str) -> Boundary:
|
|
141
|
-
"""
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
178
|
+
"""
|
|
179
|
+
Return a specific instance of the boundary.
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
name : str
|
|
184
|
+
The name of the boundary.
|
|
185
|
+
|
|
186
|
+
Returns
|
|
187
|
+
-------
|
|
188
|
+
Boundary
|
|
189
|
+
The boundary instance.
|
|
190
|
+
|
|
191
|
+
Raises
|
|
192
|
+
------
|
|
193
|
+
AttributeError
|
|
194
|
+
If the boundary name is not an attribute of the instance.
|
|
151
195
|
"""
|
|
152
196
|
if not hasattr(self, name):
|
|
153
197
|
value = None
|
|
@@ -163,16 +207,23 @@ class Boundaries:
|
|
|
163
207
|
return boundary
|
|
164
208
|
|
|
165
209
|
def offset_to_boundary(self, offset: int) -> str:
|
|
166
|
-
"""
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
210
|
+
"""
|
|
211
|
+
Determine the boundary based on the offset.
|
|
212
|
+
|
|
213
|
+
Parameters
|
|
214
|
+
----------
|
|
215
|
+
offset : int
|
|
216
|
+
The offset value.
|
|
217
|
+
|
|
218
|
+
Returns
|
|
219
|
+
-------
|
|
220
|
+
str
|
|
221
|
+
The name of the boundary corresponding to the offset.
|
|
222
|
+
|
|
223
|
+
Raises
|
|
224
|
+
------
|
|
225
|
+
ValueError
|
|
226
|
+
If the offset does not correspond to a valid boundary.
|
|
176
227
|
"""
|
|
177
228
|
if offset == 0:
|
|
178
229
|
return self.get_boundary('center')
|
|
@@ -186,5 +237,3 @@ class Boundaries:
|
|
|
186
237
|
return self.get_boundary('left')
|
|
187
238
|
|
|
188
239
|
raise ValueError("Offset does not correspond to a valid boundary.")
|
|
189
|
-
|
|
190
|
-
# -
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
from PyFinitDiff.coefficients import FiniteCoefficients
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
def get_function_derivative(
|
|
8
7
|
function: callable,
|
|
9
8
|
x_eval: float,
|
|
@@ -13,19 +12,36 @@ def get_function_derivative(
|
|
|
13
12
|
accuracy: int = 4,
|
|
14
13
|
coefficient_type: str = 'central') -> float:
|
|
15
14
|
"""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
Compute the derivative of a given function at a specified point using finite differences.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
function : callable
|
|
20
|
+
The function to differentiate.
|
|
21
|
+
x_eval : float
|
|
22
|
+
The point at which to evaluate the derivative.
|
|
23
|
+
derivative : int
|
|
24
|
+
The order of the derivative.
|
|
25
|
+
delta : float
|
|
26
|
+
The distance between points used in the finite difference.
|
|
27
|
+
function_kwargs : dict
|
|
28
|
+
Additional keyword arguments to pass to the function.
|
|
29
|
+
accuracy : int, optional
|
|
30
|
+
The accuracy of the finite difference approximation (default is 4).
|
|
31
|
+
coefficient_type : str, optional
|
|
32
|
+
The type of finite difference coefficients to use ('central', 'forward', 'backward'). Defaults to 'central'.
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
float
|
|
37
|
+
The value of the derivative at the specified point.
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------
|
|
41
|
+
>>> def func(x):
|
|
42
|
+
>>> return x**2
|
|
43
|
+
>>> get_function_derivative(func, 1.0, 1, 0.01, {})
|
|
44
|
+
2.0
|
|
29
45
|
"""
|
|
30
46
|
coefficients = FiniteCoefficients(
|
|
31
47
|
derivative=derivative,
|
|
@@ -40,5 +56,3 @@ def get_function_derivative(
|
|
|
40
56
|
summation += value * y
|
|
41
57
|
|
|
42
58
|
return summation / delta ** derivative
|
|
43
|
-
|
|
44
|
-
# -
|