Line data Source code
1 : /*
2 : * Copyright (c) 2013-2017: 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__PPREPROCESS__
34 : #define __H__LIB_ALGEBRA__OPERATOR__INTERFACE__PPREPROCESS__
35 :
36 : #include <vector>
37 :
38 : #include "common/util/smart_pointer.h"
39 :
40 : namespace ug{
41 : ///////////////////////////////////////////////////////////////////////////////
42 : // Pre/Post Process for solvers
43 : ///////////////////////////////////////////////////////////////////////////////
44 :
45 : /// interface for pre- and postprocess functions
46 : /**
47 : * This is a base (interface) class for pre- and postprocess operations
48 : * for solvers. A typical application of these operations is the projections
49 : * eliminating the kernel parts etc.
50 : *
51 : * This class defines a generic virtual function for the vectors. If the
52 : * function requires the geometry, the RTTI should be used to cast the vector
53 : * to the grid gunction type.
54 : *
55 : * \tparam TVector the vector type in the algebra
56 : */
57 : template <typename TVector>
58 : class IPProcessVector
59 : {
60 : public:
61 : typedef TVector vector_type; ///< the vector type
62 :
63 : /// user-defined pre- or post-process function
64 : virtual void apply (vector_type& v) = 0;
65 :
66 : /// virtual destructor
67 : virtual ~IPProcessVector () {}
68 : };
69 :
70 : /// a chain of pre- or postprocess operations
71 : /**
72 : * A class for storing a chain of pre- or postprocess operations
73 : *
74 : * \tparam TVector the vector type in the algebra
75 : */
76 : template <typename TVector>
77 0 : class PProcessChain
78 : {
79 : public:
80 : typedef IPProcessVector<TVector> p_process_type;
81 : typedef TVector vector_type; ///< the vector type
82 :
83 : public:
84 :
85 : /// performs all the operations
86 0 : void apply (vector_type& v)
87 : {
88 0 : for (size_t i = 0; i < m_pp_chain.size (); i++)
89 : {
90 : SmartPtr<p_process_type> op = m_pp_chain[i];
91 0 : if (op.valid ()) op->apply (v);
92 : }
93 0 : }
94 :
95 : /// adds an operation at the end of the chain
96 : void add (SmartPtr<p_process_type> p)
97 : {
98 0 : m_pp_chain.push_back (p);
99 0 : }
100 :
101 : /// returns the number of the operations
102 : size_t size () {return m_pp_chain.size ();}
103 :
104 : /// returns the operation #i
105 : SmartPtr<p_process_type> operator [] (size_t i) {return m_pp_chain [i];}
106 :
107 : /// removes an operation from the chain
108 0 : void remove (SmartPtr<p_process_type> p)
109 : {
110 : size_t i = 0;
111 0 : while (i < m_pp_chain.size ())
112 : {
113 0 : if (m_pp_chain[i].get () == p.get ())
114 0 : m_pp_chain.erase (m_pp_chain.begin () + i);
115 : else
116 0 : i++;
117 : }
118 0 : }
119 :
120 : private:
121 :
122 : std::vector<SmartPtr<p_process_type> > m_pp_chain;
123 : };
124 :
125 : } // end namespace ug
126 : #endif /* __H__LIB_ALGEBRA__OPERATOR__INTERFACE__PPREPROCESS__ */
127 :
128 : /* End of File */
|