24 #include "libmesh/elem.h" 25 #include "libmesh/libmesh_logging.h" 26 #include "libmesh/mesh_base.h" 27 #include "libmesh/gnuplot_io.h" 33 const std::string & title,
49 const std::vector<Number> & soln,
50 const std::vector<std::string> & names)
52 LOG_SCOPE(
"write_nodal_data()",
"GnuPlotIO");
60 const std::vector<Number> * soln,
61 const std::vector<std::string> * names)
71 if (this->
mesh().processor_id() == 0)
73 std::stringstream data_stream_name;
74 data_stream_name << fname <<
"_data";
75 const std::string data_file_name = data_stream_name.str();
84 std::ofstream out_stream(fname.c_str());
87 if (!out_stream.good())
88 libmesh_file_error(fname.c_str());
91 const unsigned int n_vars =
92 cast_int<unsigned int>(names->size());
95 out_stream <<
"# This file was generated by gnuplot_io.C\n" 96 <<
"# Stores 1D solution data in GNUplot format\n" 97 <<
"# Execute this by loading gnuplot and typing " 98 <<
"\"call '" << fname <<
"'\"\n" 100 <<
"set title \"" <<
_title <<
"\"\n" 101 <<
"set xlabel \"x\"\n" 102 <<
"set xtics nomirror\n";
107 Real x_min=0., x_max=0.;
110 std::stringstream xtics_stream;
112 unsigned int count = 0;
114 for (
const auto & el : the_mesh.active_element_ptr_range())
117 if (el->neighbor_ptr(0) ==
nullptr)
119 x_min = (el->point(0))(0);
120 xtics_stream <<
"\"\" " << x_min <<
", \\\n";
122 if (el->neighbor_ptr(1) ==
nullptr)
124 x_max = (el->point(1))(0);
126 xtics_stream <<
"\"\" " << (el->point(1))(0);
128 if (count+1 != n_active_elem)
130 xtics_stream <<
", \\\n";
135 out_stream <<
"set xrange [" << x_min <<
":" << x_max <<
"]\n";
138 out_stream <<
"set x2tics (" << xtics_stream.str() <<
")\nset grid noxtics noytics x2tics\n";
142 out_stream <<
"set terminal png\n";
143 out_stream <<
"set output \"" << fname <<
".png\"\n";
146 out_stream <<
"plot " 148 <<
" \"" << data_file_name <<
"\" using 1:2 title \"" << (*names)[0]
152 for (
unsigned int i=1; i<
n_vars; i++)
154 out_stream <<
", \\\n\"" << data_file_name <<
"\" using 1:" << i+2
155 <<
" title \"" << (*names)[i] <<
"\" with lines";
163 std::ofstream data(data_file_name.c_str());
165 libmesh_error_msg_if(!data.good(),
"ERROR: opening output data file " << data_file_name);
168 std::map<Real, std::vector<Number>> node_map;
170 for (
const auto & elem : the_mesh.active_element_ptr_range())
171 for (
const auto & node : elem->node_ref_range())
175 std::vector<Number> values;
176 for (
unsigned int c=0; c<
n_vars; c++)
177 values.push_back((*soln)[global_id*
n_vars + c]);
179 node_map[the_mesh.
point(global_id)(0)] = values;
182 for (
const auto & pr : node_map)
184 const std::vector<Number> & values = pr.second;
186 data << pr.first <<
"\t";
188 for (
const auto & val : values)
virtual dof_id_type n_active_elem() const =0
This class defines an abstract interface for Mesh output.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void write(const std::string &) override
Write the mesh to the specified file.
This is the MeshBase class.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
std::string axes_limits
GNUplot automatically adjusts the x and y-axes of 2D plots to "zoom in" on the data.
void write_solution(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
GnuPlotIO(const MeshBase &, const std::string &=std::string("FE 1D Solution"), int properties=0)
Constructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int mesh_dimension() const
virtual const Point & point(const dof_id_type i) const =0