/[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 441 by gross, Fri Jan 20 03:40:39 2006 UTC revision 442 by gross, Fri Jan 20 04:39:43 2006 UTC
# Line 117  def kronecker(d=3): Line 117  def kronecker(d=3):
117     return the kronecker S{delta}-symbol     return the kronecker S{delta}-symbol
118    
119     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the dimension
120     @type d: C{int} or any object with a C{getDim} method     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
121     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise
122     @rtype d: L{numarray.NumArray} of rank 2.     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 2.
    @remark: the function is identical L{identity}  
123     """     """
124     return identityTensor(d)     return identityTensor(d)
125    
# Line 139  def identity(shape=()): Line 138  def identity(shape=()):
138        if len(shape)==1:        if len(shape)==1:
139            for i0 in range(shape[0]):            for i0 in range(shape[0]):
140               out[i0,i0]=1.               out[i0,i0]=1.
   
141        elif len(shape)==2:        elif len(shape)==2:
142            for i0 in range(shape[0]):            for i0 in range(shape[0]):
143               for i1 in range(shape[1]):               for i1 in range(shape[1]):
# Line 155  def identityTensor(d=3): Line 153  def identityTensor(d=3):
153     return the dxd identity matrix     return the dxd identity matrix
154    
155     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the dimension
156     @type d: C{int} or any object with a C{getDim} method     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
157     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise
158     @rtype: L{numarray.NumArray} of rank 2.     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 2
159     """     """
160     if hasattr(d,"getDim"):     if isinstance(d,escript.FunctionSpace):
161        d=d.getDim()         return escript.Data(identity((d.getDim(),)),d)
162     return identity(shape=(d,))     elif isinstance(d,escript.Domain):
163           return identity((d.getDim(),))
164       else:
165           return identity((d,))
166    
167  def identityTensor4(d=3):  def identityTensor4(d=3):
168     """     """
# Line 170  def identityTensor4(d=3): Line 171  def identityTensor4(d=3):
171     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the dimension
172     @type d: C{int} or any object with a C{getDim} method     @type d: C{int} or any object with a C{getDim} method
173     @return: the object u of rank 4 with M{u[i,j,k,l]=1} for M{i=k and j=l} and M{u[i,j,k,l]=0} otherwise     @return: the object u of rank 4 with M{u[i,j,k,l]=1} for M{i=k and j=l} and M{u[i,j,k,l]=0} otherwise
174     @rtype: L{numarray.NumArray} of rank 4.     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 4.
175     """     """
176     if hasattr(d,"getDim"):     if isinstance(d,escript.FunctionSpace):
177        d=d.getDim()         return escript.Data(identity((d.getDim(),d.getDim())),d)
178     return identity((d,d))     elif isinstance(d,escript.Domain):
179           return identity((d.getDim(),d.getDim()))
180       else:
181           return identity((d,d))
182    
183  def unitVector(i=0,d=3):  def unitVector(i=0,d=3):
184     """     """
# Line 183  def unitVector(i=0,d=3): Line 187  def unitVector(i=0,d=3):
187     @param i: index     @param i: index
188     @type i: C{int}     @type i: C{int}
189     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the dimension
190     @type d: C{int} or any object with a C{getDim} method     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
191     @return: the object u of rank 1 with M{u[j]=1} for M{j=i} and M{u[i]=0} otherwise     @return: the object u of rank 1 with M{u[j]=1} for M{j=i} and M{u[i]=0} otherwise
192     @rtype: L{numarray.NumArray} of rank 1.     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 1
193     """     """
194     return kronecker(d)[i]     return kronecker(d)[i]
195    

Legend:
Removed from v.441  
changed lines
  Added in v.442

  ViewVC Help
Powered by ViewVC 1.1.26