# Path: sucemfem/Testing/Paths.py
# def get_module_path(modfile):
# def get_module_path_filename(filename, __file__):
# def get_module_path_file(filename, __file__, mode='r'):
# 
# Path: sucemfem/Utilities/MeshGenerators.py
# def get_centred_cube(domain_size, max_edge_len, centred_element_coordinate=None):
#     """ Generate a cube mesh centred arount [0,0,0]
# 
#     optionally translates mesh slightly such that
#     centred_element_coordinate is at the centre of an element.
#     """
#     domain_subdivisions = N.array(N.ceil(N.sqrt(2)*domain_size/max_edge_len), N.uint)
#     mesh = dolfin.UnitCube(*domain_subdivisions)
#     # Transform mesh to correct dimensions
#     mesh.coordinates()[:] *= domain_size
#     mesh.coordinates()[:] -= domain_size/2
#     if centred_element_coordinate is not None:
#         ## Translate mesh slightly so that source coordinate lies at
#         ## centroid of an element
#         centred_element_point = dolfin.Point(*centred_element_coordinate)
# #        source_elnos = mesh.all_intersected_entities(centred_element_point)
#         source_elnos = mesh.intersected_cells(centred_element_point)
#         closest_elno = source_elnos[(N.argmin(
#             [centred_element_point.distance(dolfin.Cell(mesh, i).midpoint())
#              for i in source_elnos]))]
#         centre_pt = dolfin.Cell(mesh, closest_elno).midpoint()
#         centre_coord = N.array([centre_pt.x(), centre_pt.y(), centre_pt.z()])
#         # The mesh intersect operator caches certain data
#         # structures. We need to clear them if the mesh coordinates
#         # are changed after calling any mesh intersection methods.
#         mesh.intersection_operator().clear()
#         mesh.coordinates()[:] -= centre_coord
#     return mesh
# 
# Path: sucemfem/PostProcessing/surface_ntff.py
# class SurfaceNTFFForms(object):
# class NTFF(object):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def get_N_form(self):
#     def get_L_form(self):
#     def assemble_N(self):
#     def assemble_L(self):
#     def set_parms(self, theta, phi, k0):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_frequency(self, frequency):
#     def calc_pt(self, theta_deg, phi_deg):
#         N = self.get_N_form()
#         L = self.get_L_form()
# 
# Path: sucemfem/PostProcessing/variational_ntff.py
# class TransformTestingExpression(object):
# class NTFF(object):
#     def __init__(self):
#     def set_parms(self, rhat, ahat, k0):
#     def _set_expr_parms(self, expr, rhat, k0, constfac):
#     def get_expression(self):
#     def __init__(self, function_space, testing_space=None):
#     def set_k0(self, k0):
#     def set_frequency(self, frequency):
#     def set_dofs(self, dofs):
#     def calc_pt(self, theta_deg, phi_deg):
#     def calc_pt_E_H(self, theta_deg, phi_deg):
#     def calc_ff_func(self, rhat, ahat):


import unittest
import pickle
import numpy as N
import dolfin
from sucemfem.Testing import Paths
from sucemfem.Utilities.MeshGenerators import get_centred_cube
from sucemfem.PostProcessing import surface_ntff
from sucemfem.PostProcessing import variational_ntff
        self.discretisation_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.discretisation_dofs = nf_input_data['x']
        self.frequency = nf_input_data['freq']
        
class test_surface_ntff(unittest.TestCase):
    test_data_file = 'data/reference_surface_ntff-2-0.149896229-0.0499654096667.pickle'
    rtol=1e-12
    atol=1e-7
    
    def setUp(self):
        desired_file = Paths.get_module_path_file(self.test_data_file, __file__)
        self.environment = NTFFEnvironment(desired_file)
        self.DUT = surface_ntff.NTFF(self.environment.discretisation_space)

    def test_ff(self):
        env = self.environment
        self.DUT.set_frequency(env.frequency)
        self.DUT.set_dofs(env.discretisation_dofs)
        actual_E_ff = [self.DUT.calc_pt(th_deg, ph_deg)
                       for th_deg, ph_deg in zip(env.theta_coords, env.phi_coords)]
        self.assertTrue(N.allclose(actual_E_ff, env.desired_E_ff,
                                   rtol=self.rtol, atol=self.atol))
        

class test_variational_ntff(test_surface_ntff):
    test_data_file = 'data/reference_variational_ntff-2-0.149896229-0.0499654096667.pickle'
    def setUp(self):
        desired_file = Paths.get_module_path_file(self.test_data_file, __file__)
        self.environment = NTFFEnvironment(desired_file)

# Path: sucemfem/Testing/Paths.py
# def get_module_path(modfile):
# def get_module_path_filename(filename, __file__):
# def get_module_path_file(filename, __file__, mode='r'):
# 
# Path: sucemfem/Utilities/MeshGenerators.py
# def get_centred_cube(domain_size, max_edge_len, centred_element_coordinate=None):
#     """ Generate a cube mesh centred arount [0,0,0]
# 
#     optionally translates mesh slightly such that
#     centred_element_coordinate is at the centre of an element.
#     """
#     domain_subdivisions = N.array(N.ceil(N.sqrt(2)*domain_size/max_edge_len), N.uint)
#     mesh = dolfin.UnitCube(*domain_subdivisions)
#     # Transform mesh to correct dimensions
#     mesh.coordinates()[:] *= domain_size
#     mesh.coordinates()[:] -= domain_size/2
#     if centred_element_coordinate is not None:
#         ## Translate mesh slightly so that source coordinate lies at
#         ## centroid of an element
#         centred_element_point = dolfin.Point(*centred_element_coordinate)
# #        source_elnos = mesh.all_intersected_entities(centred_element_point)
#         source_elnos = mesh.intersected_cells(centred_element_point)
#         closest_elno = source_elnos[(N.argmin(
#             [centred_element_point.distance(dolfin.Cell(mesh, i).midpoint())
#              for i in source_elnos]))]
#         centre_pt = dolfin.Cell(mesh, closest_elno).midpoint()
#         centre_coord = N.array([centre_pt.x(), centre_pt.y(), centre_pt.z()])
#         # The mesh intersect operator caches certain data
#         # structures. We need to clear them if the mesh coordinates
#         # are changed after calling any mesh intersection methods.
#         mesh.intersection_operator().clear()
#         mesh.coordinates()[:] -= centre_coord
#     return mesh
# 
# Path: sucemfem/PostProcessing/surface_ntff.py
# class SurfaceNTFFForms(object):
# class NTFF(object):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def get_N_form(self):
#     def get_L_form(self):
#     def assemble_N(self):
#     def assemble_L(self):
#     def set_parms(self, theta, phi, k0):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_frequency(self, frequency):
#     def calc_pt(self, theta_deg, phi_deg):
#         N = self.get_N_form()
#         L = self.get_L_form()
# 
# Path: sucemfem/PostProcessing/variational_ntff.py
# class TransformTestingExpression(object):
# class NTFF(object):
#     def __init__(self):
#     def set_parms(self, rhat, ahat, k0):
#     def _set_expr_parms(self, expr, rhat, k0, constfac):
#     def get_expression(self):
#     def __init__(self, function_space, testing_space=None):
#     def set_k0(self, k0):
#     def set_frequency(self, frequency):
#     def set_dofs(self, dofs):
#     def calc_pt(self, theta_deg, phi_deg):
#     def calc_pt_E_H(self, theta_deg, phi_deg):
#     def calc_ff_func(self, rhat, ahat):


# Path: sucemfem/PostProcessing/tests/test_ntff.py
import unittest
import pickle
import numpy as N
import dolfin
from sucemfem.Testing import Paths
from sucemfem.Utilities.MeshGenerators import get_centred_cube
from sucemfem.PostProcessing import surface_ntff
from sucemfem.PostProcessing import variational_ntff

        self.discretisation_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.discretisation_dofs = nf_input_data['x']
        self.frequency = nf_input_data['freq']
        
class test_surface_ntff(unittest.TestCase):
    test_data_file = 'data/reference_surface_ntff-2-0.149896229-0.0499654096667.pickle'
    rtol=1e-12
    atol=1e-7
    
    def setUp(self):
        desired_file = Paths.get_module_path_file(self.test_data_file, __file__)
        self.environment = NTFFEnvironment(desired_file)
        self.DUT = surface_ntff.NTFF(self.environment.discretisation_space)

    def test_ff(self):
        env = self.environment
        self.DUT.set_frequency(env.frequency)
        self.DUT.set_dofs(env.discretisation_dofs)
        actual_E_ff = [self.DUT.calc_pt(th_deg, ph_deg)
                       for th_deg, ph_deg in zip(env.theta_coords, env.phi_coords)]
        self.assertTrue(N.allclose(actual_E_ff, env.desired_E_ff,
                                   rtol=self.rtol, atol=self.atol))
        

class test_variational_ntff(test_surface_ntff):
    test_data_file = 'data/reference_variational_ntff-2-0.149896229-0.0499654096667.pickle'
    def setUp(self):
        desired_file = Paths.get_module_path_file(self.test_data_file, __file__)
        self.environment = NTFFEnvironment(desired_file)

        self.DUT = variational_ntff.NTFF(self.environment.discretisation_space)