ASPECT
compat.h
Go to the documentation of this file.
1 // ------------------------------------------------------
2 //
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 //
5 // SPDX-FileCopyrightText: Copyright (C) 2015-2026 by the ASPECT authors.
6 //
7 // This file is part of ASPECT.
8 //
9 // Detailed license information governing the source code and
10 // contributions can be found in the folder LICENSES and in
11 // LICENSE and CONTRIBUTING.md at the top level directory.
12 //
13 // ------------------------------------------------------
14 
15 #ifndef _aspect_compat_h
16 #define _aspect_compat_h
17 
18 #include <deal.II/base/config.h>
19 #include <deal.II/base/mpi.h>
20 
21 // C++11 related includes.
22 #include <functional>
23 #include <memory>
24 
26 
27 #if !DEAL_II_VERSION_GTE(9,7,0)
29 #endif
30 
33 
34 namespace aspect
35 {
36  namespace big_mpi
37  {
38 
39  using ::Utilities::MPI::broadcast;
40 
41  }
42 
43  // deal.II 9.6 introduced MGTransferMF as a replacement for
44  // MGTransferMatrixFree; deal.II 9.9 renamed it back.
45 #if DEAL_II_VERSION_GTE(9,9,0)
46  template <int dim, typename NumberType>
48 #else
49  template <int dim, typename NumberType>
50  using MGTransferType = ::MGTransferMF<dim, NumberType>;
51 #endif
52 
53  // Global-coarsening transfers share the same class as local smoothing
54  // from deal.II 9.7 onward; 9.6 still needs MGTransferGlobalCoarsening.
55 #if DEAL_II_VERSION_GTE(9,7,0)
56  template <int dim, typename NumberType>
58 #else
59  template <int dim, typename NumberType>
61 #endif
62 
63 
64 #if !DEAL_II_VERSION_GTE(9,7,0)
65 
71  template <typename T, typename P = void>
72  using ObserverPointer = ::SmartPointer<T, P>;
73 
78 #endif
79 
80 
81  using ::SphericalManifold;
82 
83 
84 
85 // deal.II version 9.7 introduces a new class VectorFunctionFromTensorFunctionObject
86 // that we would like to use also for earlier versions
87 #if !DEAL_II_VERSION_GTE(9,7,0)
88 
89  using namespace dealii;
90 
125  template <int dim, typename RangeNumberType = double>
127  : public Function<dim, RangeNumberType>
128  {
129  public:
148  &tensor_function_object,
149  const unsigned int selected_component = 0,
150  const unsigned int n_components = dim);
151 
156  virtual ~VectorFunctionFromTensorFunctionObject() override = default;
157 
161  virtual RangeNumberType
162  value(const Point<dim> &p, const unsigned int component = 0) const override;
163 
169  virtual void
170  vector_value(const Point<dim> &p,
171  Vector<RangeNumberType> &values) const override;
172 
180  virtual void
181  vector_value_list(
182  const std::vector<Point<dim>> &points,
183  std::vector<Vector<RangeNumberType>> &value_list) const override;
184 
185  private:
190  const std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>
191  tensor_function_object;
192 
199  const unsigned int selected_component;
200  };
201 
202 
203  template <int dim, typename RangeNumberType>
207  &tensor_function_object,
208  const unsigned int selected_component,
209  const unsigned int n_components)
210  : Function<dim, RangeNumberType>(n_components)
211  , tensor_function_object(tensor_function_object)
212  , selected_component(selected_component)
213  {
214  // Verify that the Tensor<1,dim,RangeNumberType> will fit in the given length
215  // selected_components and not hang over the end of the vector.
216  AssertIndexRange(selected_component + dim - 1, this->n_components);
217  }
218 
219 
220 
221  template <int dim, typename RangeNumberType>
222  inline RangeNumberType
224  const Point<dim> &p,
225  const unsigned int component) const
226  {
227  AssertIndexRange(component, this->n_components);
228 
229  // if the requested component is out of the range selected, then we can
230  // return early
231  if ((component < selected_component) ||
232  (component >= selected_component + dim))
233  return 0;
234 
235  // otherwise retrieve the values from the <tt>tensor_function</tt> to be
236  // placed at the <tt>selected_component</tt> to
237  // <tt>selected_component + dim - 1</tt> elements of the <tt>Vector</tt>
238  // values and pick the correct one
239  const Tensor<1, dim, RangeNumberType> tensor_value =
241 
242  return tensor_value[component - selected_component];
243  }
244 
245 
246  template <int dim, typename RangeNumberType>
247  inline void
249  const Point<dim> &p,
250  Vector<RangeNumberType> &values) const
251  {
252  Assert(values.size() == this->n_components,
253  ExcDimensionMismatch(values.size(), this->n_components));
254 
255  // Retrieve the values from the <tt>tensor_function</tt> to be placed at
256  // the <tt>selected_component</tt> to
257  // <tt>selected_component + dim - 1</tt> elements of the <tt>Vector</tt>
258  // values.
259  const Tensor<1, dim, RangeNumberType> tensor_value =
261 
262  // First we make all elements of values = 0
263  values = 0;
264 
265  // Second we adjust the desired components to take on the values in
266  // <tt>tensor_value</tt>.
267  for (unsigned int i = 0; i < dim; ++i)
268  values(i + selected_component) = tensor_value[i];
269  }
270 
271 
279  template <int dim, typename RangeNumberType>
280  void
282  const std::vector<Point<dim>> &points,
283  std::vector<Vector<RangeNumberType>> &value_list) const
284  {
285  Assert(value_list.size() == points.size(),
286  ExcDimensionMismatch(value_list.size(), points.size()));
287 
288  const unsigned int n_points = points.size();
289 
290  for (unsigned int p = 0; p < n_points; ++p)
292  points[p], value_list[p]);
293  }
294 
295 #endif
296 
297 // deal.II versions up to 9.6 had a bug for very thin shell geometries.
298 // This function contains a fixed version.
299 #if !DEAL_II_VERSION_GTE(9,7,0)
300 
301  template <int dim>
302  void
304  const Point<dim> &center,
305  const double inner_radius,
306  const double outer_radius);
307 #endif
308 
309  // deal.II 9.8 made ReferenceCell a template class, whereas older versions
310  // had it as a non-template class. This is a problem.
311  // Rather than litter our own code base with #ifdefs, we can just define the
312  // templated class variant here for older deal.II versions, and then we can
313  // use the same code in all versions.
314 #if !DEAL_II_VERSION_GTE(9,8,0)
315  template <int dim> using ReferenceCell = ::ReferenceCell;
316 #endif
317 
318 }
319 
320 #endif
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define AssertIndexRange(index, range)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &value_list) const override
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual size_type size() const override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
#define Assert(cond, exc)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
void colorize_quarter_hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius)
VectorFunctionFromTensorFunctionObject(const std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> &tensor_function_object, const unsigned int selected_component=0, const unsigned int n_components=dim)
Definition: compat.h:205
const std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> tensor_function_object
::ReferenceCell ReferenceCell
Definition: compat.h:315
*  *  const Number outer_radius