1- /*
2- * Multi-level SDC controller.
3- */
4-
51#ifndef _PFASST_MLSDC_HPP_
62#define _PFASST_MLSDC_HPP_
73
8- #include < algorithm>
9- #include < iostream>
104#include < vector>
5+ using namespace std ;
116
127#include " controller.hpp"
13- #include " logging.hpp"
148
15- using namespace std ;
169
1710namespace pfasst
1811{
19-
2012 /* *
2113 * Multilevel SDC controller.
2214 */
@@ -33,21 +25,7 @@ namespace pfasst
3325 bool initial; // <! whether we're sweeping from a new initial condition
3426 bool converged; // <! whether we've converged
3527
36- void perform_sweeps (size_t level)
37- {
38- auto sweeper = this ->get_level (level);
39- CLOG (INFO, " Controller" ) << " on level " << level + 1 << " /" << this ->nlevels ();
40- for (size_t s = 0 ; s < this ->nsweeps [level]; s++) {
41- if (predict) {
42- sweeper->predict (initial & predict);
43- sweeper->post_predict ();
44- predict = false ;
45- } else {
46- sweeper->sweep ();
47- sweeper->post_sweep ();
48- }
49- }
50- }
28+ virtual void perform_sweeps (size_t level);
5129
5230 public:
5331 /* *
@@ -56,56 +34,15 @@ namespace pfasst
5634 * This assumes that the user has set initial conditions on the finest level.
5735 * Currently uses a fixed number of iterations per step.
5836 */
59- void run ()
60- {
61- for (; this ->get_time () < this ->get_end_time (); this ->advance_time ()) {
62- predict = true ;
63- initial = true ;
64- converged = false ;
65-
66- for (this ->set_iteration (0 );
67- this ->get_iteration () < this ->get_max_iterations () && !converged;
68- this ->advance_iteration ()) {
69- cycle_v (this ->finest ());
70- initial = false ;
71- }
72-
73- perform_sweeps (this ->finest ().level );
74-
75- for (auto l = this ->finest (); l >= this ->coarsest (); --l) {
76- l.current ()->post_step ();
77- }
78-
79- if (this ->get_time () + this ->get_time_step () < this ->get_end_time ()) {
80- this ->get_finest ()->advance ();
81- }
82- }
83- }
37+ virtual void setup () override ;
38+ virtual void set_nsweeps (vector<size_t > nsweeps);
39+ virtual void run ();
8440
8541 private:
8642 /* *
8743 * Cycle down: sweep on current (fine), restrict to coarse.
8844 */
89- LevelIter cycle_down (LevelIter l)
90- {
91- auto fine = l.current ();
92- auto crse = l.coarse ();
93- auto trns = l.transfer ();
94-
95- perform_sweeps (l.level );
96-
97- if (l == this ->finest () && fine->converged ()) {
98- converged = true ;
99- return l;
100- }
101-
102- CVLOG (1 , " Controller" ) << " Cycle down onto level " << l.level << " /" << this ->nlevels ();
103- trns->restrict (crse, fine, initial);
104- trns->fas (this ->get_time_step (), crse, fine);
105- crse->save ();
106-
107- return l - 1 ;
108- }
45+ virtual LevelIter cycle_down (LevelIter l);
10946
11047 /* *
11148 * Cycle up: interpolate coarse correction to fine, sweep on current (fine).
@@ -114,67 +51,20 @@ namespace pfasst
11451 * sweep.
11552 * In this case the only operation that is performed here is interpolation.
11653 */
117- LevelIter cycle_up (LevelIter l)
118- {
119- auto fine = l.current ();
120- auto crse = l.coarse ();
121- auto trns = l.transfer ();
122-
123- CVLOG (1 , " Controller" ) << " Cycle up onto level " << l.level + 1 << " /" << this ->nlevels ();
124- trns->interpolate (fine, crse);
125-
126- if (l < this ->finest ()) {
127- perform_sweeps (l.level );
128- }
129-
130- return l + 1 ;
131- }
54+ virtual LevelIter cycle_up (LevelIter l);
13255
13356 /* *
13457 * Cycle bottom: sweep on the current (coarsest) level.
13558 */
136- LevelIter cycle_bottom (LevelIter l)
137- {
138- perform_sweeps (l.level );
139- return l + 1 ;
140- }
59+ virtual LevelIter cycle_bottom (LevelIter l);
14160
14261 /* *
14362 * Perform an MLSDC V-cycle.
14463 */
145- LevelIter cycle_v (LevelIter l)
146- {
147- if (l.level == 0 ) {
148- l = cycle_bottom (l);
149- } else {
150- l = cycle_down (l);
151- if (converged) {
152- return l;
153- }
154- l = cycle_v (l);
155- l = cycle_up (l);
156- }
157- return l;
158- }
159-
160- public:
161- virtual void setup () override
162- {
163- nsweeps.resize (this ->nlevels ());
164- fill (nsweeps.begin (), nsweeps.end (), 1 );
165- for (auto leviter = this ->coarsest (); leviter <= this ->finest (); ++leviter) {
166- leviter.current ()->set_controller (this );
167- leviter.current ()->setup (leviter != this ->finest ());
168- }
169- }
170-
171- void set_nsweeps (vector<size_t > nsweeps)
172- {
173- this ->nsweeps = nsweeps;
174- }
175-
64+ virtual LevelIter cycle_v (LevelIter l);
17665 };
177-
17866} // ::pfasst
17967
68+ #include " mlsdc_impl.hpp"
69+
18070#endif
0 commit comments