LCOV - code coverage report
Current view: top level - include/mesh - unv_io.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 1 1 100.0 %
Date: 2025-08-19 19:27:09 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_UNV_IO_H
      21             : #define LIBMESH_UNV_IO_H
      22             : 
      23             : 
      24             : // Local includes
      25             : #include "libmesh/mesh_input.h"
      26             : #include "libmesh/mesh_output.h"
      27             : 
      28             : // C++ includes
      29             : #include <cstddef>
      30             : #include <map>
      31             : #include <string>
      32             : #include <vector>
      33             : 
      34             : namespace libMesh
      35             : {
      36             : 
      37             : // Forward declarations
      38             : class MeshBase;
      39             : 
      40             : /**
      41             :  * The \p UNVIO class implements the Ideas \p UNV universal
      42             :  * file format.  This class enables both reading and writing
      43             :  * \p UNV files.
      44             :  *
      45             :  * Author history
      46             :  * \author Tammo Kaschner
      47             :  * \author Daniel Dreyer
      48             :  * \author Benjamin S. Kirk
      49             :  * \author John W. Peterson
      50             :  * \date 2003, 2004, 2014
      51             :  */
      52           2 : class UNVIO : public MeshInput<MeshBase>,
      53             :               public MeshOutput<MeshBase>
      54             : {
      55             : 
      56             : public:
      57             : 
      58             :   /**
      59             :    * Constructor.  Takes a writable reference to a mesh object.
      60             :    * This is the constructor required to read a mesh.
      61             :    */
      62             :   UNVIO (MeshBase & mesh);
      63             : 
      64             :   /**
      65             :    * Constructor.  Takes a reference to a constant mesh object.
      66             :    * This constructor will only allow us to write the mesh.
      67             :    */
      68             :   UNVIO (const MeshBase & mesh);
      69             : 
      70             :   /**
      71             :    * Destructor.
      72             :    */
      73             :   virtual ~UNVIO ();
      74             : 
      75             :   /**
      76             :    * This method implements reading a mesh from a specified file.
      77             :    */
      78             :   virtual void read (const std::string &) override;
      79             : 
      80             :   /**
      81             :    * This method implements writing a mesh to a specified file.
      82             :    */
      83             :   virtual void write (const std::string &) override;
      84             : 
      85             :   /**
      86             :    * Set the flag indicating if we should be verbose.
      87             :    */
      88             :   bool & verbose ();
      89             : 
      90             :   /**
      91             :    * Read a UNV data file containing a dataset of type "2414".
      92             :    * For more info, see http://tinyurl.com/htcf6zm
      93             :    */
      94             :   void read_dataset(std::string file_name);
      95             : 
      96             :   /**
      97             :    * \returns A pointer the values associated with the node \p node,
      98             :    * as read in by the read_dataset() method.
      99             :    *
     100             :    * If no values exist for the node in question, a nullptr is
     101             :    * returned instead.  It is up to the user to check the return value
     102             :    * before using it.
     103             :    */
     104             :   const std::vector<Number> * get_data (Node * node) const;
     105             : 
     106             : private:
     107             : 
     108             : 
     109             :   /**
     110             :    * The actual implementation of the read function.
     111             :    * The public read interface simply decides which
     112             :    * type of stream to pass the implementation.
     113             :    */
     114             :   void read_implementation (std::istream & in_stream);
     115             : 
     116             :   /**
     117             :    * The actual implementation of the write function.
     118             :    * The public write interface simply decides which
     119             :    * type of stream to pass the implementation.
     120             :    */
     121             :   void write_implementation (std::ostream & out_stream);
     122             : 
     123             :   //-------------------------------------------------------------
     124             :   // read support methods
     125             : 
     126             :   /**
     127             :    * Read nodes from file.
     128             :    */
     129             :   void nodes_in (std::istream & in_file);
     130             : 
     131             :   /**
     132             :    * Method reads elements and stores them in
     133             :    * \p std::vector<Elem *> \p _elements in the same order as they
     134             :    * come in. Within \p UNVIO, element labels are
     135             :    * ignored.
     136             :    */
     137             :   void elements_in (std::istream & in_file);
     138             : 
     139             :   /**
     140             :    * Reads the "groups" section of the file. The format of the groups section is described here:
     141             :    * http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2467.htm
     142             :    */
     143             :   void groups_in(std::istream & in_file);
     144             : 
     145             :   //-------------------------------------------------------------
     146             :   // write support methods
     147             : 
     148             :   /**
     149             :    * Outputs nodes to the file \p out_file.  Do not use this directly,
     150             :    * but through the proper write method.
     151             :    */
     152             :   void nodes_out (std::ostream & out_file);
     153             : 
     154             :   /**
     155             :    * Outputs the element data to the file \p out_file. Do not use this
     156             :    * directly, but through the proper write method.
     157             :    */
     158             :   void elements_out (std::ostream & out_file);
     159             : 
     160             :   /**
     161             :    * \returns The maximum geometric element dimension encountered while
     162             :    * reading the Mesh.  Only valid after the elements have been read
     163             :    * in and the elems_of_dimension array has been populated.
     164             :    */
     165             :   unsigned char max_elem_dimension_seen ();
     166             : 
     167             :   /**
     168             :    * Replaces "1.1111D+00" with "1.1111e+00" if necessary. This
     169             :    * function only needs to be called once per stream, one can assume
     170             :    * that if one number needs rewriting, they all do.
     171             :    *
     172             :    * \returns \p true if the replacement occurs, false otherwise.
     173             :    */
     174             :   bool need_D_to_e (std::string & number);
     175             : 
     176             :   //-------------------------------------------------------------
     177             :   // local data
     178             : 
     179             :   /**
     180             :    * should be be verbose?
     181             :    */
     182             :   bool _verbose;
     183             : 
     184             :   /**
     185             :    * Maps UNV node IDs to libMesh Node*s. Used when reading. Even if the
     186             :    * libMesh Mesh is renumbered, this map should continue to be valid.
     187             :    */
     188             :   std::map<dof_id_type, Node *> _unv_node_id_to_libmesh_node_ptr;
     189             : 
     190             :   /**
     191             :    * label for the node dataset
     192             :    */
     193             :   static const std::string _nodes_dataset_label;
     194             : 
     195             :   /**
     196             :    * label for the element dataset
     197             :    */
     198             :   static const std::string _elements_dataset_label;
     199             : 
     200             :   /**
     201             :    * label for the groups dataset
     202             :    */
     203             :   static const std::string _groups_dataset_label;
     204             : 
     205             :   /**
     206             :    * Map UNV element IDs to libmesh element IDs.
     207             :    */
     208             :   std::map<unsigned, unsigned> _unv_elem_id_to_libmesh_elem_id;
     209             : 
     210             :   /**
     211             :    * Map from libMesh Node* to data at that node, as read in by the
     212             :    * read_dataset() function.
     213             :    */
     214             :   std::map<Node *, std::vector<Number>> _node_data;
     215             : };
     216             : 
     217             : 
     218             : 
     219             : } // namespace libMesh
     220             : 
     221             : 
     222             : #endif // LIBMESH_UNV_IO_H

Generated by: LCOV version 1.14