PyFinitDiff 2.2.0__tar.gz → 2.3.0__tar.gz

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.
Files changed (83) hide show
  1. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PKG-INFO +1 -1
  2. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/__init__.py +1 -0
  3. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/_version.py +16 -3
  4. pyfinitdiff-2.3.0/PyFinitDiff/boundary_values.py +43 -0
  5. pyfinitdiff-2.2.0/PyFinitDiff/finite_difference_2D/diagonals.py → pyfinitdiff-2.3.0/PyFinitDiff/diagonal.py +48 -52
  6. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_1D/boundaries.py +25 -53
  7. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_1D/finite_difference.py +1 -1
  8. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_2D/boundaries.py +42 -68
  9. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_2D/finite_difference.py +1 -1
  10. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff.egg-info/PKG-INFO +1 -1
  11. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff.egg-info/SOURCES.txt +4 -4
  12. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_1d/example_0.py +2 -1
  13. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_1d/example_1.py +2 -1
  14. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_1d/example_2.py +2 -1
  15. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_1d/example_3.py +2 -1
  16. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_0.py +2 -1
  17. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_1.py +2 -1
  18. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_2.py +2 -1
  19. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_3.py +2 -1
  20. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_5.py +2 -1
  21. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_6.py +2 -1
  22. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_8.py +2 -1
  23. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/examples_7.py +2 -1
  24. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/extras/gradient.py +2 -1
  25. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/extras/plot_WM_field.py +2 -1
  26. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/triplets/plot_triplets_2.py +2 -1
  27. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/triplets/plot_triplets_3.py +2 -1
  28. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/code.rst +13 -10
  29. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/conf.py +1 -1
  30. pyfinitdiff-2.3.0/docs/source/sg_execution_times.rst +91 -0
  31. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_1D_api.py +5 -4
  32. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_1D_derivative.py +0 -1
  33. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_2D_api.py +9 -8
  34. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_2D_derivative.py +5 -5
  35. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_2D_eigen.py +7 -6
  36. pyfinitdiff-2.2.0/PyFinitDiff/finite_difference_1D/diagonals.py +0 -324
  37. pyfinitdiff-2.2.0/PyFinitDiff/utils.py +0 -106
  38. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.flake8 +0 -0
  39. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.github/dependabot.yml +0 -0
  40. /pyfinitdiff-2.2.0/.github/workflows/deploy_pypi.yml → /pyfinitdiff-2.3.0/.github/workflows/deploy_PyPi.yml +0 -0
  41. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.github/workflows/deploy_anaconda.yml +0 -0
  42. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.github/workflows/deploy_coverage.yml +0 -0
  43. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.github/workflows/deploy_documentation.yml +0 -0
  44. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/.gitignore +0 -0
  45. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/LICENSE +0 -0
  46. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/coefficients/__init__.py +0 -0
  47. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/coefficients/backward.py +0 -0
  48. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/coefficients/central.py +0 -0
  49. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/coefficients/forward.py +0 -0
  50. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/directories.py +0 -0
  51. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_1D/__init__.py +0 -0
  52. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_1D/derivative.py +0 -0
  53. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_1D/utils.py +0 -0
  54. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_2D/__init__.py +0 -0
  55. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_2D/derivative.py +0 -0
  56. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/finite_difference_2D/utils.py +0 -0
  57. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff/triplet.py +0 -0
  58. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff.egg-info/dependency_links.txt +0 -0
  59. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff.egg-info/requires.txt +0 -0
  60. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/PyFinitDiff.egg-info/top_level.txt +0 -0
  61. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/README.rst +0 -0
  62. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/Makefile +0 -0
  63. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/README.rst +0 -0
  64. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_1d/README.rst +0 -0
  65. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/README.rst +0 -0
  66. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/eigenmodes_2d/example_4.py +0 -0
  67. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/extras/README.rst +0 -0
  68. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/triplets/README.rst +0 -0
  69. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/triplets/plot_triplets_0.py +0 -0
  70. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/examples/triplets/plot_triplets_1.py +0 -0
  71. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/images/logo.png +0 -0
  72. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/images/triplet_example_0.png +0 -0
  73. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/make.bat +0 -0
  74. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/_static/default.css +0 -0
  75. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/gallery/index.rst +0 -0
  76. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/index.rst +0 -0
  77. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/references.rst +0 -0
  78. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/docs/source/theory.rst +0 -0
  79. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/meta.yaml +0 -0
  80. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/pyproject.toml +0 -0
  81. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/setup.cfg +0 -0
  82. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/__init__.py +0 -0
  83. {pyfinitdiff-2.2.0 → pyfinitdiff-2.3.0}/tests/test_triplet.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyFinitDiff
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A package for generating finite-difference matrices, particularly suited for physics and engineering applications.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -1,3 +1,4 @@
1
+ from PyFinitDiff.boundary_values import BoundaryValue
1
2
 
2
3
  try:
3
4
  from ._version import version as __version__ # noqa: F401
@@ -1,7 +1,14 @@
1
1
  # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
3
 
4
- __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
5
12
 
6
13
  TYPE_CHECKING = False
7
14
  if TYPE_CHECKING:
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
9
16
  from typing import Union
10
17
 
11
18
  VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
12
20
  else:
13
21
  VERSION_TUPLE = object
22
+ COMMIT_ID = object
14
23
 
15
24
  version: str
16
25
  __version__: str
17
26
  __version_tuple__: VERSION_TUPLE
18
27
  version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
19
30
 
20
- __version__ = version = '2.2.0'
21
- __version_tuple__ = version_tuple = (2, 2, 0)
31
+ __version__ = version = '2.3.0'
32
+ __version_tuple__ = version_tuple = (2, 3, 0)
33
+
34
+ __commit_id__ = commit_id = 'g3188478fd'
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from enum import Enum
5
+
6
+
7
+ class BoundaryValue(Enum):
8
+ """
9
+ Enumeration for boundary values.
10
+ """
11
+ SYMMETRIC = 'symmetric'
12
+ ANTI_SYMMETRIC = 'anti-symmetric'
13
+ ZERO = 'zero'
14
+ NONE = 'none'
15
+
16
+ @classmethod
17
+ def from_string(cls, value: str) -> 'BoundaryValue':
18
+ """
19
+ Convert a string to a BoundaryValue enum.
20
+
21
+ Parameters
22
+ ----------
23
+ value : str
24
+ String value to convert.
25
+
26
+ Returns
27
+ -------
28
+ BoundaryValue
29
+ The corresponding enum value.
30
+
31
+ Raises
32
+ ------
33
+ ValueError
34
+ If the string doesn't correspond to a valid BoundaryValue.
35
+ """
36
+ for boundary_val in cls:
37
+ if boundary_val.value == value:
38
+ return boundary_val
39
+ raise ValueError(f"No BoundaryValue found for string: '{value}'")
40
+
41
+
42
+
43
+
@@ -1,59 +1,45 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- from __future__ import annotations
5
-
6
- from dataclasses import field
7
- from typing import Optional, List
8
- from pydantic.dataclasses import dataclass
9
- from pydantic import ConfigDict
4
+ from dataclasses import dataclass
10
5
 
6
+ # Local imports
11
7
  import numpy
12
8
  from PyFinitDiff.triplet import Triplet
13
- from PyFinitDiff.finite_difference_2D.utils import MeshInfo
14
- from PyFinitDiff.finite_difference_2D.boundaries import Boundary
15
-
16
- config_dict = ConfigDict(
17
- extra='forbid',
18
- strict=True,
19
- kw_only=True,
20
- frozen=False,
21
- arbitrary_types_allowed=True
22
- )
23
9
 
24
10
 
25
- @dataclass(config=config_dict)
11
+ @dataclass
26
12
  class Diagonal:
27
13
  """
28
- Represents the diagonal elements of the finite-difference method.
14
+ Represents a diagonal element of the finite-difference method.
29
15
 
30
- This class can be initialized with parameters such as its offset or boundary condition.
16
+ This class constructs a diagonal with parameters such as its offset and boundary condition.
31
17
 
32
18
  Parameters
33
19
  ----------
34
- mesh_info : MeshInfo
20
+ mesh_info : object
35
21
  Instance describing the meta information on the mesh to be considered.
36
22
  offset : int
37
23
  Offset of the column index for the diagonal.
38
- values : numpy.ndarray
39
- Values associated with the diagonal.
40
- boundary : Optional[PyFinitDiff.finite_difference_2D.boundaries.Boundary]
41
- Instance of the boundary used for that diagonal.
24
+ values : float
25
+ Value associated with the diagonal.
26
+ boundary : object
27
+ Instance of the boundary used for the diagonal.
42
28
  """
43
- mesh_info: MeshInfo
29
+ mesh_info: object
44
30
  offset: int
45
- values: numpy.ndarray
46
- boundary: Optional[Boundary] = None
31
+ values: float
32
+ boundary: object
47
33
 
48
34
  @property
49
35
  def triplet(self) -> Triplet:
50
36
  """
51
- Returns the Triplet instance of the diagonal.
37
+ Return the Triplet instance of the diagonal.
52
38
 
53
39
  Returns
54
40
  -------
55
41
  Triplet
56
- The Triplet instance containing the array and shape.
42
+ A Triplet instance representing the non-zero values in the diagonal.
57
43
  """
58
44
  self.array: numpy.ndarray = numpy.c_[self.rows, self.columns, self.values]
59
45
 
@@ -66,9 +52,9 @@ class Diagonal:
66
52
 
67
53
  def compute_triplet(self) -> None:
68
54
  """
69
- Computes the diagonal indices and generates a Triplet instance out of it.
55
+ Compute the diagonal indices and generate a Triplet instance out of it.
70
56
 
71
- The value of the third triplet column depends on the boundary condition.
57
+ The value of the third column in the triplet depends on the boundary condition.
72
58
  """
73
59
  self.rows: numpy.ndarray = numpy.arange(0, self.mesh_info.size)
74
60
  self.columns: numpy.ndarray = self.rows + self.offset
@@ -77,10 +63,10 @@ class Diagonal:
77
63
 
78
64
  def apply_symmetry(self) -> None:
79
65
  """
80
- Adjusts the values of the diagonal indices as defined by the boundary condition.
66
+ Apply boundary symmetry conditions to the diagonal.
81
67
 
82
- If the boundary is symmetric, the value stays the same. If anti-symmetric, a minus sign is added.
83
- If zero, it returns zero.
68
+ If the boundary is symmetric, the value stays the same. If it is anti-symmetric,
69
+ a negative sign is added. If it is zero, the value becomes zero.
84
70
  """
85
71
  shift_array = self.boundary.get_shift_vector(self.offset)
86
72
 
@@ -92,7 +78,7 @@ class Diagonal:
92
78
 
93
79
  def validate_index(self) -> None:
94
80
  """
95
- Removes all negative indices from the diagonal.
81
+ Remove all negative indices from the diagonal.
96
82
  """
97
83
  valid_index = self.columns >= 0
98
84
  self.columns = self.columns[valid_index]
@@ -101,18 +87,17 @@ class Diagonal:
101
87
 
102
88
  def plot(self) -> None:
103
89
  """
104
- Plots the Triplet instance representing the diagonal.
90
+ Plot the Triplet instance representing the diagonal.
105
91
  """
106
92
  return self.triplet.plot()
107
93
 
108
-
109
94
  class ConstantDiagonal(Diagonal):
110
95
  """
111
- Represents a diagonal with constant values for the finite-difference method.
96
+ Represents a diagonal with constant values.
112
97
 
113
98
  This subclass of Diagonal is initialized with constant values for the entire diagonal.
114
99
  """
115
- def __init__(self, offset: int, value: float, mesh_info: list, boundary: Boundary):
100
+ def __init__(self, offset: int, value: float, mesh_info: list, boundary: object):
116
101
  super().__init__(
117
102
  offset=offset,
118
103
  mesh_info=mesh_info,
@@ -121,7 +106,6 @@ class ConstantDiagonal(Diagonal):
121
106
  )
122
107
 
123
108
 
124
- @dataclass(config=config_dict)
125
109
  class DiagonalSet:
126
110
  """
127
111
  Represents a set of diagonals for the finite-difference method.
@@ -135,10 +119,22 @@ class DiagonalSet:
135
119
  diagonals : List[Diagonal]
136
120
  List of Diagonal objects.
137
121
  """
138
- mesh_info: MeshInfo
139
- diagonals: List[Diagonal] = field(default_factory=list)
140
122
 
141
- def append(self, diagonal: Diagonal) -> DiagonalSet:
123
+ def __init__(self, mesh_info: object, diagonals: list = None) -> None:
124
+ """
125
+ Initializes the DiagonalSet with mesh information and an optional list of diagonals.
126
+
127
+ Parameters
128
+ ----------
129
+ mesh_info : object
130
+ Meta information about the mesh.
131
+ diagonals : list, optional
132
+ List of Diagonal objects, defaults to an empty list.
133
+ """
134
+ self.mesh_info = mesh_info
135
+ self.diagonals = diagonals if diagonals is not None else []
136
+
137
+ def append(self, diagonal: Diagonal) -> 'DiagonalSet':
142
138
  """
143
139
  Appends a Diagonal to the set.
144
140
 
@@ -155,13 +151,13 @@ class DiagonalSet:
155
151
  self.diagonals.append(diagonal)
156
152
  return self
157
153
 
158
- def concatenate(self, other_diagonal_set: DiagonalSet) -> DiagonalSet:
154
+ def concatenate(self, other_diagonal_set: 'DiagonalSet') -> 'DiagonalSet':
159
155
  """
160
156
  Concatenates another DiagonalSet to this one.
161
157
 
162
158
  Parameters
163
159
  ----------
164
- other_diagonal_set : DiagonalSet
160
+ other_diagonal_set : 'DiagonalSet'
165
161
  The other DiagonalSet to concatenate.
166
162
 
167
163
  Returns
@@ -241,7 +237,7 @@ class DiagonalSet:
241
237
  rows_index = numpy.isin(self.triplet.rows, rows)
242
238
  return self.triplet.array[rows_index]
243
239
 
244
- def remove_nan_rows(self) -> DiagonalSet:
240
+ def remove_nan_rows(self) -> 'DiagonalSet':
245
241
  """
246
242
  Removes rows containing NaN values from the triplet.
247
243
 
@@ -253,7 +249,7 @@ class DiagonalSet:
253
249
  nan_rows = self.get_row_nan_bool()
254
250
  return self.remove_rows(rows=nan_rows)
255
251
 
256
- def remove_rows(self, rows: numpy.ndarray) -> DiagonalSet:
252
+ def remove_rows(self, rows: numpy.ndarray) -> 'DiagonalSet':
257
253
  """
258
254
  Removes the specified rows from the triplet.
259
255
 
@@ -271,13 +267,13 @@ class DiagonalSet:
271
267
  self.triplet.array = numpy.delete(self.triplet.array, index_to_remove, axis=0)
272
268
  return self
273
269
 
274
- def replace_nan_rows_with(self, other: DiagonalSet) -> DiagonalSet:
270
+ def replace_nan_rows_with(self, other: 'DiagonalSet') -> 'DiagonalSet':
275
271
  """
276
272
  Replaces NaN rows in this DiagonalSet with the equivalent rows from another DiagonalSet.
277
273
 
278
274
  Parameters
279
275
  ----------
280
- other : DiagonalSet
276
+ other : 'DiagonalSet'
281
277
  The other DiagonalSet to source non-NaN rows from.
282
278
 
283
279
  Returns
@@ -293,7 +289,7 @@ class DiagonalSet:
293
289
  self.triplet.append_array(add_array)
294
290
  return self
295
291
 
296
- def initialize_triplet(self) -> DiagonalSet:
292
+ def initialize_triplet(self) -> 'DiagonalSet':
297
293
  """
298
294
  Initializes the triplet by combining all diagonals in the set.
299
295
 
@@ -338,13 +334,13 @@ class DiagonalSet:
338
334
  rows = self.triplet.rows[nan_index]
339
335
  return rows.max()
340
336
 
341
- def __add__(self, other: DiagonalSet) -> DiagonalSet:
337
+ def __add__(self, other: 'DiagonalSet') -> 'DiagonalSet':
342
338
  """
343
339
  Adds another DiagonalSet to this one.
344
340
 
345
341
  Parameters
346
342
  ----------
347
- other : DiagonalSet
343
+ other : 'DiagonalSet'
348
344
  The other DiagonalSet to add.
349
345
 
350
346
  Returns
@@ -6,6 +6,7 @@ import numpy
6
6
  from typing import Optional, List, Tuple
7
7
  from pydantic.dataclasses import dataclass
8
8
  from pydantic import ConfigDict
9
+ from PyFinitDiff.boundary_values import BoundaryValue
9
10
 
10
11
  config_dict = ConfigDict(
11
12
  extra='forbid',
@@ -16,7 +17,6 @@ config_dict = ConfigDict(
16
17
  )
17
18
 
18
19
 
19
- @dataclass(config=config_dict)
20
20
  class Boundary:
21
21
  """
22
22
  Class representing a boundary with a specific name, value, and mesh information.
@@ -25,15 +25,16 @@ class Boundary:
25
25
  ----------
26
26
  name : str
27
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'.
28
+ value : Optional[BoundaryValue]
29
+ The value associated with the boundary, such as BoundaryValue.SYMMETRIC, BoundaryValue.ANTI_SYMMETRIC, BoundaryValue.ZERO, or BoundaryValue.NONE.
30
30
  mesh_info : object
31
31
  The mesh information object containing information about the mesh size and structure.
32
32
  """
33
33
 
34
- name: str
35
- value: Optional[str]
36
- mesh_info: object
34
+ def __init__(self, name: str, value: Optional[BoundaryValue], mesh_info: object) -> None:
35
+ self.name = name
36
+ self.value = value
37
+ self.mesh_info = mesh_info
37
38
 
38
39
  def get_factor(self) -> float:
39
40
  """
@@ -50,13 +51,13 @@ class Boundary:
50
51
  If the boundary value is unexpected.
51
52
  """
52
53
  match self.value:
53
- case 'symmetric':
54
+ case BoundaryValue.SYMMETRIC:
54
55
  return 1.0
55
- case 'anti-symmetric':
56
+ case BoundaryValue.ANTI_SYMMETRIC:
56
57
  return -1.0
57
- case 'zero':
58
+ case BoundaryValue.ZERO:
58
59
  return 0.0
59
- case 'none':
60
+ case BoundaryValue.NONE:
60
61
  return numpy.nan
61
62
  case _:
62
63
  raise ValueError(f"Unexpected boundary value: {self.value}")
@@ -104,37 +105,28 @@ class Boundaries:
104
105
 
105
106
  Parameters
106
107
  ----------
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.
108
+ left : Optional[BoundaryValue]
109
+ Value of the left boundary. Defaults to BoundaryValue.ZERO.
110
+ right : Optional[BoundaryValue]
111
+ Value of the right boundary. Defaults to BoundaryValue.ZERO.
112
+
113
113
  all_boundaries : List[str]
114
114
  List of all boundary names.
115
115
  """
116
- left: Optional[str] = 'zero'
117
- right: Optional[str] = 'zero'
116
+ left: Optional[BoundaryValue] = BoundaryValue.ZERO
117
+ right: Optional[BoundaryValue] = BoundaryValue.ZERO
118
118
 
119
- acceptable_boundary = ['zero', 'symmetric', 'anti-symmetric', 'none']
120
119
  all_boundaries = ['left', 'right']
121
120
 
122
- def __post_init__(self) -> None:
123
- """
124
- Post-initialization method to assert acceptable boundary values.
125
- """
126
- for boundary in self.all_boundaries:
127
- self.assert_boundary_acceptable(boundary_string=boundary)
128
-
129
- def assert_both_boundaries_not_same(self, boundary_0: str, boundary_1: str) -> None:
121
+ def assert_both_boundaries_not_same(self, boundary_0: BoundaryValue, boundary_1: BoundaryValue) -> None:
130
122
  """
131
- Assert that both boundaries are not the same axis symmetries if they are not 'zero'.
123
+ Assert that both boundaries are not the same axis symmetries if they are not BoundaryValue.ZERO.
132
124
 
133
125
  Parameters
134
126
  ----------
135
- boundary_0 : str
127
+ boundary_0 : BoundaryValue
136
128
  The first boundary value.
137
- boundary_1 : str
129
+ boundary_1 : BoundaryValue
138
130
  The second boundary value.
139
131
 
140
132
  Raises
@@ -142,36 +134,16 @@ class Boundaries:
142
134
  ValueError
143
135
  If both boundaries are set to the same axis symmetries.
144
136
  """
145
- if boundary_0 != 'zero' and boundary_1 != 'zero':
137
+ if boundary_0 != BoundaryValue.ZERO and boundary_1 != BoundaryValue.ZERO:
146
138
  raise ValueError("Same-axis symmetries shouldn't be set on both ends")
147
139
 
148
- def assert_boundary_acceptable(self, boundary_string: str) -> None:
149
- """
150
- Assert that a given boundary value is acceptable.
151
-
152
- Parameters
153
- ----------
154
- boundary_string : str
155
- The name of the boundary to check.
156
-
157
- Raises
158
- ------
159
- AssertionError
160
- If the boundary value is not acceptable.
161
- """
162
- boundary_value = getattr(self, boundary_string)
163
- assert boundary_value in self.acceptable_boundary, (
164
- f"Error: {boundary_string} boundary: {boundary_value} argument not accepted. "
165
- f"Input must be in: {self.acceptable_boundary}"
166
- )
167
-
168
- def get_boundary_pairs(self) -> List[Tuple[str, str]]:
140
+ def get_boundary_pairs(self) -> List[Tuple[BoundaryValue, BoundaryValue]]:
169
141
  """
170
142
  Get the pairs of boundaries.
171
143
 
172
144
  Returns
173
145
  -------
174
- List[Tuple[str, str]]
146
+ List[Tuple[BoundaryValue, BoundaryValue]]
175
147
  A list of tuples containing boundary pairs.
176
148
  """
177
149
  return [(self.left, self.right)]
@@ -7,7 +7,7 @@ from dataclasses import field
7
7
  from PyFinitDiff.coefficients import FiniteCoefficients
8
8
  from PyFinitDiff.finite_difference_1D.boundaries import Boundaries
9
9
  from PyFinitDiff.finite_difference_1D.utils import MeshInfo
10
- from PyFinitDiff.finite_difference_1D.diagonals import DiagonalSet, ConstantDiagonal
10
+ from PyFinitDiff.diagonal import ConstantDiagonal, DiagonalSet
11
11
 
12
12
  config_dict = ConfigDict(
13
13
  extra='forbid',