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 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.0.4.post0'
16
- __version_tuple__ = version_tuple = (2, 0, 4)
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
- """Class representing a boundary with a specific name, value, and mesh information.
22
-
23
- Attributes:
24
- name (str): The name of the boundary.
25
- value (Optional[str]): The value associated with the boundary.
26
- mesh_info (object): The mesh information object.
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
- """Gets the factor associated with the boundary value.
39
+ """
40
+ Get the factor associated with the boundary value.
35
41
 
36
- Returns:
37
- float: The factor corresponding to the boundary value.
42
+ Returns
43
+ -------
44
+ float
45
+ The factor corresponding to the boundary value.
38
46
 
39
- Raises:
40
- ValueError: If the boundary value is unexpected.
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
- """Calculates the shift vector based on the boundary name and offset.
56
-
57
- Args:
58
- offset (int): The offset value to be used in the shift vector calculation.
59
-
60
- Returns:
61
- Optional[numpy.ndarray]: The shift vector as a numpy array, or None if the boundary name is 'center'.
62
-
63
- Raises:
64
- ValueError: If the boundary name is unexpected.
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
- """Class representing the boundaries with left and right values.
86
-
87
- Attributes:
88
- left (Optional[str]): Value of the left boundary. Defaults to 'zero' must be either ['zero', 'symmetric', 'anti-symmetric'].
89
- right (Optional[str]): Value of the right boundary. Defaults to 'zero' either ['zero', 'symmetric', 'anti-symmetric'].
90
- acceptable_boundary (List[str]): List of acceptable boundary values.
91
- all_boundaries (List[str]): List of all boundary names.
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
- """Post-initialization method to assert acceptable boundary values."""
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
- """Asserts that both boundaries are not the same axis symmetries if they are not 'zero'.
106
-
107
- Args:
108
- boundary_0 (str): The first boundary value.
109
- boundary_1 (str): The second boundary value.
110
-
111
- Raises:
112
- ValueError: If both boundaries are set to the same axis symmetries.
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
- """Asserts that a given boundary value is acceptable.
149
+ """
150
+ Assert that a given boundary value is acceptable.
119
151
 
120
- Args:
121
- boundary_string (str): The name of the boundary to check.
152
+ Parameters
153
+ ----------
154
+ boundary_string : str
155
+ The name of the boundary to check.
122
156
 
123
- Raises:
124
- AssertionError: If the boundary value is not acceptable.
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
- """Gets the pairs of boundaries.
169
+ """
170
+ Get the pairs of boundaries.
134
171
 
135
- Returns:
136
- List[Tuple[str, str]]: A list of tuples containing boundary pairs.
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
- """Returns a specific instance of the boundary.
142
-
143
- Args:
144
- name (str): The name of the boundary.
145
-
146
- Returns:
147
- Boundary: The boundary instance.
148
-
149
- Raises:
150
- AttributeError: If the boundary name is not an attribute of the instance.
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
- """Determines the boundary based on the offset.
167
-
168
- Args:
169
- offset (int): The offset value.
170
-
171
- Returns:
172
- str: The name of the boundary corresponding to the offset.
173
-
174
- Raises:
175
- ValueError: If the offset does not correspond to a valid boundary.
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
- Computes the derivative of a given function at a specified point using finite differences.
17
-
18
- Args:
19
- function (callable): The function to differentiate.
20
- x_eval (float): The point at which to evaluate the derivative.
21
- derivative (int): The order of the derivative.
22
- delta (float): The distance between points.
23
- function_kwargs (dict): Additional keyword arguments to pass to the function.
24
- accuracy (int, optional): The accuracy of the finite difference approximation. Defaults to 4.
25
- coefficient_type (str, optional): The type of finite difference coefficients ('central', 'forward', 'backward'). Defaults to 'central'.
26
-
27
- Returns:
28
- float: The value of the derivative at the specified point.
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
- # -