diff --git a/src/maths/types.nim b/src/maths/types.nim index 7fc84c2..42c56d6 100644 --- a/src/maths/types.nim +++ b/src/maths/types.nim @@ -267,7 +267,7 @@ template declaredVector*(x:ToSingle):untyped = isVector(x[]) template declaredMatrix*(x:ToSingle):untyped = isMatrix(x[]) template re*(x: ToSingle): untyped = toSingle(x[].re) template im*(x: ToSingle): untyped = toSingle(x[].im) -template simdType*(x: ToSingle): untyped = simdType(x[]) +#template simdType*(x: ToSingle): untyped = simdType(x[]) template numberType*(x: ToSingle): untyped = float32 type @@ -328,7 +328,7 @@ template declaredVector*(x:ToDouble):untyped = isVector(x[]) template declaredMatrix*(x:ToDouble):untyped = isMatrix(x[]) template re*(x:ToDouble):untyped = toDouble(x[].re) template im*(x:ToDouble):untyped = toDouble(x[].im) -template simdType*(x: ToDouble): untyped = simdType(x[]) +#template simdType*(x: ToDouble): untyped = simdType(x[]) #macro dump2(x: typed): auto = # result = newEmptyNode() # echo x.treerepr @@ -505,7 +505,7 @@ forwardFunc(Indexed, norm2) template len*(x:Indexed):untyped = obj(x).len # FIXME Simd types can use Indexed template nrows*(x:Indexed):untyped = obj(x).nrows template ncols*(x:Indexed):untyped = obj(x).ncols -template simdType*(x: Indexed): untyped = simdType(obj(x)) +#template simdType*(x: Indexed): untyped = simdType(obj(x)) template numberType*(x: Indexed): untyped = numberType(obj(x)) #template declaredVector*(x:Indexed):untyped = isVector(x.obj) #template declaredMatrix*(x:Indexed):untyped = isMatrix(x.obj) diff --git a/src/physics/colorTensor.nim b/src/physics/colorTensor.nim index e9d8bfa..306baf8 100644 --- a/src/physics/colorTensor.nim +++ b/src/physics/colorTensor.nim @@ -8,6 +8,7 @@ type Color3*[T] = Color[T] Color4*[T] = Color[T] +proc has*(t: typedesc[ColorType], x: typedesc): bool = x is ColorType #[ template getNc*[K,T](x: SomeTensor[K,T]): int = when K is ColorType: diff --git a/src/physics/spin.nim b/src/physics/spin.nim index 2a07f1b..fc8ef84 100644 --- a/src/physics/spin.nim +++ b/src/physics/spin.nim @@ -1,5 +1,5 @@ -import spinOld -export spinOld +#import spinOld +#export spinOld -#import spinTensor -#export spinTensor +import spinTensor +export spinTensor diff --git a/src/physics/spinTensor.nim b/src/physics/spinTensor.nim new file mode 100644 index 0000000..2841256 --- /dev/null +++ b/src/physics/spinTensor.nim @@ -0,0 +1,306 @@ +import tensorwrap +export tensorwrap +import maths/[complexType, matrixConcept] + +type + SpinType* = object + Spin*[T] = TensorObj[SpinType,T] + Spin2*[T] = Spin[T] + Spin3*[T] = Spin[T] + Spin4*[T] = Spin[T] +template asSpin*[T](x: typedesc[T]): typedesc = Spin[T] +template asSpin*[T](x: T): auto = Spin[T](obj: x) + +template spinVector*(x: static[int], a: untyped): untyped = + #const + # I:int = x + #type + # E = T + # VA = VectorArray[I,E] + # VAO = VectorArrayObj[I,E] + #Spin[VA](v: VA(v: a)) + #Spin[VA](v: VA(v: VAO(vec: a))) + #asSpin(VA(v: a)) + #static: echo "spinVector" + asSpin(asVectorArray(a)) + #let t1 = asVectorArray(a) + #static: echo "spinVector1" + #let t = asSpin(t1) + #static: echo "spinVector2" + #t +template spinVector*[T](x: static[int], a: typedesc[T]): untyped = + asSpin(asVectorArray(x, type T)) +template spinMatrix*[T](x,y:static[int], a: untyped): untyped = + const + I:int = x + J:int = y + type + E = T + #MA = MatrixArray[I,J,E] + MAO = MatrixArrayObj[I,J,E] + asSpin(asMatrix(MAO(mat: a))) +#template spinMatrix*[I,J:static[int],T](a: untyped): untyped = +# Spin[MatrixArray[I,J,T]](v: MatrixArray[I,J,T](v: MatrixArrayObj[I,J,T](mat: a))) +#template spinMatrix*(I,J,T,a: untyped): untyped = +# Spin[MatrixArray[I,J,T]](v: MatrixArray[I,J,T](v: MatrixArrayObj[I,J,T](mat: a))) + +const z0 = newComplex( 0.0, 0.0) +const z1 = newComplex( 1.0, 0.0) +const zi = newComplex( 0.0, 1.0) +const n1 = newComplex(-1.0, 0.0) +const ni = newComplex( 0.0, -1.0) + +template s(r,c,x: untyped): untyped = + spinMatrix[ComplexType[float]](r,c,x) +template g(x: untyped): untyped = s(4,4,x) +template p(x: untyped): untyped = s(2,4,x) +template r(x: untyped): untyped = s(4,2,x) + +const + gamma0* = g([[ z1, z0, z0, z0 ], + [ z0, z1, z0, z0 ], + [ z0, z0, z1, z0 ], + [ z0, z0, z0, z1 ]]) + gamma1* = g([[ z0, z0, z0, zi ], + [ z0, z0, zi, z0 ], + [ z0, ni, z0, z0 ], + [ ni, z0, z0, z0 ]]) + gamma2* = g([[ z0, z0, z0, n1 ], + [ z0, z0, z1, z0 ], + [ z0, z1, z0, z0 ], + [ n1, z0, z0, z0 ]]) + gamma3* = g([[ z0, z0, zi, z0 ], + [ z0, z0, z0, ni ], + [ ni, z0, z0, z0 ], + [ z0, zi, z0, z0 ]]) + gamma4* = g([[ z0, z0, z1, z0 ], + [ z0, z0, z0, z1 ], + [ z1, z0, z0, z0 ], + [ z0, z1, z0, z0 ]]) + gamma5* = g([[ z1, z0, z0, z0 ], + [ z0, z1, z0, z0 ], + [ z0, z0, n1, z0 ], + [ z0, z0, z0, n1 ]]) + + spprojmat1p* = p([[ z1, z0, z0, zi ], + [ z0, z1, zi, z0 ]]) + spprojmat1m* = p([[ z1, z0, z0, ni ], + [ z0, z1, ni, z0 ]]) + spprojmat2p* = p([[ z1, z0, z0, n1 ], + [ z0, z1, z1, z0 ]]) + spprojmat2m* = p([[ z1, z0, z0, z1 ], + [ z0, z1, n1, z0 ]]) + spprojmat3p* = p([[ z1, z0, zi, z0 ], + [ z0, z1, z0, ni ]]) + spprojmat3m* = p([[ z1, z0, ni, z0 ], + [ z0, z1, z0, zi ]]) + spprojmat4p* = p([[ z1, z0, z1, z0 ], + [ z0, z1, z0, z1 ]]) + spprojmat4m* = p([[ z1, z0, n1, z0 ], + [ z0, z1, z0, n1 ]]) + + spreconmat1p* = r([[ z1, z0 ], + [ z0, z1 ], + [ z0, ni ], + [ ni, z0 ]]) + spreconmat1m* = r([[ z1, z0 ], + [ z0, z1 ], + [ z0, zi ], + [ zi, z0 ]]) + spreconmat2p* = r([[ z1, z0 ], + [ z0, z1 ], + [ z0, z1 ], + [ n1, z0 ]]) + spreconmat2m* = r([[ z1, z0 ], + [ z0, z1 ], + [ z0, n1 ], + [ z1, z0 ]]) + spreconmat3p* = r([[ z1, z0 ], + [ z0, z1 ], + [ ni, z0 ], + [ z0, zi ]]) + spreconmat3m* = r([[ z1, z0 ], + [ z0, z1 ], + [ zi, z0 ], + [ z0, ni ]]) + spreconmat4p* = r([[ z1, z0 ], + [ z0, z1 ], + [ z1, z0 ], + [ z0, z1 ]]) + spreconmat4m* = r([[ z1, z0 ], + [ z0, z1 ], + [ n1, z0 ], + [ z0, n1 ]]) + +template I(x: typed): untyped = + newImag(1)*x +template mI(x: typed): untyped = + newImag(-1)*x + +proc spproj1p*(r: var auto, x: auto) = + ## r: HalfFermion + ## x: DiracFermion + #let nc = x[0].len + #for i in 0..