DISPATCH
stagger_utils.py
1 '''
2  Staggered derivatives and interpolations, corresponding to the ones used in the stagger2
3  solver in the DISPATCH code
4 '''
5 from numpy import roll, log, exp
6 
7 def xdn(f):
8  return (f+roll(f,1,0))*0.5
9 def ydn(f):
10  return (f+roll(f,1,1))*0.5
11 def zdn(f):
12  return (f+roll(f,1,2))*0.5
13 def xup(f):
14  return (f+roll(f,-1,0))*0.5
15 def yup(f):
16  return (f+roll(f,-1,1))*0.5
17 def zup(f):
18  return (f+roll(f,-1,2))*0.5
19 
20 def ddxdn(f,s):
21  c=1./s.ds[0]
22  return (f-roll(f,1,0))*c
23 def ddydn(f,s):
24  c=1./s.ds[1]
25  return (f-roll(f,1,1))*c
26 def ddzdn(f,s):
27  c=1./s.ds[2]
28  return (f-roll(f,1,2))*c
29 
30 def ddxup(f,s):
31  c=1./s.ds[0]
32  return (roll(f,-1,0)-f)*c
33 def ddyup(f,s):
34  c=1./s.ds[1]
35  return (roll(f,-1,1)-f)*c
36 def ddzup(f,s):
37  c=1./s.ds[2]
38  return (roll(f,-1,2)-f)*c
39 
40 def ddx(f,s):
41  c=2./s.ds[0]
42  return (roll(f,-1,0)-roll(f,1,0))*c
43 def ddy(f,s):
44  c=2./s.ds[1]
45  return (roll(f,-1,1)-roll(f,1,1))*c
46 def ddz(f,s):
47  c=2./s.ds[2]
48  return (roll(f,-1,2)-roll(f,1,2))*c
49 
50 # These functions may be used to calculate the velocity from the momenta and mass density
51 def fux(f):
52  return xup(f.px/exp(xdn(log(f.d))))
53 def fuy(f):
54  return yup(f.py/exp(ydn(log(f.d))))
55 def fuz(f):
56  return zup(f.pz/exp(zdn(log(f.d))))