/[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 2169 by caltinay, Wed Dec 17 03:08:58 2008 UTC revision 2188 by caltinay, Tue Dec 23 04:24:03 2008 UTC
# Line 182  def saveDX(filename,domain=None,**data): Line 182  def saveDX(filename,domain=None,**data):
182          raise ValueError,"saveDX: no domain detected."          raise ValueError,"saveDX: no domain detected."
183      domain.saveDX(filename,new_data)      domain.saveDX(filename,new_data)
184    
185    def saveESD(datasetName, dataDir=".", domain=None, **data):
186        """
187        Saves L{Data} objects to files and creates an I{escript dataset} (ESD) file
188        for convenient processing/visualisation.
189    
190        Example::
191    
192            tmp = Scalar(..)
193            v = Vector(..)
194            saveESD("solution", "data", temperature=tmp, velocity=v)
195    
196        tmp, v and the domain are saved in native format in the "data"
197        directory and the file "solution.esd" is created that refers to tmp by
198        the name "temperature" and to v by the name "velocity".
199    
200        @param datasetName: name of the dataset, used to name the ESD file
201        @type datasetName: C{str}
202        @param dataDir: optional directory where the data files should be saved
203        @type dataDir: C{str}
204        @param domain: domain of the L{Data} object(s). If not specified, the
205                       domain of the given L{Data} objects is used.
206        @type domain: L{escript.Domain}
207        @keyword <name>: writes the assigned value to the file using <name> as
208                         identifier
209        @type <name>: L{Data} object.
210        @note: The data objects have to be defined on the same domain. They may not
211               be in the same L{FunctionSpace} but one cannot expect that all
212               L{FunctionSpace}s can be mixed. Typically, data on the boundary and
213               data on the interior cannot be mixed.
214        """
215        new_data = {}
216        for n,d in data.items():
217              if not d.isEmpty():
218                fs = d.getFunctionSpace()
219                domain2 = fs.getDomain()
220                if fs == escript.Solution(domain2):
221                   new_data[n]=interpolate(d,escript.ContinuousFunction(domain2))
222                elif fs == escript.ReducedSolution(domain2):
223                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
224                else:
225                   new_data[n]=d
226                if domain==None: domain=domain2
227        if domain==None:
228            raise ValueError, "saveESD: no domain detected."
229    
230        if domain.onMasterProcessor() and not os.path.isdir(dataDir):
231            os.mkdir(dataDir)
232    
233        meshFile = os.path.join(dataDir, datasetName+"_mesh")
234        domain.dump(meshFile + ".nc")
235        outputString = ""
236        if domain.onMasterProcessor():
237            outputString += "#escript datafile V1.0\n"
238            # number of timesteps (currently only 1 is supported)
239            outputString += "T=1\n"
240            # name of the mesh file
241            outputString += "M=%s\n" % meshFile
242            # number of blocks (MPI size)
243            outputString += "N=%d\n" % domain.getMPISize()
244    
245        # now add the variables
246        for varName, d in new_data.items():
247            varFile = os.path.join(dataDir, datasetName+"_"+varName)
248            d.dump(varFile + ".nc")
249            if domain.onMasterProcessor():
250                outputString += "V=%s:%s\n" % (varFile, varName)
251    
252        if domain.onMasterProcessor():
253            esdfile = open(datasetName+".esd", "w")
254            esdfile.write(outputString)
255            esdfile.close()
256    
257  def kronecker(d=3):  def kronecker(d=3):
258     """     """
259     Returns the kronecker S{delta}-symbol.     Returns the kronecker S{delta}-symbol.

Legend:
Removed from v.2169  
changed lines
  Added in v.2188

  ViewVC Help
Powered by ViewVC 1.1.26