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

  // Get the number of basis functions
  unsigned int n_bfs = get_n_basis_functions();
  
  // The writing mode: ENCODE for binary, WRITE for ASCII
  XdrMODE mode = write_binary_data ? ENCODE : WRITE;
  
  // The suffix to use for all the files that are written out
  const std::string suffix = write_binary_data ? ".xdr" : ".dat";

  if(libMesh::processor_id() == 0)
  {

    // Make a directory to store all the data files
    mkdir(directory_name.c_str(), 0777);
//    if( mkdir(directory_name.c_str(), 0777) == -1)
//    {
//      libMesh::out << "In RBEvaluation::write_offline_data_to_files, directory "
//                   << directory_name << " already exists, overwriting contents." << std::endl;
//    }

    // First, write out how many basis functions we have generated
    std::ostringstream file_name;
    {
      file_name << directory_name << "/n_bfs" << suffix;
      Xdr n_bfs_out(file_name.str(), mode);
      n_bfs_out << n_bfs;
      n_bfs_out.close();
    }
    
    // Write out the parameter ranges
    file_name.str("");
    file_name << directory_name << "/parameter_ranges" << suffix;
    write_parameter_ranges_to_file(file_name.str(), write_binary_data);

    // Write out Fq representor norm data
    file_name.str("");
    file_name << directory_name << "/Fq_innerprods" << suffix;
    Xdr RB_Fq_innerprods_out(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_out << Fq_representor_innerprods[i];
    }
    RB_Fq_innerprods_out.close();

    // Write out 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_out(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_out << output_dual_innerprods[n][q];
      }
      output_dual_innerprods_out.close();
    }


    // Write out output data to 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_out(file_name.str(), mode);

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

    if(compute_RB_inner_product)
    {
      // Next write out the inner product matrix
      file_name.str("");
      file_name << directory_name << "/RB_inner_product_matrix" << suffix;
      Xdr RB_inner_product_matrix_out(file_name.str(), mode);
      for(unsigned int i=0; i<n_bfs; i++)
      {
        for(unsigned int j=0; j<n_bfs; j++)
        {
          RB_inner_product_matrix_out << RB_inner_product_matrix(i,j);
        }
      }
      RB_inner_product_matrix_out.close();
    }

    // Next write out 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_out(file_name.str(), mode);

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

    // Next write out 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_out(file_name.str(), mode);

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

    // Next write out Fq_Aq representor norm data
    file_name.str("");
    file_name << directory_name << "/Fq_Aq_innerprods" << suffix;
    Xdr RB_Fq_Aq_innerprods_out(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_out << Fq_Aq_representor_innerprods[q_f][q_a][i];
        }
      }
    }
    RB_Fq_Aq_innerprods_out.close();

    // Next write out Aq_Aq representor norm data
    file_name.str("");
    file_name << directory_name << "/Aq_Aq_innerprods" << suffix;
    Xdr RB_Aq_Aq_innerprods_out(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_out << Aq_Aq_representor_innerprods[i][j][l];
        }
      }
    }
    RB_Aq_Aq_innerprods_out.close();

    // Also, write out the greedily selected parameters
    {
      file_name.str("");
      file_name << directory_name << "/greedy_params" << suffix;
      Xdr greedy_params_out(file_name.str(), mode);
      
      for(unsigned int i=0; i<greedy_param_list.size(); i++)
      {
        RBParameters::const_iterator it     = greedy_param_list[i].begin();
        RBParameters::const_iterator it_end = greedy_param_list[i].end();
        for( ; it != it_end; ++it)
        {
          // Need to make a copy of the value so that it's not const
          // Xdr is not templated on const's
          Real param_value = it->second;
          greedy_params_out << param_value;
        }
      }
      greedy_params_out.close();
    }

  }

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

  if(this->processor_id() == 0)
  {
    // Make a directory to store all the data files
    if( mkdir(directory_name.c_str(), 0777) == -1)
    {
      libMesh::out << "In RBSCMEvaluation::write_offline_data_to_files, directory "
                   << directory_name << " already exists, overwriting contents." << std::endl;
    }

    // The writing mode: ENCODE for binary, WRITE for ASCII
    XdrMODE mode = write_binary_data ? ENCODE : WRITE;

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

    // Stream for building the file names
    std::ostringstream file_name;

    // Write out the parameter ranges
    file_name.str("");
    file_name << directory_name << "/parameter_ranges" << suffix;
    write_parameter_ranges_to_file(file_name.str(), write_binary_data);

    // Write out the bounding box min values
    file_name.str("");
    file_name << directory_name << "/B_min" << suffix;
    Xdr B_min_out(file_name.str(), mode);

    for(unsigned int i=0; i<B_min.size(); i++)
    {
      Real B_min_i = get_B_min(i);
      B_min_out << B_min_i;
    }
    B_min_out.close();


    // Write out the bounding box max values
    file_name.str("");
    file_name << directory_name << "/B_max" << suffix;
    Xdr B_max_out(file_name.str(), mode);

    for(unsigned int i=0; i<B_max.size(); i++)
    {
      Real B_max_i = get_B_max(i);
      B_max_out << B_max_i;
    }
    B_max_out.close();

    // Write out the length of the C_J data
    file_name.str("");
    file_name << directory_name << "/C_J_length" << suffix;
    Xdr C_J_length_out(file_name.str(), mode);

    unsigned int C_J_length = C_J.size();
    C_J_length_out << C_J_length;
    C_J_length_out.close();

    // Write out C_J_stability_vector
    file_name.str("");
    file_name << directory_name << "/C_J_stability_vector" << suffix;
    Xdr C_J_stability_vector_out(file_name.str(), mode);

    for(unsigned int i=0; i<C_J_stability_vector.size(); i++)
    {
      Real C_J_stability_constraint_i = get_C_J_stability_constraint(i);
      C_J_stability_vector_out << C_J_stability_constraint_i;
    }
    C_J_stability_vector_out.close();

    // Write out C_J
    file_name.str("");
    file_name << directory_name << "/C_J" << suffix;
    Xdr C_J_out(file_name.str(), mode);

    for(unsigned int i=0; i<C_J.size(); i++)
    {
      RBParameters::const_iterator it     = C_J[i].begin();
      RBParameters::const_iterator it_end = C_J[i].end();
      for( ; it != it_end; ++it)
      {
        // Need to make a copy of the value so that it's not const
        // Xdr is not templated on const's
        Real param_value = it->second;
        C_J_out << param_value;
      }
    }
    C_J_out.close();

    // Write out SCM_UB_vectors get_SCM_UB_vector
    file_name.str("");
    file_name << directory_name << "/SCM_UB_vectors" << suffix;
    Xdr SCM_UB_vectors_out(file_name.str(), mode);

    for(unsigned int i=0; i<SCM_UB_vectors.size(); i++)
    {
      for(unsigned int j=0; j<rb_theta_expansion->get_n_A_terms(); j++)
      {
        Real SCM_UB_vector_ij = get_SCM_UB_vector(i,j);
        SCM_UB_vectors_out << SCM_UB_vector_ij;
      }
    }
    SCM_UB_vectors_out.close();
  }

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