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

Diff of /trunk/escript/py_src/util.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2420 by gross, Wed May 13 02:48:39 2009 UTC revision 2421 by gross, Thu May 14 02:29:06 2009 UTC
# Line 93  def insertTaggedValues(target,**kwargs): Line 93  def insertTaggedValues(target,**kwargs):
93          target.setTaggedValue(k,kwargs[k])          target.setTaggedValue(k,kwargs[k])
94      return target      return target
95    
96  def saveVTK(filename,domain=None,**data):  def saveVTK(filename,domain=None, metadata=None, metadata_schema=None, **data):
97      """      """
98      Writes L{Data} objects and their mesh into a file using the VTK XML file      Writes L{Data} objects and their mesh into a file using the VTK XML file
99      format.      format.
# Line 102  def saveVTK(filename,domain=None,**data) Line 102  def saveVTK(filename,domain=None,**data)
102    
103          tmp=Scalar(..)          tmp=Scalar(..)
104          v=Vector(..)          v=Vector(..)
105          saveVTK("solution.vtu", temperature=tmp, velocity=v)          saveVTK("solution.xml", temperature=tmp, velocity=v)
106    
107      C{tmp} and C{v} are written into "solution.vtu" where C{tmp} is named      C{tmp} and C{v} are written into "solution.xml" where C{tmp} is named
108      "temperature" and C{v} is named "velocity".      "temperature" and C{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.xml", temperature=tmp, velocity=v, metadata="<timeStamp>1.234</timeStamp>",metadata_schema={ "gml" : "http://www.opengis.net/gml"})
115    
116        The argument C{metadata_schema} allows the definition of name spaces with a schema used in the definition of meta tags.
117    
118      @param filename: file name of the output file      @param filename: file name of the output file
119      @type filename: C{str}      @type filename: C{str}
120      @param domain: domain of the L{Data} objects. If not specified, the domain      @param domain: domain of the L{Data} objects. If not specified, the domain
# Line 114  def saveVTK(filename,domain=None,**data) Line 122  def saveVTK(filename,domain=None,**data)
122      @type domain: L{escript.Domain}      @type domain: L{escript.Domain}
123      @keyword <name>: writes the assigned value to the VTK file using <name> as      @keyword <name>: writes the assigned value to the VTK file using <name> as
124                       identifier                       identifier
125      @type <name>: L{Data} object      @param metadata: additional XML meta data which are inserted into the VTK file. The meta data are marked by the tag C{<MetaData>}.
126        @type metadata: C{str}
127        @param metadata_schema: assignes schema to namespaces which have been used to define  meta data.
128        @type metadata_schema: C{dict} with C{metadata_schema[<namespace>]=<URI>} to assign the scheme C{<URI>} to the name space C{<namespace>}.
129      @note: The data objects have to be defined on the same domain. They may not      @note: The data objects have to be defined on the same domain. They may not
130             be in the same L{FunctionSpace} but one cannot expect that all             be in the same L{FunctionSpace} but one cannot expect that all
131             L{FunctionSpace}s can be mixed. Typically, data on the boundary and             L{FunctionSpace}s can be mixed. Typically, data on the boundary and
132             data on the interior cannot be mixed.             data on the interior cannot be mixed.
133      """      """
134        # create the string if meta data:
135        if not metadata==None:
136            metadata2="<MetaData>"+metadata+"</MetaData>"
137        else:
138            metadata2=""
139        metadata_shema2=""
140        if not metadata_schema==None:
141             for i,p in metadata_schema.items():
142                 metadata_shema2="%s xmlns:%s=\"%s\""%(metadata_shema2,i,p)
143      new_data={}      new_data={}
144      for n,d in data.items():      for n,d in data.items():
145            if not d.isEmpty():            if not d.isEmpty():
# Line 134  def saveVTK(filename,domain=None,**data) Line 154  def saveVTK(filename,domain=None,**data)
154              if domain==None: domain=domain2              if domain==None: domain=domain2
155      if domain==None:      if domain==None:
156          raise ValueError,"saveVTK: no domain detected."          raise ValueError,"saveVTK: no domain detected."
157      domain.saveVTK(filename,new_data)      domain.saveVTK(filename,new_data,metadata2.strip(),metadata_shema2.strip())
158    
159  def saveDX(filename,domain=None,**data):  def saveDX(filename,domain=None,**data):
160      """      """

Legend:
Removed from v.2420  
changed lines
  Added in v.2421

  ViewVC Help
Powered by ViewVC 1.1.26