33 #ifndef __H__UG__LIB_DISC__MULTI_GRID_SOLVER__MG_SOLVER_IMPL__
34 #define __H__UG__LIB_DISC__MULTI_GRID_SOLVER__MG_SOLVER_IMPL__
54 #define GMG_PARALLEL_DEBUG_BARRIER(comm) PCL_DEBUG_BARRIER(comm)
57 #define GMG_PARALLEL_DEBUG_BARRIER(comm)
62 #define GMG_PROFILE_FUNC() PROFILE_FUNC_GROUP("gmg")
63 #define GMG_PROFILE_BEGIN(name) PROFILE_BEGIN_GROUP(name, "gmg")
64 #define GMG_PROFILE_END() PROFILE_END()
66 #define GMG_PROFILE_FUNC()
67 #define GMG_PROFILE_BEGIN(name)
68 #define GMG_PROFILE_END()
77 template <
typename TDomain,
typename TAlgebra>
80 m_spSurfaceMat(NULL), m_pSurfaceSol(nullptr), m_spAss(NULL), m_spApproxSpace(
SPNULL),
82 m_baseLev(0), m_cycleType(_V_),
83 m_numPreSmooth(2), m_numPostSmooth(2),
84 m_LocalFullRefLevel(0), m_GridLevelType(
GridLevel::LEVEL),
85 m_bUseRAP(false), m_bSmoothOnSurfaceRim(false),
86 m_bCommCompOverlap(false),
87 m_spPreSmootherPrototype(
new Jacobi<TAlgebra>()),
88 m_spPostSmootherPrototype(m_spPreSmootherPrototype),
89 m_spProjectionPrototype(
SPNULL),
91 m_spRestrictionPrototype(m_spProlongationPrototype),
92 m_spBaseSolver(
new LU<TAlgebra>()),
93 m_bGatheredBaseIfAmbiguous(true),
94 m_bGatheredBaseUsed(true),
95 m_ignoreInitForBaseSolver(false),
96 m_bMatrixStructureIsConst(false),
98 m_spDebugWriter(NULL), m_dbgIterCnt(0)
102 template <
typename TDomain,
typename TAlgebra>
105 m_spSurfaceMat(NULL), m_pSurfaceSol(nullptr), m_spAss(NULL), m_spApproxSpace(approxSpace),
107 m_baseLev(0), m_cycleType(_V_),
108 m_numPreSmooth(2), m_numPostSmooth(2),
109 m_LocalFullRefLevel(0), m_GridLevelType(
GridLevel::LEVEL),
110 m_bUseRAP(false), m_bSmoothOnSurfaceRim(false),
111 m_bCommCompOverlap(false),
112 m_spPreSmootherPrototype(
new Jacobi<TAlgebra>()),
113 m_spPostSmootherPrototype(m_spPreSmootherPrototype),
114 m_spProjectionPrototype(
new StdInjection<TDomain,TAlgebra>(m_spApproxSpace)),
116 m_spRestrictionPrototype(m_spProlongationPrototype),
117 m_spBaseSolver(
new LU<TAlgebra>()),
118 m_bGatheredBaseIfAmbiguous(true),
119 m_bGatheredBaseUsed(true),
120 m_ignoreInitForBaseSolver(false),
121 m_bMatrixStructureIsConst(false),
123 m_spDebugWriter(NULL), m_dbgIterCnt(0)
126 template <
typename TDomain,
typename TAlgebra>
130 m_spApproxSpace = approxSpace;
134 template <
typename TDomain,
typename TAlgebra>
142 clone->set_base_level(m_baseLev);
143 clone->set_base_solver(m_spBaseSolver);
144 clone->set_cycle_type(m_cycleType);
145 clone->set_debug(m_spDebugWriter);
146 clone->set_discretization(m_spAss);
147 clone->set_num_postsmooth(m_numPostSmooth);
148 clone->set_num_presmooth(m_numPreSmooth);
149 clone->set_projection(m_spProjectionPrototype);
150 clone->set_prolongation(m_spProlongationPrototype);
151 clone->set_restriction(m_spRestrictionPrototype);
152 clone->set_presmoother(m_spPreSmootherPrototype);
153 clone->set_postsmoother(m_spPostSmootherPrototype);
154 clone->set_surface_level(m_surfaceLev);
156 for(
size_t i = 0; i < m_vspProlongationPostProcess.size(); ++i)
157 clone->add_prolongation_post_process(m_vspProlongationPostProcess[i]);
159 for(
size_t i = 0; i < m_vspRestrictionPostProcess.size(); ++i)
160 clone->add_restriction_post_process(m_vspRestrictionPostProcess[i]);
165 template <
typename TDomain,
typename TAlgebra>
174 template <
typename TDomain,
typename TAlgebra>
179 GF* pC =
dynamic_cast<GF*
>(&rC);
180 if(!pC)
UG_THROW(
"GMG::apply: Expect Correction to be grid based.")
181 const GF* pD =
dynamic_cast<const GF*
>(&rD);
182 if(!pD)
UG_THROW(
"GMG::apply: Expect Defect to be grid based.")
191 if(m_topLev >= (
int)m_spApproxSpace->num_levels())
192 UG_THROW(
"GMG::apply: SurfaceLevel "<<m_topLev<<
" does not exist.");
195 if(m_baseLev > m_topLev)
196 UG_THROW(
"GMG::apply: Base level must be smaller or equal to surface Level.");
199 write_debug(d,
"Defect_In");
200 write_debug(*m_spSurfaceMat,
"SurfaceStiffness", c, c);
201 for(
int lev = m_baseLev; lev <= m_topLev; ++lev)
203 LevData& ld = *m_vLevData[lev];
211 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
212 const std::vector<SurfLevelMap>& vMap = m_vLevData[lev]->vSurfLevelMap;
213 LevData& ld = *m_vLevData[lev];
214 for(
size_t i = 0; i < vMap.size(); ++i){
215 (*ld.
sd)[vMap[i].levIndex] = d[vMap[i].surfIndex];
219 for(
int lev = m_baseLev; lev <= m_topLev; ++lev)
220 m_vLevData[lev]->sd->set_storage_type(d.get_storage_mask());
234 m_vLevData[m_topLev]->sc->set(0.0);
239 lmgc(m_topLev, m_cycleType);
244 const std::vector<SurfLevelMap>& vMap = m_vLevData[m_topLev]->vSurfLevelMap;
245 LevData& ld = *m_vLevData[m_topLev];
246 for(
size_t i = 0; i < vMap.size(); ++i){
247 c[vMap[i].surfIndex] += (*ld.
sc)[vMap[i].levIndex];
266 write_debug(c,
"Correction_Out");
269 if(m_spDebugWriter.valid()) m_dbgIterCnt++;
277 template <
typename TDomain,
typename TAlgebra>
308 if(!apply(c, rD))
return false;
311 m_spSurfaceMat->matmul_minus(rD, c);
314 const GF* pD =
dynamic_cast<const GF*
>(&rD);
315 if(!pD)
UG_THROW(
"GMG::apply: Expect Defect to be grid based.")
317 write_debug(d,
"Defect_Out");
322 template <
typename TDomain,
typename TAlgebra>
331 J.template cast_dynamic<AssembledLinearOperator<TAlgebra> >();
333 m_spAss = spALO->discretization();
337 m_spSurfaceMat = J.template cast_dynamic<matrix_type>();
349 template <
typename TDomain,
typename TAlgebra>
358 L.template cast_dynamic<AssembledLinearOperator<TAlgebra> >();
360 m_spAss = spALO->discretization();
364 m_spSurfaceMat = L.template cast_dynamic<matrix_type>();
367 m_pSurfaceSol = NULL;
378 template <
typename TDomain,
typename TAlgebra>
388 if(m_spSurfaceMat.invalid())
389 UG_THROW(
"GMG:init: Can not cast Operator to Matrix.");
392 if(m_spApproxSpace.invalid())
393 UG_THROW(
"GMG::init: Approximation Space not set.");
396 if(m_spApproxSpace->num_levels() == 0)
397 UG_THROW(
"GMG:init: No grid levels");
399 if(m_spAss.invalid())
400 UG_THROW(
"GMG::init: Discretization not set.");
402 if(m_spBaseSolver.invalid())
403 UG_THROW(
"GMG::init: Base Solver not set.");
405 if(m_spPreSmootherPrototype.invalid())
406 UG_THROW(
"GMG::init: PreSmoother not set.");
408 if(m_spPostSmootherPrototype.invalid())
409 UG_THROW(
"GMG::init: PostSmoother not set.");
411 if(m_spProlongationPrototype.invalid())
412 UG_THROW(
"GMG::init: Prolongation not set.");
414 if(m_spRestrictionPrototype.invalid())
415 UG_THROW(
"GMG::init: Restriction not set.");
418 const GF* pSol =
dynamic_cast<const GF*
>(m_pSurfaceSol);
425 else topLev = m_spApproxSpace->num_levels() - 1;
427 if(m_baseLev > topLev)
428 UG_THROW(
"GMG::init: Base Level greater than Surface level.");
430 if(m_ApproxSpaceRevision != m_spApproxSpace->revision()
431 || topLev != m_topLev)
439 init_level_memory(m_baseLev, m_topLev);
447 init_index_mappings();
457 UG_CATCH_THROW(
"GMG:init: Cannot init Transfer (Prolongation/Restriction).");
461 m_ApproxSpaceRevision = m_spApproxSpace->revision();
470 assemble_level_operator();
485 if(!ignore_init_for_base_solver()){
499 template <
typename TDomain,
typename TAlgebra>
505 "ignore_init_for_base_solver currently only works for serial runs.")
507 m_ignoreInitForBaseSolver = ignore;
510 template <
typename TDomain,
typename TAlgebra>
514 return m_ignoreInitForBaseSolver;
518 template <
typename TDomain,
typename TAlgebra>
522 m_ApproxSpaceRevision.invalidate();
526 template <
typename TDomain,
typename TAlgebra>
534 UG_THROW(
"GMG: emulate_full_refined_grid currently only implemented "
535 "for set_rap(true) - since assembling of on surface-level with "
536 " lev < topLev is currently not supported by constraints and "
537 " elem-disc loop (only top-lev or level-view poosible). It is "
538 "necessary to rework that part of the assembing procedure.")
547 UG_THROW(
"GMG::init: Can only project "
548 "a consistent solution. Make sure to pass a consistent on.");
553 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
554 const std::vector<SurfLevelMap>& vMap = m_vLevData[lev]->vSurfLevelMap;
555 LevData& ld = *m_vLevData[lev];
556 for(
size_t i = 0; i < vMap.size(); ++i){
557 (*ld.
st)[vMap[i].levIndex] = (*m_pSurfaceSol)[vMap[i].surfIndex];
564 UG_CATCH_THROW(
"GMG::init: Projection of Surface Solution failed.");
568 for(
int lev = m_topLev; lev >= m_baseLev; --lev)
570 LevData& ld = *m_vLevData[lev];
576 if(m_pSurfaceSol && lev > m_baseLev)
578 if( !ld.
t->layouts()->vertical_slave().empty() ||
579 !ld.
t->layouts()->vertical_master().empty())
589 m_Com.receive_data(ld.
t->layouts()->vertical_master(), cpVecCopy);
590 m_Com.send_data(ld.
t->layouts()->vertical_slave(), cpVecCopy);
591 m_Com.communicate_and_resume();
593 if(!m_bCommCompOverlap){
606 bool bCpyFromSurface = ((lev == m_topLev) && (lev <= m_LocalFullRefLevel));
613 m_spAss->ass_tuner()->set_force_regular_grid(
true);
614 m_spAss->assemble_jacobian(*ld.
A, *ld.
st,
GridLevel(lev, m_GridLevelType,
false));
615 m_spAss->ass_tuner()->set_force_regular_grid(
false);
628 UG_ASSERT(m_spSurfaceMat->num_rows() == m_vSurfToLevelMap.size(),
629 "Surface Matrix rows != Surf Level Indices")
631 if (m_bMatrixStructureIsConst)
632 ld.
A->clear_retain_structure();
634 ld.
A->resize_and_clear(m_spSurfaceMat->num_rows(), m_spSurfaceMat->num_cols());
635 for(
size_t srfRow = 0; srfRow < m_vSurfToLevelMap.size(); ++srfRow)
638 UG_ASSERT(m_vSurfToLevelMap[srfRow].level == m_topLev,
639 "All surface Indices must be on top level for full-ref.")
640 const size_t lvlRow = m_vSurfToLevelMap[srfRow].index;
644 typedef typename matrix_type::const_row_iterator const_row_iterator;
645 const_row_iterator conn = m_spSurfaceMat->begin_row(srfRow);
646 const_row_iterator connEnd = m_spSurfaceMat->end_row(srfRow);
647 for( ;conn != connEnd; ++conn){
649 UG_ASSERT(m_vSurfToLevelMap[conn.index()].level == m_topLev,
650 "All surface Indices must be on top level for full-ref.")
651 const size_t lvlCol = m_vSurfToLevelMap[conn.index()].index;
654 (*ld.
A)(lvlRow, lvlCol) = conn.value();
659 ld.
A->set_storage_type(m_spSurfaceMat->get_storage_mask());
660 ld.
A->set_layouts(ld.
st->layouts());
666 if(m_pSurfaceSol && lev > m_baseLev)
669 if(m_bCommCompOverlap){
679 LevData& lc = *m_vLevData[lev-1];
683 lc.
st->set_storage_type(m_pSurfaceSol->get_storage_mask());
685 }
UG_CATCH_THROW(
"GMG::init: Cannot project solution to coarse grid "
686 "function of level "<<lev-1);
693 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
694 LevData& ld = *m_vLevData[lev];
695 write_debug(*ld.
A,
"LevelMatrix", *ld.
st, *ld.
st);
702 if(m_bGatheredBaseUsed)
705 LevData& ld = *m_vLevData[m_baseLev];
710 if( !ld.
t->layouts()->vertical_slave().empty() ||
711 !ld.
t->layouts()->vertical_master().empty())
719 m_Com.receive_data(ld.
t->layouts()->vertical_master(), cpVecCopy);
720 m_Com.send_data(ld.
t->layouts()->vertical_slave(), cpVecCopy);
730 if(gathered_base_master())
735 m_spAss->ass_tuner()->set_force_regular_grid(
true);
736 m_spAss->assemble_jacobian(*spGatheredBaseMat, *ld.
t,
GridLevel(m_baseLev, m_GridLevelType,
true));
737 m_spAss->ass_tuner()->set_force_regular_grid(
false);
739 UG_CATCH_THROW(
"GMG:init: Cannot init operator base level operator");
747 assemble_rim_cpl(m_pSurfaceSol);
749 UG_CATCH_THROW(
"GMG:init: Cannot init missing coarse grid coupling.");
754 template <
typename TDomain,
typename TAlgebra>
762 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
763 LevData& ld = *m_vLevData[lev];
769 for(
int lev = m_topLev; lev > m_LocalFullRefLevel; --lev)
771 LevData& lc = *m_vLevData[lev-1];
772 LevData& lf = *m_vLevData[lev];
775 if(m_bSmoothOnSurfaceRim)
778 for(
size_t i = 0; i< lf.
vShadowing.size(); ++i)
785 typedef typename matrix_type::const_row_iterator row_iterator;
786 row_iterator conn = m_spSurfaceMat->begin_row(srfRow);
787 row_iterator connEnd = m_spSurfaceMat->end_row(srfRow);
788 for( ;conn != connEnd; ++conn)
790 const size_t srfCol = conn.index();
792 if(m_vSurfToLevelMap[srfCol].level == lev) {
793 const size_t lvlCol = m_vSurfToLevelMap[srfCol].index;
794 (*lf.
A)(lvlRow, lvlCol) = conn.value();
796 if(m_vSurfToLevelMap[srfCol].level == lev+1) {
797 if(m_vSurfToLevelMap[srfCol].levelLower == lev) {
798 const size_t lvlCol = m_vSurfToLevelMap[srfCol].indexLower;
799 (*lf.
A)(lvlRow, lvlCol) = conn.value();
802 if(m_vSurfToLevelMap[srfCol].level == lev-1){
803 const size_t lvlCol = m_vSurfToLevelMap[srfCol].index;
806 if(m_bSmoothOnSurfaceRim){
816 if(m_bSmoothOnSurfaceRim)
819 write_debug(*lf.
A,
"LevelMatrix", *lf.
st, *lf.
st);
821 if(m_bSmoothOnSurfaceRim)
828 template <
typename TDomain,
typename TAlgebra>
836 for(
int lev = m_topLev; lev >= m_baseLev; --lev)
838 LevData& ld = *m_vLevData[lev];
839 if (m_bMatrixStructureIsConst)
840 ld.
A->clear_retain_structure();
842 ld.
A->resize_and_clear(ld.
st->size(), ld.
st->size());
844 ld.
A->set_storage_type(m_spSurfaceMat->get_storage_mask());
845 ld.
A->set_layouts(ld.
st->layouts());
852 for(
size_t srfRow = 0; srfRow < m_vSurfToLevelMap.size(); ++srfRow)
856 typedef typename matrix_type::const_row_iterator const_row_iterator;
857 const_row_iterator conn = m_spSurfaceMat->begin_row(srfRow);
858 const_row_iterator connEnd = m_spSurfaceMat->end_row(srfRow);
859 for( ;conn != connEnd; ++conn)
862 const size_t srfCol = conn.index();
865 int rowLevel = m_vSurfToLevelMap[srfRow].level;
866 int colLevel = m_vSurfToLevelMap[srfCol].level;
869 size_t lvlRow = m_vSurfToLevelMap[srfRow].index;
870 size_t lvlCol = m_vSurfToLevelMap[srfCol].index;
873 UG_ASSERT(colLevel >= 0,
"Invalid colLevel: "<<colLevel)
874 UG_ASSERT(rowLevel >= 0,
"Invalid rowLevel: "<<rowLevel)
875 if(colLevel > rowLevel){
876 if(m_vSurfToLevelMap[srfCol].levelLower == rowLevel){
877 lvlCol = m_vSurfToLevelMap[srfCol].indexLower;
882 }
else if(colLevel < rowLevel){
883 if(m_vSurfToLevelMap[srfRow].levelLower == colLevel){
884 lvlRow = m_vSurfToLevelMap[srfRow].indexLower;
892 (*(m_vLevData[colLevel]->A))(lvlRow, lvlCol) = conn.value();
899 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
900 LevData& ld = *m_vLevData[lev];
901 write_debug(*ld.
A,
"LevelMatrixFromSurf", *ld.
st, *ld.
st);
907 for(
int lev = m_topLev; lev > m_baseLev; --lev)
910 LevData& lf = *m_vLevData[lev];
911 LevData& lc = *m_vLevData[lev-1];
917 if( !lf.
t->layouts()->vertical_master().empty() ||
918 !lf.
t->layouts()->vertical_slave().empty())
921 spGhostA->resize_and_clear(lf.
t->size(), lf.
t->size());
923 if(!lf.
t->layouts()->vertical_master().empty()){
931 m_Com.send_data(spGhostA->
layouts()->vertical_slave(), cpMatAdd);
932 m_Com.receive_data(spGhostA->
layouts()->vertical_master(), cpMatAdd);
933 m_Com.communicate_and_resume();
935 if(!m_bCommCompOverlap){
951 if(m_bCommCompOverlap){
967 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
968 LevData& ld = *m_vLevData[lev];
969 write_debug(*ld.
A,
"LevelMatrix", *ld.
st, *ld.
st);
972 if(m_bGatheredBaseUsed)
976 LevData& ld = *m_vLevData[m_baseLev];
977 if(gathered_base_master()){
979 if (m_bMatrixStructureIsConst)
980 spGatheredBaseMat->clear_retain_structure();
982 spGatheredBaseMat->resize_and_clear(ld.
t->size(), ld.
t->size());
983 copy_noghost_to_ghost(spGatheredBaseMat.template cast_dynamic<matrix_type>(), ld.
A, ld.
vMapPatchToGlobal);
986 *spGatheredBaseMat = *ld.
A;
988 spGatheredBaseMat->set_storage_type(m_spSurfaceMat->get_storage_mask());
989 spGatheredBaseMat->set_layouts(ld.
t->layouts());
994 m_Com.send_data(spGatheredBaseMat->layouts()->vertical_slave(), cpMatAdd);
995 if(gathered_base_master())
996 m_Com.receive_data(spGatheredBaseMat->layouts()->vertical_master(), cpMatAdd);
1000 if(!gathered_base_master()){
1001 spGatheredBaseMat =
SPNULL;
1010 UG_CATCH_THROW(
"GMG:init: Cannot init missing coarse grid coupling.");
1015 template <
typename TDomain,
typename TAlgebra>
1023 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
1024 LevData& ld = *m_vLevData[lev];
1030 for(
int lev = m_topLev; lev > m_LocalFullRefLevel; --lev)
1032 LevData& lc = *m_vLevData[lev-1];
1033 LevData& lf = *m_vLevData[lev];
1036 if(m_bSmoothOnSurfaceRim)
1039 for(
size_t i = 0; i< lf.
vShadowing.size(); ++i)
1044 typedef typename matrix_type::const_row_iterator const_row_iterator;
1045 const_row_iterator conn = m_spSurfaceMat->begin_row(srfRow);
1046 const_row_iterator connEnd = m_spSurfaceMat->end_row(srfRow);
1047 for( ;conn != connEnd; ++conn)
1049 const size_t srfCol = conn.index();
1051 if(m_vSurfToLevelMap[srfCol].level == lev-1){
1052 const size_t lvlCol = m_vSurfToLevelMap[srfCol].index;
1055 if(m_bSmoothOnSurfaceRim){
1064 if(m_bSmoothOnSurfaceRim)
1068 if(m_bSmoothOnSurfaceRim)
1076 template <
typename TDomain,
typename TAlgebra>
1084 for(
int lev = m_baseLev+1; lev <= m_topLev; ++lev)
1086 LevData& lf = *m_vLevData[lev];
1087 LevData& lc = *m_vLevData[lev-1];
1090 bool bOneOperator =
false;
1095 for(
size_t i = 0; i < m_spAss->num_constraints(); ++i){
1102 lf.
Restriction->set_levels(lc.
st->grid_level(), lf.
t->grid_level());
1104 for(
size_t i = 0; i < m_spAss->num_constraints(); ++i){
1115 template <
typename TDomain,
typename TAlgebra>
1122 for(
int lev = m_baseLev+1; lev <= m_topLev; ++lev)
1124 LevData& lf = *m_vLevData[lev];
1125 LevData& lc = *m_vLevData[lev-1];
1126 GridLevel gw_gl; enter_debug_writer_section(gw_gl,
"ProjectionInit", lev);
1127 lf.
Projection->set_levels(lc.
st->grid_level(), lf.
t->grid_level());
1129 leave_debug_writer_section(gw_gl);
1135 template <
typename TDomain,
typename TAlgebra>
1143 for(
int lev = m_baseLev+1; lev <= m_topLev; ++lev)
1145 LevData& ld = *m_vLevData[lev];
1149 GridLevel gw_gl; enter_debug_writer_section(gw_gl,
"PreSmootherInit", lev);
1151 UG_CATCH_THROW(
"GMG::init: Cannot init pre-smoother for level "<<lev);
1152 leave_debug_writer_section(gw_gl);
1154 UG_THROW(
"GMG::init: Cannot init pre-smoother for level "<<lev);
1159 GridLevel gw_gl; enter_debug_writer_section(gw_gl,
"PostSmootherInit", lev);
1161 UG_CATCH_THROW(
"GMG::init: Cannot init post-smoother for level "<<lev);
1162 leave_debug_writer_section(gw_gl);
1164 UG_THROW(
"GMG::init: Cannot init post-smoother for level "<<lev);
1171 template <
typename TDomain,
typename TAlgebra>
1177 LevData& ld = *m_vLevData[m_baseLev];
1180 if(m_bGatheredBaseUsed)
1183 if(!gathered_base_master())
return;
1190 spOneProcLayout->clear();
1191 spOneProcLayout->vertical_master() = ld.
t->layouts()->vertical_master();
1194 spGatheredBaseMat->set_layouts(spOneProcLayout);
1195 spGatheredBaseCorr->set_layouts(spOneProcLayout);
1197 ld.
t->set_layouts(spOneProcLayout);
1203 GridLevel gw_gl; enter_debug_writer_section(gw_gl,
"GatheredBaseSolverInit", m_baseLev);
1204 if(!m_spBaseSolver->init(spGatheredBaseMat, *ld.
t))
1205 UG_THROW(
"GMG::init: Cannot init base solver on baselevel "<< m_baseLev);
1206 leave_debug_writer_section(gw_gl);
1211 if(!ld.
st->layouts()->master().empty() || !ld.
st->layouts()->slave().empty())
1212 if(!m_spBaseSolver->supports_parallel())
1213 UG_THROW(
"GMG: Base level is distributed onto more than process, "
1214 "but the chosen base solver "<<m_spBaseSolver->name()<<
1215 " does not support parallel solving. Choose a parallel"
1216 " base solver or construct a situation, where a single"
1217 " process stores the whole base grid, to cure this issue.");
1222 GridLevel gw_gl; enter_debug_writer_section(gw_gl,
"BaseSolverInit", m_baseLev);
1223 if(!m_spBaseSolver->init(ld.
A, *ld.
st))
1224 UG_THROW(
"GMG::init: Cannot init base solver on baselevel "<< m_baseLev);
1225 leave_debug_writer_section(gw_gl);
1231 template <
typename TDomain,
typename TAlgebra>
1232 template <
typename TElem>
1261 std::vector<ConstSmartPtr<DoFDistribution> > vLevelDD(m_topLev+1);
1262 for(
int lev = m_baseLev; lev <= m_topLev; ++lev)
1263 vLevelDD[lev] = m_spApproxSpace->dof_distribution(
GridLevel(lev, m_GridLevelType,
false));
1281 std::vector<size_t> vSurfInd, vLevelInd;
1284 for( ; iter != iterEnd; ++iter)
1287 TElem* elem = *iter;
1290 if (pbm && pbm->
is_slave(elem))
continue;
1293 int level = m_spApproxSpace->domain()->grid()->get_level(elem);
1301 if(level < m_baseLev)
1302 UG_THROW(
"GMG::init: Some index of the surface grid is located on "
1303 "level "<<level<<
", which is below the chosen baseLev "<<
1304 m_baseLev<<
". This is not allowed, since otherwise the "
1305 "gmg correction would only affect parts of the domain. Use"
1306 "gmg:set_base_level(lvl) to cure this issue.");
1309 m_LocalFullRefLevel = std::min(m_LocalFullRefLevel, level);
1312 vLevelDD[level]->inner_algebra_indices(elem, vLevelInd);
1313 surfDD->inner_algebra_indices(elem, vSurfInd);
1314 UG_ASSERT(vSurfInd.size() == vLevelInd.size(),
"Number of indices does not match.");
1319 for(
size_t i = 0; i < vSurfInd.size(); ++i){
1320 m_vLevData[level]->vShadowing.push_back(vLevelInd[i]);
1321 m_vLevData[level]->vSurfShadowing.push_back(vSurfInd[i]);
1327 for(
size_t i = 0; i < vSurfInd.size(); ++i){
1329 && (level != m_topLev)) {
1331 m_vSurfToLevelMap[vSurfInd[i]].indexLower = vLevelInd[i];
1332 m_vSurfToLevelMap[vSurfInd[i]].levelLower = level;
1335 m_vSurfToLevelMap[vSurfInd[i]].index = vLevelInd[i];
1336 m_vSurfToLevelMap[vSurfInd[i]].level = level;
1337 m_vLevData[level]->vSurfLevelMap.push_back(
SurfLevelMap(vLevelInd[i], vSurfInd[i]));
1344 template <
typename TDomain,
typename TAlgebra>
1352 m_vSurfToLevelMap.resize(0);
1353 m_vSurfToLevelMap.resize(surfDD->num_indices());
1354 for(
int lev = m_baseLev; lev <= m_topLev; ++lev){
1355 m_vLevData[lev]->vShadowing.clear();
1356 m_vLevData[lev]->vSurfShadowing.clear();
1357 m_vLevData[lev]->vSurfLevelMap.clear();
1359 m_LocalFullRefLevel = std::numeric_limits<int>::max();
1361 if(surfDD->max_dofs(
VERTEX)) init_index_mappings<Vertex>();
1362 if(surfDD->max_dofs(
EDGE)) init_index_mappings<Edge>();
1363 if(surfDD->max_dofs(
FACE)) init_index_mappings<Face>();
1364 if(surfDD->max_dofs(
VOLUME)) init_index_mappings<Volume>();
1366 if(m_baseLev > m_LocalFullRefLevel)
1367 UG_THROW(
"GMG: Base level "<<m_baseLev<<
" does not cover whole grid. "
1368 <<
"Highest full-ref level is "<<m_LocalFullRefLevel);
1371 template <
typename TDomain,
typename TAlgebra>
1372 template <
typename TElem>
1379 iter_type iter = spNoGhostDD->begin<TElem>();
1380 iter_type iterEnd = spNoGhostDD->end<TElem>();
1383 std::vector<size_t> vGhostInd, vNoGhostInd;
1386 for( ; iter != iterEnd; ++iter){
1388 TElem* elem = *iter;
1391 spGhostDD->inner_algebra_indices(elem, vGhostInd);
1392 spNoGhostDD->inner_algebra_indices(elem, vNoGhostInd);
1393 UG_ASSERT(vGhostInd.size() == vNoGhostInd.size(),
"Number of indices does not match.");
1396 for(
size_t i = 0; i < vNoGhostInd.size(); ++i){
1397 vNoGhostToGhostMap[vNoGhostInd[i]] = vGhostInd[i];
1403 template <
typename TDomain,
typename TAlgebra>
1409 LevData& ld = *m_vLevData[lev];
1411 vMapPatchToGlobal.resize(0);
1416 if(spNoGhostDD == spGhostDD)
return;
1418 vMapPatchToGlobal.resize(spNoGhostDD->num_indices());
1420 if(spNoGhostDD->max_dofs(
VERTEX)) init_noghost_to_ghost_mapping<Vertex>(vMapPatchToGlobal, spNoGhostDD, spGhostDD);
1421 if(spNoGhostDD->max_dofs(
EDGE)) init_noghost_to_ghost_mapping<Edge>(vMapPatchToGlobal, spNoGhostDD, spGhostDD);
1422 if(spNoGhostDD->max_dofs(
FACE)) init_noghost_to_ghost_mapping<Face>(vMapPatchToGlobal, spNoGhostDD, spGhostDD);
1423 if(spNoGhostDD->max_dofs(
VOLUME)) init_noghost_to_ghost_mapping<Volume>(vMapPatchToGlobal, spNoGhostDD, spGhostDD);
1427 template <
typename TDomain,
typename TAlgebra>
1431 const std::vector<size_t>& vMapPatchToGlobal)
1435 if(spVecTo == spVecFrom)
1436 UG_THROW(
"GMG::copy_ghost_to_noghost: Should not be called on equal GF.");
1438 if(spVecTo->dd() == spVecFrom->dd())
1440 for(
size_t i = 0; i < spVecTo->size(); ++i)
1441 (*spVecTo)[i] = (*spVecFrom)[i];
1445 UG_ASSERT(vMapPatchToGlobal.size() == spVecTo->size(),
1446 "Mapping range ("<<vMapPatchToGlobal.size()<<
") != "
1447 "To-Vec-Size ("<<spVecTo->size()<<
")");
1449 for(
size_t i = 0; i < vMapPatchToGlobal.size(); ++i)
1450 (*spVecTo)[i] = (*spVecFrom)[ vMapPatchToGlobal[i] ];
1454 spVecTo->set_storage_type(spVecFrom->get_storage_mask());
1458 template <
typename TDomain,
typename TAlgebra>
1462 const std::vector<size_t>& vMapPatchToGlobal)
1466 if(spVecTo == spVecFrom)
1467 UG_THROW(
"GMG::copy_noghost_to_ghost: Should not be called on equal GF.");
1469 if(spVecTo->dd() == spVecFrom->dd())
1471 for(
size_t i = 0; i < spVecTo->size(); ++i)
1472 (*spVecTo)[i] = (*spVecFrom)[i];
1476 UG_ASSERT(vMapPatchToGlobal.size() == spVecFrom->size(),
1477 "Mapping domain ("<<vMapPatchToGlobal.size()<<
") != "
1478 "From-Vec-Size ("<<spVecFrom->size()<<
")");
1480 for(
size_t i = 0; i < vMapPatchToGlobal.size(); ++i)
1481 (*spVecTo)[ vMapPatchToGlobal[i] ] = (*spVecFrom)[i];
1484 spVecTo->set_storage_type(spVecFrom->get_storage_mask());
1488 template <
typename TDomain,
typename TAlgebra>
1492 const std::vector<size_t>& vMapPatchToGlobal)
1495 UG_ASSERT(vMapPatchToGlobal.size() == spMatFrom->num_rows(),
1496 "Mapping domain ("<<vMapPatchToGlobal.size()<<
") != "
1497 "From-Mat-Num-Rows ("<<spMatFrom->num_rows()<<
")");
1498 UG_ASSERT(vMapPatchToGlobal.size() == spMatFrom->num_cols(),
1499 "Mapping domain ("<<vMapPatchToGlobal.size()<<
") != "
1500 "From-Mat-Num-Cols ("<<spMatFrom->num_cols()<<
")");
1502 for(
size_t noghostFrom = 0; noghostFrom < vMapPatchToGlobal.size(); ++noghostFrom)
1504 typedef typename matrix_type::const_row_iterator row_iter;
1505 row_iter conn = spMatFrom->begin_row(noghostFrom);
1506 row_iter connEnd = spMatFrom->end_row(noghostFrom);
1507 for(; conn != connEnd; ++conn)
1510 size_t noghostTo = conn.index();
1512 (*spMatTo)(vMapPatchToGlobal[noghostFrom], vMapPatchToGlobal[noghostTo])
1527 template <
typename TDomain,
typename TAlgebra>
1533 m_vLevData.resize(0);
1534 m_vLevData.resize(topLev+1);
1536 for(
int lev = baseLev; lev <= topLev; ++lev)
1539 LevData& ld = *m_vLevData[lev];
1551 if( ld.
t->layouts()->vertical_slave().empty() &&
1552 ld.
t->layouts()->vertical_master().empty())
1561 ld.
PreSmoother = m_spPreSmootherPrototype->clone();
1562 if(m_spPreSmootherPrototype == m_spPostSmootherPrototype)
1573 ld.
Projection = m_spProjectionPrototype->clone();
1576 if(m_spProlongationPrototype == m_spRestrictionPrototype)
1579 ld.
Restriction = m_spRestrictionPrototype->clone();
1581 init_noghost_to_ghost_mapping(lev);
1584 bool bHasVertMaster =
false;
1585 bool bHasVertSlave =
false;
1586 bool bHasHorrMaster =
false;
1587 bool bHasHorrSlave =
false;
1589 LevData& ld = *m_vLevData[baseLev];
1590 if( !ld.
t->layouts()->vertical_master().empty()) bHasVertMaster =
true;
1591 if( !ld.
t->layouts()->vertical_slave().empty()) bHasVertSlave =
true;
1592 if( !ld.
t->layouts()->master().empty()) bHasHorrMaster =
true;
1593 if( !ld.
t->layouts()->slave().empty()) bHasHorrSlave =
true;
1595 bool bHasVertConn = bHasVertMaster || bHasVertSlave;
1596 bool bHasHorrConn = bHasHorrMaster || bHasHorrSlave;
1598 m_bGatheredBaseUsed = m_bGatheredBaseIfAmbiguous;
1604 if(!bHasVertConn) m_bGatheredBaseUsed =
false;
1607 if(!m_bGatheredBaseUsed
1609 && !m_spBaseSolver->supports_parallel())
1612 UG_THROW(
"GMG: base level distributed in parallel, without possibility"
1613 " to gather on one process, but chosen base solver is not"
1614 " parallel. Choose a parallel base solver.")
1616 m_bGatheredBaseUsed =
true;
1623 if(m_bGatheredBaseUsed){
1624 if(bHasVertMaster && bHasVertSlave)
1625 UG_THROW(
"GMG: Gathered base solver expects one proc to have all "
1626 "v-masters and no v-slaves. Use gmg:set_gathered_base_solver_if_ambiguous(false)"
1627 " to avoid this error.");
1629 if(!bHasVertConn && bHasHorrConn){
1630 UG_THROW(
"GMG: Base level distributed among processes and no possibility"
1631 " of gathering (vert. interfaces) present, but a gathering"
1632 " base solving is required. Use gmg:set_gathered_base_solver_if_ambiguous(false)"
1633 " to avoid this error.");
1637 if(bHasVertSlave && (ld.
t->layouts()->vertical_slave().num_interfaces() != 1))
1638 UG_THROW(
"GMG: Gathered base solver expects a v-slave containing "
1639 "process to send all its values to exactly on master. But "
1640 "more then one master detected. Use gmg:set_gathered_base_solver_if_ambiguous(false)"
1641 " to avoid this error.");
1643 if(bHasVertSlave && (ld.
t->layouts()->vertical_slave().num_interface_elements() != ld.
t->size()))
1644 UG_THROW(
"GMG: Gathered base solver expects that all indices "
1645 "are sent to exactly one master. But not all indices are "
1646 "v-slaves. Use gmg:set_gathered_base_solver_if_ambiguous(false)"
1647 " to avoid this error.");
1651 if(m_bGatheredBaseUsed && gathered_base_master()){
1655 spGatheredBaseCorr =
SmartPtr<GF>(
new GF(m_spApproxSpace, glGhosts,
false));
1660 spGatheredBaseCorr =
SPNULL;
1661 spGatheredBaseMat =
SPNULL;
1665 template <
typename TDomain,
typename TAlgebra>
1669 if(!m_bGatheredBaseUsed)
1670 UG_THROW(
"GMG: Should only be called when gather-base solver used.")
1673 if(!m_vLevData[m_baseLev]->t->layouts()->vertical_master().empty())
1685 template <
typename TDomain,
typename TAlgebra>
1690 LevData& lf = *m_vLevData[lev];
1691 LevData& lc = *m_vLevData[lev-1];
1695 mg_stats_defect(*lf.
sd, lev, mg_stats_type::BEFORE_PRE_SMOOTH);
1701 for(
int nu = 0; nu < m_numPreSmooth; ++nu)
1706 UG_THROW(
"GMG: Smoothing step "<<nu+1<<
" on level "<<lev<<
" failed.");
1707 leave_debug_writer_section(gw_gl);
1710 if(!m_bSmoothOnSurfaceRim){
1711 const std::vector<size_t>& vShadowing = lf.
vShadowing;
1712 for(
size_t i = 0; i < vShadowing.size(); ++i)
1713 (*lf.
st)[ vShadowing[i] ] = 0.0;
1715 if(lev > m_LocalFullRefLevel)
1726 lf.
A->apply_sub(*lf.
sd, *lf.
st);
1729 if(nu < m_numPreSmooth-1)
1730 (*lf.
sc) += (*lf.
st);
1737 log_debug_data(lev, lf.
n_restr_calls,
"AfterPreSmooth_BeforeCom");
1738 mg_stats_defect(*lf.
sd, lev, mg_stats_type::AFTER_PRE_SMOOTH);
1745 if( !lf.
t->layouts()->vertical_slave().empty() ||
1746 !lf.
t->layouts()->vertical_master().empty())
1764 m_Com.send_data(lf.
t->layouts()->vertical_slave(), cpVecAdd);
1765 m_Com.receive_data(lf.
t->layouts()->vertical_master(), cpVecAdd);
1766 m_Com.communicate_and_resume();
1768 if(!m_bCommCompOverlap){
1783 if(m_numPreSmooth > 0)
1784 (*lf.
sc) += (*lf.
st);
1788 if(m_bCommCompOverlap){
1804 UG_CATCH_THROW(
"GMG: Restriction from lev "<<lev<<
" to "<<lev-1<<
" failed.");
1809 for(
size_t i = 0; i < m_vspRestrictionPostProcess.size(); ++i)
1810 m_vspRestrictionPostProcess[i]->post_process(lc.
sd);
1812 leave_debug_writer_section(gw_gl);
1818 template <
typename TDomain,
typename TAlgebra>
1823 LevData& lf = *m_vLevData[lev];
1824 LevData& lc = *m_vLevData[lev-1];
1830 if(lev > m_LocalFullRefLevel)
1836 for(
size_t i = 0; i < vMap.size(); ++i){
1837 (*m_pC)[vMap[i].surfIndex] += (*lc.
sc)[vMap[i].levIndex];
1857 if( !lf.
t->layouts()->vertical_slave().empty() ||
1858 !lf.
t->layouts()->vertical_master().empty())
1867 UG_CATCH_THROW(
"GMG: Prolongation from lev "<<lev-1<<
" to "<<lev<<
" failed.");
1872 if( !lf.
t->layouts()->vertical_slave().empty() ||
1873 !lf.
t->layouts()->vertical_master().empty())
1882 m_Com.receive_data(lf.
t->layouts()->vertical_slave(), cpVecCopy);
1883 m_Com.send_data(lf.
t->layouts()->vertical_master(), cpVecCopy);
1884 m_Com.communicate();
1897 for(
size_t i = 0; i < m_vspProlongationPostProcess.size(); ++i)
1898 m_vspProlongationPostProcess[i]->post_process(lf.
st);
1901 leave_debug_writer_section(gw_gl);
1905 (*lf.
sc) += (*lf.
st);
1916 for(
int nu = 0; nu < m_numPostSmooth; ++nu)
1919 lf.
A->apply_sub(*lf.
sd, *lf.
st);
1923 mg_stats_defect(*lf.
sd, lev, mg_stats_type::BEFORE_POST_SMOOTH);
1929 UG_THROW(
"GMG: Smoothing step "<<nu+1<<
" on level "<<lev<<
" failed.");
1930 leave_debug_writer_section(gw_gl);
1933 if(!m_bSmoothOnSurfaceRim){
1934 const std::vector<size_t>& vShadowing = lf.
vShadowing;
1935 for(
size_t i = 0; i < vShadowing.size(); ++i)
1936 (*lf.
st)[ vShadowing[i] ] = 0.0;
1938 if(lev > m_LocalFullRefLevel)
1943 (*lf.
sc) += (*lf.
st);
1946 UG_CATCH_THROW(
"GMG: Post-Smoothing on level "<<lev<<
" failed. ")
1954 if(lev >= m_LocalFullRefLevel || m_mgstats.valid() || m_spDebugWriter.valid()){
1956 lf.
A->apply_sub(*lf.
sd, *lf.
st);
1961 mg_stats_defect(*lf.
sd, lev, mg_stats_type::AFTER_POST_SMOOTH);
1967 template <
typename TDomain,
typename TAlgebra>
1975 LevData& ld = *m_vLevData[lev];
1977 log_debug_data(lev, ld.
n_base_calls,
"BeforeBaseSolver");
1986 if(!m_bGatheredBaseUsed)
1993 if(!m_spBaseSolver->apply(*ld.
sc, *ld.
sd))
1994 UG_THROW(
"GMG::lmgc: Base solver on base level "<<lev<<
" failed.");
1997 leave_debug_writer_section(gw_gl);
2010 if( !ld.
t->layouts()->vertical_slave().empty() ||
2011 !ld.
t->layouts()->vertical_master().empty())
2020 m_Com.send_data(ld.
t->layouts()->vertical_slave(), cpVecAdd);
2021 m_Com.receive_data(ld.
t->layouts()->vertical_master(), cpVecAdd);
2022 m_Com.communicate();
2028 if(gathered_base_master())
2034 spGatheredBaseCorr->set(0.0);
2039 if(!m_spBaseSolver->apply(*spGatheredBaseCorr, *ld.
t))
2040 UG_THROW(
"GMG::lmgc: Base solver on base level "<<lev<<
" failed.");
2043 leave_debug_writer_section(gw_gl);
2052 if(gathered_base_master()) spC = spGatheredBaseCorr;
2056 m_Com.send_data(spC->layouts()->vertical_master(), cpVecCopy);
2057 m_Com.receive_data(spC->layouts()->vertical_slave(), cpVecCopy);
2058 m_Com.communicate();
2060 if(gathered_base_master()){
2075 if(lev >= m_LocalFullRefLevel){
2077 ld.
A->apply_sub(*ld.
sd, *ld.
sc);
2081 log_debug_data(lev, ld.
n_base_calls,
"AfterBaseSolver");
2089 template <
typename TDomain,
typename TAlgebra>
2091 lmgc(
int lev,
int cycleType)
2097 if(lev == m_baseLev) {
2098 base_solve(m_topLev);
2100 }
else if(lev < m_baseLev){
2101 UG_THROW(
"GMG::lmgc: call lmgc only for lev > baseLev.");
2106 presmooth_and_restriction(lev);
2108 UG_CATCH_THROW(
"GMG::lmgc: presmooth-restriction failed on level "<<lev);
2112 if(lev-1 == m_baseLev) {
2116 else if(cycleType == _F_){
2122 for(
int i = 0; i < cycleType; ++i)
2123 lmgc(lev-1, cycleType);
2126 UG_CATCH_THROW(
"GMG::lmgc: Linear multi-grid cycle on level "<<lev-1<<
2127 " failed. (BaseLev="<<m_baseLev<<
", TopLev="<<m_topLev<<
").");
2131 prolongation_and_postsmooth(lev);
2133 UG_CATCH_THROW(
"GMG::lmgc: prolongation-postsmooth failed on level "<<lev);
2142 template <
typename TDomain,
typename TAlgebra>
2146 write_debug(*spGF,
name, cycleNo);
2149 template <
typename TDomain,
typename TAlgebra>
2155 if(m_spDebugWriter.invalid())
return;
2159 std::stringstream ss;
2161 ss <<
"_i" << std::setfill(
'0') << std::setw(3) << m_dbgIterCnt;
2162 if (cycleNo >= 0) ss <<
"_cycle" << std::setfill(
'0') << std::setw(3) << cycleNo;
2166 GridLevel currGL = m_spDebugWriter->grid_level();
2167 m_spDebugWriter->set_grid_level(gl);
2168 m_spDebugWriter->write_vector(rGF, ss.str().c_str());
2169 m_spDebugWriter->set_grid_level(currGL);
2172 template <
typename TDomain,
typename TAlgebra>
2178 write_debug(mat,
name, glTo, glFrom);
2181 template <
typename TDomain,
typename TAlgebra>
2187 if(m_spDebugWriter.invalid())
return;
2190 std::stringstream ss;
2196 GridLevel currGL = m_spDebugWriter->grid_level();
2197 m_spDebugWriter->set_grid_levels(glFrom, glTo);
2198 m_spDebugWriter->write_matrix(mat, ss.str().c_str());
2199 m_spDebugWriter->set_grid_level(currGL);
2202 template <
typename TDomain,
typename TAlgebra>
2208 if(m_spDebugWriter.invalid())
return;
2210 dw_orig_gl = m_spDebugWriter->grid_level();
2211 m_spDebugWriter->set_grid_level(m_vLevData[lev]->sd->grid_level());
2213 std::stringstream ss;
2214 ss <<
"GMG_" << sec_name;
2215 ss <<
"_i" << std::setfill(
'0') << std::setw(3) << m_dbgIterCnt;
2216 if (cycleNo >= 0) ss <<
"_cycle" << std::setfill(
'0') << std::setw(3) << cycleNo;
2218 if (callNo >= 0) ss <<
"_call" << std::setfill(
'0') << std::setw(3) << callNo;
2219 m_spDebugWriter->enter_section(ss.str().c_str());
2222 template <
typename TDomain,
typename TAlgebra>
2226 if(m_spDebugWriter.invalid())
return;
2227 m_spDebugWriter->leave_section();
2228 m_spDebugWriter->set_grid_level(dw_orig_gl);
2231 template <
typename TDomain,
typename TAlgebra>
2235 if(m_spDebugWriter.valid()){
2236 std::string defName(
"Def_"); defName.append(
name);
2237 std::string curName(
"Cor_"); curName.append(
name);
2238 write_debug(m_vLevData[lvl]->sd, defName, cycleNo);
2239 write_debug(m_vLevData[lvl]->sc, curName, cycleNo);
2242 const bool bEnableSerialNorm =
false;
2243 const bool bEnableParallelNorm =
false;
2245 if(!bEnableSerialNorm && !bEnableParallelNorm)
return;
2248 if(lvl < (
int)m_vLevData.size())
2249 prefix.assign(2 + 2 * (m_vLevData.size() - lvl),
' ');
2250 prefix.append(
name).append(
" on lev ").append(
ToString(lvl)).append(
": ");
2252 LevData& ld = *m_vLevData[lvl];
2253 if(bEnableSerialNorm){
2254 UG_LOG(prefix <<
"local sd norm: " << sqrt(
VecProd(*ld.
sd, *ld.
sd)) << std::endl);
2255 UG_LOG(prefix <<
"local sc norm: " << sqrt(
VecProd(*ld.
sc, *ld.
sc)) << std::endl);
2257 if(bEnableParallelNorm){
2259 uint oldStorageMask = ld.
sd->get_storage_mask();
2261 UG_LOG(prefix <<
"sd norm: " << norm <<
"\n");
2267 oldStorageMask = ld.
sc->get_storage_mask();
2268 norm = ld.
sc->norm();
2269 UG_LOG(prefix <<
"sc norm: " << norm <<
"\n");
2295 template <
typename TDomain,
typename TAlgebra>
2299 if(m_mgstats.valid())
2300 m_mgstats->set_defect(gf, lvl, stage);
2303 template <
typename TDomain,
typename TAlgebra>
2308 std::stringstream ss;
2309 ss <<
"GeometricMultigrid (";
2310 if(m_cycleType == _V_) ss <<
"V-Cycle";
2311 else if(m_cycleType == _W_) ss <<
"W-Cycle";
2312 else if(m_cycleType == _F_) ss <<
"F-Cycle";
2313 else ss <<
" " << m_cycleType <<
"-Cycle";
2316 if(m_spPreSmootherPrototype==m_spPostSmootherPrototype)
2317 ss <<
" Smoother (" << m_numPreSmooth <<
"x pre, " << m_numPostSmooth <<
"x post): "
2318 <<
ConfigShift(m_spPreSmootherPrototype->config_string());
2321 ss <<
" Presmoother (" << m_numPreSmooth <<
"x): " <<
ConfigShift(m_spPreSmootherPrototype->config_string());
2322 ss <<
" Postsmoother ( " << m_numPostSmooth <<
"x): " <<
ConfigShift(m_spPostSmootherPrototype->config_string());
2325 ss <<
" Basesolver ( Baselevel = " << m_baseLev <<
", gathered base = " << (m_bGatheredBaseIfAmbiguous ?
"true" :
"false") <<
"): ";
2326 ss <<
ConfigShift(m_spBaseSolver->config_string());
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
Definition: pcl_process_communicator.h:70
Extends the HorizontalAlgebraLayouts by vertical layouts.
Definition: algebra_layouts.h:121
base class for approximation spaces without type of algebra or dof distribution
Definition: approximation_space.h:279
geometric multi grid preconditioner
Definition: mg_solver.h:84
void init_transfer()
initializes the transfers
Definition: mg_solver_impl.hpp:1078
void write_debug(ConstSmartPtr< GF > spGF, std::string name, int cycleNo=-1)
writes debug output for a level vector only on smooth path
Definition: mg_solver_impl.hpp:2144
void leave_debug_writer_section(GridLevel &orig_gl)
leaves the current debugger section
Definition: mg_solver_impl.hpp:2224
bool gathered_base_master() const
returns if gathered base master
Definition: mg_solver_impl.hpp:1667
void base_solve(int lev)
compute base solver
Definition: mg_solver_impl.hpp:1969
void init_rap_rim_cpl()
operator to invert (surface grid)
Definition: mg_solver_impl.hpp:1017
void assemble_level_operator()
initializes the coarse grid matrices
Definition: mg_solver_impl.hpp:528
algebra_type::vector_type vector_type
Vector type.
Definition: mg_solver.h:93
void set_approximation_space(SmartPtr< ApproximationSpace< TDomain > > approxSpace)
sets the approximation space
Definition: mg_solver_impl.hpp:128
virtual std::string config_string() const
returns information about configuration parameters
Definition: mg_solver_impl.hpp:2306
void init()
initializes common part
Definition: mg_solver_impl.hpp:380
void init_smoother()
initializes the smoother and base solver
Definition: mg_solver_impl.hpp:1137
void init_rap_operator()
operator to invert (surface grid)
Definition: mg_solver_impl.hpp:830
void init_index_mappings()
operator to invert (surface grid)
Definition: mg_solver_impl.hpp:1234
void init_base_solver()
initializes the smoother and base solver
Definition: mg_solver_impl.hpp:1173
void init_level_memory(int baseLev, int topLev)
allocates the memory
Definition: mg_solver_impl.hpp:1529
void copy_ghost_to_noghost(SmartPtr< GF > spVecTo, ConstSmartPtr< GF > spVecFrom, const std::vector< size_t > &vMapPatchToGlobal)
copies vector to smoothing patch using cached mapping
Definition: mg_solver_impl.hpp:1429
virtual bool ignore_init_for_base_solver() const
operator to invert (surface grid)
Definition: mg_solver_impl.hpp:512
void log_debug_data(int lvl, int cycleNo, std::string name)
logs a level-data-struct to the terminal
Definition: mg_solver_impl.hpp:2233
void mg_stats_defect(GF &gf, int lvl, typename mg_stats_type::Stage stage)
Calls MGStats::set_defect (if available) with the given parameters.
Definition: mg_solver_impl.hpp:2297
virtual bool apply_update_defect(vector_type &c, vector_type &d)
Compute new correction c = B*d and return new defect d := d - A*c.
Definition: mg_solver_impl.hpp:279
void init_projection()
initializes the prolongation
Definition: mg_solver_impl.hpp:1117
~AssembledMultiGridCycle()
Destructor.
Definition: mg_solver_impl.hpp:167
void enter_debug_writer_section(GridLevel &orig_gl, const char *sec_name, int lev, int cycleNo=-1, int callNo=-1)
enters a new debugger section for smoothers, base solver etc
Definition: mg_solver_impl.hpp:2204
void init_noghost_to_ghost_mapping(std::vector< size_t > &vNoGhostToGhostMap, ConstSmartPtr< DoFDistribution > spNoGhostDD, ConstSmartPtr< DoFDistribution > spGhostDD)
Definition: mg_solver_impl.hpp:1374
AssembledMultiGridCycle()
constructor without arguments
Definition: mg_solver_impl.hpp:79
algebra_type::matrix_type matrix_type
Matrix type.
Definition: mg_solver.h:96
void assemble_rim_cpl(const vector_type *u)
Definition: mg_solver_impl.hpp:756
void presmooth_and_restriction(int lev)
performs presmoothing on the given level
Definition: mg_solver_impl.hpp:1687
SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition: mg_solver_impl.hpp:137
void force_reinit()
reinit transfer operators
Definition: mg_solver_impl.hpp:520
void prolongation_and_postsmooth(int lev)
performs prolongation to the level above
Definition: mg_solver_impl.hpp:1820
void lmgc(int lev, int cycleType)
compute correction on level and update defect
Definition: mg_solver_impl.hpp:2091
virtual bool apply(vector_type &c, const vector_type &d)
Compute new correction c = B*d.
Definition: mg_solver_impl.hpp:176
void copy_noghost_to_ghost(SmartPtr< GF > spVecTo, ConstSmartPtr< GF > spVecFrom, const std::vector< size_t > &vMapPatchToGlobal)
copies vector from smoothing patch using cached mapping
Definition: mg_solver_impl.hpp:1460
Comm-Pol to add matrix rows of inner-interface couplings.
Definition: communication_policies.h:1396
Communication Policy to add values of a vector and reset value to zero on sending interface.
Definition: communication_policies.h:564
Communication Policy to copy values of a vector.
Definition: communication_policies.h:88
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
SmartPtr< DoFDistribution > dof_distribution()
Definition: grid_function.h:236
const GridLevel & grid_level() const
returns the grid level
Definition: grid_function.h:247
Definition: grid_level.h:42
@ TOP
Definition: grid_level.h:45
@ SURFACE
Definition: grid_level.h:48
@ LEVEL
Definition: grid_level.h:48
A preconditioner for the multi-grid context which is aware of the grid level it operates on.
Definition: level_preconditioner_interface.h:47
void set_grid_level(const GridLevel &gl)
set the grid level
Definition: level_preconditioner_interface.h:62
describes a linear mapping X->Y
Definition: linear_operator.h:80
Jacobi-Iteration.
Definition: jacobi.h:91
Stage
Defines at which stage data is recorded in a given multigrid cycle.
Definition: mg_stats.h:51
Definition: matrix_operator.h:49
void set_storage_type(uint type)
sets the storage type
Definition: parallel_matrix.h:101
void set_layouts(ConstSmartPtr< AlgebraLayouts > layouts)
sets the algebra layouts
Definition: parallel_matrix.h:97
ConstSmartPtr< AlgebraLayouts > layouts() const
returns the algebra layouts
Definition: parallel_matrix.h:94
uint get_storage_mask() const
returns storage type mask
Definition: parallel_matrix.h:120
Definition: periodic_boundary_manager.h:99
bool is_slave(TElem *) const
Definition: periodic_boundary_manager_impl.hpp:498
Definition: std_injection.h:61
Standard Prolongation Operator.
Definition: std_transfer.h:59
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
@ MG_SURFACE_RIM
surface, i.e., without children (at rim)
Definition: surface_view.h:76
@ ALL
Definition: surface_view.h:102
@ MG_SHADOW_RIM_COPY
covered (at rim) with identical child
Definition: surface_view.h:77
void SetLayoutValues(TVector *pVec, const IndexLayout &layout, typename TVector::value_type val)
sets the values of a vector to a given number only on the layout indices
Definition: parallelization_util.h:315
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
@ PST_ADDITIVE
Definition: parallel_storage_type.h:69
void AddMultiplyOf(ABC_type &M, const A_type &A, const B_type &B, const C_type &C, double epsilonTruncation=0.0)
Calculates M += A*B*C.
Definition: sparsematrix_util.h:167
void SetRow(TSparseMatrix &A, size_t i, size_t alpha, number val=0.0)
Definition: sparsematrix_util.h:710
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
@ PCD_LOCAL
Definition: pcl_process_communicator.h:56
std::string ToString(const T &t)
Convert a object supporting 'std::cout << obj' to a string.
Definition: string_util.h:362
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
#define UG_DLOG(__debugID__, level, msg)
Definition: log.h:298
#define UG_LOG(msg)
Definition: log.h:367
unsigned int uint
Definition: types.h:114
DebugID LIB_DISC_MULTIGRID
Definition: debug_id.h:120
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
#define GMG_PROFILE_BEGIN(name)
Definition: mg_solver_impl.hpp:63
#define GMG_PROFILE_FUNC()
Definition: mg_solver_impl.hpp:62
#define GMG_PROFILE_END()
Definition: mg_solver_impl.hpp:64
string ConfigShift(string s)
Definition: string_util.cpp:457
std::string GridLevelAppendix(const GridLevel &gl, int minfill)
returns appendix for a grid level
Definition: grid_level.cpp:56
double VecProd(const double &a, const double &b)
returns scal<a, b>
Definition: operations_vec.h:84
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
T value_type
Definition: sparsematrix_interface.h:2
Definition: mg_solver.h:418
SmartPtr< ITransferOperator< TDomain, TAlgebra > > Restriction
Definition: mg_solver.h:431
SmartPtr< GF > sc
vectors needed (sx = no-ghosts [for smoothing], t = for transfer)
Definition: mg_solver.h:434
SmartPtr< MatrixOperator< matrix_type, vector_type > > A
Level matrix operator.
Definition: mg_solver.h:420
std::vector< size_t > vSurfShadowing
list of corresponding surface index to shadowing indices
Definition: mg_solver.h:443
SmartPtr< ITransferOperator< TDomain, TAlgebra > > Projection
Projection operator.
Definition: mg_solver.h:427
int n_prolong_calls
Definition: mg_solver.h:455
matrix_type RimCpl_Coarse_Fine
missing coarse grid correction
Definition: mg_solver.h:452
int n_restr_calls
Definition: mg_solver.h:455
SmartPtr< ITransferOperator< TDomain, TAlgebra > > Prolongation
Transfer operator.
Definition: mg_solver.h:430
SmartPtr< ILinearIterator< vector_type > > PostSmoother
Definition: mg_solver.h:424
SmartPtr< ILinearIterator< vector_type > > PreSmoother
Smoother.
Definition: mg_solver.h:423
SmartPtr< GF > t
Definition: mg_solver.h:434
int n_post_calls
Definition: mg_solver.h:455
std::vector< size_t > vShadowing
list of shadowing indices
Definition: mg_solver.h:440
std::vector< SurfLevelMap > vSurfLevelMap
map surface to level
Definition: mg_solver.h:446
matrix_type RimCpl_Fine_Coarse
missing coarse grid correction
Definition: mg_solver.h:449
SmartPtr< GF > sd
Definition: mg_solver.h:434
int n_pre_calls
debugging output information (number of calls of the pre-, postsmoothers, base solver etc)
Definition: mg_solver.h:455
SmartPtr< GF > st
Definition: mg_solver.h:434
int n_base_calls
Definition: mg_solver.h:455
std::vector< size_t > vMapPatchToGlobal
maps global indices (including ghosts) to patch indices (no ghosts included).
Definition: mg_solver.h:437
Definition: mg_solver.h:409
function ProblemDisc new(problemDesc, dom)