LatticeYangMills
gaugefieldfactory.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * MIT License
4 *
5 * Copyright (c) 2018 Giovanni Pederiva
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 ******************************************************************************/
25 
35 #include <vector>
36 #include <cstdio>
37 #include <chrono>
38 #include "lqcd.h"
39 
41 GaugeFieldFactory::GaugeFieldFactory(int MCSteps, int thermSteps,
42  int NConf, double epsilon,
43  std::string startType)
44  : App() {
45  m_MCSteps = MCSteps;
46  m_thermSteps = thermSteps;
47  m_confs = NConf;
48  m_correlationSteps = m_MCSteps / m_confs;
49  m_epsilon = epsilon;
50  m_startType = startType;
51 }
52 
53 
59  initialize();
61 }
62 
68  if(m_startType == "Cold")
69  m_lat->setToUnity();
70  else if (m_startType == "Hot")
71  m_lat->setToRandom();
72 
73 
74  for(auto& obs : m_obs)
75  obs->initObservable(m_lat);
77  m_obsValues.resize(m_obs.size());
78 
81 }
82 
85  // check that current processor should be active
86  if(Parallel::isActive()){
87 
88  // thermalization
89  thermalize();
90 
91  // generate and save configurations
92  sampleConf();
93  }
94 }
95 
96 
99  for(int step = 1; step <= m_thermSteps; step++){
100  // perform an update
101  MCUpdate();
102 
103  // compute and print information on current state
104  if(step % m_correlationSteps == 0){
106  LatticeIO::OutputTerm::printThermStep(step, m_obs, double(m_accepted)/double(m_updates));
107  }
108  }
109 }
110 
116  int confNum = 0;
117  for(int step = 1; step <= m_MCSteps; step++){
118  // perform an update
119  MCUpdate();
120 
121  // compute and print information on current state
122  if(step % m_correlationSteps == 0){
125  LatticeIO::OutputTerm::printGenStep(confNum, m_obs, double(m_accepted)/double(m_updates));
127  confNum++;
128  }
129  }
130 }
131 
137  auto thermStart = std::chrono::system_clock::now();
138  auto thermStepStart = std::chrono::system_clock::now();
139  for(int step = 1; step <= m_thermSteps; step++){
140  // perform an update
141  MCUpdate();
142 
143  // compute and print information on current state
144  if(step % m_correlationSteps == 0){
146  LatticeIO::OutputTerm::printThermStep(step, m_obs, double(m_accepted)/double(m_updates));
147  std::chrono::duration<double> thermStepTime = std::chrono::system_clock::now()-thermStepStart;
148  if(Parallel::rank() == 0)
149  printf("\tThermalization Step Time: %lf s\n\n", thermStepTime.count());
150  thermStepStart = std::chrono::system_clock::now();
151  }
152  }
153  std::chrono::duration<double> thermTime = std::chrono::system_clock::now()-thermStart;
154  if(Parallel::rank() == 0){
155  printf("Total Thermalization Steps: %i\n", m_thermSteps);
156  printf("Total Thermalization Time: %lf s\n\n", thermTime.count());
157  }
158 }
159 
165  int confNum = 0;
166  auto confUpdateStart = std::chrono::system_clock::now();
167  auto writeStart = std::chrono::system_clock::now();
168  for(int step = 1; step <= m_MCSteps; step++){
169  // perform an update
170  MCUpdate();
171 
172  // compute and print information on current state
173  if(step % m_correlationSteps == 0){
175  LatticeIO::OutputTerm::printThermStep(confNum, m_obs, double(m_accepted)/double(m_updates));
176  std::chrono::duration<double> confUpdateTime = std::chrono::system_clock::now()-confUpdateStart;
177  if(Parallel::rank() == 0)
178  printf("\tConfiguration Update: %lf s\n", confUpdateTime.count());
179  writeStart = std::chrono::system_clock::now();
182  std::chrono::duration<double> writeTime = std::chrono::system_clock::now()-writeStart;
183  if(Parallel::rank() == 0)
184  printf("\tWrite Time: %lf s\n\n", writeTime.count());
185  confUpdateStart = std::chrono::system_clock::now();
186  confNum++;
187  }
188  }
189 }
190 
193  // loop through the whole sub-lattice
194  for(int x = 0; x < m_size[0]; x++){
195  for(int y = 0; y < m_size[1]; y++){
196  for(int z = 0; z < m_size[2]; z++){
197  for(int t = 0; t < m_size[3]; t++){
198  for(int mu = 0; mu < 4; mu++){
199  updateLink(x,y,z,t,mu);
200  }
201  }}}}
202 }
203 
205 void GaugeFieldFactory::updateLink(int x,int y, int z, int t, int mu){
206  // get the local staples' sum
207  m_act->computeStaples(x, y, z, t, mu);
208 
209  // try 10 hits on the current link
210  for(int i = 0; i < 30; i++){
211  newLink = Random::randSU3Transf(m_epsilon) * (*m_lat)(x,y,z,t)[mu] ;
212 
213  // metropolis accept/reject
214  if( exp(-m_act->compute(x, y, z, t, mu, newLink)) > Random::randUniform()){
215  (*m_lat)(x,y,z,t)[mu] = newLink;
216  m_accepted++;
217  }
218  m_updates++;
219  }
220 }
221 
224  for(auto& obs : m_obs)
225  obs->compute();
226 }
std::vector< Observable * > m_obs
Vector of pointers to Observable instances.
Definition: app.h:75
static void printInitialConditions()
Prints basic info about the system.
Definition: outputterm.cpp:45
static double randUniform()
returns a number from a uniform distribution between 0 and 1
Definition: random.cpp:47
void sampleConf()
Performs the Monte Carlo updates, every N_Corr saves the lattice and computes observables.
static SU3 randSU3Transf(double epsilon)
returns a random SU3 element with controlled spread around the unity matrix.
Definition: random.cpp:118
void execute()
Executes the App code. Perform initialization of subclasses and the system, then runst the Monte Carl...
static void printThermStep(int step, std::vector< Observable * > &obsList, double acceptRatio)
Prints information about a thermalization step.
Definition: outputterm.cpp:62
Main include file for all headers.
GluonField * m_lat
Pointer to the GluonField instance.
Definition: app.h:71
std::array< int, 4 > m_size
Size of the sublattice.
Definition: app.h:73
static void printGenStep(int confNum, std::vector< Observable * > &obsList, double acceptRatio)
Prints information about a generation step.
Definition: outputterm.cpp:77
void computeObservables()
Computes the Observable value for all memebers of the m_obs vector.
void sampleConfTime()
Performs the Monte Carlo updates, every N_Corr saves the lattice and computes observables. Prints out times of execution.
void thermalizeTime()
Perform N_Therm Monte Carlo updates to thermalize the system. Prints times of execution.
virtual double compute(int x, int y, int z, int t, int mu, SU3 &newLink)=0
Computes the action difference around a given link for a suggested move.
void generateConfigurations()
Run the thermalization first, then the sampling of configurations.
void initAction(GluonField *field)
Links the action to a given field and initializes.
Definition: action.cpp:41
Action * m_act
Pointer to the Action instance.
Definition: app.h:69
void MCUpdate()
Loops over all links and tres to update them.
static void writeObs(std::vector< Observable * > &obsList, int MCSteps)
Writes the list of observables to file at given generation point.
Definition: outputobs.cpp:80
void thermalize()
Perform N_Therm Monte Carlo updates to thermalize the system.
SU3 exp(const SU3 &Q)
exponential of a SU3 algebra matrix
Definition: su3.cpp:136
GaugeFieldFactory(int MCSteps, int thermSteps, int NConf, double epsilon, std::string startType)
Constructor of the GaugeFieldFactory object.
void updateLink(int x, int y, int z, int t, int mu)
Tries to update a single link 30 times (N_Hits)
static void writeConf(GluonField &lattice, int confNum)
Saves the given GluonField object to the ouput directory.
Definition: outputconf.cpp:81
void initialize()
Initializes the GluonField based on the initial condition (hot/cold), runs the initializers of the su...
static void initialize(std::vector< Observable * > &obsList)
Opens the files and writes needed headers.
Definition: outputobs.cpp:63
Prototype for the App class group.
Definition: app.h:59
virtual void computeStaples(int mu)=0
Computes the sum of the staples around all links.