Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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__LIB_ALGEBRA__OPERATOR__INTERFACE__LINEAR_OPERATOR__
34 : #define __H__LIB_ALGEBRA__OPERATOR__INTERFACE__LINEAR_OPERATOR__
35 :
36 : #include "operator.h"
37 :
38 : namespace ug{
39 :
40 : ///////////////////////////////////////////////////////////////////////////////
41 : // Linearized Operator
42 : ///////////////////////////////////////////////////////////////////////////////
43 :
44 : /// describes a linear mapping X->Y
45 : /**
46 : * This class is the base class for all linear mappings between two spaces.
47 : * The domain space and the codomain space are passed as template parameters.
48 : * The mapping must be linear. For nonlinear mappings see IOperator. The basic
49 : * usage of this class is to provide the computation of:
50 : *
51 : * f := L*u, (resp. d := J(u) * c in iterative schemes),
52 : *
53 : * where f (resp. d) is from the codomain space, u (resp. c) a function of
54 : * the domain space and L is a linear mapping (resp. J(u) a linearized mapping)
55 : *
56 : * This application is splitted into two steps, that have to be called in the
57 : * correct order:
58 : *
59 : * 1. init() or init(u):
60 : * Theses methods initialize the operator for application. One of these
61 : * methods has to be called once before one of the other two methods can be
62 : * invoked. There is no need to init the operator more than once, but
63 : * sometimes - due to parameter change - this is desirable and can be done.
64 : *
65 : * 2. apply() or apply_sub():
66 : * These methods can be called when the operator has been initialized
67 : * by a call of init. These function perform the linear mapping, where in
68 : * the case of apply_sub() the result is subtracted from the input function.
69 : *
70 : * This splitting has been made, since initialization may be computationally
71 : * expansive. Thus, the user of this class has the choice when to call this
72 : * initialization. E.g. when the operator is applied several times, the init
73 : * of the operator is only needed once.
74 : *
75 : * \tparam X Domain space function
76 : * \tparam Y Range space function
77 : */
78 : template <typename X, typename Y = X>
79 13 : class ILinearOperator : public IOperator<X,Y>
80 : {
81 : public:
82 : /// Domain space
83 : typedef X domain_function_type;
84 :
85 : /// Range space
86 : typedef Y codomain_function_type;
87 :
88 : public:
89 : /// init operator depending on a function u
90 : /**
91 : * This method initializes the operator. Once initialized the 'apply'-method
92 : * can be called. The function u is passed here, since the linear operator
93 : * may be the linearization of some non-linear operator. Thus, the operator
94 : * depends on the linearization point.
95 : * If the operator is not a linearization, this method can be implemented
96 : * by simply calling init() and forgetting about the linearization point.
97 : *
98 : * \param[in] u function (linearization point)
99 : * \returns bool success flag
100 : */
101 : virtual void init(const X& u) = 0;
102 :
103 : /// init operator
104 : /**
105 : * This method initializes the operator. Once initialized the 'apply'-method
106 : * can be called.
107 : * If the operator is a linearization this function returns false.
108 : *
109 : * \returns bool success flag
110 : */
111 : virtual void init() = 0;
112 :
113 : /// default implementation for IOperator interface
114 0 : virtual void prepare(X& u) {}
115 :
116 : // applies the operator
117 : /**
118 : * This method applies the operator, i.e. f = L*u (or d = J(u)*c in
119 : * iterative schemes). Note, that the operator must have been initialized
120 : * once before this method can be used.
121 : *
122 : * \param[in] u domain function
123 : * \param[out] f codomain function
124 : * \returns bool success flag
125 : */
126 : virtual void apply(Y& f, const X& u) = 0;
127 :
128 : // applies the operator and subtracts the result from the input
129 : /**
130 : * This method applies the operator and subracts the result from the input
131 : * codomain function, i.e. f -= L*u (or d -= J(u)*c in iterative schemes).
132 : * Note, that the operator must have been initialized once before this
133 : * method can be used.
134 : *
135 : * \param[in] u domain function
136 : * \param[in,out] f codomain function
137 : * \returns bool success flag
138 : */
139 : virtual void apply_sub(Y& f, const X& u) = 0;
140 :
141 : /// virtual destructor
142 : virtual ~ILinearOperator() {};
143 : };
144 :
145 : }
146 : #endif /* __H__LIB_ALGEBRA__OPERATOR__INTERFACE__LINEAR_OPERATOR__ */
|