/usr/include/libmesh/mesh_output.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 | // $Id: mesh_output.h 4317 2011-04-01 11:51:41Z 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 __mesh_output_h__
#define __mesh_output_h__
// C++ includes
#include <limits>
#include <string>
#include <vector>
// Local includes
#include "libmesh_common.h"
#include "mesh_base.h"
namespace libMesh
{
// Forward declares
class EquationSystems;
/**
* This class defines an abstract interface for \p Mesh output.
* Specific classes derived from this class actually implement
* writing various mesh formats.
*
* \author Benjamin S. Kirk
* \date 2004
* \version $Revision: 4317 $
*/
// ------------------------------------------------------------
// MeshOutput class definition
template <class MT>
class MeshOutput
{
protected:
/**
* Default constructor. Will set the _obj to NULL, effectively
* rendering this object useless.
*/
MeshOutput (const bool is_parallel_format = false);
/**
* Constructor. Takes a reference to a constant object.
* This constructor will only allow us to write the object.
*/
MeshOutput (const MT&, const bool is_parallel_format = false);
public:
/**
* Destructor.
*/
virtual ~MeshOutput ();
/**
* This method implements writing a mesh to a specified file.
*/
virtual void write (const std::string&) = 0;
/**
* This method implements writing a mesh with data to a specified file
* where the data is taken from the \p EquationSystems object.
*/
virtual void write_equation_systems (const std::string&,
const EquationSystems&);
/**
* 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>&)
{ libmesh_error(); }
/**
* Return/set the precision to use when writing ASCII files.
*
* By default we use numeric_limits<Real>::digits10 + 2, which
* should be enough to write out to ASCII and get the exact same
* Real back when reading in.
*/
unsigned int & ascii_precision ();
protected:
/**
* Returns the object as a read-only reference.
*/
const MT& mesh() const;
/**
* Flag specifying whether this format is parallel-capable.
* If this is false (default) I/O is only permitted when the mesh
* has been serialized.
*/
const bool _is_parallel_format;
/**
* Temporarily serialize a ParallelMesh for output
*/
class MeshOutputSerializer
{
public:
MeshOutputSerializer(MT& mesh, bool need_serial) :
_mesh(mesh),
reparallelize(false)
{
if (need_serial && !_mesh.is_serial()) {
reparallelize = true;
_mesh.allgather();
}
}
~MeshOutputSerializer() {
if (reparallelize)
_mesh.delete_remote_elements();
}
private:
MT& _mesh;
bool reparallelize;
};
private:
/**
* A pointer to a constant object.
* This allows us to write the object to file.
*/
const MT* const _obj;
/**
* Precision to use when writing ASCII files.
*/
unsigned int _ascii_precision;
/**
* A helper function which allows us to fill temporary
* name and solution vectors with an EquationSystems object
*/
void _build_variable_names_and_solution_vector(const EquationSystems& es,
std::vector<Number>& soln,
std::vector<std::string>& names);
};
// ------------------------------------------------------------
// MeshOutput inline members
template <class MT>
inline
MeshOutput<MT>::MeshOutput (const bool is_parallel_format) :
_is_parallel_format(is_parallel_format),
_obj(NULL),
_ascii_precision (std::numeric_limits<Real>::digits10 + 2)
{}
template <class MT>
inline
MeshOutput<MT>::MeshOutput (const MT& obj, const bool is_parallel_format) :
_is_parallel_format(is_parallel_format),
_obj (&obj),
_ascii_precision (std::numeric_limits<Real>::digits10 + 2)
{
if (!_is_parallel_format && !this->mesh().is_serial())
{
if (libMesh::processor_id() == 0)
{
libmesh_do_once(libMesh::err <<
"Warning: This MeshOutput subclass only support meshes which have been serialized!"
<< std::endl; libmesh_here(););
}
// libmesh_error();
}
}
template <class MT>
inline
MeshOutput<MT>::~MeshOutput ()
{
}
template <class MT>
inline
void MeshOutput<MT>::write_equation_systems (const std::string& fname,
const EquationSystems& es)
{
// We may need to gather a ParallelMesh to output it, making that
// const qualifier in our constructor a dirty lie
MeshOutputSerializer(const_cast<MT&>(*_obj), !_is_parallel_format);
// Build the nodal solution values & get the variable
// names from the EquationSystems object
std::vector<Number> soln;
std::vector<std::string> names;
this->_build_variable_names_and_solution_vector(es, soln, names);
//es.build_variable_names (names);
//es.build_solution_vector (soln);
this->write_nodal_data (fname, soln, names);
}
template <class MT>
inline
const MT& MeshOutput<MT>::mesh () const
{
libmesh_assert (_obj != NULL);
return *_obj;
}
template <class MT>
inline
unsigned int & MeshOutput<MT>::ascii_precision ()
{
return _ascii_precision;
}
} // namespace libMesh
#endif // #define __mesh_io_h__
|