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 |
|
|
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]): |
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 |
""" |
""" |
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 |
""" |
""" |
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 |
|
|