Exemplo n.º 1
0
void RBEvaluation::read_offline_data_from_files(const std::string& directory_name,
                                                bool read_error_bound_data,
                                                const bool read_binary_data)
{
  START_LOG("read_offline_data_from_files()", "RBEvaluation");

  // The reading mode: DECODE for binary, READ for ASCII
  XdrMODE mode = read_binary_data ? DECODE : READ;
  
  // The suffix to use for all the files that are written out
  const std::string suffix = read_binary_data ? ".xdr" : ".dat";

  // The string stream we'll use to make the file names
  std::ostringstream file_name;

  // First, find out how many basis functions we had when Greedy terminated
  unsigned int n_bfs;
  {
    file_name << directory_name << "/n_bfs" << suffix;
    Xdr n_bfs_in(file_name.str(), mode);

    n_bfs_in >> n_bfs;
    n_bfs_in.close();
  }

  resize_data_structures(n_bfs, read_error_bound_data);
  
  // Read in the parameter ranges
  file_name.str("");
  file_name << directory_name << "/parameter_ranges" << suffix;
  read_parameter_ranges_from_file(file_name.str(), read_binary_data);

  // Read in output data in multiple files
  for(unsigned int n=0; n<rb_theta_expansion->get_n_outputs(); n++)
  {
    for(unsigned int q_l=0; q_l<rb_theta_expansion->get_n_output_terms(n); q_l++)
    {
      file_name.str("");
      file_name << directory_name << "/output_";
      file_name << std::setw(3)
                << std::setprecision(0)
                << std::setfill('0')
                << std::right
                << n;
      file_name << "_";
      file_name << std::setw(3)
                << std::setprecision(0)
                << std::setfill('0')
                << std::right
                << q_l;
      file_name << suffix;
      Xdr output_n_in(file_name.str(), mode);

      for(unsigned int j=0; j<n_bfs; j++)
      {
        Number value;
        output_n_in >> value;
        RB_output_vectors[n][q_l](j) = value;
      }
      output_n_in.close();
    }
  }

  if(compute_RB_inner_product)
  {
    // Next read in the inner product matrix
    file_name.str("");
    file_name << directory_name << "/RB_inner_product_matrix" << suffix;
    Xdr RB_inner_product_matrix_in(file_name.str(), mode);
    
    for(unsigned int i=0; i<n_bfs; i++)
    {
      for(unsigned int j=0; j<n_bfs; j++)
      {
        Number value;
        RB_inner_product_matrix_in >> value;
        RB_inner_product_matrix(i,j) = value;
      }
    }
    RB_inner_product_matrix_in.close();
  }

  // Next read in the Fq vectors
  for(unsigned int q_f=0; q_f<rb_theta_expansion->get_n_F_terms(); q_f++)
  {
    file_name.str("");
    file_name << directory_name << "/RB_F_";
    file_name << std::setw(3)
              << std::setprecision(0)
              << std::setfill('0')
              << std::right
              << q_f;
    file_name << suffix;
    Xdr RB_Fq_f_in(file_name.str(), mode);

    for(unsigned int i=0; i<n_bfs; i++)
    {
      Number value;
      RB_Fq_f_in >> value;
      RB_Fq_vector[q_f](i) = value;
    }
    RB_Fq_f_in.close();
  }

  // Next read in the Aq matrices
  for(unsigned int q_a=0; q_a<rb_theta_expansion->get_n_A_terms(); q_a++)
  {
    file_name.str("");
    file_name << directory_name << "/RB_A_";
    file_name << std::setw(3)
              << std::setprecision(0)
              << std::setfill('0')
              << std::right
              << q_a;
    file_name << suffix;
    Xdr RB_Aq_a_in(file_name.str(), mode);

    for(unsigned int i=0; i<n_bfs; i++)
    {
      for(unsigned int j=0; j<n_bfs; j++)
      {
        Number  value;
        RB_Aq_a_in >> value;
        RB_Aq_vector[q_a](i,j) = value;
      }
    }
    RB_Aq_a_in.close();
  }


  if(read_error_bound_data)
  {
    // Next read in Fq representor norm data
    file_name.str("");
    file_name << directory_name << "/Fq_innerprods" << suffix;
    Xdr RB_Fq_innerprods_in(file_name.str(), mode);
    
    unsigned int Q_f_hat = rb_theta_expansion->get_n_F_terms()*(rb_theta_expansion->get_n_F_terms()+1)/2;
    for(unsigned int i=0; i<Q_f_hat; i++)
    {
      RB_Fq_innerprods_in >> Fq_representor_innerprods[i];
    }
    RB_Fq_innerprods_in.close();

    // Read in output data
    for(unsigned int n=0; n<rb_theta_expansion->get_n_outputs(); n++)
    {
      file_name.str("");
      file_name << directory_name << "/output_";
      file_name << std::setw(3)
                << std::setprecision(0)
                << std::setfill('0')
                << std::right
                << n;
      file_name << "_dual_innerprods" << suffix;
      Xdr output_dual_innerprods_in(file_name.str(), mode);
      
      unsigned int Q_l_hat = rb_theta_expansion->get_n_output_terms(n)*(rb_theta_expansion->get_n_output_terms(n)+1)/2;
      for(unsigned int q=0; q<Q_l_hat; q++)
      {
        output_dual_innerprods_in >> output_dual_innerprods[n][q];
      }
      output_dual_innerprods_in.close();
    }


    // Next read in Fq_Aq representor norm data
    file_name.str("");
    file_name << directory_name << "/Fq_Aq_innerprods" << suffix;
    Xdr RB_Fq_Aq_innerprods_in(file_name.str(), mode);
    
    for(unsigned int q_f=0; q_f<rb_theta_expansion->get_n_F_terms(); q_f++)
    {
      for(unsigned int q_a=0; q_a<rb_theta_expansion->get_n_A_terms(); q_a++)
      {
        for(unsigned int i=0; i<n_bfs; i++)
        {
          RB_Fq_Aq_innerprods_in >> Fq_Aq_representor_innerprods[q_f][q_a][i];
        }
      }
    }
    RB_Fq_Aq_innerprods_in.close();

    // Next read in Aq_Aq representor norm data
    file_name.str("");
    file_name << directory_name << "/Aq_Aq_innerprods" << suffix;
    Xdr RB_Aq_Aq_innerprods_in(file_name.str(), mode);
    
    unsigned int Q_a_hat = rb_theta_expansion->get_n_A_terms()*(rb_theta_expansion->get_n_A_terms()+1)/2;
    for(unsigned int i=0; i<Q_a_hat; i++)
    {
      for(unsigned int j=0; j<n_bfs; j++)
      {
        for(unsigned int l=0; l<n_bfs; l++)
        {
          RB_Aq_Aq_innerprods_in >> Aq_Aq_representor_innerprods[i][j][l];
        }
      }
    }
    RB_Aq_Aq_innerprods_in.close();
  }

  // Resize basis_functions even if we don't read them in so that
  // get_n_bfs() returns the correct value. Initialize the pointers
  // to NULL
  set_n_basis_functions(n_bfs);
  for(unsigned int i=0; i<basis_functions.size(); i++)
    {
      if(basis_functions[i])
      {
        basis_functions[i]->clear();
        delete basis_functions[i];
      }
      basis_functions[i] = NULL;
    }

  STOP_LOG("read_offline_data_from_files()", "RBEvaluation");
}
Exemplo n.º 2
0
void RBSCMEvaluation::read_offline_data_from_files(const std::string& directory_name,
                                                   const bool read_binary_data)
{
  START_LOG("read_offline_data_from_files()", "RBSCMEvaluation");

  // The reading mode: DECODE for binary, READ for ASCII
  XdrMODE mode = read_binary_data ? DECODE : READ;

  // The suffix to use for all the files that are written out
  const std::string suffix = read_binary_data ? ".xdr" : ".dat";

  // The string stream we'll use to make the file names
  std::ostringstream file_name;

  // Read in the parameter ranges
  file_name.str("");
  file_name << directory_name << "/parameter_ranges" << suffix;
  read_parameter_ranges_from_file(file_name.str(), read_binary_data);

  // Read in the bounding box min values
  // Note that there are Q_a values
  file_name.str("");
  file_name << directory_name << "/B_min" << suffix;
  Xdr B_min_in(file_name.str(), mode);

  B_min.clear();
  for(unsigned int i=0; i<rb_theta_expansion->get_n_A_terms(); i++)
  {
    Real B_min_val;
    B_min_in >> B_min_val;
    B_min.push_back(B_min_val);
  }
  B_min_in.close();


  // Read in the bounding box max values
  // Note that there are Q_a values
  file_name.str("");
  file_name << directory_name << "/B_max" << suffix;
  Xdr B_max_in(file_name.str(), mode);

  B_max.clear();
  for(unsigned int i=0; i<rb_theta_expansion->get_n_A_terms(); i++)
  {
    Real B_max_val;
    B_max_in >> B_max_val;
    B_max.push_back(B_max_val);
  }

  // Read in the length of the C_J data
  file_name.str("");
  file_name << directory_name << "/C_J_length" << suffix;
  Xdr C_J_length_in(file_name.str(), mode);

  unsigned int C_J_length;
  C_J_length_in >> C_J_length;
  C_J_length_in.close();

  // Read in C_J_stability_vector
  file_name.str("");
  file_name << directory_name << "/C_J_stability_vector" << suffix;
  Xdr C_J_stability_vector_in(file_name.str(), mode);

  C_J_stability_vector.clear();
  for(unsigned int i=0; i<C_J_length; i++)
  {
    Real C_J_stability_val;
    C_J_stability_vector_in >> C_J_stability_val;
    C_J_stability_vector.push_back(C_J_stability_val);
  }
  C_J_stability_vector_in.close();

  // Read in C_J
  file_name.str("");
  file_name << directory_name << "/C_J" << suffix;
  Xdr C_J_in(file_name.str(), mode);

  // Resize C_J based on C_J_stability_vector and Q_a
  C_J.resize( C_J_length );
  for(unsigned int i=0; i<C_J.size(); i++)
  {
    RBParameters::const_iterator it     = get_parameters().begin();
    RBParameters::const_iterator it_end = get_parameters().end();
    for( ; it != it_end; ++it)
    {
      std::string param_name = it->first;
      Real param_value;
      C_J_in >> param_value;
      C_J[i].set_value(param_name, param_value);
    }
  }
  C_J_in.close();


  // Read in SCM_UB_vectors get_SCM_UB_vector
  file_name.str("");
  file_name << directory_name << "/SCM_UB_vectors" << suffix;
  Xdr SCM_UB_vectors_in(file_name.str(), mode);

  // Resize SCM_UB_vectors based on C_J_stability_vector and Q_a
  SCM_UB_vectors.resize( C_J_stability_vector.size() );
  for(unsigned int i=0; i<SCM_UB_vectors.size(); i++)
  {
    SCM_UB_vectors[i].resize( rb_theta_expansion->get_n_A_terms() );
    for(unsigned int j=0; j<rb_theta_expansion->get_n_A_terms(); j++)
    {
      SCM_UB_vectors_in >> SCM_UB_vectors[i][j];
    }
  }
  SCM_UB_vectors_in.close();

  STOP_LOG("read_offline_data_from_files()", "RBSCMEvaluation");
}