19 #include "libmesh/libmesh_common.h" 
   20 #include "libmesh/libmesh_logging.h" 
   28 #include "libmesh/libmesh_version.h" 
   29 #include "libmesh/equation_systems.h" 
   30 #include "libmesh/mesh_base.h" 
   31 #include "libmesh/mesh_tools.h" 
   32 #include "libmesh/parallel.h" 
   33 #include "libmesh/xdr_cxx.h" 
   34 #include "libmesh/mesh_refinement.h" 
   43 std::string local_file_name (
const unsigned int processor_id,
 
   44                              const std::string & 
name)
 
   46   std::string basename(
name);
 
   49   if (basename.size() - basename.rfind(
".bz2") == 4)
 
   51       basename.erase(basename.end()-4, basename.end());
 
   52       std::sprintf(buf, 
"%s.%04u.bz2", basename.c_str(), processor_id);
 
   54   else if (basename.size() - basename.rfind(
".gz") == 3)
 
   56       basename.erase(basename.end()-3, basename.end());
 
   57       std::sprintf(buf, 
"%s.%04u.gz", basename.c_str(), processor_id);
 
   60     std::sprintf(buf, 
"%s.%04u", basename.c_str(), processor_id);
 
   62   return std::string(buf);
 
   71 template <
typename InValType>
 
   73                             const unsigned int read_flags,
 
   74                             bool partition_agnostic)
 
   77   if (
name.find(
".xdr") != std::string::npos)
 
   79   this->
read(name, mode, read_flags, partition_agnostic);
 
   81 #ifdef LIBMESH_ENABLE_AMR 
   89 template <
typename InValType>
 
   92                             const unsigned int read_flags,
 
   93                             bool partition_agnostic)
 
  103       this->_read_impl<InValType> (
name, mode, read_flags, partition_agnostic);
 
  109       libMesh::out << 
"\n*********************************************************************\n" 
  110                    << 
"READING THE FILE \"" << 
name << 
"\" FAILED.\n" 
  111                    << 
"It is possible this file contains infinite element information,\n" 
  112                    << 
"but the version string does not contain \" with infinite elements\"\n" 
  113                    << 
"Let's try this again, but looking for infinite element information...\n" 
  114                    << 
"*********************************************************************\n" 
  125           libMesh::out << 
"\n*********************************************************************\n" 
  126                        << 
"Well, at least we tried!\n" 
  128                        << 
"*********************************************************************\n" 
  134 #ifdef LIBMESH_ENABLE_AMR 
  142 template <
typename InValType>
 
  145                                   const unsigned int read_flags,
 
  146                                   bool partition_agnostic)
 
  218   bool read_parallel_files  = 
false;
 
  220   std::vector<std::pair<std::string, System *>> xda_systems;
 
  230     std::string version = 
"legacy";
 
  231     if (!read_legacy_format)
 
  234         this->
comm().broadcast(version);
 
  238         const std::string libMesh_label = 
"libMesh-";
 
  239         std::string::size_type lm_pos = version.find(libMesh_label);
 
  240         if (lm_pos==std::string::npos)
 
  251         std::istringstream iss(version.substr(lm_pos + libMesh_label.size()));
 
  252         int ver_major = 0, ver_minor = 0, ver_patch = 0;
 
  254         iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch;
 
  255         io.
set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch));
 
  258         read_parallel_files = (version.rfind(
" parallel") < version.size());
 
  265           if (!(version.rfind(
" with infinite elements") < version.size()))
 
  266             version += 
" with infinite elements";
 
  270       libmesh_deprecated();
 
  272     START_LOG(
"read()",
"EquationSystems");
 
  276     unsigned int n_sys=0;
 
  278     this->
comm().broadcast(n_sys);
 
  280     for (
unsigned int sys=0; sys<n_sys; sys++)
 
  284         std::string sys_name;
 
  286         this->
comm().broadcast(sys_name);
 
  290         std::string sys_type;
 
  292         this->
comm().broadcast(sys_type);
 
  303                                 read_additional_data,
 
  306         xda_systems.push_back(std::make_pair(sys_name, &new_system));
 
  330       if (!read_legacy_format && partition_agnostic)
 
  336       Xdr local_io (read_parallel_files ? local_file_name(this->
processor_id(),name) : 
"", mode);
 
  338       for (
auto & pr : xda_systems)
 
  339         if (read_legacy_format)
 
  341             libmesh_deprecated();
 
  342 #ifdef LIBMESH_ENABLE_DEPRECATED 
  343             pr.second->read_legacy_data (io, read_additional_data);
 
  347           if (read_parallel_files)
 
  348             pr.second->read_parallel_data<InValType>   (local_io, read_additional_data);
 
  350             pr.second->read_serialized_data<InValType> (io, read_additional_data);
 
  354       if (!read_legacy_format && partition_agnostic)
 
  358   STOP_LOG(
"read()",
"EquationSystems");
 
  367                             const unsigned int write_flags,
 
  368                             bool partition_agnostic)
 const 
  371   if (
name.find(
".xdr") != std::string::npos)
 
  373   this->
write(name, mode, write_flags, partition_agnostic);
 
  380                             const unsigned int write_flags,
 
  381                             bool partition_agnostic)
 const 
  449   if (partition_agnostic)
 
  461   const bool write_parallel_files  =
 
  480     LOG_SCOPE(
"write()", 
"EquationSystems");
 
  484     unsigned int n_sys = 0;
 
  486       if (!pr.second->hide_output())
 
  490     io.
set_version(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION,
 
  491                                       LIBMESH_MINOR_VERSION,
 
  492                                       LIBMESH_MICRO_VERSION));
 
  504         if (write_parallel_files) version += 
" parallel";
 
  506 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 
  507         version += 
" with infinite elements";
 
  509         io.
data (version, 
"# File Format Identifier");
 
  513         io.
data (n_sys, 
"# No. of Equation Systems");
 
  518             if (pr.second->hide_output()) 
continue;
 
  523               const unsigned int sys_num = pr.second->number();
 
  524               std::string sys_name       = pr.first;
 
  526               comment =  
"# Name, System No. ";
 
  527               std::sprintf(buf, 
"%u", sys_num);
 
  530               io.
data (sys_name, comment.c_str());
 
  536               const unsigned int sys_num = pr.second->number();
 
  537               std::string sys_type       = pr.second->system_type();
 
  539               comment =  
"# Type, System No. ";
 
  540               std::sprintf(buf, 
"%u", sys_num);
 
  543               io.
data (sys_type, comment.c_str());
 
  548             pr.second->write_header (io, version, write_additional_data);
 
  557         Xdr local_io (write_parallel_files ? local_file_name(this->
processor_id(),name) : 
"", mode);
 
  562             if (pr.second->hide_output()) 
continue;
 
  565             if (write_parallel_files)
 
  566               pr.second->write_parallel_data (local_io,write_additional_data);
 
  568               pr.second->write_serialized_data (io,write_additional_data);
 
  576   if (partition_agnostic)
 
  577     const_cast<MeshBase &>(
_mesh).fix_broken_node_and_element_numbering();
 
  584 template void EquationSystems::read<Number> (
const std::string & 
name, 
const unsigned int read_flags, 
bool partition_agnostic);
 
  585 template void EquationSystems::read<Number> (
const std::string & 
name, 
const XdrMODE mode, 
const unsigned int read_flags, 
bool partition_agnostic);
 
  586 template void EquationSystems::_read_impl<Number> (
const std::string & 
name, 
const XdrMODE mode, 
const unsigned int read_flags, 
bool partition_agnostic);
 
  587 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 
  588 template void EquationSystems::read<Real> (
const std::string & 
name, 
const unsigned int read_flags, 
bool partition_agnostic);
 
  589 template void EquationSystems::read<Real> (
const std::string & 
name, 
const XdrMODE mode, 
const unsigned int read_flags, 
bool partition_agnostic);
 
  590 template void EquationSystems::_read_impl<Real> (
const std::string & 
name, 
const XdrMODE mode, 
const unsigned int read_flags, 
bool partition_agnostic);