예제 #1
0
파일: square.hpp 프로젝트: todo-group/exact
 void init() {
   neighbors_.resize(num_sites());
   source_.resize(num_bonds());
   target_.resize(num_bonds());
   site_phase_.resize(num_sites());
   bond_phase_.resize(num_bonds());
   for (unsigned int s = 0; s < num_sites(); ++s) {
     int x, y;
     boost::tie(x, y) = index2xy(s);
     site_phase_[s] = 2.0 * ((x + y) % 2) - 1.0;
     for (unsigned int k = 0; k < 4; ++k) {
       int d = 1- int(k & 2);
       neighbors_[s][k] = ((k & 1) == 0) ? xy2index(x + d, y) : xy2index(x, y + d);
     }
   }
   for (unsigned int b = 0; b < num_bonds(); ++b) {
     unsigned int s = b / 2;
     int x, y;
     boost::tie(x, y) = index2xy(s);
     unsigned int t;
     if (b % 2 == 0) {
       t = xy2index(x + 1, y); // target right
       bond_phase_[b] = 2.0 * ((b / 2) % 2) - 1.0;
     } else {
       t = xy2index(x, y + 1); // target below
       bond_phase_[b] = 2.0 * ((b / length_x_ / 2) % 2) - 1.0;
     }
     source_[b] = s;
     target_[b] = t;
   }
 }
예제 #2
0
 void init() {
   source_.resize(num_bonds());
   target_.resize(num_bonds());
   site_phase_.resize(num_sites());
   bond_phase_.resize(num_bonds());
   for (unsigned int s = 0; s < num_sites(); ++s) {
     int x, y;
     boost::tie(x, y) = index2xy(s);
     site_phase_[s] = 2 * ((x + y) % 2) - 1;
   }
   for (unsigned int b = 0; b < num_bonds(); ++b) {
     unsigned int s = b / 2;
     int x, y;
     boost::tie(x, y) = index2xy(s);
     unsigned int t;
     if (b % 2 == 0) {
       t = xy2index(x + 1, y); // target right
       bond_phase_[b] = 2.0 * ((b / 2) % 2) - 1.0;
     } else {
       t = xy2index(x, y + 1); // target below
       bond_phase_[b] = 2.0 * ((b / length_x_ / 2) % 2) - 1.0;
     }
     source_[b] = s;
     target_[b] = t;
   }
 }
예제 #3
0
파일: qio_util.cpp 프로젝트: alexstrel/quda
int vcreate_M(suN_matrix *field[], int count)
{
  int i;
  /* Create an output field */
  for(i = 0; i < count; i++){
    field[i] = (suN_matrix *)malloc(sizeof(suN_matrix)*num_sites(this_node));
    if(field[i] == NULL){
      printf("vcreate_M(%d): Can't malloc field\n",this_node);
      return 1;
    }
  }

  return 0;
}
예제 #4
0
int System::find_nearest(Cartesian target_position, sub_id target_sublattice) const {
    auto nearest_index = 0;
    auto min_distance = (positions[0] - target_position).norm();

    for (auto i = 1; i < num_sites(); ++i) {
        if (target_sublattice >= 0 && sublattices[i] != target_sublattice)
            continue; // only check the target sublattice (if any)

        auto const distance = (positions[i] - target_position).norm();
        if (distance < min_distance) {
            min_distance = distance;
            nearest_index = i;
        }
    }
    
    return nearest_index;
}
예제 #5
0
파일: qio_util.cpp 프로젝트: alexstrel/quda
float vcompare_M (suN_matrix *fielda[], suN_matrix *fieldb[], int count)
{
  int i,j,k,m;
  float diff;
  float sum2 = 0;
  
  for(k = 0; k < count; k++)for(m = 0; m < num_sites(this_node); m++)
    {
      for ( j=0; j< NCLR; j++)
	for ( i=0; i< NCLR; i++)
	  {
	    diff = fielda[k][m].e[j][i].re - fieldb[k][m].e[j][i].re;
	    sum2 += diff*diff;
	    diff = fielda[k][m].e[j][i].im - fieldb[k][m].e[j][i].im;
	    sum2 += diff*diff;
	  }
    }

  /* Global sum */
  QMP_sum_float(&sum2);
  return sum2;
}
예제 #6
0
System::System(Foundation const& foundation, TranslationalSymmetry const& symmetry,
               Leads const& leads, HoppingGenerators const& hopping_generators)
    : lattice(foundation.get_lattice()) {
    auto const hamiltonian_indices = HamiltonianIndices(foundation);
    detail::populate_system(*this, foundation, hamiltonian_indices);
    if (symmetry) {
        detail::populate_boundaries(*this, foundation, hamiltonian_indices, symmetry);
    }

    for (auto const& lead : leads) {
        ports.emplace_back(foundation, hamiltonian_indices, lead);
    }

    if (!hopping_generators.empty()) {
        for (auto const& gen : hopping_generators) {
            detail::add_extra_hoppings(*this, gen);
        }
        hoppings.makeCompressed();
        has_unbalanced_hoppings = true;
    }

    if (num_sites() == 0)
        throw std::runtime_error{"Impossible system: built 0 lattice sites"};
}
예제 #7
0
int qio_test(int output_volfmt, int output_serpar, int ildgstyle, 
	     int input_volfmt, int input_serpar, int argc, char *argv[]){

  float array_in[NARRAY], array_out[NARRAY];
  float *field_in[NREAL], *subset_in[NREAL], 
    *field_out[NREAL], *subset_out[NREAL];
  suN_matrix *field_su3_out[NMATRIX], *field_su3_in[NMATRIX];
  QIO_Writer *outfile;
  QIO_Reader *infile;
  float diff_field = 0, diff_array = 0, diff_su3 = 0, diff_subset = 0;
  QMP_thread_level_t provided;
  int status;
  int sites_on_node = 0;
  int i,volume;
  char filename[] = "binary_test";
  int dim = 4;
  int lower[4] = {1, 0, 0, 2};
  int upper[4] = {2, 3, 3, 2};
  char myname[] = "qio_test";
  
  /* Start message passing */
  QMP_init_msg_passing(&argc, &argv, QMP_THREAD_SINGLE, &provided);

  this_node = mynode();
  printf("%s(%d) QMP_init_msg_passing done\n",myname,this_node);

  /* Lattice dimensions */
  lattice_dim = 4;
  lattice_size[0] = 8;
  lattice_size[1] = 4;
  lattice_size[2] = 4;
  lattice_size[3] = 4;

  volume = 1;
  for(i = 0; i < lattice_dim; i++){
    volume *= lattice_size[i];
  }

  /* Set the mapping of coordinates to nodes */
  if(setup_layout(lattice_size, 4, QMP_get_number_of_nodes())!=0)
    return 1;
  printf("%s(%d) layout set for %d nodes\n",myname,this_node,
	 QMP_get_number_of_nodes());
  sites_on_node = num_sites(this_node);

  /* Build the layout structure */
  layout.node_number     = node_number;
  layout.node_index      = node_index;
  layout.get_coords      = get_coords;
  layout.num_sites       = num_sites;
  layout.latsize         = lattice_size;
  layout.latdim          = lattice_dim;
  layout.volume          = volume;
  layout.sites_on_node   = sites_on_node;
  layout.this_node       = this_node;
  layout.number_of_nodes = QMP_get_number_of_nodes();

  /* Open the test output file */
  outfile = open_test_output(filename, output_volfmt, output_serpar, 
			     ildgstyle, myname);
  if(outfile == NULL)return 1;

  /* If this is not the ILDG file test */
  if(ildgstyle == QIO_ILDGNO){
    /* Create the test output field */
    status = vcreate_R(field_out, NREAL);
    if(status)return status;
    
    /* Set some values for the field */
    vset_R(field_out, NREAL);
    
    /* Write the real test field */
    status = write_real_field(outfile, NREAL, field_out, myname);
    if(status)return status;
    
    /* Write a subset of the real test field */
    status = write_real_field_subset(outfile, NREAL, field_out, 
				     lower, upper, dim, myname);
    if(status)return status;
    
    /* Set some values for the global array */
    for(i = 0; i < NARRAY; i++)
      array_out[i] = i;
    
    /* Write the real global array */
    status = write_real_global(outfile, NARRAY, array_out, myname);
    if(status)return status;
  }

  /* Create the test output su3 field */
  status = vcreate_M(field_su3_out, NMATRIX);
  if(status)return status;

  /* Set some values for the su3 field */
  vset_M(field_su3_out, NMATRIX);

  /* Write the su3 test field */
  status = write_su3_field(outfile, NMATRIX, field_su3_out, myname);
  if(status)return status;

  /* Close the file */
  QIO_close_write(outfile);
  printf("%s(%d): Closed file for writing\n",myname,this_node);

  /* Set up a dummy input field */
  status = vcreate_R(field_in, NREAL);
  if(status)return status;
    
  /* Set up a dummy input field for subset */
  status = vcreate_R(subset_in, NREAL);
  if(status)return status;
    
  /* Set up a dummy input SU(N) field */
  status = vcreate_M(field_su3_in, NMATRIX);
  if(status)return status;

  /* Open the test file for reading */
  infile = open_test_input(filename, input_volfmt, input_serpar, myname);
  if(infile == NULL)return 1;

  if(ildgstyle == QIO_ILDGNO){
    /* Peek at the field record */
    status = peek_record_info(infile, myname);
    if(status != QIO_SUCCESS)return status;
    /* Skip the record */

#if(0)
    
    /* Skip the field */
    status = QIO_next_record(infile);
    if(status != QIO_SUCCESS)return status;
    
#else
    
    /* Read the field record */
    printf("%s(%d) reading real field\n",myname,this_node); fflush(stdout);
    status = read_real_field(infile, NREAL, field_in, myname);
    if(status)return status;
    
#endif

    /* Read the subset of the field */
    printf("%s(%d) reading subset of real field\n",
	   myname,this_node); fflush(stdout);
    status = read_real_field_subset(infile, NREAL, subset_in, myname);
    if(status)return status;
    
    /* Read the global array record */
    printf("%s(%d) reading global field\n",myname,this_node); fflush(stdout);
    status = read_real_global(infile, NARRAY, array_in, myname);
    if(status)return status;

  }    

  /* Read the su3 field record */
  printf("%s(%d) reading su3 field\n",myname,this_node); fflush(stdout);
  status = read_su3_field(infile, NMATRIX, field_su3_in, myname);
  if(status)return status;

  /* Close the file */
  QIO_close_read(infile);
  printf("%s(%d): Closed file for reading\n",myname,this_node);

  if(ildgstyle == QIO_ILDGNO){

    /* Compare the input and output fields */
    diff_field = vcompare_R(field_out, field_in, NREAL);
    if(this_node == 0){
      printf("%s(%d): Comparison of in and out real fields |in - out|^2 = %e\n",
	     myname,this_node,diff_field);
    }
    
    /* Create the subset output field */
    status = vcreate_R(subset_out, NREAL);
    if(status)return status;

    /* Copy the subset */
    vsubset_R(subset_out, field_out, lower, upper, NREAL);
    
    /* Compare the input and output subsets */
    diff_subset = vcompare_R(subset_out, subset_in, NREAL);
    if(this_node == 0){
      printf("%s(%d): Comparison of subsets of in and out real fields |in - out|^2 = %e\n",
	     myname,this_node,diff_subset);
    }
    
    /* Compare the input and output global arrays */
    diff_array = vcompare_r(array_out, array_in, NREAL);
    if(this_node == 0){
      printf("%s(%d): Comparison of in and out real global arrays |in - out|^2 = %e\n",
	     myname, this_node, diff_array);
    }
  }

  /* Compare the input and output suN fields */
  diff_su3 = vcompare_M(field_su3_out, field_su3_in, NMATRIX);
  if(this_node == 0){
    printf("%s(%d): Comparison of in and out suN fields |in - out|^2 = %e\n",
	   myname, this_node, diff_field);
  }

  /* Clean up */
  if(ildgstyle == QIO_ILDGNO){
    vdestroy_R(field_out, NREAL);
    vdestroy_R(field_in, NREAL);
    vdestroy_R(subset_in, NREAL);
    vdestroy_R(subset_out, NREAL);
  }
  vdestroy_M(field_su3_in, NMATRIX);
  vdestroy_M(field_su3_out, NMATRIX);

  /* Shut down QMP */
  QMP_finalize_msg_passing();

  /* Report result */
  if(diff_field + diff_subset + diff_su3 + diff_array > 0){
    printf("%s(%d): Test failed\n",myname,this_node);
    return 1;
  }
  printf("%s(%d): Test passed\n",myname,this_node);

  return 0;
}
예제 #8
0
int qio_num_sites(int node){
  return num_sites(node);
}
예제 #9
0
파일: square.hpp 프로젝트: todo-group/exact
 unsigned int num_bonds() const { return 2 * num_sites(); }