/usr/include/libmesh/gmv_io.h is in libmesh-dev 0.7.1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | // $Id: gmv_io.h 3924 2010-08-24 22:10:57Z roystgnr $
// The libMesh Finite Element Library.
// Copyright (C) 2002-2008 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef __gmv_io_h__
#define __gmv_io_h__
// C++ includes
#include <cstring> // for memcpy
#include <map>
// Local includes
#include "libmesh_common.h"
#include "mesh_output.h"
#include "mesh_input.h"
#include "enum_elem_type.h"
namespace libMesh
{
// Forward declarations
class MeshBase;
/**
* This class implements writing meshes in the GMV format.
* For a full description of the GMV format and to obtain the
* GMV software see
* <a href="http://laws.lanl.gov/XCM/gmv/GMVHome.html">the GMV home page</a>
*
* @author Benjamin S. Kirk, 2004
*/
// ------------------------------------------------------------
// GMVIO class definition
class GMVIO : public MeshInput<MeshBase>,
public MeshOutput<MeshBase>
{
public:
/**
* Constructor. Takes a reference to a constant mesh object.
* This constructor will only allow us to write the mesh.
*/
GMVIO (const MeshBase&);
/**
* Constructor. Takes a writeable reference to a mesh object.
* This constructor is required to let us read in a mesh.
*/
GMVIO (MeshBase&);
/**
* This method implements writing a mesh to a specified file.
*/
virtual void write (const std::string& );
/**
* This method implements reading a mesh from a specified file.
*/
virtual void read (const std::string& mesh_file);
// /**
// * This method implements reading a mesh from a specified file.
// */
// virtual void read (const std::string& mesh_file)
// { this->read_mesh_and_nodal_data(mesh_file, NULL); }
// /**
// * Extension of the MeshInput::read() routine which
// * also takes an optional EquationSystems pointer and
// * tries to read field variables from the GMV file
// * into the EquationSystems object.
// */
// virtual void read_mesh_and_nodal_data (const std::string& ,
// EquationSystems* es=NULL);
/**
* This method implements writing a mesh with nodal data to a
* specified file where the nodal data and variable names are provided.
*/
virtual void write_nodal_data (const std::string&,
const std::vector<Number>&,
const std::vector<std::string>&);
/**
* Flag indicating whether or not to write a binary file. While binary
* files may end up being smaller than equivalent ASCII files, they will
* almost certainly take longer to write. The reason for this is that
* the ostream::write() function which is used to write "binary" data to
* streams, only takes a pointer to char as its first argument. This means
* if you want to write anything other than a buffer of chars, you first
* have to use a strange memcpy hack to get the data into the desired format.
* See the templated to_binary_stream() function below.
*/
bool & binary ();
/**
* Flag indicating whether or not to write the mesh
* as discontinuous cell patches
*/
bool & discontinuous();
/**
* Flag indicating whether or not to write the partitioning
* information for the mesh.
*/
bool & partitioning();
/**
* Flag to write element subdomain_id's as GMV "materials" instead
* of element processor_id's. Allows you to generate exploded views
* on user-defined subdomains, potentially creating a pretty picture.
*/
bool & write_subdomain_id_as_material();
/**
* Flag indicating whether or not to subdivide second order
* elements
*/
bool & subdivide_second_order();
/**
* Flag indicating whether or not to write p level
* information for p refined meshes
*/
bool & p_levels();
/**
* Writes a GMV file with discontinuous data
*/
void write_discontinuous_gmv (const std::string& name,
const EquationSystems& es,
const bool write_partitioning) const;
/**
* This method implements writing a mesh with nodal data to a
* specified file where the nodal data and variable names are optionally
* provided. This will write an ASCII file. This is the new implementation
* (without subcells).
*/
void write_ascii_new_impl (const std::string&,
const std::vector<Number>* = NULL,
const std::vector<std::string>* = NULL);
/**
* Takes a vector of cell-centered data to be plotted.
* You must ensure that for every active element e,
* v[e->id()] is a valid number. You can add an arbitrary
* number of different cell-centered data sets by calling
* this function multiple times.
*
* .) GMV does not like spaces in the cell_centered_data_name
* .) No matter what order you add cell-centered data, it will be
* output alphabetically.
*/
void add_cell_centered_data (const std::string& cell_centered_data_name,
const std::vector<Real>* cell_centered_data_vals);
/**
* If we read in a nodal solution while reading in a mesh, we can attempt
* to copy that nodal solution into an EquationSystems object.
*/
void copy_nodal_solution(EquationSystems& es);
private:
/**
* This method implements writing a mesh with nodal data to a
* specified file where the nodal data and variable names are optionally
* provided. This will write an ASCII file. This is the old implementation
* (using subcells) which was the default in libMesh-0.4.3-rc2.
*/
void write_ascii_old_impl (const std::string&,
const std::vector<Number>* = NULL,
const std::vector<std::string>* = NULL);
/**
* This method implements writing a mesh with nodal data to a
* specified file where the nodal data and variable names are optionally
* provided.
*/
void write_binary (const std::string&,
const std::vector<Number>* = NULL,
const std::vector<std::string>* = NULL);
/**
* Helper function for writing unsigned ints to an ostream in binary format.
* Implemented via memcpy as suggested in the standard.
*/
template <typename T>
void to_binary_stream(std::ostream& out,
const T i);
/**
* Flag to write binary data.
*/
bool _binary;
/**
* Flag to write the mesh as discontinuous patches.
*/
bool _discontinuous;
/**
* Flag to write the mesh partitioning.
*/
bool _partitioning;
/**
* Flag to write element subdomain_id's as GMV "materials" instead
* of element processor_id's.
*/
bool _write_subdomain_id_as_material;
/**
* Flag to subdivide second order elements
*/
bool _subdivide_second_order;
/**
* Flag to write the mesh p refinement levels.
*/
bool _p_levels;
/**
* Storage for arbitrary cell-centered data. Ex: You can use this
* to plot the effectivity index for a given cell. The map is
* between the string representing the variable name and a pointer
* to a vector containing the data.
*/
std::map<std::string, const std::vector<Real>* > _cell_centered_data;
/**
* Helper functions for reading nodes/cells from a GMV file
*/
void _read_nodes();
unsigned int _next_elem_id;
void _read_one_cell();
ElemType _gmv_elem_to_libmesh_elem(const char* elemname);
void _read_materials();
void _read_var();
std::map<std::string, std::vector<Number> > _nodal_data;
};
// ------------------------------------------------------------
// GMVIO inline members
inline
GMVIO::GMVIO (const MeshBase& mesh) :
MeshOutput<MeshBase> (mesh),
_binary (false),
_discontinuous (false),
_partitioning (true),
_write_subdomain_id_as_material (false),
_subdivide_second_order (true),
_p_levels (true),
_next_elem_id (0)
{
}
inline
GMVIO::GMVIO (MeshBase& mesh) :
MeshInput<MeshBase> (mesh),
MeshOutput<MeshBase>(mesh),
_binary (false),
_discontinuous (false),
_partitioning (true),
_write_subdomain_id_as_material (false),
_subdivide_second_order (true),
_p_levels (true),
_next_elem_id (0)
{
}
inline
bool & GMVIO::binary ()
{
return _binary;
}
inline
bool & GMVIO::discontinuous ()
{
return _discontinuous;
}
inline
bool & GMVIO::partitioning ()
{
return _partitioning;
}
inline
bool & GMVIO::write_subdomain_id_as_material ()
{
return _write_subdomain_id_as_material;
}
inline
bool & GMVIO::subdivide_second_order ()
{
return _subdivide_second_order;
}
inline
bool & GMVIO::p_levels()
{
return _p_levels;
}
template <typename T>
void GMVIO::to_binary_stream(std::ostream& out,
const T i)
{
static char buf[sizeof(T)];
memcpy(buf, &i, sizeof(T));
out.write(buf, sizeof(T));
}
} // namespace libMesh
#endif // #define __gmv_io_h__
|