QDP++
qdp_primcolormat.h
Go to the documentation of this file.
1// -*- C++ -*-
2
6
7
8#ifndef QDP_PRIMCOLORMAT_H
9#define QDP_PRIMCOLORMAT_H
10
11namespace QDP {
12
13
14//-------------------------------------------------------------------------------------
22
23
25template <class T, int N> class PColorMatrix : public PMatrix<T, N, PColorMatrix>
26{
27public:
29
30 template<class T1>
31 inline
33 {
34 this->assign(rhs);
35 return *this;
36 }
37
39
40 template<class T1>
41 inline
43 {
44 this->assign(rhs);
45 return *this;
46 }
47
48};
49 // end of group primcolormatrix
51
52//-----------------------------------------------------------------------------
53// Traits classes
54//-----------------------------------------------------------------------------
55
56// Underlying word type
57template<class T1, int N>
58struct WordType<PColorMatrix<T1,N> >
59{
60 typedef typename WordType<T1>::Type_t Type_t;
61};
62
63// Fixed Precisions
64template<class T1, int N>
69
70template<class T1, int N>
75
76
77
78// Internally used scalars
79template<class T, int N>
83
84// Makes a primitive into a scalar leaving grid along
85template<class T, int N>
89
90// Makes a lattice scalar leaving primitive indices along
91template<class T, int N>
95
96//-----------------------------------------------------------------------------
97// Traits classes to support return types
98//-----------------------------------------------------------------------------
99
100// Default unary(PColorMatrix) -> PColorMatrix
101template<class T1, int N, class Op>
105
106// Default binary(PScalar,PColorMatrix) -> PColorMatrix
107template<class T1, class T2, int N, class Op>
111
112// Default binary(PColorMatrix,PColorMatrix) -> PColorMatrix
113template<class T1, class T2, int N, class Op>
117
118// Default binary(PColorMatrix,PScalar) -> PColorMatrix
119template<class T1, int N, class T2, class Op>
123
124
125// Assignment is different
126template<class T1, class T2, int N>
130
131template<class T1, class T2, int N>
135
136template<class T1, class T2, int N>
140
141template<class T1, class T2, int N>
145
146
147template<class T1, class T2, int N>
151
152template<class T1, class T2, int N>
156
157template<class T1, class T2, int N>
161
162template<class T1, class T2, int N>
166
167template<class T1, class T2, int N>
171
172
173
174// ColorMatrix
175template<class T, int N>
179
180template<class T, int N>
184
185template<class T, int N>
189
190template<class T, int N>
194
195template<class T, int N>
199
200template<class T, int N>
204
205template<class T1, class T2, int N>
209
210template<class T1, class T2, int N>
214
215template<class T1, class T2, int N>
219
220template<class T1, class T2, int N>
224
225template<class T1, class T2, int N>
229
230template<class T1, class T2, int N>
234
235template<class T1, class T2, int N>
239
240template<class T1, class T2, int N>
244
245template<class T1, class T2, int N>
249
250template<class T1, class T2, int N>
254
255template<class T1, class T2, int N>
259
260template<class T1, class T2, int N>
264
265template<class T1, class T2, int N>
269
270template<class T1, class T2, int N>
274
275template<class T1, class T2, int N>
279
280
281
282
283
284//-----------------------------------------------------------------------------
285// Operators
286//-----------------------------------------------------------------------------
287
290
291// trace = traceColor(source1)
293template<class T, int N>
297
298template<class T, int N>
301{
303
304 // Since the color index is eaten, do not need to pass on function by
305 // calling trace(...) again
306 d.elem() = s1.elem(0,0);
307 for(int i=1; i < N; ++i)
308 d.elem() += s1.elem(i,i);
309
310 return d;
311}
312
313
315template<class T1, class T2, int N>
319
320template<class T1, class T2, int N>
323{
325
326 // The traceColor is eaten here
327 d.elem() = l.elem(0,0) * r.elem(0,0);
328 for(int k=1; k < N; ++k)
329 d.elem() += l.elem(0,k) * r.elem(k,0);
330
331 for(int j=1; j < N; ++j)
332 for(int k=0; k < N; ++k)
333 d.elem() += l.elem(j,k) * r.elem(k,j);
334
335 return d;
336}
337
339template<class T1, class T2, int N>
343
344template<class T1, class T2, int N, template<class,int> class C>
347{
349
350 // The traceColor is eaten here
351 d.elem() = l.elem(0,0) * r.elem();
352 for(int k=1; k < N; ++k)
353 d.elem() += l.elem(k,k) * r.elem();
354
355 return d;
356}
357
358// PScalar = traceColorMultiply(PScalar,PColorMatrix)
359template<class T1, class T2, int N>
363
364template<class T1, class T2, int N>
367{
369
370 // The traceColor is eaten here
371 d.elem() = l.elem() * r.elem(0,0);
372 for(int k=1; k < N; ++k)
373 d.elem() += l.elem() * r.elem(k,k);
374
375 return d;
376}
377
378
380template <class T, int N>
384
386
387template<class T, int N>
390{
392
393 for(int i=0; i < N; i++) {
394 for(int j=0; j < N; j++) {
395 // Transpose, so flip indices
396 d.elem(i,j) = s1.elem(j,i);
397 }
398 }
399 return d;
400}
401
402
403//-----------------------------------------------
404// OuterProduct must be handled specially for each color and spin
405// The problem is the traits class - I have no way to say to PVector's
406// transform into a PMatrix but downcast the trait to a PColorMatrix or PSpinMatrix
407
409template<class T1, class T2, int N>
413
414template<class T1, class T2, int N>
417{
419
420 for(int i=0; i < N; ++i)
421 for(int j=0; j < N; ++j)
422 d.elem(i,j) = outerProduct(l.elem(i),r.elem(j));
423
424 return d;
425}
426
427
428//-----------------------------------------------
429// Peeking and poking
431
432template<class T, int N>
436
437template<class T, int N>
439peekColor(const PColorMatrix<T,N>& l, int row, int col)
440{
442
443 // Note, do not need to propagate down since the function is eaten at this level
444 d.elem() = l.elem(row,col);
445 return d;
446}
447
449template<class T1, class T2, int N>
450inline PColorMatrix<T1,N>&
451pokeColor(PColorMatrix<T1,N>& l, const PScalar<T2>& r, int row, int col)
452{
453 // Note, do not need to propagate down since the function is eaten at this level
454 l.elem(row,col) = r.elem();
455 return l;
456}
457
458
459//-----------------------------------------------------------------------------
460// Contraction for color matrices
461// colorContract
462template<class T1, class T2, class T3, int N>
466
468
474template<class T1, class T2, class T3>
477{
479
480 // Permutations: +(0,1,2)+(1,2,0)+(2,0,1)-(1,0,2)-(0,2,1)-(2,1,0)
481
482 // d = \epsilon^{i1,j1,k1}\epsilon^{i2,j2,k2} Q1^{i1,i2} Q2^{j1,j2} Q3^{k1,k2}
483 d.elem() = (s1.elem(0,0)*s2.elem(1,1)
484 - s1.elem(1,0)*s2.elem(0,1)
485 - s1.elem(0,1)*s2.elem(1,0)
486 + s1.elem(1,1)*s2.elem(0,0))*s3.elem(2,2)
487 + (s1.elem(1,1)*s2.elem(2,2)
488 - s1.elem(2,1)*s2.elem(1,2)
489 - s1.elem(1,2)*s2.elem(2,1)
490 + s1.elem(2,2)*s2.elem(1,1))*s3.elem(0,0)
491 + (s1.elem(2,2)*s2.elem(0,0)
492 - s1.elem(0,2)*s2.elem(2,0)
493 - s1.elem(2,0)*s2.elem(0,2)
494 + s1.elem(0,0)*s2.elem(2,2))*s3.elem(1,1)
495
496 + (s1.elem(1,0)*s2.elem(2,1)
497 - s1.elem(2,0)*s2.elem(1,1)
498 - s1.elem(1,1)*s2.elem(2,0)
499 + s1.elem(2,1)*s2.elem(1,0))*s3.elem(0,2)
500 + (s1.elem(1,2)*s2.elem(2,0)
501 - s1.elem(2,2)*s2.elem(1,0)
502 - s1.elem(1,0)*s2.elem(2,2)
503 + s1.elem(2,0)*s2.elem(1,2))*s3.elem(0,1)
504
505 + (s1.elem(2,0)*s2.elem(0,1)
506 - s1.elem(0,0)*s2.elem(2,1)
507 - s1.elem(2,1)*s2.elem(0,0)
508 + s1.elem(0,1)*s2.elem(2,0))*s3.elem(1,2)
509 + (s1.elem(2,1)*s2.elem(0,2)
510 - s1.elem(0,1)*s2.elem(2,2)
511 - s1.elem(2,2)*s2.elem(0,1)
512 + s1.elem(0,2)*s2.elem(2,1))*s3.elem(1,0)
513
514 + (s1.elem(0,1)*s2.elem(1,2)
515 - s1.elem(1,1)*s2.elem(0,2)
516 - s1.elem(0,2)*s2.elem(1,1)
517 + s1.elem(1,2)*s2.elem(0,1))*s3.elem(2,0)
518 + (s1.elem(0,2)*s2.elem(1,0)
519 - s1.elem(1,2)*s2.elem(0,0)
520 - s1.elem(0,0)*s2.elem(1,2)
521 + s1.elem(1,0)*s2.elem(0,2))*s3.elem(2,1);
522
523 return d;
524}
525
526
528
537template<class T1, class T2, class T3>
538inline typename TrinaryReturn<PColorMatrix<T1,1>, PColorMatrix<T2,1>, PColorMatrix<T3,1>, FnColorContract>::Type_t
540{
542
543 // not written
544 QDPIO::cerr << __func__ << ": not written for Nc=1" << std::endl;
545 QDP_abort(1);
546
547 return d ;
548}
549
550
552
561template<class T1, class T2, class T3>
562inline typename TrinaryReturn<PColorMatrix<T1,2>, PColorMatrix<T2,2>, PColorMatrix<T3,2>, FnColorContract>::Type_t
564{
566
567 // not written
568 QDPIO::cerr << __func__ << ": not written for Nc=2" << std::endl;
569 QDP_abort(1);
570
571 return d ;
572}
573
574
576
585template<class T1, class T2, class T3>
586inline typename TrinaryReturn<PColorMatrix<T1,4>, PColorMatrix<T2,4>, PColorMatrix<T3,4>, FnColorContract>::Type_t
588{
590
591 // not written
592 QDPIO::cerr << __func__ << ": not written for Nc=4" << std::endl;
593 QDP_abort(1);
594
595 return d ;
596}
597
598
599//-----------------------------------------------------------------------------
600// Contraction for quark propagators
601// QuarkContract
603
609template<class T1, class T2>
610inline typename BinaryReturn<PColorMatrix<T1,3>, PColorMatrix<T2,3>, FnQuarkContractXX>::Type_t
612{
614
615 // Permutations: +(0,1,2)+(1,2,0)+(2,0,1)-(1,0,2)-(0,2,1)-(2,1,0)
616
617 // k1 = 0, k2 = 0
618 // d(0,0) = eps^{i1,j1,0}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
619 // +(1,2,0),-(2,1,0) +(1,2,0),-(2,1,0)
620 d.elem(0,0) = s1.elem(1,1)*s2.elem(2,2)
621 - s1.elem(1,2)*s2.elem(2,1)
622 - s1.elem(2,1)*s2.elem(1,2)
623 + s1.elem(2,2)*s2.elem(1,1);
624
625 // k1 = 1, k2 = 0
626 // d(0,1) = eps^{i1,j1,1}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
627 // +(2,0,1),-(0,2,1) +(1,2,0),-(2,1,0)
628 d.elem(0,1) = s1.elem(2,1)*s2.elem(0,2)
629 - s1.elem(2,2)*s2.elem(0,1)
630 - s1.elem(0,1)*s2.elem(2,2)
631 + s1.elem(0,2)*s2.elem(2,1);
632
633 // k1 = 2, k2 = 0
634 // d(0,2) = eps^{i1,j1,2}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
635 // +(0,1,2),-(1,0,2) +(1,2,0),-(2,1,0)
636 d.elem(0,2) = s1.elem(0,1)*s2.elem(1,2)
637 - s1.elem(0,2)*s2.elem(1,1)
638 - s1.elem(1,1)*s2.elem(0,2)
639 + s1.elem(1,2)*s2.elem(0,1);
640
641 // k1 = 0, k2 = 1
642 // d(1,0) = eps^{i1,j1,0}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
643 // +(1,2,0),-(2,1,0) +(2,0,1),-(0,2,1)
644 d.elem(1,0) = s1.elem(1,2)*s2.elem(2,0)
645 - s1.elem(1,0)*s2.elem(2,2)
646 - s1.elem(2,2)*s2.elem(1,0)
647 + s1.elem(2,0)*s2.elem(1,2);
648
649 // k1 = 1, k2 = 1
650 // d(1,1) = eps^{i1,j1,1}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
651 // +(2,0,1),-(0,2,1) +(2,0,1),-(0,2,1)
652 d.elem(1,1) = s1.elem(2,2)*s2.elem(0,0)
653 - s1.elem(2,0)*s2.elem(0,2)
654 - s1.elem(0,2)*s2.elem(2,0)
655 + s1.elem(0,0)*s2.elem(2,2);
656
657 // k1 = 2, k2 = 1
658 // d(1,1) = eps^{i1,j1,2}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
659 // +(0,1,2),-(1,0,2) +(2,0,1),-(0,2,1)
660 d.elem(1,2) = s1.elem(0,2)*s2.elem(1,0)
661 - s1.elem(0,0)*s2.elem(1,2)
662 - s1.elem(1,2)*s2.elem(0,0)
663 + s1.elem(1,0)*s2.elem(0,2);
664
665 // k1 = 0, k2 = 2
666 // d(2,0) = eps^{i1,j1,0}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
667 // +(1,2,0),-(2,1,0) +(0,1,2),-(1,0,2)
668 d.elem(2,0) = s1.elem(1,0)*s2.elem(2,1)
669 - s1.elem(1,1)*s2.elem(2,0)
670 - s1.elem(2,0)*s2.elem(1,1)
671 + s1.elem(2,1)*s2.elem(1,0);
672
673 // k1 = 1, k2 = 2
674 // d(2,1) = eps^{i1,j1,1}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
675 // +(2,0,1),-(0,2,1) +(0,1,2),-(1,0,2)
676 d.elem(2,1) = s1.elem(2,0)*s2.elem(0,1)
677 - s1.elem(2,1)*s2.elem(0,0)
678 - s1.elem(0,0)*s2.elem(2,1)
679 + s1.elem(0,1)*s2.elem(2,0);
680
681 // k1 = 2, k2 = 2
682 // d(2,2) = eps^{i1,j1,2}\epsilon^{i2,j2,0} Q1^{i1,i2} Q2^{j1,j2}
683 // +(0,1,2),-(1,0,2) +(0,1,2),-(1,0,2)
684 d.elem(2,2) = s1.elem(0,0)*s2.elem(1,1)
685 - s1.elem(0,1)*s2.elem(1,0)
686 - s1.elem(1,0)*s2.elem(0,1)
687 + s1.elem(1,1)*s2.elem(0,0);
688
689 return d;
690}
691
692
693// Contraction for quark propagators
694// QuarkContract
696
705template<class T1, class T2>
706inline typename BinaryReturn<PColorMatrix<T1,1>, PColorMatrix<T2,1>, FnQuarkContractXX>::Type_t
708{
710
711 // not yet written
712 QDPIO::cerr << __func__ << ": not written for Nc=1" << std::endl;
713 QDP_abort(1);
714
715 return d ;
716}
717
718
719// Contraction for quark propagators
720// QuarkContract
722
731template<class T1, class T2>
732inline typename BinaryReturn<PColorMatrix<T1,2>, PColorMatrix<T2,2>, FnQuarkContractXX>::Type_t
734{
736
737 // not yet written
738 QDPIO::cerr << __func__ << ": not written for Nc=2" << std::endl;
739 QDP_abort(1);
740
741 return d ;
742}
743
744
745// Contraction for quark propagators
746// QuarkContract
748
757template<class T1, class T2>
758inline typename BinaryReturn<PColorMatrix<T1,4>, PColorMatrix<T2,4>, FnQuarkContractXX>::Type_t
760{
762
763 // not yet written
764 QDPIO::cerr << __func__ << ": not written for Nc=4" << std::endl;
765 QDP_abort(1);
766
767 return d ;
768}
769
770 // end of group primcolormatrix
772
773} // namespace QDP
774
775#endif
Primitive color Matrix class.
PColorMatrix & operator=(const PScalar< T1 > &rhs)
PColorMatrix = PScalar.
PColorMatrix & operator=(const PColorMatrix< T1, N > &rhs)
PColorMatrix = PColorMatrix.
Primitive color Vector class.
CC & assign(const PScalar< T1 > &rhs)
T & elem(int i, int j)
Primitive Scalar.
T & elem(int i)
OLattice< PScalar< PColorMatrix< RComplexFloat, 3 > > > C
BinaryReturn< PColorMatrix< T1, 3 >, PColorMatrix< T2, 3 >, FnQuarkContractXX >::Type_t quarkContractXX(const PColorMatrix< T1, 3 > &s1, const PColorMatrix< T2, 3 > &s2)
dest = QuarkContractXX(Qprop1,Qprop2)
BinaryReturn< PColorMatrix< T1, N >, PColorMatrix< T2, N >, FnTraceColorMultiply >::Type_t traceColorMultiply(const PColorMatrix< T1, N > &l, const PColorMatrix< T2, N > &r)
StandardOutputStream cerr
Definition qdp_stdio.cc:22
Yet another random number generator.
MakeReturn< UnaryNode< FnPeekColorMatrix, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, C1 >::Expression_t peekColor(const QDPExpr< T1, C1 > &l, int row, int col)
Definition qdp_newops.h:161
MakeReturn< TrinaryNode< FnColorContract, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPType< T2, C2 > >::Leaf_t, typenameCreateLeaf< typenameSimpleScalar< typenameWordType< C1 >::Type_t >::Type_t >::Leaf_t >, typenameTrinaryReturn< C1, C2, typenameSimpleScalar< typenameWordType< C1 >::Type_t >::Type_t, FnColorContract >::Type_t >::Expression_t colorContract(const QDPType< T1, C1 > &a, const QDPType< T2, C2 > &b, const typename WordType< C1 >::Type_t &c)
Definition qdp.h:4557
MakeReturn< UnaryNode< FnTraceColor, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnTraceColor >::Type_t >::Expression_t traceColor(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4946
MakeReturn< UnaryNode< FnTransposeColor, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnTransposeColor >::Type_t >::Expression_t transposeColor(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4881
MakeReturn< BinaryNode< FnOuterProduct, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, FnOuterProduct >::Type_t >::Expression_t outerProduct(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2364
C1 & pokeColor(QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r, int row, int col)
Definition qdp_newops.h:360
void QDP_abort(int status)
Panic button.
PScalar< typename BinaryReturn< T1, T2, FnInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceMultiply >::Type_t > Type_t
PColorMatrix< typename BinaryReturn< T1, T2, Op >::Type_t, N > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceColorMultiply >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceColorMultiply >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceMultiply >::Type_t > Type_t
PColorMatrix< typename BinaryReturn< T1, T2, Op >::Type_t, N > Type_t
PColorMatrix< typename BinaryReturn< T1, T2, FnOuterProduct >::Type_t, N > Type_t
PScalar< typename BinaryReturn< T1, T2, FnInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProductReal >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnLocalInnerProduct >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceColorMultiply >::Type_t > Type_t
PScalar< typename BinaryReturn< T1, T2, FnTraceMultiply >::Type_t > Type_t
PColorMatrix< typename BinaryReturn< T1, T2, Op >::Type_t, N > Type_t
PColorMatrix< typename DoublePrecType< T1 >::Type_t, N > Type_t
Structure for extracting color matrix components.
Definition qdp_newops.h:124
PScalar< typename InternalScalar< T >::Type_t > Type_t
Construct simple word type used at some level within primitives.
Definition qdp_traits.h:98
PColorMatrix< typename LatticeScalar< T >::Type_t, N > Type_t
Makes a lattice scalar leaving primitive indices alone.
Definition qdp_traits.h:108
PScalar< typename PrimitiveScalar< T >::Type_t > Type_t
Makes a primitive scalar leaving grid alone.
Definition qdp_traits.h:103
PColorMatrix< typename SinglePrecType< T1 >::Type_t, N > Type_t
PColorMatrix< typename UnaryReturn< T1, Op >::Type_t, N > Type_t
PScalar< typename UnaryReturn< T, FnImagTrace >::Type_t > Type_t
PScalar< typename UnaryReturn< T, FnLocalNorm2 >::Type_t > Type_t
PScalar< typename UnaryReturn< T, FnNorm2 >::Type_t > Type_t
PScalar< typename UnaryReturn< T, FnPeekColorMatrix >::Type_t > Type_t
PScalar< typename UnaryReturn< T, FnRealTrace >::Type_t > Type_t
PColorMatrix< typename UnaryReturn< T, FnSumMulti >::Type_t, N > Type_t
PScalar< typename UnaryReturn< T, FnTraceColor >::Type_t > Type_t
PScalar< typename UnaryReturn< T, FnTrace >::Type_t > Type_t
PColorMatrix< typename UnaryReturn< T, FnTransposeColor >::Type_t, N > Type_t
Find the underlying word type of a field.
Definition qdp_traits.h:29