From ac001a462e3532df7bdb7d2ddde8da0e618334cb Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Wed, 15 Jul 2020 15:47:25 +0200 Subject: [PATCH] Accept MappingCollection in DataOut::build_patches() --- cmake/scripts/expand_instantiations.cc | 10 +- include/deal.II/numerics/data_out.h | 15 ++- include/deal.II/numerics/data_out_dof_data.h | 11 ++ .../numerics/data_out_dof_data.templates.h | 22 ++++ source/numerics/data_out.cc | 35 ++++-- .../data_out_mapping_collection_01.cc | 109 ++++++++++++++++++ .../data_out_mapping_collection_01.output | 91 +++++++++++++++ 7 files changed, 275 insertions(+), 18 deletions(-) create mode 100644 tests/data_out/data_out_mapping_collection_01.cc create mode 100644 tests/data_out/data_out_mapping_collection_01.output diff --git a/cmake/scripts/expand_instantiations.cc b/cmake/scripts/expand_instantiations.cc index 0b91fc2e91..7acf70fe6f 100644 --- a/cmake/scripts/expand_instantiations.cc +++ b/cmake/scripts/expand_instantiations.cc @@ -444,11 +444,11 @@ process_instantiations() // output preprocessor defines as is: if (has_prefix(whole_file, "#")) - { - std::cout << get_substring_with_delim(whole_file, "\n") << '\n'; - skip_space(whole_file); - continue; - } + { + std::cout << get_substring_with_delim(whole_file, "\n") << '\n'; + skip_space(whole_file); + continue; + } if (!has_prefix(whole_file, "for")) { diff --git a/include/deal.II/numerics/data_out.h b/include/deal.II/numerics/data_out.h index c3e73346aa..aa6a3ffaf9 100644 --- a/include/deal.II/numerics/data_out.h +++ b/include/deal.II/numerics/data_out.h @@ -44,7 +44,7 @@ namespace internal const unsigned int n_datasets, const unsigned int n_subdivisions, const std::vector &n_postprocessor_outputs, - const Mapping & mapping, + const dealii::hp::MappingCollection &mapping, const std::vector< std::shared_ptr>> & finite_elements, @@ -315,9 +315,6 @@ public: * even if the mesh is internally stored in its undeformed configuration and * the deformation is only tracked by an additional vector that holds the * deformation of each vertex. - * - * @todo The @p mapping argument should be replaced by a - * hp::MappingCollection in case of a hp::DoFHandler. */ virtual void build_patches(const Mapping &mapping, + const unsigned int n_subdivisions = 0, + const CurvedCellRegion curved_region = curved_boundary); + /** * A function that allows selecting for which cells output should be * generated. This function takes two arguments, both `std::function` diff --git a/include/deal.II/numerics/data_out_dof_data.h b/include/deal.II/numerics/data_out_dof_data.h index 2bd6d1da57..8630f7664b 100644 --- a/include/deal.II/numerics/data_out_dof_data.h +++ b/include/deal.II/numerics/data_out_dof_data.h @@ -413,6 +413,17 @@ namespace internal const UpdateFlags update_flags, const bool use_face_values); + ParallelDataBase( + const unsigned int n_datasets, + const unsigned int n_subdivisions, + const std::vector &n_postprocessor_outputs, + const dealii::hp::MappingCollection &mapping, + const std::vector< + std::shared_ptr>> + & finite_elements, + const UpdateFlags update_flags, + const bool use_face_values); + ParallelDataBase(const ParallelDataBase &data); template diff --git a/include/deal.II/numerics/data_out_dof_data.templates.h b/include/deal.II/numerics/data_out_dof_data.templates.h index d0545803c9..676a714028 100644 --- a/include/deal.II/numerics/data_out_dof_data.templates.h +++ b/include/deal.II/numerics/data_out_dof_data.templates.h @@ -69,6 +69,28 @@ namespace internal & finite_elements, const UpdateFlags update_flags, const bool use_face_values) + : ParallelDataBase( + n_datasets, + n_subdivisions, + n_postprocessor_outputs, + dealii::hp::MappingCollection(mapping), + finite_elements, + update_flags, + use_face_values) + {} + + + template + ParallelDataBase::ParallelDataBase( + const unsigned int n_datasets, + const unsigned int n_subdivisions, + const std::vector &n_postprocessor_outputs, + const dealii::hp::MappingCollection &mapping, + const std::vector< + std::shared_ptr>> + & finite_elements, + const UpdateFlags update_flags, + const bool use_face_values) : n_datasets(n_datasets) , n_subdivisions(n_subdivisions) , postprocessed_values(n_postprocessor_outputs.size()) diff --git a/source/numerics/data_out.cc b/source/numerics/data_out.cc index f35b6bbc88..d78b22e2de 100644 --- a/source/numerics/data_out.cc +++ b/source/numerics/data_out.cc @@ -45,7 +45,7 @@ namespace internal const unsigned int n_datasets, const unsigned int n_subdivisions, const std::vector &n_postprocessor_outputs, - const Mapping & mapping, + const dealii::hp::MappingCollection &mapping, const std::vector< std::shared_ptr>> & finite_elements, @@ -99,25 +99,25 @@ DataOut::build_one_patch( patch; patch.n_subdivisions = n_subdivisions; + // initialize FEValues + scratch_data.reinit_all_fe_values(this->dof_data, cell_and_index->first); + + const FEValuesBase + &fe_patch_values = scratch_data.get_present_fe_values(0); + // set the vertices of the patch. if the mapping does not preserve locations // (e.g. MappingQEulerian), we need to compute the offset of the vertex for // the graphical output. Otherwise, we can just use the vertex info. for (const unsigned int vertex : GeometryInfo::vertex_indices()) - if (scratch_data.mapping_collection[0].preserves_vertex_locations()) + if (fe_patch_values.get_mapping().preserves_vertex_locations()) patch.vertices[vertex] = cell_and_index->first->vertex(vertex); else patch.vertices[vertex] = - scratch_data.mapping_collection[0].transform_unit_to_real_cell( + fe_patch_values.get_mapping().transform_unit_to_real_cell( cell_and_index->first, GeometryInfo::unit_cell_vertex(vertex)); - // initialize FEValues - scratch_data.reinit_all_fe_values(this->dof_data, cell_and_index->first); - - const FEValuesBase - &fe_patch_values = scratch_data.get_present_fe_values(0); - const unsigned int n_q_points = fe_patch_values.n_quadrature_points; // First fill the geometric information for the patch: Where are the @@ -1085,6 +1085,23 @@ DataOut::build_patches( & mapping, const unsigned int n_subdivisions_, const CurvedCellRegion curved_region) +{ + hp::MappingCollection + mapping_collection(mapping); + + build_patches(mapping_collection, n_subdivisions_, curved_region); +} + + + +template +void +DataOut::build_patches( + const hp::MappingCollection &mapping, + const unsigned int n_subdivisions_, + const CurvedCellRegion curved_region) { // Check consistency of redundant template parameter Assert(dim == DoFHandlerType::dimension, diff --git a/tests/data_out/data_out_mapping_collection_01.cc b/tests/data_out/data_out_mapping_collection_01.cc new file mode 100644 index 0000000000..1c819f7019 --- /dev/null +++ b/tests/data_out/data_out_mapping_collection_01.cc @@ -0,0 +1,109 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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. +// +// --------------------------------------------------------------------- + + + +// Test DataOut::build_patch() that takes MappingCollection. + + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "../tests.h" + + + +template +void +test() +{ + // create quarter hyper ball with 3 cells + Triangulation triangulation; + GridGenerator::quarter_hyper_ball(triangulation); + + // create first mapping class, that does NOT preserve position of vertices + const FE_Q feq(1); + const FESystem fesystem(feq, spacedim); + DoFHandler dhq(triangulation); + dhq.distribute_dofs(fesystem); + const ComponentMask mask(spacedim, true); + Vector eulerq(dhq.n_dofs()); + VectorTools::get_position_vector(dhq, eulerq, mask); + eulerq.add(-0.01); + MappingFEField mapping_1(dhq, eulerq, mask); + + // create first mapping class, that does preserve position of vertices + MappingQGeneric mapping_2(1); + + // create mapping collection + hp::FECollection fe_collection(FE_Q(1), FE_Q(1)); + hp::MappingCollection mapping_collection(mapping_1, mapping_2); + + // create dof-handler and assign cells to different fes/manifolds + hp::DoFHandler dof_handler(triangulation); + + for (const auto &cell : dof_handler.active_cell_iterators()) + cell->set_active_fe_index(std::min(cell->active_cell_index(), 1u)); + + dof_handler.distribute_dofs(fe_collection); + + // output vector + DataOut data_out; + data_out.attach_dof_handler(dof_handler); + + Vector solution(dof_handler.n_dofs()); + + data_out.add_data_vector(solution, "solution"); + + data_out.build_patches(mapping_collection, 3); + +#if false + std::ofstream output("test.vtk"); + data_out.write_vtk(output); +#else + data_out.write_vtk(deallog.get_file_stream()); +#endif +} + + + +int +main() +{ + initlog(); + deallog.get_file_stream().precision(2); + + test<2>(); +} diff --git a/tests/data_out/data_out_mapping_collection_01.output b/tests/data_out/data_out_mapping_collection_01.output new file mode 100644 index 0000000000..2572e0c9ea --- /dev/null +++ b/tests/data_out/data_out_mapping_collection_01.output @@ -0,0 +1,91 @@ + +# vtk DataFile Version 3.0 +#This file was generated +ASCII +DATASET UNSTRUCTURED_GRID + +POINTS 48 double +-0.010 -0.010 0 +0.18 -0.010 0 +0.36 -0.010 0 +0.55 -0.010 0 +-0.010 0.18 0 +0.16 0.16 0 +0.33 0.15 0 +0.50 0.13 0 +-0.010 0.36 0 +0.15 0.33 0 +0.30 0.30 0 +0.46 0.28 0 +-0.010 0.55 0 +0.13 0.50 0 +0.28 0.46 0 +0.42 0.42 0 +1.0 0.0 0 +0.90 0.24 0 +0.80 0.47 0 +0.71 0.71 0 +0.85 0.0 0 +0.77 0.20 0 +0.69 0.41 0 +0.61 0.61 0 +0.70 0.0 0 +0.64 0.17 0 +0.58 0.35 0 +0.52 0.52 0 +0.56 0.0 0 +0.51 0.14 0 +0.47 0.29 0 +0.43 0.43 0 +0.0 1.0 0 +0.0 0.85 0 +0.0 0.70 0 +0.0 0.56 0 +0.24 0.90 0 +0.20 0.77 0 +0.17 0.64 0 +0.14 0.51 0 +0.47 0.80 0 +0.41 0.69 0 +0.35 0.58 0 +0.29 0.47 0 +0.71 0.71 0 +0.61 0.61 0 +0.52 0.52 0 +0.43 0.43 0 + +CELLS 27 135 +4 0 1 5 4 +4 1 2 6 5 +4 2 3 7 6 +4 4 5 9 8 +4 5 6 10 9 +4 6 7 11 10 +4 8 9 13 12 +4 9 10 14 13 +4 10 11 15 14 +4 16 17 21 20 +4 17 18 22 21 +4 18 19 23 22 +4 20 21 25 24 +4 21 22 26 25 +4 22 23 27 26 +4 24 25 29 28 +4 25 26 30 29 +4 26 27 31 30 +4 32 33 37 36 +4 33 34 38 37 +4 34 35 39 38 +4 36 37 41 40 +4 37 38 42 41 +4 38 39 43 42 +4 40 41 45 44 +4 41 42 46 45 +4 42 43 47 46 + +CELL_TYPES 27 + 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 +POINT_DATA 48 +SCALARS solution double 1 +LOOKUP_TABLE default +0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -- 2.39.5