44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import numpy
|
|
import numpy.testing
|
|
|
|
import pathfinder.model.oscillating as model
|
|
|
|
|
|
def test_dot_v_from_dipole():
|
|
|
|
dot_position1 = (-1, -1, -1)
|
|
dot_frequency1 = 11
|
|
expected_v1 = 0.00001421963287022476
|
|
dot = model.DotMeasurement(expected_v1, dot_position1, dot_frequency1)
|
|
|
|
# and dipole located at (4, 5, 6) with p=(1, 2, 3) and w = 7
|
|
pt = numpy.array((1, 2, 3, 4, 5, 6, 7))
|
|
|
|
numpy.testing.assert_allclose(dot.v_for_point(pt), dot.v, err_msg="v from dipole at a dot was incorrect!")
|
|
numpy.testing.assert_allclose(dot.cost(pt), 0, atol=1e-12, err_msg="cost should be zero")
|
|
|
|
|
|
def test_jac():
|
|
expected_jac = [
|
|
3.742008650059147e-6, 4.4904103800709765e-6, 5.238812110082806e-6,
|
|
-3.12967996186765e-6, -3.1568945702317167e-6, -3.184109178595783e-6,
|
|
8.603475350051953e-7
|
|
]
|
|
|
|
expected_jac2 = [
|
|
-4.428720903021825e-6, 3.5429767224174605e-6, 4.428720903021825e-6,
|
|
-6.804125751006259e-6, -4.0261099118380183e-7, 2.3754048479844336e-6,
|
|
5.181603456535536e-6
|
|
]
|
|
|
|
dot = model.DotMeasurement(50, (-1, -1, -1), 11)
|
|
|
|
# dipole located at (4, 5, 6) with p=(1, 2, 3) and w = 7
|
|
pt = numpy.array((1, 2, 3, 4, 5, 6, 7))
|
|
pt2 = numpy.array((2, 5, 3, 4, -5, -6, 2))
|
|
pts = numpy.append(pt, pt2)
|
|
expected_jac_all = expected_jac + expected_jac2
|
|
assert len(dot.jac_pt(pt)) == 7
|
|
numpy.testing.assert_allclose(dot.jac_pt(pt), expected_jac, err_msg="Jac pt doesn't match Mathematica result.")
|
|
numpy.testing.assert_allclose(dot.jac(pts), expected_jac_all, err_msg="whole row should match")
|