HILA
Loading...
Searching...
No Matches
wilson_plaquette_action.h
Go to the documentation of this file.
1/** @file wilson_plaquette_action.h */
2
3#ifndef WILSON_PLAQUETTE_ACTION_H_
4#define WILSON_PLAQUETTE_ACTION_H_
5
6#include "hila.h"
7
8// functions for Wilson's plaquette action -S_{plaq}=\beta/N * \sum_{plaq} ReTr(plaq)
9
10template <typename T>
11void rstaplesum(const GaugeField<T> &U, out_only Field<T> &staples, Direction d1) {
12
13 Field<T> lower;
14 bool first = true;
15 foralldir(d2) if (d2 != d1) {
16
17 // anticipate that these are needed
18 // not really necessary, but may be faster
19 U[d2].start_gather(d1, ALL);
20 U[d1].start_gather(d2, ALL);
21
22 // calculate first lower 'u' of the staple sum
23 onsites(ALL) {
24 lower[X] = (U[d1][X] * U[d2][X + d1]).dagger() * U[d2][X];
25 }
26 lower.start_gather(-d2, ALL);
27
28 // calculate then the upper 'n'
29 if (first) {
30 onsites(ALL) {
31 staples[X] = U[d2][X + d1] * (U[d2][X] * U[d1][X + d2]).dagger();
32 }
33 first = false;
34 } else {
35 onsites(ALL) {
36 staples[X] += U[d2][X + d1] * (U[d2][X] * U[d1][X + d2]).dagger();
37 }
38 }
39
40 // add lower
41 onsites(ALL) {
42 staples[X] += lower[X - d2];
43 }
44
45 }
46}
47
48template <typename group>
49double measure_s_wplaq(const GaugeField<group> &U) {
50 // measure the total Wilson plaquette action for the gauge field U
51 Reduction<double> plaq = 0;
52 plaq.allreduce(false).delayed(true);
53 foralldir(dir1) foralldir(dir2) if (dir1 < dir2) {
54 U[dir2].start_gather(dir1, ALL);
55 U[dir1].start_gather(dir2, ALL);
56 onsites(ALL) {
57 plaq += 1.0 - real(trace(U[dir1][X] * U[dir2][X + dir1] *
58 (U[dir2][X] * U[dir1][X + dir2]).dagger())) /
59 group::size();
60 }
61 }
62 return plaq.value();
63}
64
65template <typename group, typename atype = hila::arithmetic_type<group>>
66double measure_s_wplaq(const GaugeField<group> &U, out_only atype &max_plaq) {
67 // measure the total and maximal Wilson plaquette action for the gauge field U
68 Reduction<double> plaq = 0;
69 max_plaq = -1.0;
71 plaq.allreduce(false).delayed(true);
72 foralldir(dir1) foralldir(dir2) if (dir1 < dir2) {
73 U[dir2].start_gather(dir1, ALL);
74 U[dir1].start_gather(dir2, ALL);
75 onsites(ALL) {
76 P[X] = 1.0 - real(trace(U[dir1][X] * U[dir2][X + dir1] *
77 (U[dir2][X] * U[dir1][X + dir2]).dagger())) /
78 group::size();
79 plaq += (double)P[X];
80 }
81 atype tmax_plaq = P.max();
82 if(tmax_plaq>max_plaq) {
83 max_plaq = tmax_plaq;
84 }
85 }
86 return plaq.value();
87}
88
89template <typename group, typename atype = hila::arithmetic_type<group>>
90void get_force_wplaq_add(const GaugeField<group> &U, VectorField<Algebra<group>> &K,
91 atype eps = 1.0) {
92 // compute the force for the plaquette action and write it to K
93
94 Field<group> staple;
95 foralldir(d) {
96 rstaplesum(U, staple, d);
97 onsites(ALL) {
98 K[d][X] -= (U[d][X] * staple[X]).project_to_algebra_scaled(eps);
99 }
100 }
101
102 /*
103 Field<group> tP,tP1,tP2;
104 foralldir(d1) {
105 foralldir(d2) if(d1<d2) {
106 U[d2].start_gather(d1,ALL);
107 U[d1].start_gather(d2,ALL);
108 onsites(ALL) {
109 tP[X]=U[d1][X]*U[d2][X+d1]*(U[d2][X]*U[d1][X+d2]).dagger();
110 tP1[X]=(tP[X]*U[d2][X]).dagger()*U[d2][X]; // parallel transport tP[X].dagger() to X+d2
111 tP2[X]=U[d1][X].dagger()*tP[X]*U[d1][X]; // parallel transport tP[X] to X+d1
112 }
113 tP1.start_gather(-d2,ALL);
114 tP2.start_gather(-d1,ALL);
115 onsites(ALL) {
116 K[d1][X]-=(tP1[X-d2]+tP[X]).project_to_algebra_scaled(eps);
117 K[d2][X]-=(tP2[X-d1]-tP[X]).project_to_algebra_scaled(eps);
118 }
119 }
120 }
121 */
122}
123
124template <typename group, typename atype = hila::arithmetic_type<group>>
125void get_force_wplaq(const GaugeField<group> &U, out_only VectorField<Algebra<group>> &K,
126 atype eps = 1.0) {
127 // compute the force for the plaquette action and write it to K
128 Field<group> staple;
129 foralldir(d) {
130 rstaplesum(U, staple, d);
131 onsites(ALL) {
132 K[d][X] = (U[d][X] * staple[X]).project_to_algebra_scaled(-eps);
133 }
134 }
135}
136
137
138#endif
Array< n, m, hila::arithmetic_type< T > > real(const Array< n, m, T > &arg)
Return real part of Array.
Definition array.h:688
Definition su2.h:7
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
T max(Parity par=ALL) const
Find maximum value from Field.
Definition reduction.h:424
dir_mask_t start_gather(Direction d, Parity p=ALL) const
Definition field_comm.h:262
Gauge field class.
Definition gaugefield.h:22
Special reduction class: enables delayed and non-blocking reductions, which are not possible with the...
Definition reduction.h:14
const T value()
Return value of the reduction variable. Wait for the comms if needed.
Definition reduction.h:157
Reduction & allreduce(bool b=true)
allreduce(bool) turns allreduce on or off. By default on.
Definition reduction.h:130
Reduction & delayed(bool b=true)
deferred(bool) turns deferred on or off. By default turns on.
Definition reduction.h:148
Complex< T > dagger(const Complex< T > &val)
Return dagger of Complex number.
Definition cmplx.h:1223
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
Direction
Enumerator for direction that assigns integer to direction to be interpreted as unit vector.
Definition coordinates.h:34
constexpr Parity ALL
bit pattern: 011