-
Notifications
You must be signed in to change notification settings - Fork 0
/
momentum.py
243 lines (148 loc) · 5.33 KB
/
momentum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import numpy as np
import scipy.ndimage as ndimage
import collections
from pypic.misctools.tools import dotprod,vecprod
#------------------------------------------------------------------------------
#
# MOMENTUM
#
# This module allows to calculate the different terms of the momentum equation
# of a given specie of the plasma.
#
# Genericity : This module is generic, i.e. does not depend on a particular
# implementation. It assumes the data layout is a uniform
# cartesian mesh
#-------------------------------------------------------------------------------
def _fixtime(time):
"""checks whether time is an interval or a single time
returns a list of one time if time is a scalar"""
if isinstance(time, collections.Iterable) == False:
time = [time]
return time
def _smooth(v, sigma):
""" apply a gaussian filter on the quantity"""
for c in range(3):
v[c,:,:] = ndimage.gaussian_filter(v[c,:,:],sigma=sigma, order=0)
return v
#----------------------------------------------------------
#----------------------------------------------------------
def electric(run, time, species,smooth='no',sigma=None):
"""@todo: returns the electric force acting on 'species'
@param run @todo
@param time @todo
@param species @todo
@param smooth @todo
@param sigma @todo
@return: @todo
Exemple :
Creation : 2013-01-23 14:50:27.427773
"""
time = _fixtime(time)
q = run.GetCharge(species)
tmp = run.GetE(t[0])
nqE = np.zeros(shape=tmp.shape, dtype=tmp.dtype)
for t in time:
E = run.GetE(t)
N = run.GetN(t, species)
nqE += N*E*q
nqE /= len(time)
if smooth.lower() == 'yes':
nqE = _smooth(nqE,sigma)
return nqE
#==========================================================
#----------------------------------------------------------
#----------------------------------------------------------
def magnetic(run, time, species,smooth='no',sigma=None):
"""@todo: returns the magnetic force acting on 'species'
@param run @todo
@param time @todo
@param species @todo
@param smooth @todo
@param sigma @todo
@return: @todo
Exemple :
Creation : 2013-01-23 14:50:27.427773
"""
time = _fixtime(time)
q = run.GetCharge(species)
tmp = run.GetE(t[0])
nqVxB = np.zeros(shape=tmp.shape, dtype=tmp.dtype)
for t in time:
B = run.GetB(t)
V = run.GetV(t, species)
N = run.GetN(t, species)
nqVxB += vecprod(V,B)*N*q
#nqVxB[0,:,:] += q*N*(V[1,:,:]*B[2,:,:]-V[2,:,:]*B[1,:,:])
#nqVxB[1,:,:] += q*N*(V[2,:,:]*B[0,:,:]-V[0,:,:]*B[2,:,:])
#nqVxB[2,:,:] += q*N*(V[0,:,:]*B[1,:,:]-V[1,:,:]*B[0,:,:])
nqVxB /= len(time)
if smooth.lower() == 'yes':
nqVxB = _smooth(nqVxB, sigma)
return nqVxB
#==========================================================
#----------------------------------------------------------
#----------------------------------------------------------
def pressure(run, time, species,smooth='no',sigma=None):
"""@todo: returns the pressure force acting on 'species'
@param run @todo
@param time @todo
@param species @todo
@param smooth @todo
@param sigma @todo
@return: @todo
Exemple :
Creation : 2013-01-23 14:50:27.427773
"""
time = _fixtime(time)
tmp = run.GetE(t[0])
divP = np.zeros(shape=tmp.shape, dtype=tmp.dtype)
for t in time:
divP += run.divP(t, species)
divP /= len(time)
if smooth.lower() == 'yes':
divP = _smooth(divP, sigma)
return -divP
#==========================================================
#----------------------------------------------------------
#----------------------------------------------------------
def inertia_steady(run, time, species,smooth='no',sigma=None):
"""@todo: returns the steady inertia acting on 'species'
@param run @todo
@param time @todo
@param species @todo
@param smooth @todo
@param sigma @todo
@return: @todo
Exemple :
Creation : 2013-01-23 14:50:27.427773
"""
time = _fixtime(time)
mass = run.GetMass(species)
tmp = run.GetE(t[0])
inertia = np.zeros(shape=tmp.shape, dtype=tmp.dtype)
for t in time:
N = run.GetN(t, species)
inertia += mass*run.VGradV(t, species)
inertia /= len(time)
if smooth.lower() == 'yes':
inertia = _smooth(inertia, sigma)
return inertia
#==========================================================
#----------------------------------------------------------
#----------------------------------------------------------
def totalforces(run, time, species,smooth='no',sigma=None):
"""@todo: returns the sum of all forces acting on 'species'
@param run @todo
@param time @todo
@param species @todo
@param smooth @todo
@param sigma @todo
@return: @todo
Exemple :
Creation : 2013-01-23 14:50:27.427773
"""
fE = electric(run, time, species, smooth=smooth, sigma=sigma)
fB = magnetic(run, time, species, smooth=smooth, sigma=sigma)
fP = pressure(run, time, species, smooth=smooth, sigma=sigma)
return fE + fB + fP
#==========================================================