DUNE-FEM (unstable)

periodicfacetrans.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_DGF_PERIODICFACETRANSBLOCK_HH
6#define DUNE_DGF_PERIODICFACETRANSBLOCK_HH
7
8#include <iostream>
9#include <vector>
10
11#include <dune/grid/io/file/dgfparser/blocks/basic.hh>
12
13
14namespace Dune
15{
16
17 namespace dgf
18 {
19
20 // PeriodicFaceTransformationBlock
21 // -------------------------------
22
23 struct PeriodicFaceTransformationBlock
24 : public BasicBlock
25 {
26 template< class T >
27 class Matrix
28 {
29 int rows_;
30 int cols_;
31 std::vector< T > fields_;
32
33 public:
34 Matrix ( int rows, int cols )
35 : rows_( rows ),
36 cols_( cols ),
37 fields_( rows * cols )
38 {}
39
40 const T &operator() ( int i, int j ) const
41 {
42 return fields_[ i * cols_ + j ];
43 }
44
45 T &operator() ( int i, int j )
46 {
47 return fields_[ i * cols_ + j ];
48 }
49
50 int rows () const
51 {
52 return rows_;
53 }
54
55 int cols () const
56 {
57 return cols_;
58 }
59 };
60
61 struct AffineTransformation
62 {
63 Matrix< double > matrix;
64 std::vector< double > shift;
65
66 explicit AffineTransformation ( int dimworld )
67 : matrix( dimworld, dimworld ),
68 shift( dimworld )
69 {}
70 };
71
72 private:
73 std::vector< AffineTransformation > transformations_;
74
75 // copy not implemented
76 PeriodicFaceTransformationBlock ( const PeriodicFaceTransformationBlock & );
77
78 public:
79 // initialize block and get dimension of world
80 PeriodicFaceTransformationBlock ( std::istream &in, int dimworld );
81
82 const AffineTransformation &transformation ( int i ) const
83 {
84 assert( i < numTransformations() );
85 return transformations_[ i ];
86 }
87
88 int numTransformations () const
89 {
90 return transformations_.size();
91 }
92
93 private:
94 void match ( char what );
95 };
96
97
98
99 // PeriodicFaceTransformationBlock::AffineTransformation
100 // -----------------------------------------------------
101
102
103 inline std::ostream &
104 operator<< ( std::ostream &out, const PeriodicFaceTransformationBlock::AffineTransformation &trafo )
105 {
106 for( int i = 0; i < trafo.matrix.rows(); ++i )
107 {
108 out << (i > 0 ? ", " : "");
109 for( int j = 0; j < trafo.matrix.cols(); ++j )
110 out << (j > 0 ? " " : "") << trafo.matrix( i, j );
111 }
112 out << " +";
113 for( unsigned int i = 0; i < trafo.shift.size(); ++i )
114 out << " " << trafo.shift[ i ];
115 return out;
116 }
117
118 } // end namespace dgf
119
120} // end namespace Dune
121
122#endif
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)