1 |
jgs |
127 |
# $Id$ |
2 |
|
|
|
3 |
jgs |
147 |
from escript.modelframe import Model |
4 |
jgs |
127 |
|
5 |
|
|
class Visualization(Model): |
6 |
|
|
""" |
7 |
|
|
|
8 |
|
|
generic visualization of scalar, vector and tensorial data (not implemeted yet) |
9 |
|
|
|
10 |
jgs |
147 |
t: current time |
11 |
jgs |
127 |
scalar: scalar data set |
12 |
|
|
vector: vector data set |
13 |
|
|
tensor: tensor data set |
14 |
|
|
stride: visulaization is done every strides time step |
15 |
|
|
filename: name of the movie file |
16 |
|
|
|
17 |
|
|
""" |
18 |
|
|
def __init__(self,debug=False): |
19 |
|
|
Model.__init__(self,debug=debug) |
20 |
jgs |
147 |
self.declareParameter(t=0.,scalar=None,vector=None,tensor=None,stride=1,movie="movie.mpg",counter=0) |
21 |
jgs |
127 |
|
22 |
jgs |
147 |
def doInitialization(self): |
23 |
jgs |
127 |
self.__n=0 |
24 |
|
|
self.__scene=None |
25 |
|
|
|
26 |
jgs |
147 |
def doStepPostprocessing(self,dt): |
27 |
jgs |
127 |
self.__n+=1 |
28 |
|
|
if self.__n%self.stride: |
29 |
|
|
data=self.scalar |
30 |
|
|
if data!=None: |
31 |
|
|
pass |
32 |
|
|
data=self.vector |
33 |
|
|
if data!=None: |
34 |
|
|
pass |
35 |
|
|
data=self.tensor |
36 |
|
|
if data!=None: |
37 |
|
|
pass |
38 |
|
|
|
39 |
|
|
def doFinalization(self): |
40 |
|
|
# make the movie into self.filename |
41 |
|
|
pass |
42 |
|
|
|
43 |
|
|
class WriteVTK(Visualization): |
44 |
|
|
""" writes data into a VTK file for further processing. Currently data are written in several files for |
45 |
|
|
each data type. This may change in the future. |
46 |
|
|
|
47 |
|
|
scalar: scalar data set |
48 |
|
|
vector: vector data set |
49 |
|
|
tensor: tensor data set |
50 |
|
|
stride: file is written every stride-th time step |
51 |
|
|
filename: name of the data files. use %s for indication of data type (s,v,t) and time step id. |
52 |
|
|
|
53 |
|
|
""" |
54 |
|
|
def __init__(self,debug=False): |
55 |
|
|
Visualization.__init__(self,debug=debug) |
56 |
jgs |
147 |
self.declareParameter(filename="data.%s.xml") |
57 |
jgs |
127 |
|
58 |
jgs |
147 |
def doStepPostprocessing(self,dt): |
59 |
jgs |
127 |
self.counter+=1 |
60 |
|
|
if self.counter%self.stride==0: |
61 |
|
|
n=self.counter/self.stride |
62 |
|
|
data=self.scalar |
63 |
jgs |
147 |
if hasattr(data,"saveVTK"): data.saveVTK(self.filename%("s.%d"%n)) |
64 |
jgs |
127 |
data=self.vector |
65 |
jgs |
147 |
if hasattr(data,"saveVTK"): data.saveVTK(self.filename%("v.%d"%n)) |
66 |
jgs |
127 |
data=self.tensor |
67 |
jgs |
147 |
if hasattr(data,"saveVTK"): data.saveVTK(self.filename%("t.%d"%n)) |