pyvale 2025.4.0__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.

Potentially problematic release.


This version of pyvale might be problematic. Click here for more details.

Files changed (157) hide show
  1. pyvale/__init__.py +75 -0
  2. pyvale/core/__init__.py +7 -0
  3. pyvale/core/analyticmeshgen.py +59 -0
  4. pyvale/core/analyticsimdatafactory.py +63 -0
  5. pyvale/core/analyticsimdatagenerator.py +160 -0
  6. pyvale/core/camera.py +146 -0
  7. pyvale/core/cameradata.py +64 -0
  8. pyvale/core/cameradata2d.py +82 -0
  9. pyvale/core/cameratools.py +328 -0
  10. pyvale/core/cython/rastercyth.c +32267 -0
  11. pyvale/core/cython/rastercyth.py +636 -0
  12. pyvale/core/dataset.py +250 -0
  13. pyvale/core/errorcalculator.py +112 -0
  14. pyvale/core/errordriftcalc.py +146 -0
  15. pyvale/core/errorintegrator.py +339 -0
  16. pyvale/core/errorrand.py +614 -0
  17. pyvale/core/errorsysdep.py +331 -0
  18. pyvale/core/errorsysfield.py +407 -0
  19. pyvale/core/errorsysindep.py +905 -0
  20. pyvale/core/experimentsimulator.py +99 -0
  21. pyvale/core/field.py +136 -0
  22. pyvale/core/fieldconverter.py +154 -0
  23. pyvale/core/fieldsampler.py +112 -0
  24. pyvale/core/fieldscalar.py +167 -0
  25. pyvale/core/fieldtensor.py +221 -0
  26. pyvale/core/fieldtransform.py +384 -0
  27. pyvale/core/fieldvector.py +215 -0
  28. pyvale/core/generatorsrandom.py +528 -0
  29. pyvale/core/imagedef2d.py +566 -0
  30. pyvale/core/integratorfactory.py +241 -0
  31. pyvale/core/integratorquadrature.py +192 -0
  32. pyvale/core/integratorrectangle.py +88 -0
  33. pyvale/core/integratorspatial.py +90 -0
  34. pyvale/core/integratortype.py +44 -0
  35. pyvale/core/optimcheckfuncs.py +153 -0
  36. pyvale/core/raster.py +31 -0
  37. pyvale/core/rastercy.py +76 -0
  38. pyvale/core/rasternp.py +604 -0
  39. pyvale/core/rendermesh.py +156 -0
  40. pyvale/core/sensorarray.py +179 -0
  41. pyvale/core/sensorarrayfactory.py +210 -0
  42. pyvale/core/sensorarraypoint.py +280 -0
  43. pyvale/core/sensordata.py +72 -0
  44. pyvale/core/sensordescriptor.py +101 -0
  45. pyvale/core/sensortools.py +143 -0
  46. pyvale/core/visualexpplotter.py +151 -0
  47. pyvale/core/visualimagedef.py +71 -0
  48. pyvale/core/visualimages.py +75 -0
  49. pyvale/core/visualopts.py +180 -0
  50. pyvale/core/visualsimanimator.py +83 -0
  51. pyvale/core/visualsimplotter.py +182 -0
  52. pyvale/core/visualtools.py +81 -0
  53. pyvale/core/visualtraceplotter.py +256 -0
  54. pyvale/data/__init__.py +7 -0
  55. pyvale/data/case13_out.e +0 -0
  56. pyvale/data/case16_out.e +0 -0
  57. pyvale/data/case17_out.e +0 -0
  58. pyvale/data/case18_1_out.e +0 -0
  59. pyvale/data/case18_2_out.e +0 -0
  60. pyvale/data/case18_3_out.e +0 -0
  61. pyvale/data/case25_out.e +0 -0
  62. pyvale/data/case26_out.e +0 -0
  63. pyvale/data/optspeckle_2464x2056px_spec5px_8bit_gblur1px.tiff +0 -0
  64. pyvale/examples/__init__.py +7 -0
  65. pyvale/examples/analyticdatagen/__init__.py +7 -0
  66. pyvale/examples/analyticdatagen/ex1_1_scalarvisualisation.py +38 -0
  67. pyvale/examples/analyticdatagen/ex1_2_scalarcasebuild.py +46 -0
  68. pyvale/examples/analyticdatagen/ex2_1_analyticsensors.py +83 -0
  69. pyvale/examples/ex1_1_thermal2d.py +89 -0
  70. pyvale/examples/ex1_2_thermal2d.py +111 -0
  71. pyvale/examples/ex1_3_thermal2d.py +113 -0
  72. pyvale/examples/ex1_4_thermal2d.py +89 -0
  73. pyvale/examples/ex1_5_thermal2d.py +105 -0
  74. pyvale/examples/ex2_1_thermal3d .py +87 -0
  75. pyvale/examples/ex2_2_thermal3d.py +51 -0
  76. pyvale/examples/ex2_3_thermal3d.py +109 -0
  77. pyvale/examples/ex3_1_displacement2d.py +47 -0
  78. pyvale/examples/ex3_2_displacement2d.py +79 -0
  79. pyvale/examples/ex3_3_displacement2d.py +104 -0
  80. pyvale/examples/ex3_4_displacement2d.py +105 -0
  81. pyvale/examples/ex4_1_strain2d.py +57 -0
  82. pyvale/examples/ex4_2_strain2d.py +79 -0
  83. pyvale/examples/ex4_3_strain2d.py +100 -0
  84. pyvale/examples/ex5_1_multiphysics2d.py +78 -0
  85. pyvale/examples/ex6_1_multiphysics2d_expsim.py +118 -0
  86. pyvale/examples/ex6_2_multiphysics3d_expsim.py +158 -0
  87. pyvale/examples/features/__init__.py +7 -0
  88. pyvale/examples/features/ex_animation_tools_3dmonoblock.py +83 -0
  89. pyvale/examples/features/ex_area_avg.py +89 -0
  90. pyvale/examples/features/ex_calibration_error.py +108 -0
  91. pyvale/examples/features/ex_chain_field_errs.py +141 -0
  92. pyvale/examples/features/ex_field_errs.py +78 -0
  93. pyvale/examples/features/ex_sensor_single_angle_batch.py +110 -0
  94. pyvale/examples/imagedef2d/ex_imagedef2d_todisk.py +86 -0
  95. pyvale/examples/rasterisation/ex_rastenp.py +154 -0
  96. pyvale/examples/rasterisation/ex_rastercyth_oneframe.py +220 -0
  97. pyvale/examples/rasterisation/ex_rastercyth_static_cypara.py +194 -0
  98. pyvale/examples/rasterisation/ex_rastercyth_static_pypara.py +193 -0
  99. pyvale/simcases/case00_HEX20.i +242 -0
  100. pyvale/simcases/case00_HEX27.i +242 -0
  101. pyvale/simcases/case00_TET10.i +242 -0
  102. pyvale/simcases/case00_TET14.i +242 -0
  103. pyvale/simcases/case01.i +101 -0
  104. pyvale/simcases/case02.i +156 -0
  105. pyvale/simcases/case03.i +136 -0
  106. pyvale/simcases/case04.i +181 -0
  107. pyvale/simcases/case05.i +234 -0
  108. pyvale/simcases/case06.i +305 -0
  109. pyvale/simcases/case07.geo +135 -0
  110. pyvale/simcases/case07.i +87 -0
  111. pyvale/simcases/case08.geo +144 -0
  112. pyvale/simcases/case08.i +153 -0
  113. pyvale/simcases/case09.geo +204 -0
  114. pyvale/simcases/case09.i +87 -0
  115. pyvale/simcases/case10.geo +204 -0
  116. pyvale/simcases/case10.i +257 -0
  117. pyvale/simcases/case11.geo +337 -0
  118. pyvale/simcases/case11.i +147 -0
  119. pyvale/simcases/case12.geo +388 -0
  120. pyvale/simcases/case12.i +329 -0
  121. pyvale/simcases/case13.i +140 -0
  122. pyvale/simcases/case14.i +159 -0
  123. pyvale/simcases/case15.geo +337 -0
  124. pyvale/simcases/case15.i +150 -0
  125. pyvale/simcases/case16.geo +391 -0
  126. pyvale/simcases/case16.i +357 -0
  127. pyvale/simcases/case17.geo +135 -0
  128. pyvale/simcases/case17.i +144 -0
  129. pyvale/simcases/case18.i +254 -0
  130. pyvale/simcases/case18_1.i +254 -0
  131. pyvale/simcases/case18_2.i +254 -0
  132. pyvale/simcases/case18_3.i +254 -0
  133. pyvale/simcases/case19.geo +252 -0
  134. pyvale/simcases/case19.i +99 -0
  135. pyvale/simcases/case20.geo +252 -0
  136. pyvale/simcases/case20.i +250 -0
  137. pyvale/simcases/case21.geo +74 -0
  138. pyvale/simcases/case21.i +155 -0
  139. pyvale/simcases/case22.geo +82 -0
  140. pyvale/simcases/case22.i +140 -0
  141. pyvale/simcases/case23.geo +164 -0
  142. pyvale/simcases/case23.i +140 -0
  143. pyvale/simcases/case24.geo +79 -0
  144. pyvale/simcases/case24.i +123 -0
  145. pyvale/simcases/case25.geo +82 -0
  146. pyvale/simcases/case25.i +140 -0
  147. pyvale/simcases/case26.geo +166 -0
  148. pyvale/simcases/case26.i +140 -0
  149. pyvale/simcases/run_1case.py +61 -0
  150. pyvale/simcases/run_all_cases.py +69 -0
  151. pyvale/simcases/run_build_case.py +64 -0
  152. pyvale/simcases/run_example_cases.py +69 -0
  153. pyvale-2025.4.0.dist-info/METADATA +140 -0
  154. pyvale-2025.4.0.dist-info/RECORD +157 -0
  155. pyvale-2025.4.0.dist-info/WHEEL +5 -0
  156. pyvale-2025.4.0.dist-info/licenses/LICENSE +21 -0
  157. pyvale-2025.4.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,153 @@
1
+ """
2
+ OPTIMISATION TEST FUNCTIONS - N DIMS
3
+ https://gist.github.com/denis-bz/da697d8bc74fae4598bf
4
+ https://www.sfu.ca/~ssurjano/optimization.html
5
+ https://en.wikipedia.org/wiki/Test_functions_for_optimization
6
+ """
7
+ from typing import Callable,Any
8
+ import numpy as np
9
+ import matplotlib.pyplot as plt
10
+ from pyvale.core.visualopts import PlotOptsGeneral
11
+
12
+
13
+ def ackley(x: np.ndarray,
14
+ a: float = 20.0,
15
+ b: float = 0.2,
16
+ c: float = 2*np.pi) -> np.ndarray:
17
+ """ACKLEY
18
+ Dimension: N
19
+ Local Minima: many
20
+ Global Minimum: f(x) = 0 @ (0,0,....,0)
21
+ Eval: [-32.768,32.768] or smaller
22
+ """
23
+ n = x.shape[1]
24
+ sum1 = np.sum(x**2,axis=1)
25
+ sum2 = np.sum(np.cos(c*x),axis=1)
26
+ f = -a*np.exp(-b*np.sqrt(sum1/n)) - np.exp(sum2/n) + a + np.exp(1)
27
+ return f
28
+
29
+
30
+ def dixonprice(x: np.ndarray) -> np.ndarray:
31
+ """DIXON-PRICE
32
+ Dimension: N
33
+ Local Minima: Large valley
34
+ Global Minimum: f(x) = 0 @ x_i = 2^-((2^i-2)/2^i) for i = 1,...,d
35
+ Eval: [-10.0,10.0] or smaller
36
+ """
37
+ n = x.shape[1]
38
+ j = np.arange( 2, n+1 )
39
+ x2 = 2 * x**2
40
+ f = np.sum( j * (x2[:,1:] - x[:,:-1]) **2, axis=1) + (x[:,0] - 1) **2
41
+ return f
42
+
43
+
44
+ def griewank(x: np.ndarray, div: float = 4000.0) -> np.ndarray:
45
+ """GRIEWANK
46
+ Dimension: N
47
+ Local Minima: many
48
+ Global Minimum: f(x) = 0 @ (0,0,....,0)
49
+ Eval: [-600,600] or smaller
50
+ """
51
+ n = x.shape[1]
52
+ j = np.arange( 1., n+1 )
53
+ sum1 = np.sum( x**2, axis=1 )
54
+ p = np.prod( np.cos( x / np.sqrt(j) ), axis=1)
55
+ f = sum1/div - p + 1
56
+ return f
57
+
58
+
59
+ def rastrigin(x: np.ndarray, a: float = 10) -> np.ndarray:
60
+ """RASTRIGIN
61
+ Dimension: N
62
+ Local Minima: many
63
+ Global Minimum: f(x) = 0 @ (0,0,....,0)
64
+ Eval: [-5.12,5.12] or smaller
65
+ """
66
+ n = x.shape[1]
67
+ sum1 = np.sum(x**2 - a*np.cos(2*np.pi*x),axis=1)
68
+ f = a*n + sum1
69
+ return f
70
+
71
+
72
+ def rosenbrock(x: np.ndarray, a: float = 100) -> float:
73
+ """ROSENBROCK
74
+ Dimension: N
75
+ Local Minima: Large valley
76
+ Global minimum: at (x,y) = (1,1) where f(x,y)=0
77
+ Eval: [-5.0,10.0] or smaller
78
+ """
79
+ x0 = x[:,:-1] # x_(i) ... to n-1
80
+ x1 = x[:,1:] # x_(i+1) ... to n-1
81
+ f = a*np.sum((x1-x0**2)**2,axis=1) + np.sum((1-x0)**2, axis=1)
82
+ return f
83
+
84
+
85
+ def sphere(x: np.ndarray) -> np.ndarray:
86
+ """SPHERE
87
+ Dimension: N
88
+ Local Minima: none
89
+ Global minimum: f(x) = 0 @ (0,0,....,0)
90
+ Eval: [-inf,inf] or smaller
91
+ """
92
+ f = np.sum(x**2,axis=1)
93
+ return f
94
+
95
+
96
+ def get_mesh_x_2d(xlim1: tuple[float,float],
97
+ xlim2: tuple[float,float],
98
+ n: int = 100):
99
+ xv1 = np.linspace(xlim1[0],xlim1[1],n)
100
+ xv2 = np.linspace(xlim2[0],xlim2[1],n)
101
+ (xm1,xm2) = np.meshgrid(xv1,xv2)
102
+ return (xm1,xm2)
103
+
104
+
105
+ def get_flat_x_2d(xlim1: tuple[float,float],
106
+ xlim2: tuple[float,float],
107
+ n: int = 100) -> np.ndarray:
108
+
109
+ (xm1,xm2) = get_mesh_x_2d(xlim1,xlim2,n)
110
+ xf1 = xm1.flatten()
111
+ xf2 = xm2.flatten()
112
+ return np.column_stack((xf1,xf2))
113
+
114
+
115
+ def f_mesh_2d(fun: Callable,
116
+ xlim1: tuple[float,float],
117
+ xlim2: tuple[float,float],
118
+ n: int = 100) -> np.ndarray:
119
+
120
+ (xm1,_) = get_mesh_x_2d(xlim1,xlim2,n)
121
+ xf = get_flat_x_2d(xlim1,xlim2,n)
122
+ f_flat = fun(xf)
123
+ f_mesh = f_flat.reshape(xm1.shape)
124
+
125
+ return f_mesh
126
+
127
+
128
+ def plot_fun_2d(tStr: str,
129
+ fun: Callable,
130
+ xlim1: tuple[float,float],
131
+ xlim2: tuple[float,float],
132
+ n: int =100) -> tuple[Any,Any]:
133
+
134
+ (xm1,xm2) = get_mesh_x_2d(xlim1,xlim2,n)
135
+ f_mesh = f_mesh_2d(fun,xlim1,xlim2,n)
136
+ # Plot the function
137
+ pp = PlotOptsGeneral()
138
+ fig, ax = plt.subplots(figsize=pp.single_fig_size_square,
139
+ layout="constrained")
140
+ fig.set_dpi(pp.resolution)
141
+
142
+ plt.contourf(xm1, xm2, f_mesh, 20, cmap=pp.cmap_seq)
143
+
144
+ plt.colorbar()
145
+ plt.title(tStr,fontsize=pp.font_head_size,fontname=pp.font_name)
146
+ plt.xlabel("x1",fontsize=pp.font_ax_size,fontname=pp.font_name)
147
+ plt.ylabel("x2",fontsize=pp.font_ax_size,fontname=pp.font_name)
148
+
149
+ #plt.show()
150
+ #plt.savefig(save_path+save_name, dpi=pp.resolution, format="png", bbox_inches="tight")
151
+ return fig,ax
152
+
153
+
pyvale/core/raster.py ADDED
@@ -0,0 +1,31 @@
1
+ """
2
+ ================================================================================
3
+ pyvale: the python validation engine
4
+ License: MIT
5
+ Copyright (C) 2025 The Computer Aided Validation Team
6
+ ================================================================================
7
+ """
8
+ from abc import ABC, abstractmethod
9
+ import numpy as np
10
+
11
+ # NOTE: This module is a feature under developement.
12
+
13
+
14
+ # NOTE:
15
+ # - Need to render a single frame static/deformed
16
+ # - Need to render all frames static/deformed
17
+ class IRaster(ABC):
18
+ @abstractmethod
19
+ def render_static_frame() -> None:
20
+ pass
21
+
22
+ @abstractmethod
23
+ def render_deformed_frame() -> None:
24
+ pass
25
+
26
+
27
+ # NOTE:
28
+ # - Manages parallelisation/saving with different rendering backends
29
+ # - Uses multi-processing
30
+ class Raster:
31
+ pass
@@ -0,0 +1,76 @@
1
+ """
2
+ ================================================================================
3
+ pyvale: the python validation engine
4
+ License: MIT
5
+ Copyright (C) 2025 The Computer Aided Validation Team
6
+ ================================================================================
7
+ """
8
+ from pathlib import Path
9
+ from multiprocessing.pool import Pool
10
+ import numpy as np
11
+ from pyvale.core.cameradata import CameraData
12
+ from pyvale.core.rendermesh import RenderMeshData
13
+ import pyvale.core.cython.rastercyth as rastercyth
14
+
15
+ # NOTE: This module is a feature under developement.
16
+
17
+ class RasterCY:
18
+ @staticmethod
19
+ def raster_static_mesh(cam_data: CameraData,
20
+ render_mesh: RenderMeshData,
21
+ threads_num: int | None = None,
22
+ ) -> tuple[np.ndarray,np.ndarray,np.ndarray] | None:
23
+
24
+ frames_num = render_mesh.fields_render.shape[1]
25
+ field_num = render_mesh.fields_render.shape[2]
26
+
27
+ images_out = np.empty((cam_data.pixels_num[1],
28
+ cam_data.pixels_num[0],
29
+ frames_num,
30
+ field_num))
31
+ depths_out = np.empty((cam_data.pixels_num[1],
32
+ cam_data.pixels_num[0],
33
+ frames_num))
34
+ elems_out = np.empty((frames_num,))
35
+
36
+ if threads_num is None:
37
+ for tt in range(frames_num):
38
+ (image_buffer,
39
+ depth_buffer,
40
+ elems_in_image) = rastercyth.raster_frame(
41
+ render_mesh.coords,
42
+ render_mesh.connectivity,
43
+ render_mesh.fields_render[:,tt,:],
44
+ cam_data)
45
+
46
+ images_out[:,:,tt,:] = image_buffer
47
+ depths_out[:,:,tt] = depth_buffer
48
+ elems_out[tt] = elems_in_image
49
+
50
+ else:
51
+ assert threads_num > 0, "Number of threads must be greater than 0."
52
+
53
+ with Pool(threads_num) as pool:
54
+ processes_with_id = []
55
+
56
+ for tt in range(frames_num):
57
+ args = (render_mesh.coords,
58
+ render_mesh.connectivity,
59
+ render_mesh.fields_render[:,tt,:],
60
+ cam_data)
61
+
62
+ process = pool.apply_async(rastercyth.raster_frame, args=args)
63
+ processes_with_id.append({"process": process,
64
+ "frame": tt})
65
+
66
+ for pp in processes_with_id:
67
+ (image,depth,elems) = pp["process"].get()
68
+ images_out[:,:,pp["frame"],:] = image
69
+ depths_out[:,:,pp["frame"]] = depth
70
+ elems_out = elems
71
+
72
+ return (images_out,depths_out,elems_out)
73
+
74
+
75
+
76
+