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