Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Martin Rupp
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__UG__LIB_DISC__OPERATOR__ITERATOR_OPERATOR_INVERSE__
34 : #define __H__UG__LIB_DISC__OPERATOR__ITERATOR_OPERATOR_INVERSE__
35 :
36 : #include <string>
37 :
38 : #include "common/util/smart_pointer.h"
39 : #include "lib_algebra/operator/interface/linear_iterator.h"
40 : #include "lib_algebra/operator/interface/linear_operator_inverse.h"
41 : #include "lib_algebra/operator/interface/preconditioner.h"
42 :
43 : #include "common/log.h"
44 :
45 : #ifdef UG_PARALLEL
46 : #include "lib_algebra/parallelization/parallelization.h"
47 : #endif
48 :
49 : namespace ug{
50 :
51 : /**
52 : * a LinearIterator which can uses ILinearOperatorInverse to perform B^{-1}
53 : * this is for the case that some class needs a preconditioner, but we'd like to use a linear solver
54 : * example: 4x AMG as preconditioner
55 : * \code
56 : * linSolver = LinearSolver()
57 : * linSolver:set_preconditioner(amg)
58 : * linSolver:set_convergence_check(ConvCheck(4, 0, 0, false) )
59 : * oii = OperatorInverseIterator(linSolver)
60 : * someObject:set_preconditioner(oii)
61 : * \endcode
62 : */
63 : template <typename TAlgebra>
64 : class OperatorInverseIterator : public ILinearIterator<typename TAlgebra::vector_type>
65 : {
66 : public:
67 : /// Algebra type
68 : typedef TAlgebra algebra_type;
69 :
70 : /// Vector type
71 : typedef typename TAlgebra::vector_type vector_type;
72 :
73 : /// Matrix type
74 : typedef typename TAlgebra::matrix_type matrix_type;
75 :
76 : /// Matrix Operator type
77 : typedef typename IPreconditioner<TAlgebra>::matrix_operator_type matrix_operator_type;
78 :
79 : /// Base type
80 : typedef IPreconditioner<TAlgebra> base_type;
81 :
82 : protected:
83 : SmartPtr<ILinearOperatorInverse<vector_type> > m_opInv;
84 :
85 : public:
86 0 : virtual SmartPtr<ILinearIterator<vector_type, vector_type> > clone()
87 : {
88 : UG_ASSERT(0, "not implemented since ILinearOperatorInverse::clone not implemented");
89 0 : return SPNULL;
90 : }
91 : /// default constructor
92 0 : OperatorInverseIterator(SmartPtr<ILinearOperatorInverse<vector_type> > opInv) : m_opInv(opInv)
93 : {
94 0 : m_name = std::string("OperatorInverseIterator(") + std::string(m_opInv->name()) + std::string(")");
95 0 : }
96 0 : ~OperatorInverseIterator()
97 : {
98 :
99 0 : }
100 :
101 : std::string m_name;
102 :
103 : /// returns if parallel solving is supported
104 0 : virtual bool supports_parallel() const
105 : {
106 0 : return m_opInv->supports_parallel();
107 : }
108 :
109 0 : virtual const char* name() const
110 : {
111 0 : return m_name.c_str();
112 : }
113 :
114 0 : virtual bool init(SmartPtr<ILinearOperator<vector_type> > L)
115 : {
116 0 : if(!m_opInv->init(L))
117 : {
118 0 : UG_LOG("ERROR in '" << name() << "::init'.\n");
119 0 : return false;
120 : }
121 : return true;
122 : }
123 :
124 0 : virtual bool init(SmartPtr<ILinearOperator<vector_type> > J, const vector_type& u)
125 : {
126 0 : if(!m_opInv->init(J, u))
127 : {
128 0 : UG_LOG("ERROR in '" << name() << "::init'.\n");
129 0 : return false;
130 : }
131 : return true;
132 : }
133 :
134 0 : virtual bool apply(vector_type& c, const vector_type& d)
135 : {
136 0 : if(m_opInv->apply(c, d))
137 : {
138 : //UG_LOG("ERROR in '" << name() << "::apply'\n");
139 0 : return false;
140 : }
141 : return true;
142 : }
143 :
144 0 : virtual bool apply_update_defect(vector_type& c, vector_type& d)
145 : {
146 0 : if(m_opInv->apply_return_defect(c, d))
147 : {
148 : //UG_LOG("ERROR in '" << name() << "::apply_update_defect'\n");
149 0 : return false;
150 : }
151 : return true;
152 : }
153 :
154 : };
155 :
156 :
157 : } // end namespace ug
158 :
159 : #endif // __H__UG__LIB_DISC__OPERATOR__ITERATOR_OPERATOR_INVERSE__
|