Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fieldIO_Text_4x4x4x8.cpp
Go to the documentation of this file.
1 
10 #include "fieldIO_Text_4x4x4x8.h"
11 
12 #include <iostream>
13 #include <fstream>
14 
15 #include "commonParameters.h"
16 #include "communicator.h"
17 #include "bridgeIO.h"
18 using Bridge::vout;
19 
20 #include "field.h"
21 
22 const std::string FieldIO_Text_4x4x4x8::class_name = "FieldIO_Text_4x4x4x8";
23 
24 //====================================================================
25 void FieldIO_Text_4x4x4x8::read_file(Field *v, string filename)
26 {
27  int nin_field = v->nin();
28  int nex_field = v->nex();
29 
30  int Nc = CommonParameters::Nc();
31  int Ndim = CommonParameters::Ndim();
32  int NinG = 2 * Nc * Nc;
33  int NxF = 4;
34  int NyF = 4;
35  int NzF = 4;
36  int NtF = 8;
37  int LvolF = NxF * NyF * NzF * NtF;
38  Field v_in(NinG, LvolF, Ndim);
39 
40  int nin_file = NinG;
41  int nex_file = Ndim;
42 
43  assert(nin_file == nin_field);
44  assert(nex_file == nex_field);
45 
46  int Lvol = CommonParameters::Lvol();
47 
48  vout.detailed(m_vl, "%s: file format: nin=%d, nex=%d, Lvol=%d\n", __func__, nin_file, nex_file, Lvol);
49  vout.detailed(m_vl, "%s: field format: nin=%d, nex=%d, Lvol=%d\n", __func__, nin_field, nex_field, v->nvol());
50 
51  // temporary field holding the whole space-time data.
52  // Field vtmp;
53  Field vtmp(nin_field, LvolF, nex_field);
54 
56  vout.detailed(m_vl, "reading field data from %s\n", filename.c_str());
57 
58  // vtmp.reset(nin_field, Lvol, nex_field);
59 
60  std::fstream config(filename.c_str(), std::ios::in);
61  if (!config.is_open()) {
62  vout.crucial(m_vl, "%s: file open error: %s may not exist.\n", __func__, filename.c_str());
63  abort();
64  }
65 
66  // int s, t;
67  double val;
68  for (int isite = 0; isite < LvolF; ++isite) {
69  for (int j = 0; j < nex_file; ++j) {
70  for (int i = 0; i < nin_file; ++i) {
71  config >> val;
72 
73  if (!config.good()) {
74  if (config.eof()) {
75  // file short.
76  vout.crucial(m_vl, "%s: file size too small.\n", __func__);
77  abort();
78  }
79  if (config.fail()) {
80  // invalid data.
81  vout.crucial(m_vl, "%s: invalid data.\n", __func__);
82  abort();
83  }
84  // other error.
85  vout.crucial(m_vl, "%s: io error.\n", __func__);
86  abort();
87  }
88 
89  // m_format->file_to_field(s, t, i, j);
90  vtmp.set(i, isite, j, val);
91  }
92  }
93  }
94 
95  int dummy;
96  config >> dummy;
97 
98  if (!config.eof()) {
99  // file size mismatch
100  vout.crucial(m_vl, "%s: file size larger than expected.\n", __func__);
101  // warning only
102  }
103 
104  config.close();
105  }
107 
108  vout.detailed(m_vl, "read successful\n");
109 
110  // copy read configuration to all the nodes.
111  int count = NinG * LvolF * Ndim;
112  Communicator::broadcast(count, (double *)vtmp.ptr(0), 0);
113 
114  Index_lex idx;
115  Index_lex indexF(NxF, NyF, NzF, NtF);
116 
117  int Nx = CommonParameters::Nx();
118  int Ny = CommonParameters::Ny();
119  int Nz = CommonParameters::Nz();
120  int Nt = CommonParameters::Nt();
121 
122  int ipex = Communicator::ipe(0);
123  int ipey = Communicator::ipe(1);
124  int ipez = Communicator::ipe(2);
125  int ipet = Communicator::ipe(3);
126 
127  for (int j = 0; j < Ndim; ++j) {
128  for (int t = 0; t < Nt; ++t) {
129  int t2 = (t + ipet * Nt) % NtF;
130  for (int z = 0; z < Nz; ++z) {
131  int z2 = (z + ipez * Nz) % NzF;
132  for (int y = 0; y < Ny; ++y) {
133  int y2 = (y + ipey * Ny) % NyF;
134  for (int x = 0; x < Nx; ++x) {
135  int x2 = (x + ipex * Nx) % NxF;
136  int lsite = idx.site(x, y, z, t);
137  int gsite = indexF.site(x2, y2, z2, t2);
138 
139  for (int i = 0; i < NinG; ++i) {
140  v->set(i, lsite, j, vtmp.cmp(i, gsite, j));
141  }
142  }
143  }
144  }
145  }
146  }
147 }
148 
149 
150 //====================================================================
151 void FieldIO_Text_4x4x4x8::write_file(Field *v, std::string filename)
152 {
153  vout.crucial(m_vl, "%s: no write method is defined.\n",
154  class_name.c_str());
155 }
156 
157 
158 //====================================================================
159 //============================================================END=====
Index_lex idx
Definition: fieldIO.h:54
BridgeIO vout
Definition: bridgeIO.cpp:207
void detailed(const char *format,...)
Definition: bridgeIO.cpp:50
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:128
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:53
double * ptr(const int jin, const int site, const int jex)
Definition: field.h:118
Container of Field-type object.
Definition: field.h:37
void write_file(Field *v, string filename)
int nvol() const
Definition: field.h:101
double cmp(const int jin, const int site, const int jex) const
Definition: field.h:108
static int ipe(const int dir)
logical coordinate of current proc.
void read_file(Field *v, string filename)
static int Lvol()
int nin() const
Definition: field.h:100
int nex() const
Definition: field.h:102
Lexical site index.
Definition: index_lex.h:34
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
static const std::string class_name
static int sync()
synchronize within small world.
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
static bool is_primary()
check if the present node is primary in small communicator.
Bridge::VerboseLevel m_vl
Definition: fieldIO.h:59