From: Wolfgang Bangerth Date: Fri, 3 Dec 2021 23:28:19 +0000 (-0700) Subject: Allow storing the face number for DataPostprocessor objects. X-Git-Tag: v9.4.0-rc1~770^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3071005dbf71a06ce47d54d9283d72f3fbbf6acc;p=dealii.git Allow storing the face number for DataPostprocessor objects. --- diff --git a/include/deal.II/numerics/data_postprocessor.h b/include/deal.II/numerics/data_postprocessor.h index b270b442c3..ee82201f56 100644 --- a/include/deal.II/numerics/data_postprocessor.h +++ b/include/deal.II/numerics/data_postprocessor.h @@ -66,6 +66,7 @@ namespace DataPostprocessorInputs * then the @p normal_vectors member variable does not contain anything * useful. * + * *

Cell access

* * DataPostprocessor is typically called from classes such as DataOut @@ -144,10 +145,58 @@ namespace DataPostprocessorInputs * } * }; * @endcode + * + * + *

Face access

+ * + * When a DataPostprocessor object is used for output via the DataOutFaces + * class, it is sometimes necessary to also know which face is currently + * being worked on. Like accessing the cell as shown above, postprocessors + * can then query the face number via the CommonInputs::get_face_number() + * function. An example postprocessor that ignores its input and + * only puts the @ref GlossBoundaryIndicator "Boundary indicator" + * into the output file would then look as follows: + * @code + * template + * class BoundaryIds : public DataPostprocessorScalar + * { + * public: + * BoundaryIds() + * : DataPostprocessorScalar("boundary_id", update_quadrature_points) + * {} + * + * + * virtual void + * evaluate_scalar_field( + * const DataPostprocessorInputs::Scalar &inputs, + * std::vector> &computed_quantities) const override + * { + * AssertDimension(computed_quantities.size(), + * inputs.solution_values.size()); + * + * // Get the cell and face we are currently dealing with: + * const typename DoFHandler::active_cell_iterator cell = + * inputs.template get_cell(); + * const unsigned int face = inputs.get_face_number(); + * + * // Then fill the output fields with the boundary_id of the face + * for (auto &output : computed_quantities) + * { + * AssertDimension(output.size(), 1); + * output(0) = cell->face(face)->boundary_id(); + * } + * } + * }; + * @endcode */ template struct CommonInputs { + /** + * Constructor. + */ + CommonInputs(); + /** * An array of vectors normal to the faces of cells, evaluated at the points * at which we are generating graphical output. This array is only used by @@ -192,6 +241,22 @@ namespace DataPostprocessorInputs void set_cell(const typename DoFHandler::cell_iterator &cell); + /** + * Set the cell and face number that is currently being used in evaluating + * the data for which the DataPostprocessor object is being called. Given + * that a face is required, this function is meant to be called by a class + * such as DataOutFaces. + * + * This function is not usually called from user space, but is instead + * called by DataOutFaces and similar classes when creating the object that + * is then passed to DataPostprocessor. + */ + template + void + set_cell_and_face( + const typename DoFHandler::cell_iterator &cell, + const unsigned int face_number); + /** * Set the cell that is currently being used in evaluating the data * for which the DataPostprocessor object is being called. @@ -228,6 +293,18 @@ namespace DataPostprocessorInputs DEAL_II_DEPRECATED typename DoFHandlerType::cell_iterator get_cell() const; + /** + * Query the face number on which we currently produce graphical output. + * See the documentation of the current class for an example on how + * to use the related get_cell() function that is meant to query the cell + * currently being worked on. + * + * This function is intended for use when producing graphical output on + * faces, for example through the DataOutFaces class. + */ + unsigned int + get_face_number() const; + private: /** * The place where set_cell() stores the cell. Since the actual data @@ -237,6 +314,12 @@ namespace DataPostprocessorInputs * get_cell(). */ boost::any cell; + + /** + * The place where set_cell_and_face() stores the number of the face + * being worked on. + */ + unsigned int face_number; }; /** @@ -1224,6 +1307,23 @@ namespace DataPostprocessorInputs // if we had nothing stored before, or if we had stored a different // data type, just let boost::any replace things cell = new_cell; + + // Also reset the face number, just to make sure nobody + // accidentally uses an outdated value. + face_number = numbers::invalid_unsigned_int; + } + + + + template + template + void + CommonInputs::set_cell_and_face( + const typename DoFHandler::cell_iterator &new_cell, + const unsigned int new_face_number) + { + set_cell(new_cell); + face_number = new_face_number; } diff --git a/source/numerics/data_postprocessor.cc b/source/numerics/data_postprocessor.cc index e37168895a..61fa1fd222 100644 --- a/source/numerics/data_postprocessor.cc +++ b/source/numerics/data_postprocessor.cc @@ -19,6 +19,29 @@ DEAL_II_NAMESPACE_OPEN +namespace DataPostprocessorInputs +{ + template + CommonInputs::CommonInputs() + : face_number(numbers::invalid_unsigned_int) + {} + + + + template + unsigned int + CommonInputs::get_face_number() const + { + Assert( + face_number != numbers::invalid_unsigned_int, + ExcMessage( + "This function can only be called if set_cell_and_face() has " + "previously been called. Typically, this would be by using DataOutFaces " + "or a related class.")); + return face_number; + } +} // namespace DataPostprocessorInputs + // -------------------------- DataPostprocessor --------------------------- template @@ -54,7 +77,7 @@ DataPostprocessor::get_data_component_interpretation() const } -// -------------------------- DataPostprocessorScalar ------------------------- +// -------------------- DataPostprocessorScalar ------------------------- template DataPostprocessorScalar::DataPostprocessorScalar( @@ -93,7 +116,8 @@ DataPostprocessorScalar::get_needed_update_flags() const -// -------------------------- DataPostprocessorVector ------------------------- +// -------------------------- DataPostprocessorVector +// ------------------------- template DataPostprocessorVector::DataPostprocessorVector( @@ -132,7 +156,8 @@ DataPostprocessorVector::get_needed_update_flags() const -// -------------------------- DataPostprocessorTensor ------------------------- +// -------------------------- DataPostprocessorTensor +// ------------------------- template DataPostprocessorTensor::DataPostprocessorTensor( diff --git a/source/numerics/data_postprocessor.inst.in b/source/numerics/data_postprocessor.inst.in index 4d7d920de9..528475a017 100644 --- a/source/numerics/data_postprocessor.inst.in +++ b/source/numerics/data_postprocessor.inst.in @@ -16,6 +16,10 @@ for (deal_II_dimension : DIMENSIONS) { + namespace DataPostprocessorInputs + \{ + template class CommonInputs; + \} template class DataPostprocessor; template class DataPostprocessorScalar; template class DataPostprocessorVector;