From 92d5f6482e6e242e8a5fa17534723fe174f1c7c6 Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 30 Mar 2001 11:06:57 +0000 Subject: [PATCH] Fix an obscure corner case where add_data_vector could not detect itself whether something is a dof vector or a cell vector. Also abolish the _units_ field. git-svn-id: https://svn.dealii.org/trunk@4352 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/data_out.h | 68 +++++++++++++++----- deal.II/deal.II/source/numerics/data_out.cc | 71 ++++++++++++++------- deal.II/doc/news/2001/c-3-1.html | 13 ++++ 3 files changed, 114 insertions(+), 38 deletions(-) diff --git a/deal.II/deal.II/include/numerics/data_out.h b/deal.II/deal.II/include/numerics/data_out.h index e6dadb5fdc..d28a42eb12 100644 --- a/deal.II/deal.II/include/numerics/data_out.h +++ b/deal.II/deal.II/include/numerics/data_out.h @@ -10,13 +10,6 @@ #define __deal2__data_out_h -//TODO:[?] DataOut determines whether something is a DoF or cell vector by the size of the vector. -// This will fail if someone is using DG0 elements, -// since there the number of elements of both types of vectors is the -// same, but the ordering will usually differ. Errors cannot be plotted -// anyway, since they are float vectors. - - #include #include @@ -159,6 +152,29 @@ template class DataOut_DoFData : public DataOutInterface { public: + /** + * Type describing what the + * vector given to + * @ref{add_data_vector} is: a + * vector that has one entry per + * degree of freedom in a + * @ref{DoFHandler} object (such + * as solution vectors), or one + * entry per cell in the + * triangulation underlying the + * @ref{DoFHandler} object (such + * as error per cell data). The + * value @p{type_automatic} tells + * @ref{add_data_vector} to find + * out itself (see the + * documentation of + * @p{add_data_vector} for the + * method used). + */ + enum DataVectorType { + type_dof_data, type_cell_data, type_automatic + }; + /** * Constructor */ @@ -202,7 +218,31 @@ class DataOut_DoFData : public DataOutInterface * the number of active cells on * the present grid, in which * case it is assumed to be a - * cell data vector. + * cell data vector. As the + * number of degrees of freedom + * and of cells is usually not + * equal, the function can + * determine itself which type of + * vector it is given; however, + * there is one corner case, + * namely if you compute with + * piecewise constant elements + * and have one scalar quantity, + * then there are as many cells + * as there are degrees of + * freedom, but they may be + * ordered differently. In that + * case, you can change the last + * argument of the function from + * its default value + * @p{type_automatic} to either + * @p{type_dof_data} or @p{type_cell_data}, + * depending on what the vector + * represents. Apart from this + * corner case, you can leave the + * argument at its default value + * and let the function determine + * the type of the vector itself. * * If it is a vector holding DoF * data, the names given shall be @@ -227,7 +267,8 @@ class DataOut_DoFData : public DataOutInterface * are valid and which are not. */ void add_data_vector (const Vector &data, - const std::vector &names); + const std::vector &names, + const DataVectorType type = type_automatic); /** * This function is an @@ -254,7 +295,8 @@ class DataOut_DoFData : public DataOutInterface * each component to @p{name} */ void add_data_vector (const Vector &data, - const std::string &name); + const std::string &name, + const DataVectorType type = type_automatic); /** * Release the pointers to the @@ -385,12 +427,6 @@ class DataOut_DoFData : public DataOutInterface * data vector. */ std::vector names; - - /** - * Physical unit name of this - * component. - */ - std::string units; }; /** diff --git a/deal.II/deal.II/source/numerics/data_out.cc b/deal.II/deal.II/source/numerics/data_out.cc index 66ddf28414..76b0acfcf4 100644 --- a/deal.II/deal.II/source/numerics/data_out.cc +++ b/deal.II/deal.II/source/numerics/data_out.cc @@ -57,8 +57,7 @@ DataOut_DoFData:: DataEntry::memory_consumption () const { return (sizeof (data) + - MemoryConsumption::memory_consumption (names) + - MemoryConsumption::memory_consumption (units)); + MemoryConsumption::memory_consumption (names)); }; @@ -100,8 +99,10 @@ attach_dof_handler (const DoFHandler &d) template void -DataOut_DoFData::add_data_vector (const Vector &vec, - const std::vector &names) +DataOut_DoFData:: +add_data_vector (const Vector &vec, + const std::vector &names, + const DataVectorType type) { Assert (dofs != 0, ExcNoDoFHandlerSelected ()); @@ -109,16 +110,46 @@ DataOut_DoFData::add_data_vector (con // vectors Assert ((vec.size() == dofs->get_tria().n_active_cells()) || (vec.size() == dofs->n_dofs()), - ExcInvalidVectorSize(vec.size(), dofs->get_tria().n_active_cells(), dofs->n_dofs())); + ExcInvalidVectorSize(vec.size(), dofs->get_tria().n_active_cells(), + dofs->n_dofs())); // either cell data and one name, // or dof data and n_components names - if (vec.size() == dofs->get_tria().n_active_cells()) - Assert (names.size() == 1, - ExcInvalidNumberOfNames (names.size(), 1)); - if (vec.size() == dofs->n_dofs()) - Assert (names.size() == dofs->get_fe().n_components(), - ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components())); + DataVectorType actual_type = type; + if (type == type_automatic) + { + if (vec.size() == dofs->get_tria().n_active_cells()) + actual_type = type_cell_data; + else + actual_type = type_dof_data; + }; + + switch (actual_type) + { + case type_cell_data: + Assert (vec.size() == dofs->get_tria().n_active_cells(), + ExcInvalidVectorSize (vec.size(), + dofs->n_dofs(), + dofs->get_tria().n_active_cells())); + Assert (names.size() == 1, + ExcInvalidNumberOfNames (names.size(), 1)); + break; + + case type_dof_data: + Assert (vec.size() == dofs->n_dofs(), + ExcInvalidVectorSize (vec.size(), + dofs->n_dofs(), + dofs->get_tria().n_active_cells())); + Assert (names.size() == dofs->get_fe().n_components(), + ExcInvalidNumberOfNames (names.size(), dofs->get_fe().n_components())); + break; + + case type_automatic: + // this case should have + // been handled above... + Assert (false, ExcInternalError()); + }; + for (unsigned int i=0; i::add_data_vector (con ExcInvalidCharacter (names[i])); DataEntry new_entry (&vec, names); - if (vec.size() == dofs->n_dofs()) + if (actual_type == type_dof_data) dof_data.push_back (new_entry); else - if (vec.size() == dofs->get_tria().n_active_cells()) - cell_data.push_back (new_entry); - else - Assert (false, - ExcInvalidVectorSize (vec.size(), - dofs->n_dofs(), - dofs->get_tria().n_active_cells())); + cell_data.push_back (new_entry); }; template void -DataOut_DoFData::add_data_vector (const Vector &vec, - const std::string &name) +DataOut_DoFData:: +add_data_vector (const Vector &vec, + const std::string &name, + const DataVectorType type) { unsigned int n_components = dofs->get_fe().n_components (); @@ -168,7 +195,7 @@ DataOut_DoFData::add_data_vector (con }; }; - add_data_vector (vec, names); + add_data_vector (vec, names, type); } diff --git a/deal.II/doc/news/2001/c-3-1.html b/deal.II/doc/news/2001/c-3-1.html index 917b44fa26..516d99eea2 100644 --- a/deal.II/doc/news/2001/c-3-1.html +++ b/deal.II/doc/news/2001/c-3-1.html @@ -315,6 +315,19 @@ documentation, etc.

deal.II

    +
  1. + New/fixed: In some obscure corner cases, the detection logic in DataOut_DoFData::add_data_vector would + not have been able to detect whether something is a DoF data + vector or a vector of cell data, and in some equally rare cases + this would also have made a difference. This is now fixed by + adding another argument to the function telling it either to + automatically detect the vector type (default) or to assume + that it has a certain type (for these corner cases). +
    + (WB 2001/03/30) +

    +
  2. Removed: the ProblemBase class, which has been deprecated since before the release of -- 2.39.5