# 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/Consts.py
# Z0 = mu0*c0                              
# 
# Path: sucemfem/PostProcessing/power_flux.py
# class SurfaceFlux(object):
# class VariationalSurfaceFlux(object):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_k0(self,k0):
#     def _get_mur_function(self):
#     def set_mur_function(self, mur_function):
#     def _get_form(self):
#     def calc_flux(self):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_k0(self,k0):
#     def set_epsr_function(self, epsr_function):
#     def set_mur_function(self, mur_function):
#     def calc_flux(self):
#     def _get_mur_function(self):
#     def _get_epsr_function(self):


import unittest
import os
import pickle
import numpy as np
import dolfin
from sucemfem.Testing import Paths
from sucemfem.Consts import c0
from sucemfem.PostProcessing import power_flux
        data_file = open(os.path.join(data_dir, self.test_data_file))
        data = self.data = pickle.load(data_file)
        self.mesh = dolfin.Mesh(os.path.join(data_dir, data['meshfile']))
        self.discretisation_order = data['order']
        self.function_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.k0 = 2*np.pi*data['freq']/c0
        self.DUT = power_flux.SurfaceFlux(self.function_space)

    def test_calc_flux(self):
        self.DUT.set_k0(self.k0)
        self.DUT.set_dofs(self.data['x'])
        # Desired result as calculated with gitrev 953c7063b02547f5233a29ced884ba5af0fd0fe3
        self.assertAlmostEqual(self.DUT.calc_flux(), 26.3586862457)



class test_SurfaceFlux(unittest.TestCase):
    data_dir = 'data'
    test_data_file = 'power_flux_reference_dofs_f-1000000000.000000_o-2_s-0.074948_l-0.100000_h-0.166667.pickle'
    
    def setUp(self):
        data_dir = Paths.get_module_path_filename(self.data_dir,  __file__)
        data_file = open(os.path.join(data_dir, self.test_data_file))
        data = self.data = pickle.load(data_file)
        self.mesh = dolfin.Mesh(os.path.join(data_dir, data['meshfile']))
        self.discretisation_order = data['order']
        self.function_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.k0 = 2*np.pi*data['freq']/c0

# 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/Consts.py
# Z0 = mu0*c0                              
# 
# Path: sucemfem/PostProcessing/power_flux.py
# class SurfaceFlux(object):
# class VariationalSurfaceFlux(object):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_k0(self,k0):
#     def _get_mur_function(self):
#     def set_mur_function(self, mur_function):
#     def _get_form(self):
#     def calc_flux(self):
#     def __init__(self, function_space):
#     def set_dofs(self, dofs):
#     def set_k0(self,k0):
#     def set_epsr_function(self, epsr_function):
#     def set_mur_function(self, mur_function):
#     def calc_flux(self):
#     def _get_mur_function(self):
#     def _get_epsr_function(self):


# Path: sucemfem/PostProcessing/tests/test_power_flux.py
import unittest
import os
import pickle
import numpy as np
import dolfin
from sucemfem.Testing import Paths
from sucemfem.Consts import c0
from sucemfem.PostProcessing import power_flux

        data_file = open(os.path.join(data_dir, self.test_data_file))
        data = self.data = pickle.load(data_file)
        self.mesh = dolfin.Mesh(os.path.join(data_dir, data['meshfile']))
        self.discretisation_order = data['order']
        self.function_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.k0 = 2*np.pi*data['freq']/c0
        self.DUT = power_flux.SurfaceFlux(self.function_space)

    def test_calc_flux(self):
        self.DUT.set_k0(self.k0)
        self.DUT.set_dofs(self.data['x'])
        # Desired result as calculated with gitrev 953c7063b02547f5233a29ced884ba5af0fd0fe3
        self.assertAlmostEqual(self.DUT.calc_flux(), 26.3586862457)



class test_SurfaceFlux(unittest.TestCase):
    data_dir = 'data'
    test_data_file = 'power_flux_reference_dofs_f-1000000000.000000_o-2_s-0.074948_l-0.100000_h-0.166667.pickle'
    
    def setUp(self):
        data_dir = Paths.get_module_path_filename(self.data_dir,  __file__)
        data_file = open(os.path.join(data_dir, self.test_data_file))
        data = self.data = pickle.load(data_file)
        self.mesh = dolfin.Mesh(os.path.join(data_dir, data['meshfile']))
        self.discretisation_order = data['order']
        self.function_space = dolfin.FunctionSpace(
            self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order)
        self.k0 = 2*np.pi*data['freq']/c0

        self.DUT = power_flux.VariationalSurfaceFlux(self.function_space)