-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13027 from bangerth/face_number
Allow accessing face numbers in data postprocessors
- Loading branch information
Showing
7 changed files
with
354 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
New: The DataPostprocessorInputs::CommonInputs class now also | ||
stores the face number that is currently being worked on when | ||
using a DataOutFaces object. This allows accessing face-related | ||
data like the boundary id from a DataPostprocessor. | ||
<br> | ||
(Wolfgang Bangerth, 2021/12/03) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
tests/data_out/data_out_faces_postprocessor_boundary_id.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2016 - 2018 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// Tests DataPostprocessor: access the cell and face we are currently | ||
// working on for a scalar finite element field and DataOutFaces. This | ||
// is then used to output the boundary id of a face. | ||
|
||
|
||
#include <deal.II/base/function.h> | ||
|
||
#include <deal.II/dofs/dof_accessor.h> | ||
#include <deal.II/dofs/dof_handler.h> | ||
|
||
#include <deal.II/fe/fe_dgq.h> | ||
#include <deal.II/fe/fe_system.h> | ||
|
||
#include <deal.II/grid/grid_generator.h> | ||
#include <deal.II/grid/tria.h> | ||
#include <deal.II/grid/tria_accessor.h> | ||
#include <deal.II/grid/tria_iterator.h> | ||
|
||
#include <deal.II/lac/vector.h> | ||
|
||
#include <deal.II/numerics/data_out_faces.h> | ||
#include <deal.II/numerics/data_postprocessor.h> | ||
#include <deal.II/numerics/matrix_tools.h> | ||
#include <deal.II/numerics/vector_tools.h> | ||
|
||
#include "../tests.h" | ||
|
||
|
||
|
||
std::ofstream logfile("output"); | ||
|
||
|
||
template <int dim> | ||
class BoundaryIds : public DataPostprocessorScalar<dim> | ||
{ | ||
public: | ||
BoundaryIds() | ||
: DataPostprocessorScalar<dim>("boundary_id", update_quadrature_points) | ||
{} | ||
|
||
|
||
virtual void | ||
evaluate_scalar_field( | ||
const DataPostprocessorInputs::Scalar<dim> &inputs, | ||
std::vector<Vector<double>> &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<dim>::active_cell_iterator cell = | ||
inputs.template get_cell<dim>(); | ||
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(); | ||
} | ||
} | ||
}; | ||
|
||
|
||
|
||
template <int dim> | ||
void | ||
test() | ||
{ | ||
Triangulation<dim> triangulation; | ||
FE_DGQ<dim> fe(1); | ||
DoFHandler<dim> dof_handler(triangulation); | ||
|
||
GridGenerator::hyper_cube(triangulation, 0, 1, true); | ||
triangulation.refine_global(1); | ||
triangulation.begin_active()->set_refine_flag(); | ||
triangulation.execute_coarsening_and_refinement(); | ||
|
||
dof_handler.distribute_dofs(fe); | ||
|
||
// Create a dummy vector. We will ignore its contents. | ||
Vector<double> solution(dof_handler.n_dofs()); | ||
|
||
BoundaryIds<dim> p; | ||
DataOutFaces<dim> data_out; | ||
data_out.attach_dof_handler(dof_handler); | ||
data_out.add_data_vector(solution, p); | ||
data_out.build_patches(); | ||
data_out.write_gnuplot(logfile); | ||
} | ||
|
||
|
||
int | ||
main() | ||
{ | ||
logfile << std::setprecision(2); | ||
deallog << std::setprecision(2); | ||
|
||
test<2>(); | ||
test<2>(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.