3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
localstiffness.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_LOCAL_STIFFNESS_HH
25#define DUMUX_LOCAL_STIFFNESS_HH
26
27#include <array>
28#include<iostream>
29#include<vector>
30#include<set>
31#include<map>
32
33#include<dune/common/timer.hh>
34#include<dune/common/fvector.hh>
35#include<dune/common/fmatrix.hh>
36#include<dune/geometry/type.hh>
37#include<dune/grid/common/grid.hh>
38#include<dune/istl/operators.hh>
39#include<dune/istl/bvector.hh>
40#include<dune/istl/matrix.hh>
41
44
45namespace Dumux {
46
58template<class TypeTag, int m>
60{
63 // grid types
64 using Entity = typename GridView::template Codim<0>::Entity;
65 enum {n=GridView::dimension};
66
67public:
68 // types for matrics, vectors and boundary conditions
69 using MBlockType = Dune::FieldMatrix<Scalar, m, m>; // one entry in the stiffness matrix
70 using VBlockType = Dune::FieldVector<Scalar, m>; // one entry in the global vectors
71 using BCBlockType = std::array<BoundaryConditions::Flags, m>; // componentwise boundary conditions
73
74 virtual ~LocalStiffness ()
75 {
76 }
77
98 virtual void assemble (const Entity& e, int k=1) = 0;
99
124 virtual void assemble (const Entity& e, const Dune::BlockVector<VBlockType>& localSolution, int k=1) = 0;
125
145 virtual void assembleBoundaryCondition (const Entity& e, int k=1) = 0;
146
154 void print (std::ostream& s, int width, int precision)
155 {
156 // set the output format
157 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
158 int oldprec = s.precision();
159 s.precision(precision);
160
161 for (int i=0; i<currentsize(); i++)
162 {
163 s << "FEM"; // start a new row
164 s << " "; // space in front of each entry
165 s.width(4); // set width for counter
166 s << i; // number of first entry in a line
167 for (int j=0; j<currentsize(); j++)
168 {
169 s << " "; // space in front of each entry
170 s.width(width); // set width for each entry anew
171 s << mat(i,j); // yeah, the number !
172 }
173 s << " "; // space in front of each entry
174 s.width(width); // set width for each entry anew
175 s << rhs(i);
176 s << " "; // space in front of each entry
177 s.width(width); // set width for each entry anew
178 s << bc(i)[0];
179 s << std::endl;// start a new line
180 }
181
182
183 // reset the output format
184 s.precision(oldprec);
185 s.setf(std::ios_base::fixed, std::ios_base::floatfield);
186 }
187
197 const MBlockType& mat (int i, int j) const
198 {
199 return A[i][j];
200 }
201
210 const VBlockType& rhs (int i) const
211 {
212 return b[i];
213 }
214
223 const BoundaryTypes& bc (int i) const
224 {
225 return bctype[i];
226 }
227
233 void setcurrentsize (int s)
234 {
235 A.setSize(s,s);
236 b.resize(s);
237 bctype.resize(s);
238 }
239
244 {
245 return A.N();
246 }
247
248protected:
249 // assembled data
250 Dune::Matrix<MBlockType> A;
251 std::vector<VBlockType> b;
252 std::vector<BoundaryTypes> bctype;
253};
254
266template<class TypeTag, int m>
267class LinearLocalStiffness : public LocalStiffness<TypeTag,m>
268{
271
272 // grid types
273 using Entity = typename GridView::template Codim<0>::Entity;
274 enum {n=GridView::dimension};
275
276public:
277 // types for matrics, vectors and boundary conditions
278 using MBlockType = Dune::FieldMatrix<Scalar, m, m>; // one entry in the stiffness matrix
279 using VBlockType = Dune::FieldVector<Scalar, m>; // one entry in the global vectors
280 using BCBlockType = std::array<BoundaryConditions::Flags, m>; // componentwise boundary conditions
281
284 {}
285
287 {
288 }
289
310 virtual void assemble (const Entity& e, int k=1) = 0;
311
321 virtual void assemble (const Entity& e, const Dune::BlockVector<VBlockType>& localSolution, int k=1)
322 {
323 assemble(e,k);
324 }
325};
326
327} // end namespace Dumux
328#endif
Definition of boundary condition types, extend if necessary.
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Base class for local assemblers.
Definition: localstiffness.hh:60
virtual ~LocalStiffness()
Definition: localstiffness.hh:74
void print(std::ostream &s, int width, int precision)
Prints contents of local stiffness matrix.
Definition: localstiffness.hh:154
Dune::FieldMatrix< Scalar, m, m > MBlockType
Definition: localstiffness.hh:69
int currentsize()
Gets the current size of the local stiffness matrix.
Definition: localstiffness.hh:243
GetPropType< TypeTag, Properties::BoundaryTypes > BoundaryTypes
Definition: localstiffness.hh:72
std::array< BoundaryConditions::Flags, m > BCBlockType
Definition: localstiffness.hh:71
const VBlockType & rhs(int i) const
Accesses right hand side.
Definition: localstiffness.hh:210
const MBlockType & mat(int i, int j) const
Accesses the local stiffness matrix.
Definition: localstiffness.hh:197
virtual void assembleBoundaryCondition(const Entity &e, int k=1)=0
assemble only boundary conditions for given element and order
void setcurrentsize(int s)
Sets the current size of the local stiffness matrix.
Definition: localstiffness.hh:233
const BoundaryTypes & bc(int i) const
Accesses boundary condition for each dof.
Definition: localstiffness.hh:223
Dune::Matrix< MBlockType > A
Definition: localstiffness.hh:250
Dune::FieldVector< Scalar, m > VBlockType
Definition: localstiffness.hh:70
virtual void assemble(const Entity &e, int k=1)=0
Assembles local stiffness matrix including boundary conditions for given element and order.
virtual void assemble(const Entity &e, const Dune::BlockVector< VBlockType > &localSolution, int k=1)=0
assemble local stiffness matrix including boundary conditions for given element and order
std::vector< VBlockType > b
Definition: localstiffness.hh:251
std::vector< BoundaryTypes > bctype
Definition: localstiffness.hh:252
Base class for linear local assemblers.
Definition: localstiffness.hh:268
virtual void assemble(const Entity &e, const Dune::BlockVector< VBlockType > &localSolution, int k=1)
Assembles local stiffness matrix including boundary conditions for given element and order.
Definition: localstiffness.hh:321
virtual void assemble(const Entity &e, int k=1)=0
Assembles local stiffness matrix including boundary conditions for given element and order.
virtual ~LinearLocalStiffness()
Definition: localstiffness.hh:286
LinearLocalStiffness()
Definition: localstiffness.hh:283
Base file for properties related to sequential models.