ExaDG
Loading...
Searching...
No Matches
solution_field.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_POSTPROCESSOR_SOLUTION_FIELD_H_
23#define INCLUDE_EXADG_POSTPROCESSOR_SOLUTION_FIELD_H_
24
25#include <deal.II/dofs/dof_handler.h>
26#include <deal.II/lac/la_parallel_vector.h>
27
28namespace ExaDG
29{
30enum class SolutionFieldType
31{
32 scalar,
33 vector,
34 cellwise
35};
36
37template<int dim, typename Number>
38class SolutionField : public dealii::Subscriptor
39{
40public:
41 using VectorType = dealii::LinearAlgebra::distributed::Vector<Number>;
42
44 : initialize_vector([](VectorType &) {}),
45 recompute_solution_field([](VectorType &, VectorType const &) {}),
46 type(SolutionFieldType::scalar),
47 name("solution"),
48 dof_handler(nullptr),
49 is_available(false)
50 {
51 }
52
57 void
59 {
60 initialize_vector(solution_vector);
61 }
62
66 void
68 {
69 is_available = false;
70 }
71
72 void
73 evaluate(VectorType const & src)
74 {
75 if(not is_available)
76 {
77 recompute_solution_field(solution_vector, src);
78 is_available = true;
79 }
80 }
81
82 VectorType const &
83 get() const
84 {
85 AssertThrow(is_available,
86 dealii::ExcMessage("You are trying to access a Vector that is invalid."));
87
88 return solution_vector;
89 }
90
91 VectorType const &
92 evaluate_get(VectorType const & src)
93 {
94 evaluate(src);
95
96 return get();
97 }
98
99 std::string const &
100 get_name() const
101 {
102 return name;
103 }
104
105 dealii::DoFHandler<dim> const &
106 get_dof_handler() const
107 {
108 return *dof_handler;
109 }
110
111 SolutionFieldType
112 get_type() const
113 {
114 return type;
115 }
116
117 // TODO: these element variables should not be public but instead be passed to the reinit function
118 std::function<void(VectorType &)> initialize_vector;
119
120 std::function<void(VectorType &, VectorType const &)> recompute_solution_field;
121
122 SolutionFieldType type;
123
124 std::string name;
125
126 dealii::DoFHandler<dim> const * dof_handler;
127
128private:
129 bool is_available;
130 VectorType solution_vector;
131};
132
133} // namespace ExaDG
134
135#endif /* INCLUDE_EXADG_POSTPROCESSOR_SOLUTION_FIELD_H_ */
Definition solution_field.h:39
void reinit()
Definition solution_field.h:58
void invalidate()
Definition solution_field.h:67
Definition driver.cpp:33