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

Contents of /trunk/weipa/py_src/weipa.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3037 - (show annotations)
Mon Jun 14 00:59:30 2010 UTC (9 years, 4 months ago) by caltinay
File MIME type: text/x-python
File size: 3241 byte(s)
Renamed escriptexport to weipa. Fixes #475.

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 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-2010 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 from esys.escript.util import interpolate
28 new_data={}
29 for n,d in data.items():
30 if not d.isEmpty():
31 fs=d.getFunctionSpace()
32 domain2=fs.getDomain()
33 if fs == Solution(domain2):
34 new_data[n]=interpolate(d, ContinuousFunction(domain2))
35 elif fs == ReducedSolution(domain2):
36 new_data[n]=interpolate(d, ReducedContinuousFunction(domain2))
37 else:
38 new_data[n]=d
39 if domain==None:
40 domain=domain2
41 elif not domain==domain2:
42 raise ValueError, "save: Data must be on same domain!"
43 return domain, new_data
44
45 def saveSilo(filename, cycle=0, time=0., domain=None, **data):
46 """
47 Writes `Data` objects and their mesh into a file using the Silo file
48 format.
49
50 Example::
51
52 ## Within a loop using 'cycle' as the loop counter:
53 time=...
54 tmp=Scalar(..)
55 v=Vector(..)
56 saveSilo("timestep_%02d.silo"%(cycle), cycle, time, domain,
57 temperature=tmp, velocity=v)
58
59 ``tmp`` and ``v`` are written into "timestep_XX.silo" where ``tmp`` is
60 named "temperature" and ``v`` is named "velocity". The Silo file will
61 contain the cycle number and time value as metadata.
62
63 :param filename: file name of the output file
64 :type filename: ``str``
65 :param cycle: cycle number for this data set
66 :type cycle: ``int``
67 :param time: time value for this data set
68 :type time: ``float``
69 :param domain: domain of the `Data` objects. If not specified, the domain
70 of the given `Data` objects is used.
71 :type domain: `escript.Domain`
72 :note: The data objects have to be defined on the same domain although
73 they don't have to share the same `FunctionSpace`.
74 :note: If escript was compiled without Silo support then this function
75 will throw an exception.
76 """
77 from weipacpp import _saveSilo
78 domain, newData = __checkAndFilterData(domain, data)
79 if domain==None:
80 raise ValueError,"saveSilo: no domain detected."
81
82 _saveSilo(filename, cycle, time, domain, newData)
83

  ViewVC Help
Powered by ViewVC 1.1.26