Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
solution_time_series.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__LIB_DISC__TIME_DISC__PREVIOUS_SOLUTION__
34#define __H__UG__LIB_DISC__TIME_DISC__PREVIOUS_SOLUTION__
35
36// extern libraries
37#include <deque>
38
39// other ug libraries
40#include "common/common.h"
41
43
44namespace ug{
45
48
50
57template <typename TVector>
59{
60 public:
62 typedef TVector vector_type;
63
64 public:
65 virtual ~VectorTimeSeries() {}
66
69 {
72
73 for(int i = m_vTimeSol.size()-1; i >= 0 ; --i)
74 cloneTimeSol->push(solution(i)->clone(), time(i));
75
76 return cloneTimeSol;
77 }
78
80 void clear() {m_vTimeSol.clear();}
81
83 size_t size() const {return m_vTimeSol.size();}
84
86 number time(size_t i) const {return m_vTimeSol.at(i).time();}
87
89 SmartPtr<vector_type> solution(size_t i) {return m_vTimeSol.at(i).solution();}
90
92 ConstSmartPtr<vector_type> solution(size_t i) const {return m_vTimeSol.at(i).solution();}
93
95 SmartPtr<vector_type> oldest() {return m_vTimeSol.back().solution();}
96
98 ConstSmartPtr<vector_type> oldest() const {return m_vTimeSol.back().solution();}
99
101 number oldest_time() const {return m_vTimeSol.back().time();}
102
104 SmartPtr<vector_type> latest() {return m_vTimeSol.front().solution();}
105
107 ConstSmartPtr<vector_type> latest() const {return m_vTimeSol.front().solution();}
108
110 number latest_time() const {return m_vTimeSol.front().time();}
111
114
117 {
118 SmartPtr<vector_type> discardVec = m_vTimeSol.back().solution();
119 remove_oldest(); push(vec, time);
120 return discardVec;
121 }
122
124 void remove_latest() {m_vTimeSol.pop_front();}
125
127 void remove_oldest() {m_vTimeSol.pop_back();}
128
129 protected:
132 {
133 public:
134 TimeSol() : vec(NULL), t(0.0) {}
135
137 : vec(vec_), t(t_) {}
138
141
144
146 number& time() {return t;}
147
149 const number& time() const {return t;}
150
151 protected:
152 // solution vector at time point
154
155 // point in time
157 };
158
159 protected:
160
161 // deque of previous solutions
162 std::deque<TimeSol> m_vTimeSol;
163};
164
167{
168 public:
171
173 size_t size() const {return m_vLocalVector.size();}
174
176 number time(size_t i) const {return m_vTime.at(i);}
177
179 const std::vector<number>& times() const {return m_vTime;}
180
182 const LocalVector& solution(size_t i) const {return m_vLocalVector.at(i);}
183
185 LocalVector& solution(size_t i) {return m_vLocalVector.at(i);}
186
189 {
190 for(size_t t=0; t < size(); ++t)
191 solution(t).access_by_map(funcMap);
192 }
193
195 template <typename TVector>
197 {
198 m_vLocalVector.resize(vecTimeSeries->size());
199 for(size_t i = 0; i < m_vLocalVector.size(); ++i)
200 {
201 m_vLocalVector[i].resize(ind);
202 GetLocalVector(m_vLocalVector[i], *vecTimeSeries->solution(i));
203 }
204 }
205
207 template <typename TVector>
209 {
210 m_vTime.resize(vecTimeSeries->size());
211 for(size_t i = 0; i < m_vTime.size(); ++i)
212 m_vTime[i] = vecTimeSeries->time(i);
213 }
214
215 protected:
217 std::vector<number> m_vTime;
218
220 std::vector<LocalVector> m_vLocalVector;
221};
222
224
225} // end namespace ug
226
227#endif /* __H__UG__LIB_DISC__TIME_DISC__PREVIOUS_SOLUTION__ */
Definition smart_pointer.h:296
Definition smart_pointer.h:108
describes a mapping between two local index sets
Definition function_group.h:186
Definition local_algebra.h:50
Definition local_algebra.h:198
void access_by_map(const FunctionIndexMapping &funcMap)
access only part of the functions using mapping (restrict functions)
Definition local_algebra.h:306
time series of local vectors
Definition solution_time_series.h:167
void read_values(ConstSmartPtr< VectorTimeSeries< TVector > > vecTimeSeries, LocalIndices &ind)
extract local values from global vectors
Definition solution_time_series.h:196
const std::vector< number > & times() const
returns time points
Definition solution_time_series.h:179
void read_times(ConstSmartPtr< VectorTimeSeries< TVector > > vecTimeSeries)
extract time points
Definition solution_time_series.h:208
number time(size_t i) const
returns time point i
Definition solution_time_series.h:176
LocalVectorTimeSeries()
constructor
Definition solution_time_series.h:170
size_t size() const
returns number of time points
Definition solution_time_series.h:173
std::vector< number > m_vTime
time series
Definition solution_time_series.h:217
std::vector< LocalVector > m_vLocalVector
vector of local vectors (one for each time point)
Definition solution_time_series.h:220
void access_by_map(const FunctionIndexMapping &funcMap)
access dofs by map
Definition solution_time_series.h:188
const LocalVector & solution(size_t i) const
returns the local vector for the i'th time point
Definition solution_time_series.h:182
LocalVector & solution(size_t i)
returns the local vector for the i'th time point
Definition solution_time_series.h:185
grouping of solution and time point
Definition solution_time_series.h:132
TimeSol(SmartPtr< vector_type > vec_, number t_)
Definition solution_time_series.h:136
const number & time() const
const access time
Definition solution_time_series.h:149
number & time()
access time
Definition solution_time_series.h:146
SmartPtr< vector_type > vec
Definition solution_time_series.h:153
ConstSmartPtr< vector_type > solution() const
const access solution
Definition solution_time_series.h:143
SmartPtr< vector_type > solution()
access solution
Definition solution_time_series.h:140
number t
Definition solution_time_series.h:156
TimeSol()
Definition solution_time_series.h:134
time series of solutions and corresponding time point
Definition solution_time_series.h:59
size_t size() const
returns number of time steps handled
Definition solution_time_series.h:83
SmartPtr< VectorTimeSeries< vector_type > > clone() const
clones the object (deep-copy) including values
Definition solution_time_series.h:68
SmartPtr< vector_type > push_discard_oldest(SmartPtr< vector_type > vec, number time)
adds new time point, oldest solution is discarded and returned
Definition solution_time_series.h:116
number oldest_time() const
time associated with oldest solution
Definition solution_time_series.h:101
number latest_time() const
time associated with latest solution
Definition solution_time_series.h:110
SmartPtr< vector_type > latest()
returns latest solution
Definition solution_time_series.h:104
virtual ~VectorTimeSeries()
Definition solution_time_series.h:65
TVector vector_type
vector type of solutions
Definition solution_time_series.h:62
SmartPtr< vector_type > oldest()
returns oldest solution
Definition solution_time_series.h:95
number time(size_t i) const
returns point in time for solution
Definition solution_time_series.h:86
ConstSmartPtr< vector_type > oldest() const
const access to oldest solution
Definition solution_time_series.h:98
void clear()
clears the content of the member m_vTimeSol
Definition solution_time_series.h:80
ConstSmartPtr< vector_type > latest() const
const access to latest solution
Definition solution_time_series.h:107
void push(SmartPtr< vector_type > vec, number time)
adds new time point, not discarding the oldest
Definition solution_time_series.h:113
void remove_oldest()
removes oldest time point
Definition solution_time_series.h:127
SmartPtr< vector_type > solution(size_t i)
returns solution
Definition solution_time_series.h:89
void remove_latest()
removes latest time point
Definition solution_time_series.h:124
ConstSmartPtr< vector_type > solution(size_t i) const
returns solution
Definition solution_time_series.h:92
std::deque< TimeSol > m_vTimeSol
Definition solution_time_series.h:162
double number
Definition types.h:124
the ug namespace
void GetLocalVector(LocalVector &lvec, const TVector &vec)
Definition local_algebra.h:739