5 |
|
|
6 |
Currently includes: |
Currently includes: |
7 |
- Projector - to project a discontinuous |
- Projector - to project a discontinuous |
8 |
|
- Locator - to trace values in data objects at a certain location |
9 |
|
- TimeIntegrationManager - to handel extraplotion in time |
10 |
""" |
""" |
11 |
|
|
12 |
import escript |
import escript |
14 |
import numarray |
import numarray |
15 |
import util |
import util |
16 |
|
|
17 |
|
class TimeIntegrationManager: |
18 |
|
""" |
19 |
|
a simple mechanism to manage time dependend values. |
20 |
|
|
21 |
|
typical usage is: |
22 |
|
|
23 |
|
dt=0.1 # time increment |
24 |
|
tm=TimeIntegrationManager(inital_value,p=1) |
25 |
|
while t<1. |
26 |
|
v_guess=tm.extrapolate(dt) # extrapolate to t+dt |
27 |
|
v=... |
28 |
|
tm.checkin(dt,v) |
29 |
|
t+=dt |
30 |
|
|
31 |
|
@remark: currently only p=1 is supported. |
32 |
|
""" |
33 |
|
def __init__(self,*inital_values,**kwargs): |
34 |
|
""" |
35 |
|
sets up the value manager where inital_value is the initial value and p is order used for extrapolation |
36 |
|
""" |
37 |
|
if kwargs.has_key("p"): |
38 |
|
self.__p=kwargs["p"] |
39 |
|
else: |
40 |
|
self.__p=1 |
41 |
|
if kwargs.has_key("time"): |
42 |
|
self.__t=kwargs["time"] |
43 |
|
else: |
44 |
|
self.__t=0. |
45 |
|
self.__v_mem=[inital_values] |
46 |
|
self.__order=0 |
47 |
|
self.__dt_mem=[] |
48 |
|
self.__num_val=len(inital_values) |
49 |
|
|
50 |
|
def getTime(self): |
51 |
|
return self.__t |
52 |
|
|
53 |
|
def checkin(self,dt,*values): |
54 |
|
""" |
55 |
|
adds new values to the manager. the p+1 last value get lost |
56 |
|
""" |
57 |
|
o=min(self.__order+1,self.__p) |
58 |
|
self.__order=min(self.__order+1,self.__p) |
59 |
|
v_mem_new=[values] |
60 |
|
dt_mem_new=[dt] |
61 |
|
for i in range(o-1): |
62 |
|
v_mem_new.append(self.__v_mem[i]) |
63 |
|
dt_mem_new.append(self.__dt_mem[i]) |
64 |
|
v_mem_new.append(self.__v_mem[o-1]) |
65 |
|
self.__order=o |
66 |
|
self.__v_mem=v_mem_new |
67 |
|
self.__dt_mem=dt_mem_new |
68 |
|
self.__t+=dt |
69 |
|
|
70 |
|
def extrapolate(self,dt): |
71 |
|
""" |
72 |
|
extrapolates to dt forward in time. |
73 |
|
""" |
74 |
|
if self.__order==0: |
75 |
|
out=self.__v_mem[0] |
76 |
|
else: |
77 |
|
out=[] |
78 |
|
for i in range(self.__num_val): |
79 |
|
out.append((1.+dt/self.__dt_mem[0])*self.__v_mem[0][i]-dt/self.__dt_mem[0]*self.__v_mem[1][i]) |
80 |
|
|
81 |
|
if len(out)==0: |
82 |
|
return None |
83 |
|
elif len(out)==1: |
84 |
|
return out[0] |
85 |
|
else: |
86 |
|
return out |
87 |
|
|
88 |
class Projector: |
class Projector: |
89 |
""" |
""" |
90 |
The Projector is a factory which projects a discontiuous function onto a |
The Projector is a factory which projects a discontiuous function onto a |