executable-engineering 0.1.36__tar.gz → 0.1.39__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 (20) hide show
  1. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/PKG-INFO +1 -1
  2. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/__init__.py +3 -1
  3. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/linearsystems_module.py +61 -0
  4. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/openrootfinder_module.py +18 -12
  5. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering.egg-info/PKG-INFO +1 -1
  6. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/setup.py +1 -1
  7. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/LICENSE +0 -0
  8. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/README.md +0 -0
  9. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/closedoptimization_module.py +0 -0
  10. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/closedrootfinder_module.py +0 -0
  11. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/gradientoptimization_module.py +0 -0
  12. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/neuralnet_module.py +0 -0
  13. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/numerical_error_module.py +0 -0
  14. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering/openoptimization_module.py +0 -0
  15. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering.egg-info/SOURCES.txt +0 -0
  16. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering.egg-info/dependency_links.txt +0 -0
  17. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering.egg-info/requires.txt +0 -0
  18. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/executable_engineering.egg-info/top_level.txt +0 -0
  19. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/pyproject.toml +0 -0
  20. {executable_engineering-0.1.36 → executable_engineering-0.1.39}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: executable_engineering
3
- Version: 0.1.36
3
+ Version: 0.1.39
4
4
  Summary: Demonstrative tools for the Executable Engineering textbook
5
5
  Home-page: https://github.com/themintlab/ExecutableEngineering/tree/main/executable_engineering
6
6
  Author: Michael Welland
@@ -5,9 +5,11 @@ from .closedoptimization_module import OptimizerClosed
5
5
  from .openoptimization_module import OptimizerOpen
6
6
  from .gradientoptimization_module import OptimizerGrad
7
7
  from .numerical_error_module import python_internal_binary, decimal_to_binary
8
- from .linearsystems_module import visual_solve_2d, visualize_conditioning, visualize_matrix_norms, jacobi_step, gauss_seidel_step, sor_step, visualize_convergence_2d, create_diagonally_dominant_matrix, iter_solve, steepest_descent, conjugate_gradient, IterationTracker
8
+ from .linearsystems_module import visual_solve_2d, visualize_conditioning, visualize_matrix_norms, jacobi_step, gauss_seidel_step, sor_step, visualize_convergence_2d, create_diagonally_dominant_matrix, iter_solve, steepest_descent, conjugate_gradient, IterationTracker, discretise_poisson, spai
9
9
 
10
10
  __all__ = [
11
+ "discretise_poisson",
12
+ "spai",
11
13
  "visual_solve_2d",
12
14
  "visualize_conditioning",
13
15
  "visualize_matrix_norms",
@@ -471,3 +471,64 @@ class IterationTracker:
471
471
  if self.print_residual:
472
472
  guess_str = np.array2string(x, precision=4, separator=', ', suppress_small=True)
473
473
  print(f"Step {self.step}: Guess = {guess_str}, Residual = {res:.4e}")
474
+
475
+
476
+ def discretise_poisson(N, Q):
477
+ """Generate the matrix and rhs associated with the discrete Poisson operator."""
478
+ import numpy as np
479
+ from scipy.sparse import coo_matrix
480
+
481
+ nelements = 5 * N**2 - 16 * N + 16
482
+
483
+ row_ind = np.empty(nelements, dtype=np.float64)
484
+ col_ind = np.empty(nelements, dtype=np.float64)
485
+ data = np.empty(nelements, dtype=np.float64)
486
+
487
+ f = np.empty(N * N, dtype=np.float64)
488
+
489
+ count = 0
490
+ for j in range(N):
491
+ for i in range(N):
492
+ if i == 0 or i == N - 1 or j == 0 or j == N - 1:
493
+ row_ind[count] = col_ind[count] = j * N + i
494
+ data[count] = 1
495
+ f[j * N + i] = 0
496
+ count += 1
497
+
498
+ else:
499
+ row_ind[count : count + 5] = j * N + i
500
+ col_ind[count] = j * N + i
501
+ col_ind[count + 1] = j * N + i + 1
502
+ col_ind[count + 2] = j * N + i - 1
503
+ col_ind[count + 3] = (j + 1) * N + i
504
+ col_ind[count + 4] = (j - 1) * N + i
505
+
506
+ data[count] = 4 * (N - 1)**2
507
+ data[count + 1 : count + 5] = - (N - 1)**2
508
+ f[j * N + i] = Q
509
+
510
+ count += 5
511
+
512
+ return coo_matrix((data, (row_ind, col_ind)), shape=(N**2, N**2)).tocsr(), f
513
+
514
+ def spai(A, m):
515
+ """Perform m step of the SPAI iteration."""
516
+ import numpy as np
517
+ from scipy.sparse import identity
518
+ from scipy.sparse.linalg import onenormest
519
+
520
+ n = A.shape[0]
521
+
522
+ ident = identity(n, format='csr')
523
+ alpha = 2 / onenormest(A @ A.T)
524
+ M = alpha * A
525
+
526
+ for index in range(m):
527
+ C = A @ M
528
+ G = ident - C
529
+ AG = A @ G
530
+ trace = (G.T @ AG).diagonal().sum()
531
+ alpha = trace / np.linalg.norm(AG.data)**2
532
+ M = M + alpha * G
533
+
534
+ return M
@@ -138,20 +138,26 @@ class RootFinderOpen:
138
138
  return HTML(anim.to_jshtml())
139
139
 
140
140
  def show_toggle_open(self, interval_ms=750):
141
- newton_anim_html = self._make_animation_open('Newton', interval_ms)
142
- secant_anim_html = self._make_animation_open('Secant', interval_ms)
141
+ newton_anim_html = self._make_animation_open('Newton', interval_ms)
142
+ secant_anim_html = self._make_animation_open('Secant', interval_ms)
143
143
 
144
- if newton_anim_html is None or secant_anim_html is None:
145
- print("Cannot create animations. Check function definition or initial points (x0, x1).")
146
- return
144
+ if newton_anim_html is None or secant_anim_html is None:
145
+ print("Cannot create animations. Check function definition or initial points (x0, x1).")
146
+ return
147
147
 
148
- newton_content = widgets.HTML(value=newton_anim_html.data)
149
- secant_content = widgets.HTML(value=secant_anim_html.data)
148
+ newton_out = widgets.Output()
149
+ secant_out = widgets.Output()
150
150
 
151
- tab_container = widgets.Tab()
152
- tab_container.children = [newton_content, secant_content]
151
+ with newton_out:
152
+ display(newton_anim_html)
153
+
154
+ with secant_out:
155
+ display(secant_anim_html)
153
156
 
154
- tab_container.set_title(0, 'Newton')
155
- tab_container.set_title(1, 'Secant')
157
+ tab_container = widgets.Tab()
158
+ tab_container.children = [newton_out, secant_out]
156
159
 
157
- display(tab_container)
160
+ tab_container.set_title(0, 'Newton')
161
+ tab_container.set_title(1, 'Secant')
162
+
163
+ display(tab_container)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: executable_engineering
3
- Version: 0.1.36
3
+ Version: 0.1.39
4
4
  Summary: Demonstrative tools for the Executable Engineering textbook
5
5
  Home-page: https://github.com/themintlab/ExecutableEngineering/tree/main/executable_engineering
6
6
  Author: Michael Welland
@@ -6,7 +6,7 @@ long_description = (this_directory / "README.md").read_text(encoding="utf-8")
6
6
 
7
7
  setup(
8
8
  name="executable_engineering",
9
- version="0.1.36",
9
+ version="0.1.39",
10
10
  description="Demonstrative tools for the Executable Engineering textbook",
11
11
  long_description=long_description,
12
12
  long_description_content_type="text/markdown",