# calculating viscosity in 2D using Green-Kubo example

Greetings,

I was looking at the example for calculating the viscosity in 2D using the Green-Kubo method that I saw here: https://github.com/lammps/lammps/blob/master/examples/VISCOSITY/in.gk.2d. I have copied it below as well.

But for 2D you only have one off-diagonal component, P_xy, so the example code below somewhat confuses me. Particularly the two lines:

variable pxx equal pxx-press

and

variable eta equal 0.5*({etaxy}+{etaxx})

My apologies in advanced if I am missing something simple, and thanks for any advice one may have,
–Joe

# settings

variable x equal 20
variable y equal 20

variable rho equal 0.6
variable t equal 1.0
variable rc equal 2.5

variable p equal 400 # correlation length
variable s equal 5 # sample interval
variable d equal \$p*\$s # dump interval

# problem setup

units lj
dimension 2
atom_style atomic
neigh_modify delay 0 every 1

lattice sq2 \${rho}
region simbox block 0 \$x 0 \$y -0.1 0.1
create_box 1 simbox
create_atoms 1 box

pair_style lj/cut \${rc}
pair_coeff * * 1 1

mass * 1.0
velocity all create \$t 97287

# equilibration run

fix 1 all nve
fix 2 all langevin \$t \$t 0.1 498094
fix 3 all enforce2d

thermo \$d
run 10000

velocity all scale \$t

unfix 2

reset_timestep 0

# Define distinct components of symmetric traceless stress tensor

variable pxy equal pxy
variable pxx equal pxx-press

fix SS all ave/correlate \$s \$p \$d &
v_pxy v_pxx type auto file profile.gk.2d ave running

# See Daivis and Evans, J.Chem.Phys, 100, 541-547 (1994)

variable scale equal 1.0/\$tvols*dt variable diagfac equal 2-2/2 variable vxy equal trap(f_SS[3])*{scale}
variable vxx equal trap(f_SS[4])*{scale}/{diagfac}

thermo_style custom step temp press pxy v_vxy v_vxx

run 500000

variable etaxy equal v_vxy
variable etaxx equal v_vxx
variable eta equal 0.5*({etaxy}+{etaxx})
print “running average viscosity: \${eta}”

I think that is Aidan’s script. He can comment.

Steve

A symmetric stress tensor in D dimensions can be written as the sum of a hydrostatic tensor (unit tensor times scalar pressure) and a symmetric traceless shear tensor. The later has D*(D-1)/2 independent off-diagonal components, but it also has D-1 independent diagonal components. Hence in 2D, there is one off-diagonal component and one diagonal component. I chose to use pxy and pxx-press.