| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2021 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_data_out_resample_h |
| 16 |
#define dealii_data_out_resample_h |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <deal.II/base/config.h> |
| 21 |
|
| 22 |
#include <deal.II/base/mpi_remote_point_evaluation.h> |
| 23 |
#include <deal.II/base/partitioner.h> |
| 24 |
|
| 25 |
#include <deal.II/numerics/data_out.h> |
| 26 |
#include <deal.II/numerics/data_out_dof_data.h> |
| 27 |
|
| 28 |
#include <memory> |
| 29 |
|
| 30 |
DEAL_II_NAMESPACE_OPEN |
| 31 |
|
| 32 |
/** |
| 33 |
* A DataOut-like class which interpolates values defined on one Triangulation |
| 34 |
* onto a second potentially unrelated Triangulation. By using this class, |
| 35 |
* one can output the result obtained on an unstructured mesh onto a |
| 36 |
* structured one or one can create a slice in 3d. |
| 37 |
* |
| 38 |
* The following code snippet shows the steps how to use the class when the |
| 39 |
* solution is given for a three dimensional triangulation and the result |
| 40 |
* should be outputted on a (2d) slice: |
| 41 |
* @code |
| 42 |
* // setup and first usage |
| 43 |
* DataOutResample<3, 2, 3> data_out(patch_tria,patch_mapping); |
| 44 |
* data_out.add_data_vector(dof_handler, vector, "solution"); |
| 45 |
* data_out.build_patches(mapping); |
| 46 |
* |
| 47 |
* // ... no changes in triangulation and mapping -> reuse internal data |
| 48 |
* // structures |
| 49 |
* data_out.build_patches(); |
| 50 |
* |
| 51 |
* // ... changes in triangulation or mapping -> reinitialize internal data |
| 52 |
* // structures |
| 53 |
* data_out.build_patches(mapping); |
| 54 |
* @endcode |
| 55 |
* |
| 56 |
* @note While the dimension of the two triangulations might differ, their |
| 57 |
* space dimension need to coincide. |
| 58 |
*/ |
| 59 |
template <int dim, int patch_dim, int spacedim> |
| 60 |
class DataOutResample |
| 61 |
: public DataOut_DoFData<dim, patch_dim, spacedim, spacedim> |
| 62 |
{ |
| 63 |
public: |
| 64 |
/** |
| 65 |
* Constructor taking the triangulation and mapping for which the patches |
| 66 |
* should be generated. |
| 67 |
*/ |
| 68 |
DataOutResample(const Triangulation<patch_dim, spacedim> &patch_tria, |
| 69 |
const Mapping<patch_dim, spacedim> &patch_mapping); |
| 70 |
|
| 71 |
/** |
| 72 |
* Update the @p mapping of original triangulation. One needs to call this |
| 73 |
* function if the mapping has changed. Just like in the DataOut context, |
| 74 |
* @p n_subdivisions determines how many "patches" this function will build |
| 75 |
* out of every cell. |
| 76 |
* |
| 77 |
* This function involves an expensive setup: evaluation points are generated |
| 78 |
* and their owners are determined, which is used to set up the communication |
| 79 |
* pattern. |
| 80 |
* |
| 81 |
* @note If you use the version of build_patches() that does not take a |
| 82 |
* mapping, this function has to be called before its first usage. |
| 83 |
*/ |
| 84 |
void |
| 85 |
update_mapping(const Mapping<dim, spacedim> &mapping, |
| 86 |
const unsigned int n_subdivisions = 0); |
| 87 |
|
| 88 |
/** |
| 89 |
* This is the central function of this class since it builds the list of |
| 90 |
* patches to be written by the low-level functions of the base class. A |
| 91 |
* patch is, in essence, some intermediate representation of the data on |
| 92 |
* each cell of a triangulation and DoFHandler object that can then be used |
| 93 |
* to write files in some format that is readable by visualization programs. |
| 94 |
* |
| 95 |
* Since this function calls internally at the beginning update_mapping(), |
| 96 |
* this function also involves an expensive setup. |
| 97 |
* |
| 98 |
* Just like in the DataOut::build_patches() context, @p n_subdivisions |
| 99 |
* determines how many "patches" this function will build out of every cell. |
| 100 |
*/ |
| 101 |
void |
| 102 |
build_patches( |
| 103 |
const Mapping<dim, spacedim> &mapping, |
| 104 |
const unsigned int n_subdivisions = 0, |
| 105 |
const typename DataOut<patch_dim, spacedim>::CurvedCellRegion |
| 106 |
curved_region = |
| 107 |
DataOut<patch_dim, spacedim>::CurvedCellRegion::curved_boundary); |
| 108 |
|
| 109 |
/** |
| 110 |
* Just like the above function, this function builds a list of |
| 111 |
* patches to be written by the low-level functions of the base class. |
| 112 |
* However it skips the update of the mapping and reuses the one registered |
| 113 |
* via update_mapping(). This allows to skip the expensive setup of the |
| 114 |
* internal communication routines. |
| 115 |
* |
| 116 |
* @note This function can be only used if a mapping has been registered via |
| 117 |
* update_mapping() or the other build_patches() function. The same |
| 118 |
* n_subdivisions previously passed to these functions is used. |
| 119 |
*/ |
| 120 |
void |
| 121 |
build_patches( |
| 122 |
const typename DataOut<patch_dim, spacedim>::CurvedCellRegion |
| 123 |
curved_region = |
| 124 |
DataOut<patch_dim, spacedim>::CurvedCellRegion::curved_boundary); |
| 125 |
|
| 126 |
protected: |
| 127 |
virtual const std::vector<typename DataOutBase::Patch<patch_dim, spacedim>> & |
| 128 |
get_patches() const override; |
| 129 |
|
| 130 |
private: |
| 131 |
/** |
| 132 |
* Intermediate DoFHandler |
| 133 |
*/ |
| 134 |
DoFHandler<patch_dim, spacedim> patch_dof_handler; |
| 135 |
|
| 136 |
/** |
| 137 |
* Mapping used in connection with patch_tria. |
| 138 |
*/ |
| 139 |
const ObserverPointer<const Mapping<patch_dim, spacedim>> patch_mapping; |
| 140 |
|
| 141 |
/** |
| 142 |
* DataOut object that does the actual building of the patches. |
| 143 |
*/ |
| 144 |
DataOut<patch_dim, spacedim> patch_data_out; |
| 145 |
|
| 146 |
/** |
| 147 |
* Object to evaluate |
| 148 |
*/ |
| 149 |
Utilities::MPI::RemotePointEvaluation<dim, spacedim> rpe; |
| 150 |
|
| 151 |
/** |
| 152 |
* Partitioner to create internally distributed vectors. |
| 153 |
*/ |
| 154 |
std::shared_ptr<Utilities::MPI::Partitioner> partitioner; |
| 155 |
|
| 156 |
/** |
| 157 |
* Process local indices to access efficiently internal distributed vectors. |
| 158 |
*/ |
| 159 |
std::vector<types::global_dof_index> point_to_local_vector_indices; |
| 160 |
|
| 161 |
/** |
| 162 |
* Mapping of the original triangulation provided in update_mapping(). |
| 163 |
*/ |
| 164 |
ObserverPointer<const Mapping<dim, spacedim>> mapping; |
| 165 |
}; |
| 166 |
|
| 167 |
DEAL_II_NAMESPACE_CLOSE |
| 168 |
|
| 169 |
#endif |