37 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__SEQUENTIAL_SSC__
38 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__SEQUENTIAL_SSC__
57 template <
typename TDomain,
typename TAlgebra,
typename TObject>
98 virtual size_t size() {
return 0; }
104 template <
typename TDomain,
typename TAlgebra,
typename TObject>
139 typedef typename TAlgebra::matrix_type::const_row_iterator const_row_iterator;
140 const static int blockSize = TAlgebra::blockSize;
141 const size_t numIndex = this->
size();
147 for (
size_t j = 0; j<numIndex; j++)
149 for (
size_t k=0;k<numIndex;k++)
151 const_row_iterator it = A.get_connection(
m_vInd[j],
m_vInd[k], bFound);
163 const size_t numIndex = this->
size();
164 const static int blockSize = TAlgebra::blockSize;
169 for (
size_t j = 0; j<numIndex; j++)
179 typedef typename TAlgebra::matrix_type::const_row_iterator const_row_iterator;
180 const static int blockSize = TAlgebra::blockSize;
181 const size_t numIndex = this->
size();
186 for (
size_t j = 0; j<numIndex; j++)
189 for(const_row_iterator it = A.begin_row(
m_vInd[j]); it != A.end_row(
m_vInd[j]) ; ++it)
191 MatMultAdd(sumj, 1.0, sumj, -1.0, it.value(), c[it.index()]);
202 const size_t numIndex = this->
size();
207 for (
size_t j=0;j<numIndex;j++)
231 template <
typename TDomain,
typename TAlgebra,
typename TObject>
253 {
return (
dynamic_cast<TObject*
> (obj) != NULL); }
263 const size_t numIndex = this->
size();
268 for (
size_t j = 0; j<numIndex; ++j)
270 for (
size_t k=0; k<numIndex; ++k)
282 const size_t numIndex = this->
size();
285 for (
size_t j = 0; j<numIndex; j++)
294 typedef typename TAlgebra::matrix_type::const_row_iterator const_row_iterator;
295 const static int blockSize = TAlgebra::blockSize;
296 const size_t numIndex = this->
size();
302 for (
size_t j = 0; j<numIndex; j++)
305 for(const_row_iterator it = A.begin_row(
m_vInd[j][0]); it != A.end_row(
m_vInd[j][0]) ; ++it)
306 {
MatMultAdd(sumdj, 1.0, sumdj, -1.0, it.value(), c[it.index()]); }
318 const size_t numIndex = this->
size();
323 for (
size_t j=0;j<numIndex;j++)
347 template <
typename TDomain,
typename TAlgebra>
388 const TGridFunction *c =
dynamic_cast<const TGridFunction *
> (&cvec);
389 std::vector<TElement*> vElem;
393 for(
size_t i = 0; i < vElem.size(); ++i)
395 c->algebra_indices(vElem[i], vInd,
false);
401 std::sort(vInd.begin(), vInd.end());
402 vInd.erase(std::unique(vInd.begin(), vInd.end()), vInd.end());
410 template <
typename TDomain,
typename TAlgebra>
446 for(
size_t i = 0; i <
m_vVtxCmp.size(); ++i)
460 const TGridFunction *c =
dynamic_cast<const TGridFunction *
> (&cvec);
478 const TGridFunction *c =
dynamic_cast<const TGridFunction *
> (&cvec);
479 std::vector<TElement*> vElem;
483 for(
size_t i = 0; i < vElem.size(); ++i)
486 c->dof_indices(vElem[i],
m_vElemFct[f], vInd,
false,
false);
490 for(
size_t f = 0; f <
m_vVtxFct.size(); ++f)
491 c->dof_indices(groupObj,
m_vVtxFct[f], vInd,
false,
false);
496 std::sort(vInd.begin(), vInd.end());
497 vInd.erase(std::unique(vInd.begin(), vInd.end()), vInd.end());
576 template<
typename TGroupObj,
typename TDomain,
typename TAlgebra>
579 const typename TAlgebra::vector_type& d,
588 for(GroupObjIter iter = objIterBegin; iter != objIterEnd; ++iter)
591 TGroupObj* groupObj = *iter;
592 subspace.
init(groupObj, c);
600 template<
typename TGroupObj,
typename TGroupObjIter,
typename TDomain,
typename TAlgebra>
603 const typename TAlgebra::vector_type& d,
606 TGroupObjIter objIterBegin, TGroupObjIter objIterEnd)
610 for(TGroupObjIter iter = objIterBegin; iter != objIterEnd; ++iter)
613 TGroupObj* groupObj = *iter;
614 if (groupObj == NULL)
616 UG_LOG(
"WARNING: Found empty object!: "<< count);
620 subspace.
init(groupObj, c);
630 template<
typename TGroupObj,
typename TDomain,
typename TAlgebra>
633 const typename TAlgebra::vector_type& d,
644 for(GroupObjIter iter = objIterBegin; iter != objIterEnd; ++iter)
649 std::vector<TGroupObj*> objects(ncount);
650 for(GroupObjIter iter = objIterBegin; iter != objIterEnd; ++iter)
653 objects.push_back(*iter);
658 for(
typename std::vector<TGroupObj*>::reverse_iterator riter = objects.rbegin(); riter != objects.rend(); ++riter)
661 TGroupObj* groupObj = *riter;
662 if (groupObj == NULL)
continue;
666 subspace.
init(groupObj, c);
673 template <
class TDomain>
680 const typename TDomain::position_accessor_type&
_aaPos;
685 template <
typename TDomain,
typename TAlgebra>
713 template <
typename TDomain,
typename TAlgebra>
737 template <
typename TElem>
738 typename TGridFunction::template traits<TElem>::const_iterator
740 {
return m_pSol->template begin<Vertex>();}
742 template <
typename TElem>
743 typename TGridFunction::template traits<TElem>::const_iterator
745 {
return m_pSol->template end<Vertex>(); }
753 template <
typename TDomain,
typename TAlgebra>
796 newInst->set_damp(this->
damping());
798 newInst->set_type(
m_type);
823 virtual const char*
name()
const
824 {
return "SequentialSubspaceCorrection";}
836 UG_ASSERT(0,
"SequentialSubspaceCorrection not implemented in parallel. Need to think about this");
840 m_oD.set_layouts(
m_A.layouts());
841 m_oC.set_layouts(
m_A.layouts());
842 m_oD.resize(
m_A.num_rows(),
false);
843 m_oC.resize(
m_A.num_rows(),
false);
864 TGridFunction* pC =
dynamic_cast<TGridFunction*
>(&c);
866 UG_COND_THROW(pC == NULL,
"SequentialSubspaceCorrection expects correction to be a GridFunction.");
877 UG_ASSERT(0,
"SequentialSubspaceCorrection not implemented in parallel. Need to think about this");
889 TVertexIter objIterBegin = pC->template begin<Vertex>();
890 TVertexIter objIterEnd = pC->template end<Vertex>();
897 for(TVertexIter iter = objIterBegin; iter != objIterEnd; ++iter)
903 typedef std::vector<Vertex*> TObjVector;
904 TObjVector objects(ncount);
906 for(TVertexIter iter = objIterBegin; iter != objIterEnd; ++iter)
909 objects.push_back(*iter);
913 SequentialSubspaceCorrectionLoop<Vertex,TObjVector::const_iterator, TDomain,TAlgebra>
917 SequentialSubspaceCorrectionLoop<Vertex,TObjVector::const_reverse_iterator, TDomain,TAlgebra>
923 }
else if(
m_type ==
"element") {
930 else UG_THROW(
"SequentialSubspaceCorrectionStep: wrong patch type '"<<
m_type<<
"'."
Definition: smart_pointer.h:296
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:420
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
const value_type & entry(size_type r, size_type c) const
Definition: densematrix.h:200
Definition: densevector.h:101
void subassign(size_t i, const value_type &t)
Definition: densevector.h:290
Definition: sequential_subspace_correction.h:715
TGridFunction * m_pSol
Definition: sequential_subspace_correction.h:747
TGridFunction::template traits< TElem >::const_iterator end() const
Definition: sequential_subspace_correction.h:744
TGridFunction::element_type TElement
Definition: sequential_subspace_correction.h:724
ISpaceDecomposition< TDomain, TAlgebra > base_type
Definition: sequential_subspace_correction.h:718
static const int dim
Definition: sequential_subspace_correction.h:722
GridFunction< TDomain, TAlgebra > TGridFunction
Definition: sequential_subspace_correction.h:720
virtual void init(const typename base_type::vector_type &x)
Definition: sequential_subspace_correction.h:731
TGridFunction::template traits< TElem >::const_iterator begin() const
Definition: sequential_subspace_correction.h:739
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
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
SmartPtr< IDamping< TAlgebra::vector_type, TAlgebra::vector_type > > damping()
returns the scaling
Definition: linear_iterator.h:173
Abstract definition for subspace V_k.
Definition: sequential_subspace_correction.h:59
virtual void update_solution(vector_type &u, double omega=1.0)=0
u = u + omega*ck.
virtual void init(TObject *, const vector_type &)=0
Extract local data (based on group obj).
virtual void extract_rhs(const vector_type &d)=0
Extract rhs (on local index set) for parallel subspace correction.
virtual void extract_rhs(const vector_type &d, const matrix_type &A, const vector_type &c)=0
Extract rhs (on local index set) for sequential subspace correction.
DenseVector< VariableArray1< number > > vector_type_local
Definition: sequential_subspace_correction.h:72
GridFunction< TDomain, TAlgebra > grid_function_type
Grid function type.
Definition: sequential_subspace_correction.h:71
virtual bool preprocess(const vector_type &c)
Called once.
Definition: sequential_subspace_correction.h:79
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:65
DenseMatrix< VariableArray2< number > > matrix_type_local
Definition: sequential_subspace_correction.h:73
virtual void extract_matrix(const matrix_type &A)=0
Extract matrix (on local index set).
virtual size_t size()
Definition: sequential_subspace_correction.h:98
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:68
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:62
describes a linear iterator that is based on a matrix operator
Definition: preconditioner.h:103
Abstract.
Definition: sequential_subspace_correction.h:686
virtual void init(const vector_type &x)=0
Initialize decomposition.
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:696
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:690
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:693
GridFunction< TDomain, TAlgebra > grid_function_type
Grid function type.
Definition: sequential_subspace_correction.h:699
static const int dim
World Dimension.
Definition: sequential_subspace_correction.h:708
Abstract definition for subspace V_k (based on DoFIndex)
Definition: sequential_subspace_correction.h:233
matrix_type_local m_Aloc
Definition: sequential_subspace_correction.h:340
std::vector< DoFIndex > m_vInd
Algebraic indices.
Definition: sequential_subspace_correction.h:335
DenseMatrix< VariableArray2< number > > matrix_type_local
Definition: sequential_subspace_correction.h:247
std::vector< DoFIndex > index_vector
Local data.
Definition: sequential_subspace_correction.h:245
bool check(void *obj) const
Definition: sequential_subspace_correction.h:252
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:242
vector_type_local m_uloc
Definition: sequential_subspace_correction.h:338
DenseVector< VariableArray1< number > > vector_type_local
Definition: sequential_subspace_correction.h:246
virtual void extract_rhs(const vector_type &d, const matrix_type &A, const vector_type &c)
Extract rhs (on local index set) for sequential subspace correction.
Definition: sequential_subspace_correction.h:292
virtual void update_solution(vector_type &u, double omega=1.0)
u = u + ck
Definition: sequential_subspace_correction.h:316
vector_type_local m_dloc
Definition: sequential_subspace_correction.h:339
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:239
virtual size_t size()
Definition: sequential_subspace_correction.h:331
virtual void extract_rhs(const vector_type &d)
Extract rhs (on local index set) for parallel subspace correction.
Definition: sequential_subspace_correction.h:280
virtual void extract_matrix(const matrix_type &A)
Extract matrix (on local index set)
Definition: sequential_subspace_correction.h:259
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:236
virtual void init(TObject *, const vector_type &)=0
Extract local data (based on group obj)
Concrete definition of subspace V_k (based on size_t)
Definition: sequential_subspace_correction.h:106
std::vector< size_t > index_vector
Local data.
Definition: sequential_subspace_correction.h:118
DenseMatrix< VariableArray2< number > > matrix_type_local
Definition: sequential_subspace_correction.h:120
matrix_type_local m_Aloc
Definition: sequential_subspace_correction.h:225
virtual void update_solution(vector_type &u, double omega=1.0)
u = u + ck
Definition: sequential_subspace_correction.h:200
virtual void extract_matrix(const matrix_type &A)
Extract matrix (on local index set)
Definition: sequential_subspace_correction.h:137
vector_type_local m_uloc
Memory for local algebra.
Definition: sequential_subspace_correction.h:223
index_vector m_vInd
Algebraic indices.
Definition: sequential_subspace_correction.h:220
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:115
DenseVector< VariableArray1< number > > vector_type_local
Definition: sequential_subspace_correction.h:119
virtual void extract_rhs(const vector_type &d)
Extract rhs (on local index set) for parallel subspace correction.
Definition: sequential_subspace_correction.h:161
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:112
virtual void init(TObject *, const vector_type &)=0
Called once.
virtual size_t size()
Definition: sequential_subspace_correction.h:215
vector_type_local m_dloc
Definition: sequential_subspace_correction.h:224
virtual void extract_rhs(const vector_type &d, const matrix_type &A, const vector_type &c)
Extract rhs (on local index set) for sequential subspace correction.
Definition: sequential_subspace_correction.h:177
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:109
Definition: matrix_operator.h:49
Sequential subspace correction preconditioner.
Definition: sequential_subspace_correction.h:755
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:758
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:761
vector_type m_oD
for overlaps only
Definition: sequential_subspace_correction.h:960
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:764
std::string m_type
Definition: sequential_subspace_correction.h:949
vector_type m_oC
Definition: sequential_subspace_correction.h:961
number m_relax
Definition: sequential_subspace_correction.h:948
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: sequential_subspace_correction.h:780
GridFunction< TDomain, TAlgebra >::element_type Element
Definition: sequential_subspace_correction.h:946
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: sequential_subspace_correction.h:859
matrix_type m_A
matrix with overlap
Definition: sequential_subspace_correction.h:957
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition: sequential_subspace_correction.h:808
void set_vertex_subspace(SmartPtr< TVertexSubspace > spVertexSubspace)
set subspace
Definition: sequential_subspace_correction.h:817
SequentialSubspaceCorrection(number relax)
constructor setting relaxation
Definition: sequential_subspace_correction.h:787
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
Preprocess routine.
Definition: sequential_subspace_correction.h:827
virtual bool postprocess()
Postprocess routine.
Definition: sequential_subspace_correction.h:942
virtual ~SequentialSubspaceCorrection()
Destructor.
Definition: sequential_subspace_correction.h:804
ILocalSubspace< TDomain, TAlgebra, Vertex > TVertexSubspace
Subspace for vertices.
Definition: sequential_subspace_correction.h:770
virtual const char * name() const
Name of preconditioner.
Definition: sequential_subspace_correction.h:823
void set_type(const std::string &type)
set type
Definition: sequential_subspace_correction.h:814
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition: sequential_subspace_correction.h:767
SmartPtr< TVertexSubspace > m_spVertexSubspace
Definition: sequential_subspace_correction.h:952
IPreconditioner< TAlgebra > base_type
Base type.
Definition: sequential_subspace_correction.h:773
void set_relax(number omega)
set relaxation parameter
Definition: sequential_subspace_correction.h:811
SequentialSubspaceCorrection()
default constructor
Definition: sequential_subspace_correction.h:784
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition: sequential_subspace_correction.h:791
bool resize(size_type n, bool bCopyValues=true)
Definition: variable_array_impl.h:92
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: variable_array_impl.h:237
Collects indices on all elements with v \in Vtx(elem)
Definition: sequential_subspace_correction.h:349
void init(void *obj, const vector_type &cvec)
Extract indices for local DoFs.
Definition: sequential_subspace_correction.h:376
LocalIndexSubspace< TDomain, TAlgebra, Vertex > base_type
Base type.
Definition: sequential_subspace_correction.h:364
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:361
Vertex TObject
Definition: sequential_subspace_correction.h:351
bool check(void *obj) const
Definition: sequential_subspace_correction.h:372
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:358
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:355
Collects indices on all elements with v \in Vtx(elem)
Definition: sequential_subspace_correction.h:412
TAlgebra::vector_type vector_type
Vector type.
Definition: sequential_subspace_correction.h:418
void extract_ids(const grid_function_type *c)
Extracts function IDs.
Definition: sequential_subspace_correction.h:437
TAlgebra algebra_type
Algebra type.
Definition: sequential_subspace_correction.h:415
void init(Vertex *groupObj, const vector_type &cvec)
Extract indices for single vertex.
Definition: sequential_subspace_correction.h:469
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: sequential_subspace_correction.h:421
std::vector< std::string > m_vVtxCmp
Definition: sequential_subspace_correction.h:512
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: sequential_subspace_correction.h:423
bool preprocess(const vector_type &cvec)
OVERRIDE.
Definition: sequential_subspace_correction.h:457
std::vector< size_t > m_vElemFct
Definition: sequential_subspace_correction.h:516
LocalDoFSubspace< TDomain, TAlgebra, Vertex > base_type
Base type.
Definition: sequential_subspace_correction.h:426
std::vector< size_t > m_vVtxFct
Definition: sequential_subspace_correction.h:515
std::vector< std::string > m_vElemCmp
Definition: sequential_subspace_correction.h:513
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Definition: sequential_subspace_correction.h:674
const TDomain::position_accessor_type & _aaPos
Definition: sequential_subspace_correction.h:680
bool operator()(Vertex *a, Vertex *b) const
Definition: sequential_subspace_correction.h:677
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
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
#define UG_LOG(msg)
Definition: log.h:367
#define THROW_IF_NOT_EQUAL(s1, s2)
Definition: error.h:181
#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
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition: multi_index.h:276
void SequentialSubspaceCorrectionLoop(const typename TAlgebra::matrix_type &A, GridFunction< TDomain, TAlgebra > &c, const typename TAlgebra::vector_type &d, number omega_relax, ILocalSubspace< TDomain, TAlgebra, TGroupObj > &subspace, TGroupObjIter objIterBegin, TGroupObjIter objIterEnd)
Abstract loop over TGroupObj (forward)
Definition: sequential_subspace_correction.h:601
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 CreateOverlap(TMatrix &matInOut)
Adds coefficients and connections to create an overlapping matrix.
Definition: matrix_overlap_impl.h:434
void ParallelSubspaceCorrectionLoop(const typename TAlgebra::matrix_type &A, GridFunction< TDomain, TAlgebra > &c, const typename TAlgebra::vector_type &d, number omega_relax, ILocalSubspace< TDomain, TAlgebra, TGroupObj > &subspace, typename GridFunction< TDomain, TAlgebra >::template traits< TGroupObj >::const_iterator objIterBegin, typename GridFunction< TDomain, TAlgebra >::template traits< TGroupObj >::const_iterator objIterEnd)
Abstract loop.
Definition: sequential_subspace_correction.h:577
void SequentialSubspaceCorrectionLoopBackward(const typename TAlgebra::matrix_type &A, GridFunction< TDomain, TAlgebra > &c, const typename TAlgebra::vector_type &d, number omega_relax, ILocalSubspace< TDomain, TAlgebra, TGroupObj > &subspace, typename GridFunction< TDomain, TAlgebra >::template traits< TGroupObj >::const_iterator objIterBegin, typename GridFunction< TDomain, TAlgebra >::template traits< TGroupObj >::const_iterator objIterEnd)
Abstract loop (backward)
Definition: sequential_subspace_correction.h:631
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
#define PROFILE_BEGIN_GROUP(name, groups)
Definition: profiler.h:255
T value_type
Definition: sparsematrix_interface.h:2