ug4
Loading...
Searching...
No Matches
debug_iterator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2015: G-CSC, Goethe University Frankfurt
3 * Author: Arne Nägel
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__LINEAR_OPERATOR__DEBUG_ITERATOR__
34#define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__DEBUG_ITERATOR__
35
40
41
42#ifdef UG_PARALLEL
45#endif
46
47namespace ug{
48
50
60template <typename TAlgebra>
62public virtual ILinearIterator<typename TAlgebra::vector_type>,
63public VectorDebugWritingObject <typename TAlgebra::vector_type>
64{
65 public:
66 // Algebra type
67 typedef TAlgebra algebra_type;
68
69 // Vector type
70 typedef typename TAlgebra::vector_type vector_type;
71
72 // Matrix type
73 typedef typename TAlgebra::matrix_type matrix_type;
74
75 // Base type
77
79 private:
80 typedef VectorDebugWritingObject <typename TAlgebra::vector_type> vdwo_type;
81
82 public:
89
97
100 {
102 newInst->set_damp(this->damping());
103 newInst->set_preconditioner(this->get_preconditioner()->clone()); // clone preconditioner
104 newInst->set_solver(this->get_solver()); // keep solver (initialized below)
105 newInst->set_debug(this->vdwo_type::vector_debug_writer());
106 newInst->from = this->from;
107 newInst->to = this->to;
108 return newInst;
109 }
110
112 virtual bool supports_parallel() const
113 {
114 if(m_pprecond.valid())
115 return m_pprecond->supports_parallel();
116 return true;
117 }
118
124 void set_random_bounds(double a, double b){from =a; to=b;}
125
128
129 protected:
134
135
137 virtual const char* name() const
138 {return "DebugIterator";}
139
140
143 const vector_type& u)
144 {
145 // cast to matrix based operator
147 J.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
148
149 // Check that matrix if of correct type
150 if(pOp.invalid())
151 UG_THROW(name() << "::init': Passed Operator is "
152 "not based on matrix. This Preconditioner can only "
153 "handle matrix-based operators.");
154
155 // forward request to matrix based implementation
156 return init(pOp);
157 }
158
161 {
162 // cast to matrix based operator
164 L.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
165
166 // Check that matrix if of correct type
167 if(pOp.invalid())
168 UG_THROW(name() << "::init': Passed Operator is "
169 "not based on matrix. This Preconditioner can only "
170 "handle matrix-based operators.");
171
172 // forward request to matrix based implementation
173 return init(pOp);
174 }
175
178 {
179 m_pOperator->get_matrix() = pOp->get_matrix();
180 //m_pOperator->get_matrix().set_as_copy_of(pOp->get_matrix());
181#ifdef UG_PARALLEL
182 //m_pOperator->get_matrix().set_storage_Type(pOp->get_matrix()->get_storage_type());
183#endif
184 m_pprecond->init(pOp);
185
186 //write_debug(pOp->get_matrix(), "DebugMatrix");
188
189 return true;
190 }
191
193
196 {
197 if (m_solver.invalid())
198 {
199 UG_LOG("WARNING: cannot find smooth error; no solver supplied!");
200 return false;
201 }
202
204 {
205 UG_LOG("WARNING: cannot find smooth error; no valid vector !");
206 return false;
207 }
208
209 //vector_type myRhs(m_pOperator->get_matrix().num_rows());
210 //vector_type myError(m_pOperator->get_matrix().num_rows());
211
213 SmartPtr<vector_type> myRhs = m_spSolVector->clone_without_values();
214
215 myError->set(0.0);
216 myError->set_random(from, to);
217
218 myRhs->set(0.0);
219
220 this->write_debug(*myError, "DebugIterError0");
221 m_solver->init(m_pOperator);
222 m_solver->apply(*myError, *myRhs);
223
224 this->write_debug(*myError, "DebugIterErrorS");
225
226 return true;
227 }
228
230 virtual bool apply(vector_type& c, const vector_type& d)
231 {
232 return m_pprecond->apply(c, d);
233 }
234
237 {
238 return (m_pprecond->apply_update_defect(c, d));
239 }
240
241 protected:
242
244
248
249 double from, to;
250
251};
252
253
254
255} // end namespace ug
256
257#endif // __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__TRANSFORMING__
Definition smart_pointer.h:108
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:212
Debugging iterator.
Definition debug_iterator.h:64
void set_preconditioner(SmartPtr< base_type > pprecond)
specify the real preconditioner (used for iterating)
Definition debug_iterator.h:120
void set_solver(SmartPtr< solver_type > psolver)
specify the solver that will be used for debugging (optional)
Definition debug_iterator.h:122
DebugIterator(SmartPtr< base_type > pprecond, SmartPtr< solver_type > psolver)
Definition debug_iterator.h:90
virtual bool apply(vector_type &c, const vector_type &d)
forwarding call to original preconditioner
Definition debug_iterator.h:230
virtual bool init(SmartPtr< ILinearOperator< vector_type > > L)
init (expensive)
Definition debug_iterator.h:160
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition debug_iterator.h:112
SmartPtr< MatrixOperator< matrix_type, vector_type > > m_pOperator
Definition debug_iterator.h:246
TAlgebra algebra_type
Definition debug_iterator.h:67
virtual const char * name() const
name of preconditioner
Definition debug_iterator.h:137
TAlgebra::matrix_type matrix_type
Definition debug_iterator.h:73
double to
Definition debug_iterator.h:249
IPreconditionedLinearOperatorInverse< vector_type > solver_type
Definition debug_iterator.h:78
ILinearIterator< typename TAlgebra::vector_type > base_type
Definition debug_iterator.h:76
virtual bool init(SmartPtr< ILinearOperator< vector_type > > J, const vector_type &u)
init (expensive)
Definition debug_iterator.h:142
void set_random_bounds(double a, double b)
specify bounds for random initial guess (optional)
Definition debug_iterator.h:124
void set_solution(SmartPtr< vector_type > sol)
Definition debug_iterator.h:126
SmartPtr< solver_type > m_solver
Definition debug_iterator.h:245
VectorDebugWritingObject< typename TAlgebra::vector_type > vdwo_type
Definition debug_iterator.h:80
bool find_smooth_error()
Determines algebraically smooth error.
Definition debug_iterator.h:195
double from
Definition debug_iterator.h:249
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition debug_iterator.h:99
DebugIterator()
Constructor.
Definition debug_iterator.h:84
TAlgebra::vector_type vector_type
Definition debug_iterator.h:70
virtual bool apply_update_defect(vector_type &c, vector_type &d)
forwarding call to original preconditioner
Definition debug_iterator.h:236
SmartPtr< base_type > get_preconditioner()
get reference to 'real' preconditioner
Definition debug_iterator.h:131
SmartPtr< solver_type > get_solver()
get reference to aux. solver
Definition debug_iterator.h:133
SmartPtr< base_type > m_pprecond
Definition debug_iterator.h:243
SmartPtr< vector_type > m_spSolVector
Definition debug_iterator.h:247
bool init(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
init (expensive, since it calls
Definition debug_iterator.h:177
describes a linear iterator
Definition linear_iterator.h:81
SmartPtr< IDamping< TAlgebra::vector_type, TAlgebra::vector_type > > damping()
returns the scaling
Definition linear_iterator.h:173
describes a linear mapping X->Y
Definition linear_operator.h:80
describes an inverse linear mapping X->X
Definition preconditioned_linear_operator_inverse.h:63
Definition matrix_operator.h:49
virtual M & get_matrix()
Definition matrix_operator.h:74
Definition debug_writer.h:266
void write_debug(const vector_type &vec, const char *filename)
writing debug output for a vector (if debug writer set)
Definition debug_writer.h:293
virtual void init()
#define UG_THROW(msg)
Definition error.h:57
#define UG_LOG(msg)
Definition log.h:367
the ug namespace