Beispiel #1
0
 def test_transform_coeff_with_x_and_r(self):
     """Test coefficient transform between x and r."""
     coeff = np.array([2, 3, 4])
     ltf = LinearFiniteRTransform(1, 10)  # (-1, 1) -> (r0, rmax)
     inv_tf = InverseRTransform(ltf)  # (r0, rmax) -> (-1, 1)
     x = np.linspace(-1, 1, 20)
     r = ltf.transform(x)
     assert r[0] == 1
     assert r[-1] == 10
     coeff_b = ODE._transformed_coeff_ode(coeff, inv_tf, x)
     derivs_fun = [inv_tf.deriv, inv_tf.deriv2, inv_tf.deriv3]
     coeff_b_ref = ODE._transformed_coeff_ode_with_r(coeff, derivs_fun, r)
     assert_allclose(coeff_b, coeff_b_ref)
Beispiel #2
0
def test_transform_coeff_with_x_and_r():
    """Test coefficient transform between x and r."""
    coeff = np.array([2, 3, 4])
    ltf = LinearFiniteRTransform(1, 10)  # (-1, 1) -> (r0, rmax)
    inv_tf = InverseRTransform(ltf)  # (r0, rmax) -> (-1, 1)
    x = np.linspace(-1, 1, 20)
    r = ltf.transform(x)
    assert r[0] == 1
    assert r[-1] == 10
    # Transform ODE from [1, 10) to (-1, 1)
    coeff_transform = _transform_ode_from_rtransform(coeff, inv_tf, x)
    derivs_fun = [inv_tf.deriv, inv_tf.deriv2, inv_tf.deriv3]
    coeff_transform_all_pts = _transform_ode_from_derivs(coeff, derivs_fun, r)
    assert_allclose(coeff_transform, coeff_transform_all_pts)
Beispiel #3
0
 def test_linear_inverse(self):
     """Test inverse transform and derivs function."""
     ltf = LinearFiniteRTransform(0.1, 10)
     iltf = InverseRTransform(ltf)
     # transform & inverse
     self._transform_and_inverse(0, 20, iltf)
     # finite diff for derivs
     self._deriv_finite_diff(0, 20, iltf)
Beispiel #4
0
 def test_linear_transform_coeff(self):
     """Test coefficient with linear transformation."""
     x = GaussLaguerre(10).points
     ltf = LinearFiniteRTransform(1, 10)
     inv_ltf = InverseRTransform(ltf)
     derivs_fun = [inv_ltf.deriv, inv_ltf.deriv2, inv_ltf.deriv3]
     coeff = np.array([2, 3, 4])
     coeff_b = ODE._transformed_coeff_ode_with_r(coeff, derivs_fun, x)
     # assert values
     assert_allclose(coeff_b[0], np.ones(len(x)) * coeff[0])
     assert_allclose(coeff_b[1], 1 / 4.5 * coeff[1])
     assert_allclose(coeff_b[2], (1 / 4.5)**2 * coeff[2])
Beispiel #5
0
def test_transformation_of_ode_with_linear_transform():
    """Test transformation of ODE with linear transformation."""
    x = GaussLaguerre(10).points
    # Obtain linear transformation with rmin = 1 and rmax = 10.
    ltf = LinearFiniteRTransform(1, 10)
    # The inverse is x_i = \frac{r_i - r_{min} - R} {r_i - r_{min} + R}
    inv_ltf = InverseRTransform(ltf)
    derivs_fun = [inv_ltf.deriv, inv_ltf.deriv2, inv_ltf.deriv3]
    # Test with 2y + 3y` + 4y``
    coeff = np.array([2, 3, 4])
    coeff_b = _transform_ode_from_derivs(coeff, derivs_fun, x)
    # assert values
    assert_allclose(coeff_b[0], np.ones(len(x)) * coeff[0])
    assert_allclose(coeff_b[1], 1 / 4.5 * coeff[1])
    assert_allclose(coeff_b[2], (1 / 4.5)**2 * coeff[2])
Beispiel #6
0
 def test_domain(self):
     """Test domain errors."""
     rad = UniformInteger(10)
     with self.assertRaises(ValueError):
         tf = BeckeRTransform(0.1, 1.2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = HandyModRTransform(0.1, 10.0, 2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = KnowlesRTransform(0.1, 1.2, 2)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = LinearFiniteRTransform(0.1, 10)
         tf.transform_1d_grid(rad)
     with self.assertRaises(ValueError):
         tf = MultiExpRTransform(0.1, 1.2)
         tf.transform_1d_grid(rad)
Beispiel #7
0
 def test_linear_finite_diff(self):
     """Test finite diff for linear derivs."""
     ltf = LinearFiniteRTransform(0.1, 10)
     self._deriv_finite_diff(-1, 1, ltf)
Beispiel #8
0
 def test_linear_transform(self):
     """Test linear transformation."""
     ltf = LinearFiniteRTransform(0.1, 10)
     self._transform_and_inverse(-1, 1, ltf)