/[escript]/trunk/dataexporter/py_src/dataexporter.py
ViewVC logotype

Contents of /trunk/dataexporter/py_src/dataexporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2812 - (show annotations)
Tue Dec 8 00:12:07 2009 UTC (11 years, 6 months ago) by caltinay
File MIME type: text/x-python
File size: 3203 byte(s)
Implemented saveSilo within a new dataexporter module. If Silo is not available
at compile time the function throws. Ultimately, saveVTK will be moved here as
well.

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2009 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2009 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 def __checkAndFilterData(domain, data):
23 # (Reduced)Solution is not directly supported so interpolate to different
24 # function space and ensure all data is defined on same domain
25 from esys.escript import Solution, ReducedSolution
26 from esys.escript import ContinuousFunction, ReducedContinuousFunction
27 new_data={}
28 for n,d in data.items():
29 if not d.isEmpty():
30 fs=d.getFunctionSpace()
31 domain2=fs.getDomain()
32 if fs == Solution(domain2):
33 new_data[n]=interpolate(d, ContinuousFunction(domain2))
34 elif fs == ReducedSolution(domain2):
35 new_data[n]=interpolate(d, ReducedContinuousFunction(domain2))
36 else:
37 new_data[n]=d
38 if domain==None:
39 domain=domain2
40 elif not domain==domain2:
41 raise ValueError, "save: Data must be on same domain!"
42 return domain, new_data
43
44 def saveSilo(filename, cycle=0, time=0., domain=None, **data):
45 """
46 Writes `Data` objects and their mesh into a file using the Silo file
47 format.
48
49 Example::
50
51 ## Within a loop using 'cycle' as the loop counter:
52 time=...
53 tmp=Scalar(..)
54 v=Vector(..)
55 saveSilo("timestep_%02d.silo"%(cycle), cycle, time, domain,
56 temperature=tmp, velocity=v)
57
58 ``tmp`` and ``v`` are written into "timestep_XX.silo" where ``tmp`` is
59 named "temperature" and ``v`` is named "velocity". The Silo file will
60 contain the cycle number and time value as metadata.
61
62 :param filename: file name of the output file
63 :type filename: ``str``
64 :param cycle: cycle number for this data set
65 :type cycle: ``int``
66 :param time: time value for this data set
67 :type time: ``float``
68 :param domain: domain of the `Data` objects. If not specified, the domain
69 of the given `Data` objects is used.
70 :type domain: `escript.Domain`
71 :note: The data objects have to be defined on the same domain although
72 they don't have to share the same `FunctionSpace`.
73 :note: If escript was compiled without Silo support then this function
74 will throw an exception.
75 """
76 from escriptexportcpp import _saveSilo
77 domain, newData = __checkAndFilterData(domain, data)
78 if domain==None:
79 raise ValueError,"saveSilo: no domain detected."
80
81 _saveSilo(filename, cycle, time, domain, newData)
82

  ViewVC Help
Powered by ViewVC 1.1.26