# 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 openmodes
import os
import os.path as osp
import dill as pickle
import tempfile
import numpy as np
from openmodes.sources import PlaneWaveSource
"""
from __future__ import print_function




def test_pickling_references():
    """Test that references to parent objects survive the pickling and
    upickling process"""

    def save():
        name = "SRR"
        mesh_tol = 1e-3

        sim = openmodes.Simulation(name=name)
        mesh = sim.load_mesh(osp.join(openmodes.geometry_dir, name+'.geo'),
                             mesh_tol=mesh_tol)
        parent_part = sim.place_part()
        sim.place_part(mesh, parent=parent_part)
        sim.place_part(mesh, parent=parent_part, location=[10, 10, 10])
        sim.place_part(mesh, location=[10, 10, 10])

        parents_dict = {}
        for part in sim.parts.iter_all():
            print("Original part", part)
            if part.parent_ref is None:
                parents_dict[str(part.id)] = 'None'
            else:
                parents_dict[str(part.id)] = str(part.parent_ref().id)


# 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_vector.py
import openmodes
import os
import os.path as osp
import dill as pickle
import tempfile
import numpy as np
from openmodes.sources import PlaneWaveSource

"""
from __future__ import print_function




def test_pickling_references():
    """Test that references to parent objects survive the pickling and
    upickling process"""

    def save():
        name = "SRR"
        mesh_tol = 1e-3

        sim = openmodes.Simulation(name=name)
        mesh = sim.load_mesh(osp.join(openmodes.geometry_dir, name+'.geo'),
                             mesh_tol=mesh_tol)
        parent_part = sim.place_part()
        sim.place_part(mesh, parent=parent_part)
        sim.place_part(mesh, parent=parent_part, location=[10, 10, 10])
        sim.place_part(mesh, location=[10, 10, 10])

        parents_dict = {}
        for part in sim.parts.iter_all():
            print("Original part", part)
            if part.parent_ref is None:
                parents_dict[str(part.id)] = 'None'
            else:
                parents_dict[str(part.id)] = str(part.parent_ref().id)


        pw = PlaneWaveSource([0, 1, 0], [0, 0, 1])