libMesh::GnuPlotIO Class Reference
#include <gnuplot_io.h>

Public Types | |
| enum | PlottingProperties { GRID_ON = 1, PNG_OUTPUT = 2 } |
Public Member Functions | |
| GnuPlotIO (const MeshBase &, const std::string &=std::string("FE 1D Solution"), int properties=0) | |
| virtual void | write (const std::string &) |
| virtual void | write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) |
| void | set_title (const std::string &title) |
| void | use_grid (bool grid) |
| void | set_png_output (bool png_output) |
| virtual void | write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=NULL) |
| unsigned int & | ascii_precision () |
Public Attributes | |
| std::string | axes_limits |
Protected Member Functions | |
| const MeshBase & | mesh () const |
Protected Attributes | |
| const bool | _is_parallel_format |
Private Member Functions | |
| void | write_solution (const std::string &, const std::vector< Number > *=NULL, const std::vector< std::string > *=NULL) |
Private Attributes | |
| std::string | _title |
| bool | _grid |
| bool | _png_output |
Detailed Description
This class implements writing meshes using GNUplot, designed for use only with 1D meshes.
Definition at line 45 of file gnuplot_io.h.
Member Enumeration Documentation
Define enumerations to set plotting properties on construction
Definition at line 52 of file gnuplot_io.h.
00052 { GRID_ON = 1, 00053 PNG_OUTPUT = 2};
Constructor & Destructor Documentation
| libMesh::GnuPlotIO::GnuPlotIO | ( | const MeshBase & | mesh_in, | |
| const std::string & | title = std::string("FE 1D Solution"), |
|||
| int | properties = 0 | |||
| ) | [explicit] |
Constructor. Takes a reference to a constant mesh object. To set the properties, we input a bitwise OR of the GnuPlotIO::PlottingProperties enumerations, e.g. GnuPlotIO::GRID_ON | GnuPlotIO::PNG_OUTPUT
Definition at line 32 of file gnuplot_io.C.
References _grid, _png_output, GRID_ON, and PNG_OUTPUT.
00035 : 00036 MeshOutput<MeshBase> (mesh_in), 00037 _title(title) 00038 { 00039 _grid = (mesh_properties & GRID_ON); 00040 _png_output = (mesh_properties & PNG_OUTPUT); 00041 }
Member Function Documentation
| unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision | ( | ) | [inherited] |
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.
Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().
| const MeshBase & libMesh::MeshOutput< MeshBase >::mesh | ( | ) | const [protected, inherited] |
Returns the object as a read-only reference.
Referenced by libMesh::PostscriptIO::write(), libMesh::FroIO::write(), libMesh::EnsightIO::write(), libMesh::DivaIO::write(), libMesh::TecplotIO::write_ascii(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_binary(), libMesh::EnsightIO::write_geometry_ascii(), libMesh::EnsightIO::write_scalar_ascii(), write_solution(), libMesh::DivaIO::write_stream(), and libMesh::EnsightIO::write_vector_ascii().
| void libMesh::GnuPlotIO::set_png_output | ( | bool | png_output | ) | [inline] |
Write output to a .png file using gnuplot
Definition at line 93 of file gnuplot_io.h.
References _png_output.
00093 { _png_output = png_output; }
| void libMesh::GnuPlotIO::set_title | ( | const std::string & | title | ) | [inline] |
Set title of plot
Definition at line 82 of file gnuplot_io.h.
References _title.
00082 { _title = title; }
| void libMesh::GnuPlotIO::use_grid | ( | bool | grid | ) | [inline] |
Turn grid on or off.
Definition at line 87 of file gnuplot_io.h.
References _grid.
00087 { _grid = grid; }
| void libMesh::GnuPlotIO::write | ( | const std::string & | fname | ) | [virtual] |
Write the mesh to the specified file.
Implements libMesh::MeshOutput< MeshBase >.
Definition at line 43 of file gnuplot_io.C.
References write_solution().
00044 { 00045 this->write_solution(fname); 00046 }
| virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems | ( | const std::string & | , | |
| const EquationSystems & | , | |||
| const std::set< std::string > * | system_names = NULL | |||
| ) | [virtual, inherited] |
This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.
Referenced by libMesh::Nemesis_IO::write_timestep().
| void libMesh::GnuPlotIO::write_nodal_data | ( | const std::string & | fname, | |
| const std::vector< Number > & | soln, | |||
| const std::vector< std::string > & | names | |||
| ) | [virtual] |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.
Reimplemented from libMesh::MeshOutput< MeshBase >.
Definition at line 48 of file gnuplot_io.C.
References write_solution().
00051 { 00052 START_LOG("write_nodal_data()", "GnuPlotIO"); 00053 00054 this->write_solution(fname, &soln, &names); 00055 00056 STOP_LOG("write_nodal_data()", "GnuPlotIO"); 00057 }
| void libMesh::GnuPlotIO::write_solution | ( | const std::string & | fname, | |
| const std::vector< Number > * | soln = NULL, |
|||
| const std::vector< std::string > * | names = NULL | |||
| ) | [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.
Definition at line 62 of file gnuplot_io.C.
References _grid, _png_output, _title, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), axes_limits, data, libMesh::err, libMesh::Elem::get_node(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_active_elem(), libMesh::Elem::n_nodes(), n_vars, libMesh::Elem::neighbor(), libMesh::Elem::node(), libMesh::MeshBase::point(), libMesh::processor_id(), and libMesh::Real.
Referenced by write(), and write_nodal_data().
00065 { 00066 // Even when writing on a serialized ParallelMesh, we expect 00067 // non-proc-0 help with calls like n_active_elem 00068 // libmesh_assert_equal_to (libMesh::processor_id(), 0); 00069 00070 const MeshBase& the_mesh = MeshOutput<MeshBase>::mesh(); 00071 00072 dof_id_type n_active_elem = the_mesh.n_active_elem(); 00073 00074 if (libMesh::processor_id() == 0) 00075 { 00076 std::stringstream data_stream_name; 00077 data_stream_name << fname << "_data"; 00078 const std::string data_file_name = data_stream_name.str(); 00079 00080 // This class is designed only for use with 1D meshes 00081 libmesh_assert_equal_to (the_mesh.mesh_dimension(), 1); 00082 00083 // Make sure we have a solution to plot 00084 libmesh_assert ((names != NULL) && (soln != NULL)); 00085 00086 // Create an output stream for script file 00087 std::ofstream out_stream(fname.c_str()); 00088 00089 // Make sure it opened correctly 00090 if (!out_stream.good()) 00091 libmesh_file_error(fname.c_str()); 00092 00093 // The number of variables in the equation system 00094 const unsigned int n_vars = 00095 libmesh_cast_int<unsigned int>(names->size()); 00096 00097 // Write header to stream 00098 out_stream << "# This file was generated by gnuplot_io.C\n" 00099 << "# Stores 1D solution data in GNUplot format\n" 00100 << "# Execute this by loading gnuplot and typing " 00101 << "\"call '" << fname << "'\"\n" 00102 << "reset\n" 00103 << "set title \"" << _title << "\"\n" 00104 << "set xlabel \"x\"\n" 00105 << "set xtics nomirror\n"; 00106 00107 // Loop over the elements to find the minimum and maximum x values, 00108 // and also to find the element boundaries to write out as xtics 00109 // if requested. 00110 Real x_min=0., x_max=0.; 00111 00112 // construct string for xtic positions at element edges 00113 std::stringstream xtics_stream; 00114 00115 MeshBase::const_element_iterator it = the_mesh.active_elements_begin(); 00116 const MeshBase::const_element_iterator end_it = 00117 the_mesh.active_elements_end(); 00118 00119 unsigned int count = 0; 00120 00121 for( ; it != end_it; ++it) 00122 { 00123 const Elem* el = *it; 00124 00125 // if el is the left edge of the mesh, print its left node position 00126 if(el->neighbor(0) == NULL) 00127 { 00128 x_min = (*(el->get_node(0)))(0); 00129 xtics_stream << "\"\" " << x_min << ", \\\n"; 00130 } 00131 if(el->neighbor(1) == NULL) 00132 { 00133 x_max = (*(el->get_node(1)))(0); 00134 } 00135 xtics_stream << "\"\" " << (*(el->get_node(1)))(0); 00136 00137 if(count+1 != n_active_elem) 00138 { 00139 xtics_stream << ", \\\n"; 00140 } 00141 count++; 00142 } 00143 00144 out_stream << "set xrange [" << x_min << ":" << x_max << "]\n"; 00145 00146 if(_grid) 00147 out_stream << "set x2tics (" << xtics_stream.str() << ")\nset grid noxtics noytics x2tics\n"; 00148 00149 if(_png_output) 00150 { 00151 out_stream << "set terminal png\n"; 00152 out_stream << "set output \"" << fname << ".png\"\n"; 00153 } 00154 00155 out_stream << "plot " 00156 << axes_limits 00157 << " \"" << data_file_name << "\" using 1:2 title \"" << (*names)[0] 00158 << "\" with lines"; 00159 if(n_vars > 1) 00160 { 00161 for(unsigned int i=1; i<n_vars; i++) 00162 { 00163 out_stream << ", \\\n\"" << data_file_name << "\" using 1:" << i+2 00164 << " title \"" << (*names)[i] << "\" with lines"; 00165 } 00166 } 00167 00168 out_stream.close(); 00169 00170 00171 // Create an output stream for data file 00172 std::ofstream data(data_file_name.c_str()); 00173 00174 if (!data.good()) 00175 { 00176 libMesh::err << "ERROR: opening output data file " << std::endl; 00177 libmesh_error(); 00178 } 00179 00180 // get ordered nodal data using a map 00181 typedef std::pair<Real, std::vector<Number> > key_value_pair; 00182 typedef std::map<Real, std::vector<Number> > map_type; 00183 typedef map_type::iterator map_iterator; 00184 00185 map_type node_map; 00186 00187 00188 it = the_mesh.active_elements_begin(); 00189 00190 for ( ; it != end_it; ++it) 00191 { 00192 const Elem* elem = *it; 00193 00194 for(unsigned int i=0; i<elem->n_nodes(); i++) 00195 { 00196 std::vector<Number> values; 00197 00198 // Get the global id of the node 00199 dof_id_type global_id = elem->node(i); 00200 00201 for(unsigned int c=0; c<n_vars; c++) 00202 { 00203 values.push_back( (*soln)[global_id*n_vars + c] ); 00204 } 00205 00206 node_map[ the_mesh.point(global_id)(0) ] = values; 00207 } 00208 } 00209 00210 00211 map_iterator map_it = node_map.begin(); 00212 const map_iterator end_map_it = node_map.end(); 00213 00214 for( ; map_it != end_map_it; ++map_it) 00215 { 00216 key_value_pair kvp = *map_it; 00217 std::vector<Number> values = kvp.second; 00218 00219 data << kvp.first << "\t"; 00220 00221 for(unsigned int i=0; i<values.size(); i++) 00222 { 00223 data << values[i] << "\t"; 00224 } 00225 00226 data << "\n"; 00227 } 00228 00229 data.close(); 00230 } 00231 }
Member Data Documentation
bool libMesh::GnuPlotIO::_grid [private] |
Definition at line 117 of file gnuplot_io.h.
Referenced by GnuPlotIO(), use_grid(), and write_solution().
const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format [protected, inherited] |
Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.
Definition at line 126 of file mesh_output.h.
Referenced by libMesh::PostscriptIO::write(), libMesh::FroIO::write(), libMesh::EnsightIO::write(), and libMesh::DivaIO::write().
bool libMesh::GnuPlotIO::_png_output [private] |
Definition at line 118 of file gnuplot_io.h.
Referenced by GnuPlotIO(), set_png_output(), and write_solution().
std::string libMesh::GnuPlotIO::_title [private] |
Definition at line 115 of file gnuplot_io.h.
Referenced by set_title(), and write_solution().
| std::string libMesh::GnuPlotIO::axes_limits |
GNUplot automatically adjusts the x and y-axes of 2D plots to "zoom in" on the data. You can set this string to force GNUplot to maintain a fixed set of axes. Example: axes_limits = "[0:1] [0:1]" would force x and y to be plotted on the range 0<=x<=1 and 0<=y<=1 regardless of where the data lie.
Definition at line 103 of file gnuplot_io.h.
Referenced by write_solution().
The documentation for this class was generated from the following files:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:26 UTC
Hosted By: