37 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ELEMENT_GAUSS_SEIDEL__
38 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ELEMENT_GAUSS_SEIDEL__
55 template<
typename TGroupObj,
typename TDomain,
typename TAlgebra>
58 const typename TAlgebra::vector_type& d,
61 ,
const std::vector<std::string>& cmp,
number alpha,
bool elim_off_diag=
false
65 typedef typename TAlgebra::matrix_type::const_row_iterator const_row_iterator;
66 const static int blockSize = TAlgebra::blockSize;
72 std::vector<size_t> vInd;
80 std::vector<Element*> vElem;
84 for(GroupObjIter iter = c.template begin<TGroupObj>();
85 iter != c.template end<TGroupObj>(); ++iter){
88 TGroupObj* groupObj = *iter;
95 for(
size_t i = 0; i < vElem.size(); ++i)
100 std::sort(vInd.begin(), vInd.end());
101 vInd.erase(std::unique(vInd.begin(), vInd.end()), vInd.end());
105 const size_t numIndex = vInd.size();
109 mat.resize(numIndex, numIndex);
111 for (
size_t j = 0; j<numIndex; j++){
112 for (
size_t k=0;k<numIndex;k++){
113 const_row_iterator it = A.get_connection(vInd[j],vInd[k], bFound);
115 mat.
subassign(j*blockSize,k*blockSize,it.value());
123 for (
size_t j = 0; j<numIndex; j++)
126 for(const_row_iterator it = A.begin_row(vInd[j]); it != A.end_row(vInd[j]) ; ++it)
128 MatMultAdd(sj, 1.0, sj, -1.0, it.value(), c[it.index()]);
131 s.subassign(j*blockSize,sj);
142 std::vector<size_t> vFct;
143 for(
size_t i = 0; i < cmp.size(); ++i)
144 vFct.push_back(ddinfo->fct_id_by_name(cmp[i].c_str()));
148 weights.resize(numIndex);
152 std::vector<DoFIndex> vSchurDoFIndex;
153 c.
dof_indices(groupObj, vFct[0], vSchurDoFIndex,
true);
156 UG_ASSERT(blockSize==1,
"Element GS: Elimination does only work for blockSize==1!")
158 std::vector<size_t> vIndElim;
161 const size_t numElim = vSchurDoFIndex.size();
162 for (
size_t j = 0; j<numElim; j++)
164 vIndElim.push_back(vSchurDoFIndex[j][0]);
167 std::vector<size_t> mapElim;
168 std::vector<size_t> mapKeep;
171 for (
size_t j = 0; j<numIndex; j++)
173 std::vector<size_t>::iterator it =
find (vIndElim.begin(), vIndElim.end(), vInd[j]);
174 if (it != vIndElim.end()) {
176 mapElim.push_back(j);
179 mapKeep.push_back(j);
183 const size_t numKeep = mapKeep.size();
184 UG_ASSERT((numElim+numKeep == numIndex),
"Map elim does not match!");
185 UG_ASSERT(mapElim.size()==numElim,
"Map elim does not match!");
186 UG_ASSERT(mapKeep.size()==numKeep,
"Map mon elim does not match!");
191 matKeep.resize(numKeep, numKeep);
193 for (
size_t j = 0; j<numKeep; j++)
195 for (
size_t k=0;k<numKeep;k++)
197 matKeep(j,k) = mat(mapKeep[j], mapKeep[k]);
215 for (
size_t j = 0; j<numElim; j++)
217 for (
size_t k=0; k<numKeep; k++)
219 schur_cj[k] = mat(mapKeep[k], mapElim[j]);
224 for (
size_t i = 0; i<numElim; i++)
228 for (
size_t k=0; k<numKeep; k++)
230 number schur_bik = mat(mapElim[i], mapKeep[k]);
231 matElim(i,j) += schur_bik*schur_yj[k];
237 mat(mapElim[i], mapElim[j]) -=
alpha*matElim(i,j);
251 for (
size_t j = 0; j<numElim; j++)
253 for (
size_t k=0; k<numKeep; k++)
255 mat(mapElim[j], mapKeep[k]) = 0.0;
256 mat(mapKeep[k], mapElim[j]) = 0.0;
259 for (
size_t k=0; k<numElim; k++)
263 mat(mapElim[j], mapElim[k]) = 0.0;
264 mat(mapElim[k], mapElim[j]) = 0.0;
273 for (
size_t i = 0; i<numElim; i++)
275 for (
size_t j=0; j<numElim; j++)
277 mat(mapElim[i], mapElim[j]) *=
alpha;
292 for (
size_t j=0;j<numIndex;j++)
294 c[vInd[j]] += relax*x[j];
303 template <
typename TDomain,
typename TAlgebra>
348 newInst->set_damp(this->
damping());
350 newInst->set_type(
m_type);
380 virtual const char*
name()
const {
return "ElementGaussSeidel";}
404 UG_THROW(
"ElementGaussSeidel expects correction to be a GridFunction.");
419 else UG_THROW(
"ElementGaussSeidel: wrong patch type '"<<
m_type<<
"'."
420 " Options: element, side, face, edge, vertex.");
436 else UG_THROW(
"ElementGaussSeidel: wrong patch type '"<<
m_type<<
"'."
437 " Options: element, side, face, edge, vertex.")
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
virtual void set_debug(SmartPtr< IDebugWriter< algebra_type > > spDebugWriter)
set debug writer
Definition: debug_writer.h:384
void write_debug(const matrix_type &mat, const char *filename)
write debug output for a matrix (if debug writer set)
Definition: debug_writer.h:399
TAlgebra::vector_type vector_type
type of vector
Definition: debug_writer.h:360
SmartPtr< IDebugWriter< algebra_type > > debug_writer()
returns the debug writer
Definition: debug_writer.h:391
TAlgebra::matrix_type matrix_type
type of matrix
Definition: debug_writer.h:363
Definition: densematrix.h:57
void subassign(size_t r, size_t c, const TStorage2 &t)
Definition: densematrix.h:215
Definition: densevector.h:101
ElementGaussSeidel Preconditioner.
Definition: element_gauss_seidel.h:305
number m_schur_alpha
Definition: element_gauss_seidel.h:459
bool m_elim_off_diag
Definition: element_gauss_seidel.h:460
void select_schur_cmp(const std::vector< std::string > &cmp, number alpha)
Definition: element_gauss_seidel.h:370
ElementGaussSeidel(number relax, const std::string &type)
constructor setting relaxation and type
Definition: element_gauss_seidel.h:340
virtual const char * name() const
Name of preconditioner.
Definition: element_gauss_seidel.h:380
virtual ~ElementGaussSeidel()
Destructor.
Definition: element_gauss_seidel.h:358
void set_type(const std::string &type)
set type
Definition: element_gauss_seidel.h:368
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
Preprocess routine.
Definition: element_gauss_seidel.h:383
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition: element_gauss_seidel.h:362
TAlgebra::vector_type vector_type
Vector type.
Definition: element_gauss_seidel.h:311
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition: element_gauss_seidel.h:343
number m_relax
Definition: element_gauss_seidel.h:454
ElementGaussSeidel()
default constructor
Definition: element_gauss_seidel.h:331
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: element_gauss_seidel.h:327
TAlgebra algebra_type
Algebra type.
Definition: element_gauss_seidel.h:308
ElementGaussSeidel(const std::string &type)
constructor setting type
Definition: element_gauss_seidel.h:337
matrix_type m_A
Definition: element_gauss_seidel.h:451
std::vector< std::string > m_schur_cmp
Definition: element_gauss_seidel.h:458
void set_relax(number omega)
set relaxation parameter
Definition: element_gauss_seidel.h:365
virtual bool postprocess()
Postprocess routine.
Definition: element_gauss_seidel.h:447
std::string m_type
Definition: element_gauss_seidel.h:455
void set_elim_offdiag(bool elim)
Definition: element_gauss_seidel.h:376
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition: element_gauss_seidel.h:317
virtual bool step(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp, vector_type &c, const vector_type &d)
computes a new correction c = B*d
Definition: element_gauss_seidel.h:399
ElementGaussSeidel(number relax)
constructor setting relaxation
Definition: element_gauss_seidel.h:334
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: element_gauss_seidel.h:314
IPreconditioner< TAlgebra > base_type
Base type.
Definition: element_gauss_seidel.h:320
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
SmartPtr< ApproximationSpace< TDomain > > approx_space()
returns approx space
Definition: grid_function.h:348
size_t dof_indices(TElem *elem, size_t fct, std::vector< DoFIndex > &ind, bool bHang=false, bool bClear=true) const
get multi indices on an finite element in canonical order
Definition: grid_function.h:322
size_t algebra_indices(TElem *elem, std::vector< size_t > &ind, bool bClear=true) const
get algebra indices on an geometric object in canonical order
Definition: grid_function.h:332
void collect_associated(std::vector< TBaseElem * > &vAssElem, TElem *elem, bool clearContainer=true) const
returns the adjacend elements
Definition: grid_function.h:290
dim_traits< dim >::grid_base_object element_type
Definition: grid_function.h:159
dim_traits< dim-1 >::grid_base_object side_type
Definition: grid_function.h:163
SmartPtr< IDamping< TAlgebra::vector_type, TAlgebra::vector_type > > damping()
returns the scaling
Definition: linear_iterator.h:173
describes a linear iterator that is based on a matrix operator
Definition: preconditioner.h:103
Definition: matrix_operator.h:49
#define SCHUR_MOD
Definition: element_gauss_seidel.h:52
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
@ PST_UNIQUE
Definition: parallel_storage_type.h:70
@ PST_ADDITIVE
Definition: parallel_storage_type.h:69
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
Definition: parallel_index_layout.h:77
bool MakeConsistent(const ParallelMatrix< matrix_type > &_mat, ParallelMatrix< matrix_type > &newMat)
Definition: parallel_matrix_overlap_impl.h:438
bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition: operations_mat.h:68
void ElementGaussSeidelStep(const typename TAlgebra::matrix_type &A, GridFunction< TDomain, TAlgebra > &c, const typename TAlgebra::vector_type &d, number relax, const std::vector< std::string > &cmp, number alpha, bool elim_off_diag=false)
Definition: element_gauss_seidel.h:56
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
T value_type
Definition: sparsematrix_interface.h:2