38 #ifndef __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NL_GAUSS_SEIDEL__NL_GAUSS_SEIDEL_IMPL_H_
39 #define __H__UG__LIB_DISC__OPERATOR__NON_LINEAR_OPERATOR__NL_GAUSS_SEIDEL__NL_GAUSS_SEIDEL_IMPL_H_
48 #define PROFILE_NL_GAUSSSEIDEL
49 #ifdef PROFILE_NL_GAUSSSEIDEL
50 #define NL_GAUSSSEIDEL_PROFILE_FUNC() PROFILE_FUNC_GROUP("NL GaussSeidel")
51 #define NL_GAUSSSEIDEL_PROFILE_BEGIN(name) PROFILE_BEGIN_GROUP(name, "NL GaussSeidel")
52 #define NL_GAUSSSEIDEL_PROFILE_END() PROFILE_END()
54 #define NL_GAUSSSEIDEL_PROFILE_FUNC()
55 #define NL_GAUSSSEIDEL_PROFILE_BEGIN(name)
56 #define NL_GAUSSSEIDEL_PROFILE_END()
62 template <
typename TAlgebra>
69 for(
size_t dof=0; dof < lvec.
num_all_dof(fct); ++dof)
71 const size_t index = ind.
index(fct,dof);
72 if (index == m_assemblingIndex)
74 const size_t comp = ind.
comp(fct,dof);
81 template <
typename TAlgebra>
91 const size_t rowIndex = rowInd.
index(fct1,dof1);
93 if (rowIndex == m_assemblingIndex)
95 const size_t rowComp = rowInd.
comp(fct1,dof1);
99 const size_t colIndex = colInd.
index(fct2,dof2);
100 if (colIndex == m_assemblingIndex)
102 const size_t colComp = colInd.
comp(fct2,dof2);
103 BlockRef(mat(0, 0), rowComp, colComp)
104 += lmat.
value(fct1,dof1,fct2,dof2);
112 template <
typename TDomain,
typename TAlgebra>
116 m_spApproxSpace(spApproxSpace),
117 m_spConvCheck(spConvCheck),
119 m_bProjectedGS(false),
123 template <
typename TDomain,
typename TAlgebra>
126 m_spApproxSpace(NULL),
129 m_bProjectedGS(false),
134 template <
typename TDomain,
typename TAlgebra>
138 m_spConvCheck = spConvCheck;
139 m_spConvCheck->set_offset(3);
140 m_spConvCheck->set_symbol(
'#');
141 m_spConvCheck->set_name(
"Nonlinear Gauss Seidel Solver");
144 template <
typename TDomain,
typename TAlgebra>
150 m_spAssOp = op.template cast_dynamic<AssembledOperator<TAlgebra> >();
151 if(m_spAssOp.invalid())
152 UG_THROW(
"NLGaussSeidelSolver: currently only works for AssembledDiscreteOperator.");
154 m_spAss = m_spAssOp->discretization();
155 if(m_spAss.invalid())
156 UG_THROW(
"AssembledLinearOperator: Assembling routine not set.");
159 if(m_spApproxSpace.invalid())
160 UG_THROW(
"NLGaussSeidelSolver::prepare: Approximation Space not set.");
162 m_gridLevel = m_spAssOp->level();
166 m_spLevDD = m_spApproxSpace->dof_distribution(m_gridLevel);
168 m_spSurfDD = m_spApproxSpace->dof_distribution(m_gridLevel);
170 UG_THROW(
"Grid Level not recognized.");
182 template <
typename TDomain,
typename TAlgebra>
190 if(m_spApproxSpace.invalid())
191 UG_THROW(
"NLGaussSeidelSolver::apply: Approximation Space not set.");
194 if(m_spLevDD.invalid() && m_spSurfDD.invalid())
195 UG_THROW(
"NLGaussSeidelSolver::apply: DoFDistribution not set."
196 " 'NLGaussSeidelSolver::init'-call is necessary!");
199 TDomain& dom = *m_spApproxSpace->domain();
200 typename TDomain::grid_type& grid = *dom.grid();
203 typedef typename TDomain::grid_type::template traits<grid_base_object>::iterator
206 ElemIter iterBegin = grid.template begin<grid_base_object>(grid.top_level());
207 ElemIter iterEnd = grid.template end<grid_base_object>(grid.top_level());
209 typedef typename elemList::iterator ListIter;
225 m_vElemList.resize(u.size());
228 for(ElemIter elemIter = iterBegin; elemIter != iterEnd; ++elemIter)
234 m_spLevDD->indices(elem, ind);
236 m_spSurfDD->indices(elem, ind);
238 UG_THROW(
"Grid Level not recognized.");
243 bool elemInList =
false;
246 for(
size_t dof=0; dof < locU.
num_all_dof(fct); ++dof)
248 size_t globIndex = ind.
index(fct,dof);
251 for(ListIter listIter = m_vElemList[globIndex].begin();
252 listIter != m_vElemList[globIndex].end(); ++listIter)
253 if (*listIter == *elemIter)
258 if (!elemInList) m_vElemList[globIndex].push_back(*elemIter);
267 template <
typename TDomain,
typename TAlgebra>
275 if(m_spApproxSpace.invalid())
276 UG_THROW(
"NLGaussSeidelSolver::apply: Approximation Space not set.");
279 if(m_spLevDD.invalid() && m_spSurfDD.invalid())
280 UG_THROW(
"NLGaussSeidelSolver::apply: DoFDistribution not set."
281 " 'NLGaussSeidelSolver::init'-call is necessary!");
284 if(m_spJBlock.invalid() || m_spJBlock->discretization() != m_spAss) {
286 m_spJBlock->set_level(m_gridLevel);
295 (*spC).resize(1); (*spDBlock).resize(1);
299 m_spAssOp->prepare(u);
301 UG_CATCH_THROW(
"NLGaussSeidelSolver::apply: Prepare of Operator failed.");
306 m_spAssOp->apply(*spD, u);
309 "Computation of Start-Defect failed.");
313 char ext[20]; snprintf(ext,
sizeof(ext),
"_iter%03d", loopCnt);
314 std::string
name(
"NLGaussSeidel_Defect");
316 write_debug(*spD,
name.c_str());
317 write_debug(u,
"NLGaussSeidel_StartSolution");
320 m_spConvCheck->start(*spD);
323 TDomain& dom = *m_spApproxSpace->domain();
324 typename TDomain::grid_type& grid = *dom.grid();
325 m_sel.assign_grid(grid);
330 while(!m_spConvCheck->iteration_ended())
333 m_spAss->ass_tuner()->set_mapping(&m_map);
336 for (
size_t i = 0; i < u.size(); i++)
343 m_sel.select(m_vElemList[i].begin(), m_vElemList[i].end());
347 m_spAss->ass_tuner()->set_selector(&m_sel);
350 m_spAss->ass_tuner()->set_single_index_assembling(i);
351 m_map.set_assembling_index(i);
358 "Initialization of Jacobian failed.");
362 m_spAssOp->apply(*spDBlock, u);
431 m_spAss->ass_tuner()->set_mapping();
432 m_spAss->ass_tuner()->set_selector();
433 m_spAss->ass_tuner()->disable_single_index_assembling();
436 m_spAssOp->prepare(u);
437 m_spAssOp->apply(*spD, u);
442 snprintf(ext,
sizeof(ext),
"_iter%03d", loopCnt);
445 m_spConvCheck->update(*spD);
448 std::string
name(
"NLGaussSeidel_Defect");
name.append(ext);
449 write_debug(*spD,
name.c_str());
452 return m_spConvCheck->post();
455 template <
typename TDomain,
typename TAlgebra>
459 std::string
name(filename);
460 char ext[20]; snprintf(ext,
sizeof(ext),
"_call%03d", m_dgbCall);
461 name.append(ext).append(
".vec");
464 base_writer_type::write_debug(vec,
name.c_str());
467 template <
typename TDomain,
typename TAlgebra>
471 std::string
name(filename);
472 char ext[20]; snprintf(ext,
sizeof(ext),
"_call%03d", m_dgbCall);
473 name.append(ext).append(
".mat");
476 base_writer_type::write_debug(mat,
name.c_str());
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
matrix operator based on the assembling of a problem
Definition: assembled_linear_operator.h:60
TAlgebra::vector_type vector_type
type of vector
Definition: debug_writer.h:360
TAlgebra::matrix_type matrix_type
type of matrix
Definition: debug_writer.h:363
@ SURFACE
Definition: grid_level.h:48
@ LEVEL
Definition: grid_level.h:48
Definition: convergence_check.h:72
describes a mapping X->Y
Definition: operator.h:86
Definition: local_algebra.h:50
index_type index(size_t fct, size_t dof) const
global algebra index for (fct, dof)
Definition: local_algebra.h:139
comp_type comp(size_t fct, size_t dof) const
algebra comp for (fct, dof)
Definition: local_algebra.h:153
Definition: local_algebra.h:422
size_t num_all_col_fct() const
returns the number of all functions
Definition: local_algebra.h:627
size_t num_all_row_fct() const
returns the number of all functions
Definition: local_algebra.h:624
number & value(size_t rowFct, size_t rowDoF, size_t colFct, size_t colDoF)
access to coupling (rowFct, rowDoF) x (colFct, colDoF)
Definition: local_algebra.h:636
size_t num_all_col_dof(size_t fct) const
returns the number of dofs for a function
Definition: local_algebra.h:633
size_t num_all_row_dof(size_t fct) const
returns the number of dofs for a function
Definition: local_algebra.h:630
const LocalIndices & get_col_indices() const
get current local indices
Definition: local_algebra.h:470
const LocalIndices & get_row_indices() const
get current local indices
Definition: local_algebra.h:467
algebra_type::matrix_type matrix_type
Type of algebra matrix.
Definition: nl_gauss_seidel.h:58
void add_local_vec_to_global(vector_type &vec, const LocalVector &lvec, ConstSmartPtr< DoFDistribution > dd)
adds a local vector to the global rhs
Definition: nl_gauss_seidel_impl.h:63
void add_local_mat_to_global(matrix_type &mat, const LocalMatrix &lmat, ConstSmartPtr< DoFDistribution > dd)
adds a local matrix to the global matrix
Definition: nl_gauss_seidel_impl.h:82
algebra_type::vector_type vector_type
Type of algebra vector.
Definition: nl_gauss_seidel.h:61
Definition: local_algebra.h:198
const LocalIndices & get_indices() const
get current local indices
Definition: local_algebra.h:225
size_t num_all_fct() const
returns the number of all functions
Definition: local_algebra.h:370
number & value(size_t fct, size_t dof)
access to dof of a fct (unrestricted functions)
Definition: local_algebra.h:376
void resize(const LocalIndices &ind)
resize for current local indices
Definition: local_algebra.h:214
size_t num_all_dof(size_t fct) const
returns the number of dofs for a function (unrestricted functions)
Definition: local_algebra.h:373
virtual bool prepare(vector_type &u)
prepare Operator
Definition: nl_gauss_seidel_impl.h:183
virtual bool init(SmartPtr< IOperator< vector_type > > op)
This operator inverts the Operator op: Y -> X.
Definition: nl_gauss_seidel_impl.h:147
NLGaussSeidelSolver()
constructor
Definition: nl_gauss_seidel_impl.h:125
domain_traits< TDomain::dim >::grid_base_object grid_base_object
Type of geometric base object.
Definition: nl_gauss_seidel.h:146
virtual bool apply(vector_type &u)
apply Operator, i.e. op^{-1}(0) = u
Definition: nl_gauss_seidel_impl.h:268
void set_convergence_check(SmartPtr< IConvergenceCheck< vector_type > > spConvCheck)
Definition: nl_gauss_seidel_impl.h:136
void write_debug(const vector_type &vec, const char *filename)
Definition: nl_gauss_seidel_impl.h:456
Definition: convergence_check.h:179
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
double & BlockRef(T &vec, size_t i)
Definition: blocks.h:66
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
#define NL_GAUSSSEIDEL_PROFILE_BEGIN(name)
Definition: nl_gauss_seidel_impl.h:51
#define NL_GAUSSSEIDEL_PROFILE_END()
Definition: nl_gauss_seidel_impl.h:52
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
Definition: domain_traits.h:53
function ProblemDisc new(problemDesc, dom)