MFEM  v3.0
 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.googlecode.com.
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 *((Operator *)this);
58  }
59 
61  void PrintMatlab (std::ostream & out, int n = 0, int m = 0);
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  void Mult(const Vector & x, Vector & y) const
181  { P.Mult(x, Px); A.Mult(Px, APx); Rt.MultTranspose(APx, y); }
182 
183  void MultTranspose(const Vector & x, Vector & y) const
184  { Rt.Mult(x, APx); A.MultTranspose(APx, Px); P.MultTranspose(Px, y); }
185 
187 };
188 
189 }
190 
191 #endif
virtual double GetTime() const
Definition: operator.hpp:84
void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: operator.hpp:183
Solver(int s=0, bool iter_mode=false)
Definition: operator.hpp:111
void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: operator.hpp:180
Base abstract class for time dependent operators: (x,t) -> 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.
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 'h' and width 'w'.
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
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
The operator x -> R*A*P*x.
Definition: operator.hpp:164
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Definition: operator.hpp:92
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
void PrintMatlab(std::ostream &out, int n=0, int m=0)
Prints operator with input size n and output size m in matlab format.
Definition: operator.cpp:21
The transpose of a given operator.
Definition: operator.hpp:138
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:29
Operator I: x -> 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
RAPOperator(Operator &Rt_, Operator &A_, Operator &P_)
Construct the RAP operator given R^T, A and P.
Definition: operator.hpp:175