ExaDG
Loading...
Searching...
No Matches
interpolate.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 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 INCLUDE_EXADG_TIME_INTEGRATION_INTERPOLATE_H_
23#define INCLUDE_EXADG_TIME_INTEGRATION_INTERPOLATE_H_
24
25namespace ExaDG
26{
27/*
28 * time t
29 * --------> t_{n-2} t_{n-1} t_{n} t t_{n+1}
30 * _______________|_________|________|_____|______|___________\
31 * | | | | | /
32 * sol[2] sol[1] sol[0] dst
33 */
34template<typename VectorType>
35void
36interpolate(VectorType & dst,
37 double const & time,
38 std::vector<VectorType const *> const & solutions,
39 std::vector<double> const & times)
40{
41 dst = 0;
42
43 // loop over all interpolation points
44 for(unsigned int k = 0; k < solutions.size(); ++k)
45 {
46 // evaluate Lagrange polynomial l_k
47 double l_k = 1.0;
48
49 for(unsigned int j = 0; j < solutions.size(); ++j)
50 {
51 if(j != k)
52 {
53 l_k *= (time - times[j]) / (times[k] - times[j]);
54 }
55 }
56
57 dst.add(l_k, *solutions[k]);
58 }
59}
60
61} // namespace ExaDG
62
63#endif /* INCLUDE_EXADG_TIME_INTEGRATION_INTERPOLATE_H_ */
Definition driver.cpp:33