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

Annotation of /trunk/weipa/py_src/__init__.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4114 - (hide annotations)
Fri Dec 14 04:24:46 2012 UTC (6 years, 10 months ago) by caltinay
File MIME type: text/x-python
File size: 6526 byte(s)
Time to remove deprecated saveVTK/DX methods from Data and Domain.

1 caltinay 2812
2 jfenwick 3981 ##############################################################################
3 caltinay 2812 #
4 jfenwick 3911 # Copyright (c) 2003-2012 by University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 caltinay 2812 #
7     # Primary Business: Queensland, Australia
8     # Licensed under the Open Software License version 3.0
9     # http://www.opensource.org/licenses/osl-3.0.php
10     #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     # Development since 2012 by School of Earth Sciences
13     #
14     ##############################################################################
15 caltinay 2812
16 jfenwick 3911 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
17 jfenwick 3981 http://www.uq.edu.au
18 caltinay 2812 Primary Business: Queensland, Australia"""
19     __license__="""Licensed under the Open Software License version 3.0
20     http://www.opensource.org/licenses/osl-3.0.php"""
21     __url__="https://launchpad.net/escript-finley"
22    
23 jfenwick 3892 from .weipacpp import visitInitialize, visitPublishData
24 caltinay 3364
25 caltinay 3344 def interpolateEscriptData(domain, data):
26     """
27     esys.weipa does not support the function spaces Solution and
28     ReducedSolution. This function interpolates Data defined on those function
29     spaces to compatible alternatives.
30     """
31     from esys.escript import Solution, ReducedSolution
32     from esys.escript import ContinuousFunction, ReducedContinuousFunction
33     from esys.escript.util import interpolate
34     new_data={}
35 jfenwick 3775 for n,d in list(data.items()):
36 caltinay 3344 if not d.isEmpty():
37     fs=d.getFunctionSpace()
38     if domain is None:
39     domain=fs.getDomain()
40     elif domain != fs.getDomain():
41     raise ValueError("weipa: All Data must be on the same domain!")
42     if fs == Solution(domain):
43     new_data[n]=interpolate(d, ContinuousFunction(domain))
44     elif fs == ReducedSolution(domain):
45     new_data[n]=interpolate(d, ReducedContinuousFunction(domain))
46     else:
47     new_data[n]=d
48     return domain,new_data
49    
50     def createDataset(domain=None, **data):
51     """
52     Creates and returns an esys.weipa dataset consisting of a Domain and Data
53     objects. The returned object provides methods to access and export data.
54     """
55 jfenwick 3892 from .weipacpp import EscriptDataset
56 caltinay 3344 dataset=EscriptDataset()
57     domain,new_data=interpolateEscriptData(domain, data)
58     dataset.setDomain(domain)
59 jfenwick 3775 for n,d in sorted(new_data.items()):
60 caltinay 3344 #TODO: data units are not supported here yet
61     dataset.addData(d, n, "")
62     return dataset
63    
64 caltinay 3623 def saveSilo(filename, domain=None, write_meshdata=False, **data):
65 caltinay 3344 """
66     Writes `Data` objects and their mesh to a file using the SILO file format.
67    
68     Example::
69    
70     temp=Scalar(..)
71     v=Vector(..)
72     saveSilo("solution.silo", temperature=temp, velocity=v)
73    
74     ``temp`` and ``v`` are written to "solution.silo" where ``temp`` is named
75     "temperature" and ``v`` is named "velocity".
76    
77     :param filename: name of the output file ('.silo' is added if required)
78     :type filename: ``str``
79     :param domain: domain of the `Data` objects. If not specified, the domain
80     of the given `Data` objects is used.
81     :type domain: `escript.Domain`
82 caltinay 3623 :param write_meshdata: whether to save mesh-related data such as element
83     identifiers, ownership etc. This is mainly useful
84     for debugging.
85     :type write_meshdata: ``bool``
86 caltinay 3344 :keyword <name>: writes the assigned value to the Silo file using <name> as
87     identifier
88     :note: All data objects have to be defined on the same domain but they may
89     be defined on separate `FunctionSpace` s.
90     """
91    
92     dataset = createDataset(domain, **data)
93 caltinay 3623 dataset.setSaveMeshData(write_meshdata)
94 caltinay 3627 return dataset.saveSilo(filename)
95 caltinay 3344
96 caltinay 3623 def saveVTK(filename, domain=None, metadata='', metadata_schema=None, write_meshdata=False, **data):
97 caltinay 3344 """
98     Writes `Data` objects and their mesh to a file using the VTK XML file
99     format.
100    
101     Example::
102    
103     temp=Scalar(..)
104     v=Vector(..)
105     saveVTK("solution.vtu", temperature=temp, velocity=v)
106    
107     ``temp`` and ``v`` are written to "solution.vtu" where ``temp`` is named
108     "temperature" and ``v`` is named "velocity".
109    
110     Meta tags, e.g. a timeStamp, can be added to the file, for instance::
111    
112     tmp=Scalar(..)
113     v=Vector(..)
114     saveVTK("solution.vtu", temperature=tmp, velocity=v,
115     metadata="<timeStamp>1.234</timeStamp>",
116     metadata_schema={"gml":"http://www.opengis.net/gml"})
117    
118     The argument ``metadata_schema`` allows the definition of name spaces with
119     a schema used in the definition of meta tags.
120    
121     :param filename: name of the output file ('.vtu' is added if required)
122     :type filename: ``str``
123     :param domain: domain of the `Data` objects. If not specified, the domain
124     of the given `Data` objects is used.
125     :type domain: `escript.Domain`
126     :keyword <name>: writes the assigned value to the VTK file using <name> as
127     identifier
128     :param metadata: additional XML meta data which are inserted into the VTK
129     file. The meta data are marked by the tag ``<MetaData>``.
130     :type metadata: ``str``
131     :param metadata_schema: assigns schemas to namespaces which have been used
132     to define meta data.
133     :type metadata_schema: ``dict`` with ``metadata_schema[<namespace>]=<URI>``
134     to assign the scheme ``<URI>`` to the name space
135     ``<namespace>``.
136 caltinay 3623 :param write_meshdata: whether to save mesh-related data such as element
137     identifiers, ownership etc. This is mainly useful
138     for debugging.
139     :type write_meshdata: ``bool``
140 caltinay 3344 :note: All data objects have to be defined on the same domain. They may not
141     be in the same `FunctionSpace` but not all combinations of
142     `FunctionSpace` s can be written to a single VTK file.
143     Typically, data on the boundary and on the interior cannot be mixed.
144     """
145    
146     dataset = createDataset(domain, **data)
147     ss=''
148     ms=''
149     if not metadata is None:
150     ms=metadata
151     if not metadata_schema is None:
152     if hasattr(metadata_schema, 'items'):
153 jfenwick 3775 for i,p in list(metadata_schema.items()):
154 caltinay 3344 ss="%s xmlns:%s=\"%s\""%(ss, i, p)
155     else:
156     ss=metadata_schema
157     dataset.setMetadataSchemaString(ss.strip(), ms.strip())
158 caltinay 3623 dataset.setSaveMeshData(write_meshdata)
159     return dataset.saveVTK(filename)
160 caltinay 3344

  ViewVC Help
Powered by ViewVC 1.1.26