# needs description
# DESCRIPTION: haynes-schockley
# continuity eqn: n,t = J,x + (G-R) = D n,xx + mu (n E),x + G - 1/tau (n - n_0)
# w/ J = D n,x + mu n phi,x
# poisson eqn for E-field: epsilon phi,xx = -e (n - p + N_D - N_A)
# w/ E = phi,x
# NOTE: does not conserve electrons even with fixed E field and zero mobility
# if J=0 --> n,x = mu/D n phi,x

echo both
units    metal

variable E equal  10.0
variable n0 equal 0.0001
variable dn equal 2.0*${n0}
variable dt equal 0.0000001

timestep  ${dt}

atom_style  atomic
lattice         fcc 1.0 
region    simRegion block -50 50  0 1 0 1
boundary  f p p
create_box  1 simRegion
mass    1 1.0 # need to keep this
atom_modify     sort 0 1

#          ID  group atc PhysicsType ParameterFile
fix        AtC all   atc drift_diffusion  Si_ddm.mat

#          ID  part keywords    nx ny nz region
fix_modify AtC mesh  create 100 1  1  simRegion f p p

fix_modify AtC mesh create_nodeset lbc -50.1 -49.9 -INF  INF -INF  INF
fix_modify AtC mesh create_nodeset rbc  49.9  50.1 -INF  INF -INF  INF

# fix a temperature
fix_modify AtC  initial temperature          all 300.0
fix_modify AtC  initial electron_temperature all 300.0
fix_modify AtC  initial electron_density all gaussian 0 0 0 1 0 0 5.0 ${dn} ${n0}
# isolate system: 
# diffusion: dn/dx = 0
# drift    : n = 0
fix_modify AtC  fix electron_density lbc ${n0}
fix_modify AtC  fix electron_density rbc ${n0}
fix_modify AtC  fix electric_potential all linear 0 0 0 $E 0 0 1
variable perm equal 0.06 
variable nD equal  1.0e-4 
fix_modify AtC  source electric_potential all ${nD}

variable s equal 10
thermo  $s
# f_AtC:1 thermal energy, 2 avg T, 3 electron energy, 4 avg Te, 5 total n
thermo_style custom step cpu f_AtC[1] f_AtC[2] f_AtC[3] f_AtC[4] f_AtC[5]
thermo_modify  format 1 %5i format 2 %7.2g
fix_modify      AtC  output   no_atoms_ddmFE $s text
fix_modify AtC extrinsic electron_integration implicit
run     40

# free electric field and allow shielding
fix_modify AtC  unfix electric_potential all
fix_modify AtC  fix electric_potential  lbc linear 0 0 0 $E 0 0 1
fix_modify AtC  fix electric_potential  rbc linear 0 0 0 $E 0 0 1
fix_modify AtC extrinsic electron_integration implicit 10
run     40
