FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
afc_limiter.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#include <kernel/global/matrix.hpp>
9#include <kernel/global/filter.hpp>
10#include <kernel/lafem/unit_filter.hpp>
11#include <kernel/solver/iterative.hpp>
12#include <kernel/solver/base.hpp>
13#include <kernel/solver/bicgstab.hpp>
14#include <kernel/solver/fgmres.hpp>
15#include <kernel/solver/schwarz_precond.hpp>
16#include <kernel/solver/ilu_precond.hpp>
17#include <kernel/solver/jacobi_precond.hpp>
18#include <kernel/solver/ssor_precond.hpp>
19
20#include <memory>
21
22namespace FEAT
23{
24 namespace Control
25 {
26 namespace Intern
27 {
28 template<typename MatrixType_>
30 {
31 static constexpr bool is_global = false;
32 typedef MatrixType_ LocalMatrixType;
35 };
36
37 template<typename LocalMatrixType_, typename RowMirror_, typename ColMirror_>
38 struct MatrixTypeHelper<Global::Matrix<LocalMatrixType_, RowMirror_, ColMirror_>>
39 {
40 static constexpr bool is_global = true;
41 typedef LocalMatrixType_ LocalMatrixType;
44 typedef RowMirror_ RowMirror;
45 typedef ColMirror_ ColMirror;
46 };
47 }
48
65 template<typename MatrixType_>
67 {
68 public:
69 typedef MatrixType_ MatrixType;
70 typedef typename MatrixType::VectorTypeR VectorType;
71 typedef typename MatrixType::DataType DataType;
72 typedef typename MatrixType::IndexType IndexType;
73 static constexpr bool is_global = Intern::MatrixTypeHelper<MatrixType_>::is_global;
74 typedef typename Intern::MatrixTypeHelper<MatrixType_>::LocalMatrixType LocalMatrixType;
75 typedef typename LocalMatrixType::VectorTypeR LocalVectorType;
76
79
80 protected:
81 // our internal (to be filtered) matrices
82 MatrixType _matrix_mass, _matrix_conv, _matrix_stiff, _matrix_react;
83 // Helper matrices
84 MatrixType _matrix_art_diff;
85 MatrixType _matrix_hlp;
86 MatrixType _matrix_hlp_t; // MCL
87 // L = M_L + theta * dt * (K - D + L + N + B_(L)) (Matrices evaluated at n + 1)
88 MatrixType _matrix_left; // FCT impl, MCL impl
89 // R = M_L - (1 - theta) * dt * (K - D + L + N + B_(L)) (Matrices evaluated at n)
90 MatrixType _matrix_right;
91 LocalMatrixType _matrix_schwarz;
92
93 //our solver for the implicit diffusion part
94 std::shared_ptr<Solver::IterativeSolver<VectorType>> _solver;
95
96 // helper vectors
97 VectorType _vec_mass_lump;
98 VectorType _vec_mass_lump_inverse;
99 // weak boundary conditions
100 VectorType _vec_bc;
101
102 // strong boundary conditions
103 FilterType _filter;
104 LocalFilterType _loc_filter;
105
106 // known size? -> std::array<VectorType, k>, anyway reserve enough space beforehand
107 std::vector<VectorType> _vec_hlp;
108
109 // which type of theta scheme do we want
110 DataType _theta = 0;
111 // stepsize for the time stepping
112 DataType _stepsize = DataType(-1);
113 // which limiter do we want? 1: FCT, 2: MCL
114 int _limiter = 1;
115 // how do we want the boundary conditions to be applied? 1: weak, 2: strong, 3: both
116 int _bc_config = 0;
117 // config for solver:
118 int _lin_solver = 1;
119 int _precond = 1;
120
121 // we need those for synchronising the limiter
124 std::shared_ptr<Global::SynchMatrix<LocalMatrixType, typename Intern::MatrixTypeHelper<MatrixType_>::RowMirror>> _synch_matrix_ticket;
125 LocalMatrixType _matrix_freq;
126
127 bool _matrix_mass_set = false;
128 bool _matrix_conv_set = false;
129 bool _matrix_stiff_set = false;
130 bool _matrix_react_set = false;
131 bool _init_symbolic_called = false;
132 bool _init_stepsize_called = false;
133 bool _init_time_stepping_called = false;
134 // should the diffusion (i.e. stiffnes matrix) also be limited?
135 bool _limit_matrix_stiff = false;
136
137 // stopwatches for time measuring
138 StopWatch watch_solve, watch_init;
139
140 // we need those to iterate over our matrices all the time
141 IndexType _num_rows;
142
143 void _set_loc_filter()
144 {
145 if constexpr(is_global)
146 {
147 _loc_filter = _filter.local().clone(LAFEM::CloneMode::Shallow);
148 }
149 else
150 {
151 _loc_filter = _filter.clone(LAFEM::CloneMode::Shallow);
152 }
153 }
154
155 void _set_glob_filter()
156 {
157 if constexpr(is_global)
158 {
159 _filter.local() = _loc_filter.clone(LAFEM::CloneMode::Shallow);
160 }
161 else
162 {
163 _filter = _loc_filter.clone(LAFEM::CloneMode::Shallow);
164 }
165 }
166
167 public:
168 // Rule of 5
169 AFCTransportSolver() = default;
170 AFCTransportSolver(const AFCTransportSolver&) = delete;
171 AFCTransportSolver& operator=(const AFCTransportSolver&) = delete;
173 AFCTransportSolver& operator=(AFCTransportSolver&&) = default;
174 ~AFCTransportSolver() = default;
175
176 LocalFilterType& get_filter()
177 {
178 return _loc_filter;
179 }
180
181 const LocalFilterType& get_filter() const
182 {
183 return _loc_filter;
184 }
185
186 void set_filter(const LocalFilterType& filter)
187 {
188 _loc_filter = filter.clone(LAFEM::CloneMode::Shallow);
189 _set_glob_filter();
190 _bc_config = 2;
191 }
192
200 void set_weak_bc(const VectorType& vec)
201 {
202 XASSERTM(_init_symbolic_called, "Need to call init_symbolic() first");
203 _vec_bc.copy(vec);
204 _bc_config = 1;
205 }
206
210 MatrixType& get_mass_matrix()
211 {
212 _matrix_mass_set = true;
213 return _matrix_mass;
214 }
215
219 MatrixType& get_conv_matrix()
220 {
221 _matrix_conv_set = true;
222 return _matrix_conv;
223 }
224
228 MatrixType& get_stiff_matrix()
229 {
230 _matrix_stiff_set = true;
231 return _matrix_stiff;
232 }
233
237 MatrixType& get_react_matrix()
238 {
239 _matrix_react_set = true;
240 return _matrix_react;
241 }
242
257 void limit_stiff_matrix(bool limit)
258 {
259 _limit_matrix_stiff = limit;
260 }
261
273 {
274 XASSERTM(_init_symbolic_called, "Need to call init_symbolic() first");
275 XASSERTM(_matrix_stiff_set, "stiffnes matrix not set");
276 auto mat_l_plus = _matrix_stiff.local().clone(LAFEM::CloneMode::Weak);
277 mat_l_plus.format();
278 auto mat_stiff_t = _matrix_stiff.local().transpose();
279
280 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
281 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
282 const Memory::TypedView<DataType> val_stiff = _matrix_stiff.local().val_view_r();
283 const Memory::TypedView<DataType> val_stiff_t = mat_stiff_t.val_view_r();
284 Memory::TypedView<DataType> val_plus = mat_l_plus.val_view_rw();
285 for(IndexType row = 0; row < _num_rows; ++row)
286 {
287 const IndexType start = row_ptr_view[row];
288 const IndexType end = row_ptr_view[row + 1];
289
290 IndexType diag = end;
291 DataType lump = DataType(0);
292
293 for(IndexType k = start; k < end; ++k)
294 {
295 if(col_idx_view[k] == row)
296 diag = k;
297 else
298 {
299 auto val = Math::max(DataType(0), Math::max(val_stiff[k], val_stiff_t[k]));
300 val_plus[k] += val;
301 lump += val;
302 }
303 }
304 val_plus[diag] += -lump;
305 }
306 // 0 to 1 to 0???!!!
307 _matrix_stiff.local().axpy(mat_l_plus, -1);
308 }
309
317 void set_theta(DataType theta)
318 {
319 XASSERTM(!_init_symbolic_called, "theta can only be set before init_symbolic or after done_symbolic has been called");
320 XASSERTM((theta >= 0) && (theta <= 1), "theta must be in the intervall [0, 1]");
321 _theta = theta;
322 }
323
330 void set_limiter(int limiter)
331 {
332 XASSERTM(!_init_symbolic_called, "Limiter can only be set before init_symbolic or after done_symbolic has been called");
333 XASSERTM((limiter == 1) || (limiter == 2), "Limiter must be 1 or 2");
334 _limiter = limiter;
335 }
336
343 void set_lin_solver(IndexType solver)
344 {
345 XASSERTM(!_init_symbolic_called, "Linear solver can only be set before init_symbolic or after done_symbolic has been called");
346 XASSERTM((solver == 1) || (solver == 2), "solver must be 1 or2");
347 _lin_solver = solver;
348 }
349
357 void set_precond(IndexType precond)
358 {
359 XASSERTM(!_init_symbolic_called, "Preconditioner can only be set before init_symbolic or after done_symbolic has been called");
360 XASSERTM((precond == 1) || (precond == 2) || (precond == 3), "Preconditioner must be 1, 2 or 3");
361 _precond = precond;
362 }
363
372 void init()
373 {
374 this->init_symbolic();
375 this->init_numeric();
376 }
377
387 {
388 XASSERTM(_matrix_mass_set && _matrix_conv_set, "Massmatrix and convection matrix must be set!");
389 watch_init.start();
390
391 // symbolic init, structure of matrices must not be changend after this
392
393 // matrix structures for internal matrices
394 _matrix_hlp = _matrix_mass.clone(LAFEM::CloneMode::Layout);
395 _matrix_right = _matrix_mass.clone(LAFEM::CloneMode::Layout);
396 _matrix_art_diff = _matrix_mass.clone(LAFEM::CloneMode::Layout);
397
398 // only need matrix_left for implicit time stepping
399 if(_theta > 0)
400 _matrix_left = _matrix_mass.clone(LAFEM::CloneMode::Layout);
401
402 // need those all the time to iterate over matrixes
403 _num_rows = _matrix_mass.local().num_rows();
404
405 // we need one to clone our help vectors from
406 _vec_mass_lump = _matrix_mass.create_vector_l();
407 //now we also need way more help vectors, 5 for explicit MCL, 8 for FCT and 7 for implicit MCL
408 for(int i(0); i < 8; ++i) // everyone need at least 4 vecs
409 _vec_hlp.push_back(_vec_mass_lump.clone(LAFEM::CloneMode::Layout));
410 // also initialize vec_bc and set it to zero in case its not set by user
411 _vec_bc = _vec_mass_lump.clone(LAFEM::CloneMode::Layout);
412 _vec_bc.format();
413
414 // the stuff for synchronising
415 _row_gate = _matrix_mass.get_row_gate();
416 _col_gate = _matrix_mass.get_col_gate();
417
418 _synch_matrix_ticket = std::make_shared<Global::SynchMatrix<LocalMatrixType, typename Intern::MatrixTypeHelper<MatrixType_>::RowMirror>>(
419 *_row_gate->_comm, _row_gate->_ranks, _row_gate->_mirrors, _col_gate->_mirrors);
420
421 // matrix for 1 to 0 conversion of matrices
422 _matrix_freq = _matrix_mass.local().clone(LAFEM::CloneMode::Layout);
423 _matrix_freq.format(DataType(1.0));
424
425 // sync it to know which matrix entry lives on how many patches
426 _synch_matrix_ticket->init(_matrix_freq);
427 _synch_matrix_ticket->exec(_matrix_freq);
428
429 // solver for implicit time stepping
430 if(_theta > 0)
431 {
432 _matrix_schwarz = _matrix_left.convert_to_1();
433
434 _setup_lin_solver();
435
436 _solver->set_plot_mode(Solver::PlotMode::none);
437 _solver->set_tol_abs(1e-6);
438 _solver->init_symbolic();
439 }
440
441 watch_init.stop();
442
443 _init_symbolic_called = true;
444 }
445
455 DataType cfl_cond()
456 {
457 if(_theta == 1)
458 return 0;
459 VectorType& vec_cfl = _vec_hlp.at(1);
460 _get_cfl_vec(vec_cfl);
461 // first we have to sync it (since its made from the type-0 matrices)
462 // vec_cfl.sync_0(); // or we don't, since we call all operations on global matrices
463
464 // vec_mass_lump needs to be synced here!!!
465 vec_cfl.component_product(vec_cfl, _vec_mass_lump);
466
467 return vec_cfl.min_abs_element();
468 }
469
481 DataType init_stepsize()
482 {
483 XASSERTM(_init_symbolic_called, "Need to call init_symbolic() first");
484 watch_init.start();
485
486 // all this stuff is unnecessary for those matrices that didn't change after the last init_stepsize call...
487 _matrix_sync_0_1_0(_matrix_mass);
488 _matrix_sync_0_1_0(_matrix_conv);
489 if(_matrix_stiff_set)
490 _matrix_sync_0_1_0(_matrix_stiff);
491 if(_matrix_react_set)
492 _matrix_sync_0_1_0(_matrix_react);
493
494 _vec_mass_lump = _matrix_mass.lump_rows();
496 _matrix_sync_0_1_0(_matrix_art_diff);
497
498 DataType cfl = cfl_cond();
499
500 _init_stepsize_called = true;
501 watch_init.stop();
502
503 return cfl;
504 }
505
517 void init_time_stepping(DataType stepsize)
518 {
519 XASSERTM(_init_stepsize_called, "Need to call init_stepsize() first");
520 XASSERTM(stepsize > 0, "stepsize has to be greater than zero! If using implicit euler as time stepping scheme (theta = 1), you need to specify a stepsize yourself!");
521
522 watch_init.start();
523
524 _stepsize = stepsize;
525
526 // assemble matrix_right fpr calculation of right hand side for low order solution
527 // we start with R = K - D + L + N
528 _matrix_right.local().copy(_matrix_conv.local());
529 _matrix_right.local().axpy(_matrix_art_diff.local(), DataType(-1.0));
530 if(_matrix_stiff_set)
531 {
532 // if(_bc_config == 2)
533 // {
534 // _filter.local().filter_mat(_matrix_stiff.local());
535
536 // auto& vec_dof_fltr = _filter.local().get_filter_vector();
537 // auto* idx_fltr = vec_dof_fltr.indices();
538
539 // DataType* val_stiff = _matrix_stiff.local().val();
540 // for(Index i = 0; i < vec_dof_fltr.used_elements(); ++i)
541 // {
542 // const IndexType row = idx_fltr[i];
543 // for(IndexType j(_row_ptr[row]); j < _row_ptr[row + 1]; ++j)
544 // val_stiff[j] = DataType(0);
545 // }
546 // }
547
548 _matrix_right.local().axpy(_matrix_stiff.local());
549 }
550 if(_matrix_react_set)
551 {
552 // _filter.local().filter_mat(_matrix_react.local());
553 _matrix_right.local().axpy(_matrix_react.local());
554 }
555
556 // then we scale according to our time scheme and limiter
557 DataType scale_right = (_theta - DataType(1.0)) * (_limiter == 1 ? _stepsize : 1);
558 if(_theta > 0)
559 _matrix_left.local().scale(_matrix_right.local(), _stepsize * _theta);
560 _matrix_right.local().scale(_matrix_right.local(), scale_right);
561
562 if(_limiter == 1)
563 {
564 // we need to add the lmped mass matrix onto the other matrices,
565 // therefore we need the vector to be type 0
566 auto vec_mass_lump_type_0 = _matrix_mass.lump_rows(false);
567 const Memory::TypedView<DataType> lump_vec_view(vec_mass_lump_type_0.local().elements_view_r());
568 const Memory::TypedView<IndexType> row_ptr_view(_matrix_right.local().row_ptr_view_r());
569 const Memory::TypedView<IndexType> col_idx_view(_matrix_right.local().col_idx_view_r());
570 Memory::TypedView<DataType> val_right = _matrix_right.local().val_view_rw();
571 Memory::TypedView<DataType> val_left = _matrix_left.local().val_view_rw();
572 for(IndexType i = 0; i < _num_rows; ++i)
573 {
574 for(IndexType j = row_ptr_view[i]; j < row_ptr_view[i+1]; ++j)
575 {
576 if(col_idx_view[j] == i)
577 {
578 val_right[j] += lump_vec_view(i);
579 if(_theta > 0)
580 val_left[j] += lump_vec_view(i);
581 }
582 }
583 }
584 }
585
586 // _filter.local().filter_mat(_matrix_right.local());
587
588 if(_theta > 0)
589 {
590 _matrix_schwarz = _matrix_left.convert_to_1();
591 _solver->init_numeric();
592 }
593 else
594 {
595 // if theta = 0, we solve with the lumped mass matrix (which is diagonal)
596 _vec_mass_lump_inverse = _vec_mass_lump.clone(LAFEM::CloneMode::Layout);
597 _vec_mass_lump_inverse.component_invert(_vec_mass_lump);
598 }
599
600 _init_time_stepping_called = true;
601 watch_init.stop();
602 }
603
618 DataType init_numeric()
619 {
620 _stepsize = init_stepsize();
621 init_time_stepping(_stepsize);
622 return _stepsize;
623 }
624
628 void done()
629 {
630 this->done_numeric();
631 this->done_symbolic();
632 }
633
638 {
639 XASSERTM(_init_symbolic_called, "Need to call init_symbolic() first");
640 _matrix_hlp.local().clear();
641 _matrix_right.local().clear();
642 _matrix_art_diff.local().clear();
643 if(_theta > 0)
644 _matrix_left.local().clear();
645
646 _vec_mass_lump.clear();
647 _vec_bc.clear();
648 for(auto& vec : _vec_hlp)
649 vec.clear();
650 _vec_hlp.clear();
651
652 _matrix_freq.clear();
653
654 if(_theta > 0)
655 _solver->done_symbolic();
656
657 _init_symbolic_called = false;
658 _init_stepsize_called = false;
659 _init_time_stepping_called = false;
660 }
661
666 {
667 }
668
672 Solver::Status apply(VectorType& vec_sol, const VectorType& vec_rhs)
673 {
674 XASSERTM(_init_time_stepping_called, "Need to call init_numeric() or init_time_stepping() first");
675
676 watch_solve.start();
677
678 if(_limiter == 1)
679 limit_fct(vec_sol, vec_rhs);
680 else if(_limiter == 2)
681 limit_mcl_explicit(vec_sol, vec_rhs);
682
683 watch_solve.stop();
684
686 }
687
691 Solver::Status apply_heun(VectorType& vec_sol, const VectorType& vec_rhs1, const VectorType& vec_rhs2)
692 {
693 XASSERTM(_theta == 0, "Only use heun when theta = 0 (because Heun makes two explicit Euler steps)");
694 watch_solve.start();
695 auto vec_hlp = vec_sol.clone();
696 watch_solve.stop();
697
698 // Heun step:
699 this->apply(vec_sol, vec_rhs1);
700 this->apply(vec_sol, vec_rhs2);
701
702 watch_solve.start();
703 vec_sol.axpy(vec_hlp);
704 vec_sol.scale(vec_sol, 0.5);
705 watch_solve.stop();
706
708 }
709
716 {
717 _row_gate->_comm->print("Time initializing solver: " + watch_init.elapsed_string());
718 _row_gate->_comm->print("Time solving: " + watch_solve.elapsed_string());
719 }
720
726 void limit_fct(VectorType& vec_sol, const VectorType& vec_rhs)
727 {
728 if(_bc_config == 2)
729 _filter.filter_sol(vec_sol);
730 // solve for low order solution
731 VectorType& vec_rhs_low = _vec_hlp.at(2);
732 // if(_bc_config == 2)
733 // _filter.filter_rhs(vec_rhs_low);
734 _matrix_right.apply(vec_rhs_low, vec_sol);
735 if(_bc_config == 1)
736 vec_rhs_low.axpy(_vec_bc, _stepsize);
737 vec_rhs_low.axpy(vec_rhs, _stepsize);
738
739 VectorType& vec_sol_low = _vec_hlp.at(3);
740 vec_sol_low.format();
741 if(_theta == 0)
742 vec_sol_low.component_product(vec_rhs_low, _vec_mass_lump_inverse);
743 else
744 {
745 if(_bc_config == 2)
746 {
747 _filter.filter_rhs(vec_rhs_low);
748 _filter.filter_sol(vec_sol_low);
749 }
750 Solver::Status solving = Solver::solve(*_solver, vec_sol_low, vec_rhs_low, _matrix_left, _filter);
751
752 if (solving != Solver::Status::success)
753 {
754 std::cerr << std::endl
755 << "ERROR: solving was not successful" << std::endl;
757 }
758 }
759
760 // local bounds for each node
761 VectorType& vec_min = _vec_hlp.at(4);
762 VectorType& vec_max = _vec_hlp.at(5);
763 _calc_local_bounds_fct(vec_min.local(), vec_max.local(), vec_sol_low.local());
764 // which need a special synchronisation, where we don't add the values up, but look for the min/max of the bordering patches
765 _synch_vector_max(vec_min.local(), *_row_gate->_comm, _row_gate->_ranks, _col_gate->_mirrors);
766 _synch_vector_max(vec_max.local(), *_row_gate->_comm, _row_gate->_ranks, _col_gate->_mirrors);
767
768 //for the sum of the negative/positive fluxes that go into each node
769 VectorType& vec_neg_flux = _vec_hlp.at(6);
770 VectorType& vec_pos_flux = _vec_hlp.at(7);
771 // calculates above mentioned variables, matrix_hlp has the unlimited fluxes
772 _calc_antidiffusive_flux_fct(_matrix_hlp.local(), vec_neg_flux.local(), vec_pos_flux.local(), vec_sol.local(), vec_sol_low.local());
773 // the sum of the fluxes has to be synchronised
774 vec_neg_flux.sync_0();
775 vec_pos_flux.sync_0();
776
777 // limits the antidiffusive fluxes and return vector, that has to be added to low order solution
778 VectorType& vec_lim_flux = _vec_hlp.at(2);
779 _calc_lim_flux_fct(vec_lim_flux.local(), vec_min.local(), vec_max.local(), vec_neg_flux.local(), vec_pos_flux.local(), _matrix_hlp.local(), _vec_mass_lump.local());
780 // the limited flux has to be synced as well
781 vec_lim_flux.sync_0();
782
783 //update solution with limited flux
784 vec_sol.copy(vec_lim_flux);
785 vec_sol.axpy(vec_sol_low);
786 }
787
793 void limit_mcl_explicit(VectorType& vec_sol, const VectorType& vec_rhs)
794 {
795 VectorType& vec_lim_flux = _vec_hlp.at(4);
796 _calc_lim_flux_mcl(vec_lim_flux, vec_sol);
797
798 VectorType& vec_hlp = _vec_hlp.at(1);
799 // add fluxes to rhs of ode form
800 vec_hlp.copy(_vec_hlp.at(0));
801 vec_hlp.axpy(vec_lim_flux);// in vec_hlp[0] ist rhs_low = R*u gespeichert
802 // also add rhs
803 vec_hlp.axpy(vec_rhs);
804 // solve ode by multipling with inverse lumped mass matrix
805 vec_hlp.component_product(vec_hlp, _vec_mass_lump_inverse);
806 // scaling with time step
807 vec_hlp.scale(vec_hlp, _stepsize);
808 // and finally add to solution of the old time step (i.e. the explicit euler step)
809 vec_sol.axpy(vec_hlp);
810 }
811
812 protected:
813 // syncs the matrix from 0 to 1 to 0
814 void _matrix_sync_0_1_0(MatrixType& mat)
815 {
816 auto& mat_local = mat.local();
817 _synch_matrix_ticket->exec(mat_local);
818 const Memory::TypedView<DataType> vfreq = _matrix_freq.val_view_r();
819 Memory::TypedView<DataType> val = mat_local.val_view_rw();
820 for(Index i = 0; i < mat_local.num_nzes(); ++i)
821 val[i] /= vfreq[i];
822 }
823
824 void _setup_lin_solver()
825 {
826 // we need a preconditioner
827 std::shared_ptr<Solver::SolverBase<LocalVectorType>> precond;
828 if(_precond == 1)
829 precond = Solver::new_ilu_precond(PreferredBackend::generic, _matrix_schwarz, _filter.local());
830 else if(_precond == 2)
831 precond = Solver::new_jacobi_precond(_matrix_schwarz, _filter.local());
832 else if(_precond == 3)
833 precond = Solver::new_ssor_precond(PreferredBackend::generic, _matrix_schwarz, _filter.local());
834 else
835 XABORTM("No valid preconditioner chosen");
836
837 // and the schwarz stuff
838 auto schwarz = Solver::new_schwarz_precond(precond, _filter);
839
840 // to make our solver
841 if(_lin_solver == 1)
842 _solver = Solver::new_bicgstab(_matrix_left, _filter, schwarz);
843 else if(_lin_solver == 2)
844 _solver = Solver::new_fgmres(_matrix_left, _filter, 20, 0, schwarz);
845 else
846 XABORTM("No valid linear solver chosen");
847 }
848
855 {
856 _matrix_art_diff.local().format();
857
858 _matrix_right.local().copy(_matrix_conv.local());
859 if(_limit_matrix_stiff)
860 {
861 XASSERTM(_matrix_stiff_set, "Stiffness matrix needs to be set to limit it");
862 _matrix_right.local().axpy(_matrix_stiff.local());
863 }
864 _matrix_hlp.local().transpose(_matrix_right.local());
865
866 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
867 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
868 const Memory::TypedView<DataType> val = _matrix_right.local().val_view_r();
869 const Memory::TypedView<DataType> val_t = _matrix_hlp.local().val_view_r();
870 Memory::TypedView<DataType> val_art_diff = _matrix_art_diff.local().val_view_rw();
871
872 for(IndexType row = 0; row < _num_rows; ++row)
873 {
874 const IndexType start = row_ptr_view[row];
875 const IndexType end = row_ptr_view[row + 1];
876
877 IndexType diag = end;
878 DataType lump = DataType(0);
879
880 for(IndexType k = start; k < end; ++k)
881 {
882 if(col_idx_view[k] == row)
883 diag = k;
884 else
885 {
886 const DataType max_val_val_t = Math::max(Math::abs(val[k]), Math::abs(val_t[k]));
887 lump += (val_art_diff[k] = Math::max(DataType(0), max_val_val_t));
888 }
889 }
890
891 val_art_diff[diag] = -lump;
892 }
893 }
894
895 // calculates the vector 1/(1 - theta) * 1/(e_ii + l_ii + k_ii - d_ii), needed for the cfl condition (e is react mat, l is stiffnes mat, k is conv mat, d is art diff mat)
896 void _get_cfl_vec(VectorType& vec_cfl)
897 {
898 // was passiert bei theta = 1?
899 VectorType& vec_hlp = _vec_hlp.at(0);
900
901 // returns synched diagonal entries
902 _matrix_conv.extract_diag(vec_cfl);
903 if(_matrix_stiff_set)
904 {
905 _matrix_stiff.extract_diag(vec_hlp);
906 vec_cfl.axpy(vec_hlp);
907 }
908 if(_matrix_react_set)
909 {
910 _matrix_react.extract_diag(vec_hlp);
911 vec_cfl.axpy(vec_hlp);
912 }
913 _matrix_art_diff.extract_diag(vec_hlp);
914 vec_cfl.axpy(vec_hlp, DataType(-1.0));
915
916 vec_cfl.component_invert(vec_cfl, DataType(1.0/(1.0 - _theta)));
917 }
918
919 // ------------------- everything FCT -------------------
920 // u_i^min = max_j(0, -(u_i^L - u_j^L)); u_i^max = max_j(0, (u_i^L - u_j^L))
921 void _calc_local_bounds_fct(LocalVectorType& vec_u_min, LocalVectorType& vec_u_max, LocalVectorType& vec_sol_low)
922 {
923 XASSERT(vec_sol_low.size() == vec_u_min.size());
924 XASSERT(vec_sol_low.size() == vec_u_max.size());
925
926 vec_u_min.format(); //prob not necessary?
927 vec_u_max.format();
928
929 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
930 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
931 const Memory::TypedView<DataType> vec_sol_low_ptr = vec_sol_low.elements_view_r();
932 Memory::TypedView<DataType> vec_u_min_ptr = vec_u_min.elements_view_w();
933 Memory::TypedView<DataType> vec_u_max_ptr = vec_u_max.elements_view_w();
934
935 for(IndexType row = 0; row < _num_rows; ++row)
936 {
937 const IndexType start = row_ptr_view[row];
938 const IndexType end = row_ptr_view[row + 1];
939 DataType mi = Math::max(0.0, -(vec_sol_low_ptr[row] - vec_sol_low_ptr[col_idx_view[start]]));
940 DataType ma = Math::max(0.0, (vec_sol_low_ptr[row] - vec_sol_low_ptr[col_idx_view[start]]));
941 for (IndexType i = start + 1; i < end; ++i)
942 {
943 mi = Math::max(mi, Math::max(0.0, -(vec_sol_low_ptr[row] - vec_sol_low_ptr[col_idx_view[i]])));
944 ma = Math::max(ma, Math::max(0.0, (vec_sol_low_ptr[row] - vec_sol_low_ptr[col_idx_view[i]])));
945 }
946 vec_u_min_ptr[row] = mi;
947 vec_u_max_ptr[row] = ma;
948 }
949 }
950
951 void _calc_antidiffusive_flux_fct(LocalMatrixType& matrix_flux, LocalVectorType& vec_neg_flux,
952 LocalVectorType& vec_pos_flux, LocalVectorType& vec_sol_corr, LocalVectorType& vec_sol_low)
953 {
954 // calc derivatve
955 LocalVectorType& vec_deriv = _vec_hlp.at(0).local();
956 vec_deriv.copy(vec_sol_low);
957 vec_deriv.axpy(vec_sol_corr, -1.0);
958 vec_deriv.scale(vec_deriv, 1.0/_stepsize);
959
960 matrix_flux.format();
961 vec_neg_flux.format();
962 vec_pos_flux.format();
963
964
965 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
966 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
967 const Memory::TypedView<DataType> val_mass = _matrix_mass.local().val_view_r();
968 const Memory::TypedView<DataType> val_art_diff = _matrix_art_diff.local().val_view_r();
969 const Memory::TypedView<DataType> val_deriv = vec_deriv.elements_view_r();
970 const Memory::TypedView<DataType> val_sol_corr = vec_sol_corr.elements_view_r();
971 const Memory::TypedView<DataType> val_sol_low = vec_sol_low.elements_view_r();
972 Memory::TypedView<DataType> val_neg_flux = vec_neg_flux.elements_view_rw();
973 Memory::TypedView<DataType> val_pos_flux = vec_pos_flux.elements_view_rw();
974 Memory::TypedView<DataType> val_flux = matrix_flux.val_view_r();
975
976 for(IndexType i = 0; i < _num_rows; ++i)
977 {
978 const IndexType start = row_ptr_view[i];
979 const IndexType end = row_ptr_view[i+1];
980
981 for(IndexType m = start; m < end; ++m)
982 {
983 const IndexType j = col_idx_view[m];
984
985 // flux is calculated as in Christophs matlab code
986 const DataType flux = _stepsize * val_mass[m] * (val_deriv(j) - val_deriv(i))
987 - _stepsize * _theta * val_art_diff[m] * (val_sol_low(i) - val_sol_low(j))
988 - _stepsize * (1.0 - _theta) * val_art_diff[m] * (val_sol_corr(i) - val_sol_corr(j));
989
990 // prelimiting step
991 if(flux * (val_sol_low(i) - val_sol_low(j)) > 0)
992 val_flux[m] = 0;
993 else
994 val_flux[m] = flux;
995
996 // sum of negative (sum_i!=j max(0, -f_ij)) and positive (sum_i!=j max(0, f_ij)) flux into one node
997 if(j != i)
998 {
999 val_neg_flux[i] += Math::max(0.0, -val_flux[m]);
1000 val_pos_flux[i] += Math::max(0.0, val_flux[m]);
1001 }
1002 }
1003 }
1004 }
1005
1006 // returns the limited fluxes of the fct-scheme, that have to be added to the low order solution
1007 void _calc_lim_flux_fct(LocalVectorType& vec_lim_flux, LocalVectorType& vec_min, LocalVectorType& vec_max,
1008 LocalVectorType& vec_neg_flux, LocalVectorType& vec_pos_flux, LocalMatrixType& matrix_flux, LocalVectorType& vec_mass_lump)
1009 {
1010 LocalVectorType& vec_bnd_neg = _vec_hlp.at(0).local();
1011 vec_bnd_neg.format();
1012 LocalVectorType& vec_bnd_pos = _vec_hlp.at(1).local();
1013 vec_bnd_pos.format();
1014
1015 const Memory::TypedView<DataType> val_mass_lump = vec_mass_lump.elements_view_r();
1016 const Memory::TypedView<DataType> val_min = vec_min.elements_view_r();
1017 const Memory::TypedView<DataType> val_max = vec_max.elements_view_r();
1018 const Memory::TypedView<DataType> val_pos_flux = vec_pos_flux.elements_view_r();
1019 const Memory::TypedView<DataType> val_neg_flux = vec_neg_flux.elements_view_r();
1020
1021 Memory::TypedView<DataType> vbn = vec_bnd_neg.elements_view_rw();
1022 Memory::TypedView<DataType> vbp = vec_bnd_pos.elements_view_rw();
1023
1024 for(IndexType row = 0; row < _num_rows; ++row)
1025 {
1026 // distance from low order solution to local min/max, looks like this because of definition of local min/max
1027 DataType Q_p = val_mass_lump(row) * val_max(row);
1028 DataType Q_m = val_mass_lump(row) * val_min(row);
1029
1030 // bounds for correction factors
1031 vbp[row] = Math::min(1.0, Q_p/val_pos_flux(row));
1032 vbn[row] = Math::min(1.0, Q_m/val_neg_flux(row));
1033 }
1034
1035 if(_bc_config == 2)
1036 {
1037 // look for every boundary node and set the pos and neg bound to 1
1038 // (because then alpha_ij is also one)
1039 auto& vec_dof_fltr = _filter.local().get_filter_vector();
1040 const Memory::TypedView<IndexType> idx_fltr = vec_dof_fltr.indices_view_r();
1041 for(Index row = 0; row < vec_dof_fltr.num_nzes(); ++row)
1042 vbn[idx_fltr[row]] = DataType(1);
1043 }
1044
1045 // calc correction factor and multiply together with unlim fluxes
1046 const Memory::TypedView<DataType> val_flux = matrix_flux.val_view_r();
1047
1048 vec_lim_flux.format();
1049 Memory::TypedView<DataType> val_lim_flux = vec_lim_flux.elements_view_rw();
1050
1051 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
1052 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
1053 for(IndexType i = 0; i < _num_rows; ++i)
1054 {
1055 const IndexType start = row_ptr_view[i];
1056 const IndexType end = row_ptr_view[i+1];
1057
1058 // add up to get flux into one node
1059 DataType sum = 0;
1060 for(IndexType m = start; m < end; ++m)
1061 {
1062 const IndexType j = col_idx_view[m];
1063 if(i == j) continue;
1064
1065 if(val_flux[m] > 0)
1066 sum += Math::min(vbp(i), vbn(j)) * val_flux[m];
1067 else if(val_flux[m] < 0)
1068 sum += Math::min(vbn(i), vbp(j)) * val_flux[m];
1069 }
1070 val_lim_flux[i] = -sum/val_mass_lump(i);
1071 }
1072 }
1073
1074 // ------------------- everything MCL -------------------
1075 void _calc_lim_flux_mcl(VectorType& vec_lim_flux, VectorType& vec_sol)
1076 {
1077 VectorType& vec_rhs_low = _vec_hlp.at(0);
1078 // apply matrix to get right hand side of ode (low order)
1079 _matrix_right.apply(vec_rhs_low, vec_sol);
1080 // add type-1 bc vector
1081 if(_bc_config == 1)
1082 vec_rhs_low.axpy(_vec_bc);
1083
1084 VectorType& vec_deriv = _vec_hlp.at(1);
1085 vec_deriv.component_product(vec_rhs_low, _vec_mass_lump_inverse);
1086
1087 VectorType& vec_min = _vec_hlp.at(2);
1088 VectorType& vec_max = _vec_hlp.at(3);
1089 // local min/max for each node
1090 _calc_local_bounds_mcl(vec_min.local(), vec_max.local(), vec_sol.local());
1091 // need the same special sync as seen in fct as well
1092 _synch_vector_min(vec_min.local(), *_row_gate->_comm, _row_gate->_ranks, _col_gate->_mirrors);
1093 _synch_vector_max(vec_max.local(), *_row_gate->_comm, _row_gate->_ranks, _col_gate->_mirrors);
1094
1095 // scaled bar states
1096 _calc_bar_states(_matrix_hlp.local(), vec_sol.local());
1097
1098 // calculation of the limited antidiffusive flux
1099 _calc_lim_flux_mcl_from_bar_state(vec_lim_flux.local(), vec_sol.local(), vec_deriv.local(), vec_min.local(), vec_max.local(), _matrix_hlp.local());
1100 // which has to be synced, since its based on the local matrices (type 0)
1101 vec_lim_flux.sync_0();
1102 }
1103
1104 // u_i^min = min_j u_j; u_i^max = max_j u_j
1105 void _calc_local_bounds_mcl(LocalVectorType& vec_u_min, LocalVectorType& vec_u_max, LocalVectorType& vec_sol)
1106 {
1107 XASSERT(vec_sol.size() == vec_u_min.size());
1108 XASSERT(vec_sol.size() == vec_u_max.size());
1109
1110 vec_u_min.format(); //prob not necessary?
1111 vec_u_max.format();
1112
1113 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
1114 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
1115 const Memory::TypedView<DataType> vec_sol_ptr = vec_sol.elements_view_r();
1116 Memory::TypedView<DataType> vec_u_min_ptr = vec_u_min.elements_view_w();
1117 Memory::TypedView<DataType> vec_u_max_ptr = vec_u_max.elements_view_w();
1118
1119 for(IndexType row = 0; row < _num_rows; ++row)
1120 {
1121 const IndexType start = row_ptr_view[row];
1122 const IndexType end = row_ptr_view[row + 1];
1123
1124 DataType mi = vec_sol_ptr[col_idx_view[start]];
1125 DataType ma = mi;
1126 for (IndexType i = start + 1; i < end; ++i)
1127 {
1128 Math::minimax(vec_sol_ptr[col_idx_view[i]], mi, ma);
1129 }
1130 vec_u_min_ptr[row] = mi;
1131 vec_u_max_ptr[row] = ma;
1132 }
1133 }
1134
1135 // scaled bar states d_ij \bar{u_ij} (convex average of u_i and u_j for no diffusion)
1136 void _calc_bar_states(LocalMatrixType& matrix, LocalVectorType& vec_sol)
1137 {
1138 matrix.format();
1139
1140 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
1141 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
1142 const Memory::TypedView<DataType> val_sol = vec_sol.elements_view_w();
1143 Memory::TypedView<DataType> val_art_dif = _matrix_art_diff.local().val_view_r();
1144 Memory::TypedView<DataType> val_conv = _matrix_conv.local().val_view_r();
1145 Memory::TypedView<DataType> val_mat = matrix.val_view_w();
1146
1147 for(IndexType row = 0; row < _num_rows; ++row)
1148 {
1149 const IndexType start = row_ptr_view[row];
1150 const IndexType end = row_ptr_view[row+1];
1151
1152 for(IndexType i = start; i < end; ++i)
1153 {
1154 const IndexType col = col_idx_view[i];
1155 val_mat[i] = val_art_dif[i] * (val_sol(col) + val_sol(row)) - val_conv[i] * (val_sol(col) - val_sol(row));
1156 }
1157 }
1158 }
1159
1160 // computes the limited flux that has to be added to the right hand side of the ode for the mcl scheme
1161 void _calc_lim_flux_mcl_from_bar_state(LocalVectorType& vec_lim_flux, LocalVectorType& vec_sol, LocalVectorType& vec_deriv, LocalVectorType& vec_min, LocalVectorType& vec_max, LocalMatrixType& matrix_bar_state)
1162 {
1163 vec_lim_flux.format();
1164 _matrix_hlp_t.local() = matrix_bar_state.transpose();
1165
1166 const Memory::TypedView<IndexType> row_ptr_view = _matrix_mass.local().row_ptr_view_r();
1167 const Memory::TypedView<IndexType> col_idx_view = _matrix_mass.local().col_idx_view_r();
1168 const Memory::TypedView<DataType> val_sol = vec_sol.elements_view_r();
1169 const Memory::TypedView<DataType> val_deriv = vec_deriv.elements_view_r();
1170 const Memory::TypedView<DataType> val_min = vec_min.elements_view_r();
1171 const Memory::TypedView<DataType> val_max = vec_max.elements_view_r();
1172 Memory::TypedView<DataType> val_mass = _matrix_mass.local().val_view_r();
1173 Memory::TypedView<DataType> val_art_diff = _matrix_art_diff.local().val_view_r();
1174 Memory::TypedView<DataType> val_bar_state = matrix_bar_state.val_view_r();
1175 Memory::TypedView<DataType> val_bar_state_t = _matrix_hlp_t.local().val_view_r();
1176 Memory::TypedView<DataType> vec_lim_flux_ptr = vec_lim_flux.elements_view_w();
1177
1178 for(IndexType row = 0; row < _num_rows; ++row)
1179 {
1180 const IndexType start = row_ptr_view[row];
1181 const IndexType end = row_ptr_view[row+1];
1182
1183 DataType sum = 0;
1184 for(IndexType i = start; i < end; ++i)
1185 {
1186 const IndexType col = col_idx_view[i];
1187
1188 if( row == col )
1189 continue;
1190
1191 // the flux between node "row" and "col"
1192 const DataType flux = val_art_diff[i] * (val_sol(row) - val_sol(col))
1193 + val_mass[i] * (val_deriv(row) - val_deriv(col));
1194 // add prelimiting?
1195
1196 // the limited flux
1197 if(flux > 0)
1198 sum += Math::min(flux, Math::min(2 * val_art_diff[i] * val_max(row) - val_bar_state[i], val_bar_state_t[i] - 2 * val_art_diff[i] * val_min(col)));
1199 else
1200 sum += Math::max(flux, Math::max(2 * val_art_diff[i] * val_min(row) - val_bar_state[i], val_bar_state_t[i] - 2 * val_art_diff[i] * val_max(col)));
1201 }
1202 vec_lim_flux_ptr[row] = sum;
1203 }
1204 }
1205
1206 // ------------------- syncs for both limiters -------------------
1207 // synchronise a vector by not summing up over the values on each patch, but by taking the minimum over all patches
1209 const std::vector<int>& ranks, const std::vector<FEAT::LAFEM::VectorMirror<DataType, IndexType>>& mirrors)
1210 {
1211 typedef LAFEM::DenseVector<DataType, IndexType> BufferMain;
1212
1214 Dist::RequestVector send_reqs, recv_reqs;
1216 std::vector<BufferMain> send_bufs, recv_bufs;
1217 std::vector<Memory::TypedView<DataType>> send_views, recv_views;
1218
1219 const std::size_t n = ranks.size();
1220
1221 XASSERTM(mirrors.size() == n, "invalid vector mirror count");
1222
1223 // post receives
1224 recv_reqs.reserve(n);
1225 recv_bufs.resize(n);
1226 recv_views.resize(n);
1227 for(std::size_t i(0); i < n; ++i)
1228 {
1229 // create buffer vector
1230 recv_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1231 recv_views.at(i) = recv_bufs.at(i).elements_view_w();
1232
1233 // post receive
1234 recv_reqs.push_back(comm.irecv(recv_views.at(i).get_w(), recv_bufs.at(i).size(), ranks.at(i)));
1235 }
1236
1237 // post sends
1238 send_reqs.reserve(n);
1239 send_bufs.resize(n);
1240 send_views.resize(n);
1241 for(std::size_t i(0); i < n; ++i)
1242 {
1243 // create buffer vector
1244 send_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1245
1246 // gather from mirror
1247 mirrors.at(i).gather(send_bufs.at(i), vector);
1248 send_views.at(i) = send_bufs.at(i).elements_view_r();
1249
1250 // post send
1251 send_reqs.push_back(comm.isend(send_views.at(i).get_r(), send_bufs.at(i).size(), ranks.at(i)));
1252 }
1253
1254 Memory::TypedView<DataType> values = vector.elements_view_rw();
1255
1256 // process all pending receives
1257 for(std::size_t idx(0u); recv_reqs.wait_any(idx); )
1258 {
1259 // get buffer indices and values
1260 const Index m = recv_bufs.at(idx).size();
1261 const Memory::TypedView<IndexType> ind = mirrors.at(idx).indices_view_r();
1262 //const DataType* val = recv_bufs.at(idx).elements();
1263 const Memory::TypedView<DataType>& val = recv_views.at(idx);
1264 for(Index k(0); k < m; ++k)
1265 //Math::mini(values(idx[k]), val[k]);
1266 values[ind[k]] = Math::min(values[ind[k]], val[k]);
1267 }
1268
1269 // wait for all sends to finish
1270 send_reqs.wait_all();
1271 }
1272
1273 // synchronise a vector by not summing up over the values on each patch, but by taking the maximum over all patches
1275 const std::vector<int>& ranks, const std::vector<FEAT::LAFEM::VectorMirror<DataType, IndexType>>& mirrors)
1276 {
1277 typedef LAFEM::DenseVector<DataType, IndexType> BufferMain;
1278
1280 Dist::RequestVector send_reqs, recv_reqs;
1282 std::vector<BufferMain> send_bufs, recv_bufs;
1283 std::vector<Memory::TypedView<DataType>> send_views, recv_views;
1284
1285 const std::size_t n = ranks.size();
1286
1287 XASSERTM(mirrors.size() == n, "invalid vector mirror count");
1288
1289 // post receives
1290 recv_reqs.reserve(n);
1291 recv_bufs.resize(n);
1292 recv_views.resize(n);
1293 for(std::size_t i(0); i < n; ++i)
1294 {
1295 // create buffer vector
1296 recv_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1297 recv_views.at(i) = recv_bufs.at(i).elements_view_w();
1298
1299 // post receive
1300 recv_reqs.push_back(comm.irecv(recv_views.at(i).get_w(), recv_bufs.at(i).size(), ranks.at(i)));
1301 }
1302
1303 // post sends
1304 send_reqs.reserve(n);
1305 send_bufs.resize(n);
1306 send_views.resize(n);
1307 for(std::size_t i(0); i < n; ++i)
1308 {
1309 // create buffer vector
1310 send_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1311
1312 // gather from mirror
1313 mirrors.at(i).gather(send_bufs.at(i), vector);
1314 send_views.at(i) = send_bufs.at(i).elements_view_r();
1315
1316 // post send
1317 send_reqs.push_back(comm.isend(send_views.at(i).get_r(), send_bufs.at(i).size(), ranks.at(i)));
1318 }
1319
1320 Memory::TypedView<DataType> values = vector.elements_view_rw();
1321
1322 // process all pending receives
1323 for(std::size_t idx(0u); recv_reqs.wait_any(idx); )
1324 {
1325 // get buffer indices and values
1326 const Index m = recv_bufs.at(idx).size();
1327 const Memory::TypedView<IndexType> ind = mirrors.at(idx).indices_view_r();
1328 //const Memory::TypedView<DataType> val = recv_bufs.at(idx).elements_view_r();
1329 const Memory::TypedView<DataType>& val = recv_views.at(idx);
1330 for(Index k(0); k < m; ++k)
1331 values[ind[k]] = Math::max(values[ind[k]], val[k]);
1332 }
1333
1334 // wait for all sends to finish
1335 send_reqs.wait_all();
1336 }
1337 };
1338 } // namespace Control
1339} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
An algebraic flux correction solver for the instationary scalar advection, diffusion,...
Definition: afc_limiter.hpp:67
void set_limiter(int limiter)
Choose the limiter.
void set_weak_bc(const VectorType &vec)
Sets vector for weak boundary conditions.
void done_numeric()
Does nothing.
DataType init_numeric()
Numeric initialization.
DataType cfl_cond()
Calculated the cfl condition.
void init()
Initializes solver.
MatrixType & get_stiff_matrix()
Returns the sitffness matrix \int_\Omega \nabla u \cdot \nabla \psi dx.
void _synch_vector_max(FEAT::LAFEM::DenseVector< DataType, IndexType > &vector, const FEAT::Dist::Comm &comm, const std::vector< int > &ranks, const std::vector< FEAT::LAFEM::VectorMirror< DataType, IndexType > > &mirrors)
void init_symbolic()
Initializes symbolic structure of solver.
void init_time_stepping(DataType stepsize)
Initializes the time stepping scheme.
void set_lin_solver(IndexType solver)
Choose a linear solver for implict time stepping.
MatrixType & get_react_matrix()
Returns the reaction matrix \int_\Omega u\psi dx.
void done()
Calls done_numeric() and done_symbolic()
void stiff_mat_to_m()
changes physical diffusion matrix to make it an M-Matrix
void done_symbolic()
Release any data allocated in the call to init_symbolic()
void limit_mcl_explicit(VectorType &vec_sol, const VectorType &vec_rhs)
Makes an MCL step.
void print_times()
Print measured time.
MatrixType & get_mass_matrix()
Returns the mass matrix \int_\Omega u \psi dx.
void _synch_vector_min(FEAT::LAFEM::DenseVector< DataType, IndexType > &vector, const FEAT::Dist::Comm &comm, const std::vector< int > &ranks, const std::vector< FEAT::LAFEM::VectorMirror< DataType, IndexType > > &mirrors)
DataType init_stepsize()
Initializes the time stepizse.
Solver::Status apply_heun(VectorType &vec_sol, const VectorType &vec_rhs1, const VectorType &vec_rhs2)
Apply Heun.
void limit_fct(VectorType &vec_sol, const VectorType &vec_rhs)
Makes an FCT step.
MatrixType & get_conv_matrix()
Returns the convection matrix \int_\Omega (v\cdot \nabla) u \psi dx.
void set_theta(DataType theta)
Sets the time stepping parameter.
void limit_stiff_matrix(bool limit)
Wether or not to also limit the stiffness matrix.
Solver::Status apply(VectorType &vec_sol, const VectorType &vec_rhs)
Applies transport solver to a given rhs.
void set_precond(IndexType precond)
Choose a linear solver for implict time stepping.
Communicator class.
Definition: dist.hpp:1657
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Definition: dist.cpp:719
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
Definition: dist.cpp:707
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
Definition: dist.cpp:800
Communication Request vector class.
Definition: dist.hpp:948
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
Definition: dist.hpp:1194
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
Definition: dist.hpp:1121
std::size_t size() const
Returns the total number of (both active and null) requests in the vector.
Definition: dist.hpp:1209
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
Definition: dist.cpp:332
void wait_all()
Blocks until all active requests are fulfilled.
Definition: dist.cpp:327
Global Filter wrapper class template.
Definition: filter.hpp:21
Global gate implementation.
Definition: gate.hpp:78
std::vector< Mirror_ > _mirrors
vector mirrors
Definition: gate.hpp:100
const Dist::Comm * _comm
our communicator
Definition: gate.hpp:96
std::vector< int > _ranks
communication ranks
Definition: gate.hpp:98
Dense data vector class template.
Unit Filter class template.
Definition: unit_filter.hpp:31
UnitFilter clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
void filter_rhs(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto the right-hand-side vector.
void filter_sol(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto the solution vector.
Memory::TypedView< IT_ > indices_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the indices array for a given memory location.
Handles vector prolongation, restriction and serialization.
Typed memory view class.
Index size() const
Returns the number of array elements mapped to this view.
void format(const T_ &value)
Formats the array elements to a given value, i.e. sets all elements to the same value.
static void abort(bool dump_call_stack=true)
FEAT abortion.
Definition: runtime.cpp:431
Stop-Watch class.
Definition: stop_watch.hpp:21
void start()
Starts the stop-watch.
Definition: stop_watch.hpp:43
void stop()
Stops the stop-watch and increments elapsed time.
Definition: stop_watch.hpp:51
String elapsed_string(TimeFormat format=TimeFormat::s_m) const
Return the time elapsed in the stop-watch.
Definition: stop_watch.hpp:98
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
void minimax(T_ x, T_ &a, T_ &b)
Updates the minimum and maximum.
Definition: math.hpp:195
T_ min(T_ a, T_ b)
Returns the minimum of two values.
Definition: math.hpp:123
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
std::shared_ptr< SSORPrecond< Matrix_, Filter_ > > new_ssor_precond(const PreferredBackend backend, const Matrix_ &matrix, const Filter_ &filter, const typename Matrix_::DataType omega=typename Matrix_::DataType(1))
Creates a new SSORPrecond solver object.
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
std::shared_ptr< FGMRES< Matrix_, Filter_ > > new_fgmres(const Matrix_ &matrix, const Filter_ &filter, Index krylov_dim, typename Matrix_::DataType inner_res_scale=typename Matrix_::DataType(0), std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new FGMRES solver object.
Definition: fgmres.hpp:444
@ none
No plotting whatsoever.
std::shared_ptr< JacobiPrecond< Matrix_, Filter_ > > new_jacobi_precond(const Matrix_ &matrix, const Filter_ &filter, const typename Matrix_::DataType omega=typename Matrix_::DataType(1))
Creates a new JacobiPrecond solver object.
std::shared_ptr< ILUPrecond< Matrix_, Filter_ > > new_ilu_precond(PreferredBackend backend, const Matrix_ &matrix, const Filter_ &filter, const int p=0)
Creates a new ILUPrecond solver object.
std::shared_ptr< SchwarzPrecond< Global::Vector< typename LocalFilter_::VectorType, Mirror_ >, Global::Filter< LocalFilter_, Mirror_ > > > new_schwarz_precond(std::shared_ptr< SolverBase< typename LocalFilter_::VectorType > > local_solver, const Global::Filter< LocalFilter_, Mirror_ > &filter)
Creates a new SchwarzPrecond solver object.
std::shared_ptr< BiCGStab< Matrix_, Filter_ > > new_bicgstab(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr, BiCGStabPreconVariant precon_variant=BiCGStabPreconVariant::left)
Creates a new BiCGStab solver object.
Definition: bicgstab.hpp:608
Status solve(SolverBase< Vector_ > &solver, Vector_ &vec_sol, const Vector_ &vec_rhs, const Matrix_ &matrix, const Filter_ &filter)
Solve linear system with initial solution guess.
Definition: base.hpp:347
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.