Exemplo n.º 1
0
def run_cases(q_dim, p_dim, charge_electron, tau):

    params.charge[0] = charge_electron
    params.tau = tau

    # Running the setup for all resolutions:
    for i in range(N.size):
        af.device_gc()
        domain.N_q1 = int(N[i])

        if (q_dim == 2):
            domain.N_q2 = int(N[i])
            params.k_q2 = 4 * np.pi

        if (p_dim >= 2):

            domain.N_p2 = 32
            domain.p2_start = -10
            domain.p2_end = 10

        if (p_dim == 3):

            domain.N_p3 = 32
            domain.p3_start = -10
            domain.p3_end = 10

        if (charge_electron != 0):
            domain.N_p1 = int(N[i])

            if (p_dim >= 2):
                domain.N_p2 = int(N[i])

            if (p_dim == 3):
                domain.N_p3 = int(N[i])

        params.p_dim = p_dim

        # Defining the physical system to be solved:
        system = physical_system(domain, boundary_conditions, params,
                                 initialize, advection_terms,
                                 collision_operator.BGK, moments)

        nls = nonlinear_solver(system)

        # Timestep as set by the CFL condition:
        dt = params.N_cfl * min(nls.dq1, nls.dq2) \
                          / max(domain.p1_end, domain.p2_end, domain.p3_end)

        time_array = np.arange(dt, params.t_final + dt, dt)
        # Checking that time array doesn't cross final time:
        if (time_array[-1] > params.t_final):
            time_array = np.delete(time_array, -1)

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)
            if (time_index % 25 == 0):
                nls.f = lowpass_filter(nls.f)

        nls.dump_distribution_function('dump_files/nlsf_' + str(N[i]))
Exemplo n.º 2
0
def check_error(params):
    error = np.zeros(N.size)

    for i in range(N.size):
        domain.N_p1 = int(N[i])
        domain.N_p2 = int(N[i])
        domain.N_p3 = int(N[i])

        # Defining the physical system to be solved:
        system = physical_system(domain, boundary_conditions, params,
                                 initialize, advection_terms,
                                 collision_operator.BGK, moments)

        # Declaring a linear system object which will evolve the defined physical system:
        nls = nonlinear_solver(system)

        # Time parameters:
        dt = 0.0001 * 32 / nls.N_p1
        t_final = 0.2

        time_array = np.arange(dt, t_final + dt, dt)

        if (time_array[-1] > t_final):
            time_array = np.delete(time_array, -1)

        # Finding final resting point of the blob:
        E1 = nls.fields_solver.cell_centered_EM_fields[0]
        E2 = nls.fields_solver.cell_centered_EM_fields[1]
        E3 = nls.fields_solver.cell_centered_EM_fields[2]

        B1 = nls.fields_solver.cell_centered_EM_fields[3]
        B2 = nls.fields_solver.cell_centered_EM_fields[4]
        B3 = nls.fields_solver.cell_centered_EM_fields[5]

        sol = odeint(dp_dt,
                     np.array([0, 0, 0]),
                     time_array,
                     args=(af.mean(E1), af.mean(E2), af.mean(E3), af.mean(B1),
                           af.mean(B2), af.mean(B3), af.sum(params.charge[0]),
                           af.sum(params.mass[0])),
                     atol=1e-12,
                     rtol=1e-12)

        f_reference = af.broadcast(initialize.initialize_f, nls.q1_center,
                                   nls.q2_center, nls.p1_center - sol[-1, 0],
                                   nls.p2_center - sol[-1, 1],
                                   nls.p3_center - sol[-1, 2], params)

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)

        error[i] = af.mean(af.abs(nls.f - f_reference))

    return (error)
Exemplo n.º 3
0
def check_error(params):

    error = np.zeros(N.size)

    for i in range(N.size):
        af.device_gc()

        domain.N_q1 = int(N[i])
        domain.N_p1 = int(N[i])
 
        # Defining the physical system to be solved:
        system = physical_system(domain,
                                 boundary_conditions,
                                 params,
                                 initialize,
                                 advection_terms,
                                 collision_operator.BGK,
                                 moments
                                )

        # Declaring a linear system object which will evolve the defined physical system:
        nls = nonlinear_solver(system)
        N_g = nls.N_ghost

        # Time parameters:
        dt      = 0.001 * 32/nls.N_q1
        t_final = 0.1

        time_array  = np.arange(dt, t_final + dt, dt)
        f_reference = af.broadcast(initialize.initialize_f,
                                   af.broadcast(lambda a, b:a+b, nls.q1_center, - nls.p1_center * t_final), 
                                   nls.q2_center, nls.p1_center, nls.p2_center, nls.p3_center, params
                                  )

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)

        error[i] = af.mean(af.abs(  nls.f[:, :, N_g:-N_g, N_g:-N_g] 
                                  - f_reference[:, :, N_g:-N_g, N_g:-N_g]
                                 )
                          )

    return(error)
Exemplo n.º 4
0
def check_error(params):
    error = np.zeros(N.size)

    for i in range(N.size):
        domain.N_p1 = int(N[i])
        # Defining the physical system to be solved:
        system = physical_system(domain, boundary_conditions, params,
                                 initialize, advection_terms,
                                 collision_operator.BGK, moments)

        # Declaring a linear system object which will evolve the defined physical system:
        nls = nonlinear_solver(system)

        # Time parameters:
        dt = 0.01 * 32 / nls.N_p1
        t_final = 0.2

        time_array = np.arange(dt, t_final + dt, dt)

        (A_p1, A_p2,
         A_p3) = af.broadcast(nls._A_p, nls.f, 0, nls.q1_center, nls.q2_center,
                              nls.p1_center, nls.p2_center, nls.p3_center,
                              nls.fields_solver, nls.physical_system.params)

        f_analytic = af.broadcast(initialize.initialize_f, nls.q1_center,
                                  nls.q2_center,
                                  add(nls.p1_center, -A_p1 * t_final),
                                  add(nls.p2_center, -A_p2 * t_final),
                                  nls.p3_center, nls.physical_system.params)

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)

        error[i] = af.mean(af.abs(nls.f - f_analytic))

    return (error)
Exemplo n.º 5
0
import input_files.domain as domain
import input_files.boundary_conditions as boundary_conditions
import input_files.params as params
import input_files.initialize as initialize

import bolt.src.nonrelativistic_boltzmann.advection_terms as advection_terms
import bolt.src.nonrelativistic_boltzmann.collision_operator as collision_operator
import bolt.src.nonrelativistic_boltzmann.moments as moments

# Defining the physical system to be solved:
system = physical_system(domain, boundary_conditions, params, initialize,
                         advection_terms, collision_operator.BGK, moments)

N_g_q = system.N_ghost_q

nls = nonlinear_solver(system)

# Timestep as set by the CFL condition:
dt = params.N_cfl * min(nls.dq1, nls.dq2) \
                  / max(domain.p1_end, domain.p2_end, domain.p3_end)

time_array = np.arange(0, params.t_final + dt, dt)

# Checking that time array doesn't cross final time:
if (time_array[-1] > params.t_final):
    time_array = np.delete(time_array, -1)

# Storing data at time t = 0:
n_nls = np.array(nls.compute_moments('density'))
nls.dump_moments('dump/0000')
Exemplo n.º 6
0
params_1.current_time = time_elapsed_1 = 0.0
params_1.time_step = time_step_1 = 0

dt_2 = params_2.dt
t_final_2 = params_2.t_final
params_2.current_time = time_elapsed_2 = 0.0
params_2.time_step = time_step_2 = 0

dump_counter = 0
dump_time_array = []

N_g_1 = domain_1.N_ghost
N_g_2 = domain_2.N_ghost

# Declaring a nonlinear system object which will evolve the defined physical system:
nls_1 = nonlinear_solver(system_1)
params_1.rank = nls_1._comm.rank

nls_2 = nonlinear_solver(system_2)
params_2.rank = nls_2._comm.rank

params.f_1 = nls_1.f
params.f_2 = nls_2.f

if (params_1.restart):
    nls_1.load_distribution_function(params_1_.restart_file)
if (params_2.restart):
    nls_2.load_distribution_function(params_2_.restart_file)

# Checking that the file writing intervals are greater than dt:
assert (params_1.dt_dump_f > dt_1)
Exemplo n.º 7
0
import arrayfire as af
import numpy as np
import pylab as pl

from bolt.lib.physical_system import physical_system
from bolt.lib.nonlinear.nonlinear_solver import nonlinear_solver

from bolt.lib.nonlinear.tests.input_files import domain
from bolt.lib.nonlinear.tests.input_files import boundary_conditions
from bolt.lib.nonlinear.tests.input_files import params
from bolt.lib.nonlinear.tests.input_files import initialize

import bolt.src.nonrelativistic_boltzmann.advection_terms as advection_terms
import bolt.src.nonrelativistic_boltzmann.collision_operator as collision_operator
import bolt.src.nonrelativistic_boltzmann.moments as moments

# Defining the physical system to be solved:
system = physical_system(domain, boundary_conditions, params, initialize,
                         advection_terms, collision_operator.BGK, moments)

# Defining a nonlinear solver object:
nls = nonlinear_solver(system, True)
nls.strang_timestep(0.001)
af.sync()

for i in range(100):
    nls.strang_timestep(0.001)

af.sync()
nls.print_performance_timings(101)
Exemplo n.º 8
0
def check_error(params):
    error = np.zeros(N.size)

    for i in range(N.size):
        domain.N_p1 = int(N[i])
        domain.N_p2 = int(N[i])
        # Defining the physical system to be solved:
        system = physical_system(domain,
                                 boundary_conditions,
                                 params,
                                 initialize,
                                 advection_terms,
                                 collision_operator.BGK,
                                 moments
                                )

        nls = nonlinear_solver(system)

        # Time parameters:
        dt = 0.001 * 32/nls.N_p1
        
        # First, we check when the blob returns to (0, 0)
        E1 = nls.fields_solver.cell_centered_EM_fields[0]
        E2 = nls.fields_solver.cell_centered_EM_fields[1]
        B3 = nls.fields_solver.cell_centered_EM_fields[5]

        sol = odeint(dp_dt, np.array([0, 0]), time_array_odeint,
                     args = (af.mean(E1), af.mean(E2), af.mean(B3), 
                             af.sum(params.charge[0]),
                             af.sum(params.mass[0])
                            ),
                     atol = 1e-12, rtol = 1e-12
                    ) 

        dist_from_origin = abs(sol[:, 0]) + abs(sol[:, 1])
        
        # The time when the distance is minimum apart from the start is the time
        # when the blob returns back to the center:
        # However, this is an approximate solution. To get a more accurate solution, 
        # we provide this guess to our root finder scipy.optimize.root
        t_final_approx = time_array_odeint[np.argmin(dist_from_origin[1:])]
        t_final        = root(residual, t_final_approx, 
                              args = (af.mean(E1), af.mean(E2), af.mean(B3), 
                                      params.charge[0],
                                      params.mass[0]
                                     ),
                              method = 'lm', tol = 1e-12
                             ).x

        time_array  = np.arange(dt, float("{0:.3f}".format(t_final[0])) + dt, dt)

        if(time_array[-1]>t_final):
            time_array = np.delete(time_array, -1)
    
        f_reference = nls.f

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)

        error[i] = af.mean(af.abs(  nls.f
                                  - f_reference
                                 )
                          )

    return(error)
Exemplo n.º 9
0
def run_cases(q_dim, p_dim, charge_electron, tau):

    params.charge[0] = charge_electron
    params.tau       = tau

    # Running the setup for all resolutions:
    for i in range(N.size):
        af.device_gc()
        domain.N_q1 = int(N[i])

        if(q_dim == 2):
            domain.N_q2 = int(N[i])
            params.k_q2 = 4 * np.pi

        if(p_dim == 2):
         
            domain.N_p2     = 32
            domain.p2_start = -10
            domain.p2_end   = 10

        if(p_dim == 3):

            domain.N_p3     = 32
            domain.p3_start = -10
            domain.p3_end   = 10


        if(charge_electron != 0):
            domain.N_p1 = int(N[i])

            if(p_dim == 2):
                domain.N_p2 = int(N[i])

            if(p_dim == 3):
                domain.N_p3 = int(N[i])

        params.p_dim = p_dim
        dt           = 1e-3/(2**i)

        # Defining the physical system to be solved:
        system = physical_system(domain,
                                 boundary_conditions,
                                 params,
                                 initialize,
                                 advection_terms,
                                 collision_operator.BGK,
                                 moments
                                )
        
        # linearized_system = physical_system(domain,
        #                                     boundary_conditions,
        #                                     params,
        #                                     initialize,
        #                                     advection_terms,
        #                                     collision_operator.linearized_BGK,
        #                                     moments
        #                                    )

        # Declaring a linear system object which will 
        # evolve the defined physical system:
        nls = nonlinear_solver(system)
        ls  = linear_solver(system)

        time_array = np.arange(dt, t_final + dt, dt)

        for time_index, t0 in enumerate(time_array):
            nls.strang_timestep(dt)
            ls.RK4_timestep(dt)

        nls.dump_distribution_function('dump_files/nlsf_' + str(N[i]))
        ls.dump_distribution_function('dump_files/lsf_' + str(N[i]))