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>
28 template<
typename MatrixType_>
31 static constexpr bool is_global =
false;
32 typedef MatrixType_ LocalMatrixType;
37 template<
typename LocalMatrixType_,
typename RowMirror_,
typename ColMirror_>
40 static constexpr bool is_global =
true;
41 typedef LocalMatrixType_ LocalMatrixType;
44 typedef RowMirror_ RowMirror;
45 typedef ColMirror_ ColMirror;
65 template<
typename MatrixType_>
69 typedef MatrixType_ MatrixType;
70 typedef typename MatrixType::VectorTypeR VectorType;
71 typedef typename MatrixType::DataType DataType;
72 typedef typename MatrixType::IndexType IndexType;
74 typedef typename Intern::MatrixTypeHelper<MatrixType_>::LocalMatrixType LocalMatrixType;
75 typedef typename LocalMatrixType::VectorTypeR LocalVectorType;
82 MatrixType _matrix_mass, _matrix_conv, _matrix_stiff, _matrix_react;
84 MatrixType _matrix_art_diff;
85 MatrixType _matrix_hlp;
86 MatrixType _matrix_hlp_t;
88 MatrixType _matrix_left;
90 MatrixType _matrix_right;
91 LocalMatrixType _matrix_schwarz;
94 std::shared_ptr<Solver::IterativeSolver<VectorType>> _solver;
97 VectorType _vec_mass_lump;
98 VectorType _vec_mass_lump_inverse;
107 std::vector<VectorType> _vec_hlp;
112 DataType _stepsize = DataType(-1);
124 std::shared_ptr<Global::SynchMatrix<LocalMatrixType, typename Intern::MatrixTypeHelper<MatrixType_>::RowMirror>> _synch_matrix_ticket;
125 LocalMatrixType _matrix_freq;
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;
135 bool _limit_matrix_stiff =
false;
143 void _set_loc_filter()
145 if constexpr(is_global)
155 void _set_glob_filter()
157 if constexpr(is_global)
202 XASSERTM(_init_symbolic_called,
"Need to call init_symbolic() first");
212 _matrix_mass_set =
true;
221 _matrix_conv_set =
true;
230 _matrix_stiff_set =
true;
231 return _matrix_stiff;
239 _matrix_react_set =
true;
240 return _matrix_react;
259 _limit_matrix_stiff = limit;
274 XASSERTM(_init_symbolic_called,
"Need to call init_symbolic() first");
275 XASSERTM(_matrix_stiff_set,
"stiffnes matrix not set");
278 auto mat_stiff_t = _matrix_stiff.local().transpose();
285 for(IndexType row = 0; row < _num_rows; ++row)
287 const IndexType start = row_ptr_view[row];
288 const IndexType end = row_ptr_view[row + 1];
290 IndexType diag = end;
291 DataType lump = DataType(0);
293 for(IndexType k = start; k < end; ++k)
295 if(col_idx_view[k] == row)
304 val_plus[diag] += -lump;
307 _matrix_stiff.local().axpy(mat_l_plus, -1);
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]");
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");
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;
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");
388 XASSERTM(_matrix_mass_set && _matrix_conv_set,
"Massmatrix and convection matrix must be set!");
403 _num_rows = _matrix_mass.local().num_rows();
406 _vec_mass_lump = _matrix_mass.create_vector_l();
408 for(
int i(0); i < 8; ++i)
415 _row_gate = _matrix_mass.get_row_gate();
416 _col_gate = _matrix_mass.get_col_gate();
418 _synch_matrix_ticket = std::make_shared<Global::SynchMatrix<LocalMatrixType, typename Intern::MatrixTypeHelper<MatrixType_>::RowMirror>>(
423 _matrix_freq.format(DataType(1.0));
426 _synch_matrix_ticket->init(_matrix_freq);
427 _synch_matrix_ticket->exec(_matrix_freq);
432 _matrix_schwarz = _matrix_left.convert_to_1();
437 _solver->set_tol_abs(1e-6);
438 _solver->init_symbolic();
443 _init_symbolic_called =
true;
459 VectorType& vec_cfl = _vec_hlp.at(1);
460 _get_cfl_vec(vec_cfl);
465 vec_cfl.component_product(vec_cfl, _vec_mass_lump);
467 return vec_cfl.min_abs_element();
483 XASSERTM(_init_symbolic_called,
"Need to call init_symbolic() first");
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);
494 _vec_mass_lump = _matrix_mass.lump_rows();
496 _matrix_sync_0_1_0(_matrix_art_diff);
500 _init_stepsize_called =
true;
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!");
524 _stepsize = stepsize;
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)
548 _matrix_right.local().axpy(_matrix_stiff.local());
550 if(_matrix_react_set)
553 _matrix_right.local().axpy(_matrix_react.local());
557 DataType scale_right = (_theta - DataType(1.0)) * (_limiter == 1 ? _stepsize : 1);
559 _matrix_left.local().scale(_matrix_right.local(), _stepsize * _theta);
560 _matrix_right.local().scale(_matrix_right.local(), scale_right);
566 auto vec_mass_lump_type_0 = _matrix_mass.lump_rows(
false);
572 for(IndexType i = 0; i < _num_rows; ++i)
574 for(IndexType j = row_ptr_view[i]; j < row_ptr_view[i+1]; ++j)
576 if(col_idx_view[j] == i)
578 val_right[j] += lump_vec_view(i);
580 val_left[j] += lump_vec_view(i);
590 _matrix_schwarz = _matrix_left.convert_to_1();
591 _solver->init_numeric();
597 _vec_mass_lump_inverse.component_invert(_vec_mass_lump);
600 _init_time_stepping_called =
true;
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();
644 _matrix_left.local().clear();
646 _vec_mass_lump.clear();
648 for(
auto& vec : _vec_hlp)
652 _matrix_freq.clear();
655 _solver->done_symbolic();
657 _init_symbolic_called =
false;
658 _init_stepsize_called =
false;
659 _init_time_stepping_called =
false;
674 XASSERTM(_init_time_stepping_called,
"Need to call init_numeric() or init_time_stepping() first");
680 else if(_limiter == 2)
693 XASSERTM(_theta == 0,
"Only use heun when theta = 0 (because Heun makes two explicit Euler steps)");
695 auto vec_hlp = vec_sol.clone();
699 this->
apply(vec_sol, vec_rhs1);
700 this->
apply(vec_sol, vec_rhs2);
703 vec_sol.axpy(vec_hlp);
704 vec_sol.scale(vec_sol, 0.5);
726 void limit_fct(VectorType& vec_sol,
const VectorType& vec_rhs)
731 VectorType& vec_rhs_low = _vec_hlp.at(2);
734 _matrix_right.apply(vec_rhs_low, vec_sol);
736 vec_rhs_low.axpy(_vec_bc, _stepsize);
737 vec_rhs_low.axpy(vec_rhs, _stepsize);
739 VectorType& vec_sol_low = _vec_hlp.at(3);
740 vec_sol_low.format();
742 vec_sol_low.component_product(vec_rhs_low, _vec_mass_lump_inverse);
754 std::cerr << std::endl
755 <<
"ERROR: solving was not successful" << std::endl;
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());
769 VectorType& vec_neg_flux = _vec_hlp.at(6);
770 VectorType& vec_pos_flux = _vec_hlp.at(7);
772 _calc_antidiffusive_flux_fct(_matrix_hlp.local(), vec_neg_flux.local(), vec_pos_flux.local(), vec_sol.local(), vec_sol_low.local());
774 vec_neg_flux.sync_0();
775 vec_pos_flux.sync_0();
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());
781 vec_lim_flux.sync_0();
784 vec_sol.copy(vec_lim_flux);
785 vec_sol.axpy(vec_sol_low);
795 VectorType& vec_lim_flux = _vec_hlp.at(4);
796 _calc_lim_flux_mcl(vec_lim_flux, vec_sol);
798 VectorType& vec_hlp = _vec_hlp.at(1);
800 vec_hlp.copy(_vec_hlp.at(0));
801 vec_hlp.axpy(vec_lim_flux);
803 vec_hlp.axpy(vec_rhs);
805 vec_hlp.component_product(vec_hlp, _vec_mass_lump_inverse);
807 vec_hlp.scale(vec_hlp, _stepsize);
809 vec_sol.axpy(vec_hlp);
814 void _matrix_sync_0_1_0(MatrixType& mat)
816 auto& mat_local = mat.local();
817 _synch_matrix_ticket->exec(mat_local);
820 for(
Index i = 0; i < mat_local.num_nzes(); ++i)
824 void _setup_lin_solver()
827 std::shared_ptr<Solver::SolverBase<LocalVectorType>> precond;
830 else if(_precond == 2)
832 else if(_precond == 3)
835 XABORTM(
"No valid preconditioner chosen");
843 else if(_lin_solver == 2)
846 XABORTM(
"No valid linear solver chosen");
856 _matrix_art_diff.local().format();
858 _matrix_right.local().copy(_matrix_conv.local());
859 if(_limit_matrix_stiff)
861 XASSERTM(_matrix_stiff_set,
"Stiffness matrix needs to be set to limit it");
862 _matrix_right.local().axpy(_matrix_stiff.local());
864 _matrix_hlp.local().transpose(_matrix_right.local());
872 for(IndexType row = 0; row < _num_rows; ++row)
874 const IndexType start = row_ptr_view[row];
875 const IndexType end = row_ptr_view[row + 1];
877 IndexType diag = end;
878 DataType lump = DataType(0);
880 for(IndexType k = start; k < end; ++k)
882 if(col_idx_view[k] == row)
887 lump += (val_art_diff[k] =
Math::max(DataType(0), max_val_val_t));
891 val_art_diff[diag] = -lump;
896 void _get_cfl_vec(VectorType& vec_cfl)
899 VectorType& vec_hlp = _vec_hlp.at(0);
902 _matrix_conv.extract_diag(vec_cfl);
903 if(_matrix_stiff_set)
905 _matrix_stiff.extract_diag(vec_hlp);
906 vec_cfl.axpy(vec_hlp);
908 if(_matrix_react_set)
910 _matrix_react.extract_diag(vec_hlp);
911 vec_cfl.axpy(vec_hlp);
913 _matrix_art_diff.extract_diag(vec_hlp);
914 vec_cfl.axpy(vec_hlp, DataType(-1.0));
916 vec_cfl.component_invert(vec_cfl, DataType(1.0/(1.0 - _theta)));
921 void _calc_local_bounds_fct(LocalVectorType& vec_u_min, LocalVectorType& vec_u_max, LocalVectorType& vec_sol_low)
923 XASSERT(vec_sol_low.size() == vec_u_min.size());
924 XASSERT(vec_sol_low.size() == vec_u_max.size());
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();
935 for(IndexType row = 0; row < _num_rows; ++row)
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)
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]])));
946 vec_u_min_ptr[row] = mi;
947 vec_u_max_ptr[row] = ma;
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)
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);
960 matrix_flux.format();
961 vec_neg_flux.format();
962 vec_pos_flux.format();
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();
976 for(IndexType i = 0; i < _num_rows; ++i)
978 const IndexType start = row_ptr_view[i];
979 const IndexType end = row_ptr_view[i+1];
981 for(IndexType m = start; m < end; ++m)
983 const IndexType j = col_idx_view[m];
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));
991 if(flux * (val_sol_low(i) - val_sol_low(j)) > 0)
999 val_neg_flux[i] +=
Math::max(0.0, -val_flux[m]);
1000 val_pos_flux[i] +=
Math::max(0.0, val_flux[m]);
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)
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();
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();
1021 Memory::TypedView<DataType> vbn = vec_bnd_neg.elements_view_rw();
1022 Memory::TypedView<DataType> vbp = vec_bnd_pos.elements_view_rw();
1024 for(IndexType row = 0; row < _num_rows; ++row)
1027 DataType Q_p = val_mass_lump(row) * val_max(row);
1028 DataType Q_m = val_mass_lump(row) * val_min(row);
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));
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);
1046 const Memory::TypedView<DataType> val_flux = matrix_flux.val_view_r();
1049 Memory::TypedView<DataType> val_lim_flux = vec_lim_flux.elements_view_rw();
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)
1055 const IndexType start = row_ptr_view[i];
1056 const IndexType end = row_ptr_view[i+1];
1060 for(IndexType m = start; m < end; ++m)
1062 const IndexType j = col_idx_view[m];
1063 if(i == j)
continue;
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];
1070 val_lim_flux[i] = -sum/val_mass_lump(i);
1075 void _calc_lim_flux_mcl(VectorType& vec_lim_flux, VectorType& vec_sol)
1077 VectorType& vec_rhs_low = _vec_hlp.at(0);
1079 _matrix_right.apply(vec_rhs_low, vec_sol);
1082 vec_rhs_low.axpy(_vec_bc);
1084 VectorType& vec_deriv = _vec_hlp.at(1);
1085 vec_deriv.component_product(vec_rhs_low, _vec_mass_lump_inverse);
1087 VectorType& vec_min = _vec_hlp.at(2);
1088 VectorType& vec_max = _vec_hlp.at(3);
1090 _calc_local_bounds_mcl(vec_min.local(), vec_max.local(), vec_sol.local());
1096 _calc_bar_states(_matrix_hlp.local(), vec_sol.local());
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());
1101 vec_lim_flux.sync_0();
1105 void _calc_local_bounds_mcl(LocalVectorType& vec_u_min, LocalVectorType& vec_u_max, LocalVectorType& vec_sol)
1107 XASSERT(vec_sol.size() == vec_u_min.size());
1108 XASSERT(vec_sol.size() == vec_u_max.size());
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();
1119 for(IndexType row = 0; row < _num_rows; ++row)
1121 const IndexType start = row_ptr_view[row];
1122 const IndexType end = row_ptr_view[row + 1];
1124 DataType mi = vec_sol_ptr[col_idx_view[start]];
1126 for (IndexType i = start + 1; i < end; ++i)
1130 vec_u_min_ptr[row] = mi;
1131 vec_u_max_ptr[row] = ma;
1136 void _calc_bar_states(LocalMatrixType& matrix, LocalVectorType& vec_sol)
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();
1147 for(IndexType row = 0; row < _num_rows; ++row)
1149 const IndexType start = row_ptr_view[row];
1150 const IndexType end = row_ptr_view[row+1];
1152 for(IndexType i = start; i < end; ++i)
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));
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)
1163 vec_lim_flux.format();
1164 _matrix_hlp_t.local() = matrix_bar_state.transpose();
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();
1178 for(IndexType row = 0; row < _num_rows; ++row)
1180 const IndexType start = row_ptr_view[row];
1181 const IndexType end = row_ptr_view[row+1];
1184 for(IndexType i = start; i < end; ++i)
1186 const IndexType col = col_idx_view[i];
1192 const DataType flux = val_art_diff[i] * (val_sol(row) - val_sol(col))
1193 + val_mass[i] * (val_deriv(row) - val_deriv(col));
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)));
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)));
1202 vec_lim_flux_ptr[row] = sum;
1216 std::vector<BufferMain> send_bufs, recv_bufs;
1217 std::vector<Memory::TypedView<DataType>> send_views, recv_views;
1219 const std::size_t n = ranks.
size();
1221 XASSERTM(mirrors.size() == n,
"invalid vector mirror count");
1225 recv_bufs.resize(n);
1226 recv_views.resize(n);
1227 for(std::size_t i(0); i < n; ++i)
1230 recv_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1231 recv_views.at(i) = recv_bufs.at(i).elements_view_w();
1234 recv_reqs.
push_back(comm.
irecv(recv_views.at(i).get_w(), recv_bufs.at(i).size(), ranks.at(i)));
1239 send_bufs.resize(n);
1240 send_views.resize(n);
1241 for(std::size_t i(0); i < n; ++i)
1244 send_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1247 mirrors.at(i).gather(send_bufs.at(i), vector);
1248 send_views.at(i) = send_bufs.at(i).elements_view_r();
1251 send_reqs.
push_back(comm.
isend(send_views.at(i).get_r(), send_bufs.at(i).size(), ranks.at(i)));
1257 for(std::size_t idx(0u); recv_reqs.
wait_any(idx); )
1260 const Index m = recv_bufs.at(idx).
size();
1264 for(
Index k(0); k < m; ++k)
1266 values[ind[k]] =
Math::min(values[ind[k]], val[k]);
1282 std::vector<BufferMain> send_bufs, recv_bufs;
1283 std::vector<Memory::TypedView<DataType>> send_views, recv_views;
1285 const std::size_t n = ranks.
size();
1287 XASSERTM(mirrors.size() == n,
"invalid vector mirror count");
1291 recv_bufs.resize(n);
1292 recv_views.resize(n);
1293 for(std::size_t i(0); i < n; ++i)
1296 recv_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1297 recv_views.at(i) = recv_bufs.at(i).elements_view_w();
1300 recv_reqs.
push_back(comm.
irecv(recv_views.at(i).get_w(), recv_bufs.at(i).size(), ranks.at(i)));
1305 send_bufs.resize(n);
1306 send_views.resize(n);
1307 for(std::size_t i(0); i < n; ++i)
1310 send_bufs.at(i) = BufferMain(mirrors.at(i).buffer_size(vector));
1313 mirrors.at(i).gather(send_bufs.at(i), vector);
1314 send_views.at(i) = send_bufs.at(i).elements_view_r();
1317 send_reqs.
push_back(comm.
isend(send_views.at(i).get_r(), send_bufs.at(i).size(), ranks.at(i)));
1323 for(std::size_t idx(0u); recv_reqs.
wait_any(idx); )
1326 const Index m = recv_bufs.at(idx).
size();
1330 for(
Index k(0); k < m; ++k)
1331 values[ind[k]] =
Math::max(values[ind[k]], val[k]);
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
An algebraic flux correction solver for the instationary scalar advection, diffusion,...
void set_limiter(int limiter)
Choose the limiter.
void _calc_artificial_diffusion()
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.
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
Communication Request vector class.
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
std::size_t size() const
Returns the total number of (both active and null) requests in the vector.
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
void wait_all()
Blocks until all active requests are fulfilled.
Global Filter wrapper class template.
Global gate implementation.
std::vector< Mirror_ > _mirrors
vector mirrors
const Dist::Comm * _comm
our communicator
std::vector< int > _ranks
communication ranks
Dense data vector class template.
Unit Filter class template.
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.
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.
void start()
Starts the stop-watch.
void stop()
Stops the stop-watch and increments elapsed time.
String elapsed_string(TimeFormat format=TimeFormat::s_m) const
Return the time elapsed in the stop-watch.
T_ abs(T_ x)
Returns the absolute value.
void minimax(T_ x, T_ &a, T_ &b)
Updates the minimum and maximum.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
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.
@ 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.
@ 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.
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.
std::uint64_t Index
Index data type.