ExaDG
Loading...
Searching...
No Matches
interpolate.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2024 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_FUNCTIONS_AND_BOUNDARY_CONDITIONS_INTERPOLATE_H_
23#define EXADG_FUNCTIONS_AND_BOUNDARY_CONDITIONS_INTERPOLATE_H_
24
25// deal.II
26#include <deal.II/numerics/vector_tools.h>
27
28// C/C++
29#include <type_traits>
30
31namespace ExaDG
32{
33namespace Utilities
34{
35template<int dim,
36 int spacedim,
37 typename Number,
38 template<typename>
39 typename VectorType,
40 typename FunctionNumber>
41void
42interpolate(dealii::DoFHandler<dim, spacedim> const & dof_handler,
43 dealii::Function<spacedim, FunctionNumber> const & function,
45{
46 if constexpr(std::is_same_v<Number, FunctionNumber>)
47 {
48 dealii::VectorTools::interpolate(dof_handler, function, vec);
49 }
50 else
51 {
53 vec_fn.reinit(vec);
54 dealii::VectorTools::interpolate(dof_handler, function, vec_fn);
55 vec.copy_locally_owned_data_from(vec_fn);
56 }
57}
58
59template<int dim, int spacedim, typename VectorType, typename FunctionNumber>
60void
61interpolate(dealii::DoFHandler<dim, spacedim> const & dof_handler,
62 dealii::Function<spacedim, FunctionNumber> & function,
63 VectorType & vec,
64 double const time)
65{
66 function.set_time(time);
67 interpolate(dof_handler, function, vec);
68}
69
70template<int dim,
71 int spacedim,
72 typename Number,
73 template<typename>
74 typename VectorType,
75 typename FunctionNumber>
76void
77interpolate(dealii::Mapping<dim, spacedim> const & mapping,
78 dealii::DoFHandler<dim, spacedim> const & dof_handler,
79 dealii::Function<spacedim, FunctionNumber> const & function,
81{
82 if constexpr(std::is_same_v<Number, FunctionNumber>)
83 {
84 dealii::VectorTools::interpolate(mapping, dof_handler, function, vec);
85 }
86 else
87 {
89 vec_fn.reinit(vec);
90 dealii::VectorTools::interpolate(mapping, dof_handler, function, vec_fn);
91 vec.copy_locally_owned_data_from(vec_fn);
92 }
93}
94
95template<int dim, int spacedim, typename VectorType, typename FunctionNumber>
96void
97interpolate(dealii::Mapping<dim, spacedim> const & mapping,
98 dealii::DoFHandler<dim, spacedim> const & dof_handler,
99 dealii::Function<spacedim, FunctionNumber> & function,
100 VectorType & vec,
101 double const time)
102{
103 function.set_time(time);
104 interpolate(mapping, dof_handler, function, vec);
105}
106
107} // namespace Utilities
108} // namespace ExaDG
109
110#endif /*EXADG_FUNCTIONS_AND_BOUNDARY_CONDITIONS_INTERPOLATE_H_ */
Definition interpolate.h:34
Definition driver.cpp:33