/usr/include/libmesh/unv_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 | // $Id: unv_io.h 3874 2010-07-02 21:57:26Z 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 __unv_io_h__
#define __unv_io_h__
// C++ inludes
#include <vector>
#include <map>
#include <string>
// Local includes
#include "mesh_input.h"
#include "mesh_output.h"
namespace libMesh
{
// Forward declarations
class MeshBase;
class MeshData;
/**
* The \p UNVIO class implements the Ideas \p UNV universal
* file format. This class enables both reading and writing
* \p UNV files.
*/
// ------------------------------------------------------------
// UNVIO class definition
class UNVIO : public MeshInput<MeshBase>,
public MeshOutput<MeshBase>
{
public:
/**
* Constructor. Takes a writeable reference to a mesh object.
* This is the constructor required to read a mesh.
*/
UNVIO (MeshBase& mesh, MeshData& mesh_data);
/**
* Constructor. Takes a reference to a constant mesh object.
* This constructor will only allow us to write the mesh.
*/
UNVIO (const MeshBase& mesh, MeshData& mesh_data);
/**
* Destructor.
*/
virtual ~UNVIO ();
/**
* This method implements reading a mesh from a specified file.
*/
virtual void read (const std::string& );
/**
* This method implements writing a mesh to a specified file.
*/
virtual void write (const std::string& );
/**
* Set the flag indicationg if we should be verbose.
*/
bool & verbose ();
private:
/**
* The actual implementation of the read function.
* The public read interface simply decides which
* type of stream to pass the implementation.
*/
void read_implementation (std::istream& in_stream);
/**
* The actual implementation of the write function.
* The public write interface simply decides which
* type of stream to pass the implementation.
*/
void write_implementation (std::ostream& out_stream);
/**
* Clears the data structures to a pristine
* state.
*/
void clear();
//-------------------------------------------------------------
// read support methods
/**
* When reading, counting the nodes first
* helps pre-allocation. Also determine
* whether we need to convert from "D" to "e".
*/
void count_nodes (std::istream& in_file);
/**
* Method reads nodes from \p in_file and stores them in
* vector<Node*> \p nodes in the order they come in.
* The original node labels are being stored in
* \p _assign_nodes in order to assign the elements to
* the correct nodes later. In addition, provided it is
* active, the \p MeshData gets to know the node id from
* the Universal file, too.
*/
void node_in (std::istream& in_file);
/**
* When reading, counting the elements first
* helps pre-allocation.
*/
void count_elements (std::istream& in_file);
/**
* Method reads elements and stores them in
* \p std::vector<Elem*> \p _elements in the same order as they
* come in. Within \p UNVIO, element labels are
* ignored, but \p MeshData takes care of such things
* (if active).
*/
void element_in (std::istream& in_file);
/**
* @returns \p false when error occured, \p true otherwise.
* Adjusts the \p in_stream to the beginning of the
* dataset \p ds_name.
*/
bool beginning_of_dataset (std::istream& in_file,
const std::string& ds_name) const;
/**
* Method for converting exponential notation
* from "D" to "e", for example
* \p 3.141592654D+00 \p --> \p 3.141592654e+00
* in order to make it readable for C++.
*/
Real D_to_e (std::string& number) const;
//-------------------------------------------------------------
// write support methods
/**
* Outputs nodes to the file \p out_file.
* For this to work, the \p MeshData of the current
* \p MeshBase has to be active. Do not use this directly,
* but through the proper write method.
*/
void node_out (std::ostream& out_file);
/**
* Outputs the element data to the file \p out_file.
* For this to work, the \p MeshData of the current
* \p Mesh has to be active. Do not use this directly,
* but through the proper write method.
*/
void element_out (std::ostream& out_file);
//-------------------------------------------------------------
// local data
/**
* should be be verbose?
*/
bool _verbose;
/**
* maps node id's from UNV to internal. Used when reading.
*/
std::vector<unsigned int> _assign_nodes;
/**
* stores positions of relevant datasets in the file, should
* help to re-read the data faster. Used when reading.
*/
std::map<std::string,std::streampos> _ds_position;
/**
* total number of nodes, determined through \p count_nodes().
* Primarily used when reading.
*/
unsigned int _n_nodes;
/**
* total number of elements, determined through
* \p count_elements(). Primarily used when reading.
*/
unsigned int _n_elements;
/**
* label for the node dataset
*/
static const std::string _label_dataset_nodes;
/**
* label for the element dataset
*/
static const std::string _label_dataset_elements;
/**
* whether we need to convert notation of exponentials.
* Used when reading.
*/
bool _need_D_to_e;
/**
* A pointer to the MeshData object you would like to use.
* with this UNVIO object. Can be NULL.
*/
MeshData& _mesh_data;
};
// ------------------------------------------------------------
// MeshIO inline members
inline
UNVIO::UNVIO (MeshBase& mesh, MeshData& mesh_data) :
MeshInput<MeshBase> (mesh),
MeshOutput<MeshBase>(mesh),
_verbose (false),
_mesh_data (mesh_data)
{
}
inline
UNVIO::UNVIO (const MeshBase& mesh, MeshData& mesh_data) :
MeshOutput<MeshBase> (mesh),
_verbose (false),
_mesh_data (mesh_data)
{
}
inline
UNVIO::~UNVIO ()
{
this->clear ();
}
inline
bool & UNVIO::verbose ()
{
return _verbose;
}
inline
bool UNVIO::beginning_of_dataset (std::istream& in_file,
const std::string& ds_name) const
{
libmesh_assert (in_file.good());
libmesh_assert (!ds_name.empty());
std::string olds, news;
while (true)
{
in_file >> olds >> news;
/*
* a "-1" followed by a number means the beginning of a dataset
* stop combing at the end of the file
*/
while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() )
{
olds = news;
in_file >> news;
}
if (in_file.eof())
return false;
if (news == ds_name)
return true;
}
// should never end up here
libmesh_error();
return false;
}
inline
Real UNVIO::D_to_e (std::string& number) const
{
/* find "D" in string, start looking at
* 6th element, to improve speed.
* We dont expect a "D" earlier
*/
#ifdef __HP_aCC
// Use an int instead of an unsigned int,
// otherwise HP aCC may crash!
const int position = number.find("D",6);
#else
const std::string::size_type position = number.find("D",6);
#endif
libmesh_assert (position != std::string::npos);
number.replace(position, 1, "e");
return std::atof (number.c_str());
}
} // namespace libMesh
#endif // #define __unv_io_h__
|