radia 1.3.3__py3-none-any.whl → 1.3.5__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.
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Radia VTK Export Utilities
5
+
6
+ Functions for exporting Radia geometry to VTK format for visualization
7
+ in ParaView and other VTK-compatible tools.
8
+ """
9
+
10
+ import csv
11
+ from itertools import accumulate
12
+
13
+ def _get_radia_length_unit():
14
+ """
15
+ Get current Radia length unit by querying rad.FldUnits().
16
+
17
+ Returns:
18
+ tuple: (unit_name, scale_to_meters)
19
+ ('mm', 0.001) if Radia is using millimeters
20
+ ('m', 1.0) if Radia is using meters
21
+
22
+ Raises:
23
+ ValueError: If length unit cannot be determined
24
+ """
25
+ import radia as rad
26
+
27
+ units_str = rad.FldUnits()
28
+
29
+ if 'Length: mm' in units_str:
30
+ return ('mm', 0.001)
31
+ elif 'Length: m' in units_str:
32
+ return ('m', 1.0)
33
+ else:
34
+ raise ValueError(f"Cannot determine Radia length unit from: {units_str}")
35
+
36
+ def chunks(lst, n):
37
+ """
38
+ Yield successive n-sized chunks from a list.
39
+
40
+ Args:
41
+ lst: List to be chunked
42
+ n: Chunk size
43
+
44
+ Yields:
45
+ Chunks of size n from the input list
46
+ """
47
+ for i in range(0, len(lst), n):
48
+ yield lst[i:i + n]
49
+
50
+ def exportGeometryToVTK(obj, fileName='radia_Geometry'):
51
+ """
52
+ Export Radia object geometry to VTK Legacy format file.
53
+
54
+ Writes the geometry of a Radia object to a .vtk file for visualization
55
+ in ParaView. The format is VTK Legacy (ASCII), consisting of polygons only.
56
+
57
+ Args:
58
+ obj: Radia object ID (integer)
59
+ fileName: Output filename without extension (default: 'radia_Geometry')
60
+
61
+ Output:
62
+ Creates fileName.vtk in the current directory
63
+
64
+ Example:
65
+ >>> import radia as rad
66
+ >>> from radia_vtk_export import exportGeometryToVTK
67
+ >>> mag = rad.ObjRecMag([0,0,0], [10,10,10], [0,0,1])
68
+ >>> exportGeometryToVTK(mag, 'my_magnet')
69
+ """
70
+ import radia as rad
71
+
72
+ vtkData = rad.ObjDrwVTK(obj, 'Axes->False')
73
+
74
+ lengths = vtkData['polygons']['lengths']
75
+ nPoly = len(lengths)
76
+ offsets = list(accumulate(lengths))
77
+ offsets.insert(0, 0) # prepend list with a zero
78
+ points = vtkData['polygons']['vertices']
79
+ nPnts = int(len(points)/3)
80
+
81
+ # Get Radia's current length unit and convert to meters for VTK standard
82
+ unit_name, scale_to_meters = _get_radia_length_unit()
83
+ points = [round(num * scale_to_meters, 8) for num in points]
84
+
85
+ # define colours array
86
+ colors = vtkData['polygons']['colors']
87
+
88
+ # pre-process the output lists to have chunkLength items per line
89
+ chunkLength = 9 # this writes 9 numbers per line
90
+ points = list(chunks(points, chunkLength))
91
+ colors = list(chunks(colors, chunkLength))
92
+
93
+ # write the data to file (VTK Legacy format - most compatible)
94
+ with open(fileName + ".vtk", "w", newline="") as f:
95
+ f.write('# vtk DataFile Version 3.0\n')
96
+ f.write('vtk output\nASCII\nDATASET POLYDATA\n')
97
+ f.write('POINTS ' + str(nPnts) + ' float\n')
98
+ writer = csv.writer(f, delimiter=" ")
99
+ writer.writerows(points)
100
+ f.write('\n')
101
+
102
+ # POLYGONS in classic format (most compatible with all ParaView versions)
103
+ # Format: nPoly totalSize
104
+ # Each line: nVertices v1 v2 v3 ...
105
+ total_size = sum(lengths) + nPoly # sum of (nVertices + nVertices) for each polygon
106
+ f.write('POLYGONS ' + str(nPoly) + ' ' + str(total_size) + '\n')
107
+ for i in range(nPoly):
108
+ n_vertices = lengths[i]
109
+ start = offsets[i]
110
+ end = offsets[i+1]
111
+ f.write(str(n_vertices))
112
+ for j in range(start, end):
113
+ f.write(' ' + str(j))
114
+ f.write('\n')
115
+
116
+ f.write('\n')
117
+ f.write('CELL_DATA ' + str(nPoly) + '\n')
118
+ f.write('COLOR_SCALARS Radia_colours 3\n')
119
+ writer.writerows(colors)
120
+
121
+ print(f"VTK file exported: {fileName}.vtk")
122
+ print(f" Polygons: {nPoly}")
123
+ print(f" Points: {nPnts}")
124
+
125
+
126
+ def exportFieldToVTK(points, field_data, fileName='field_distribution', field_name='B_field'):
127
+ """
128
+ Export magnetic field distribution to VTK Legacy format file.
129
+
130
+ Args:
131
+ points: List of observation points [[x, y, z], ...] in Radia's current units
132
+ field_data: List of field vectors [[Bx, By, Bz], ...] in Tesla
133
+ fileName: Output file name (without .vtk extension)
134
+ field_name: Name for the vector field in VTK file
135
+
136
+ Note:
137
+ Points are automatically converted to meters (VTK standard) based on
138
+ Radia's current unit setting (queried via rad.FldUnits()).
139
+ """
140
+ import numpy as np
141
+
142
+ points = np.array(points)
143
+ field_data = np.array(field_data)
144
+
145
+ if points.shape[0] != field_data.shape[0]:
146
+ raise ValueError(f"Points ({points.shape[0]}) and field data ({field_data.shape[0]}) must have same length")
147
+
148
+ if points.shape[1] != 3 or field_data.shape[1] != 3:
149
+ raise ValueError("Points and field data must be Nx3 arrays")
150
+
151
+ # Get Radia's current length unit
152
+ unit_name, scale_to_meters = _get_radia_length_unit()
153
+
154
+ # Ensure .vtk extension
155
+ if not fileName.endswith('.vtk'):
156
+ fileName += '.vtk'
157
+
158
+ with open(fileName, 'w') as f:
159
+ # Header
160
+ f.write('# vtk DataFile Version 3.0\n')
161
+ f.write('Magnetic Field Distribution\n')
162
+ f.write('ASCII\n')
163
+ f.write('DATASET POLYDATA\n')
164
+
165
+ # Points (convert to meters for VTK standard)
166
+ f.write(f'POINTS {len(points)} float\n')
167
+ for pt in points:
168
+ # Convert to meters using detected unit scale
169
+ f.write(f'{pt[0]*scale_to_meters} {pt[1]*scale_to_meters} {pt[2]*scale_to_meters}\n')
170
+
171
+ # Point data (vector field)
172
+ f.write(f'\nPOINT_DATA {len(points)}\n')
173
+ f.write(f'VECTORS {field_name} float\n')
174
+ for B in field_data:
175
+ f.write(f'{B[0]} {B[1]} {B[2]}\n')
176
+
177
+ print(f"VTK field file exported: {fileName}")
178
+ print(f" Points: {len(points)}")
179
+ print(f" Field: {field_name}")
180
+
181
+
182
+ if __name__ == '__main__':
183
+ """
184
+ Demo: Export a simple Radia geometry to VTK format
185
+ """
186
+ import sys
187
+ import os
188
+
189
+ # Add build directory to path
190
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'build', 'Release'))
191
+
192
+ import radia as rad
193
+
194
+ print("=" * 60)
195
+ print("Radia VTK Export Demo")
196
+ print("=" * 60)
197
+
198
+ # Create a simple test geometry
199
+ print("\nCreating test geometry...")
200
+
201
+ # Rectangular magnet
202
+ mag = rad.ObjRecMag([0, 0, 0], [30, 30, 10], [0, 0, 1])
203
+
204
+ # Cylindrical magnet
205
+ cyl = rad.ObjCylMag([50, 0, 0], 15, 20, 16, 'z', [0, 0, 1])
206
+
207
+ # Container
208
+ container = rad.ObjCnt([mag, cyl])
209
+
210
+ # Export to VTK
211
+ output_file = 'radia_demo_geometry'
212
+ print(f"\nExporting geometry to {output_file}.vtk...")
213
+ exportGeometryToVTK(container, output_file)
214
+
215
+ print("\n" + "=" * 60)
216
+ print("Export complete!")
217
+ print("\nTo view in ParaView:")
218
+ print(f" 1. Open ParaView")
219
+ print(f" 2. File → Open → {output_file}.vtk")
220
+ print(f" 3. Click 'Apply' in the Properties panel")
221
+ print("=" * 60)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: radia
3
- Version: 1.3.3
3
+ Version: 1.3.5
4
4
  Summary: Radia 3D Magnetostatics with NGSolve Integration and OpenMP Parallelization
5
5
  Home-page: https://github.com/ksugahar/Radia_NGSolve
6
6
  Author: Pascal Elleaume
@@ -182,9 +182,6 @@ See [examples/Radia_to_NGSolve_CoefficientFunction/](examples/Radia_to_NGSolve_C
182
182
  - [examples/Radia_to_NGSolve_CoefficientFunction/EXAMPLES_GUIDE.md](examples/Radia_to_NGSolve_CoefficientFunction/EXAMPLES_GUIDE.md) - Detailed usage guide
183
183
  - [tests/test_radia_ngsolve.py](tests/test_radia_ngsolve.py) - Integration tests
184
184
 
185
- ### Visualization
186
- - [docs/PYVISTA_VIEWER.md](examples/2024_02_03_振分電磁石/PYVISTA_VIEWER.md) - PyVista viewer guide
187
-
188
185
  ### Development
189
186
  - [docs/TAB_CONVERSION_REPORT.md](docs/TAB_CONVERSION_REPORT.md) - Code style conversion
190
187
  - [docs/CLAUDE.md](docs/CLAUDE.md) - Development notes
@@ -0,0 +1,18 @@
1
+ radia/__init__.py,sha256=edxD1jM_-2LddwoxqtgATa_vTaruXk5WZsntpFJ9qtM,47
2
+ radia/nastran_mesh_import.py,sha256=CSoVhZCXa85lPiTF2hlspE2clBKOD7-_sCp1bxu_IK0,18147
3
+ radia/netgen_mesh_import.py,sha256=UopXk-5bbfj1j9_hyiq8jbjb4SQXnWaeuaC7TDf17wA,19872
4
+ radia/rad_ngsolve.pyd,sha256=s5ZvpTIrjYeV_B3vQv5HrtP4u_RaPhvxuZf5aKv3oC0,566272
5
+ radia/rad_ngsolve_fast.py,sha256=GkC7ruKy3MESHsO0iRSWsrgLU4-DPPgctOi6pPpsWg4,5675
6
+ radia/radia_coil_builder.py,sha256=nQkiAbfhueNvvxUARHdPD0C68ImidHmUQv_q4RsImeY,11253
7
+ radia/radia_field_cached.py,sha256=Bjw3ecNe3u7AAXnLob5m_tjYIY7HwB9DpgFg9a-aP_8,9509
8
+ radia/radia_ngsolve.pyd,sha256=s5ZvpTIrjYeV_B3vQv5HrtP4u_RaPhvxuZf5aKv3oC0,566272
9
+ radia/radia_ngsolve_field.py,sha256=suJr4wacfYFKOkyV-5AQuHWnW5rtUMb0gSSjq8VRSXc,10166
10
+ radia/radia_ngsolve_utils.py,sha256=xZCR9DOIKMwdEjmC28rOXVZiWFY5BQYH2VfopfuVBps,8406
11
+ radia/radia_pyvista_viewer.py,sha256=JS33Mx4azGI7hUX0bzefc6zJfhv6qfRjM3Kl1bE9Mjs,4275
12
+ radia/radia_tetra_mesh.py,sha256=nEpNpOBdJ-0DjS7WUx_bRHskrDKSKH3rSEWr-CwyQRM,21147
13
+ radia/radia_vtk_export.py,sha256=I8Vyyt9tky78Qw1xPru9f0Rii6QEmdEgTFjQtamyooc,6540
14
+ radia-1.3.5.dist-info/licenses/LICENSE,sha256=yaWxyzG9DpJ44dDNdGni4nukwiZ8pU-r_aW-1tYNAjk,4374
15
+ radia-1.3.5.dist-info/METADATA,sha256=LuqDACqJI2J9ucBkZe1UQFfh77ZuYnZvZIwI9JwRpX0,13202
16
+ radia-1.3.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ radia-1.3.5.dist-info/top_level.txt,sha256=kNDonE5X3Q2xnmOsWleQnGKQobuFsKM6Px5_Ta1I6x8,6
18
+ radia-1.3.5.dist-info/RECORD,,
@@ -1,93 +1,93 @@
1
- RADIA SOFTWARE LICENSE
2
- ======================
3
-
4
- This software contains multiple components with different licenses:
5
-
6
- 1. RADIA Core (BSD-style License)
7
- 2. HACApK_LH-Cimplm Library (MIT License)
8
-
9
- All licenses are permissive open-source licenses allowing redistribution
10
- and modification.
11
-
12
- ================================================================================
13
- PART 1: RADIA CORE
14
- ================================================================================
15
-
16
- Copyright © 1997 - 2018, European Synchrotron Radiation Facility
17
-
18
- The RADIA software is distributed subject to the following license conditions:
19
-
20
- Redistribution and use in source and binary forms, with or without
21
- modification, are permitted provided that the following conditions are met:
22
-
23
- 1. Redistributions of source code must retain the above copyright notice,
24
- this list of conditions and the following disclaimer.
25
-
26
- 2. Redistributions in binary form must reproduce the above copyright notice,
27
- this list of conditions and the following disclaimer in the documentation
28
- and/or other materials provided with the distribution.
29
-
30
- DISCLAIMER: THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS"
31
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
34
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
-
41
- The views and conclusions contained in the software and documentation are
42
- those of the authors and should not be interpreted as representing official
43
- policies, either expressed or implied, of the RADIA project.
44
-
45
- ================================================================================
46
- PART 2: HACApK_LH-Cimplm (H-matrix Library)
47
- ================================================================================
48
-
49
- Software Name : HACApK
50
- Version : 1.3.0
51
- Location: src/ext/HACApK_LH-Cimplm/
52
-
53
- Copyright (c) 2015 Akihiro Ida and Takeshi Iwashita
54
-
55
- MIT License
56
-
57
- Permission is hereby granted, free of charge, to any person obtaining a copy
58
- of this software and associated documentation files (the "Software"), to deal
59
- in the Software without restriction, including without limitation the rights
60
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
- copies of the Software, and to permit persons to whom the Software is
62
- furnished to do so, subject to the following conditions:
63
-
64
- The above copyright notice and this permission notice shall be included in all
65
- copies or substantial portions of the Software.
66
-
67
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
- SOFTWARE.
74
-
75
- ppOpen-HPC project:
76
- Open Source Infrastructure for Development and Execution of Large-Scale
77
- Scientific Applications on Post-Peta-Scale Supercomputers with Automatic
78
- Tuning (AT).
79
-
80
- Sponsorship:
81
- Japan Science and Technology Agency (JST), Basic Research Programs: CREST,
82
- Development of System Software Technologies for post-Peta Scale High
83
- Performance Computing.
84
-
85
- ================================================================================
86
- ADDITIONAL COMPONENTS
87
- ================================================================================
88
-
89
- This software may include additional third-party libraries and components,
90
- each governed by their respective licenses. Please refer to the individual
91
- component directories for specific license information.
92
-
93
- ================================================================================
1
+ RADIA SOFTWARE LICENSE
2
+ ======================
3
+
4
+ This software contains multiple components with different licenses:
5
+
6
+ 1. RADIA Core (BSD-style License)
7
+ 2. HACApK_LH-Cimplm Library (MIT License)
8
+
9
+ All licenses are permissive open-source licenses allowing redistribution
10
+ and modification.
11
+
12
+ ================================================================================
13
+ PART 1: RADIA CORE
14
+ ================================================================================
15
+
16
+ Copyright © 1997 - 2018, European Synchrotron Radiation Facility
17
+
18
+ The RADIA software is distributed subject to the following license conditions:
19
+
20
+ Redistribution and use in source and binary forms, with or without
21
+ modification, are permitted provided that the following conditions are met:
22
+
23
+ 1. Redistributions of source code must retain the above copyright notice,
24
+ this list of conditions and the following disclaimer.
25
+
26
+ 2. Redistributions in binary form must reproduce the above copyright notice,
27
+ this list of conditions and the following disclaimer in the documentation
28
+ and/or other materials provided with the distribution.
29
+
30
+ DISCLAIMER: THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS"
31
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
34
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
+
41
+ The views and conclusions contained in the software and documentation are
42
+ those of the authors and should not be interpreted as representing official
43
+ policies, either expressed or implied, of the RADIA project.
44
+
45
+ ================================================================================
46
+ PART 2: HACApK_LH-Cimplm (H-matrix Library)
47
+ ================================================================================
48
+
49
+ Software Name : HACApK
50
+ Version : 1.3.0
51
+ Location: src/ext/HACApK_LH-Cimplm/
52
+
53
+ Copyright (c) 2015 Akihiro Ida and Takeshi Iwashita
54
+
55
+ MIT License
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ of this software and associated documentation files (the "Software"), to deal
59
+ in the Software without restriction, including without limitation the rights
60
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ copies of the Software, and to permit persons to whom the Software is
62
+ furnished to do so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in all
65
+ copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ SOFTWARE.
74
+
75
+ ppOpen-HPC project:
76
+ Open Source Infrastructure for Development and Execution of Large-Scale
77
+ Scientific Applications on Post-Peta-Scale Supercomputers with Automatic
78
+ Tuning (AT).
79
+
80
+ Sponsorship:
81
+ Japan Science and Technology Agency (JST), Basic Research Programs: CREST,
82
+ Development of System Software Technologies for post-Peta Scale High
83
+ Performance Computing.
84
+
85
+ ================================================================================
86
+ ADDITIONAL COMPONENTS
87
+ ================================================================================
88
+
89
+ This software may include additional third-party libraries and components,
90
+ each governed by their respective licenses. Please refer to the individual
91
+ component directories for specific license information.
92
+
93
+ ================================================================================
@@ -0,0 +1 @@
1
+ radia
python/__init__.py DELETED
@@ -1,2 +0,0 @@
1
- # Radia Python package
2
- __version__ = "1.1.0"