/[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 3851 by caltinay, Mon Jan 30 04:41:33 2012 UTC revision 3852 by jfenwick, Thu Mar 1 05:34:52 2012 UTC
# Line 98  def insertTaggedValues(target,**kwargs): Line 98  def insertTaggedValues(target,**kwargs):
98    
99  def interpolateTable(tab, dat, start, step, undef=1.e50, check_boundaries=False):  def interpolateTable(tab, dat, start, step, undef=1.e50, check_boundaries=False):
100      try:      try:
101      dim=len(start)          dim=len(start)
102      except TypeError:      except TypeError:
103      start=(start,)          start=(start,)
104      dim=1          dim=1
105      try:      try:
106      slen=len(step)          slen=len(step)
107      except TypeError:      except TypeError:
108      step=(step,)          step=(step,)
109      slen=1          slen=1
110      if dim<1 or dim>3:      if dim<1 or dim>3:
111      raise ValueError("Length of start list must be between 1 and 3.")          raise ValueError("Length of start list must be between 1 and 3.")
112      if dim!=slen:      if dim!=slen:
113      raise ValueError("Length of start and step must be the same.")          raise ValueError("Length of start and step must be the same.")
114      dshape=dat.getShape()      dshape=dat.getShape()
115      if len(dshape)==0:      if len(dshape)==0:
116      datdim=0          datdim=0
117      firstdim=dat          firstdim=dat
118      else:      else:
119      datdim=dshape[0]          datdim=dshape[0]
120      firstdim=dat[0]          firstdim=dat[0]
121      #So now we know firstdim is a scalar      #So now we know firstdim is a scalar
122      if (dim==1 and datdim>1) or (dim>1 and datdim!=dim):      if (dim==1 and datdim>1) or (dim>1 and datdim!=dim):
123      print((dim, datdim))          print((dim, datdim))
124      raise ValueError("The dimension of dat must be equal to the length of start.")          raise ValueError("The dimension of dat must be equal to the length of start.")
125      if dim==3:      if dim==3:
126      d1=dat[1]          d1=dat[1]
127      d2=dat[2]          d2=dat[2]
128      return firstdim._interpolateTable3d(tab, start[0], step[0], d1, start[1], step[1], d2, start[2], step[2], undef, check_boundaries)          return firstdim._interpolateTable3d(tab, start[0], step[0], d1, start[1], step[1], d2, start[2], step[2], undef, check_boundaries)
129      if dim==2:      if dim==2:
130      d1=dat[1]          d1=dat[1]
131      return firstdim.interpolateTable(tab, start[0], step[0], d1, start[1], step[1], undef, check_boundaries)          return firstdim.interpolateTable(tab, start[0], step[0], d1, start[1], step[1], undef, check_boundaries)
132  #   return d1.interpolateTable(tab, start[1], step[1], firstdim, start[0], step[0], undef, check_boundaries)  #   return d1.interpolateTable(tab, start[1], step[1], firstdim, start[0], step[0], undef, check_boundaries)
133      else:      else:
134      return firstdim.interpolateTable(tab, start[0], step[0], undef, check_boundaries)          return firstdim.interpolateTable(tab, start[0], step[0], undef, check_boundaries)
135    
136    
137  def saveDataCSV(filename, append=False, sep=", ", csep="_", **data):  def saveDataCSV(filename, append=False, sep=", ", csep="_", **data):
# Line 171  def saveDataCSV(filename, append=False, Line 171  def saveDataCSV(filename, append=False,
171      # find a function space:      # find a function space:
172      fs = None      fs = None
173      for n,d in list(data.items()):      for n,d in list(data.items()):
174      if isinstance(d, Data): fs=d.getFunctionSpace()          if isinstance(d, Data): fs=d.getFunctionSpace()
175      if fs == None:      if fs == None:
176      raise ValueError("saveDataCSV: there must be at least one Data object in the argument list.")          raise ValueError("saveDataCSV: there must be at least one Data object in the argument list.")
177            
178      new_data={}      new_data={}
179      for n,d in list(data.items()):      for n,d in list(data.items()):
180      if isinstance(d, Data):          if isinstance(d, Data):
181              new_data[n]=d              new_data[n]=d
182          else:          else:
183              try:              try:
184                 new_data[n]=Data(d,fs)                 new_data[n]=Data(d,fs)
185              except:              except:
186             raise ValueError("saveDataCSV: unknown non-data argument type for %s"%(str(n)))                 raise ValueError("saveDataCSV: unknown non-data argument type for %s"%(str(n)))
187      _saveDataCSV(filename, new_data,sep, csep, append)      _saveDataCSV(filename, new_data,sep, csep, append)
188    
189  def saveVTK(filename,domain=None, metadata=None, metadata_schema=None, **data):  def saveVTK(filename,domain=None, metadata=None, metadata_schema=None, **data):
# Line 4786  def maximum(*args): Line 4786  def maximum(*args):
4786            out=a*1.            out=a*1.
4787         else:         else:
4788            if isinstance(out,escript.Data) and isinstance(a,escript.Data):            if isinstance(out,escript.Data) and isinstance(a,escript.Data):
4789           if out.getRank()==0 and a.getRank()>0:               if out.getRank()==0 and a.getRank()>0:
4790          #We need to consider the case where we have scalars and higher          #We need to consider the case where we have scalars and higher
4791          #ranked objects mixed. If the scalar was first it will get          #ranked objects mixed. If the scalar was first it will get
4792          #picked as the initial out and we have a problem,          #picked as the initial out and we have a problem,

Legend:
Removed from v.3851  
changed lines
  Added in v.3852

  ViewVC Help
Powered by ViewVC 1.1.26