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_{impr}=\beta/N * \sum_{plaq} ReTr(plaq)
9
10template <typename T>
11void rstaplesum(const GaugeField<T> &U, Field<T> &staples, Direction d1, Parity par = ALL) {
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, par);
21
22 // calculate first lower 'U' of the staple sum
23 // do it on opp parity
24 onsites(opp_parity(par)) {
25 lower[X] = (U[d1][X] * U[d2][X + d1]).dagger() * U[d2][X];
26 }
27
28 // calculate then the upper 'n', and add the lower
29 // lower could also be added on a separate loop
30 if (first) {
31 onsites(par) {
32 staples[X] = U[d2][X + d1] * (U[d2][X] * U[d1][X + d2]).dagger() + lower[X - d2];
33 }
34 first = false;
35 } else {
36 onsites(par) {
37 staples[X] += U[d2][X + d1] * (U[d2][X] * U[d1][X + d2]).dagger() + lower[X - d2];
38 }
39 }
40 }
41}
42
43template <typename group, typename atype = hila::arithmetic_type<group>>
44atype measure_s_wplaq(const GaugeField<group> &U) {
45 // measure the Wilson plaquette action
46 Reduction<double> plaq = 0;
47 plaq.allreduce(false).delayed(true);
48 foralldir(dir1) foralldir(dir2) if (dir1 < dir2) {
49 U[dir2].start_gather(dir1, ALL);
50 U[dir1].start_gather(dir2, ALL);
51 onsites(ALL) {
52 plaq += 1.0 - real(trace(U[dir1][X] * U[dir2][X + dir1] *
53 (U[dir2][X] * U[dir1][X + dir2]).dagger())) /
54 group::size();
55 }
56 }
57 return (atype)plaq.value();
58}
59
60template <typename group, typename atype = hila::arithmetic_type<group>>
61void get_force_wplaq_add(const GaugeField<group> &U, VectorField<Algebra<group>> &K,
62 atype eps = 1.0) {
63 // compute the force for the plaquette action and write it to K
64
65 Field<group> staple;
66 foralldir(d) {
67 rstaplesum(U, staple, d);
68 onsites(ALL) {
69 K[d][X] -= (U[d][X] * staple[X]).project_to_algebra_scaled(eps);
70 }
71 }
72
73 /*
74 Field<group> tP,tP1,tP2;
75 foralldir(d1) {
76 foralldir(d2) if(d1<d2) {
77 U[d2].start_gather(d1,ALL);
78 U[d1].start_gather(d2,ALL);
79 onsites(ALL) {
80 tP[X]=U[d1][X]*U[d2][X+d1]*(U[d2][X]*U[d1][X+d2]).dagger();
81 tP1[X]=(tP[X]*U[d2][X]).dagger()*U[d2][X]; // parallel transport tP[X].dagger() to
82 X+d2 tP2[X]=U[d1][X].dagger()*tP[X]*U[d1][X]; // parallel transport tP[X] to X+d1
83 }
84 tP1.start_gather(-d2,ALL);
85 tP2.start_gather(-d1,ALL);
86 onsites(ALL) {
87 K[d1][X]-=(tP1[X-d2]+tP[X]).project_to_algebra_scaled(eps);
88 K[d2][X]-=(tP2[X-d1]-tP[X]).project_to_algebra_scaled(eps);
89 }
90 }
91 }
92 */
93}
94
95template <typename group, typename atype = hila::arithmetic_type<group>>
96void get_force_wplaq(const GaugeField<group> &U, VectorField<Algebra<group>> &K, atype eps = 1.0) {
97 // compute the force for the plaquette action and write it to K
98 Field<group> staple;
99 foralldir(d) {
100 rstaplesum(U, staple, d);
101 onsites(ALL) {
102 K[d][X] = (U[d][X] * staple[X]).project_to_algebra_scaled(-eps);
103 }
104 }
105}
106
107
108#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
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
Parity
Parity enum with values EVEN, ODD, ALL; refers to parity of the site. Parity of site (x,...
#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