Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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__LIB_ALGEBRA__OPERATOR__ALGEBRA_DEBUG_WRITER__
34 : #define __H__LIB_ALGEBRA__OPERATOR__ALGEBRA_DEBUG_WRITER__
35 :
36 : #include "debug_writer.h"
37 : #include "lib_algebra/common/connection_viewer_output.h"
38 : #include "common/util/file_util.h"
39 :
40 : namespace ug{
41 :
42 :
43 : /// Debug writer for connection viewer (based on algebraic information + vector positions only)
44 : template <typename TAlgebra>
45 : class AlgebraDebugWriter : public IDebugWriter<TAlgebra>
46 : {
47 : public:
48 : /// type of matrix
49 : typedef TAlgebra algebra_type;
50 :
51 : /// type of vector
52 : typedef typename algebra_type::vector_type vector_type;
53 :
54 : /// type of matrix
55 : typedef typename algebra_type::matrix_type matrix_type;
56 :
57 : /// type of base
58 : typedef IDebugWriter<TAlgebra> base_type;
59 : using base_type::get_base_dir;
60 :
61 : public:
62 : /// Constructor
63 0 : AlgebraDebugWriter() : base_type() {}
64 :
65 : /// write vector
66 0 : virtual void write_vector(const vector_type& vec,
67 : const char* filename)
68 : {
69 0 : switch (base_type::current_dimension())
70 : {
71 0 : case 1: write_vector_dim<1>(vec, filename); break;
72 0 : case 2: write_vector_dim<2>(vec, filename); break;
73 0 : case 3: write_vector_dim<3>(vec, filename); break;
74 0 : default: UG_ASSERT(0, "Dimension not implemented.");
75 : }
76 0 : }
77 :
78 : /// write matrix
79 0 : virtual void write_matrix(const matrix_type& mat,
80 : const char* filename)
81 : {
82 : // check name
83 0 : if( !FileTypeIs( filename, ".mat" ) ) {
84 0 : UG_THROW( "Only '.mat' format supported for matrices, but"
85 : " filename is '" << filename << "'.");
86 : }
87 : // write to file
88 0 : switch (base_type::current_dimension())
89 : {
90 0 : case 1: write_matrix_dim<1>(mat, filename); break;
91 0 : case 2: write_matrix_dim<2>(mat, filename); break;
92 0 : case 3: write_matrix_dim<3>(mat, filename); break;
93 0 : default: UG_ASSERT(0, "Dimension not implemented.");
94 : }
95 :
96 0 : }
97 : private:
98 : /// auxiliary function for vectors
99 : template <int dim>
100 0 : void write_vector_dim(const vector_type& vec, const char* filename)
101 : {
102 0 : std::string name = get_base_dir() + "/" + filename;
103 0 : const std::vector<MathVector<dim> > &posvec = base_type::template get_positions<dim>();
104 : // check size
105 0 : if(vec.size() > posvec.size())
106 0 : UG_THROW("'AlgebraDebugWriter::write_vector':"
107 : " Number of positions does not match. Vector has "
108 : << vec.size() << " elements, but " << posvec.size() << " positions were supplied!\n");
109 :
110 : // write connection viewer output to file
111 0 : ConnectionViewer::WriteVectorPar<vector_type, MathVector<dim> >(name, vec, &posvec[0], dim);
112 :
113 0 : }
114 :
115 : /// auxiliary function for matrices
116 : template <int dim>
117 0 : void write_matrix_dim(const matrix_type& mat,
118 : const char* filename)
119 : {
120 0 : std::string name = get_base_dir() + "/" + filename;
121 0 : const std::vector<MathVector<dim> > &posvec = base_type::template get_positions<dim>();
122 : // check size
123 0 : if(mat.num_rows() > posvec.size() || mat.num_cols() > posvec.size())
124 0 : UG_THROW("'AlgebraDebugWriter::write_matrix':"
125 : " Number of positions does not match: Matrix has "
126 : << mat.num_rows() << " rows, " << mat.num_cols() << " cols, but "
127 : << posvec.size()<< "positions were supplied." << "\n");
128 : // write to connection viewer
129 : ConnectionViewer::WriteMatrixPar<matrix_type, MathVector<dim> >
130 0 : ( name, mat, &base_type::template get_positions<dim>()[0], dim);
131 :
132 0 : }
133 :
134 : };
135 :
136 : } // end namespace ug
137 :
138 : #endif /* __H__LIB_ALGEBRA__OPERATOR__ALGEBRA_DEBUG_WRITER__ */
|