forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtoroidal_field_basic.py
More file actions
211 lines (169 loc) · 6.81 KB
/
toroidal_field_basic.py
File metadata and controls
211 lines (169 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python3
# Copyright (c) 2025 ACTS-Project
# This file is part of ACTS.
# See LICENSE for details.
"""
Simple test script for ToroidField Python bindings
Tests the magnetic field functionality without complex dependencies
"""
import sys
def test_toroidal_field_basic():
"""Test basic import and configuration"""
print("=" * 60)
print("Testing ToroidField Python Bindings")
print("=" * 60)
import acts
print("✅ Successfully imported acts.ToroidField")
# Test Config creation with defaults
print("\n📋 Testing Config with defaults:")
try:
config = acts.ToroidField.Config()
print(f" Barrel R_in: {config.barrel.R_in / 1000:.1f} m")
print(f" Barrel R_out: {config.barrel.R_out / 1000:.1f} m")
print(f" Barrel c: {config.barrel.c / 1000:.1f} m")
print(f" Barrel b: {config.barrel.b / 1000:.3f} m")
print(f" Barrel I: {config.barrel.I} A")
print(f" Barrel Nturns: {config.barrel.Nturns}")
print(f" Number of coils: {config.layout.nCoils}")
print("✅ Config creation successful")
except Exception as e:
print(f"❌ Config creation failed: {e}")
return False
# Test Config customization
print("\n🔧 Testing Config customization:")
try:
custom_config = acts.ToroidField.Config()
custom_config.barrel.R_in = 5.2 * 1000 # Convert to mm
custom_config.barrel.R_out = 9.8 * 1000 # Convert to mm
custom_config.barrel.I = 18000.0
custom_config.layout.nCoils = 10
print(f" Customized Barrel R_in: {custom_config.barrel.R_in / 1000:.1f} m")
print(f" Customized Barrel R_out: {custom_config.barrel.R_out / 1000:.1f} m")
print(f" Customized Barrel I: {custom_config.barrel.I} A")
print(f" Customized number of coils: {custom_config.layout.nCoils}")
print("✅ Config customization successful")
except Exception as e:
print(f"❌ Config customization failed: {e}")
return False
# Test ToroidField creation
print("\n🧲 Testing ToroidField creation:")
try:
field = acts.ToroidField(config)
print("✅ ToroidField creation successful")
except Exception as e:
print(f"❌ ToroidField creation failed: {e}")
return False
return True
def test_toroidal_field_calculation():
"""Test magnetic field calculation"""
print("\n" + "=" * 60)
print("Testing Magnetic Field Calculation")
print("=" * 60)
try:
import acts
# Create field
config = acts.ToroidField.Config()
field = acts.ToroidField(config)
# Create magnetic field context and cache
ctx = acts.MagneticFieldContext()
cache = field.makeCache(ctx)
print("✅ Magnetic field context and cache created")
# Test field calculation at various points
test_points = [
(6000.0, 0.0, 0.0, "Barrel region"),
(0.0, 7000.0, 1000.0, "Barrel region (rotated)"),
(2000.0, 0.0, 15000.0, "Endcap region"),
(0.0, 3000.0, -12000.0, "Negative endcap"),
(0.0, 0.0, 0.0, "Origin"),
]
print(f"\n🎯 Testing field calculation at {len(test_points)} points:")
for x, y, z, description in test_points:
position = acts.Vector3(x, y, z)
field_value = field.getField(position, cache)
# Calculate field magnitude
magnitude = (
field_value[0] ** 2 + field_value[1] ** 2 + field_value[2] ** 2
) ** 0.5
print(f" {description}:")
print(f" Position: ({x/1000:.1f}, {y/1000:.1f}, {z/1000:.1f}) m")
print(
f" Field: ({field_value[0]:.2e}, {field_value[1]:.2e}, {field_value[2]:.2e}) T"
)
print(f" Magnitude: {magnitude:.2e} T")
print("✅ Field calculation successful")
return True
except Exception as e:
print(f"❌ Field calculation failed: {e}")
return False
def test_configuration_classes():
"""Test individual configuration classes"""
print("\n" + "=" * 60)
print("Testing Configuration Classes")
print("=" * 60)
try:
import acts
# Test BarrelConfig
print("\n🏺 Testing BarrelConfig:")
barrel_config = acts.ToroidField.BarrelConfig()
print(f" Default R_in: {barrel_config.R_in / 1000:.1f} m")
print(f" Default R_out: {barrel_config.R_out / 1000:.1f} m")
print(f" Default current: {barrel_config.I} A")
print(f" Default turns: {barrel_config.Nturns}")
# Test EctConfig
print("\n🔚 Testing EctConfig:")
ect_config = acts.ToroidField.EctConfig()
print(f" Default R_in: {ect_config.R_in / 1000:.3f} m")
print(f" Default R_out: {ect_config.R_out / 1000:.2f} m")
print(f" Default current: {ect_config.I} A")
print(f" Default turns: {ect_config.Nturns}")
# Test LayoutConfig
print("\n📐 Testing LayoutConfig:")
layout_config = acts.ToroidField.LayoutConfig()
print(f" Default nCoils: {layout_config.nCoils}")
print(f" Default theta0: {layout_config.theta0:.4f} rad")
print(f" Default thetaStep: {layout_config.thetaStep:.4f} rad")
print("✅ Configuration classes test successful")
return True
except Exception as e:
print(f"❌ Configuration classes test failed: {e}")
return False
def main():
"""Run all tests"""
print("🚀 Starting ToroidField Python Binding Tests")
print("=" * 80)
tests = [
("Basic functionality", test_toroidal_field_basic),
("Field calculation", test_toroidal_field_calculation),
("Configuration classes", test_configuration_classes),
]
results = []
for test_name, test_func in tests:
print(f"\n🧪 Running test: {test_name}")
try:
result = test_func()
results.append(result)
if result:
print(f"✅ {test_name}: PASSED")
else:
print(f"❌ {test_name}: FAILED")
except Exception as e:
print(f"💥 {test_name}: ERROR - {e}")
results.append(False)
# Summary
print("\n" + "=" * 80)
print("🏁 Test Summary")
print("=" * 80)
passed = sum(results)
total = len(results)
for i, (test_name, _) in enumerate(tests):
status = "✅ PASSED" if results[i] else "❌ FAILED"
print(f" {test_name}: {status}")
print(f"\nOverall: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! ToroidField is working correctly.")
return 0
else:
print("⚠️ Some tests failed. Check the output above for details.")
return 1
if __name__ == "__main__":
sys.exit(main())