Line data Source code
1 : /*
2 : * Copyright (c) 2010-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__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ASSEMBLED_LINEAR_OPERATOR__
34 : #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ASSEMBLED_LINEAR_OPERATOR__
35 :
36 : #include "lib_algebra/operator/interface/operator.h"
37 : #include "lib_algebra/operator/interface/matrix_operator.h"
38 :
39 : #ifdef UG_PARALLEL
40 : #include "lib_disc/parallelization/parallelization_util.h"
41 : #endif
42 :
43 : #include "lib_disc/assemble_interface.h"
44 :
45 : namespace ug{
46 :
47 : /// matrix operator based on the assembling of a problem
48 : /**
49 : * This operator implements the MatrixOperator interface, thus is basically a
50 : * matrix that can be applied to vectors. In addition the class allows to set
51 : * an IAssemble object and an the GridLevel. Invoking the init method the
52 : * matrix is created using the IAssemble routine on the given GridLevel.
53 : *
54 : * \tparam TAlgebra algebra type
55 : */
56 : template <typename TAlgebra>
57 : class AssembledLinearOperator :
58 : public virtual MatrixOperator< typename TAlgebra::matrix_type,
59 : typename TAlgebra::vector_type>
60 : {
61 : public:
62 : /// Type of Algebra
63 : typedef TAlgebra algebra_type;
64 :
65 : /// Type of Vector
66 : typedef typename TAlgebra::vector_type vector_type;
67 :
68 : /// Type of Matrix
69 : typedef typename TAlgebra::matrix_type matrix_type;
70 :
71 : /// Type of base class
72 : typedef MatrixOperator<matrix_type,vector_type> base_type;
73 :
74 : public:
75 : /// Default Constructor
76 0 : AssembledLinearOperator() : m_spAss(NULL) {};
77 :
78 : /// Constructor
79 0 : AssembledLinearOperator(SmartPtr<IAssemble<TAlgebra> > ass) : m_spAss(ass) {};
80 :
81 : /// Constructor
82 0 : AssembledLinearOperator(SmartPtr<IAssemble<TAlgebra> > ass, const GridLevel& gl)
83 0 : : m_spAss(ass), m_gridLevel(gl) {};
84 :
85 : /// sets the discretization to be used
86 0 : void set_discretization(SmartPtr<IAssemble<TAlgebra> > ass) {m_spAss = ass;}
87 :
88 : /// returns the discretization to be used
89 : SmartPtr<IAssemble<TAlgebra> > discretization() {return m_spAss;}
90 :
91 : /// sets the level used for assembling
92 0 : void set_level(const GridLevel& gl) {m_gridLevel = gl;}
93 :
94 : /// returns the level
95 0 : const GridLevel& level() const {return m_gridLevel;}
96 :
97 : /// initializes the operator that may depend on the current solution
98 : virtual void init(const vector_type& u);
99 :
100 : /// initialize the operator
101 : virtual void init();
102 :
103 : /// initializes the operator and assembles the passed rhs vector
104 : void init_op_and_rhs(vector_type& b);
105 :
106 : /// compute d = J(u)*c (here, J(u) is a Matrix)
107 : virtual void apply(vector_type& d, const vector_type& c);
108 :
109 : /// Compute d := d - J(u)*c
110 : virtual void apply_sub(vector_type& d, const vector_type& c);
111 :
112 : /// Set Dirichlet values
113 : void set_dirichlet_values(vector_type& u);
114 :
115 : /// Destructor
116 0 : virtual ~AssembledLinearOperator() {};
117 :
118 : protected:
119 : // assembling procedure
120 : SmartPtr<IAssemble<TAlgebra> > m_spAss;
121 :
122 : // DoF Distribution used
123 : GridLevel m_gridLevel;
124 : };
125 :
126 : ///////////////////////////////////////////////////////////////////////////////
127 : ///////////////////////////////////////////////////////////////////////////////
128 :
129 : /// help function to assemble a linear operator
130 : /**
131 : * This function initializes the operator, sets the vector b to the computed rhs
132 : * and sets the dirichlet post processes for the vector u.
133 : *
134 : * \param[out] op Operator
135 : * \param[out] u Solution
136 : * \param[out] b Rigth-Hand side vector
137 : *
138 : * \tparam TAlgebra algebra type
139 : */
140 : template <typename TAlgebra>
141 : void AssembleLinearOperatorRhsAndSolution
142 : (AssembledLinearOperator<TAlgebra>& op,
143 : typename TAlgebra::vector_type& u,
144 : typename TAlgebra::vector_type& b);
145 :
146 : } // namespace ug
147 :
148 : // include implementation
149 : #include "assembled_linear_operator_impl.h"
150 :
151 : #endif /* __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ASSEMBLED_LINEAR_OPERATOR__ */
|