LCOV - code coverage report
Current view: top level - include/mesh - gmv_io.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 5 5 100.0 %
Date: 2025-08-19 19:27:09 Functions: 5 5 100.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_GMV_IO_H
      21             : #define LIBMESH_GMV_IO_H
      22             : 
      23             : // Local includes
      24             : #include "libmesh/libmesh_common.h"
      25             : #include "libmesh/mesh_output.h"
      26             : #include "libmesh/mesh_input.h"
      27             : 
      28             : // C++ includes
      29             : #include <map>
      30             : 
      31             : namespace libMesh
      32             : {
      33             : 
      34             : // Forward declarations
      35             : class MeshBase;
      36             : enum ElemType : int;
      37             : 
      38             : /**
      39             :  * This class implements writing meshes in the GMV format.
      40             :  * For a full description of the GMV format and to obtain the
      41             :  * GMV software see http://www.generalmeshviewer.com
      42             :  *
      43             :  * \author Benjamin S. Kirk
      44             :  * \date 2004
      45             :  */
      46             : class GMVIO : public MeshInput<MeshBase>,
      47             :               public MeshOutput<MeshBase>
      48             : {
      49             : public:
      50             : 
      51             :   /**
      52             :    * Constructor.  Takes a reference to a constant mesh object.
      53             :    * This constructor will only allow us to write the mesh.
      54             :    */
      55             :   explicit
      56             :   GMVIO (const MeshBase &);
      57             : 
      58             :   /**
      59             :    * Constructor.  Takes a writable reference to a mesh object.
      60             :    * This constructor is required to let us read in a mesh.
      61             :    */
      62             :   explicit
      63             :   GMVIO (MeshBase &);
      64             : 
      65             :   /**
      66             :    * This method implements writing a mesh to a specified file.
      67             :    */
      68             :   virtual void write (const std::string &) override;
      69             : 
      70             :   /**
      71             :    * This method implements reading a mesh from a specified file.
      72             :    */
      73             :   virtual void read (const std::string & mesh_file) override;
      74             : 
      75             :   /**
      76             :    * Bring in base class functionality for name resolution and to
      77             :    * avoid warnings about hidden overloaded virtual functions.
      78             :    */
      79             :   using MeshOutput<MeshBase>::write_nodal_data;
      80             : 
      81             :   /**
      82             :    * This method implements writing a mesh with nodal data to a
      83             :    * specified file where the nodal data and variable names are provided.
      84             :    */
      85             :   virtual void write_nodal_data (const std::string &,
      86             :                                  const std::vector<Number> &,
      87             :                                  const std::vector<std::string> &) override;
      88             : 
      89             :   /**
      90             :    * Flag indicating whether or not to write a binary file.  While
      91             :    * binary files may end up being smaller than equivalent ASCII
      92             :    * files, they are harder to debug if anything goes wrong, since
      93             :    * they are not human-readable.
      94             :    */
      95        1048 :   bool & binary () { return _binary; }
      96             : 
      97             :   /**
      98             :    * Flag indicating whether or not to write the mesh
      99             :    * as discontinuous cell patches
     100             :    */
     101             :   bool & discontinuous() { return _discontinuous; }
     102             : 
     103             :   /**
     104             :    * Flag indicating whether or not to write the partitioning
     105             :    * information for the mesh.
     106             :    */
     107         524 :   bool & partitioning() { return _partitioning; }
     108             : 
     109             :   /**
     110             :    * Flag to write element subdomain_id's as GMV "materials" instead
     111             :    * of element processor_id's.  Allows you to generate exploded views
     112             :    * on user-defined subdomains, potentially creating a pretty picture.
     113             :    */
     114         524 :   bool & write_subdomain_id_as_material() { return _write_subdomain_id_as_material; }
     115             : 
     116             :   /**
     117             :    * Flag indicating whether or not to subdivide second order
     118             :    * elements
     119             :    */
     120      771486 :   bool & subdivide_second_order() { return _subdivide_second_order; }
     121             : 
     122             :   /**
     123             :    * Flag indicating whether or not to write p level
     124             :    * information for p refined meshes
     125             :    */
     126        1048 :   bool & p_levels() { return _p_levels; }
     127             : 
     128             :   /**
     129             :    * Writes a GMV file with discontinuous data
     130             :    */
     131             :   void write_discontinuous_gmv (const std::string & name,
     132             :                                 const EquationSystems & es,
     133             :                                 const bool write_partitioning,
     134             :                                 const std::set<std::string> * system_names=nullptr) const;
     135             : 
     136             : 
     137             :   /**
     138             :    * This method implements writing a mesh with nodal data to a
     139             :    * specified file where the nodal data and variable names are optionally
     140             :    * provided.  This will write an ASCII file.   This is the new implementation
     141             :    * (without subcells).
     142             :    */
     143             :   void write_ascii_new_impl (const std::string &,
     144             :                              const std::vector<Number> * = nullptr,
     145             :                              const std::vector<std::string> * = nullptr);
     146             : 
     147             :   /**
     148             :    * Takes a vector of cell-centered data to be plotted.
     149             :    * You must ensure that for every active element e,
     150             :    * v[e->id()] is a valid number.  You can add an arbitrary
     151             :    * number of different cell-centered data sets by calling
     152             :    * this function multiple times.
     153             :    *
     154             :    * .) GMV does not like spaces in the cell_centered_data_name
     155             :    * .) No matter what order you add cell-centered data, it will be
     156             :    *    output alphabetically.
     157             :    */
     158             :   void add_cell_centered_data (const std::string &       cell_centered_data_name,
     159             :                                const std::vector<Real> * cell_centered_data_vals);
     160             : 
     161             :   /**
     162             :    * If we read in a nodal solution while reading in a mesh, we can attempt
     163             :    * to copy that nodal solution into an EquationSystems object.
     164             :    */
     165             :   void copy_nodal_solution(EquationSystems & es);
     166             : 
     167             : private:
     168             : 
     169             :   /**
     170             :    * This method implements writing a mesh with nodal data to a
     171             :    * specified file where the nodal data and variable names are optionally
     172             :    * provided.  This will write an ASCII file.  This is the old implementation
     173             :    * (using subcells) which was the default in libMesh-0.4.3-rc2.
     174             :    */
     175             :   void write_ascii_old_impl (const std::string &,
     176             :                              const std::vector<Number> * = nullptr,
     177             :                              const std::vector<std::string> * = nullptr);
     178             : 
     179             :   /**
     180             :    * This method implements writing a mesh with nodal data to a
     181             :    * specified file where the nodal data and variable names are optionally
     182             :    * provided.
     183             :    */
     184             :   void write_binary (const std::string &,
     185             :                      const std::vector<Number> * = nullptr,
     186             :                      const std::vector<std::string> * = nullptr);
     187             : 
     188             :   /**
     189             :    * Flag to write binary data.
     190             :    */
     191             :   bool _binary;
     192             : 
     193             :   /**
     194             :    * Flag to write the mesh as discontinuous patches.
     195             :    */
     196             :   bool _discontinuous;
     197             : 
     198             :   /**
     199             :    * Flag to write the mesh partitioning.
     200             :    */
     201             :   bool _partitioning;
     202             : 
     203             :   /**
     204             :    * Flag to write element subdomain_id's as GMV "materials" instead
     205             :    * of element processor_id's.
     206             :    */
     207             :   bool _write_subdomain_id_as_material;
     208             : 
     209             :   /**
     210             :    * Flag to subdivide second order elements
     211             :    */
     212             :   bool _subdivide_second_order;
     213             : 
     214             :   /**
     215             :    * Flag to write the mesh p refinement levels.
     216             :    */
     217             :   bool _p_levels;
     218             : 
     219             :   /**
     220             :    * Storage for arbitrary cell-centered data.  Ex: You can use this
     221             :    * to plot the effectivity index for a given cell.  The map is
     222             :    * between the string representing the variable name and a pointer
     223             :    * to a vector containing the data.
     224             :    */
     225             :   std::map<std::string, const std::vector<Real> * > _cell_centered_data;
     226             : 
     227             :   /**
     228             :    * Helper functions for reading nodes/cells from a GMV file
     229             :    */
     230             :   void _read_nodes();
     231             :   unsigned int _next_elem_id;
     232             :   void _read_one_cell();
     233             :   ElemType gmv_elem_to_libmesh_elem(std::string elemname);
     234             :   void _read_materials();
     235             :   void _read_var();
     236             :   std::map<std::string, std::vector<Number>> _nodal_data;
     237             : 
     238             :   /**
     239             :    * Static map from string -> ElementType for
     240             :    * use during reading.
     241             :    */
     242             :   static std::map<std::string, ElemType> _reading_element_map;
     243             : 
     244             :   /**
     245             :    * Static function used to build the _reading_element_map.
     246             :    */
     247             :   static std::map<std::string, ElemType> build_reading_element_map();
     248             : };
     249             : 
     250             : } // namespace libMesh
     251             : 
     252             : 
     253             : #endif // LIBMESH_GMV_IO_H

Generated by: LCOV version 1.14