LatticeYangMills
outputobs.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 
34 #include <cstdio>
35 #include <boost/filesystem.hpp>
36 #include "Observables/observable.h"
37 #include "InputOutput/outputobs.h"
38 #include "Math/lattice.h"
39 #include "ParallelTools/parallel.h"
40 
41 namespace LatticeIO {
42 
43  char OutputObs::fileName[1024];
44  FILE* OutputObs::m_file;
45  std::string OutputObs::m_outputDir;
46 
47 
52  void OutputObs::setOutputDir(std::string outputDir){
53  m_outputDir = outputDir;
54  boost::filesystem::create_directory(m_outputDir);
55  boost::filesystem::create_directory(m_outputDir+"/flow");
56  }
57 
58 
63  void OutputObs::initialize(std::vector<Observable*>& obsList){
64  if(Parallel::rank() == 0){
65  sprintf(fileName, "%s/observables.dat", m_outputDir.c_str());
66  m_file = fopen(fileName, "w+");
67  fprintf(m_file, "Step\t");
68  for(auto& obs : obsList)
69  fprintf(m_file, "%s\t", obs->getName());
70  fprintf(m_file, "\n");
71  fclose(m_file);
72  }
73  }
74 
80  void OutputObs::writeObs(std::vector<Observable*>& obsList, int MCSteps){
81  if(Parallel::rank() == 0){
82  m_file = fopen(fileName, "a");
83  fprintf(m_file, "%i\t", MCSteps);
84  for(auto& obs : obsList)
85  fprintf(m_file, "%lf\t", obs->value());
86  fprintf(m_file, "\n");
87  fclose(m_file);
88  }
89  }
90 
97  void OutputObs::writeFlowObs(int confNum, std::vector<Observable*>& obsList, std::vector<std::vector<double>>& obsMatrix){
98  if(Parallel::rank() == 0){
99  char flowFileName [1024];
100  sprintf(flowFileName, "%s/flow/conf%04d.dat", m_outputDir.c_str(), confNum);
101  FILE* flowOut = fopen(flowFileName, "w+");
102  fprintf(flowOut, "Flow Time\t");
103  //for(auto& obs : obsList)
104  // fprintf(flowOut, "%s\t", obs->getName());
105  fprintf(flowOut, "%s\t", "Plaq.");
106  fprintf(flowOut, "%s\t", "Topc.");
107  fprintf(flowOut, "%s\t", "Energ.");
108  fprintf(flowOut, "\n");
109 
110  for(auto& flowStep : obsMatrix){
111  for(auto& obs : flowStep)
112  fprintf(flowOut, "%lf\t", obs);
113  fprintf(flowOut, "\n");
114  }
115  fclose(flowOut);
116  }
117  }
118 
119 } // end LatticeIO
Contains classes for output to file of observables values.
Contains the definition of the Lattice class.
static char fileName[1024]
The name of the output file.
Definition: outputobs.h:74
Contains the definition of the Observable prototype.
static void writeFlowObs(int confNum, std::vector< Observable * > &obsList, std::vector< std::vector< double >> &obsMatrix)
Writes the observables for given flow step.
Definition: outputobs.cpp:97
static void setOutputDir(std::string outputDir)
Sets the output directory for the file output.
Definition: outputobs.cpp:52
Utilities for parallelization.
static std::string m_outputDir
The output directory.
Definition: outputobs.h:76
static void writeObs(std::vector< Observable * > &obsList, int MCSteps)
Writes the list of observables to file at given generation point.
Definition: outputobs.cpp:80
static FILE * m_file
The file object for target output.
Definition: outputobs.h:72
static void initialize(std::vector< Observable * > &obsList)
Opens the files and writes needed headers.
Definition: outputobs.cpp:63