MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
operator.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_OPERATOR
13 #define MFEM_OPERATOR
14 
15 #include "vector.hpp"
16 
17 namespace mfem
18 {
19 
21 class Operator
22 {
23 protected:
24  int height, width;
25 
26 public:
28  explicit Operator(int s = 0) { height = width = s; }
29 
32  Operator(int h, int w) { height = h; width = w; }
33 
35  inline int Height() const { return height; }
38  inline int NumRows() const { return height; }
39 
41  inline int Width() const { return width; }
44  inline int NumCols() const { return width; }
45 
47  virtual void Mult(const Vector &x, Vector &y) const = 0;
48 
50  virtual void MultTranspose(const Vector &x, Vector &y) const
51  { mfem_error ("Operator::MultTranspose() is not overloaded!"); }
52 
54  virtual Operator &GetGradient(const Vector &x) const
55  {
56  mfem_error("Operator::GetGradient() is not overloaded!");
57  return const_cast<Operator &>(*this);
58  }
59 
61  void PrintMatlab (std::ostream & out, int n = 0, int m = 0) const;
62 
63  virtual ~Operator() { }
64 };
65 
66 
69 {
70 protected:
71  double t;
72 
73 public:
76  explicit TimeDependentOperator(int n = 0, double _t = 0.0)
77  : Operator(n) { t = _t; }
78 
81  TimeDependentOperator(int h, int w, double _t = 0.0)
82  : Operator(h, w) { t = _t; }
83 
84  virtual double GetTime() const { return t; }
85 
86  virtual void SetTime(const double _t) { t = _t; }
87 
92  virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
93  {
94  mfem_error("TimeDependentOperator::ImplicitSolve() is not overloaded!");
95  }
96 
97  virtual ~TimeDependentOperator() { }
98 };
99 
100 
102 class Solver : public Operator
103 {
104 public:
107 
111  explicit Solver(int s = 0, bool iter_mode = false)
112  : Operator(s) { iterative_mode = iter_mode; }
113 
115  Solver(int h, int w, bool iter_mode = false)
116  : Operator(h, w) { iterative_mode = iter_mode; }
117 
119  virtual void SetOperator(const Operator &op) = 0;
120 };
121 
122 
125 {
126 public:
128  explicit IdentityOperator(int n) : Operator(n) { }
129 
131  virtual void Mult(const Vector &x, Vector &y) const { y = x; }
132 
134 };
135 
136 
139 {
140 private:
141  const Operator &A;
142 
143 public:
146  : Operator(a->Width(), a->Height()), A(*a) { }
147 
150  : Operator(a.Width(), a.Height()), A(a) { }
151 
153  virtual void Mult(const Vector &x, Vector &y) const
154  { A.MultTranspose(x, y); }
155 
156  virtual void MultTranspose(const Vector &x, Vector &y) const
157  { A.Mult(x, y); }
158 
160 };
161 
162 
164 class RAPOperator : public Operator
165 {
166 private:
167  Operator & Rt;
168  Operator & A;
169  Operator & P;
170  mutable Vector Px;
171  mutable Vector APx;
172 
173 public:
176  : Operator(Rt_.Width(), P_.Width()), Rt(Rt_), A(A_), P(P_),
177  Px(P.Height()), APx(A.Height()) { }
178 
180  virtual void Mult(const Vector & x, Vector & y) const
181  { P.Mult(x, Px); A.Mult(Px, APx); Rt.MultTranspose(APx, y); }
182 
183  virtual void MultTranspose(const Vector & x, Vector & y) const
184  { Rt.Mult(x, APx); A.MultTranspose(APx, Px); P.MultTranspose(Px, y); }
185 
186  virtual ~RAPOperator() { }
187 };
188 
189 
192 {
193  Operator *A;
194  Operator *B;
195  Operator *C;
196  bool ownA, ownB, ownC;
197  mutable Vector t1, t2;
198 
199 public:
201  bool ownA, bool ownB, bool ownC)
202  : Operator(A->Height(), C->Width())
203  , A(A), B(B), C(C)
204  , ownA(ownA), ownB(ownB), ownC(ownC)
205  , t1(C->Height()), t2(B->Height())
206  {}
207 
208  virtual void Mult(const Vector &x, Vector &y) const
209  { C->Mult(x, t1); B->Mult(t1, t2); A->Mult(t2, y); }
210 
211  virtual void MultTranspose(const Vector &x, Vector &y) const
212  { A->MultTranspose(x, t2); B->MultTranspose(t2, t1); C->MultTranspose(t1, y); }
213 
215  {
216  if (ownA) { delete A; }
217  if (ownB) { delete B; }
218  if (ownC) { delete C; }
219  }
220 };
221 
222 }
223 
224 #endif
virtual double GetTime() const
Definition: operator.hpp:84
Solver(int s=0, bool iter_mode=false)
Definition: operator.hpp:111
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:180
Base abstract class for time dependent operators: (x,t) -&gt; f(x,t)
Definition: operator.hpp:68
virtual Operator & GetGradient(const Vector &x) const
Evaluate the gradient operator at the point x.
Definition: operator.hpp:54
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols.
Definition: operator.hpp:41
virtual void SetTime(const double _t)
Definition: operator.hpp:86
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application.
TripleProductOperator(Operator *A, Operator *B, Operator *C, bool ownA, bool ownB, bool ownC)
Definition: operator.hpp:200
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: operator.hpp:156
bool iterative_mode
If true, use the second argument of Mult as an initial guess.
Definition: operator.hpp:106
virtual ~TimeDependentOperator()
Definition: operator.hpp:97
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: operator.hpp:50
Solver(int h, int w, bool iter_mode=false)
Initialize a Solver with height &#39;h&#39; and width &#39;w&#39;.
Definition: operator.hpp:115
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:153
TransposeOperator(const Operator &a)
Construct the transpose of a given operator.
Definition: operator.hpp:149
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: operator.hpp:183
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows.
Definition: operator.hpp:35
TimeDependentOperator(int n=0, double _t=0.0)
Definition: operator.hpp:76
virtual ~RAPOperator()
Definition: operator.hpp:186
The operator x -&gt; R*A*P*x.
Definition: operator.hpp:164
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Definition: operator.hpp:92
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:208
TimeDependentOperator(int h, int w, double _t=0.0)
Definition: operator.hpp:81
Operator(int s=0)
Construct a square Operator with given size s (default 0)
Definition: operator.hpp:28
IdentityOperator(int n)
Creates I_{nxn}.
Definition: operator.hpp:128
int NumRows() const
Definition: operator.hpp:38
void mfem_error(const char *msg)
Definition: error.cpp:23
int NumCols() const
Definition: operator.hpp:44
The transpose of a given operator.
Definition: operator.hpp:138
void PrintMatlab(std::ostream &out, int n=0, int m=0) const
Prints operator with input size n and output size m in matlab format.
Definition: operator.cpp:21
General triple product operator x -&gt; A*B*C*x, with ownership of the factors.
Definition: operator.hpp:191
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:131
Operator(int h, int w)
Definition: operator.hpp:32
virtual void SetOperator(const Operator &op)=0
Set/update the solver for the given operator.
Vector data type.
Definition: vector.hpp:33
Operator I: x -&gt; x.
Definition: operator.hpp:124
TransposeOperator(const Operator *a)
Construct the transpose of a given operator.
Definition: operator.hpp:145
Base class for solvers.
Definition: operator.hpp:102
Abstract operator.
Definition: operator.hpp:21
virtual ~Operator()
Definition: operator.hpp:63
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: operator.hpp:211
RAPOperator(Operator &Rt_, Operator &A_, Operator &P_)
Construct the RAP operator given R^T, A and P.
Definition: operator.hpp:175