KASKADE 7 development version
reshape.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2024-2024 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef RESHAPE_HH
14#define RESHAPE_HH
15
16#include "dune/istl/bvector.hh"
17
18#include <cassert>
19
20namespace Kaskade
21{
22
24 template <class Entry>
25 class DynamicMatrix;
27
28
43 template <int n, class Entry, int m, class A>
46 {
47 assert( (x.N()*m) % n == 0);
49 for (int i=0; i<x.N(); ++i)
50 for (int j=0; j<m; ++j)
51 {
52 int k = (m*i+j) / n;
53 int l = (m*i+j) % n;
54 y[k][l] = x[i][j];
55 }
56
57 return y;
58 }
59
60 // ----------------------------------------------------------------------------------------------
61
62 template <class Kb, int nb, int mb, class Ka, int na, int ma>
63 DynamicMatrix<Dune::FieldMatrix<Kb,nb,mb>>
65 {
66 assert( (A.N()*na) % nb == 0 );
67 assert( (A.M()*ma) % mb == 0 );
68
69 DynamicMatrix<Dune::FieldMatrix<Kb,nb,mb>> B(A.N()*na/nb,A.M()*ma/mb);
70 for (int j=0; j<A.M(); ++j)
71 for (int i=0; i<A.N(); ++i)
72 for (int k=0; k<na; ++k)
73 for (int l=0; l<ma; ++l)
74 {
75 int r = i*na+k;
76 int c = j*ma+l;
77 B[r/nb][c/mb][r%nb][c%mb] = A[i][j][k][l];
78 }
79 return B;
80 }
81
82}
83
84#endif
A LAPACK-compatible dense matrix class with shape specified at runtime.
Dune::BlockVector< Dune::FieldVector< double, dimOut > > reshapeBlocks(Dune::BlockVector< Dune::FieldVector< double, dimIn > > const &b)
reshapes a Dune::BlockVector block structure