ug4
schur_complement_operator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015: G-CSC, Goethe University Frankfurt
3  * Author: Arne Nägel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__SCHUR_COMPLEMENT_OPERATOR__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__SCHUR_COMPLEMENT_OPERATOR__
35 
36 
37 #ifdef UG_PARALLEL
38 
39 #include <iostream>
40 #include <sstream>
41 #include <string>
42 #include <set>
43 
54 #include "pcl/pcl.h"
55 
56 #include "common/log.h"
57 
58 #include "schur.h"
59 
60 namespace ug{
61 
62 
63 
64 
65 template <typename TAlgebra>
67  : public ILinearOperator< typename TAlgebra::vector_type,
68  typename TAlgebra::vector_type>
69 {
70  public:
71 
72  // Algebra type
73  typedef TAlgebra algebra_type;
74 
75  // Vector type
76  typedef typename TAlgebra::vector_type vector_type;
77 
78  // Matrix type
79  typedef typename TAlgebra::matrix_type matrix_type;
80 
81 
82 
83  public:
87  : m_spOperator(Alocal),
88  m_slicing(sdv)
89  {
94  }
95 
96  // destructor
98 
100  virtual const char* name() const {return "My local Schur complement Solver";}
101 
102 
104  void init(const vector_type& u) {init();}
105 
107  virtual void init();
108 
111  virtual void apply(vector_type& f, const vector_type& u);
112 
115  virtual void apply_sub(vector_type& f, const vector_type& u);
116 
117  // save current operator
119  { m_spOperator = A; }
120 
123  { m_spDirichletSolver = dirichletSolver; }
124 
125 
126  matrix_type &sub_matrix(int r, int c)
127  {return sub_operator(r,c)->get_matrix();}
128 
130  {return m_op[r][c];}
131 
133  {return m_slicing.get_num_elems(type);}
134 
135  const SchurSlicingData &slicing() const
136  {return m_slicing;}
137 
138 
139  // for debugging: computes schur operator
140  void debug_compute_matrix();
141 
142  void compute_matrix(matrix_type &schur_matrix, double threshold=0.0);
143  virtual void set_debug(SmartPtr<IDebugWriter<algebra_type> > spDebugWriter);
144 
145  template<typename T>
147  {
148  if(!m_spDebugWriterInner.valid()) return;
150  = op.template cast_dynamic<VectorDebugWritingObject<vector_type> >();
151  if(dvwo.valid())
152  dvwo->set_debug(m_spDebugWriterInner);
153  }
154 
155  template<typename T>
157  {
158  if(!m_spDebugWriterSkeleton.valid()) return;
160  = op.template cast_dynamic<VectorDebugWritingObject<vector_type> >();
161  if(dvwo.valid())
162  dvwo->set_debug(m_spDebugWriterSkeleton);
163  }
164 
165 protected:
166  // Operator that is inverted by this Inverse Operator
168 
169  // slices from matrix
171 
172  // Linear Solver to invert the local Dirichlet problems
174 
175 
176 
177  // sub matrices/operator (will be set by init)
179 
180 
181  template<int dim> void set_debug_dim();
182 
186 
188 
189 };
190 
191 
192 
193 } // end namespace ug
194 
195 #endif /* UG_PARALLEL */
196 
197 #endif /* __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__SCHUR_COMPLEMENT_OPERATOR__ */
Definition: smart_pointer.h:108
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
base class for all debug writer
Definition: debug_writer.h:244
describes a linear mapping X->Y
Definition: linear_operator.h:80
describes an inverse linear mapping X->Y
Definition: linear_operator_inverse.h:80
Definition: matrix_operator.h:49
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
Definition: schur_complement_operator.h:69
SmartPtr< AlgebraDebugWriter< algebra_type > > m_spDebugWriterInner
Definition: schur_complement_operator.h:183
SmartPtr< MatrixOperator< matrix_type, vector_type > > m_op[2][2]
Definition: schur_complement_operator.h:178
SmartPtr< IDebugWriter< algebra_type > > m_spDebugWriter
Definition: schur_complement_operator.h:185
void set_debug_dim()
Definition: schur_complement_operator.cpp:401
TAlgebra::vector_type vector_type
Definition: schur_complement_operator.h:76
const SchurSlicingData m_slicing
Definition: schur_complement_operator.h:170
SchurComplementOperator(SmartPtr< MatrixOperator< matrix_type, vector_type > > Alocal, SchurSlicingData::slice_desc_type_vector &sdv)
constructor
Definition: schur_complement_operator.h:85
void compute_matrix(matrix_type &schur_matrix, double threshold=0.0)
Definition: schur_complement_operator.cpp:330
virtual void apply(vector_type &f, const vector_type &u)
apply schur complement
Definition: schur_complement_operator.cpp:177
virtual void apply_sub(vector_type &f, const vector_type &u)
Definition: schur_complement_operator.cpp:277
void debug_compute_matrix()
Definition: schur_complement_operator.cpp:294
SmartPtr< MatrixOperator< matrix_type, vector_type > > m_spOperator
Definition: schur_complement_operator.h:167
void set_matrix(SmartPtr< MatrixOperator< matrix_type, vector_type > > A)
Definition: schur_complement_operator.h:118
void set_inner_debug(SmartPtr< T > op)
Definition: schur_complement_operator.h:146
virtual void init()
initializes the solver for operator A
Definition: schur_complement_operator.cpp:97
TAlgebra algebra_type
Definition: schur_complement_operator.h:73
void set_skeleton_debug(SmartPtr< T > op)
Definition: schur_complement_operator.h:156
SmartPtr< MatrixOperator< matrix_type, vector_type > > sub_operator(int r, int c)
Definition: schur_complement_operator.h:129
const SchurSlicingData & slicing() const
Definition: schur_complement_operator.h:135
void init(const vector_type &u)
implementation of the operator for the solution dependent initialization.
Definition: schur_complement_operator.h:104
matrix_type & sub_matrix(int r, int c)
Definition: schur_complement_operator.h:126
void set_dirichlet_solver(SmartPtr< ILinearOperatorInverse< vector_type > > dirichletSolver)
sets a Dirichlet solver
Definition: schur_complement_operator.h:122
virtual ~SchurComplementOperator()
Definition: schur_complement_operator.h:97
SmartPtr< AlgebraDebugWriter< algebra_type > > m_spDebugWriterSkeleton
Definition: schur_complement_operator.h:184
SmartPtr< ILinearOperatorInverse< vector_type > > m_spDirichletSolver
Definition: schur_complement_operator.h:173
virtual void set_debug(SmartPtr< IDebugWriter< algebra_type > > spDebugWriter)
Definition: schur_complement_operator.cpp:430
TAlgebra::matrix_type matrix_type
Definition: schur_complement_operator.h:79
size_t sub_size(schur_slice_desc_type type)
Definition: schur_complement_operator.h:132
int m_applyCnt
Definition: schur_complement_operator.h:187
virtual const char * name() const
name of solver
Definition: schur_complement_operator.h:100
Definition: slicing.h:68
TVec slice_desc_type_vector
Definition: slicing.h:72
size_t get_num_elems(slice_desc_type type) const
Number of elements for each type.
Definition: slicing.h:247
CPUAlgebra::vector_type vector_type
the ug namespace
schur_slice_desc_type
Definition: schur.h:63
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836