From: wolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d> Date: Fri, 29 Jul 2005 20:40:23 +0000 (+0000) Subject: Handle the case that a vector-valued element is given to add_data_vector, but X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f3ab44a273707b219a47f85d3c46e0ad496752b;p=dealii-svn.git Handle the case that a vector-valued element is given to add_data_vector, but only a single name. git-svn-id: https://svn.dealii.org/trunk@11218 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/numerics/data_out_stack.h b/deal.II/deal.II/include/numerics/data_out_stack.h index 62500f5d88..df9ba68e19 100644 --- a/deal.II/deal.II/include/numerics/data_out_stack.h +++ b/deal.II/deal.II/include/numerics/data_out_stack.h @@ -191,6 +191,14 @@ class DataOutStack : public DataOutInterface<dim+1> * and therefore only one name needs to * be given. * + * If @p vec is a vector with + * multiple components this + * function will generate + * distinct names for all + * components by appending an + * underscore and the number of + * each component to @p name + * * The data vector must have been * registered using the @p declare_data_vector * function before actually using it the diff --git a/deal.II/deal.II/source/numerics/data_out_stack.cc b/deal.II/deal.II/source/numerics/data_out_stack.cc index 75915ed45c..8cd39eff8d 100644 --- a/deal.II/deal.II/source/numerics/data_out_stack.cc +++ b/deal.II/deal.II/source/numerics/data_out_stack.cc @@ -24,7 +24,11 @@ #include <fe/fe_values.h> #include <fe/mapping_q1.h> - +#ifdef HAVE_STD_STRINGSTREAM +# include <sstream> +#else +# include <strstream> +#endif template <int dim> @@ -128,8 +132,37 @@ template <typename number> void DataOutStack<dim>::add_data_vector (const Vector<number> &vec, const std::string &name) { + const unsigned int n_components = dof_handler->get_fe().n_components (); + std::vector<std::string> names; - names.push_back (name); + // if only one component or vector + // is cell vector: we only need one + // name + if ((n_components == 1) || + (vec.size() == dof_handler->get_tria().n_active_cells())) + { + names.resize (1, name); + } + else + // otherwise append _i to the + // given name + { + names.resize (n_components); + for (unsigned int i=0; i<n_components; ++i) + { +#ifdef HAVE_STD_STRINGSTREAM + std::ostringstream namebuf; +#else + std::ostrstream namebuf; +#endif + namebuf << '_' << i; +#ifndef HAVE_STD_STRINGSTREAM + namebuf << std::ends; +#endif + names[i] = name + namebuf.str(); + } + } + add_data_vector (vec, names); } diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index ba4299bc81..5abb9cbbe5 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -583,6 +583,16 @@ inconvenience this causes. <h3>deal.II</h3> <ol> + <li> <p> + New: The <code class="member">DataOutStack::add_data_vector</code> + function now also allows to give only a single name even if the data is + vector-valued. It then makes up names for the individual components by + adding numbers to the name, just like the <code + class="class">DataOut</code> class already does for a long time. + <br> + (WB, 2005/07/29) + </p> + <li> <p> New: The <code class="class">DataOutStack</code> class can now also be used to stack two-dimensional time or parameter dependent data into a 3d