Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
source_Local.cpp
Go to the documentation of this file.
1 
14 #include "source_Local.h"
15 
16 #ifdef USE_PARAMETERS_FACTORY
17 #include "parameters_factory.h"
18 #endif
19 
20 using std::valarray;
21 
22 #ifdef USE_FACTORY
23 namespace {
24  Source *create_object()
25  {
26  return new Source_Local();
27  }
28 
29 
30  bool init = Source::Factory::Register("Local", create_object);
31 }
32 #endif
33 
34 //- parameter entry
35 namespace {
36  void append_entry(Parameters& param)
37  {
38  param.Register_int_vector("source_position", valarray<int>());
39 
40  param.Register_string("verbose_level", "NULL");
41  }
42 
43 
44 #ifdef USE_PARAMETERS_FACTORY
45  bool init_param = ParametersFactory::Register("Source.Local", append_entry);
46 #endif
47 }
48 //- end
49 
50 //- parameters class
52 //- end
53 
54 //====================================================================
56 {
57  const string str_vlevel = params.get_string("verbose_level");
58 
59  m_vl = vout.set_verbose_level(str_vlevel);
60 
61  //- fetch and check input parameters
62  valarray<int> source_position;
63 
64  int err = 0;
65  err += params.fetch_int_vector("source_position", source_position);
66 
67  if (err) {
68  vout.crucial(m_vl, "Source_Local: fetch error, input parameter not found.\n");
69  abort();
70  }
71 
72  set_parameters(source_position);
73 }
74 
75 
76 //====================================================================
77 void Source_Local::set_parameters(const valarray<int>& source_position)
78 {
79  // #### parameter setup ####
80  int Ndim = CommonParameters::Ndim();
81 
82  valarray<int> Lsize(Ndim);
83  Lsize[0] = CommonParameters::Lx();
84  Lsize[1] = CommonParameters::Ly();
85  Lsize[2] = CommonParameters::Lz();
86  Lsize[3] = CommonParameters::Lt();
87 
88  //- print input parameters
89  vout.general(m_vl, "Source for spinor field - local:\n");
90  for (int mu = 0; mu < Ndim; ++mu) {
91  vout.general(m_vl, " source_position[%d] = %d\n",
92  mu, source_position[mu]);
93  }
94 
95  //- range check
96  int err = 0;
97  for (int mu = 0; mu < Ndim; ++mu) {
98  // NB. Lsize[mu] > abs(source_position[mu])
99  err += ParameterCheck::non_negative(Lsize[mu] - abs(source_position[mu]));
100  }
101 
102  if (err) {
103  vout.crucial(m_vl, "Source_Local: parameter range check failed.\n");
104  abort();
105  }
106 
107  assert(source_position.size() == Ndim);
108 
109  //- store values
110  m_source_position.resize(Ndim);
111  m_source_position = source_position;
112 
113  for (int mu = 0; mu < Ndim; ++mu) {
114  while (m_source_position[mu] < 0)
115  {
116  m_source_position[mu] += Lsize[mu];
117  }
118  m_source_position[mu] %= Lsize[mu];
119  }
120 
121 
122  //- post-process
123  valarray<int> Nsize(Ndim);
124  Nsize[0] = CommonParameters::Nx();
125  Nsize[1] = CommonParameters::Ny();
126  Nsize[2] = CommonParameters::Nz();
127  Nsize[3] = CommonParameters::Nt();
128 
129  //- check if source position is in current local node.
130  m_in_node = true;
131  for (int i = 0; i < Ndim; ++i) {
132  int inode = m_source_position[i] / Nsize[i];
133 
134  if (inode != Communicator::ipe(i)) {
135  m_in_node = false;
136  break;
137  }
138  }
139 
140  //- find local coordinate of source position.
141  if (m_in_node) {
142  for (int i = 0; i < Ndim; ++i) {
143  m_source_position[i] %= Nsize[i];
144  }
145  } else {
146  for (int i = 0; i < Ndim; ++i) {
147  m_source_position[i] = -1;
148  }
149  }
150 }
151 
152 
153 //====================================================================
154 void Source_Local::set(Field& src, int j)
155 {
156  //- clear field
157  src = 0.0;
158 
159  if (m_in_node) {
160  int isite = m_index.site(
165  );
166 
167  //XXX complex as two doubles
168  src.set(2 * j, isite, 0, 1.0);
169  }
170 }
171 
172 
173 //====================================================================
174 //============================================================END=====