File indexing completed on 2026-07-16 08:08:22
0001
0002
0003
0004
0005
0006
0007 """
0008 Simple test script for ToroidalField Python bindings
0009 Tests the magnetic field functionality without complex dependencies
0010 """
0011
0012 import sys
0013
0014
0015 def test_toroidal_field_basic():
0016 """Test basic import and configuration"""
0017 print("=" * 60)
0018 print("Testing ToroidalField Python Bindings")
0019 print("=" * 60)
0020
0021 try:
0022 import acts.acts_toroidal_field as toroidal_field
0023
0024 print("โ
Successfully imported acts.acts_toroidal_field")
0025 except ImportError as e:
0026 print(f"โ Failed to import acts.acts_toroidal_field: {e}")
0027 return False
0028
0029
0030 print("\n๐ Testing Config with defaults:")
0031 try:
0032 config = toroidal_field.Config()
0033 print(f" Barrel R_in: {config.barrel.R_in / 1000:.1f} m")
0034 print(f" Barrel R_out: {config.barrel.R_out / 1000:.1f} m")
0035 print(f" Barrel c: {config.barrel.c / 1000:.1f} m")
0036 print(f" Barrel b: {config.barrel.b / 1000:.3f} m")
0037 print(f" Barrel I: {config.barrel.I} A")
0038 print(f" Barrel Nturns: {config.barrel.Nturns}")
0039 print(f" Number of coils: {config.layout.nCoils}")
0040 print("โ
Config creation successful")
0041 except Exception as e:
0042 print(f"โ Config creation failed: {e}")
0043 return False
0044
0045
0046 print("\n๐ง Testing Config customization:")
0047 try:
0048 custom_config = toroidal_field.Config()
0049 custom_config.barrel.R_in = 5.2 * 1000
0050 custom_config.barrel.R_out = 9.8 * 1000
0051 custom_config.barrel.I = 18000.0
0052 custom_config.layout.nCoils = 10
0053
0054 print(f" Customized Barrel R_in: {custom_config.barrel.R_in / 1000:.1f} m")
0055 print(f" Customized Barrel R_out: {custom_config.barrel.R_out / 1000:.1f} m")
0056 print(f" Customized Barrel I: {custom_config.barrel.I} A")
0057 print(f" Customized number of coils: {custom_config.layout.nCoils}")
0058 print("โ
Config customization successful")
0059 except Exception as e:
0060 print(f"โ Config customization failed: {e}")
0061 return False
0062
0063
0064 print("\n๐งฒ Testing ToroidalField creation:")
0065 try:
0066 field = toroidal_field.ToroidalField(config)
0067 print("โ
ToroidalField creation successful")
0068 except Exception as e:
0069 print(f"โ ToroidalField creation failed: {e}")
0070 return False
0071
0072 return True
0073
0074
0075 def test_toroidal_field_calculation():
0076 """Test magnetic field calculation"""
0077 print("\n" + "=" * 60)
0078 print("Testing Magnetic Field Calculation")
0079 print("=" * 60)
0080
0081 try:
0082 import acts
0083 import acts.acts_toroidal_field as toroidal_field
0084
0085
0086 config = toroidal_field.Config()
0087 field = toroidal_field.ToroidalField(config)
0088
0089
0090 ctx = acts.MagneticFieldContext()
0091 cache = field.makeCache(ctx)
0092 print("โ
Magnetic field context and cache created")
0093
0094
0095 test_points = [
0096 (6000.0, 0.0, 0.0, "Barrel region"),
0097 (0.0, 7000.0, 1000.0, "Barrel region (rotated)"),
0098 (2000.0, 0.0, 15000.0, "Endcap region"),
0099 (0.0, 3000.0, -12000.0, "Negative endcap"),
0100 (0.0, 0.0, 0.0, "Origin"),
0101 ]
0102
0103 print(f"\n๐ฏ Testing field calculation at {len(test_points)} points:")
0104 for x, y, z, description in test_points:
0105 position = acts.Vector3(x, y, z)
0106 field_value = field.getField(position, cache)
0107
0108
0109 magnitude = (
0110 field_value[0] ** 2 + field_value[1] ** 2 + field_value[2] ** 2
0111 ) ** 0.5
0112
0113 print(f" {description}:")
0114 print(f" Position: ({x/1000:.1f}, {y/1000:.1f}, {z/1000:.1f}) m")
0115 print(
0116 f" Field: ({field_value[0]:.2e}, {field_value[1]:.2e}, {field_value[2]:.2e}) T"
0117 )
0118 print(f" Magnitude: {magnitude:.2e} T")
0119
0120 print("โ
Field calculation successful")
0121 return True
0122
0123 except Exception as e:
0124 print(f"โ Field calculation failed: {e}")
0125 return False
0126
0127
0128 def test_configuration_classes():
0129 """Test individual configuration classes"""
0130 print("\n" + "=" * 60)
0131 print("Testing Configuration Classes")
0132 print("=" * 60)
0133
0134 try:
0135 import acts.acts_toroidal_field as toroidal_field
0136
0137
0138 print("\n๐บ Testing BarrelConfig:")
0139 barrel_config = toroidal_field.BarrelConfig()
0140 print(f" Default R_in: {barrel_config.R_in / 1000:.1f} m")
0141 print(f" Default R_out: {barrel_config.R_out / 1000:.1f} m")
0142 print(f" Default current: {barrel_config.I} A")
0143 print(f" Default turns: {barrel_config.Nturns}")
0144
0145
0146 print("\n๐ Testing EctConfig:")
0147 ect_config = toroidal_field.EctConfig()
0148 print(f" Default R_in: {ect_config.R_in / 1000:.3f} m")
0149 print(f" Default R_out: {ect_config.R_out / 1000:.2f} m")
0150 print(f" Default current: {ect_config.I} A")
0151 print(f" Default turns: {ect_config.Nturns}")
0152
0153
0154 print("\n๐ Testing LayoutConfig:")
0155 layout_config = toroidal_field.LayoutConfig()
0156 print(f" Default nCoils: {layout_config.nCoils}")
0157 print(f" Default theta0: {layout_config.theta0:.4f} rad")
0158 print(f" Default thetaStep: {layout_config.thetaStep:.4f} rad")
0159
0160 print("โ
Configuration classes test successful")
0161 return True
0162
0163 except Exception as e:
0164 print(f"โ Configuration classes test failed: {e}")
0165 return False
0166
0167
0168 def main():
0169 """Run all tests"""
0170 print("๐ Starting ToroidalField Python Binding Tests")
0171 print("=" * 80)
0172
0173 tests = [
0174 ("Basic functionality", test_toroidal_field_basic),
0175 ("Field calculation", test_toroidal_field_calculation),
0176 ("Configuration classes", test_configuration_classes),
0177 ]
0178
0179 results = []
0180 for test_name, test_func in tests:
0181 print(f"\n๐งช Running test: {test_name}")
0182 try:
0183 result = test_func()
0184 results.append(result)
0185 if result:
0186 print(f"โ
{test_name}: PASSED")
0187 else:
0188 print(f"โ {test_name}: FAILED")
0189 except Exception as e:
0190 print(f"๐ฅ {test_name}: ERROR - {e}")
0191 results.append(False)
0192
0193
0194 print("\n" + "=" * 80)
0195 print("๐ Test Summary")
0196 print("=" * 80)
0197
0198 passed = sum(results)
0199 total = len(results)
0200
0201 for i, (test_name, _) in enumerate(tests):
0202 status = "โ
PASSED" if results[i] else "โ FAILED"
0203 print(f" {test_name}: {status}")
0204
0205 print(f"\nOverall: {passed}/{total} tests passed")
0206
0207 if passed == total:
0208 print("๐ All tests passed! ToroidalField is working correctly.")
0209 return 0
0210 else:
0211 print("โ ๏ธ Some tests failed. Check the output above for details.")
0212 return 1
0213
0214
0215 if __name__ == "__main__":
0216 sys.exit(main())