def __rmul__(self, other): from Scientific import Geometry if Geometry.isTensor(other): product = other.dot(Geometry.Tensor(self.array)) if product.rank == 1: return Vector(product.array) else: return product else: return Vector(Numeric.multiply(self.array, other))
def __init__(self, *args): if len(args) == 1: if Geometry.isTensor(args[0]): self.tensor = args[0] else: self.tensor = Geometry.Tensor(args[0]) assert self.tensor.rank == 2 elif len(args) == 3 and Geometry.isVector(args[0]) \ and Geometry.isVector(args[1]) and Geometry.isVector(args[2]): self.tensor = Geometry.Tensor( [args[0].array, args[1].array, args[2].array]).transpose()
def __init__(self, *args): if len(args) == 1: if Geometry.isTensor(args[0]): self.tensor = args[0] else: self.tensor = Geometry.Tensor(args[0]) assert self.tensor.rank == 2 elif len(args) == 3 and Geometry.isVector(args[0]) \ and Geometry.isVector(args[1]) and Geometry.isVector(args[2]): self.tensor = Geometry.Tensor([args[0].array, args[1].array, args[2].array]).transpose()
def __mul__(self, other): from Scientific import Geometry if isVector(other): return Numeric.add.reduce(self.array * other.array) elif Geometry.isTensor(other): product = Geometry.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 __mul__(self, other): from Scientific import Geometry if isVector(other): return Numeric.add.reduce(self.array*other.array) elif Geometry.isTensor(other): product = Geometry.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 dyadicProduct(self, other): """ @param other: a vector or a tensor @type other: L{Vector} or L{Scientific.Geometry.Tensor} @returns: the dyadic product with other @rtype: L{Scientific.Geometry.Tensor} @raises TypeError: if other is not a vector or a tensor """ from Scientific import Geometry if isVector(other): return Geometry.Tensor( self.array[:, N.NewAxis] * other.array[N.NewAxis, :], 1) elif Geometry.isTensor(other): return Geometry.Tensor(self.array, 1) * other else: raise TypeError("Dyadic product with non-vector")
def dyadicProduct(self, other): """ @param other: a vector or a tensor @type other: L{Vector} or L{Scientific.Geometry.Tensor} @returns: the dyadic product with other @rtype: L{Scientific.Geometry.Tensor} @raises TypeError: if other is not a vector or a tensor """ from Scientific import Geometry if isVector(other): return Geometry.Tensor(self.array, 1) * \ Geometry.Tensor(other.array, 1) elif Geometry.isTensor(other): return Geometry.Tensor(self.array, 1)*other else: raise TypeError("Dyadic product with non-vector")
def __init__(self, *args): """ There are two calling patterns: - Rotation(tensor), where tensor is a L{Scientific.Geometry.Tensor} of rank 2 containing the rotation matrix. - Rotation(axis, angle), where axis is a L{Scientific.Geometry.Vector} and angle a number (the angle in radians). """ if len(args) == 1: self.tensor = args[0] if not Geometry.isTensor(self.tensor): self.tensor = Geometry.Tensor(self.tensor) elif len(args) == 2: axis, angle = args axis = axis.normal() projector = axis.dyadicProduct(axis) self.tensor = projector - \ N.sin(angle)*Geometry.epsilon*axis + \ N.cos(angle)*(Geometry.delta-projector) else: raise TypeError('one or two arguments required')
def __init__(self, *args): """ There are two calling patterns: - Rotation(tensor), where tensor is a L{Scientific.Geometry.Tensor} of rank 2 containing the rotation matrix. - Rotation(axis, angle), where axis is a L{Scientific.Geometry.Vector} and angle a number (the angle in radians). """ if len(args) == 1: self.tensor = args[0] if not Geometry.isTensor(self.tensor): self.tensor = Geometry.Tensor(self.tensor) elif len(args) == 2: axis, angle = args axis = axis.normal() projector = axis.dyadicProduct(axis) self.tensor = projector - \ Numeric.sin(angle)*Geometry.epsilon*axis + \ Numeric.cos(angle)*(Geometry.delta-projector) else: raise TypeError('one or two arguments required')