mesh_output.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_MESH_OUTPUT_H 00021 #define LIBMESH_MESH_OUTPUT_H 00022 00023 00024 // Local includes 00025 #include "libmesh/libmesh_common.h" 00026 #include "libmesh/libmesh_logging.h" 00027 #include "libmesh/mesh_base.h" 00028 #include "libmesh/mesh_serializer.h" 00029 00030 // C++ includes 00031 #include <cstddef> 00032 #include <limits> 00033 #include <string> 00034 #include <vector> 00035 00036 namespace libMesh 00037 { 00038 00039 // Forward declares 00040 class EquationSystems; 00041 00042 00052 // ------------------------------------------------------------ 00053 // MeshOutput class definition 00054 template <class MT> 00055 class MeshOutput 00056 { 00057 protected: 00058 00063 explicit 00064 MeshOutput (const bool is_parallel_format = false); 00065 00070 explicit 00071 MeshOutput (const MT&, const bool is_parallel_format = false); 00072 00073 00074 public: 00075 00079 virtual ~MeshOutput (); 00080 00084 virtual void write (const std::string&) = 0; 00085 00090 virtual void write_equation_systems (const std::string&, 00091 const EquationSystems&, 00092 const std::set<std::string>* system_names=NULL); 00093 00098 virtual void write_nodal_data (const std::string&, 00099 const std::vector<Number>&, 00100 const std::vector<std::string>&) 00101 { libmesh_error(); } 00102 00110 unsigned int & ascii_precision (); 00111 00112 protected: 00113 00114 00118 const MT& mesh() const; 00119 00120 00126 const bool _is_parallel_format; 00127 00128 00129 private: 00130 00131 00136 const MT* const _obj; 00137 00141 unsigned int _ascii_precision; 00142 00149 void _build_variable_names_and_solution_vector(const EquationSystems& es, 00150 std::vector<Number>& soln, 00151 std::vector<std::string>& names, 00152 const std::set<std::string>* system_names=NULL); 00153 }; 00154 00155 00156 00157 00158 00159 00160 // ------------------------------------------------------------ 00161 // MeshOutput inline members 00162 template <class MT> 00163 inline 00164 MeshOutput<MT>::MeshOutput (const bool is_parallel_format) : 00165 _is_parallel_format(is_parallel_format), 00166 _obj(NULL), 00167 _ascii_precision (std::numeric_limits<Real>::digits10 + 2) 00168 {} 00169 00170 00171 00172 template <class MT> 00173 inline 00174 MeshOutput<MT>::MeshOutput (const MT& obj, const bool is_parallel_format) : 00175 _is_parallel_format(is_parallel_format), 00176 _obj (&obj), 00177 _ascii_precision (std::numeric_limits<Real>::digits10 + 2) 00178 { 00179 if (!_is_parallel_format && !this->mesh().is_serial()) 00180 { 00181 if (libMesh::processor_id() == 0) 00182 { 00183 libmesh_do_once(libMesh::out << 00184 "Warning: This MeshOutput subclass only supports meshes which have been serialized!" 00185 << std::endl;); 00186 } 00187 // libmesh_error(); 00188 } 00189 } 00190 00191 00192 00193 template <class MT> 00194 inline 00195 MeshOutput<MT>::~MeshOutput () 00196 { 00197 } 00198 00199 00200 00201 template <class MT> 00202 inline 00203 void MeshOutput<MT>::write_equation_systems (const std::string& fname, 00204 const EquationSystems& es, 00205 const std::set<std::string>* system_names) 00206 { 00207 START_LOG("write_equation_systems()", "MeshOutput"); 00208 00209 // We may need to gather and/or renumber a ParallelMesh to output 00210 // it, making that const qualifier in our constructor a dirty lie 00211 MT& my_mesh = const_cast<MT&>(*_obj); 00212 00213 // A non-renumbered mesh may not have a contiguous numbering, and 00214 // that needs to be fixed before we can build a solution vector. 00215 if (my_mesh.max_elem_id() != my_mesh.n_elem() || 00216 my_mesh.max_node_id() != my_mesh.n_nodes()) 00217 { 00218 // If we were allowed to renumber then we should have already 00219 // been properly renumbered... 00220 libmesh_assert(!my_mesh.allow_renumbering()); 00221 00222 libmesh_do_once(libMesh::out << 00223 "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!" 00224 << std::endl;); 00225 00226 my_mesh.allow_renumbering(true); 00227 00228 my_mesh.renumber_nodes_and_elements(); 00229 00230 // Not sure what good going back to false will do here, the 00231 // renumbering horses have already left the barn... 00232 my_mesh.allow_renumbering(false); 00233 } 00234 00235 MeshSerializer serialize(const_cast<MT&>(*_obj), !_is_parallel_format); 00236 00237 // Build the nodal solution values & get the variable 00238 // names from the EquationSystems object 00239 std::vector<Number> soln; 00240 std::vector<std::string> names; 00241 00242 this->_build_variable_names_and_solution_vector(es, soln, names, system_names); 00243 //es.build_variable_names (names); 00244 //es.build_solution_vector (soln); 00245 00246 this->write_nodal_data (fname, soln, names); 00247 00248 STOP_LOG("write_equation_systems()", "MeshOutput"); 00249 } 00250 00251 00252 00253 template <class MT> 00254 inline 00255 const MT& MeshOutput<MT>::mesh () const 00256 { 00257 libmesh_assert(_obj); 00258 return *_obj; 00259 } 00260 00261 00262 00263 template <class MT> 00264 inline 00265 unsigned int & MeshOutput<MT>::ascii_precision () 00266 { 00267 return _ascii_precision; 00268 } 00269 00270 00271 } // namespace libMesh 00272 00273 00274 #endif // LIBMESH_MESH_OUTPUT_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: