source: anuga_work/development/2010-projects/anuga_1d/generic/util.py @ 7839

Last change on this file since 7839 was 7839, checked in by steve, 14 years ago

Changing name of 1d projects so that it will be easy to moveto the trunk

File size: 1.1 KB
Line 
1"""
2This module contains various auxiliary function used by pyvolution.
3"""
4
5
6import numpy
7
8def mean(x):
9    return numpy.sum(x)/len(x)
10
11
12def gradient(x0, x1, q0, q1):
13
14    if q1-q0 != 0:
15        a = (q1-q0)/(x1-x0)
16    else:
17        a = 0
18       
19    return a
20
21def  minmod(beta_p,beta_m):
22    if (abs(beta_p) < abs(beta_m)) & (beta_p*beta_m > 0.0):
23        phi = beta_p
24    elif (abs(beta_m) < abs(beta_p)) & (beta_p*beta_m > 0.0):
25        phi = beta_m
26    else:
27        phi = 0.0
28    return phi
29
30def  minmod_kurganov(a,b,c):
31    from numpy import sign
32    if sign(a)==sign(b)==sign(c):
33        return sign(a)*min(abs(a),abs(b),abs(c))
34    else:
35        return 0.0
36
37def  maxmod(a,b):
38    if (abs(a) > abs(b)) & (a*b > 0.0):
39        phi = a
40    elif (abs(b) > abs(a)) & (a*b > 0.0):
41        phi = b
42    else:
43        phi = 0.0
44    return phi
45
46def vanleer(a,b):
47    if abs(a)+abs(b) > 1e-12:
48        return (a*abs(b)+abs(a)*b)/(abs(a)+abs(b))
49    else:
50        return 0.0
51
52def vanalbada(a,b):
53    if a*a+b*b > 1e-12:
54        return (a*a*b+a*b*b)/(a*a+b*b)
55    else:
56        return 0.0
57
Note: See TracBrowser for help on using the repository browser.