LifeV
MonolithicBlockComposed.hpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //@HEADER
3 /*
4 *******************************************************************************
5 
6  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
7  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
8 
9  This file is part of LifeV.
10 
11  LifeV is free software; you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  LifeV is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  @file
30  @brief this file contains a class which is suited for handling a block-structured matrix that can be written as a
31  multiplication of a variable number of factors. It contains a vector of pointers for each factor, BCHandler, FESpace
32  and for each coupling part.
33 
34  @author Paolo Crosetto <crosetto@iacspc70.epfl.ch>
35  @date 08 Jun 2010
36 
37  */
38 
39 #ifndef MONOLITHICBLOCKCOMPOSED_H
40 #define MONOLITHICBLOCKCOMPOSED_H 1
41 
42 #include <lifev/core/LifeV.hpp>
43 #include <Epetra_Operator.h>
44 #include <lifev/core/algorithm/ComposedOperator.hpp>
45 #include <lifev/fsi/solver/MonolithicBlock.hpp>
46 
47 #include <boost/scoped_ptr.hpp>
48 
49 namespace LifeV
50 {
51 
52 //! MonolithicBlockComposed - Class handling block-structured preconditioners
53 /*!
54  @author Paolo Crosetto
55  see \cite CrosettoEtAl2009
56 
57  Pure virtual class which is suited for handling a block-structured matrix that can be written as a
58  multiplication of a variable number of factors. It contains a vector of pointers for each factor, BCHandler, FESpace
59  and for each coupling part.
60 
61  It can be used e.g. to build preconditioners for the FSI system which are composed of different factors.
62  It derives from the pure virtual class MonolithicBlock, it is still pure virtual and it is intended to be the base
63  class for every preconditioner that can be split into factors. Notice that the vector of the preconditioned factors
64  is missing, because it has to be implemented in the children. It could be for instance of type
65  ComposedOperator<T> or PreconditionerComposed.
66  */
67 class MonolithicBlockComposed : public MonolithicBlock
68 {
69 public:
70 
71  enum Block { solid, fluid, mesh };
72 
73  //! @name Public Types
74  //@{
75  typedef MonolithicBlock super_Type;
76  typedef super_Type::fespacePtr_Type fespacePtr_Type;
77  typedef ComposedOperator<Epetra_Operator> operatorPtr_Type;
78  //@}
79 
80  //! @name Constructor and Destructor
81  //@{
82  //! Constructor
83  /**
84  The coupling and the order have to be specified in input. In particular the order specifies which block go
85  first, second etc.
86  \param flags: vector of flags specifying the type of coupling between the different blocks that we chose for this operator
87  \param order: vector specifying the order of the blocks.
88  */
89  MonolithicBlockComposed (const std::vector<Int>& flags, const std::vector<Int>& order) :
90  super_Type(),
91  M_recompute (order.size() ),
92  M_coupling(),
93  M_couplingFlags (new std::vector<Int> (flags) ), // here I copy, so that the input param can be destroyed
94  M_blockReordering (new std::vector<Int> (order) )
95  {}
96 
97 
98  ~MonolithicBlockComposed() {}
99  //@}
100 
101  //! @name Pure virtual methods
102  //@{
103  //! Solves the preconditioned linear system
104  /*!
105  Provided the linear solver and the right hand side this method computes the solution and returns it into
106  the result vector.
107  @param rhs right hand side of the linear system
108  @param result output result
109  @param linearSolver the linear system
110  */
111  virtual int solveSystem ( const vector_Type& rhs, vector_Type& step, solverPtr_Type& linearSolver) = 0;
112 
113  //! Sets the parameters needed by the preconditioner from data file
114  /*!
115  @param data GetPot object reading the text data file
116  @param section string specifying the path in the data file where to find the options for the operator
117  */
118  virtual void setDataFromGetPot (const GetPot& data, const std::string& section) = 0;
119 
120  //! returns true if the operator is set
121  /*!
122  returns the length of the vector M_blocks
123  */
124  virtual bool set() = 0;
125 
126  //@}
127  //!@name Public Methods
128  //@{
129 
130 
131  //! runs GlobalAssemble on the blocks
132  /*!
133  closes and distributes all the blocks in the vector M_blocks, before computing the preconditioner.
134  */
135  void GlobalAssemble();
136 
137  //!sums the coupling matrices with the corresponding blocks
138  /*!
139  Everything (but the boundary conditions assembling) must have been set before calling this
140  */
141  virtual void blockAssembling();
142 
143 
144  //! adds a default coupling matrix for a specified block.
145  /*!
146  The default coupling matrix it is an identity matrix with zeros on the diagonal corresponding to the specified block.
147  The couplings are specified through the vector M_couplingFlags, as usual. If the coupling block is not the last one
148  in the M_coupling vector then it is inserted at the specified position.
149  @param map: global MapEpetra of the problem
150  @param locDofMap: std::map holding the connections between the coupling interface dofs
151  @param numerationInterface: the numeration of the interface dofs
152  @param timeStep: time step
153  @param couplingBlock: UInt specifying the position of the coupling block to be added. Not used in this case, since the coupling flag for each block
154  is contained in the vector M_couplingFlags. See MonolithicBlock::couplingMatrix to understand what the values
155  for this flag correspond to.
156  @param couplingBlock: flag specifying which block is considered (must not exceed the size of the vector of blocks,
157  otherwise a std::bad_alloc exception is thrown). The coupling for each block is specified by a static vector passed to the constructor.
158  */
159  void coupler (mapPtr_Type& map,
160  const std::map<ID, ID>& locDofMap,
161  const vectorPtr_Type& numerationInterface,
162  const Real& timeStep,
163  const Real& coefficient,
164  const Real& rescaleFactor,
165  UInt couplingBlock
166  );
167 
168 
169  //! pushes a block at the end of the vector
170  /*!
171  adds a new block
172  @param Mat: block matrix to push
173  @param recompute: flag stating wether the preconditioner for this block have to be recomputed at every time step
174  */
175  virtual void push_back_matrix (const matrixPtr_Type& Mat, const bool recompute);
176 
177  //! Merges an input MonolithicBlockComposed operator with this one
178  /*!
179  pushes the operator vector of the input operator at the end of the operatoe vector of this instance, and does the same for the
180  vector of coupling matrices.
181  @param Oper: input operator
182  */
183  virtual void push_back_oper ( MonolithicBlockComposed& Oper);
184 
185 
186  //! Pushes an extra coupling matrix at the end of the vector of coupling matrices
187  /*!
188  @param coupling: extra coupling matrix
189  */
190  virtual void push_back_coupling ( matrixPtr_Type& coupling);
191 
192  //! replaces a block
193  /*!
194  replaces a block on a specified position in the vector
195  @param Mat: block matrix to push
196  @param index: position in the vector
197  */
198  virtual void replace_matrix ( const matrixPtr_Type& oper, UInt position ); //{M_blocks.replace(oper, position);}
199 
200 
201  //! replaces a coupling block
202  /*!
203  replaces a coupling block on a specified position in the vector
204  @param Mat block matrix to push
205  @param index position in the vector
206  */
207  virtual void replace_coupling ( const matrixPtr_Type& Mat, UInt index);
208 
209  //! pushes a block at the end of the vector
210  /*!
211  adds a new block
212  @param Mat block matrix to push
213  @param recompute flag stating wether the preconditioner for this block have to be recomputed at every time step
214  */
215  virtual void addToCoupling ( const matrixPtr_Type& Mat, UInt position);
216 
217  //!
218  /*!
219  adds an entry to the coupling matrix
220  @param entry entry
221  @param row row for the insertion
222  @param col colon for the insertion
223  */
224  void addToCoupling ( const Real& entry , UInt row, UInt col, UInt position );
225 
226  //@}
227 
228  //!@name Get Methods
229  //@{
230  //! returns the vector of flags (by const reference).
231  const std::vector<bool>& recompute()
232  {
233  return M_recompute;
234  }
235 
236  //! returns the vector of pointers to the coupling blocks (by const reference).
237  const std::vector<matrixPtr_Type>& couplingVector() const
238  {
239  return M_coupling;
240  }
241 
242  //@}
243 
244  //!@name Set Methods
245  //@{
246 
247  //! turns on/off the recomputation of the preconditioner for a specified factor
248  void setRecompute ( UInt position, bool flag )
249  {
250  M_recompute[position] = flag;
251  }
252 
253  const UInt whereIsBlock ( UInt position ) const;
254 
255  //@}
256 protected:
257 
258  //! @name Protected Methods
259  //@{
260 
261  //!sums the coupling matrix in the specified position with the corresponding block
262  /*!
263  Everything (but the boundary conditions assembling) must have been set before calling this
264  */
265  void blockAssembling (const UInt k);
266 
267 
268  //! swaps the blocks
269  /*!
270  swaps two elements in the vectors of blocks, couplings, offsets, BC handlers, FE spaces, flags M_recompute
271  \param i: element to swap
272  \param j: element to swap
273  */
274  virtual void swap (const UInt i, const UInt j);
275  //@}
276 
277  //! @name Protected Members
278  //@{
279 
280  //! vector of flags saying if the matrix is to be recomputed every time
281  std::vector<bool> M_recompute;
282  //! vector of coupling matrices
283  std::vector<matrixPtr_Type> M_coupling;
284 
285  //! vector of flags specifying the coupling strategy for each block.
286  /*!
287  In particular for each block the method couplingMatrix is called with the corresponding flag in this vector.
288  The coupling vector is passed to the constructor when the preconditioner is registered in the factory. So
289  each coupling vector defines a new preconditioner type. It is created statically before the registration, then it
290  is copied into this scoped_ptr.
291  */
292  std::unique_ptr<std::vector<Int> > M_couplingFlags;
293 
294  //! vector of reordering for the different blocks.
295  /*!the order in which the factors are allpied is specified by this
296  vector. e.g. the fisrt block to be applied corresponds to the number M_blockReordering[0] in the vector
297  M_blocks of blocks. This vector is assigned in the coupler method of each class.
298  */
299  std::unique_ptr<std::vector<Int> > M_blockReordering;
300 
301  //@}
302 
303 private:
304 
305 };
306 
307 } // Namespace LifeV
308 
309 #endif /* MONOLITHICBLOCKCOMPOSED_H */
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
double Real
Generic real data.
Definition: LifeV.hpp:175
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191