Poster of Linux kernelThe best gift for a Linux geek
FroIO

FroIO

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

FroIO -  

SYNOPSIS


#include <fro_io.h>

Inherits MeshOutput< MeshBase >.  

Public Member Functions


FroIO (const MeshBase &)

virtual void write (const std::string &)

virtual void write_equation_systems (const std::string &, const EquationSystems &)

virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 

Protected Member Functions


const MeshBase & mesh () const
 

Detailed Description

This class implements writing meshes in the .fro format used by the MIT ACDL. Valid only for triangular meshes.

Author:

Benjamin S. Kirk, 2007

Definition at line 43 of file fro_io.h.  

Constructor & Destructor Documentation

 

FroIO::FroIO (const MeshBase &mesh) [inline]Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.

Definition at line 68 of file fro_io.h.

                                  :
  MeshOutput<MeshBase> (mesh)
{
}
 

Member Function Documentation

 

const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.

Referenced by PostscriptIO::write(), write(), MEDITIO::write_ascii(), EnsightIO::write_geometry_ascii(), EnsightIO::write_scalar_ascii(), GnuPlotIO::write_solution(), DivaIO::write_stream(), and EnsightIO::write_vector_ascii().  

void FroIO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified file.

Implements MeshOutput< MeshBase >.

Definition at line 38 of file fro_io.C.

References MeshBase::active_elements_begin(), MeshBase::active_elements_end(), MeshBase::boundary_info, Elem::build_side(), MeshBase::elem(), MeshOutput< MeshBase >::mesh(), MeshBase::n_elem(), MeshBase::n_nodes(), MeshBase::point(), libMesh::processor_id(), and libMeshEnums::TRI3.

Referenced by UnstructuredMesh::write().

{
  if (libMesh::processor_id() == 0)
    {
      // Open the output file stream
      std::ofstream out (fname.c_str());
      libmesh_assert (out.good());

      // Make sure it opened correctly
      if (!out.good())
        libmesh_file_error(fname.c_str());

      // Get a reference to the mesh
      const MeshBase& mesh = MeshOutput<MeshBase>::mesh();

      // Write the header
      out << mesh.n_elem()  << ' '
          << mesh.n_nodes() << ' '
          << '0 0 '
          << mesh.boundary_info->n_boundary_ids()  << ' 1;

      // Write the nodes -- 1-based!
      for (unsigned int n=0; n<mesh.n_nodes(); n++)
        out << n+1 << ' 	'
            << std::scientific
            << std::setprecision(12)
            << mesh.point(n)(0) << ' 	'
            << mesh.point(n)(1) << ' 	'
            << 0. << ';

      // Write the elements -- 1-based!
      MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = mesh.active_elements_end();
      unsigned int e=0;
      
      for ( ; it != end; ++it)
        {
          // .fro likes TRI3's
          if ((*it)->type() != TRI3)
            {
              std::cerr << 'ERROR:  .fro format only valid for triangles!
                        << '  writing of ' << fname << ' aborted.
                        << std::endl;
              libmesh_error();
            }
          
          out << ++e << ' 	';

          for (unsigned int n=0; n<(*it)->n_nodes(); n++)
            out << (*it)->node(n)+1 << ' 	';

//        // LHS -> RHS Mapping, for inverted triangles
//        out << (*it)->node(0)+1 << ' 	';
//        out << (*it)->node(2)+1 << ' 	';
//        out << (*it)->node(1)+1 << ' 	';

          out << '1;
        }

      // Write BCs.
      {
        const std::set<short int>& bc_ids =
          mesh.boundary_info->get_boundary_ids();

        std::vector<unsigned int>       el;
        std::vector<unsigned short int> sl;
        std::vector<short int>          il;
        
        mesh.boundary_info->build_side_list (el, sl, il);


        // Map the boundary ids into [1,n_bc_ids],
        // treat them one at a time.
        short int bc_id=0;
        for (std::set<short int>::const_iterator id = bc_ids.begin();
             id != bc_ids.end(); ++id)
          {
            std::deque<unsigned int> node_list;
            
            std::map<unsigned int, unsigned int>
              forward_edges, backward_edges;
            
            // Get all sides on this element with the relevant BC id.
            for (unsigned int e=0; e<el.size(); e++)
              if (il[e] == *id)
                {
                  // need to build up node_list as a sorted array of edge nodes...
                  // for the following:
                  // a---b---c---d---e
                  // node_list [ a b c d e];
                  //
                  // the issue is just how to get this out of the elem/side based data structure.
                  // the approach is to build up 'chain links' like this:
                  // a---b b---c c---d d---e
                  // and piece them together.
                  //
                  // so, for an arbitray edge n0---n1, we build the
                  // 'forward_edges'  map n0-->n1
                  // 'backward_edges' map n1-->n0
                  // and then start with one chain link, and add on...
                  //
                  AutoPtr<Elem> side = mesh.elem(el[e])->build_side(sl[e]);

                  const unsigned int
                    n0 = side->node(0),
                    n1 = side->node(1);

                  // insert into forward-edge set
                  forward_edges.insert (std::make_pair(n0, n1));

                  // insert into backward-edge set
                  backward_edges.insert (std::make_pair(n1, n0));

                  // go ahead and add one edge to the list -- this will give us the beginning of a
                  // chain to work from!
                  if (node_list.empty())
                    {
                      node_list.push_front(n0);
                      node_list.push_back (n1);
                    }
                }

            // we now have the node_list with one edge, the forward_edges, and the backward_edges
            // the node_list will be filled when (node_list.size() == (n_edges+1))
            // until that is the case simply add on to the beginning and end of the node_list,
            // building up a chain of ordered nodes...
            const unsigned int n_edges = forward_edges.size();
            
            while (node_list.size() != (n_edges+1))
              {
                const unsigned int
                  front_node = node_list.front(),
                  back_node  = node_list.back();

                // look for front_pair in the backward_edges list
                {
                  std::map<unsigned int, unsigned int>::iterator
                    pos = backward_edges.find(front_node);

                  if (pos != backward_edges.end())
                    {
                      node_list.push_front(pos->second);
                       
                      backward_edges.erase(pos);
                    }
                }

                // look for back_pair in the forward_edges list
                {
                  std::map<unsigned int, unsigned int>::iterator
                    pos = forward_edges.find(back_node);

                  if (pos != forward_edges.end())
                    {
                      node_list.push_back(pos->second);
                       
                      forward_edges.erase(pos);
                    }
                }

//              std::cout << 'node_list.size()=' << node_list.size()
//                        << ', n_edges+1=' << n_edges+1 << std::endl;            
              }
                    

            out << ++bc_id << ' ' << node_list.size() << ';

            std::deque<unsigned int>::iterator pos = node_list.begin();
            for ( ; pos != node_list.end(); ++pos)
                out << *pos+1 << ' 	0;
          }     
      }      
    }
}
 

virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [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 VTKIO.  

virtual void 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 ExodusII_IO, GmshIO, GMVIO, GnuPlotIO, MEDITIO, and TecplotIO.

Definition at line 91 of file mesh_output.h.

  { libmesh_error(); }

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Protected Member Functions
Detailed Description
Constructor & Destructor Documentation
FroIO::FroIO (const MeshBase &mesh) [inline]Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.
Member Function Documentation
const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.
void FroIO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified file.
virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [virtual, inherited]This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.
virtual void 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.
Author

This document was created by man2html, using the manual pages.
Time: 21:46:22 GMT, April 16, 2011