/[escript]/trunk/modellib/py_src/visualization.py
ViewVC logotype

Annotation of /trunk/modellib/py_src/visualization.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (hide annotations)
Mon Jan 20 03:37:18 2020 UTC (10 months ago) by uqaeller
File MIME type: text/x-python
File size: 16139 byte(s)
Updated the copyright header.


1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1312 #
4 uqaeller 6939 # Copyright (c) 2003-2020 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1312 #
7 ksteube 1809 # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1312 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 uqaeller 6939 # Development from 2019 by School of Earth and Environmental Sciences
15 jfenwick 3981 #
16     ##############################################################################
17 jgs 127
18 sshaw 5706 from __future__ import print_function, division
19    
20 uqaeller 6939 __copyright__="""Copyright (c) 2003-2020 by The University of Queensland
21 jfenwick 3981 http://www.uq.edu.au
22 ksteube 1809 Primary Business: Queensland, Australia"""
23 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
24     http://www.apache.org/licenses/LICENSE-2.0"""
25 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
26 elspeth 628
27 gross 912 from esys.escript.modelframe import Model, Link
28 caltinay 3346 from esys.escript import Data
29     from esys.weipa import saveVTK
30 jgs 148 import os
31 jgs 127
32     class Visualization(Model):
33 jgs 148 """
34 gross 912 Generic visualization Model
35 jgs 127
36 jfenwick 2625 :ivar t: current time (in)
37     :ivar n: frame counter (in)
38     :ivar dt: increment for output (in)
39     :ivar filename: name of the output file (in)
40 jgs 148 """
41 jgs 127
42 gross 918 def __init__(self, **kwargs):
43 jgs 148 """
44     Initialisation of the visualisation model object
45 jgs 127
46 jfenwick 2625 :keyword debug: Debugging flag
47 jgs 148 """
48 gross 918 super(Visualization,self).__init__(**kwargs)
49 jgs 148 self.declareParameter(t=0.,
50 gross 423 n=0,
51     dt=1,
52     filename="movie.mpg")
53 jgs 127
54 jgs 148 def doInitialization(self):
55 gross 814 """
56     does some kind of initialisation
57     """
58     self.__last_t=self.t
59 gross 912 fnc=self.filename.split('.')
60     if len(fnc)==0:
61     self.__frame_filename="data.%s.xml"
62     else:
63     n=fnc[0]
64     for i in range(1,len(fnc)-1):
65     n+="."+fnc[i]
66     if len(fnc)==1:
67     self.__frame_filename=n+".%s"
68     else:
69     self.__frame_filename=n+".%s."+fnc[-1]
70     self.trace("output filename is %s."%self.__frame_filename)
71 jgs 127
72 gross 912 def getFrameFileName(self):
73     return self.__frame_filename%self.getFrameCounter()
74    
75 gross 423 def writeFrame(self):
76 gross 814 """
77     returns True if the time stamp for writing frame is reached.
78     """
79 gross 423 out=self.t>=self.__last_t+self.dt
80     if out:
81     self.__last_t+=self.dt
82     self.n+=1
83     return out
84    
85     def getFrameCounter(self):
86 gross 814 """
87     returns a frame counter
88     """
89 gross 908 return self.n
90 gross 423
91     def getSafeTimeStepSize(self,dt):
92 gross 814 """
93     returns new step size
94 gross 423
95 jfenwick 2625 :param dt: last time step size used
96     :type dt: ``float``
97     :return: time step size that can savely be used
98     :rtype: ``float``
99 gross 814 """
100     return self.__last_t+self.dt-self.t
101    
102 gross 912 class WriteVTK(Visualization):
103     """
104     Writes data into a VTK file.
105    
106     The Model can handel up to 20 data sets that are written into a single file tagged with the given name. If no name is given and
107 jfenwick 2625 the data are defined by a `Link` the name of the target attribute is used as a tag.
108 gross 912
109 jfenwick 2625 :ivar data0: data set 0 to be written
110     :type data0: `escript.Data`
111     :ivar name0: name tag for data set 0
112     :type name0: ``str`` or ``None``
113     :ivar data1: data set 1 to be written
114     :type data1: `escript.Data`
115     :ivar name1: name tag for data set 1
116     :type name1: ``str`` or ``None``
117     :ivar data2: data set 2 to be written
118     :type data2: `escript.Data`
119     :ivar name2: name tag for data set 2
120     :type name2: ``str`` or ``None``
121     :ivar data3: data set 3 to be written
122     :type data3: `escript.Data`
123     :ivar name3: name tag for data set 3
124     :type name3: ``str`` or ``None``
125     :ivar data4: data set 4 to be written
126     :type data4: `escript.Data`
127     :ivar name4: name tag for data set 4
128     :type name4: ``str`` or ``None``
129     :ivar data5: data set 5 to be written
130     :type data5: `escript.Data`
131     :ivar name5: name tag for data set 5
132     :type name5: ``str`` or ``None``
133     :ivar data6: data set 6 to be written
134     :type data6: `escript.Data`
135     :ivar name6: name tag for data set 6
136     :type name6: ``str`` or ``None``
137     :ivar data7: data set 7 to be written
138     :type data7: `escript.Data`
139     :ivar name7: name tag for data set 7
140     :type name7: ``str`` or ``None``
141     :ivar data8: data set 8 to be written
142     :type data8: `escript.Data`
143     :ivar name8: name tag for data set 8
144     :type name8: ``str`` or ``None``
145     :ivar data9: data set 9 to be written
146     :type data9: `escript.Data`
147     :ivar name9: name tag for data set 9
148     :type name9: ``str`` or ``None``
149     :ivar data10: data set 10 to be written
150     :type data10: `escript.Data`
151     :ivar name10: name tag for data set 10
152     :type name10: ``str`` or ``None``
153     :ivar data11: data set 11 to be written
154     :type data11: `escript.Data`
155     :ivar name11: name tag for data set 11
156     :type name11: ``str`` or ``None``
157     :ivar data12: data set 12 to be written
158     :type data12: `escript.Data`
159     :ivar name12: name tag for data set 12
160     :type name12: ``str`` or ``None``
161     :ivar data13: data set 13 to be written
162     :type data13: `escript.Data`
163     :ivar name13: name tag for data set 13
164     :type name13: ``str`` or ``None``
165     :ivar data14: data set 14 to be written
166     :type data14: `escript.Data`
167     :ivar name14: name tag for data set 14
168     :type name14: ``str`` or ``None``
169     :ivar data15: data set 15 to be written
170     :type data15: `escript.Data`
171     :ivar name15: name tag for data set 15
172     :type name15: ``str`` or ``None``
173     :ivar data16: data set 16 to be written
174     :type data16: `escript.Data`
175     :ivar name16: name tag for data set 16
176     :type name16: ``str`` or ``None``
177     :ivar data17: data set 17 to be written
178     :type data17: `escript.Data`
179     :ivar name17: name tag for data set 17
180     :type name17: ``str`` or ``None``
181     :ivar data18: data set 18 to be written
182     :type data18: `escript.Data`
183     :ivar name18: name tag for data set 18
184     :type name18: ``str`` or ``None``
185     :ivar data19: data set 19 to be written
186     :type data19: `escript.Data`
187     :ivar name19: name tag for data set 19
188     :type name19: ``str`` or ``None``
189 gross 912 """
190 gross 918 def __init__(self, **kwargs):
191 gross 912 """
192     Initialisation of the WriteVTK object
193    
194 jfenwick 2625 :keyword debug: debugging flag
195     :type debug: ``bool``
196 gross 912 """
197 gross 918 super(WriteVTK,self).__init__(**kwargs)
198 gross 912 self.declareParameter(data0=None,name0=None,
199     data1=None,name1=None,
200     data2=None,name2=None,
201     data3=None,name3=None,
202     data4=None,name4=None,
203     data5=None,name5=None,
204     data6=None,name6=None,
205     data7=None,name7=None,
206     data8=None,name8=None,
207     data9=None,name9=None,
208     data10=None,name10=None,
209     data11=None,name11=None,
210     data12=None,name12=None,
211     data13=None,name13=None,
212     data14=None,name14=None,
213     data15=None,name15=None,
214     data16=None,name16=None,
215     data17=None,name17=None,
216     data18=None,name18=None,
217     data19=None,name19=None)
218     def collectData(self):
219     kwargs={}
220 gross 917 if isinstance(self.data0, Data):
221 gross 912 if self.name0 == None:
222     if isinstance(self.getAttributeObject("data0"),Link):
223     kwargs[self.getAttributeObject("data0").getAttributeName()]=self.data0
224     else:
225     kwargs["data0"]=self.data0
226     else:
227     kwargs[str(self.name0)]=self.data0
228    
229    
230 gross 917 if isinstance(self.data1, Data):
231 gross 912 if self.name1 == None:
232     if isinstance(self.getAttributeObject("data1"),Link):
233     kwargs[self.getAttributeObject("data1").getAttributeName()]=self.data1
234     else:
235     kwargs["data1"]=self.data1
236     else:
237     kwargs[str(self.name1)]=self.data1
238    
239    
240 gross 917 if isinstance(self.data2, Data):
241 gross 912 if self.name2 == None:
242     if isinstance(self.getAttributeObject("data2"),Link):
243     kwargs[self.getAttributeObject("data2").getAttributeName()]=self.data2
244     else:
245     kwargs["data2"]=self.data2
246     else:
247     kwargs[str(self.name2)]=self.data2
248    
249    
250 gross 917 if isinstance(self.data3, Data):
251 gross 912 if self.name3 == None:
252     if isinstance(self.getAttributeObject("data3"),Link):
253     kwargs[self.getAttributeObject("data3").getAttributeName()]=self.data3
254     else:
255     kwargs["data3"]=self.data3
256     else:
257     kwargs[str(self.name3)]=self.data3
258    
259    
260 gross 917 if isinstance(self.data4, Data):
261 gross 912 if self.name4 == None:
262     if isinstance(self.getAttributeObject("data4"),Link):
263     kwargs[self.getAttributeObject("data4").getAttributeName()]=self.data4
264     else:
265     kwargs["data4"]=self.data4
266     else:
267     kwargs[str(self.name4)]=self.data4
268    
269    
270 gross 917 if isinstance(self.data5, Data):
271 gross 912 if self.name5 == None:
272     if isinstance(self.getAttributeObject("data5"),Link):
273     kwargs[self.getAttributeObject("data5").getAttributeName()]=self.data5
274     else:
275     kwargs["data5"]=self.data5
276     else:
277     kwargs[str(self.name5)]=self.data5
278    
279    
280 gross 917 if isinstance(self.data6, Data):
281 gross 912 if self.name6 == None:
282     if isinstance(self.getAttributeObject("data6"),Link):
283     kwargs[self.getAttributeObject("data6").getAttributeName()]=self.data6
284     else:
285     kwargs["data6"]=self.data6
286     else:
287     kwargs[str(self.name6)]=self.data6
288    
289    
290 gross 917 if isinstance(self.data7, Data):
291 gross 912 if self.name7 == None:
292     if isinstance(self.getAttributeObject("data7"),Link):
293     kwargs[self.getAttributeObject("data7").getAttributeName()]=self.data7
294     else:
295     kwargs["data7"]=self.data7
296     else:
297     kwargs[str(self.name7)]=self.data7
298    
299    
300 gross 917 if isinstance(self.data8, Data):
301 gross 912 if self.name8 == None:
302     if isinstance(self.getAttributeObject("data8"),Link):
303     kwargs[self.getAttributeObject("data8").getAttributeName()]=self.data8
304     else:
305     kwargs["data8"]=self.data8
306     else:
307     kwargs[str(self.name8)]=self.data8
308    
309    
310 gross 917 if isinstance(self.data9, Data):
311 gross 912 if self.name9 == None:
312     if isinstance(self.getAttributeObject("data9"),Link):
313     kwargs[self.getAttributeObject("data9").getAttributeName()]=self.data9
314     else:
315     kwargs["data9"]=self.data9
316     else:
317     kwargs[str(self.name9)]=self.data9
318    
319    
320 gross 917 if isinstance(self.data10, Data):
321 gross 912 if self.name10 == None:
322     if isinstance(self.getAttributeObject("data10"),Link):
323     kwargs[self.getAttributeObject("data10").getAttributeName()]=self.data10
324     else:
325     kwargs["data10"]=self.data10
326     else:
327     kwargs[str(self.name10)]=self.data10
328    
329    
330 gross 917 if isinstance(self.data11, Data):
331 gross 912 if self.name11 == None:
332     if isinstance(self.getAttributeObject("data11"),Link):
333     kwargs[self.getAttributeObject("data11").getAttributeName()]=self.data11
334     else:
335     kwargs["data11"]=self.data11
336     else:
337     kwargs[str(self.name11)]=self.data11
338    
339    
340 gross 917 if isinstance(self.data12, Data):
341 gross 912 if self.name12 == None:
342     if isinstance(self.getAttributeObject("data12"),Link):
343     kwargs[self.getAttributeObject("data12").getAttributeName()]=self.data12
344     else:
345     kwargs["data12"]=self.data12
346     else:
347     kwargs[str(self.name12)]=self.data12
348    
349    
350 gross 917 if isinstance(self.data13, Data):
351 gross 912 if self.name13 == None:
352     if isinstance(self.getAttributeObject("data13"),Link):
353     kwargs[self.getAttributeObject("data13").getAttributeName()]=self.data13
354     else:
355     kwargs["data13"]=self.data13
356     else:
357     kwargs[str(self.name13)]=self.data13
358    
359    
360 gross 917 if isinstance(self.data14, Data):
361 gross 912 if self.name14 == None:
362     if isinstance(self.getAttributeObject("data14"),Link):
363     kwargs[self.getAttributeObject("data14").getAttributeName()]=self.data14
364     else:
365     kwargs["data14"]=self.data14
366     else:
367     kwargs[str(self.name14)]=self.data14
368    
369    
370 gross 917 if isinstance(self.data15, Data):
371 gross 912 if self.name15 == None:
372     if isinstance(self.getAttributeObject("data15"),Link):
373     kwargs[self.getAttributeObject("data15").getAttributeName()]=self.data15
374     else:
375     kwargs["data15"]=self.data15
376     else:
377     kwargs[str(self.name15)]=self.data15
378    
379    
380 gross 917 if isinstance(self.data16, Data):
381 gross 912 if self.name16 == None:
382     if isinstance(self.getAttributeObject("data16"),Link):
383     kwargs[self.getAttributeObject("data16").getAttributeName()]=self.data16
384     else:
385     kwargs["data16"]=self.data16
386     else:
387     kwargs[str(self.name16)]=self.data16
388    
389    
390 gross 917 if isinstance(self.data17, Data):
391 gross 912 if self.name17 == None:
392     if isinstance(self.getAttributeObject("data17"),Link):
393     kwargs[self.getAttributeObject("data17").getAttributeName()]=self.data17
394     else:
395     kwargs["data17"]=self.data17
396     else:
397     kwargs[str(self.name17)]=self.data17
398    
399    
400 gross 917 if isinstance(self.data18, Data):
401 gross 912 if self.name18 == None:
402     if isinstance(self.getAttributeObject("data18"),Link):
403     kwargs[self.getAttributeObject("data18").getAttributeName()]=self.data18
404     else:
405     kwargs["data18"]=self.data18
406     else:
407     kwargs[str(self.name18)]=self.data18
408    
409    
410 gross 917 if isinstance(self.data19, Data):
411 gross 912 if self.name19 == None:
412     if isinstance(self.getAttributeObject("data19"),Link):
413     kwargs[self.getAttributeObject("data19").getAttributeName()]=self.data19
414     else:
415     kwargs["data19"]=self.data19
416     else:
417     kwargs[str(self.name19)]=self.data19
418     return kwargs
419    
420     def doInitialPostprocessing(self):
421     """
422     writes vtk file at the end of initial iteration
423     """
424     super(WriteVTK,self).doInitialPostprocessing()
425     kwargs=self.collectData()
426     if len(kwargs)>0:
427     saveVTK(self.getFrameFileName(),**kwargs)
428     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
429    
430     def doStepPostprocessing(self, dt):
431     """
432     writes vtk file at the end of time iteration
433     """
434     super(WriteVTK,self).doStepPostprocessing(dt)
435     if self.writeFrame():
436     kwargs=self.collectData()
437     if len(kwargs)>0:
438     saveVTK(self.getFrameFileName(),**kwargs)
439     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
440    
441 jgs 148 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26