include/meltpooldg/time_integration/solution_history.hpp Source File

Developer Documentation: include/meltpooldg/time_integration/solution_history.hpp Source File
Developer Documentation
solution_history.hpp
Go to the documentation of this file.
1#pragma once
2
11#include <deal.II/base/exceptions.h>
12
13#include <functional>
14#include <memory>
15#include <vector>
16
18{
19 template <typename VectorType>
21 {
22 public:
23 SolutionHistory() = default;
24
25 explicit SolutionHistory(unsigned int size)
27 {}
28
29 void
30 resize(const unsigned int size)
31 {
32 solutions.clear();
33 solutions.resize(size);
34 }
35
36 void
37 apply(std::function<void(VectorType &)> f)
38 {
39 for (unsigned int i = 0; i < solutions.size(); ++i)
40 f(solutions[i]);
41 }
42
43 void
44 apply_old(std::function<void(VectorType &)> f)
45 {
46 Assert(solutions.size() > 1, dealii::ExcInternalError());
47
48 for (unsigned int i = 1; i < solutions.size(); ++i)
49 f(solutions[i]);
50 }
51
52
53 void
54 update_ghost_values(const bool check = false) const
55 {
56 for (unsigned int i = 0; i < solutions.size(); ++i)
57 if (not check or not solutions[i].has_ghost_elements())
58 solutions[i].update_ghost_values();
59 }
60
61 void
62 zero_out_ghost_values(const bool check = false) const
63 {
64 for (unsigned int i = 0; i < solutions.size(); ++i)
65 if (not check or solutions[i].has_ghost_elements())
66 solutions[i].zero_out_ghost_values();
67 }
68
69 void
71 {
72 //@note we don't use swap for now since in the HeatOperation
73 // solutions[0] is initialized with a different DoFHandler
74 // than solutions[1]
75 for (int i = solutions.size() - 1; i >= 1; --i)
76 solutions[i] = solutions[i - 1];
77 }
78
79 void
80 set_recent_old_solution(const VectorType &src)
81 {
82 Assert(solutions.size() > 1, dealii::ExcInternalError());
83
84 solutions[1] = src;
85 }
86
87 const VectorType &
89 {
90 Assert(solutions.size() >= 1, dealii::ExcInternalError());
91 return solutions[1];
92 }
93
94 VectorType &
96 {
97 Assert(solutions.size() >= 1, dealii::ExcInternalError());
98 return solutions[1];
99 }
100
101 const VectorType &
103 {
104 return solutions[0];
105 }
106
107 VectorType &
109 {
110 return solutions[0];
111 }
112
119 VectorType &
120 get_solution(unsigned int i)
121 {
122 return solutions[i];
123 }
124
125 const std::vector<std::shared_ptr<VectorType>> &
127 {
128 return std::vector<std::shared_ptr<VectorType>>(solutions.begin() + 1, solutions.end());
129 }
130
131 const std::vector<VectorType> &
133 {
134 return solutions;
135 }
136
137 unsigned int
138 size() const
139 {
140 return solutions.size();
141 }
142
143 private:
144 std::vector<VectorType> solutions;
145 };
146} // namespace MeltPoolDG::TimeIntegration
147
149// KEPT AS TEMPLATES
150//
151// using BlockVectorType = dealii::LinearAlgebra::distributed::BlockVector<number>;
152//
153// TODO
154// SolutionHistory(std::vector<std::shared_ptr<VectorType>> solutions)
155//: solutions(solutions)
156//{}
157// SolutionHistory<VectorType>
158// filter(const bool keep_current = true,
159// const bool keep_recent = true,
160// const bool keep_old = true) const
161//{
162// std::vector<std::shared_ptr<VectorType>> subset;
163
164// for (unsigned int i = 0; i < solutions.size(); ++i)
165// if (can_process(i, keep_current, keep_recent, keep_old))
166// subset.push_back(solutions[i]);
167
168// return SolutionHistory(subset);
169//}
170
171// TODO ?
172// virtual std::size_t
173// memory_consumption() const
174//{
175// return MyMemoryConsumption::memory_consumption(solutions);
176//}
177
178// void
179// extrapolate(VectorType &dst, const double factor) const
180//{
181// Assert(solutions.size() >= 1, ExcInternalError());
182
183// dst = solutions[0];
184// dst.add(-1.0, solutions[1]);
185// dst.sadd(factor, solutions[0]);
186//}
187// bool
188// can_process(const unsigned int index,
189// const bool keep_current,
190// const bool keep_recent,
191// const bool keep_old) const
192//{
193// return (index == 0 and keep_current) or (index == 1 and keep_recent) or (index > 1 and keep_old);
194//}
195
196
197// void
198// apply_blockwise(std::function<void(BlockVectorType &)> f) const
199//{
200// for (unsigned int i = 0; i < solutions.size(); ++i)
201// for (unsigned int b = 0; b < solutions[i]->n_blocks(); ++b)
202// f(solutions[i]->block(b));
203//}
204
205// unsigned int
206// n_blocks_total() const
207//{
208// unsigned int n_blocks = 0;
209// for (const auto &sol : solutions)
210// n_blocks += sol->n_blocks();
211
212// return n_blocks;
213//}
214// void
215// flatten(VectorType &dst) const
216//{
217// unsigned int b_dst = 0;
218
219// for (unsigned int i = 0; i < solutions.size(); ++i)
220// for (unsigned int b = 0; b < solutions[i]->n_blocks(); ++b)
221//{
222// dst.block(b_dst).copy_locally_owned_data_from(solutions[i]->block(b));
223//++b_dst;
224//}
225//}
226
227// std::vector<BlockVectorType *>
228// get_all_blocks() const
229//{
230// std::vector<BlockVectorType *> solution_ptr;
231
232// for (unsigned int i = 0; i < solutions.size(); ++i)
233// for (unsigned int b = 0; b < solutions[i]->n_blocks(); ++b)
234// solution_ptr.push_back(&solutions[i]->block(b));
235
236// return solution_ptr;
237//}
Definition solution_history.hpp:21
void apply_old(std::function< void(VectorType &)> f)
Definition solution_history.hpp:44
const VectorType & get_recent_old_solution() const
Definition solution_history.hpp:88
void resize(const unsigned int size)
Definition solution_history.hpp:30
void apply(std::function< void(VectorType &)> f)
Definition solution_history.hpp:37
VectorType & get_solution(unsigned int i)
Definition solution_history.hpp:120
void zero_out_ghost_values(const bool check=false) const
Definition solution_history.hpp:62
VectorType & get_recent_old_solution()
Definition solution_history.hpp:95
const std::vector< std::shared_ptr< VectorType > > & get_old_solutions() const
Definition solution_history.hpp:126
const VectorType & get_current_solution() const
Definition solution_history.hpp:102
unsigned int size() const
Definition solution_history.hpp:138
void set_recent_old_solution(const VectorType &src)
Definition solution_history.hpp:80
VectorType & get_current_solution()
Definition solution_history.hpp:108
const std::vector< VectorType > & get_all_solutions() const
Definition solution_history.hpp:132
std::vector< VectorType > solutions
Definition solution_history.hpp:144
void commit_old_solutions()
Definition solution_history.hpp:70
SolutionHistory(unsigned int size)
Definition solution_history.hpp:25
void update_ghost_values(const bool check=false) const
Definition solution_history.hpp:54
Class providing different low storage explicit Runge-Kutta schemes. The schemes implemented in this c...
Definition bdf_time_integration.hpp:18