Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
time_integrator_subject.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2020: G-CSC, Goethe University Frankfurt
3 * Author: Tim Schön
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__TIME_INTEGRATOR_SUBJECT
34#define __H__UG__LIB_DISC__TIME_DISC__TIME_INTEGRATOR_SUBJECT
35
37
38namespace ug {
39
41
50template<class TDomain, class TAlgebra>
52{
53public:
56 typedef ITimeIntegratorStageObserver_init<TDomain, TAlgebra> init_observer_type;
57 typedef ITimeIntegratorStageObserver_rewind<TDomain, TAlgebra> rewind_observer_type;
58 typedef ITimeIntegratorStageObserver_finalize<TDomain, TAlgebra> finalize_observer_type;
59 typedef ITimeIntegratorStageObserver_preprocess<TDomain, TAlgebra> preprocess_observer_type;
60 typedef ITimeIntegratorStageObserver_postprocess<TDomain, TAlgebra> postprocess_observer_type;
61 typedef ITimeIntegratorStageObserver_start<TDomain, TAlgebra> start_observer_type;
62 typedef ITimeIntegratorStageObserver_end<TDomain, TAlgebra> end_observer_type;
63 typedef typename std::vector<SmartPtr<process_observer_type> > process_observer_container_type;
64
74
75protected:
76 // process_observer_container_type m_vProcessObservers;
78
79 // container for statically mapped observers
80 std::vector<SmartPtr<init_observer_type> > m_vInitObservers;
81 std::vector<SmartPtr<rewind_observer_type> > m_vRewindObservers;
82 std::vector<SmartPtr<finalize_observer_type> > m_vFinalizeObservers;
83 std::vector<SmartPtr<preprocess_observer_type> > m_vPreprocessObservers;
84 std::vector<SmartPtr<postprocess_observer_type> > m_vPostprocessObservers;
85 std::vector<SmartPtr<start_observer_type> > m_vStartObservers;
86 std::vector<SmartPtr<end_observer_type> > m_vEndObservers;
87
88
89protected:
91 template<int tGroup>
93 {
94 //UG_LOG("TimeIntegratorSubject::attach_observer[" << tGroup <<"]" << this << std::endl);
95 m_vProcessObservers[tGroup].push_back(obs);
96 }
97
100 {
101 //UG_LOG("TimeIntegratorSubject::attach_observer[" << tGroup <<"]" << this << std::endl);
102 m_vProcessObservers[tGroup].push_back(obs);
103 }
104public:
105
106#define DECLARE_CHECK_STATIC_ATTACH(stage, container) \
107 bool check_attach_##stage(SmartPtr<process_observer_type> obs)\
108 {\
109 SmartPtr<stage##_observer_type> sp_staticObs = obs.template cast_dynamic<stage##_observer_type>();\
110 if (sp_staticObs.valid())\
111 {\
112 (container).push_back(sp_staticObs);\
113 return true;\
114 }\
115 return false;\
116 }
117
125
126
129 {
130 const bool isStaticallyAttached =
131 check_attach_init(obs) ||
132 check_attach_rewind(obs) ||
133 check_attach_finalize(obs) ||
134 check_attach_preprocess(obs) ||
135 check_attach_postprocess(obs) ||
136 check_attach_start(obs) ||
137 check_attach_end(obs);
138
139 if (!isStaticallyAttached)
141 }
142
144 { attach_to_group<TIO_GROUP_INIT_STEP>(obs); }
145
147 { attach_to_group<TIO_GROUP_REWIND_STEP>(obs); }
148
150 { attach_to_group<TIO_GROUP_FINALIZE_STEP>(obs); }
151
153 { attach_to_group<TIO_GROUP_PREPROCESS_STEP>(obs); }
154
156 { attach_to_group<TIO_GROUP_POSTPROCESS_STEP>(obs); }
157
159 { attach_to_group<TIO_GROUP_START>(obs); }
160
162 { attach_to_group<TIO_GROUP_END>(obs); }
163
182
183protected:
185 template<int tGroup>
187 {
189
190 bool result = true;
191 for (typename process_observer_container_type::iterator it = observers.begin(); it!= observers.end(); ++it)
192 {
193 result = (*it)->step_process(u, step, time, dt) && result;
194 }
195
196 return result;
197 }
198
199
200public:
201
202#define DECLARE_NOTIFY_STEP(functionName, stageName, stageID, container) \
203 bool notify_##functionName(SmartPtr<grid_function_type> u, int step, number time, number dt)\
204 {\
205 bool res = notify_group<(stageID)>(u, step, time, dt);\
206 const size_t numObs = (container).size();\
207 for (size_t o = 0; o < numObs; ++o)\
208 res &= (container)[o]->stageName##_action(u, step, time, dt);\
209 return res;\
210 }
211
214
215
217
218
220
221
223
224
226
227
229
230
232};
233
234}
235
236#endif
Definition smart_pointer.h:108
represents numerical solutions on a grid using an algebraic vector
Definition grid_function.h:121
Abstract base class for time integration observer.
Definition time_integrator_observer_interface.h:43
Base class for a subject notifying observers attachment.
Definition time_integrator_subject.hpp:52
ITimeIntegratorStageObserver_finalize< TDomain, TAlgebra > finalize_observer_type
Definition time_integrator_subject.hpp:58
void reset_observers()
Definition time_integrator_subject.hpp:164
ITimeIntegratorObserver< TDomain, TAlgebra > process_observer_type
Definition time_integrator_subject.hpp:55
std::vector< SmartPtr< finalize_observer_type > > m_vFinalizeObservers
Definition time_integrator_subject.hpp:82
void attach_init_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:143
ITimeIntegratorStageObserver_rewind< TDomain, TAlgebra > rewind_observer_type
Definition time_integrator_subject.hpp:57
void attach_postprocess_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:155
observer_group_type
Definition time_integrator_subject.hpp:65
@ TIO_GROUP_REWIND_STEP
Definition time_integrator_subject.hpp:67
@ TIO_GROUP_SIZE
Definition time_integrator_subject.hpp:73
@ TIO_GROUP_END
Definition time_integrator_subject.hpp:72
@ TIO_GROUP_POSTPROCESS_STEP
Definition time_integrator_subject.hpp:70
@ TIO_GROUP_PREPROCESS_STEP
Definition time_integrator_subject.hpp:69
@ TIO_GROUP_FINALIZE_STEP
Definition time_integrator_subject.hpp:68
@ TIO_GROUP_START
Definition time_integrator_subject.hpp:71
@ TIO_GROUP_INIT_STEP
Definition time_integrator_subject.hpp:66
std::vector< SmartPtr< end_observer_type > > m_vEndObservers
Definition time_integrator_subject.hpp:86
ITimeIntegratorStageObserver_preprocess< TDomain, TAlgebra > preprocess_observer_type
Definition time_integrator_subject.hpp:59
void attach_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:128
std::vector< SmartPtr< init_observer_type > > m_vInitObservers
Definition time_integrator_subject.hpp:80
process_observer_container_type m_vProcessObservers[TIO_GROUP_SIZE]
Definition time_integrator_subject.hpp:77
ITimeIntegratorStageObserver_init< TDomain, TAlgebra > init_observer_type
Definition time_integrator_subject.hpp:56
std::vector< SmartPtr< preprocess_observer_type > > m_vPreprocessObservers
Definition time_integrator_subject.hpp:83
ITimeIntegratorStageObserver_start< TDomain, TAlgebra > start_observer_type
Definition time_integrator_subject.hpp:61
void attach_rewind_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:146
ITimeIntegratorStageObserver_postprocess< TDomain, TAlgebra > postprocess_observer_type
Definition time_integrator_subject.hpp:60
bool notify_group(SmartPtr< grid_function_type > u, int step, number time, number dt)
Notify all observers for a certain group.
Definition time_integrator_subject.hpp:186
std::vector< SmartPtr< start_observer_type > > m_vStartObservers
Definition time_integrator_subject.hpp:85
GridFunction< TDomain, TAlgebra > grid_function_type
Definition time_integrator_subject.hpp:54
ITimeIntegratorStageObserver_end< TDomain, TAlgebra > end_observer_type
Definition time_integrator_subject.hpp:62
void attach_to_group(SmartPtr< process_observer_type > obs)
register observer (default: postprocess)
Definition time_integrator_subject.hpp:92
void attach_end_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:161
std::vector< SmartPtr< process_observer_type > > process_observer_container_type
Definition time_integrator_subject.hpp:63
void attach_finalize_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:149
void attach_start_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:158
std::vector< SmartPtr< postprocess_observer_type > > m_vPostprocessObservers
Definition time_integrator_subject.hpp:84
void attach_preprocess_observer(SmartPtr< process_observer_type > obs)
Definition time_integrator_subject.hpp:152
void attach_to_group(int tGroup, SmartPtr< process_observer_type > obs)
register observer (default: postprocess)
Definition time_integrator_subject.hpp:99
std::vector< SmartPtr< rewind_observer_type > > m_vRewindObservers
Definition time_integrator_subject.hpp:81
virtual void init()
double number
Definition types.h:124
the ug namespace
#define DECLARE_CHECK_STATIC_ATTACH(stage, container)
Definition time_integrator_subject.hpp:106
#define DECLARE_NOTIFY_STEP(functionName, stageName, stageID, container)
Definition time_integrator_subject.hpp:202