ug4
Loading...
Searching...
No Matches
overlap_writer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
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_overlap_writer
34#define __H__UG_overlap_writer
35
36#include <vector>
37#include "common/error.h"
41
42namespace ug{
43
45
51template <class TAlgebra>
53public:
54 typedef typename TAlgebra::vector_type vector_type;
55 typedef typename TAlgebra::matrix_type matrix_type;
56
57 OverlapWriter () : m_dim (-1) {}
58
66 template <class vector_t>
67 void init(const AlgebraLayouts& layouts,
68 size_t nonOverlapVecSize,
69 vector_t* nonOverlapPositions,
70 size_t overlapVecSize)
71 {
72 using namespace std;
73
74 UG_COND_THROW(nonOverlapVecSize > overlapVecSize,
75 "nonOverlapVecSize > overlapVecSize. "
76 "This should not be the case!");
77
78 m_dim = vector_t::Size;
79 vector<MathVector<vector_t::Size> >& pos = get_pos (Int2Type<vector_t::Size>());
80
81 pos.resize(overlapVecSize);
82 for(size_t i = 0; i < nonOverlapVecSize; ++i){
83 pos[i] = nonOverlapPositions[i];
84 }
85
86 // copy positions from slave-overlap to master-overlap
87 CopyValues(&pos, layouts.slave_overlap(), layouts.master_overlap(),
88 &layouts.comm());
89 }
90
97 inline
98 void init(const AlgebraLayouts& layouts,
100 size_t overlapVecSize)
101 {
102 m_dim = dbgWriter.get_dim();
103
104 switch(m_dim) {
105 case 1: init(layouts, dbgWriter.template get_positions<1>().size(),
106 &dbgWriter.template get_positions<1>().front(),
107 overlapVecSize);
108 break;
109 case 2: init(layouts, dbgWriter.template get_positions<2>().size(),
110 &dbgWriter.template get_positions<2>().front(),
111 overlapVecSize);
112 break;
113 case 3: init(layouts, dbgWriter.template get_positions<3>().size(),
114 &dbgWriter.template get_positions<3>().front(),
115 overlapVecSize);
116 break;
117 default: UG_THROW("Unsupported dimension: " << m_dim); break;
118 }
119 }
120
121
124 template <class T>
125 void write(const T& t, std::string name)
126 {
127 UG_COND_THROW (m_dim == -1, "Call 'OverlapWriter::init before calling "
128 "OverlapWriter::write");
129
130 switch(m_dim) {
131 case 1: write_dim_<1>(t, name); break;
132 case 2: write_dim_<2>(t, name); break;
133 case 3: write_dim_<3>(t, name); break;
134 }
135 }
136
137
138private:
139 template <int dim>
140 void write_dim_(const vector_type& v, std::string name)
141 {
142 std::vector<MathVector<dim> >& pos = get_pos(Int2Type<dim>());
143 ConnectionViewer::WriteVectorPar(name + ".vec", v, &pos.front(), m_dim);
144 }
145
146 template <int dim>
147 void write_dim_(const matrix_type& A, std::string name)
148 {
149 std::vector<MathVector<dim> >& pos = get_pos(Int2Type<dim>());
150 ConnectionViewer::WriteMatrixPar(name + ".mat", A, &pos.front(), m_dim);
151 }
152
153 std::vector<MathVector<1> >& get_pos(Int2Type<1>) {return m_pos1d;}
154 std::vector<MathVector<2> >& get_pos(Int2Type<2>) {return m_pos2d;}
155 std::vector<MathVector<3> >& get_pos(Int2Type<3>) {return m_pos3d;}
156
157 // MEMBER VARIABLES
158 int m_dim;
159
160 std::vector<MathVector<1> > m_pos1d;
161 std::vector<MathVector<2> > m_pos2d;
162 std::vector<MathVector<3> > m_pos3d;
163};
164
165}// end of namespace
166
167#endif //__H__UG_overlap_writer
location name
Definition checkpoint_util.lua:128
Extends the HorizontalAlgebraLayouts by vertical layouts.
Definition algebra_layouts.h:121
const IndexLayout & slave_overlap() const
Definition algebra_layouts.h:64
pcl::InterfaceCommunicator< IndexLayout > & comm() const
returns (non-const !!!) communicator
Definition algebra_layouts.h:78
const IndexLayout & master_overlap() const
Definition algebra_layouts.h:62
base class for all vector debug writer
Definition debug_writer.h:118
int get_dim() const
get the dimensionality
Definition debug_writer.h:167
Writes overlapping matrices and vectors.
Definition overlap_writer.h:52
std::vector< MathVector< 2 > > & get_pos(Int2Type< 2 >)
Definition overlap_writer.h:154
std::vector< MathVector< 3 > > & get_pos(Int2Type< 3 >)
Definition overlap_writer.h:155
std::vector< MathVector< 1 > > & get_pos(Int2Type< 1 >)
Definition overlap_writer.h:153
std::vector< MathVector< 3 > > m_pos3d
Definition overlap_writer.h:162
int m_dim
Definition overlap_writer.h:158
OverlapWriter()
Definition overlap_writer.h:57
void init(const AlgebraLayouts &layouts, IVectorDebugWriter< vector_type > &dbgWriter, size_t overlapVecSize)
Definition overlap_writer.h:98
TAlgebra::vector_type vector_type
Definition overlap_writer.h:54
void write(const T &t, std::string name)
Definition overlap_writer.h:125
TAlgebra::matrix_type matrix_type
Definition overlap_writer.h:55
std::vector< MathVector< 2 > > m_pos2d
Definition overlap_writer.h:161
void write_dim_(const vector_type &v, std::string name)
Definition overlap_writer.h:140
void init(const AlgebraLayouts &layouts, size_t nonOverlapVecSize, vector_t *nonOverlapPositions, size_t overlapVecSize)
Definition overlap_writer.h:67
std::vector< MathVector< 1 > > m_pos1d
Definition overlap_writer.h:160
void write_dim_(const matrix_type &A, std::string name)
Definition overlap_writer.h:147
void CopyValues(TVector *pVec, const IndexLayout &sourceLayout, const IndexLayout &targetLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
Copies values from the source to the target layout.
Definition parallelization_util.h:228
virtual void init()
#define UG_THROW(msg)
Definition error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
Definition smart_pointer.h:814
void WriteVectorPar(std::string filename, const Vector_type &b, const postype *positions, int dimensions, const Vector_type *compareVec=NULL)
Definition connection_viewer_output.h:425
void WriteMatrixPar(std::string name, const Matrix_type &A, const postype *positions, int dimensions)
Definition connection_viewer_output.h:153
the ug namespace
Definition metaprogramming_util.h:42