Skip to content

Electronic Boltzmann made compatible with master #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
dd8bbf5
Changed output format to PETSc binary. No more HDF5 headaches.
May 24, 2019
b035d59
Working version of electronic boltzmann with cartesian coordinates. T…
gitansh95 May 27, 2019
86753c0
Added dump_aux_arrays function back
gitansh95 May 30, 2019
348354c
Cleaned up collision_operator.py
gitansh95 May 30, 2019
94f1b65
Fixed a naming bug
gitansh95 Jun 1, 2019
05657b2
main.py cleaned up
gitansh95 Jun 1, 2019
8b17938
Comments added to domain.py
gitansh95 Jun 1, 2019
6fb3d51
cartesian/polar p_space_grid switch added. TODO : Implement polar bcs
gitansh95 Jun 1, 2019
77f3c4e
Added f0_ee_constant_T() to collision_operator.py with auxiliary func…
gitansh95 Jun 1, 2019
8854ea8
cartesian/polar switch added to files in the example folder
gitansh95 Jun 1, 2019
507b734
Indentation fixed
gitansh95 Jun 1, 2019
9ced5e2
Polar option added to switch, working
gitansh95 Jun 2, 2019
ed9d4e9
Removed extra file \
gitansh95 Jun 2, 2019
b9d4279
Changed polar to polar2D, added multiplicative factor mu in compute_m…
gitansh95 Jun 3, 2019
bff6c0d
(1) True 1D3V works. Tested with
Jun 8, 2019
611a45e
post processing file seperated out
gitansh95 Jun 10, 2019
295de2c
(1) Faster matplotlib post processing
Jun 11, 2019
c8cf5e4
Updated fire_job_script.py
Jun 17, 2019
1a7ab6a
Prototype post processing script for f.
Jun 17, 2019
1436a65
Forgot to fix load.py to load .bin files. Done now.
Jun 18, 2019
8a43a2c
Added docstrings to src functions
gitansh95 Jun 18, 2019
3d81b50
Merged mchandra/binary_output
gitansh95 Jul 1, 2019
a186acd
Prelim check for T=0 formulation done
gitansh95 Aug 21, 2019
db72ead
Injecting j_x, j_y into params through RTA; Added switches to disable…
gitansh95 Aug 21, 2019
d15af88
Bugfix in collision_operator.py
gitansh95 Aug 28, 2019
de62a04
added distribution function script for binary output
gitansh95 Oct 9, 2019
a50c40f
Udated readme and domain for 1d polar
gitansh95 Oct 9, 2019
1244237
Merge branch 'master' of https://github.com/gitansh95/Bolt
gitansh95 Oct 9, 2019
fb9fa4b
dump_aux_array in binary IO, zero T momentum space plot script added
gitansh95 Oct 9, 2019
aeae0fd
Fixed discrepancy in momentum space plot script
gitansh95 Oct 10, 2019
f51fad5
Example height scaling folder with lanl submit file
Oct 31, 2019
1d7430f
Merge branch 'master' of https://github.com/gitansh95/Bolt
gitansh95 Oct 31, 2019
a90d095
Added Ben's auto restart code to main. Util files to be updated
gitansh95 Feb 6, 2020
c668187
Added utils required for latest_restart
gitansh95 Feb 6, 2020
3d35b4f
Added recursive batch script. fixed bugs --gitansh
gitansh95 Feb 7, 2020
64fa44e
Bug fixes in 1 x 5.25 example with tasu inf
gitansh95 Feb 17, 2020
0496b26
Fixed integral measure in the computation of density
gitansh95 Feb 17, 2020
efcab6d
Added dump time array, and other fixes to main
gitansh95 Mar 21, 2020
90e6eb4
Added Petsc_BinaryIO and petsc_conf
gitansh95 Mar 22, 2020
551e0b8
Bugfix, Cleaned up compute_moments
gitansh95 Mar 23, 2020
eee8865
Fix error in compute_moments
gitansh95 Mar 23, 2020
f4fb6cc
Added AC/DC switch in params
gitansh95 Mar 28, 2020
b86aa98
Example folder for PdCoO2
gitansh95 Mar 28, 2020
bf7f307
Improved readability of hexagon unit vector function
gitansh95 Mar 28, 2020
9cdbfee
Fixed hexagon ascii image
gitansh95 Mar 28, 2020
dbd9757
Reorder sectors in hexagon
gitansh95 Mar 28, 2020
f1b3303
Bugfix, normal to hexagon unit vector
gitansh95 Mar 28, 2020
667dfe7
Hexagonal band_energy
gitansh95 Mar 28, 2020
e7cbfcc
check updated to output a plot
gitansh95 Mar 28, 2020
dbbc9f1
Fixed indices issue, added test funcs, working version
gitansh95 Mar 29, 2020
2ffa4ca
Moved unit_vec and polygon functions to lib/utils
gitansh95 Mar 29, 2020
a648963
Moved polygon and unit vec functions to src/electronic_boltzmann/utils
gitansh95 Mar 30, 2020
69d1aec
Changes to clean up the code, improve conceptual understanding
gitansh95 Apr 7, 2020
6940bd4
Some bug fixes [WIP]
gitansh95 Apr 7, 2020
db88036
Bug fix, integral_over_p removed from attributes
gitansh95 Apr 7, 2020
6760f8e
Clean up collision op, bugfix in integral measure in initialize.py
gitansh95 Apr 8, 2020
93ffe31
cleaned up params
gitansh95 Apr 8, 2020
4f04436
moment defs now take p1, p2, p3, instead of p_x, p_y, p_z
gitansh95 Apr 9, 2020
3808d5b
Added test for compute moments. Not passing and to be cleaned.
gitansh95 Apr 13, 2020
e304093
Bug fix in params
gitansh95 Apr 23, 2020
69f6424
Reference folder for PdCoO2 height scaling runs.
gitansh95 Sep 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 165 additions & 15 deletions bolt/lib/nonlinear/boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ def apply_dirichlet_bcs_f(self, boundary):

return

def apply_mirror_bcs_f(self, boundary):
def apply_mirror_bcs_f_cartesian(self, boundary):
"""
Applies mirror boundary conditions along boundary specified
for the distribution function
for the distribution function when momentum space is on a cartesian grid

Parameters
----------
Expand Down Expand Up @@ -310,6 +310,108 @@ def apply_mirror_bcs_f(self, boundary):

return

def apply_mirror_bcs_f_polar2D(self, boundary):
"""
Applies mirror boundary conditions along boundary specified
for the distribution function when momentum space is on a 2D polar grid

Parameters
----------
boundary: str
Boundary along which the boundary condition is to be applied.
"""

N_g = self.N_ghost

if(boundary == 'left'):
# x-0-x-0-x-0-|-0-x-0-x-0-x-....
# 0 1 2 3 4 5
# For mirror boundary conditions:
# 0 = 5; 1 = 4; 2 = 3;
self.f[:, :, :N_g] = af.flip(self.f[:, :, N_g:2 * N_g], 2)

# For a particle moving with initial momentum at an angle \theta
# with the x-axis, a collision with the left boundary changes
# the angle of momentum after reflection to (pi - \theta)
# To do this, we split the array into to equal halves,
# flip each of the halves along the p_theta axis and then
# join the two flipped halves together.

N_theta = self.N_p2

tmp1 = self._convert_to_p_expanded(self.f)[:, :N_theta/2, :, :]
tmp1 = af.flip(tmp1, 1)
tmp2 = self._convert_to_p_expanded(self.f)[:, N_theta/2:, :, :]
tmp2 = af.flip(tmp2, 1)
tmp = af.join(1, tmp1, tmp2)

self.f[:, :, :N_g] = \
self._convert_to_q_expanded(tmp)[:, :, :N_g]

elif(boundary == 'right'):
# ...-x-0-x-0-x-0-|-0-x-0-x-0-x
# -6 -5 -4 -3 -2 -1
# For mirror boundary conditions:
# -1 = -6; -2 = -5; -3 = -4;
self.f[:, :, -N_g:] = af.flip(self.f[:, :, -2 * N_g:-N_g], 2)

# For a particle moving with initial momentum at an angle \theta
# with the x-axis, a collision with the right boundary changes
# the angle of momentum after reflection to (pi - \theta)
# To do this, we split the array into to equal halves,
# flip each of the halves along the p_theta axis and then
# join the two flipped halves together.

N_theta = self.N_p2

tmp1 = self._convert_to_p_expanded(self.f)[:, :N_theta/2, :, :]
tmp1 = af.flip(tmp1, 1)
tmp2 = self._convert_to_p_expanded(self.f)[:, N_theta/2:, :, :]
tmp2 = af.flip(tmp2, 1)
tmp = af.join(1, tmp1, tmp2)

self.f[:, :, -N_g:] = \
self._convert_to_q_expanded(tmp)[:, :, -N_g:]

elif(boundary == 'bottom'):
# x-0-x-0-x-0-|-0-x-0-x-0-x-....
# 0 1 2 3 4 5
# For mirror boundary conditions:
# 0 = 5; 1 = 4; 2 = 3;
self.f[:, :, :, :N_g] = af.flip(self.f[:, :, :, N_g:2 * N_g], 3)

# For a particle moving with initial momentum at an angle \theta
# with the x-axis, a collision with the bottom boundary changes
# the angle of momentum after reflection to (2*pi - \theta) = (-\theta)
# To do this we flip the axis that contains the variation in p_theta
self.f[:, :, :, :N_g] = \
self._convert_to_q_expanded(af.flip(self._convert_to_p_expanded(self.f),
1
)
)[:, :, :, :N_g]

elif(boundary == 'top'):
# ...-x-0-x-0-x-0-|-0-x-0-x-0-x
# -6 -5 -4 -3 -2 -1
# For mirror boundary conditions:
# -1 = -6; -2 = -5; -3 = -4;
self.f[:, :, :, -N_g:] = af.flip(self.f[:, :, :, -2 * N_g:-N_g], 3)

# For a particle moving with initial momentum at an angle \theta
# with the x-axis, a collision with the top boundary changes
# the angle of momentum after reflection to (2*pi - \theta) = (-\theta)
# To do this we flip the axis that contains the variation in p_theta
self.f[:, :, :, -N_g:] = \
self._convert_to_q_expanded(af.flip(self._convert_to_p_expanded(self.f),
1
)
)[:, :, :, -N_g:]

else:
raise Exception('Invalid choice for boundary')

return

def apply_bcs_f(self):
"""
Applies boundary conditions to the distribution function as specified by
Expand All @@ -332,14 +434,26 @@ def apply_bcs_f(self):
apply_dirichlet_bcs_f(self, 'left')

elif(self.boundary_conditions.in_q1_left == 'mirror'):
apply_mirror_bcs_f(self, 'left')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'left')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'left')
else :
raise NotImplementedError('Unsupported coordinate system in p_space')

elif(self.boundary_conditions.in_q1_left == 'mirror+dirichlet'):
apply_mirror_bcs_f(self, 'left')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'left')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'left')
else :
raise NotImplementedError('Unsupported coordinate system in p_space')
apply_dirichlet_bcs_f(self, 'left')

# This is automatically handled by the PETSc function globalToLocal()
elif(self.boundary_conditions.in_q1_left == 'periodic'):
elif( self.boundary_conditions.in_q1_left == 'periodic'
or self.boundary_conditions.in_q1_left == 'none' # no ghost zones (1D)
):
pass

elif(self.boundary_conditions.in_q1_left == 'shearing-box'):
Expand All @@ -355,14 +469,26 @@ def apply_bcs_f(self):
apply_dirichlet_bcs_f(self, 'right')

elif(self.boundary_conditions.in_q1_right == 'mirror'):
apply_mirror_bcs_f(self, 'right')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'right')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'right')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')

elif(self.boundary_conditions.in_q1_right == 'mirror+dirichlet'):
apply_mirror_bcs_f(self, 'right')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'right')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'right')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')
apply_dirichlet_bcs_f(self, 'right')

# This is automatically handled by the PETSc function globalToLocal()
elif(self.boundary_conditions.in_q1_right == 'periodic'):
elif( self.boundary_conditions.in_q1_right == 'periodic'
or self.boundary_conditions.in_q1_right == 'none' # no ghost zones (1D)
):
pass

elif(self.boundary_conditions.in_q1_right == 'shearing-box'):
Expand All @@ -378,14 +504,26 @@ def apply_bcs_f(self):
apply_dirichlet_bcs_f(self, 'bottom')

elif(self.boundary_conditions.in_q2_bottom == 'mirror'):
apply_mirror_bcs_f(self, 'bottom')
if (self.physical_system.params.p_space_grid =='cartesian'):
apply_mirror_bcs_f_cartesian(self, 'bottom')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'bottom')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')

elif(self.boundary_conditions.in_q2_bottom == 'mirror+dirichlet'):
apply_mirror_bcs_f(self, 'bottom')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'bottom')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'bottom')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')
apply_dirichlet_bcs_f(self, 'bottom')

# This is automatically handled by the PETSc function globalToLocal()
elif(self.boundary_conditions.in_q2_bottom == 'periodic'):
elif( self.boundary_conditions.in_q2_bottom == 'periodic'
or self.boundary_conditions.in_q2_bottom == 'none' # no ghost zones (1D)
):
pass

elif(self.boundary_conditions.in_q2_bottom == 'shearing-box'):
Expand All @@ -401,14 +539,26 @@ def apply_bcs_f(self):
apply_dirichlet_bcs_f(self, 'top')

elif(self.boundary_conditions.in_q2_top == 'mirror'):
apply_mirror_bcs_f(self, 'top')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'top')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'top')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')

elif(self.boundary_conditions.in_q2_top == 'mirror+dirichlet'):
apply_mirror_bcs_f(self, 'top')
if (self.physical_system.params.p_space_grid == 'cartesian'):
apply_mirror_bcs_f_cartesian(self, 'top')
elif (self.physical_system.params.p_space_grid == 'polar2D'):
apply_mirror_bcs_f_polar2D(self, 'top')
else:
raise NotImplementedError('Unsupported coordinate system in p_space')
apply_dirichlet_bcs_f(self, 'top')

# This is automatically handled by the PETSc function globalToLocal()
elif(self.boundary_conditions.in_q2_top == 'periodic'):
elif( self.boundary_conditions.in_q2_top == 'periodic'
or self.boundary_conditions.in_q2_top == 'none' # no ghost zones (1D)
):
pass

elif(self.boundary_conditions.in_q2_top == 'shearing-box'):
Expand Down
77 changes: 17 additions & 60 deletions bolt/lib/nonlinear/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-

import arrayfire as af
from bolt.lib.utils.af_petsc_conversion import af_to_petsc_glob_array
from bolt.lib.utils.af_petsc_conversion import petsc_local_array_to_af

def communicate_f(self):
"""
Expand All @@ -14,43 +16,19 @@ def communicate_f(self):
if(self.performance_test_flag == True):
tic = af.time()

# Obtaining start coordinates for the local zone
# Additionally, we also obtain the size of the local zone
((i_q1_start, i_q2_start), (N_q1_local, N_q2_local)) = self._da_f.getCorners()

N_g = self.N_ghost

# Assigning the local array only when Dirichlet
# boundary conditions are applied. This is needed since
# only inflowing characteristics are to be changed by
# the apply boundary conditions function.

if( self.boundary_conditions.in_q1_left == 'dirichlet'
or self.boundary_conditions.in_q1_right == 'dirichlet'
or self.boundary_conditions.in_q2_bottom == 'dirichlet'
or self.boundary_conditions.in_q2_top == 'dirichlet'
):
af.flat(self.f).to_ndarray(self._local_f_array)

# Global value is non-inclusive of the ghost-zones:
af.flat(self.f[:, :, N_g:-N_g, N_g:-N_g]).to_ndarray(self._glob_f_array)
# Transfer data from af.Array to PETSc.Vec
af_to_petsc_glob_array(self, self.f, self._glob_f_array)

# The following function takes care of interzonal communications
# Additionally, it also automatically applies periodic BCs when necessary
self._da_f.globalToLocal(self._glob_f, self._local_f)

# Converting back from PETSc.Vec to af.Array:
f_flattened = af.to_array(self._local_f_array)
self.f = af.moddims(f_flattened,
self.N_p1
* self.N_p2
* self.N_p3,
self.N_species,
N_q1_local + 2 * N_g,
N_q2_local + 2 * N_g
)

af.eval(self.f)
self.f = petsc_local_array_to_af(self,
self.N_p1*self.N_p2*self.N_p3,
self.N_species,
self._local_f_array
)

if(self.performance_test_flag == True):
af.sync()
Expand All @@ -59,7 +37,6 @@ def communicate_f(self):

return


def communicate_fields(self, on_fdtd_grid = False):
"""
Used in communicating the values at the boundary zones for each of
Expand All @@ -72,46 +49,26 @@ def communicate_fields(self, on_fdtd_grid = False):
if(self.performance_test_flag == True):
tic = af.time()

# Obtaining start coordinates for the local zone
# Additionally, we also obtain the size of the local zone
((i_q1_start, i_q2_start), (N_q1_local, N_q2_local)) = self._da_fields.getCorners()

N_g = self.N_g

# Assigning the values of the af.Array
# fields quantities to the PETSc.Vec:
if(on_fdtd_grid is True):
flattened_global_EM_fields_array = \
af.flat(self.yee_grid_EM_fields[:, :, N_g:-N_g, N_g:-N_g])
flattened_global_EM_fields_array.to_ndarray(self._glob_fields_array)

tmp_array = self.yee_grid_EM_fields
else:
flattened_global_EM_fields_array = \
af.flat(self.cell_centered_EM_fields[:, :, N_g:-N_g, N_g:-N_g])
flattened_global_EM_fields_array.to_ndarray(self._glob_fields_array)
tmp_array = self.cell_centered_EM_fields

af_to_petsc_glob_array(self, tmp_array, self._glob_fields_array)

# Takes care of boundary conditions and interzonal communications:
self._da_fields.globalToLocal(self._glob_fields, self._local_fields)

# Converting back to af.Array
if(on_fdtd_grid is True):

self.yee_grid_EM_fields = af.moddims(af.to_array(self._local_fields_array),
6, 1, N_q1_local + 2 * N_g,
N_q2_local + 2 * N_g
)

af.eval(self.yee_grid_EM_fields)
tmp_array = petsc_local_array_to_af(self, 6, 1, self._local_fields_array)

if(on_fdtd_grid is True):
self.yee_grid_EM_fields = tmp_array
else:

self.cell_centered_EM_fields = af.moddims(af.to_array(self._local_fields_array),
6, 1, N_q1_local + 2 * N_g,
N_q2_local + 2 * N_g
)
self.cell_centered_EM_fields = tmp_array

af.eval(self.cell_centered_EM_fields)

if(self.performance_test_flag == True):
af.sync()
toc = af.time()
Expand Down
4 changes: 3 additions & 1 deletion bolt/lib/nonlinear/compute_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def compute_moments(self, moment_name, f=None):

if(f is None):
f = self.f

#measure = (4./(2.*np.pi*self.physical_system.params.h_bar)**2) * self.dp3 * self.dp2 * self.dp1

moment = af.broadcast(getattr(self.physical_system.moments,
moment_name
), f, p1, p2, p3, self.dp3 * self.dp2 * self.dp1
), f, p1, p2, p3, self.physical_system.params.integral_measure
)

af.eval(moment)
Expand Down
Loading