# Path: sucemfem/Forms.py
# class NullForm(object):
# class GalerkinInteriorForms(object):
# class EMGalerkinInteriorForms(GalerkinInteriorForms):
# class CombineGalerkinForms(object):
#     def __add__(self, other):
#     def set_material_functions(self, material_functions):
#     def set_function_space(self, function_space):
#     def get_mass_form(self):
#     def get_stiffness_form(self):
#     def get_mass_form(self):
#     def get_stiffness_form(self):
#     def set_interior_forms(self, interior_forms):
#     def set_boundary_conditions(self, boundary_conditions):
#     def get_combined_forms(self):
#         V = self.function_space = function_space
# 
# Path: sucemfem/SystemMatrices.py
# class SystemMatrices(object):
#     MatrixClass = dolfin.PETScMatrix
# 
#     def set_matrix_class(self, matrix_class):
#         """Set matrix class to use for system matrix.
# 
#         Overrides the default value (dolfin.PETScMatrix) set in the
#         class definition
#         
#         """
#         self.MatrixClass = matrix_class
# 
#     def set_matrix_forms(self, matrix_forms):
#         """Set matrix_forms with a dict mapping matrix names to bilinear forms"""
#         self.matrix_forms = matrix_forms
# 
#     def set_boundary_conditions(self, boundary_conditions):
#         """Set boundary_conditions with instance of BoundaryConditions"""
#         self.boundary_conditions = boundary_conditions
# 
#     def calc_system_matrices(self):
#         """Calculate and return system matrices in a dict"""
#         system_matrices = dict()
#         for matname, form in self.matrix_forms.items():
#             mat = self.MatrixClass()
#             if isinstance(form, Forms.NullForm):
#                 mat = None
#             else:
#                 dolfin.assemble(form, tensor=mat)
#                 self.boundary_conditions.apply_essential(mat)
#             system_matrices[matname] = mat
# 
#         return system_matrices
# 
# Path: sucemfem/Consts.py
# Z0 = mu0*c0                              
# 
# Path: sucemfem/Utilities/Converters.py
# def dolfin_ublassparse_to_scipy_csr ( A, dtype=None, imagify=False ):
#     """
#     convert a DOLFIN uBLASSparseMatrix to a scipy.sparse.csr_matrix()
#     
#     @param A: a DOLFIN uBLASSparseMatrix
#     @param dtype: the numpy data type to use to store the matrix
#     @param imagify: multiply the original matrix data by 1j
#     """
#     import scipy.sparse
#     # get the sparse data from the input matrix
#     (row,col,data) = A.data()   # get sparse data
#     col = np.intc(col)
#     row = np.intc(row)
#     n = A.size(0)
#     if imagify: data = data*1j
#     A_sp = scipy.sparse.csr_matrix( (data,col,row), shape=(n,n), dtype=dtype)
#     
#     return A_sp


import numpy as N
import dolfin
from sucemfem import Forms 
from sucemfem import SystemMatrices
from sucemfem.Consts import c0, Z0
from sucemfem.Utilities.Converters import dolfin_ublassparse_to_scipy_csr
from EMProblem import EMProblem
    
    where n is a face normal and u,v are the trial and testing
    functions. All forms are assumed to be real valued. They real
    forms will be combined into a complex system matrix of the form

    A = S - k0**2*M + 1j*k_0*S_0

    where S, M are stiffness and mass matrices and k0 is the
    freespace wave-number
    """

    FormCombiner = CombineForms

    def set_sources(self, sources):
        self.sources = sources

    def set_frequency(self, frequency):
        """Set simulation frequency in Hz"""
        self.frequency = frequency

    def get_LHS_matrix(self):
        k0 = 2*N.pi*self.frequency/c0
        M = dolfin_ublassparse_to_scipy_csr(self.system_matrices['M'])
        S = dolfin_ublassparse_to_scipy_csr(self.system_matrices['S'])
        S_0 = dolfin_ublassparse_to_scipy_csr(self.system_matrices['S_0'])
        return S - k0**2*M + 1j*k0*S_0

    def get_RHS(self):
        RHS = N.zeros(self.get_global_dimension(), N.complex128)
        dofnos, contribs = self._get_RHS_contributions()

# Path: sucemfem/Forms.py
# class NullForm(object):
# class GalerkinInteriorForms(object):
# class EMGalerkinInteriorForms(GalerkinInteriorForms):
# class CombineGalerkinForms(object):
#     def __add__(self, other):
#     def set_material_functions(self, material_functions):
#     def set_function_space(self, function_space):
#     def get_mass_form(self):
#     def get_stiffness_form(self):
#     def get_mass_form(self):
#     def get_stiffness_form(self):
#     def set_interior_forms(self, interior_forms):
#     def set_boundary_conditions(self, boundary_conditions):
#     def get_combined_forms(self):
#         V = self.function_space = function_space
# 
# Path: sucemfem/SystemMatrices.py
# class SystemMatrices(object):
#     MatrixClass = dolfin.PETScMatrix
# 
#     def set_matrix_class(self, matrix_class):
#         """Set matrix class to use for system matrix.
# 
#         Overrides the default value (dolfin.PETScMatrix) set in the
#         class definition
#         
#         """
#         self.MatrixClass = matrix_class
# 
#     def set_matrix_forms(self, matrix_forms):
#         """Set matrix_forms with a dict mapping matrix names to bilinear forms"""
#         self.matrix_forms = matrix_forms
# 
#     def set_boundary_conditions(self, boundary_conditions):
#         """Set boundary_conditions with instance of BoundaryConditions"""
#         self.boundary_conditions = boundary_conditions
# 
#     def calc_system_matrices(self):
#         """Calculate and return system matrices in a dict"""
#         system_matrices = dict()
#         for matname, form in self.matrix_forms.items():
#             mat = self.MatrixClass()
#             if isinstance(form, Forms.NullForm):
#                 mat = None
#             else:
#                 dolfin.assemble(form, tensor=mat)
#                 self.boundary_conditions.apply_essential(mat)
#             system_matrices[matname] = mat
# 
#         return system_matrices
# 
# Path: sucemfem/Consts.py
# Z0 = mu0*c0                              
# 
# Path: sucemfem/Utilities/Converters.py
# def dolfin_ublassparse_to_scipy_csr ( A, dtype=None, imagify=False ):
#     """
#     convert a DOLFIN uBLASSparseMatrix to a scipy.sparse.csr_matrix()
#     
#     @param A: a DOLFIN uBLASSparseMatrix
#     @param dtype: the numpy data type to use to store the matrix
#     @param imagify: multiply the original matrix data by 1j
#     """
#     import scipy.sparse
#     # get the sparse data from the input matrix
#     (row,col,data) = A.data()   # get sparse data
#     col = np.intc(col)
#     row = np.intc(row)
#     n = A.size(0)
#     if imagify: data = data*1j
#     A_sp = scipy.sparse.csr_matrix( (data,col,row), shape=(n,n), dtype=dtype)
#     
#     return A_sp


# Path: sucemfem/ProblemConfigurations/EMDrivenProblem.py
import numpy as N
import dolfin
from sucemfem import Forms 
from sucemfem import SystemMatrices
from sucemfem.Consts import c0, Z0
from sucemfem.Utilities.Converters import dolfin_ublassparse_to_scipy_csr
from EMProblem import EMProblem

    
    where n is a face normal and u,v are the trial and testing
    functions. All forms are assumed to be real valued. They real
    forms will be combined into a complex system matrix of the form

    A = S - k0**2*M + 1j*k_0*S_0

    where S, M are stiffness and mass matrices and k0 is the
    freespace wave-number
    """

    FormCombiner = CombineForms

    def set_sources(self, sources):
        self.sources = sources

    def set_frequency(self, frequency):
        """Set simulation frequency in Hz"""
        self.frequency = frequency

    def get_LHS_matrix(self):
        k0 = 2*N.pi*self.frequency/c0
        M = dolfin_ublassparse_to_scipy_csr(self.system_matrices['M'])
        S = dolfin_ublassparse_to_scipy_csr(self.system_matrices['S'])
        S_0 = dolfin_ublassparse_to_scipy_csr(self.system_matrices['S_0'])
        return S - k0**2*M + 1j*k0*S_0

    def get_RHS(self):
        RHS = N.zeros(self.get_global_dimension(), N.complex128)
        dofnos, contribs = self._get_RHS_contributions()

        k0 = 2*N.pi*self.frequency/c0