MFEM  v3.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
blockoperator.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_BLOCKOPERATOR
13 #define MFEM_BLOCKOPERATOR
14 
15 #include "../config/config.hpp"
16 #include "../general/array.hpp"
17 #include "operator.hpp"
18 #include "blockvector.hpp"
19 
20 namespace mfem
21 {
22 
24 
34 class BlockOperator : public Operator
35 {
36 public:
39 
44  BlockOperator(const Array<int> & offsets);
46 
52  BlockOperator(const Array<int> & row_offsets, const Array<int> & col_offsets);
53 
55 
59  void SetDiagonalBlock(int iblock, Operator *op);
61 
65  void SetBlock(int iRow, int iCol, Operator *op);
66 
68  int NumRowBlocks() const { return nRowBlocks; }
70  int NumColBlocks() const { return nColBlocks; }
71 
73  int IsZeroBlock(int i, int j) const { return (op(i,j)==NULL) ? 1 : 0; }
75  Operator & GetBlock(int i, int j)
76  { MFEM_VERIFY(op(i,j), ""); return *op(i,j); }
77 
79  Array<int> & RowOffsets() { return row_offsets; }
81  Array<int> & ColOffsets() { return col_offsets; }
82 
84  virtual void Mult (const Vector & x, Vector & y) const;
85 
87  virtual void MultTranspose (const Vector & x, Vector & y) const;
88 
90 
94 
95 private:
97  int nRowBlocks;
99  int nColBlocks;
101  Array<int> row_offsets;
103  Array<int> col_offsets;
106 
108  mutable BlockVector xblock;
109  mutable BlockVector yblock;
110  mutable Vector tmp;
111 };
112 
114 
126 {
127 public:
129  BlockDiagonalPreconditioner(const Array<int> & offsets);
131 
135  void SetDiagonalBlock(int iblock, Operator *op);
137  virtual void SetOperator(const Operator &op) { }
138 
140  int NumBlocks() const { return nBlocks; }
141 
144  { MFEM_VERIFY(op[iblock], ""); return *op[iblock]; }
145 
147  Array<int> & Offsets() { return offsets; }
148 
150  virtual void Mult (const Vector & x, Vector & y) const;
151 
153  virtual void MultTranspose (const Vector & x, Vector & y) const;
154 
156 
161 
162 private:
164  int nBlocks;
166  Array<int> offsets;
171  mutable BlockVector xblock;
172  mutable BlockVector yblock;
173 };
174 
175 }
176 
177 #endif /* MFEM_BLOCKOPERATOR */
Array< int > & RowOffsets()
Return the row offsets for block starts.
Array< int > & Offsets()
Return the offsets for block starts.
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
int IsZeroBlock(int i, int j) const
Check if block (i,j) is a zero block.
void SetBlock(int iRow, int iCol, Operator *op)
Add a block op in the block-entry (iblock, jblock).
Operator & GetBlock(int i, int j)
Return a reference to block i,j.
int NumBlocks() const
Return the number of blocks.
Operator & GetDiagonalBlock(int iblock)
Return a reference to block i,i.
A class to handle Block diagonal preconditioners in a matrix-free implementation. ...
void SetDiagonalBlock(int iblock, Operator *op)
Add block op in the block-entry (iblock, iblock).
BlockDiagonalPreconditioner(const Array< int > &offsets)
Constructor that specifies the block structure.
BlockOperator(const Array< int > &offsets)
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
virtual void SetOperator(const Operator &op)
This method is present since required by the abstract base class Solver.
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
int NumRowBlocks() const
Return the number of row blocks.
Vector data type.
Definition: vector.hpp:33
Base class for solvers.
Definition: operator.hpp:102
Abstract operator.
Definition: operator.hpp:21
A class to handle Block systems in a matrix-free implementation.
int NumColBlocks() const
Return the number of column blocks.
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
Array< int > & ColOffsets()
Return the columns offsets for block starts.