ExaDG
Loading...
Searching...
No Matches
tensor_utilities.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_UTILITIES_TENSOR_UTILITIES_H_
23#define INCLUDE_EXADG_UTILITIES_TENSOR_UTILITIES_H_
24
25// C/C++
26#include <memory>
27
28// deal.II
29#include <deal.II/base/tensor.h>
30#include <deal.II/lac/vector.h>
31
32namespace ExaDG
33{
37template<int n_components1, int n_components2, typename Number>
38inline void
40 dealii::Vector<Number> & dst,
41 std::vector<dealii::Tensor<n_components1, n_components2, Number>> const & values,
42 unsigned int const comp1,
43 unsigned int const comp2)
44{
45 AssertIndexRange(comp1, n_components1);
46 AssertIndexRange(comp2, n_components2);
47
48 auto iter = dst.begin();
49 for(auto const & val : values)
50 {
51 *iter = val[comp1][comp2];
52 ++iter;
53 }
54}
55
59template<int n_components, typename Number>
60inline void
61extract_component_from_tensors(dealii::Vector<Number> & dst,
62 std::vector<dealii::Tensor<1, n_components, Number>> const & values,
63 unsigned int const comp)
64{
65 AssertIndexRange(comp, n_components);
66
67 auto iter = dst.begin();
68 for(auto const & val : values)
69 {
70 *iter = val[comp];
71 ++iter;
72 }
73}
74
75template<int rank, int dim>
76constexpr unsigned int
77rank_to_n_components()
78{
79 return (rank == 0) ? 1 : ((rank == 1) ? dim : dealii::numbers::invalid_unsigned_int);
80}
81
82template<int n_components, int dim>
83constexpr unsigned int
84n_components_to_rank()
85{
86 return (n_components == 1) ? 0 :
87 ((n_components == dim) ? 1 : dealii::numbers::invalid_unsigned_int);
88}
89
90} // namespace ExaDG
91
92
93
94#endif /* INCLUDE_EXADG_UTILITIES_TENSOR_UTILITIES_H_ */
Definition driver.cpp:33
void extract_component_from_tensors(dealii::Vector< Number > &dst, std::vector< dealii::Tensor< n_components1, n_components2, Number > > const &values, unsigned int const comp1, unsigned int const comp2)
Definition tensor_utilities.h:39