Skip to content
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

Add oblique angle #57

Open
wants to merge 157 commits into
base: Pulsar_Development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
52ced49
adding pulsar as a compiler option
RevathiJambunathan Jan 14, 2020
eef1a1e
Adding pulsar input and reading pulsar parameters using Don's PR
RevathiJambunathan Jan 15, 2020
2d58835
adding input file for pulsar
RevathiJambunathan Jan 15, 2020
428ee01
Merge branch 'dev' of https://github.com/ECP-WarpX/WarpX into InjectP…
RevathiJambunathan Jan 15, 2020
f689dd5
whitespace style fix
RevathiJambunathan Jan 15, 2020
e2bf5fd
moved vis from pulsar file to tools
RevathiJambunathan Jan 15, 2020
86b84a9
scaling notebook to detemine inputs for pulsar
RevathiJambunathan Jan 15, 2020
51e5f4b
removing unwanted file
RevathiJambunathan Jan 15, 2020
8b827cd
Merge branch 'dev' of https://github.com/ECP-WarpX/WarpX into PulsarB…
RevathiJambunathan Jan 15, 2020
25a1b5f
Merge branch 'ParticlesEBParser' of https://github.com/RevathiJambuna…
RevathiJambunathan Jan 15, 2020
ac92eae
Merge branch 'ParticlesEBParser' of https://github.com/RevathiJambuna…
RevathiJambunathan Jan 17, 2020
4d9cfcc
Merge branch 'dev' of https://github.com/ECP-WarpX/WarpX into InjectP…
RevathiJambunathan Jan 17, 2020
3c9502b
added external E and B fields and the appropriate input parameters
RevathiJambunathan Jan 17, 2020
eba1352
EOL whitespace
RevathiJambunathan Jan 17, 2020
f55260e
Merge branch 'dev' of https://github.com/ECP-WarpX/WarpX into PulsarB…
RevathiJambunathan Jan 17, 2020
e1a07c0
Merge branch 'PulsarBranch' of https://github.com/RevathiJambunathan/…
RevathiJambunathan Jan 17, 2020
e3e1dc6
seeting up bounds for pulsar surface
RevathiJambunathan Jan 17, 2020
68f6ead
pushing changes for comparison
RevathiJambunathan Jan 18, 2020
387bcc5
particles injected below surface, dipole magnetic field inside and ou…
RevathiJambunathan Jan 21, 2020
36552f2
making changes suggested in the review
RevathiJambunathan Jan 22, 2020
ac7d1ab
merging with upstream dev
RevathiJambunathan Jan 22, 2020
52b327d
merging with dev and fixing conflicts
RevathiJambunathan Jan 22, 2020
bf3e2bd
Merge branch 'PulsarBranch' of https://github.com/RevathiJambunathan/…
RevathiJambunathan Jan 22, 2020
1dc685f
removing unwanted commented out lines
RevathiJambunathan Jan 22, 2020
9f134a0
removing EOL whitespace
RevathiJambunathan Jan 22, 2020
ec1409d
Merge pull request #3 from RevathiJambunathan/pulsarinput_field
RevathiJambunathan Jan 22, 2020
56db49f
add particles based on analytical surface charge density
RevathiJambunathan Jan 22, 2020
90e62dd
using local Er and Er_cor to compute particle introduction
RevathiJambunathan Jan 23, 2020
e8a638a
fixing particle injection with local Er that includes Er_external
RevathiJambunathan Jan 23, 2020
7bebeb7
changes to pulsar
RevathiJambunathan Jan 23, 2020
10e559d
michel and li efields inside and outside star. Particle injection rho_GJ
RevathiJambunathan Jan 23, 2020
82b4a30
fixing conlficts with PulsarBranch
RevathiJambunathan Jan 23, 2020
4c0b091
cleaning
RevathiJambunathan Jan 23, 2020
6ecd29a
adding input parameters to toggle rho gj scaling, ninjection, maxden
RevathiJambunathan Jan 24, 2020
a3f323e
removing unwanted insidePulsarBound function
RevathiJambunathan Jan 24, 2020
9fd33e4
Merge pull request #5 from RevathiJambunathan/InjectParticlesInSpheroid
dwillcox Jan 24, 2020
f0b5799
Damp electric fields internal to the pulsar when compiling with PULSA…
dwillcox Jan 21, 2020
33336da
Turn on inputs parameter to damp internal E-field for the pulsar setup.
dwillcox Jan 21, 2020
ce5f3af
Separate out cartesian ijk -> spherical radius into a utility functio…
dwillcox Jan 21, 2020
283074d
Rename damping function, damp in domain [0, R_star-dR_star]. Normaliz…
dwillcox Jan 22, 2020
bd5be63
Add PulsarParm::Omega(t) function that returns omega(t) depending on …
dwillcox Jan 23, 2020
7449928
Add comments to distinguish different kinds of momentum injections. A…
dwillcox Jan 24, 2020
52dc42b
Change form of damping function to tanh(damping_scale * (r/R_star-1))…
dwillcox Jan 24, 2020
4aec790
Add scale factor for damping internal E-field to the inputs file.
dwillcox Jan 24, 2020
8a28a66
Add a python script for making plots and a gif from a set of plotfiles.
dwillcox Jan 24, 2020
400f9d9
Remove PulsarEBField from PulsarParameters.cpp after a rebase mistake.
dwillcox Jan 24, 2020
d8503ab
Default the momentum initialization to 0.
dwillcox Jan 24, 2020
2bc3060
Swap tabs for spaces.
dwillcox Jan 24, 2020
fe5940c
Ran the style commands suggested by Travis CI to remove trailing whit…
dwillcox Jan 24, 2020
4dc6357
Rename pulsar analysis scripts to make the WarpX style checker happy.
dwillcox Jan 24, 2020
f643f66
Merge pull request #6 from dwillcox/damp_Efield_rebased
RevathiJambunathan Jan 24, 2020
2dd3d74
fixing an error in rho_GJ calculation
RevathiJambunathan Jan 24, 2020
b56e67f
merged upstream master branch and fixed conflicts
RevathiJambunathan Mar 10, 2020
9f3763f
Upsating GetPosition() based on recent changes in master branch
RevathiJambunathan Mar 10, 2020
82ad2fa
Merge pull request #7 from RevathiJambunathan/MergingMasterIntoPulsar…
dwillcox Mar 13, 2020
bad249e
Damp electric fields internal to the pulsar when compiling with PULSA…
dwillcox Jan 21, 2020
36dcd2f
Separate out cartesian ijk -> spherical radius into a utility functio…
dwillcox Jan 21, 2020
84dd785
Rename damping function, damp in domain [0, R_star-dR_star]. Normaliz…
dwillcox Jan 22, 2020
a10599b
Add PulsarParm::Omega(t) function that returns omega(t) depending on …
dwillcox Jan 23, 2020
d58f6f5
Change form of damping function to tanh(damping_scale * (r/R_star-1))…
dwillcox Jan 24, 2020
6f8fe5a
Add a python script for making plots and a gif from a set of plotfiles.
dwillcox Jan 24, 2020
8d02eec
Undo line removal.
dwillcox Mar 13, 2020
2adeb79
Undo removal of newline.
dwillcox Mar 13, 2020
5344fae
Merge pull request #4 from dwillcox/damp_internal_Efield
RevathiJambunathan Mar 27, 2020
52d9fed
fixing conflicts after merging with WarpX/development
RevathiJambunathan Jun 25, 2020
46c2856
fix compilation error
RevathiJambunathan Jun 25, 2020
810c2f8
some more compilation error
RevathiJambunathan Jun 25, 2020
5d6e216
Calling External E and B for pulsar from GetExternal functions
RevathiJambunathan Jun 25, 2020
9dad457
a few fixes in the getexternalEB and addplasma to ensure test works
RevathiJambunathan Jul 9, 2020
ac15f36
include staggering
RevathiJambunathan Jul 9, 2020
6a48c94
damp b field and include staggering. fix compilation errors
RevathiJambunathan Jul 9, 2020
6c14fc7
merging with development and fixing conflicts in AddPlasma
RevathiJambunathan Jul 15, 2020
fe53bd6
Merge branch 'development' of https://github.com/ECP-WarpX/WarpX into…
RevathiJambunathan Jul 15, 2020
9946626
fixed Ecell
RevathiJambunathan Jul 23, 2020
70a497a
Merge branch 'development' of https://github.com/ECP-WarpX/WarpX into…
RevathiJambunathan Jul 23, 2020
f0f4de0
removing particles if inside R_Star
RevathiJambunathan Jul 23, 2020
2756eb8
recent input file
RevathiJambunathan Jul 23, 2020
c26d473
eol fix
RevathiJambunathan Jul 23, 2020
8154234
fix merge conflict after merge with development
RevathiJambunathan Jul 30, 2020
ca2a20c
fix conflict
RevathiJambunathan Oct 16, 2020
2579dd7
Add functor for pulsar particle injection
RevathiJambunathan Aug 13, 2020
c1a2c37
fix eol
RevathiJambunathan Aug 13, 2020
cba43b2
Add Functor file
RevathiJambunathan Aug 13, 2020
0f8ab60
fix eol
RevathiJambunathan Aug 13, 2020
f722ea2
add updated input file
RevathiJambunathan Aug 13, 2020
28f554a
push external-EB-on-grid to debug. particle injection off.
RevathiJambunathan Sep 3, 2020
185bfee
inject fixed number of particles when injection is on
RevathiJambunathan Sep 3, 2020
76ce2ca
adding file with external EM field on grid
RevathiJambunathan Sep 3, 2020
d1fc5b0
fix indent
RevathiJambunathan Sep 3, 2020
9ab0419
fixing for loop to include last dimension
RevathiJambunathan Sep 3, 2020
d8e4b2f
add notebook with scaling
RevathiJambunathan Sep 4, 2020
c1ca960
uncomment DampFields for E and B
RevathiJambunathan Sep 7, 2020
cdd4244
fixing E-corotating insdie. E-quad outside. B-dipole everywhere
RevathiJambunathan Sep 8, 2020
82059a3
gather external pulsar fields, add num_ppc particles, damp Maxwell f…
RevathiJambunathan Sep 9, 2020
0e56778
include particles only outside r_star
RevathiJambunathan Sep 10, 2020
74b4efb
fix EOL
RevathiJambunathan Sep 10, 2020
7c05c16
particle injection inner ring and particle removal in same location
RevathiJambunathan Sep 11, 2020
4894d01
damp EB fields inside R_Star, intro and remove part inside R_star
RevathiJambunathan Sep 20, 2020
f6d871f
fix typo in cell cell z coordinate
RevathiJambunathan Oct 15, 2020
4e43c60
add fraction of particles through pcounts of cell.
RevathiJambunathan Oct 16, 2020
cf6e020
Revert "add fraction of particles through pcounts of cell."
RevathiJambunathan Oct 16, 2020
3def6ef
ensuring that fractional particle injection is uniform in cell
RevathiJambunathan Oct 16, 2020
23eb044
we dont need the p.id=-1 to remove particles 1-fractional part injection
RevathiJambunathan Oct 16, 2020
3fb3b79
updated input file
RevathiJambunathan Oct 16, 2020
3fefb74
terminate ifdef PULSAR
RevathiJambunathan Oct 17, 2020
3e48944
remove unnecessary call to add external EB on EB Multifab. we call it…
RevathiJambunathan Oct 17, 2020
a327fb3
clean commented out lines in GetExternalFields
RevathiJambunathan Oct 17, 2020
33ed47d
remove commented out code and old unused PulsarEField and PulsarBField
RevathiJambunathan Oct 17, 2020
a117c43
remove unused function init
RevathiJambunathan Oct 17, 2020
f8a6e90
removing AddPulsarPlasma functor which is not used
RevathiJambunathan Oct 22, 2020
dde5752
remove commented out code and calls to add plasma functor
RevathiJambunathan Oct 22, 2020
e091bdc
add obliquity for pulsar, Chi, to be parsed in degree.
RevathiJambunathan Oct 22, 2020
f38cfdb
add Chi option in input file
RevathiJambunathan Oct 22, 2020
9156e60
add spaces between operators
RevathiJambunathan Oct 22, 2020
d857b33
fix conflict with WarpX
RevathiJambunathan Oct 28, 2020
cd04809
Add functor for pulsar particle injection
RevathiJambunathan Aug 13, 2020
f4d3e0e
fix eol
RevathiJambunathan Aug 13, 2020
c6a0acb
Add Functor file
RevathiJambunathan Aug 13, 2020
c045d2e
fix eol
RevathiJambunathan Aug 13, 2020
d5aa0ae
add updated input file
RevathiJambunathan Aug 13, 2020
d45dc0a
push external-EB-on-grid to debug. particle injection off.
RevathiJambunathan Sep 3, 2020
c82b83c
inject fixed number of particles when injection is on
RevathiJambunathan Sep 3, 2020
b447a5c
adding file with external EM field on grid
RevathiJambunathan Sep 3, 2020
fea5a5b
fix indent
RevathiJambunathan Sep 3, 2020
9c3784c
fixing for loop to include last dimension
RevathiJambunathan Sep 3, 2020
a606725
add notebook with scaling
RevathiJambunathan Sep 4, 2020
8be9907
uncomment DampFields for E and B
RevathiJambunathan Sep 7, 2020
b89a289
fixing E-corotating insdie. E-quad outside. B-dipole everywhere
RevathiJambunathan Sep 8, 2020
a2f145e
gather external pulsar fields, add num_ppc particles, damp Maxwell f…
RevathiJambunathan Sep 9, 2020
9fbcd4e
include particles only outside r_star
RevathiJambunathan Sep 10, 2020
062b0d6
fix EOL
RevathiJambunathan Sep 10, 2020
b847c30
particle injection inner ring and particle removal in same location
RevathiJambunathan Sep 11, 2020
609cc5e
damp EB fields inside R_Star, intro and remove part inside R_star
RevathiJambunathan Sep 20, 2020
8bd533e
fix typo in cell cell z coordinate
RevathiJambunathan Oct 15, 2020
f3b81e2
add fraction of particles through pcounts of cell.
RevathiJambunathan Oct 16, 2020
e52d67b
Revert "add fraction of particles through pcounts of cell."
RevathiJambunathan Oct 16, 2020
7608182
ensuring that fractional particle injection is uniform in cell
RevathiJambunathan Oct 16, 2020
b544279
we dont need the p.id=-1 to remove particles 1-fractional part injection
RevathiJambunathan Oct 16, 2020
cd821dc
updated input file
RevathiJambunathan Oct 16, 2020
203ebfb
terminate ifdef PULSAR
RevathiJambunathan Oct 17, 2020
dc8ed54
remove unnecessary call to add external EB on EB Multifab. we call it…
RevathiJambunathan Oct 17, 2020
446ddeb
clean commented out lines in GetExternalFields
RevathiJambunathan Oct 17, 2020
7bb1e45
remove commented out code and old unused PulsarEField and PulsarBField
RevathiJambunathan Oct 17, 2020
7b7495b
remove unused function init
RevathiJambunathan Oct 17, 2020
75d5d86
removing AddPulsarPlasma functor which is not used
RevathiJambunathan Oct 22, 2020
8e784b3
remove commented out code and calls to add plasma functor
RevathiJambunathan Oct 22, 2020
b2e28b9
adding missing ;
RevathiJambunathan Oct 28, 2020
cead130
FillBoundary for EB after dampingEB
Oct 30, 2020
600db62
using gpuarray for staggering used to damp EB fields
RevathiJambunathan Nov 1, 2020
211ae8d
default values in fieldgather doShapeN for problo, probhi, and cur_time
RevathiJambunathan Nov 5, 2020
6f28e8a
empty array
RevathiJambunathan Nov 5, 2020
ee46f94
pass by reference
RevathiJambunathan Nov 5, 2020
3b0f7e1
merge with addExternalEB
RevathiJambunathan Nov 11, 2020
25ff086
fix conflict
RevathiJambunathan Nov 11, 2020
d41103a
Adding cosChi to monopole term in Er
RevathiJambunathan Nov 14, 2020
f1d909a
corotating Efield inside Rstar where particles are introduced. This w…
RevathiJambunathan Nov 16, 2020
df17ffc
fix conflict and add cmake for pulsar
Dec 11, 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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ endif()
target_compile_definitions(WarpX PRIVATE
WARPX_PARSER_DEPTH=${WarpX_PARSER_DEPTH})

target_compile_definitions(WarpX PRIVATE PULSAR)



# Warnings ####################################################################
#
Expand Down
1,392 changes: 1,392 additions & 0 deletions Examples/Physics_applications/pulsar/Pulsar_scale_RstarPhysical.ipynb

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions Examples/Physics_applications/pulsar/analysis_pulsar_vis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import yt
import os
import glob
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-f", "--plotfile", type=str, help="Path to single input plotfile to visualize.")
parser.add_argument("-d", "--dir", type=str, help="Path to input plotfile directory to visualize.")

args = parser.parse_args()

def visualize(plt, annotate_particles=True):
ds = yt.load(plt)
sl = yt.SlicePlot(ds, 0, 'Ez', aspect=1) # Create a sliceplot object
if annotate_particles:
sl.annotate_particles(width=(2.e3, 'm'),ptype="plasma_p",col='b',p_size=5.0)
sl.annotate_particles(width=(2.e3, 'm'),ptype="plasma_e",col='r',p_size=5.0)
sl.annotate_streamlines("Ey", "Ez", plot_args={"color": "black"})
sl.annotate_grids() # Show grids
sl.annotate_sphere([90000.0, 90000.0, 90000.0], radius=12000.0,
circle_args={'color':'white', 'linewidth':2})
out_name = os.path.join(os.path.dirname(plt), "pulsar_{}.png".format(os.path.basename(plt)))
sl.save(out_name)

if __name__ == "__main__":
yt.funcs.mylog.setLevel(50)
if args.dir:
failed = []
plotfiles = glob.glob(os.path.join(args.dir, "plt" + "[0-9]"*5))
for pf in plotfiles:
try:
visualize(pf)
except:
# plotfile 0 may not have particles, so turn off annotations if we first failed
try:
visualize(pf, annotate_particles=False)
except:
failed.append(pf)
pass

if len(failed) > 0:
print("Visualization failed for the following plotfiles:")
for fp in failed:
print(fp)
else:
print("No plots failed, creating a gif ...")
input_files = os.path.join(args.dir, "*.png")
output_gif = os.path.join(args.dir, "pulsar.gif")
os.system("convert -delay 20 -loop 0 {} {}".format(input_files, output_gif))

elif args.plotfile:
visualize(args.plotfile)
else:
print("Supply either -f or -d options for visualization. Use the -h option to see help.")
745 changes: 745 additions & 0 deletions Examples/Physics_applications/pulsar/analysis_pulsar_viz.ipynb

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions Examples/Physics_applications/pulsar/inputs.corotating.3d.PM
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Description:
#
# This inputs file sets up a NS with these properties:
# - E = -(omega*R)[cross]B inside the NS
# - external E and B outside the star
#
# See the "Pulsar Setup" section at the end for the options
#
# This initializes the electrons and positrons with a corotating momentum function.
# Based on the pulsar_type = "active" or "dead", particles are injected continuously or
# until rho_GJ is reached

#################################
####### GENERAL PARAMETERS ######
#################################
max_step = 50000
amr.n_cell = 128 128 128
amr.max_grid_size = 128
amr.blocking_factor = 128
amr.max_level = 0
geometry.coord_sys = 0 # 0: Cartesian
geometry.is_periodic = 0 0 0 # Is periodic?
geometry.prob_lo = 0.0 0.0 0.0
geometry.prob_hi = 180000 180000 180000

#################################
############ NUMERICS ###########
#################################
#algo.maxwell_fdtd_solver = yee
warpx.verbose = 1
warpx.do_dive_cleaning = 0
warpx.use_filter = 1
warpx.cfl = .2
warpx.do_pml = 1
my_constants.pi = 3.141592653589793
my_constants.dens = 5.544e6
my_constants.xc = 90000
my_constants.yc = 90000
my_constants.zc = 90000
my_constants.r_star = 12032
my_constants.omega = 6245.676
my_constants.c = 299792458.
my_constants.B_star = 8.0323e-6 # magnetic field of NS (T)
my_constants.dR = 1400
my_constants.to = 2.e-4
interpolation.nox = 3
interpolation.noy = 3
interpolation.noz = 3

#################################
############ PLASMA #############
#################################
particles.nspecies = 2
particles.species_names = plasma_e plasma_p

plasma_e.charge = -q_e
plasma_e.mass = m_e
plasma_e.injection_style = "NUniformPerCell"
plasma_e.profile = parse_density_function
plasma_e.density_function(x,y,z) = "( ((( (z-zc)*(z-zc) + (y-yc)*(y-yc) + (x-xc)*(x-xc) )^(0.5))<=(r_star)) * ((( (z-zc)*(z-zc) + (y-yc)*(y-yc) + (x-xc)*(x-xc) )^(0.5))>=(r_star-dR)) )*dens"
plasma_e.num_particles_per_cell_each_dim = 4 4 4
plasma_e.momentum_distribution_type = parse_momentum_function

## Inject stationary pairs
plasma_e.momentum_function_ux(x,y,z) = "0.0"
plasma_e.momentum_function_uy(x,y,z) = "0.0"
## uz is always 0 for the injection methods above
plasma_e.momentum_function_uz(x,y,z) = "0.0"

plasma_e.do_continuous_injection = 0
plasma_e.density_min = 1E0

plasma_p.charge = q_e
plasma_p.mass = m_e
plasma_p.injection_style = "NUniformPerCell"
plasma_p.profile = parse_density_function
plasma_p.density_function(x,y,z) = "( ((( (z-zc)*(z-zc) + (y-yc)*(y-yc) + (x-xc)*(x-xc) )^(0.5))<=(r_star)) * ((( (z-zc)*(z-zc) + (y-yc)*(y-yc) + (x-xc)*(x-xc) )^(0.5))>=(r_star-dR)) )*dens"
plasma_p.num_particles_per_cell_each_dim = 4 4 4
plasma_p.momentum_distribution_type = parse_momentum_function

## Inject stationary pairs
plasma_p.momentum_function_ux(x,y,z) = "0.0"
plasma_p.momentum_function_uy(x,y,z) = "0.0"
## uz is always 0 for the injection methods above
plasma_p.momentum_function_uz(x,y,z) = "0.0"

plasma_p.do_continuous_injection = 0
plasma_p.density_min = 1E0

diagnostics.diags_names = plt chk
plt.diag_type = Full
plt.period = 20
plt.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho divE

chk.format = checkpoint
chk.diag_type = Full
chk.period = 1000

#################################
######### PULSAR SETUP ##########
#################################
pulsar.pulsarType = "dead" # [dead/active]: sets particle injection type
pulsar.omega_star = 6245.676 # angular velocity of NS (rad/s)
pulsar.ramp_omega_time = 0.0 # time over which to ramp up NS angular velocity (s)
# if ramp_omega_time < 0, omega = omega_star for any t
# consistency requires ramp_omega_time = my_constants.to
pulsar.center_star = 90000 90000 90000
pulsar.R_star = 12032 # radius of NS (m)
pulsar.B_star = 8.0323e-6 # magnetic field of NS (T)
pulsar.dR = 1400 # thickness on the surface of the pulsar
pulsar.Chi = 45
# consistency requires dR = my_constants.dR
pulsar.verbose = 0 # [0/1]: turn on verbosity for debugging print statements
pulsar.EB_external = 1 # [0/1]: to apply external E and B
pulsar.E_external_monopole = 1 # [0/1]
pulsar.max_ndens = 5.54e6 # max ndens == ndens used in initializing density
pulsar.Ninj_fraction = 0.2 # fraction of sigma injected
pulsar.rhoGJ_scale = 1e0 # scaling down of rho_GJ
pulsar.damp_EB_internal = 1 # Damp internal electric field
pulsar.damping_scale = 1000.0 # Damping scale factor for internal electric field
54 changes: 54 additions & 0 deletions Examples/Physics_applications/pulsar/pulsar_vis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import yt
import os
import glob
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-f", "--plotfile", type=str, help="Path to single input plotfile to visualize.")
parser.add_argument("-d", "--dir", type=str, help="Path to input plotfile directory to visualize.")

args = parser.parse_args()

def visualize(plt, annotate_particles=True):
ds = yt.load(plt)
sl = yt.SlicePlot(ds, 0, 'Ez', aspect=1) # Create a sliceplot object
if annotate_particles:
sl.annotate_particles(width=(2.e3, 'm'),ptype="plasma_p",col='b',p_size=5.0)
sl.annotate_particles(width=(2.e3, 'm'),ptype="plasma_e",col='r',p_size=5.0)
sl.annotate_streamlines("Ey", "Ez", plot_args={"color": "black"})
sl.annotate_grids() # Show grids
sl.annotate_sphere([90000.0, 90000.0, 90000.0], radius=12000.0,
circle_args={'color':'white', 'linewidth':2})
out_name = os.path.join(os.path.dirname(plt), "pulsar_{}.png".format(os.path.basename(plt)))
sl.save(out_name)

if __name__ == "__main__":
yt.funcs.mylog.setLevel(50)
if args.dir:
failed = []
plotfiles = glob.glob(os.path.join(args.dir, "plt" + "[0-9]"*5))
for pf in plotfiles:
try:
visualize(pf)
except:
# plotfile 0 may not have particles, so turn off annotations if we first failed
try:
visualize(pf, annotate_particles=False)
except:
failed.append(pf)
pass

if len(failed) > 0:
print("Visualization failed for the following plotfiles:")
for fp in failed:
print(fp)
else:
print("No plots failed, creating a gif ...")
input_files = os.path.join(args.dir, "*.png")
output_gif = os.path.join(args.dir, "pulsar.gif")
os.system("convert -delay 20 -loop 0 {} {}".format(input_files, output_gif))

elif args.plotfile:
visualize(args.plotfile)
else:
print("Supply either -f or -d options for visualization. Use the -h option to see help.")
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ USE_ASCENT_INSITU = FALSE
USE_OPENPMD = FALSE

WarpxBinDir = Bin
PULSAR = TRUE

USE_PSATD = FALSE
USE_PSATD_PICSAR = FALSE
Expand Down
102 changes: 102 additions & 0 deletions Source/Evolve/WarpXEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# include "FieldSolver/SpectralSolver/SpectralSolver.H"
#endif

#ifdef PULSAR
#include "Particles/PulsarParameters.H"
#endif
#include <cmath>
#include <limits>

Expand Down Expand Up @@ -136,7 +139,94 @@ WarpX::Evolve (int numsteps)
// B : guard cells are NOT up-to-date
}

#ifdef PULSAR
if (PulsarParm::damp_EB_internal) {
MultiFab *Ex, *Ey, *Ez;
MultiFab *Bx, *By, *Bz;
for (int lev = 0; lev <= finest_level; ++lev) {
Ex = Efield_fp[lev][0].get();
Ey = Efield_fp[lev][1].get();
Ez = Efield_fp[lev][2].get();
Bx = Bfield_fp[lev][0].get();
By = Bfield_fp[lev][1].get();
Bz = Bfield_fp[lev][2].get();
amrex::IntVect ex_type = Ex->ixType().toIntVect();
amrex::IntVect ey_type = Ey->ixType().toIntVect();
amrex::IntVect ez_type = Ez->ixType().toIntVect();
amrex::IntVect bx_type = Bx->ixType().toIntVect();
amrex::IntVect by_type = By->ixType().toIntVect();
amrex::IntVect bz_type = Bz->ixType().toIntVect();
amrex::GpuArray<int, 3> Ex_stag, Ey_stag, Ez_stag, Bx_stag, By_stag, Bz_stag;
for (int idim = 0; idim < 3; ++idim)
{
Ex_stag[idim] = ex_type[idim];
Ey_stag[idim] = ey_type[idim];
Ez_stag[idim] = ez_type[idim];
Bx_stag[idim] = bx_type[idim];
By_stag[idim] = by_type[idim];
Bz_stag[idim] = bz_type[idim];
}
auto geom = Geom(lev).data();
#ifdef _OPENMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for ( MFIter mfi(*Ex, TilingIfNotGPU()); mfi.isValid(); ++mfi )
{
const Box& tex = mfi.tilebox( Ex->ixType().toIntVect() );
const Box& tey = mfi.tilebox( Ey->ixType().toIntVect() );
const Box& tez = mfi.tilebox( Ez->ixType().toIntVect() );

auto const& Exfab = Ex->array(mfi);
auto const& Eyfab = Ey->array(mfi);
auto const& Ezfab = Ez->array(mfi);

amrex::ParallelFor(tex, tey, tez,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Exfab, Ex_stag);
},
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Eyfab, Ey_stag);
},
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Ezfab, Ez_stag);
});
}
for ( MFIter mfi(*Bx, TilingIfNotGPU()); mfi.isValid(); ++mfi )
{
const Box& tex = mfi.tilebox( Bx->ixType().toIntVect() );
const Box& tey = mfi.tilebox( By->ixType().toIntVect() );
const Box& tez = mfi.tilebox( Bz->ixType().toIntVect() );

auto const& Bxfab = Bx->array(mfi);
auto const& Byfab = By->array(mfi);
auto const& Bzfab = Bz->array(mfi);

amrex::ParallelFor(tex, tey, tez,
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Bxfab, Bx_stag);
},
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Byfab, By_stag);
},
[=] AMREX_GPU_DEVICE (int i, int j, int k)
{
PulsarParm::DampField(i, j, k, geom, Bzfab, Bz_stag);
});
}
}
}
FillBoundaryE(guard_cells.ng_FieldSolver, IntVect::TheZeroVector());
FillBoundaryB(guard_cells.ng_FieldSolver, IntVect::TheZeroVector());
#endif

#ifdef WARPX_USE_PY
if (warpx_py_beforeEsolve) warpx_py_beforeEsolve();
#endif

if (cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) {
// At the end of last step, push p by 0.5*dt to synchronize
Expand All @@ -151,7 +241,9 @@ WarpX::Evolve (int numsteps)
is_synchronized = true;
}

#ifdef WARPX_USE_PY
if (warpx_py_afterEsolve) warpx_py_afterEsolve();
#endif

for (int lev = 0; lev <= max_level; ++lev) {
++istep[lev];
Expand All @@ -175,6 +267,16 @@ WarpX::Evolve (int numsteps)

int num_moved = MoveWindow(move_j);

#ifdef PULSAR
if (!rho_fp[0]) {
amrex::Print() << " no rho -- compute rho! \n";
}
else {
amrex::Print() << " rho is computed \n";
}
mypc->PulsarParticleRemoval();
mypc->PulsarParticleInjection();
#endif
mypc->ApplyBoundaryConditions();

// Electrostatic solver: particles can move by an arbitrary number of cells
Expand Down
Loading