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();
81 libmesh_assert ((names !=
nullptr) && (soln !=
nullptr));
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;
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());
166 libmesh_error_msg(
"ERROR: opening output data file " << data_file_name);
169 std::map<Real, std::vector<Number>> node_map;
172 for (
const auto & node : elem->node_ref_range())
176 std::vector<Number> values;
177 for (
unsigned int c=0; c<
n_vars; c++)
178 values.push_back((*soln)[global_id*
n_vars + c]);
180 node_map[the_mesh.
point(global_id)(0)] = values;
183 for (
const auto & pr : node_map)
185 const std::vector<Number> & values = pr.second;
187 data << pr.first <<
"\t";
189 for (
const auto & val : values)
virtual dof_id_type n_active_elem() const =0
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
const unsigned int n_vars
virtual void write(const std::string &) override
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
void write_solution(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
GnuPlotIO(const MeshBase &, const std::string &=std::string("FE 1D Solution"), int properties=0)
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