ASPECT
compat.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2024 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef _aspect_compat_h
22 #define _aspect_compat_h
23 
24 #include <deal.II/base/config.h>
25 #include <deal.II/base/mpi.h>
26 
27 // C++11 related includes.
28 #include <functional>
29 #include <memory>
30 
32 
33 #if !DEAL_II_VERSION_GTE(9,7,0)
35 #endif
36 
39 
40 namespace aspect
41 {
42  namespace big_mpi
43  {
44 
45  using ::Utilities::MPI::broadcast;
46 
47  }
48 
49  // deal.II 9.6 introduced MGTransferMF as a replacement for
50  // MGTransferMatrixFree; deal.II 9.9 renamed it back.
51 #if DEAL_II_VERSION_GTE(9,9,0)
52  template <int dim, typename NumberType>
54 #else
55  template <int dim, typename NumberType>
56  using MGTransferType = ::MGTransferMF<dim, NumberType>;
57 #endif
58 
59  // Global-coarsening transfers share the same class as local smoothing
60  // from deal.II 9.7 onward; 9.6 still needs MGTransferGlobalCoarsening.
61 #if DEAL_II_VERSION_GTE(9,7,0)
62  template <int dim, typename NumberType>
64 #else
65  template <int dim, typename NumberType>
67 #endif
68 
69 
70 #if !DEAL_II_VERSION_GTE(9,7,0)
71 
77  template <typename T, typename P = void>
78  using ObserverPointer = ::SmartPointer<T, P>;
79 
84 #endif
85 
86 
87  using ::SphericalManifold;
88 
89 
90 
91 // deal.II version 9.7 introduces a new class VectorFunctionFromTensorFunctionObject
92 // that we would like to use also for earlier versions
93 #if !DEAL_II_VERSION_GTE(9,7,0)
94 
95  using namespace dealii;
96 
131  template <int dim, typename RangeNumberType = double>
133  : public Function<dim, RangeNumberType>
134  {
135  public:
154  &tensor_function_object,
155  const unsigned int selected_component = 0,
156  const unsigned int n_components = dim);
157 
162  virtual ~VectorFunctionFromTensorFunctionObject() override = default;
163 
167  virtual RangeNumberType
168  value(const Point<dim> &p, const unsigned int component = 0) const override;
169 
175  virtual void
176  vector_value(const Point<dim> &p,
177  Vector<RangeNumberType> &values) const override;
178 
186  virtual void
187  vector_value_list(
188  const std::vector<Point<dim>> &points,
189  std::vector<Vector<RangeNumberType>> &value_list) const override;
190 
191  private:
196  const std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>
197  tensor_function_object;
198 
205  const unsigned int selected_component;
206  };
207 
208 
209  template <int dim, typename RangeNumberType>
213  &tensor_function_object,
214  const unsigned int selected_component,
215  const unsigned int n_components)
216  : Function<dim, RangeNumberType>(n_components)
217  , tensor_function_object(tensor_function_object)
218  , selected_component(selected_component)
219  {
220  // Verify that the Tensor<1,dim,RangeNumberType> will fit in the given length
221  // selected_components and not hang over the end of the vector.
222  AssertIndexRange(selected_component + dim - 1, this->n_components);
223  }
224 
225 
226 
227  template <int dim, typename RangeNumberType>
228  inline RangeNumberType
230  const Point<dim> &p,
231  const unsigned int component) const
232  {
233  AssertIndexRange(component, this->n_components);
234 
235  // if the requested component is out of the range selected, then we can
236  // return early
237  if ((component < selected_component) ||
238  (component >= selected_component + dim))
239  return 0;
240 
241  // otherwise retrieve the values from the <tt>tensor_function</tt> to be
242  // placed at the <tt>selected_component</tt> to
243  // <tt>selected_component + dim - 1</tt> elements of the <tt>Vector</tt>
244  // values and pick the correct one
245  const Tensor<1, dim, RangeNumberType> tensor_value =
247 
248  return tensor_value[component - selected_component];
249  }
250 
251 
252  template <int dim, typename RangeNumberType>
253  inline void
255  const Point<dim> &p,
256  Vector<RangeNumberType> &values) const
257  {
258  Assert(values.size() == this->n_components,
259  ExcDimensionMismatch(values.size(), this->n_components));
260 
261  // Retrieve the values from the <tt>tensor_function</tt> to be placed at
262  // the <tt>selected_component</tt> to
263  // <tt>selected_component + dim - 1</tt> elements of the <tt>Vector</tt>
264  // values.
265  const Tensor<1, dim, RangeNumberType> tensor_value =
267 
268  // First we make all elements of values = 0
269  values = 0;
270 
271  // Second we adjust the desired components to take on the values in
272  // <tt>tensor_value</tt>.
273  for (unsigned int i = 0; i < dim; ++i)
274  values(i + selected_component) = tensor_value[i];
275  }
276 
277 
285  template <int dim, typename RangeNumberType>
286  void
288  const std::vector<Point<dim>> &points,
289  std::vector<Vector<RangeNumberType>> &value_list) const
290  {
291  Assert(value_list.size() == points.size(),
292  ExcDimensionMismatch(value_list.size(), points.size()));
293 
294  const unsigned int n_points = points.size();
295 
296  for (unsigned int p = 0; p < n_points; ++p)
298  points[p], value_list[p]);
299  }
300 
301 #endif
302 
303 // deal.II versions up to 9.6 had a bug for very thin shell geometries.
304 // This function contains a fixed version.
305 #if !DEAL_II_VERSION_GTE(9,7,0)
306 
307  template <int dim>
308  void
310  const Point<dim> &center,
311  const double inner_radius,
312  const double outer_radius);
313 #endif
314 
315  // deal.II 9.8 made ReferenceCell a template class, whereas older versions
316  // had it as a non-template class. This is a problem.
317  // Rather than litter our own code base with #ifdefs, we can just define the
318  // templated class variant here for older deal.II versions, and then we can
319  // use the same code in all versions.
320 #if !DEAL_II_VERSION_GTE(9,8,0)
321  template <int dim> using ReferenceCell = ::ReferenceCell;
322 #endif
323 
324 }
325 
326 #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:211
const std::function< Tensor< 1, dim, RangeNumberType >(const Point< dim > &)> tensor_function_object
::ReferenceCell ReferenceCell
Definition: compat.h:321
*  *  const Number outer_radius