def dyadicProduct(self, other): "Returns the dyadic product with vector or tensor |other|." if isVector(other): return TensorModule.Tensor(self.array, 1) * \ TensorModule.Tensor(other.array, 1) elif TensorModule.isTensor(other): return TensorModule.Tensor(self.array, 1)*other else: raise TypeError, "Dyadic product with non-vector"
def __rmul__(self, other): if TensorModule.isTensor(other): product = other.dot(TensorModule.Tensor(self.array)) if product.rank == 1: return Vector(product.array) else: return product else: return Vector(Numeric.multiply(self.array, other))
def __mul__(self, other): if isVector(other): return Numeric.add.reduce(self.array*other.array) elif TensorModule.isTensor(other): product = TensorModule.Tensor(self.array).dot(other) if product.rank == 1: return Vector(product.array) else: return product elif hasattr(other, "_product_with_vector"): return other._product_with_vector(self) else: return Vector(Numeric.multiply(self.array, other))
def __init__(self, *args): if len(args) == 1: self.tensor = args[0] if not TensorModule.isTensor(self.tensor): self.tensor = TensorModule.Tensor(self.tensor) elif len(args) == 2: axis, angle = args axis = axis.normal() projector = axis.dyadicProduct(axis) self.tensor = projector - \ Numeric.sin(angle)*TensorModule.epsilon*axis + \ Numeric.cos(angle)*(TensorModule.delta-projector) else: raise TypeError, 'one or two arguments required'
def testType(self): if not HAVE_SYMPY: return self.assertEqual(TensorModule.isTensor(self.U), 1)