# Path: openmodes/mesh/gmsh.py
# MIN_VERSION = (3, 0, 0)
# EDGE_TYPE = 1
# TRIANGLE_TYPE = 2
# POINT_TYPE = 15
# GMSH_ELEMENT_NODES = {EDGE_TYPE: 2, TRIANGLE_TYPE: 3, POINT_TYPE: 1}
# ELEMENT_NAME_MAPPING = {"edges": EDGE_TYPE, "triangles": TRIANGLE_TYPE,
#                         "points": POINT_TYPE}
# def mesh_geometry(filename, dirname, mesh_tol=None, binary=True,
#                   parameters={}):
# def read_nodes(file_handle):
# def check_format(file_handle):
# def read_elements(file_handle, wanted_element_types):
# def read_physical_names(file_handle):
# def read_mesh(filename, returned_elements=("edges", "triangles")):
# def read_mesh_meshio(filename):
# def check_installed():
# 
# Path: openmodes/constants.py

# 
# Path: openmodes/sources.py
# class PlaneWaveSource(object):
#     def __init__(self, e_inc, k_hat, material=FreeSpace, p_inc=None):
#         """Generate a plane wave with a given direction of propagation and
#         magnitude and direction of the electric field
# 
#         Parameters
#         ----------
#         e_inc: ndarray[3]
#             Incident field polarisation in free space
#         k_hat: ndarray[3], real
#             Incident wave vector in free space
#         n: real, optional
#             Refractive index of the background medium, defaults to free space
#         eta: real, optional
#             Characteristic impedance of background medium, defaults to free
#             space
#         p_inc: real, optional
#             If specified, the incident power will be scaled to ensure constant
#             power.
#         """
# 
#         self.e_inc = np.asarray(e_inc)
#         k_hat = np.asarray(k_hat)
#         self.k_hat = k_hat/np.sqrt(np.dot(k_hat, k_hat))
#         self.material = material
#         self.h_inc = np.cross(k_hat, self.e_inc)  # unscaled
#         self.p_inc = p_inc
# 
#     def electric_field(self, s, r):
#         """Calculate the electric field distribution at a given frequency
# 
#         Parameters
#         ----------
#         s : complex
#             Complex frequency at which to evaluate fields
#         r : ndarray, real
#             The locations at which to calculate the field. This array can have
#             an arbitrary number of dimensions. The last dimension must of size
#             3, corresponding to the three cartesian coordinates
# 
#         Returns
#         -------
#         E : ndarray, complex
#             An array with the same dimensions as r, giving the field at each
#             point
#         """
#         jk = self.k_hat*self.material.n(s)*s/c
# 
#         e_inc = self.e_inc
# 
#         if self.p_inc is not None:
#             # scale the incident power if requested
#             h_inc = self.h_inc/self.material.eta(s)
#             p_unscaled = np.sqrt(np.sum(np.cross(e_inc, h_inc.conj()).real)**2)
#             e_inc = e_inc*np.sqrt(self.p_inc/p_unscaled)
# 
#         # Dimensions are expanded so that r can have an arbitrary number
#         # of dimensions
#         return e_inc*np.exp(np.dot(r, -jk))[..., None]
# 
#     def magnetic_field(self, s, r):
#         """Calculate the magnetic field distribution at a given frequency
# 
#         Parameters
#         ----------
#         s : complex
#             Complex frequency at which to evaluate fields
#         r : ndarray, real
#             The locations at which to calculate the field. This array can have
#             an arbitrary number of dimensions. The last dimension must of size
#             3, corresponding to the three cartesian coordinates
# 
#         Returns
#         -------
#         E : ndarray, complex
#             An array with the same dimensions as r, giving the field at each
#             point
#         """
#         jk = self.k_hat*self.material.n(s)*s/c
# 
#         h_inc = self.h_inc/self.material.eta(s)
#         if self.p_inc is not None:
#             # scale the incident power if requested
#             h_inc = self.h_inc/self.material.eta(s)
#             p_unscaled = np.sqrt(np.sum(np.cross(self.e_inc, h_inc.conj()).real)**2)
#             h_inc = h_inc*np.sqrt(self.p_inc/p_unscaled)
# 
#         return h_inc*np.exp(np.dot(r, -jk))[..., None]


import numpy as np
import os.path as osp
import matplotlib.pyplot as plt
import openmodes
import helpers
from openmodes.mesh import gmsh
from openmodes.constants import c
from openmodes.sources import PlaneWaveSource
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 18 16:59:21 2016

@author: dap124
"""




tests_filename = __file__
input_dir = helpers.get_input_dir(tests_filename)
meshfile = osp.join(input_dir, 'sphere.msh')


def generate_mesh():
    "Generate a fixed mesh file to ensure consistent results of tests"

# Path: openmodes/mesh/gmsh.py
# MIN_VERSION = (3, 0, 0)
# EDGE_TYPE = 1
# TRIANGLE_TYPE = 2
# POINT_TYPE = 15
# GMSH_ELEMENT_NODES = {EDGE_TYPE: 2, TRIANGLE_TYPE: 3, POINT_TYPE: 1}
# ELEMENT_NAME_MAPPING = {"edges": EDGE_TYPE, "triangles": TRIANGLE_TYPE,
#                         "points": POINT_TYPE}
# def mesh_geometry(filename, dirname, mesh_tol=None, binary=True,
#                   parameters={}):
# def read_nodes(file_handle):
# def check_format(file_handle):
# def read_elements(file_handle, wanted_element_types):
# def read_physical_names(file_handle):
# def read_mesh(filename, returned_elements=("edges", "triangles")):
# def read_mesh_meshio(filename):
# def check_installed():
# 
# Path: openmodes/constants.py

# 
# Path: openmodes/sources.py
# class PlaneWaveSource(object):
#     def __init__(self, e_inc, k_hat, material=FreeSpace, p_inc=None):
#         """Generate a plane wave with a given direction of propagation and
#         magnitude and direction of the electric field
# 
#         Parameters
#         ----------
#         e_inc: ndarray[3]
#             Incident field polarisation in free space
#         k_hat: ndarray[3], real
#             Incident wave vector in free space
#         n: real, optional
#             Refractive index of the background medium, defaults to free space
#         eta: real, optional
#             Characteristic impedance of background medium, defaults to free
#             space
#         p_inc: real, optional
#             If specified, the incident power will be scaled to ensure constant
#             power.
#         """
# 
#         self.e_inc = np.asarray(e_inc)
#         k_hat = np.asarray(k_hat)
#         self.k_hat = k_hat/np.sqrt(np.dot(k_hat, k_hat))
#         self.material = material
#         self.h_inc = np.cross(k_hat, self.e_inc)  # unscaled
#         self.p_inc = p_inc
# 
#     def electric_field(self, s, r):
#         """Calculate the electric field distribution at a given frequency
# 
#         Parameters
#         ----------
#         s : complex
#             Complex frequency at which to evaluate fields
#         r : ndarray, real
#             The locations at which to calculate the field. This array can have
#             an arbitrary number of dimensions. The last dimension must of size
#             3, corresponding to the three cartesian coordinates
# 
#         Returns
#         -------
#         E : ndarray, complex
#             An array with the same dimensions as r, giving the field at each
#             point
#         """
#         jk = self.k_hat*self.material.n(s)*s/c
# 
#         e_inc = self.e_inc
# 
#         if self.p_inc is not None:
#             # scale the incident power if requested
#             h_inc = self.h_inc/self.material.eta(s)
#             p_unscaled = np.sqrt(np.sum(np.cross(e_inc, h_inc.conj()).real)**2)
#             e_inc = e_inc*np.sqrt(self.p_inc/p_unscaled)
# 
#         # Dimensions are expanded so that r can have an arbitrary number
#         # of dimensions
#         return e_inc*np.exp(np.dot(r, -jk))[..., None]
# 
#     def magnetic_field(self, s, r):
#         """Calculate the magnetic field distribution at a given frequency
# 
#         Parameters
#         ----------
#         s : complex
#             Complex frequency at which to evaluate fields
#         r : ndarray, real
#             The locations at which to calculate the field. This array can have
#             an arbitrary number of dimensions. The last dimension must of size
#             3, corresponding to the three cartesian coordinates
# 
#         Returns
#         -------
#         E : ndarray, complex
#             An array with the same dimensions as r, giving the field at each
#             point
#         """
#         jk = self.k_hat*self.material.n(s)*s/c
# 
#         h_inc = self.h_inc/self.material.eta(s)
#         if self.p_inc is not None:
#             # scale the incident power if requested
#             h_inc = self.h_inc/self.material.eta(s)
#             p_unscaled = np.sqrt(np.sum(np.cross(self.e_inc, h_inc.conj()).real)**2)
#             h_inc = h_inc*np.sqrt(self.p_inc/p_unscaled)
# 
#         return h_inc*np.exp(np.dot(r, -jk))[..., None]


# Path: test/test_multipoles.py
import numpy as np
import os.path as osp
import matplotlib.pyplot as plt
import openmodes
import helpers
from openmodes.mesh import gmsh
from openmodes.constants import c
from openmodes.sources import PlaneWaveSource

# -*- coding: utf-8 -*-
"""
Created on Fri Mar 18 16:59:21 2016

@author: dap124
"""




tests_filename = __file__
input_dir = helpers.get_input_dir(tests_filename)
meshfile = osp.join(input_dir, 'sphere.msh')


def generate_mesh():
    "Generate a fixed mesh file to ensure consistent results of tests"

    meshed_name = gmsh.mesh_geometry(osp.join(openmodes.geometry_dir, 'sphere.geo'),