File indexing completed on 2025-12-03 09:15:57
0001 import pathlib, acts, acts.examples
0002 import pytest
0003
0004 from helpers import covfieEnabled
0005
0006
0007 @pytest.mark.skipif(not covfieEnabled, reason="Covfie plugin not available")
0008 def test_constant_field_conversion():
0009 from acts import covfie
0010
0011 v = acts.Vector3(1, 2, 3)
0012 af = acts.ConstantBField(v)
0013 cf = covfie.makeCovfieField(af)
0014 view = covfie.toView(cf)
0015 points = [(0, 0, 1), (1, 1, 1), (1, 0, 2)]
0016 for [x, y, z] in points:
0017 field = view.at(x, y, z)
0018 assert field.at(0) == 1
0019 assert field.at(1) == 2
0020 assert field.at(2) == 3
0021
0022
0023 @pytest.mark.skipif(not covfieEnabled, reason="Covfie plugin not available")
0024 def test_inhomogeneous_field_conversion():
0025 from acts import covfie
0026
0027 u = acts.UnitConstants
0028
0029 af = acts.SolenoidBField(
0030 radius=10 * u.m, length=40 * u.m, nCoils=1000, bMagCenter=2 * u.T
0031 )
0032 bc = acts.MagneticFieldContext()
0033 fc = af.makeCache(bc)
0034
0035 cf = covfie.makeCovfieField(
0036 af,
0037 fc,
0038 [100, 100, 100],
0039 acts.Vector3(-15000, -15000, -15000),
0040 acts.Vector3(15000, 15000, 15000),
0041 )
0042 view = covfie.toView(cf)
0043 points = [
0044 (9300.0, 4700.0, 11200.0),
0045 (9999.0, 9999.0, 14300.0),
0046 (-2900.0, -4700.0, 5200.0),
0047 (-2900.0, -4800.0, 9100.0),
0048 (-2900.0, -5200.0, -8800.0),
0049 (-4400.0, 4800.0, -12700.0),
0050 (-6600.0, 1900.0, 7700.0),
0051 (-9700.0, -900.0, 12700.0),
0052 (-9999.0, -9999.0, -13000.0),
0053 (9999.0, 0, 14900.0),
0054 ]
0055
0056
0057 error_margin_half_width = 0.005
0058 for x, y, z in points:
0059 rfield = af.getField(acts.Vector3(x, y, z), fc)
0060 Bx1, By1, Bz1 = rfield[0], rfield[1], rfield[2]
0061
0062 tfield = view.at(x, y, z)
0063 Bx2, By2, Bz2 = tfield.at(0), tfield.at(1), tfield.at(2)
0064
0065 assert (
0066 abs(Bx1 - Bx2) < error_margin_half_width
0067 and abs(By1 - By2) < error_margin_half_width
0068 and abs(Bz1 - Bz2) < error_margin_half_width
0069 )