Exemplo n.º 1
0
def run(nx):

    # the band width
    D = nx * grid_step.x

    # the mapping
    mapping = hichi.TightFocusingMapping(spherical_pulse.R0,
                                         spherical_pulse.pulselength, D)

    # the bounds of the band
    x_min = mapping.get_min_coord()
    x_max = mapping.get_max_coord()
    band_min_coords = hichi.Vector3d(x_min, min_coords.y, min_coords.z)
    band_max_coords = hichi.Vector3d(x_max, max_coords.y, max_coords.z)

    # the field size for the periodic space (that is the real field size)
    grid_size = hichi.Vector3d(nx, NY, NZ)

    # the creation of the computational field with the approciate mapping
    field = hichi.PSATDField(grid_size, band_min_coords, grid_step, time_step)
    field = field.apply_mapping(mapping)

    # the field initialisation
    spherical_pulse.set_field(field)

    # the correction of the start conditions using the Poisson's equation
    field.convert_fields_poisson_equation()

    # the performing one iteration of the field solver
    field.update_fields()

    return get_fields(field)
Exemplo n.º 2
0
 def get_field_plane_(self, coords, shape, plane, last_coordinate_value, func):
     field = np.zeros(shape=(shape[1], shape[0]))
     
     if plane == Plane.XOY:
         for i0 in range(shape[0]):
             for i1 in range(shape[1]):
                 coord = hichi.Vector3d(coords[0][i0], coords[1][i1], last_coordinate_value)
                 field[i1, i0] = func(self, coord) 
         return field
         
     elif plane == Plane.XOZ:
         for i0 in range(shape[0]):
             for i1 in range(shape[1]):
                 coord = hichi.Vector3d(coords[0][i0], last_coordinate_value, coords[1][i1])
                 field[i1, i0] = func(self, coord) 
         return field
         
     elif plane == Plane.YOZ:
         for i0 in range(shape[0]):
             for i1 in range(shape[1]):
                 coord = hichi.Vector3d(last_coordinate_value, coords[0][i0], coords[1][i1])
                 field[i1, i0] = func(self, coord) 
         return field
         
     return None
Exemplo n.º 3
0
def new_random_array(size) :
    p_array = hichi.ParticleArray()  #type = ELECTRON
    for i in range(size) :
        pos = hichi.Vector3d(1.2*i, 3.4*i, 5.6*i)
        mo = hichi.Vector3d(9.8*i, 7.6*i, 54.3*i)
        new_p = hichi.Particle(pos, mo, 0.5, hichi.ELECTRON)
        p_array.add(new_p)
    return p_array
Exemplo n.º 4
0
def get_fields(field):
    global x, N
    res = np.zeros(shape=(N, ))
    for ix in range(N):
        coord_xy = hichi.Vector3d(x[ix], 0.0, 0.0)
        res[ix] = field.get_E(coord_xy).y
    return res
Exemplo n.º 5
0
def get_fields(field):
    global x, y, N
    res = np.zeros(shape=(N, N))
    for ix in range(N):
        for iy in range(N):
            coord_xy = hichi.Vector3d(x[ix], y[iy], 0.0)
            res[N - iy - 1, ix] = field.get_E(coord_xy).norm()
    return res
Exemplo n.º 6
0
def gen_electron(gamma):
    """Electron creation.

    Args:
        gamma: energy

    Returns:
        electron
    """

    pos = pfc.Vector3d(0, 0, 0)

    momentum_x = gamma * pfc.LIGHT_VELOCITY * pfc.ELECTRON_MASS
    momentum = pfc.Vector3d(momentum_x, 0, 0)
    particle = pfc.Particle(pos, momentum, 1.0, pfc.ELECTRON)

    return particle
Exemplo n.º 7
0
def get_fields(field):
    x = np.arange(min_coords.x, max_coords.x,
                  (max_coords.x - min_coords.x) / NX_FULL)
    y = np.arange(min_coords.y, max_coords.y,
                  (max_coords.y - min_coords.y) / NY)
    res = np.zeros(shape=(NX_FULL, NY))
    for ix in range(NX_FULL):
        for iy in range(NY):
            coord_xy = hichi.Vector3d(x[ix], y[iy], 0.0)
            E = field.get_E(coord_xy)
            res[ix, iy] = E.norm()
    return res
Exemplo n.º 8
0
def get_fields():
    global field, x, y, Nx, Ny
    Ey = np.zeros(shape=(Ny, Nx))
    Bz = np.zeros(shape=(Ny, Nx))
    for ix in range(Nx):
        for iy in range(Ny):
            coord_xy = hichi.Vector3d(x[ix], y[iy], 0.0)
            E = field.get_E(coord_xy)
            Ey[iy, ix] = E.y
            B = field.get_B(coord_xy)
            Bz[iy, ix] = B.z
    return Ey, Bz
Exemplo n.º 9
0
 def get_field_axis_(self, coords, n_points, axis, last_coordinate_value, func):
     field = np.zeros(shape=(n_points))
     
     if axis == Axis.X:
         for i in range(n_points):
             coord = hichi.Vector3d(coords[i], last_coordinate_value[0], last_coordinate_value[1])
             field[i] = func(self, coord) 
         return field
         
     elif axis == Axis.Y:
         for i in range(n_points):
             coord = hichi.Vector3d(last_coordinate_value[0], coords[i], last_coordinate_value[1])
             field[i] = func(self, coord) 
         return field
         
     elif axis == Axis.Z:
         for i in range(n_points):
             coord = hichi.Vector3d(last_coordinate_value[0], last_coordinate_value[1], coords[i])
             field[i] = func(self, coord) 
         return field
         
     return None
Exemplo n.º 10
0
def create_field():
    d = (max_coords.x - min_coords.x) / grid_size.x
    grid_step = hichi.Vector3d(d, d, d)

    @cfunc("float64(float64,float64,float64)")
    def null_value(x, y, z):
        return 0.0

    @cfunc("float64(float64,float64,float64)")
    def field_value(x, y, z):
        return np.sin(0.4 * np.pi * x)

    field = hichi.PSATDField(grid_size, min_coords, grid_step, time_step)
    field.set_E(null_value.address, field_value.address, null_value.address)
    field.set_B(null_value.address, null_value.address, field_value.address)
    field.convert_fields_poisson_equation()

    return field
Exemplo n.º 11
0
def step(min_coords, max_coords, grid_size):
    """Calculating grid steps.

    Args:
        min_coords: minimum coordinate of the computational domain
        max_coords: maximum coordinate of the computational domain
        grid_size: computational domain size

    Returns:
        calculated step size
    """

    steps = pfc.Vector3d(1, 1, 1)

    steps.x = (max_coords.x - min_coords.x) / (grid_size.x)
    steps.y = (max_coords.y - min_coords.y) / (grid_size.y)
    steps.z = (max_coords.z - min_coords.z) / (grid_size.z)

    return steps
Exemplo n.º 12
0
def get_fields():
    global field, x, z, N
    Ex = np.zeros(shape=(N, N))
    Ey = np.zeros(shape=(N, N))
    Ez = np.zeros(shape=(N, N))
    Bx = np.zeros(shape=(N, N))
    By = np.zeros(shape=(N, N))
    Bz = np.zeros(shape=(N, N))
    for ix in range(N):
        for iy in range(N):
            coord_xz = hichi.Vector3d(x[ix], 0.0, z[iy])
            E = field.get_E(coord_xz)
            Ex[ix, iy] = E.x
            Ey[ix, iy] = E.y
            Ez[ix, iy] = E.z
            B = field.get_B(coord_xz)
            Bx[ix, iy] = B.x
            By[ix, iy] = B.y
            Bz[ix, iy] = B.z
    return Ex, Ey, Ez, Bx, By, Bz
Exemplo n.º 13
0
def valueB(x, y, z):
    B = hichi.Vector3d(-np.cos(z), 0, 0)
    return B
Exemplo n.º 14
0
def valueBx(x, y, z):
    Bx = -np.cos(z)
    return Bx


def valueBy(x, y, z):
    By = 0
    return By


def valueBz(x, y, z):
    Bz = 0
    return Bz


field_size = hichi.Vector3d(5, 10, 11)
min_coords = hichi.Vector3d(0.0, 1.0, 0.0)
max_coords = hichi.Vector3d(3.5, 7.0, 2 * np.pi)
field_step = (max_coords - min_coords) / field_size
time_step = 1e-16

field1 = hichi.YeeField(field_size, min_coords, field_step, time_step)
field2 = hichi.YeeField(field_size, min_coords, field_step, time_step)

field1.set_E(valueE)
field1.set_B(valueB)

field2.set_E(valueEx, valueEy, valueEz)
field2.set_B(valueBx, valueBy, valueBz)

#show
Exemplo n.º 15
0
import sys
sys.path.append("../../python_modules")
sys.path.append("../../bin")
import pyHiChi as hichi
from tight_focusing_fields import SphericalPulseC, SphericalPulsePython

# ------------------- initializing -------------------------------------

FACTOR = 0.5
NX_FULL = int(FACTOR * 320)  # size of field in full area
NY = int(FACTOR * 256)
NZ = int(FACTOR * 256)
NX_BAND = int(56 * FACTOR)  # size of field in the band
grid_size = hichi.Vector3d(NX_BAND, NY, NZ)  # real size of field

# creating of spherical pulse
spherical_pulse = SphericalPulsePython(f_number=0.3,
                                       R0=16,
                                       pulselength=2.0,
                                       edge_smoothing_angle=0.1)

time_step = 1.0 / hichi.c  # time step in CGS system of units
max_iter = 32  # number of iterations to compute

min_coords = hichi.Vector3d(-20, -20, -20)  # bounds of full area
max_coords = hichi.Vector3d(20, 20, 20)

D = 3.5 * spherical_pulse.pulselength  # band width

# to compute the task in the full area just set
# D = max_coords.x - min_coords.x
Exemplo n.º 16
0
import pyHiChi as hichi
import numpy as np
from tight_focusing_fields import SphericalPulseC

# the output directory
DIR_RESULT = "./"

# the creation of the spherical pulse
# f_number=0.3 (opening angle = 1 rad)
spherical_pulse = SphericalPulseC(f_number=0.3,
                                  R0=16,
                                  pulselength=2.0,
                                  edge_smoothing_angle=0.1)

# the computational area (coordinates of the opposite corners of the parallelepiped)
min_coords = hichi.Vector3d(-20, -20, -20)
max_coords = hichi.Vector3d(20, 20, 20)

# the field size for the entire original computational domain
FACTOR = 1.0  # the coefficient to adjust the field size
NX_FULL = int(320 * FACTOR)
NY = int(256 * FACTOR)
NZ = int(256 * FACTOR)
full_grid_size = hichi.Vector3d(NX_FULL, NY, NZ)

# the spatial step
grid_step = (max_coords - min_coords) / full_grid_size

# the time step which is equal to R0 in the universal system of units
time_step = spherical_pulse.R0 / hichi.c
def value_E_analytical(pos, t):
    E = hichi.Vector3d(10**-5, 10**-5, 10**-5)  #sin(pos.x)
    return E
def value_B_analytical(pos, t):
    B = hichi.Vector3d(0, 0, 0)
    return B
def value_E_analytical(pos, t):
    E = hichi.Vector3d(10**-5, 10**-5, 10**-5)  #sin(pos.x)
    return E


def value_B_analytical(pos, t):
    B = hichi.Vector3d(0, 0, 0)
    return B


t = 0
p_array = hichi.ParticleArray()
fields_array = []
for i in range(11):
    pos = hichi.Vector3d(1.2 * i, 3.4 * i, 5.6 * i)
    mo = hichi.Vector3d(i * 10, 0, 0)
    new_p = hichi.Particle(pos, mo, 0.5, hichi.ELECTRON)
    p_array.add(new_p)
    fields_array.append(
        hichi.FieldValue(value_E_analytical(pos, t),
                         value_B_analytical(pos, t)))

#Boris Pusher with RadiationReaction
dt = 0.001
pusher = hichi.BorisPusher()
rr = hichi.RadiationReaction()
for k in range(11):
    print(p_array[0].get_momentum())
    pusher(p_array, fields_array, dt)
    rr(p_array, fields_array, dt)
Exemplo n.º 20
0
import sys
sys.path.append("../bin/")
import pyHiChi as hichi

E = hichi.Vector3d(1.2, 2.2, 3.4)
B = hichi.Vector3d(34, 5.6, 7.8)

#FieldValue
f = hichi.Field(E, B)
print(f.get_E())
print(f.get_B())
f.set_E(B)
f.set_B(E)
print(f.get_E())
print(f.get_B())

f2 = hichi.Field(E.z, E.y, E.x, B.x, B.x, B.x) #Ex, Ey, Ez, Bx, By, Bz
print(f2.get_E())
print(f2.get_B())
Exemplo n.º 21
0
    Bx = np.sin(x - z)/np.sqrt(2) #for xz
    return Bx

def valueBy(x, y, z):
    By = 0  #for x or y or xz
    #By = np.sin(z) #for z
    return By

def valueBz(x, y, z):
    #Bz = 0  #for y or z
    #Bz = np.sin(x) #for x
    Bz = np.sin(x - z)/np.sqrt(2) #for xz
    return Bz


grid_size = hichi.Vector3d(20, 20, 20)
min_coords = hichi.Vector3d(0.0, 0.0, 0.0)
max_coords = hichi.Vector3d(2*np.pi, 2*np.pi, 2*np.pi)
grid_step = (max_coords - min_coords) / grid_size
time_step = 1e-14

field = hichi.YeeField(grid_size, min_coords, grid_step, time_step)
field.set_E(valueEx, valueEy, valueEz)
field.set_B(valueBx, valueBy, valueBz)

field.set_PML(0, 0, 0)
field.set_periodical_BC()

#show
import matplotlib.pyplot as plt
import matplotlib.animation as animation
Exemplo n.º 22
0
def value_E_analytical(pos, t):
    E = hichi.Vector3d(1, 0, 0)  #sin(pos.x)
    return E
Exemplo n.º 23
0
import sys
sys.path.append("../bin")
import pyHiChi as hichi
import numpy as np
from numba import cfunc, types, carray

min_coords = hichi.Vector3d(-10, -10, 0.0)
max_coords = hichi.Vector3d(10, 10, 0.0)

time_step = 0.05 / hichi.c
grid_size = hichi.Vector3d(128, 1, 1)

# ---------------- create original field ----------


def create_field():
    d = (max_coords.x - min_coords.x) / grid_size.x
    grid_step = hichi.Vector3d(d, d, d)

    @cfunc("float64(float64,float64,float64)")
    def null_value(x, y, z):
        return 0.0

    @cfunc("float64(float64,float64,float64)")
    def field_value(x, y, z):
        return np.sin(0.4 * np.pi * x)

    field = hichi.PSATDField(grid_size, min_coords, grid_step, time_step)
    field.set_E(null_value.address, field_value.address, null_value.address)
    field.set_B(null_value.address, null_value.address, field_value.address)
    field.convert_fields_poisson_equation()
Exemplo n.º 24
0
def valueE(x, y, z):
    E = hichi.Vector3d(0, np.cos(z), 0)  #sin(x)
    return E
Exemplo n.º 25
0
import sys
sys.path.append("../bin")
import pyHiChi as hichi
import numpy as np


def field_value(x, y, z):
    return np.exp(-x**2 - y**2 - z**2) * np.sin(5 * x)


def null_value(x, y, z):
    return 0.0


min_coords = hichi.Vector3d(-5, -5, -5)
max_coords = hichi.Vector3d(5, 5, 5)

grid_size = hichi.Vector3d(64, 64, 64)
grid_step = (max_coords - min_coords) / grid_size
time_step = 0.1 / hichi.c

field = hichi.PSATDField(grid_size, min_coords, grid_step, time_step)
field.set_E(null_value, field_value, null_value)
field.set_B(null_value, null_value, field_value)
field.convert_fields_poisson_equation()


# create the first transformed field
# rotation
def getRotatedField(field):
    mapping = hichi.RotationMapping(hichi.Axis.Z, -np.pi / 6)  # local object
Exemplo n.º 26
0
import sys
sys.path.append("../bin")
import pyHiChi as hichi
import numpy as np
from numba import cfunc


min_coords = hichi.Vector3d(-10, -10, 0.0)
max_coords = hichi.Vector3d(10, 10, 0.0)

time_step = 0.05/hichi.c

@cfunc("float64(float64,float64,float64)")  
def null_value(x, y, z):
    return 0.0
    
@cfunc("float64(float64,float64,float64,float64)")  
def null_value_t(x, y, z, t):
    return 0.0


# ------- create the first pulse (PSATD solver) ---------------

@cfunc("float64(float64,float64,float64)")
def field_value_1(x, y, z):
    return np.exp(-x**2-y**2)*np.sin(3*x)  # omega=3
    
grid_size_1 = hichi.Vector3d(128, 128, 1)
d1 = (max_coords.x - min_coords.x) / grid_size_1.x
grid_step_1 = hichi.Vector3d(d1, d1, d1)
Exemplo n.º 27
0
import sys
sys.path.append("../bin/")
import pyHiChi as hichi
import numpy as np

grid_size = hichi.Vector3d(5, 10, 11)
min_coords = hichi.Vector3d(0.0, 1.0, 0.0)
max_coords = hichi.Vector3d(3.5, 7.0, 2 * np.pi)


def value_Ex(x, y, z):
    Ex = np.sin(2 * np.pi / (max_coords.z - min_coords.z) * z)
    return Ex


def value_Ey(x, y, z):
    Ey = 0
    return Ey


def value_Ez(x, y, z):
    Ez = 0
    return Ez


def value_Bx(x, y, z):
    Bx = 0
    return Bx


def value_By(x, y, z):
Exemplo n.º 28
0
import sys
sys.path.append("../bin/")
import pyHiChi as hichi
import numpy as np

field_size = hichi.Vector3d(144, 30, 1)
pml_size = hichi.Vector3d(8, 0, 0)
min_coords = hichi.Vector3d(0.0, 0.0, 0.0)
max_coords = hichi.Vector3d(field_size.x * hichi.c, field_size.y * hichi.c, field_size.z * hichi.c)
    
field_step = (max_coords - min_coords) / field_size
time_step = 0.1

pml_left_end = min_coords.x + pml_size.x*field_step.x
pml_right_end = max_coords.x - pml_size.x*field_step.x
internal_width = pml_right_end - pml_left_end

def value_Ex(x, y, z):
    Ex = 0
    return Ex

def value_Ey(x, y, z):
    if (x < pml_left_end or x >= pml_right_end):
        Ey=0
    else: 
        Ey = np.sin(2*np.pi/internal_width*(x - pml_left_end))
    return Ey

def value_Ez(x, y, z):
    Ez = 0
    return Ez
Exemplo n.º 29
0
import sys
sys.path.append("../bin/")
import pyHiChi as hichi

# ensemble
ensemble = hichi.Ensemble()
for i in range(11):
    pos = hichi.Vector3d(1.2 * i, 1.3 * i, 1.6 * i)
    mo = hichi.Vector3d(1.1 * i, 1.4 * i, 1.5 * i)
    new_p = hichi.Particle(pos, mo, 0.5, hichi.ELECTRON)
    ensemble.add(new_p)
for i in range(10):
    pos = hichi.Vector3d(13 * i, 14 * i, 17 * i)
    mo = hichi.Vector3d(12 * i, 15 * i, 16 * i)
    new_p = hichi.Particle(pos, mo, 0.5, hichi.POSITRON)
    ensemble.add(new_p)
for i in range(13):
    pos = hichi.Vector3d(140 * i, 150 * i, 180 * i)
    mo = hichi.Vector3d(130 * i, 160 * i, 170 * i)
    new_p = hichi.Particle(pos, mo, 0.5, hichi.PROTON)
    ensemble.add(new_p)

print('Count Particles: ', ensemble.size())
print('Count Electron: ',
      ensemble['Electron'].size())  #use index 'Electron' or hichi.ELECTRON
print('Count Positron: ', ensemble['Positron'].size())  #same Electron
print('Count Proton: ', ensemble['Proton'].size())  #same Electron

print('Positions Electron: ')
for elem in ensemble[hichi.ELECTRON]:
    print(elem.get_position())
Exemplo n.º 30
0
import sys
sys.path.append("../bin/")
import pyHiChi as hichi

#vector3d
v = hichi.Vector3d(1.2, 2.2, 3.4)
print("volume: ", v.volume())
print("norm: ", v.norm())
print("norm2: ", v.norm2())
print("vector: ", str(v))
print(v)
print(v.x)
print(v.y)
print(v.z)
v2 = hichi.Vector3d()
print("v2: ", str(v2))
v2.x = 2.4
v2.y = 4.5
v2.z = 312
print("v2: ", str(v2))