Dune Core Modules (2.9.1)

periodicfacetrans.hh
1// SPDX-FileCopyrightText: Copyright (C) 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 struct AffineTransformation;
30
31 private:
32 std::vector< AffineTransformation > transformations_;
33
34 // copy not implemented
35 PeriodicFaceTransformationBlock ( const PeriodicFaceTransformationBlock & );
36
37 public:
38 // initialize block and get dimension of world
39 PeriodicFaceTransformationBlock ( std::istream &in, int dimworld );
40
41 const AffineTransformation &transformation ( int i ) const
42 {
43 assert( i < numTransformations() );
44 return transformations_[ i ];
45 }
46
47 int numTransformations () const
48 {
49 return transformations_.size();
50 }
51
52 private:
53 void match ( char what );
54 };
55
56
57 // PeriodicFaceTransformationBlock::Matrix
58 // ---------------------------------------
59
60 template< class T >
61 class PeriodicFaceTransformationBlock::Matrix
62 {
63 int rows_;
64 int cols_;
65 std::vector< T > fields_;
66
67 public:
68 Matrix ( int rows, int cols )
69 : rows_( rows ),
70 cols_( cols ),
71 fields_( rows * cols )
72 {}
73
74 const T &operator() ( int i, int j ) const
75 {
76 return fields_[ i * cols_ + j ];
77 }
78
79 T &operator() ( int i, int j )
80 {
81 return fields_[ i * cols_ + j ];
82 }
83
84 int rows () const
85 {
86 return rows_;
87 }
88
89 int cols () const
90 {
91 return cols_;
92 }
93 };
94
95
96 // PeriodicFaceTransformationBlock::AffineTransformation
97 // -----------------------------------------------------
98
99 struct PeriodicFaceTransformationBlock::AffineTransformation
100 {
101 Matrix< double > matrix;
102 std::vector< double > shift;
103
104 explicit AffineTransformation ( int dimworld )
105 : matrix( dimworld, dimworld ),
106 shift( dimworld )
107 {}
108 };
109
110
111 inline std::ostream &
112 operator<< ( std::ostream &out, const PeriodicFaceTransformationBlock::AffineTransformation &trafo )
113 {
114 for( int i = 0; i < trafo.matrix.rows(); ++i )
115 {
116 out << (i > 0 ? ", " : "");
117 for( int j = 0; j < trafo.matrix.cols(); ++j )
118 out << (j > 0 ? " " : "") << trafo.matrix( i, j );
119 }
120 out << " +";
121 for( unsigned int i = 0; i < trafo.shift.size(); ++i )
122 out << " " << trafo.shift[ i ];
123 return out;
124 }
125
126 } // end namespace dgf
127
128} // end namespace Dune
129
130#endif
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)