$extrastylesheet
#include <legacy_xdr_io.h>

Public Types | |
| enum | FileFormat { DEAL = 0, MGF = 1, LIBM = 2 } |
Public Member Functions | |
| LegacyXdrIO (MeshBase &, const bool=false) | |
| LegacyXdrIO (const MeshBase &, const bool=false) | |
| virtual | ~LegacyXdrIO () |
| virtual void | read (const std::string &) |
| void | read_mgf (const std::string &) |
| virtual void | write (const std::string &) |
| void | write_mgf (const std::string &) |
| void | read_mgf_soln (const std::string &name, std::vector< Number > &soln, std::vector< std::string > &var_names) const |
| void | write_mgf_soln (const std::string &name, std::vector< Number > &soln, std::vector< std::string > &var_names) const |
| bool & | binary () |
| bool | binary () const |
| virtual void | write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=NULL) |
| virtual void | write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) |
| unsigned int & | ascii_precision () |
Protected Member Functions | |
| MeshBase & | mesh () |
| void | set_n_partitions (unsigned int n_parts) |
| void | skip_comment_lines (std::istream &in, const char comment_start) |
| const MeshBase & | mesh () const |
Protected Attributes | |
| std::vector< bool > | elems_of_dimension |
| const bool | _is_parallel_format |
Private Member Functions | |
| void | read_ascii (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM) |
| void | read_binary (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM) |
| void | write_ascii (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM) |
| void | write_binary (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM) |
| void | read_mesh (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM, MeshData *=NULL) |
| void | write_mesh (const std::string &, const LegacyXdrIO::FileFormat=LegacyXdrIO::LIBM) |
| void | read_soln (const std::string &, std::vector< Real > &, std::vector< std::string > &) const |
| void | write_soln (const std::string &name, std::vector< Real > &soln, std::vector< std::string > &) const |
Private Attributes | |
| bool | _binary |
Definition at line 45 of file legacy_xdr_io.h.
Enumeration flag for the type of software. DEAL is old-style LibMesh files without adaptivity MGF is for files created by the MGF software package LIBM is for new files generated by LibMesh with adaptivity. You will likely use this one most often.
Definition at line 57 of file legacy_xdr_io.h.
| libMesh::LegacyXdrIO::LegacyXdrIO | ( | MeshBase & | mesh, |
| const bool | binary_in = false |
||
| ) | [explicit] |
Constructor. Takes a writeable reference to a mesh object. This is the constructor required to read a mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.
Definition at line 57 of file legacy_xdr_io.C.
| libMesh::LegacyXdrIO::LegacyXdrIO | ( | const MeshBase & | mesh, |
| const bool | binary_in = false |
||
| ) | [explicit] |
Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.
Definition at line 67 of file legacy_xdr_io.C.
| libMesh::LegacyXdrIO::~LegacyXdrIO | ( | ) | [virtual] |
| unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision | ( | ) | [inherited] |
Return/set the precision to use when writing ASCII files.
By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.
Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().
| bool & libMesh::LegacyXdrIO::binary | ( | ) |
Set the flag indicating if we should read/write binary.
Definition at line 83 of file legacy_xdr_io.C.
References _binary.
Referenced by read(), read_mesh(), read_mgf(), read_soln(), write(), write_mesh(), write_mgf(), and write_soln().
{
return _binary;
}
| bool libMesh::LegacyXdrIO::binary | ( | ) | const |
Read the flag indicating if we should read/write binary.
Definition at line 91 of file legacy_xdr_io.C.
References _binary.
{
return _binary;
}
| MeshBase & libMesh::MeshInput< MeshBase >::mesh | ( | ) | [protected, inherited] |
Returns the object as a writeable reference.
Referenced by libMesh::GMVIO::_read_materials(), libMesh::GMVIO::_read_nodes(), libMesh::GMVIO::_read_one_cell(), libMesh::AbaqusIO::assign_boundary_node_ids(), libMesh::AbaqusIO::assign_sideset_ids(), libMesh::AbaqusIO::assign_subdomain_ids(), libMesh::VTKIO::cells_to_vtk(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::GMVIO::copy_nodal_solution(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::AbaqusIO::read(), libMesh::NameBasedIO::read(), libMesh::TetGenIO::read(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::VTKIO::read(), read_ascii(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::AbaqusIO::read_elements(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), read_mesh(), libMesh::AbaqusIO::read_nodes(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::NameBasedIO::write(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::CheckpointIO::write_bcs(), libMesh::GMVIO::write_binary(), libMesh::CheckpointIO::write_connectivity(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::Nemesis_IO::write_nodal_data(), libMesh::NameBasedIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), write_soln(), and libMesh::CheckpointIO::write_subdomain_names().
| const MeshBase & libMesh::MeshOutput< MeshBase >::mesh | ( | ) | const [protected, inherited] |
Returns the object as a read-only reference.
Referenced by libMesh::TecplotIO::elem_dimension(), libMesh::FroIO::write(), libMesh::DivaIO::write(), libMesh::TecplotIO::write(), libMesh::PostscriptIO::write(), libMesh::MEDITIO::write(), libMesh::EnsightIO::write(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_ascii(), libMesh::TecplotIO::write_binary(), libMesh::EnsightIO::write_geometry_ascii(), libMesh::TecplotIO::write_nodal_data(), libMesh::MEDITIO::write_nodal_data(), libMesh::EnsightIO::write_scalar_ascii(), libMesh::GnuPlotIO::write_solution(), libMesh::DivaIO::write_stream(), and libMesh::EnsightIO::write_vector_ascii().
| void libMesh::LegacyXdrIO::read | ( | const std::string & | name | ) | [virtual] |
This method implements reading a mesh from a specified file.
Implements libMesh::MeshInput< MeshBase >.
Definition at line 98 of file legacy_xdr_io.C.
References binary(), libMesh::processor_id(), read_ascii(), and read_binary().
Referenced by libMesh::XdrIO::read().
{
// This is a serial-only process for now;
// the Mesh should be read on processor 0 and
// broadcast later
if (MeshOutput<MeshBase>::mesh().processor_id() != 0)
return;
if (this->binary())
this->read_binary (name);
else
this->read_ascii (name);
}
| void libMesh::LegacyXdrIO::read_ascii | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM |
||
| ) | [private] |
Read meshes in libMesh XDR format. Should be compatible with the mgf mesh file formats. This method actually expects an ASCII-file.
Definition at line 206 of file legacy_xdr_io.C.
References libMesh::MeshBase::clear(), libMesh::MeshInput< MeshBase >::mesh(), and read_mesh().
Referenced by read(), read_binary(), and read_mgf().
{
// get a writeable reference to the underlying mesh
MeshBase& mesh = MeshInput<MeshBase>::mesh();
// clear any existing mesh data
mesh.clear();
// read the mesh
this->read_mesh (name, originator);
}
| void libMesh::LegacyXdrIO::read_binary | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM |
||
| ) | [private] |
Read meshes in libMesh XDR format. Should be compatible with the mgf mesh file formats. This method expects an XDR-encoded binary file.
Definition at line 221 of file legacy_xdr_io.C.
References libMesh::err, and read_ascii().
Referenced by read(), and read_mgf().
{
libMesh::err << "WARNING: Compiled without XDR binary support.\n"
<< "Will try ASCII instead" << std::endl << std::endl;
this->read_ascii (name);
}
| void libMesh::LegacyXdrIO::read_mesh | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM, |
||
| MeshData * | mesh_data = NULL |
||
| ) | [private] |
Implements reading either a binary XDR or ASCII XDA mesh.
Definition at line 269 of file legacy_xdr_io.C.
References libMesh::MeshData::active(), libMesh::Elem::add_child(), libMesh::MeshBase::add_elem(), libMesh::MeshData::add_foreign_elem_id(), libMesh::MeshData::add_foreign_node_id(), libMesh::MeshBase::add_point(), libMesh::BoundaryInfo::add_side(), libMesh::XdrMESH::BC(), binary(), libMesh::Elem::build(), libMesh::MeshBase::clear(), libMesh::MeshData::close_foreign_id_maps(), libMesh::XdrMESH::coord(), DEAL, libMesh::XdrMGF::DECODE, libMesh::Elem::dim(), libMesh::MeshInput< MeshBase >::elems_of_dimension, libMesh::XdrMHEAD::get_block_elt_types(), libMesh::MeshBase::get_boundary_info(), libMesh::XdrMHEAD::get_n_blocks(), libMesh::XdrMHEAD::get_num_elem_each_block(), libMesh::XdrMGF::get_num_levels(), libMesh::XdrMGF::get_orig_flag(), libMesh::XdrHEAD::getNumBCs(), libMesh::XdrMHEAD::getNumEl(), libMesh::XdrHEAD::getNumNodes(), libMesh::XdrMHEAD::getSumWghts(), libMesh::XdrMESH::header(), libMesh::XdrMESH::Icon(), libMesh::MeshTools::Generation::Private::idx(), libMesh::Elem::INACTIVE, libMesh::XdrMESH::init(), libMesh::Elem::JUST_REFINED, LIBM, libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::mesh_dimension(), MGF, libMesh::MeshTools::n_levels(), libMesh::Elem::n_nodes(), libMesh::MeshBase::node_ptr(), libMesh::processor_id(), libMesh::XdrMGF::R_ASCII, libMesh::MeshBase::reserve_elem(), libMesh::MeshBase::reserve_nodes(), libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::XdrMGF::set_orig_flag(), libMesh::Elem::set_refinement_flag(), libMesh::START_LOG(), and libMesh::Elem::type().
Referenced by read_ascii().
{
// This is a serial-only process for now;
// the Mesh should be read on processor 0 and
// broadcast later
libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0);
// get a writeable reference to the mesh
MeshBase& mesh = MeshInput<MeshBase>::mesh();
// clear any data in the mesh
mesh.clear();
// Keep track of what kinds of elements this file contains
elems_of_dimension.clear();
elems_of_dimension.resize(4, false);
// Create an XdrMESH object.
XdrMESH m;
// Create a pointer
// to an XdrMESH file
// header.
XdrMHEAD mh;
// Open the XDR file for reading.
// Note 1: Provide an additional argument
// to specify the dimension.
//
// Note 2: Has to do the right thing for
// both binary and ASCII files.
m.set_orig_flag(originator);
m.init((this->binary() ? XdrMGF::DECODE : XdrMGF::R_ASCII), name.c_str(), 0); // mesh files are always number 0 ...
// From here on, things depend
// on whether we are reading or
// writing! First, we define
// header variables that may
// be read OR written.
unsigned int n_blocks = 0;
unsigned int n_levels = 0;
if (m.get_orig_flag() == LegacyXdrIO::LIBM)
n_levels = m.get_num_levels();
std::vector<ElemType> etypes;
std::vector<unsigned int> neeb;
// Get the information from
// the header, and place it
// in the header pointer.
m.header(&mh);
// Read information from the
// file header. This depends on
// whether its a libMesh or MGF mesh.
const int numElem = mh.getNumEl();
const int numNodes = mh.getNumNodes();
const int totalWeight = mh.getSumWghts();
const int numBCs = mh.getNumBCs();
// If a libMesh-type mesh, read the augmented mesh information
if ((m.get_orig_flag() == LegacyXdrIO::DEAL) || (m.get_orig_flag() == LegacyXdrIO::LIBM))
{
// Read augmented header
n_blocks = mh.get_n_blocks();
etypes.resize(n_blocks);
mh.get_block_elt_types(etypes);
mh.get_num_elem_each_block(neeb);
}
// Read the connectivity
std::vector<int> conn;
// Now that we know the
// number of nodes and elements,
// we can resize the
// appropriate vectors if we are
// reading information in.
mesh.reserve_nodes (numNodes);
mesh.reserve_elem (numElem);
// Each element stores two extra
// locations: one which tells
// what type of element it is,
// and one which tells how many
// nodes it has. Therefore,
// the total number of nodes
// (totalWeight) must be augmented
// by 2 times the number of elements
// in order to read in the entire
// connectivity array.
// Note: This section now depends on
// whether we are reading an old-style libMesh,
// MGF, or a new-style libMesh mesh.
if (m.get_orig_flag() == LegacyXdrIO::DEAL)
{
conn.resize(totalWeight);
m.Icon(&conn[0], 1, totalWeight);
}
else if (m.get_orig_flag() == LegacyXdrIO::MGF)
{
conn.resize(totalWeight+(2*numElem));
m.Icon(&conn[0], 1, totalWeight+(2*numElem));
}
else if (m.get_orig_flag() == LegacyXdrIO::LIBM)
{
conn.resize(totalWeight);
m.Icon(&conn[0], 1, totalWeight);
}
else
{
// I don't know what type of mesh it is.
libmesh_error_msg("Unrecognized flag " << m.get_orig_flag());
}
// read in the nodal coordinates and form points.
{
std::vector<Real> coords(numNodes*3); // Always use three coords per node
m.coord(&coords[0], 3, numNodes);
// Form Nodes out of
// the coordinates. If the
// MeshData object is active,
// add the nodes and ids also
// to its map.
for (int innd=0; innd<numNodes; ++innd)
{
Node* node = mesh.add_point (Point(coords[0+innd*3],
coords[1+innd*3],
coords[2+innd*3]), innd);
if (mesh_data != NULL)
if (mesh_data->active())
{
// add the id to the MeshData, so that
// it knows the foreign id, even when
// the underlying mesh got re-numbered,
// refined, elements/nodes added...
mesh_data->add_foreign_node_id(node, innd);
}
}
}
// Build the elements.
// Note: If the originator was MGF, we don't
// have to do much checking ...
// all the elements are Hex27.
// If the originator was
// this code, we have to loop over
// et and neeb to read in all the
// elements correctly.
//
// (This used to be before the coords block, but it
// had to change now that elements store pointers to
// nodes. The nodes must exist before we assign them to
// the elements. BSK, 1/13/2003)
if ((m.get_orig_flag() == LegacyXdrIO::DEAL) || (m.get_orig_flag() == LegacyXdrIO::LIBM))
{
// This map keeps track of elements we've previously
// constructed, to avoid O(n) lookup times for parent pointers
// and to enable elements to be added in ascending ID order
std::map<unsigned int, Elem*> parents;
{
unsigned int lastConnIndex = 0;
unsigned int lastFaceIndex = 0;
// Keep track of Element ids in MGF-style meshes;
unsigned int next_elem_id = 0;
for (unsigned int level=0; level<=n_levels; level++)
{
for (unsigned int idx=0; idx<n_blocks; idx++)
{
for (unsigned int e=lastFaceIndex; e<lastFaceIndex+neeb[level*n_blocks+idx]; e++)
{
// Build a temporary element of the right type, so we know how
// connectivity entries will be on the line for this element.
UniquePtr<Elem> temp_elem = Elem::build(etypes[idx]);
// A pointer to the element which will eventually be added to the mesh.
Elem* elem;
// New-style libMesh mesh
if (m.get_orig_flag() == LegacyXdrIO::LIBM)
{
unsigned int self_ID = conn[lastConnIndex + temp_elem->n_nodes()];
#ifdef LIBMESH_ENABLE_AMR
unsigned int parent_ID = conn[lastConnIndex + temp_elem->n_nodes()+1];
if (level > 0)
{
// Do a linear search for the parent
Elem* my_parent;
// Search for parent in the parents map (log(n))
START_LOG("log(n) search for parent", "LegacyXdrIO::read_mesh");
std::map<unsigned int, Elem*>::iterator it = parents.find(parent_ID);
STOP_LOG("log(n) search for parent", "LegacyXdrIO::read_mesh");
// If the parent was not previously added, we cannot continue.
if (it == parents.end())
libmesh_error_msg("Parent element with ID " << parent_ID << " not found.");
// Set the my_parent pointer
my_parent = (*it).second;
// my_parent is now INACTIVE, since he has children
my_parent->set_refinement_flag(Elem::INACTIVE);
// Now that we know the parent, build the child
elem = Elem::build(etypes[idx],my_parent).release();
// The new child is marked as JUST_REFINED
elem->set_refinement_flag(Elem::JUST_REFINED);
// Tell the parent about his new child
my_parent->add_child(elem);
// sanity check
libmesh_assert_equal_to (my_parent->type(), elem->type());
}
// Add level-0 elements to the mesh
else
#endif // #ifdef LIBMESH_ENABLE_AMR
{
elem = Elem::build(etypes[idx]).release();
}
// Assign the newly-added element's ID so that future
// children which may be added can find it correctly.
elem->set_id() = self_ID;
// Add this element to the map, it may be a parent for a future element
START_LOG("insert elem into map", "LegacyXdrIO::read_mesh");
parents[self_ID] = elem;
STOP_LOG("insert elem into map", "LegacyXdrIO::read_mesh");
}
// MGF-style meshes
else
{
elem = Elem::build(etypes[idx]).release();
elem->set_id(next_elem_id++);
elems_of_dimension[elem->dim()] = true;
mesh.add_elem(elem);
}
// Add elements with the same id as in libMesh.
// Provided the data files that MeshData reads
// were only written with MeshData, then this
// should work properly. This is an inline
// function, so that for disabled MeshData, this
// should not induce too much cost
if (mesh_data != NULL)
mesh_data->add_foreign_elem_id (elem, e);
// Set the node pointers of the newly-created element
for (unsigned int innd=0; innd < elem->n_nodes(); innd++)
{
elem->set_node(innd) = mesh.node_ptr(conn[innd+lastConnIndex]);
}
lastConnIndex += (m.get_orig_flag() == LegacyXdrIO::LIBM) ? (elem->n_nodes()+2) : elem->n_nodes();
}
lastFaceIndex += neeb[idx];
}
}
}
if (m.get_orig_flag() == LegacyXdrIO::LIBM)
{
{
// Iterate in ascending elem ID order
unsigned int next_elem_id = 0;
for (std::map<unsigned int, Elem *>::iterator i =
parents.begin();
i != parents.end(); ++i)
{
Elem *elem = i->second;
if (elem)
{
elem->set_id(next_elem_id++);
elems_of_dimension[elem->dim()] = true;
mesh.add_elem(elem);
}
else
// We can probably handle this, but we don't expect it
libmesh_error_msg("Unexpected NULL elem encountered while reading libmesh XDR file.");
}
}
}
}
// MGF-style (1) Hex27 mesh
else if (m.get_orig_flag() == LegacyXdrIO::MGF)
{
#ifdef DEBUG
if (mesh_data != NULL)
if (mesh_data->active())
libmesh_error_msg("ERROR: MeshData not implemented for MGF-style mesh.");
#endif
for (int ielm=0; ielm < numElem; ++ielm)
{
Elem* elem = new Hex27;
elem->set_id(ielm);
elems_of_dimension[elem->dim()] = true;
mesh.add_elem(elem);
for (int innd=0; innd < 27; ++innd)
elem->set_node(innd) = mesh.node_ptr(conn[innd+2+(27+2)*ielm]);
}
}
// Set the mesh dimension to the largest encountered for an element
for (unsigned char i=0; i!=4; ++i)
if (elems_of_dimension[i])
mesh.set_mesh_dimension(i);
#if LIBMESH_DIM < 3
if (mesh.mesh_dimension() > LIBMESH_DIM)
libmesh_error_msg("Cannot open dimension " \
<< mesh.mesh_dimension() \
<< " mesh file when configured without " \
<< mesh.mesh_dimension() \
<< "D support." );
#endif
// tell the MeshData object that we are finished
// reading data
if (mesh_data != NULL)
mesh_data->close_foreign_id_maps ();
// Free memory used in
// the connectivity
// vector.
conn.clear();
// If we are reading,
// read in the BCs
// from the mesh file,
// otherwise write the
// boundary conditions
// if the BoundaryInfo
// object exists.
if (numBCs > 0)
{
std::vector<int> bcs(numBCs*3);
// Read the BCs from the XDR file
m.BC(&bcs[0], numBCs);
// Add to the boundary_info
for (int ibc=0; ibc < numBCs; ibc++)
mesh.get_boundary_info().add_side
(cast_int<dof_id_type>(bcs[0+ibc*3]),
cast_int<unsigned short>(bcs[1+ibc*3]),
cast_int<boundary_id_type>(bcs[2+ibc*3]));
}
}
| void libMesh::LegacyXdrIO::read_mgf | ( | const std::string & | name | ) |
This method implements reading a mesh in the MGF format from a specified file.
Definition at line 114 of file legacy_xdr_io.C.
References binary(), MGF, read_ascii(), and read_binary().
Referenced by libMesh::NameBasedIO::read().
{
if (this->binary())
this->read_binary (name, LegacyXdrIO::MGF);
else
this->read_ascii (name, LegacyXdrIO::MGF);
}
| void libMesh::LegacyXdrIO::read_mgf_soln | ( | const std::string & | name, |
| std::vector< Number > & | soln, | ||
| std::vector< std::string > & | var_names | ||
| ) | const |
Read solutions in mgflo's XDR format. Should be compatible with the MGF solution file format. This method expects an ASCII file. What is MGF? It was a microgravity fluid physics code developed under a NASA ESS Grand Challenge Grant. This method exists solely for backwards compatiblity with MGF and could be deprecated at any time.
Definition at line 144 of file legacy_xdr_io.C.
References libMesh::Utility::complex_filename(), libMesh::Utility::prepare_complex_data(), and read_soln().
{
libmesh_deprecated();
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
// buffer for writing separately
std::vector<Real> real_soln;
std::vector<Real> imag_soln;
Utility::prepare_complex_data (soln, real_soln, imag_soln);
this->read_soln (Utility::complex_filename(name, 0),
real_soln,
var_names);
this->read_soln (Utility::complex_filename(name, 1),
imag_soln,
var_names);
#else
this->read_soln (name, soln, var_names);
#endif
}
| void libMesh::LegacyXdrIO::read_soln | ( | const std::string & | name, |
| std::vector< Real > & | soln, | ||
| std::vector< std::string > & | var_names | ||
| ) | const [private] |
Implements reading either a binary or ASCII MGF solution.
Definition at line 962 of file legacy_xdr_io.C.
References binary(), libMesh::XdrMGF::DECODE, libMesh::XdrHEAD::getNumNodes(), libMesh::XdrSHEAD::getVarTitle(), libMesh::XdrSHEAD::getWrtVar(), libMesh::XdrSOLN::header(), libMesh::XdrSOLN::init(), libMesh::XdrMGF::R_ASCII, and libMesh::XdrSOLN::values().
Referenced by read_mgf_soln().
{
// Create an XdrSOLN object.
XdrSOLN s;
// Create an XdrSHEAD object.
XdrSHEAD sh;
// Open the XDR file for
// reading or writing.
// Note 1: Provide an additional argument
// to specify the dimension.
//
// Note 2: Has to do the right thing for
// both binary and ASCII files.
s.init((this->binary() ? XdrMGF::DECODE : XdrMGF::R_ASCII), name.c_str(), 0); // mesh files are always number 0 ...
// From here on, things depend
// on whether we are reading or
// writing! First, we define
// header variables that may
// be read OR written.
int numVar = 0;
int numNodes = 0;
const char* varNames;
// Get the information from
// the header, and place it
// in the header pointer.
s.header(&sh);
// Read information from the
// file header. This depends on
// whether its a libMesh or MGF mesh.
numVar = sh.getWrtVar();
numNodes = sh.getNumNodes();
varNames = sh.getVarTitle();
// Get the variable names
{
var_names.resize(numVar);
const char* p = varNames;
for (int i=0; i<numVar; i++)
{
var_names[i] = p;
p += std::strlen(p) + 1;
}
}
// Read the soln vector
soln.resize(numVar*numNodes);
s.values(&soln[0], numNodes);
}
| void libMesh::MeshInput< MeshBase >::set_n_partitions | ( | unsigned int | n_parts | ) | [inline, protected, inherited] |
Sets the number of partitions in the mesh. Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".
Definition at line 94 of file mesh_input.h.
References libMesh::MeshInput< MT >::mesh().
Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read().
{ this->mesh().set_n_partitions() = n_parts; }
| void libMesh::MeshInput< MeshBase >::skip_comment_lines | ( | std::istream & | in, |
| const char | comment_start | ||
| ) | [protected, inherited] |
Reads input from in, skipping all the lines that start with the character comment_start.
Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().
| void libMesh::LegacyXdrIO::write | ( | const std::string & | name | ) | [virtual] |
This method implements writing a mesh to a specified file.
Implements libMesh::MeshOutput< MeshBase >.
Definition at line 124 of file legacy_xdr_io.C.
References binary(), write_ascii(), and write_binary().
Referenced by libMesh::XdrIO::write().
{
if (this->binary())
this->write_binary (name);
else
this->write_ascii (name);
}
| void libMesh::LegacyXdrIO::write_ascii | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM |
||
| ) | [private] |
Write meshes in libMesh XDR format. Note: MGF won't be able to read these meshes in general since they will be hybrid meshes. The types are: 0: "DEAL" old type libmesh meshes without refinement 1: "MGF " even older style meshes from MGF 2: "LIBM" new type meshes which contain refinement trees.
Definition at line 245 of file legacy_xdr_io.C.
References write_mesh().
Referenced by write(), write_binary(), and write_mgf().
{
this->write_mesh (name, originator);
}
| void libMesh::LegacyXdrIO::write_binary | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM |
||
| ) | [private] |
Write meshes in libMesh XDR format. Note: MGF won't be able to read these meshes in general since they will be hybrid meshes.
Definition at line 253 of file legacy_xdr_io.C.
References libMesh::err, and write_ascii().
Referenced by write(), and write_mgf().
{
libMesh::err << "WARNING: Compiled without XDR binary support.\n"
<< "Will try ASCII instead" << std::endl << std::endl;
this->write_ascii (name);
}
| virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems | ( | const std::string & | , |
| const EquationSystems & | , | ||
| const std::set< std::string > * | system_names = NULL |
||
| ) | [virtual, inherited] |
This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.
Reimplemented in libMesh::NameBasedIO.
Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().
| void libMesh::LegacyXdrIO::write_mesh | ( | const std::string & | name, |
| const LegacyXdrIO::FileFormat | originator = LegacyXdrIO::LIBM |
||
| ) | [private] |
Implements writing either a binary XDR or ASCII XDA mesh.
Definition at line 659 of file legacy_xdr_io.C.
References libMesh::XdrMESH::BC(), binary(), libMesh::BoundaryInfo::build_side_list(), libMesh::ParallelObject::comm(), libMesh::XdrMESH::coord(), DEAL, libMesh::MeshBase::elem(), libMesh::MeshTools::elem_types(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::XdrMGF::ENCODE, end, libMesh::MeshBase::get_boundary_info(), libMesh::XdrMGF::get_orig_flag(), libMesh::XdrMESH::header(), libMesh::XdrMESH::Icon(), libMesh::DofObject::id(), libMesh::MeshTools::Generation::Private::idx(), libMesh::XdrMESH::init(), libMesh::MeshBase::is_serial(), libMesh::Elem::level(), LIBM, libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), MGF, libMesh::BoundaryInfo::n_boundary_conds(), libMesh::MeshBase::n_elem(), libMesh::MeshTools::n_levels(), libMesh::Elem::n_nodes(), libMesh::MeshTools::n_non_subactive_elem_of_type_at_level(), libMesh::Elem::node(), libMesh::MeshBase::node(), libMesh::Elem::parent(), libMesh::XdrMHEAD::set_block_elt_types(), libMesh::XdrMHEAD::set_n_blocks(), libMesh::XdrMHEAD::set_num_elem_each_block(), libMesh::XdrMGF::set_num_levels(), libMesh::XdrMGF::set_orig_flag(), libMesh::XdrHEAD::setId(), libMesh::XdrHEAD::setNumBCs(), libMesh::XdrMHEAD::setNumEl(), libMesh::XdrHEAD::setNumNodes(), libMesh::XdrHEAD::setStrSize(), libMesh::XdrMHEAD::setSumWghts(), libMesh::XdrHEAD::setTitle(), libMesh::START_LOG(), libMesh::Elem::subactive(), libMesh::MeshTools::total_weight(), libMesh::Elem::type(), and libMesh::XdrMGF::W_ASCII.
Referenced by write_ascii().
{
// get a read-only reference to the mesh
const MeshBase& mesh = MeshOutput<MeshBase>::mesh();
// n_levels is a parallel-only method
libmesh_parallel_only(mesh.comm());
const unsigned int n_levels = MeshTools::n_levels(mesh);
// The Legacy Xdr IO code only works if we have a serialized mesh
libmesh_assert (mesh.is_serial());
// In which case only processor 0 needs to do any writing
if (MeshOutput<MeshBase>::mesh().processor_id() != 0)
return;
// Create an XdrMESH object.
XdrMESH m;
// Create a pointer
// to an XdrMESH file
// header.
XdrMHEAD mh;
// Open the XDR file for writing.
// Note 1: Provide an additional argument
// to specify the dimension.
//
// Note 2: Has to do the right thing for
// both binary and ASCII files.
m.set_orig_flag(originator);
// From here on, things depend
// on whether we are reading or
// writing! First, we define
// header variables that may
// be read OR written.
std::vector<unsigned int> neeb;
std::vector<ElemType> etypes;
int n_non_subactive = 0;
int non_subactive_weight = 0;
// This map will associate
// the distance from the beginning of the set
// to each node ID with the node ID itself.
std::map<dof_id_type, dof_id_type> node_map;
{
// For each non-subactive element:
// 1.) Increment the number of non subactive elements
// 2.) Accumulate the total weight
// 3.) Add the node ids to a set of non subactive node ids
std::set<dof_id_type> not_subactive_node_ids;
MeshBase::const_element_iterator el = mesh.elements_begin();
const MeshBase::const_element_iterator end_el = mesh.elements_end();
for( ; el != end_el; ++el)
{
const Elem* elem = (*el);
if(!elem->subactive())
{
n_non_subactive++;
non_subactive_weight += elem->n_nodes();
for (unsigned int n=0; n<elem->n_nodes(); ++n)
not_subactive_node_ids.insert(elem->node(n));
}
}
// Now that the set is built, most of the hard work is done. We build
// the map next and let the set go out of scope.
std::set<dof_id_type>::iterator it = not_subactive_node_ids.begin();
const std::set<dof_id_type>::iterator end = not_subactive_node_ids.end();
dof_id_type cnt=0;
for (; it!=end; ++it)
node_map[*it] = cnt++;
}
const int numElem = n_non_subactive;
const int numBCs =
cast_int<int>(mesh.get_boundary_info().n_boundary_conds());
// Fill the etypes vector with all of the element types found in the mesh
MeshTools::elem_types(mesh, etypes);
// store number of elements in each block at each refinement level
neeb.resize((n_levels+1)*etypes.size());
// Store a variable for the number of element types
const unsigned int n_el_types =
cast_int<unsigned int>(etypes.size());
m.set_num_levels(n_levels);
// The last argument is zero because mesh files are always number 0 ...
m.init((this->binary() ? XdrMGF::ENCODE : XdrMGF::W_ASCII), name.c_str(), 0);
// Loop over all levels and all element types to set the entries of neeb
for(unsigned int level=0; level<=n_levels; level++)
for (unsigned int el_type=0; el_type<n_el_types; el_type++)
neeb[level*n_el_types + el_type] =
MeshTools::n_non_subactive_elem_of_type_at_level(mesh, etypes[el_type], level);
// gotta change this function name!!!
// Now we check to see if we're doing
// MGF-style headers or libMesh-style
// "augmented" headers. An
// augmented header contains
// information about mesh blocks,
// allowing us to optimize storage
// and minimize IO requirements
// for these meshes.
if ((m.get_orig_flag() == LegacyXdrIO::DEAL) || (m.get_orig_flag() == LegacyXdrIO::LIBM))
{
mh.set_n_blocks(cast_int<unsigned int>(etypes.size()));
mh.set_block_elt_types(etypes);
mh.set_num_elem_each_block(neeb);
}
else
libmesh_assert_equal_to (etypes.size(), 1);
mh.setNumEl(numElem);
mh.setNumNodes(cast_int<int>(node_map.size()));
mh.setStrSize(65536);
// set a local variable for the total weight of the mesh
int totalWeight =0;
if (m.get_orig_flag() == LegacyXdrIO::DEAL) // old-style LibMesh
totalWeight=MeshTools::total_weight(mesh);
else if (m.get_orig_flag() == LegacyXdrIO::MGF) // MGF-style
totalWeight = MeshTools::total_weight(mesh)+2*numElem;
else if (m.get_orig_flag() == LegacyXdrIO::LIBM) // new-style LibMesh
totalWeight = non_subactive_weight+2*numElem;
else
libmesh_error_msg("Unrecognized flag " << m.get_orig_flag());
// Set the total weight in the header
mh.setSumWghts(totalWeight);
mh.setNumBCs(numBCs);
mh.setId("Id String"); // You can put whatever you want, it will be ignored
mh.setTitle("Title String"); // You can put whatever you want, it will be ignored
// Put the information
// in the XDR file.
m.header(&mh);
// Write the connectivity
{
std::vector<int> conn;
LegacyXdrIO::FileFormat orig_type = m.get_orig_flag();
// Resize the connectivity vector to hold all the connectivity for the mesh
conn.resize(totalWeight);
unsigned int lastConnIndex = 0;
unsigned int nn = 0;
// Loop over levels and types again, write connectivity information to conn.
for (unsigned int level=0; level<=n_levels; level++)
for (unsigned int idx=0; idx<etypes.size(); idx++)
{
nn = lastConnIndex = 0;
for (unsigned int e=0; e<mesh.n_elem(); e++)
if ((mesh.elem(e)->type() == etypes[idx]) &&
(mesh.elem(e)->level() == level) &&
!mesh.elem(e)->subactive())
{
int nstart=0;
if (orig_type == LegacyXdrIO::DEAL)
nn = mesh.elem(e)->n_nodes();
else if (orig_type == LegacyXdrIO::MGF)
{
nstart=2; // ignore the 27 and 0 entries
nn = mesh.elem(e)->n_nodes()+2;
conn[lastConnIndex + 0] = 27;
conn[lastConnIndex + 1] = 0;
}
else if (orig_type == LegacyXdrIO::LIBM) // LIBMESH format
nn = mesh.elem(e)->n_nodes() + 2;
else
libmesh_error_msg("Unrecognized orig_type = " << orig_type);
// Loop over the connectivity entries for this element and write to conn.
START_LOG("set connectivity", "LegacyXdrIO::write_mesh");
const unsigned int loopmax = (orig_type==LegacyXdrIO::LIBM) ? nn-2 : nn;
for (unsigned int n=nstart; n<loopmax; n++)
{
unsigned int connectivity_value=0;
// old-style Libmesh and MGF meshes
if (orig_type != LegacyXdrIO::LIBM)
connectivity_value = mesh.elem(e)->node(n-nstart);
// new-style libMesh meshes: compress the connectivity entries to account for
// subactive nodes that will not be in the mesh we write out.
else
{
std::map<dof_id_type, dof_id_type>::iterator pos =
node_map.find(mesh.elem(e)->node(n-nstart));
libmesh_assert (pos != node_map.end());
connectivity_value = (*pos).second;
}
conn[lastConnIndex + n] = connectivity_value;
}
STOP_LOG("set connectivity", "LegacyXdrIO::write_mesh");
// In the case of an adaptive mesh, set last 2 entries to this ID and parent ID
if (orig_type == LegacyXdrIO::LIBM)
{
int self_ID = mesh.elem(e)->id();
int parent_ID = -1;
if(level != 0)
parent_ID = mesh.elem(e)->parent()->id();
// Self ID is the second-to-last entry, Parent ID is the last
// entry on each connectivity line
conn[lastConnIndex+nn-2] = self_ID;
conn[lastConnIndex+nn-1] = parent_ID;
}
lastConnIndex += nn;
}
// Send conn to the XDR file. If there are no elements of this level and type,
// then nn will be zero, and we there is no connectivity to write.
if (nn != 0)
m.Icon(&conn[0], nn, lastConnIndex/nn);
}
}
// create the vector of coords and send
// it to the XDR file.
{
std::vector<Real> coords;
coords.resize(3*node_map.size());
int lastIndex=0;
std::map<dof_id_type,dof_id_type>::iterator it = node_map.begin();
const std::map<dof_id_type,dof_id_type>::iterator end = node_map.end();
for (; it != end; ++it)
{
const Point& p = mesh.node((*it).first);
coords[lastIndex+0] = p(0);
coords[lastIndex+1] = p(1);
coords[lastIndex+2] = p(2);
lastIndex += 3;
}
// Put the nodes in the XDR file
m.coord(&coords[0], 3, cast_int<int>(node_map.size()));
}
// write the
// boundary conditions
// if the BoundaryInfo
// object exists.
if (numBCs > 0)
{
std::vector<int> bcs(numBCs*3);
//libMesh::out << "numBCs=" << numBCs << std::endl;
//libMesh::out << "Preparing to write boundary conditions." << std::endl;
std::vector<dof_id_type> elem_list;
std::vector<unsigned short int> side_list;
std::vector<boundary_id_type> elem_id_list;
mesh.get_boundary_info().build_side_list (elem_list, side_list, elem_id_list);
for (int ibc=0; ibc<numBCs; ibc++)
{
bcs[0+ibc*3] = elem_list[ibc];
bcs[1+ibc*3] = side_list[ibc];
bcs[2+ibc*3] = elem_id_list[ibc];
}
// Put the BCs in the XDR file
m.BC(&bcs[0], numBCs);
}
}
| void libMesh::LegacyXdrIO::write_mgf | ( | const std::string & | name | ) |
This method implements writing a mesh in the MGF format from a specified file.
Definition at line 134 of file legacy_xdr_io.C.
References binary(), MGF, write_ascii(), and write_binary().
Referenced by libMesh::NameBasedIO::write().
{
if (this->binary())
this->write_binary (name, LegacyXdrIO::MGF);
else
this->write_ascii (name, LegacyXdrIO::MGF);
}
| void libMesh::LegacyXdrIO::write_mgf_soln | ( | const std::string & | name, |
| std::vector< Number > & | soln, | ||
| std::vector< std::string > & | var_names | ||
| ) | const |
Write solutions in mgflo's XDR format. Should be compatible with the MGF solution file format. What is MGF? It was a microgravity fluid physics code developed under a NASA ESS Grand Challenge Grant. This method exists solely for backwards compatiblity with MGF and could be deprecated at any time.
Definition at line 175 of file legacy_xdr_io.C.
References libMesh::Utility::complex_filename(), libMesh::Utility::prepare_complex_data(), and write_soln().
{
libmesh_deprecated();
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
// buffer for writing separately
std::vector<Real> real_soln;
std::vector<Real> imag_soln;
Utility::prepare_complex_data (soln, real_soln, imag_soln);
this->write_soln (Utility::complex_filename(name, 0),
real_soln,
var_names);
this->write_soln (Utility::complex_filename(name, 1),
imag_soln,
var_names);
#else
this->write_soln (name, soln, var_names);
#endif
}
| virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data | ( | const std::string & | , |
| const std::vector< Number > & | , | ||
| const std::vector< std::string > & | |||
| ) | [inline, virtual, inherited] |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.
Reimplemented in libMesh::ExodusII_IO, libMesh::GMVIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::Nemesis_IO, libMesh::VTKIO, libMesh::UCDIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.
Definition at line 98 of file mesh_output.h.
{ libmesh_not_implemented(); }
| void libMesh::LegacyXdrIO::write_soln | ( | const std::string & | name, |
| std::vector< Real > & | soln, | ||
| std::vector< std::string > & | var_names | ||
| ) | const [private] |
Implements writing either a binary or ASCII MGF solution.
Definition at line 1023 of file legacy_xdr_io.C.
References binary(), libMesh::XdrMGF::ENCODE, libMesh::MeshBase::get_boundary_info(), libMesh::XdrSOLN::header(), libMesh::XdrSOLN::init(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::MeshBase::n_nodes(), libMesh::XdrHEAD::setId(), libMesh::XdrSHEAD::setKstep(), libMesh::XdrSHEAD::setMeshCnt(), libMesh::XdrHEAD::setNumBCs(), libMesh::XdrHEAD::setNumNodes(), libMesh::XdrSHEAD::setNumVar(), libMesh::XdrHEAD::setStrSize(), libMesh::XdrSHEAD::setTime(), libMesh::XdrHEAD::setTitle(), libMesh::XdrSHEAD::setUserTitle(), libMesh::XdrSHEAD::setVarTitle(), libMesh::XdrSHEAD::setWrtVar(), libMesh::XdrSOLN::values(), and libMesh::XdrMGF::W_ASCII.
Referenced by write_mgf_soln().
{
// get a read-only reference to the mesh
const MeshBase& mesh = MeshOutput<MeshBase>::mesh();
// Create an XdrSOLN object.
XdrSOLN s;
// Create an XdrSHEAD object.
XdrSHEAD sh;
// Open the XDR file for
// reading or writing.
// Note 1: Provide an additional argument
// to specify the dimension.
//
// Note 2: Has to do the right thing for
// both binary and ASCII files.
s.init((this->binary() ? XdrMGF::ENCODE : XdrMGF::W_ASCII), name.c_str(), 0); // mesh files are always number 0 ...
// Build the header
sh.setWrtVar(cast_int<int>(var_names.size()));
sh.setNumVar(cast_int<int>(var_names.size()));
sh.setNumNodes(cast_int<int>(mesh.n_nodes()));
sh.setNumBCs(cast_int<int>(mesh.get_boundary_info().n_boundary_conds()));
sh.setMeshCnt(0);
sh.setKstep(0);
sh.setTime(0.);
sh.setStrSize(65536);
sh.setId("Id String"); // Ignored
sh.setTitle("Title String"); // Ignored
sh.setUserTitle("User Title String"); // Ignored
// create the variable array
{
std::string var_title;
for (unsigned int var=0; var<var_names.size(); var++)
{
for (unsigned int c=0; c<var_names[var].size(); c++)
var_title += var_names[var][c];
var_title += '\0';
}
sh.setVarTitle(var_title.c_str(), cast_int<int>(var_title.size()));
}
// Put the informationin the XDR file.
s.header(&sh); // Needs to work for both types of file
// Write the solution vector
libmesh_assert_equal_to (soln.size(), var_names.size()*mesh.n_nodes());
s.values(&soln[0], mesh.n_nodes());
}
bool libMesh::LegacyXdrIO::_binary [private] |
should we read/write binary?
Definition at line 217 of file legacy_xdr_io.h.
Referenced by binary().
const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format [protected, inherited] |
Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.
Definition at line 126 of file mesh_output.h.
Referenced by libMesh::FroIO::write(), libMesh::DivaIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().
std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension [protected, inherited] |
A vector of bools describing what dimension elements have been encountered when reading a mesh.
Definition at line 100 of file mesh_input.h.
Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::max_elem_dimension_seen(), libMesh::AbaqusIO::max_elem_dimension_seen(), libMesh::AbaqusIO::read(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::VTKIO::read(), libMesh::AbaqusIO::read_elements(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), read_mesh(), and libMesh::XdrIO::read_serialized_connectivity().