def test_read_parameters_filename_default(self):
        params = FFD(n_control_points=[3, 2, 2])
        params.read_parameters()
        outfilename = 'parameters.prm'
        outfilename_expected = 'tests/test_datasets/parameters_default.prm'

        self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
        os.remove(outfilename)
 def test_read_parameters_array_mu_z(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     array_mu_z_exact = np.array(
         [0., -0.2, 0., -0.45622985, 0., 0., 0., 0., -1.22, 0., -1.,
          0.]).reshape((3, 2, 2))
     np.testing.assert_array_almost_equal(params.array_mu_z,
                                          array_mu_z_exact)
 def test_read_parameters_rotation_matrix(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     rotation_matrix_exact = np.array(
         [[0.98162718, 0., 0.190809], [0.06619844, 0.93788893, -0.34056147],
          [-0.17895765, 0.34693565, 0.92065727]])
     np.testing.assert_array_almost_equal(params.rotation_matrix,
                                          rotation_matrix_exact)
 def test_reflect_wrong_symmetry_plane_3(self):
     params = FFD([3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     params.array_mu_z = np.array(
         [0.2, 0., 0., 0., 0.5, 0., 0., 0., 1., 0., 0.3, 0.1]).reshape(
             (3, 2, 2))
     with self.assertRaises(RuntimeError):
         params.reflect(axis=2)
 def test_ffd_sphere_mod(self):
     ffd = FFD()
     ffd.read_parameters(
         filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
     mesh_points = np.load('tests/test_datasets/meshpoints_sphere_orig.npy')
     mesh_points_ref = np.load(
         'tests/test_datasets/meshpoints_sphere_mod.npy')
     mesh_points_test = ffd(mesh_points)
     np.testing.assert_array_almost_equal(mesh_points_test, mesh_points_ref)
    def test_write_parameters(self):
        params = FFD(n_control_points=[3, 2, 2])
        params.read_parameters('tests/test_datasets/parameters_sphere.prm')

        outfilename = 'tests/test_datasets/parameters_sphere_out.prm'
        outfilename_expected = 'tests/test_datasets/parameters_sphere_out_true.prm'
        params.write_parameters(outfilename)
        self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
        os.remove(outfilename)
    def test_read_parameters_position_vertex_0(self):
        params = FFD(n_control_points=[3, 2, 2])
        params.read_parameters('tests/test_datasets/parameters_sphere.prm')
        position_vertices = np.array(
            [[-20.0, -55.0, -45.0], [24.17322326, -52.02107006, -53.05309404],
             [-20., 29.41000412, -13.77579136],
             [-2.82719042, -85.65053198, 37.85915459]])

        np.testing.assert_array_almost_equal(params.position_vertices,
                                             position_vertices)
 def test_reflect_axis_2(self):
     params = FFD([3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     params.array_mu_z = np.array(
         [0.2, 0., 0., 0., 0.5, 0., 0., 0., 0., 0., 0., 0.]).reshape(
             (3, 2, 2))
     params.reflect(axis=2)
     array_mu_z_exact = np.array([
         0.2, 0., -0.2, 0., 0., 0., 0.5, 0., -0.5, 0., 0., -0., 0., 0., -0.,
         0., 0., -0.
     ]).reshape((3, 2, 3))
     np.testing.assert_array_almost_equal(params.array_mu_z,
                                          array_mu_z_exact)
 def test_read_parameters_filename_default_existance(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters()
     outfilename = 'parameters.prm'
     assert os.path.isfile(outfilename)
     os.remove(outfilename)
 def test_read_parameters_failing_filename_type(self):
     params = FFD(n_control_points=[3, 2, 2])
     with self.assertRaises(TypeError):
         params.read_parameters(3)
 def test_read_parameters_position_vertex_0_origin(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     np.testing.assert_array_almost_equal(params.position_vertices[0],
                                          params.box_origin)
 def test_read_parameters_rot_angle_x(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     assert np.array_equal(params.rot_angle, [20.3, 11.0, 0.])
 def test_read_parameters_box_origin(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     box_origin_exact = np.array([-20.0, -55.0, -45.0])
     np.testing.assert_array_almost_equal(params.box_origin,
                                          box_origin_exact)
 def test_read_parameters_box_length_x(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     assert np.array_equal(params.box_length, [45.0, 90.0, 90.0])
 def test_read_parameters_n_control_points(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     assert np.array_equal(params.n_control_points, [3, 2, 2])
 def test_read_parameters_conversion_unit(self):
     params = FFD(n_control_points=[3, 2, 2])
     params.read_parameters('tests/test_datasets/parameters_sphere.prm')
     assert params.conversion_unit == 1.