-
Notifications
You must be signed in to change notification settings - Fork 226
Correct collision algorithm in RZ. #2510
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
Changes from 10 commits
e5a29ad
d86b048
a9bf51f
c659885
1d2483d
bbc8b5b
bb5a147
9453118
74a47d1
17b7465
c234306
411d21f
73892dd
c5c9d82
787f5de
306dd0c
2b81a12
ab21e68
61df218
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #! /usr/bin/env python | ||
|
|
||
| # Copyright 2019-2020 Yinjian Zhao | ||
Yin-YinjianZhao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # | ||
| # This file is part of WarpX. | ||
| # | ||
| # License: BSD-3-Clause-LBNL | ||
|
|
||
| # This script tests the collision module in RZ. | ||
| # Electrons are set with the same vr, | ||
| # such that correct collisions will not lead to any velocity changes. | ||
RemiLehe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Thus the initial electron momentum will be compared with the final momentum. | ||
|
|
||
| # Possible errors: | ||
| # tolerance: 1.0e-30 | ||
| # Possible running time: ~ 1.0 s | ||
|
|
||
| import sys | ||
ax3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import yt | ||
| import numpy as np | ||
| from glob import glob | ||
| sys.path.insert(1, '../../../../warpx/Regression/Checksum/') | ||
| import checksumAPI | ||
|
|
||
| tolerance = 1.0e-30 | ||
|
|
||
| last_fn = sys.argv[1] | ||
| if (last_fn[-1] == "/"): last_fn = last_fn[:-1] | ||
| fn_list = glob(last_fn[:-5] + "?????") | ||
|
|
||
| for fn in fn_list: | ||
| # get time index j | ||
| j = int(fn[-5:]) | ||
| if j==0: | ||
| # load file | ||
| ds = yt.load( fn ) | ||
| ad = ds.all_data() | ||
| px1 = ad['particle_momentum_x'].to_ndarray() | ||
| py1 = ad['particle_momentum_y'].to_ndarray() | ||
| if j==150: | ||
| # load file | ||
| ds = yt.load( fn ) | ||
| ad = ds.all_data() | ||
| px2 = ad['particle_momentum_x'].to_ndarray() | ||
| py2 = ad['particle_momentum_y'].to_ndarray() | ||
|
|
||
| error = np.max( abs(px1-px2)+abs(py1-py2) ) | ||
|
|
||
| print('error = ', error) | ||
| print('tolerance = ', tolerance) | ||
| assert(error < tolerance) | ||
|
|
||
| test_name = last_fn[:-9] # Could also be os.path.split(os.getcwd())[1] | ||
Yin-YinjianZhao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| checksumAPI.evaluate_checksum(test_name, fn, do_particles=False) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ################################# | ||
| ####### GENERAL PARAMETERS ###### | ||
| ################################# | ||
| max_step = 150 | ||
| amr.n_cell = 8 8 | ||
| amr.max_grid_size = 8 | ||
| amr.blocking_factor = 8 | ||
| amr.max_level = 0 | ||
| geometry.coord_sys = 1 | ||
| geometry.prob_lo = 0. 0. | ||
| geometry.prob_hi = 4.154046151855669e2 4.154046151855669e2 | ||
|
|
||
| ################################# | ||
| ###### Boundary Condition ####### | ||
| ################################# | ||
| boundary.field_lo = none periodic | ||
| boundary.field_hi = none periodic | ||
|
|
||
| ################################# | ||
| ############ NUMERICS ########### | ||
| ################################# | ||
| warpx.serialize_ics = 1 | ||
| warpx.verbose = 1 | ||
| warpx.cfl = 1.0 | ||
|
|
||
| # Order of particle shape factors | ||
| algo.particle_shape = 1 | ||
|
|
||
| ################################# | ||
| ############ PLASMA ############# | ||
| ################################# | ||
| particles.species_names = electron | ||
|
|
||
| electron.charge = -q_e | ||
| electron.mass = m_e | ||
| electron.injection_style = "NUniformPerCell" | ||
| electron.num_particles_per_cell_each_dim = 1 10 1 | ||
| electron.profile = constant | ||
| electron.density = 1.0e21 | ||
| electron.momentum_distribution_type = parse_momentum_function | ||
| electron.momentum_function_ux(x,y,z) = "if(x*x+y*y>0.0, 1.0*x/sqrt(x*x+y*y), 0.0)" | ||
| electron.momentum_function_uy(x,y,z) = "if(x*x+y*y>0.0, 1.0*y/sqrt(x*x+y*y), 0.0)" | ||
| electron.momentum_function_uz(x,y,z) = "0" | ||
| electron.do_not_deposit = 1 | ||
| electron.do_not_push = 1 | ||
|
|
||
| ################################# | ||
| ############ COLLISION ########## | ||
| ################################# | ||
| collisions.collision_names = collision | ||
| collision.species = electron electron | ||
| collision.CoulombLog = 15.9 | ||
|
|
||
| diagnostics.diags_names = diag1 | ||
| diag1.intervals = 10 | ||
| diag1.diag_type = Full |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "lev=0": { | ||
| "Bx": 0.0, | ||
| "By": 0.0, | ||
| "Bz": 0.0, | ||
| "Ex": 0.0, | ||
| "Ey": 0.0, | ||
| "Ez": 0.0, | ||
| "jx": 0.0, | ||
| "jy": 0.0, | ||
| "jz": 0.0 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,18 +107,44 @@ void ElasticCollisionPerez ( | |
| amrex::max(n1,n2), T_R(-1.0/3.0) ); | ||
| lmdD = amrex::max(lmdD, rmin); | ||
|
|
||
| #if (defined WARPX_DIM_RZ) | ||
| T_R * const AMREX_RESTRICT theta1 = soa_1.m_rdata[PIdx::theta]; | ||
| T_R * const AMREX_RESTRICT theta2 = soa_2.m_rdata[PIdx::theta]; | ||
| #endif | ||
|
|
||
| // call UpdateMomentumPerezElastic() | ||
| { | ||
| int i1 = I1s; int i2 = I2s; | ||
| for (int k = 0; k < amrex::max(NI1,NI2); ++k) | ||
| { | ||
|
|
||
| #if (defined WARPX_DIM_RZ) | ||
| //When particles are having the same vr, their velocities would change after collision, | ||
| //because they may have different azimuth angles, but their velocities are not supposed to be changed. | ||
| //To fix this, we rotate one particle to be in parallel with the other particle, | ||
| //such that their velocities won't change after collision if they have the same vr. | ||
| //Then, we rotate that particle back. | ||
Yin-YinjianZhao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| T_R const theta = theta2[I2[i2]]-theta1[I1[i1]]; | ||
Yin-YinjianZhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| T_R u1xbuf; | ||
| u1xbuf = u1x[I1[i1]]; | ||
Yin-YinjianZhao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); | ||
| u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); | ||
| #endif | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why write to the backing arrays rather than just using local variables for these two values? This seems like pointless memory traffic.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so I see these are passed by reference, and updated inside
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PhilMiller Hi, thanks for you comments, could you provide more details how to improve the code, I'm not sure if I understand your point. Stack variables also work on GPUs?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yin-YinjianZhao#2 |
||
| UpdateMomentumPerezElastic( | ||
| u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], | ||
| u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], | ||
| n1, n2, n12, | ||
| q1, m1, w1[ I1[i1] ], q2, m2, w2[ I2[i2] ], | ||
| dt, L, lmdD, | ||
| engine); | ||
|
|
||
| #if (defined WARPX_DIM_RZ) | ||
| u1xbuf = u1x[I1[i1]]; | ||
| u1x[I1[i1]] = u1xbuf*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); | ||
| u1y[I1[i1]] = u1xbuf*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); | ||
Yin-YinjianZhao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #endif | ||
|
|
||
| ++i1; if ( i1 == static_cast<int>(I1e) ) { i1 = I1s; } | ||
| ++i2; if ( i2 == static_cast<int>(I2e) ) { i2 = I2s; } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.