ug4
algebra_debug_writer.h
Go to the documentation of this file.
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"
38 #include "common/util/file_util.h"
39 
40 namespace ug{
41 
42 
44 template <typename TAlgebra>
45 class AlgebraDebugWriter : public IDebugWriter<TAlgebra>
46 {
47  public:
49  typedef TAlgebra algebra_type;
50 
52  typedef typename algebra_type::vector_type vector_type;
53 
55  typedef typename algebra_type::matrix_type matrix_type;
56 
60 
61  public:
64 
66  virtual void write_vector(const vector_type& vec,
67  const char* filename)
68  {
70  {
71  case 1: write_vector_dim<1>(vec, filename); break;
72  case 2: write_vector_dim<2>(vec, filename); break;
73  case 3: write_vector_dim<3>(vec, filename); break;
74  default: UG_ASSERT(0, "Dimension not implemented.");
75  }
76  }
77 
79  virtual void write_matrix(const matrix_type& mat,
80  const char* filename)
81  {
82  // check name
83  if( !FileTypeIs( filename, ".mat" ) ) {
84  UG_THROW( "Only '.mat' format supported for matrices, but"
85  " filename is '" << filename << "'.");
86  }
87  // write to file
89  {
90  case 1: write_matrix_dim<1>(mat, filename); break;
91  case 2: write_matrix_dim<2>(mat, filename); break;
92  case 3: write_matrix_dim<3>(mat, filename); break;
93  default: UG_ASSERT(0, "Dimension not implemented.");
94  }
95 
96  }
97  private:
99  template <int dim>
100  void write_vector_dim(const vector_type& vec, const char* filename)
101  {
102  std::string name = get_base_dir() + "/" + filename;
103  const std::vector<MathVector<dim> > &posvec = base_type::template get_positions<dim>();
104  // check size
105  if(vec.size() > posvec.size())
106  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  ConnectionViewer::WriteVectorPar<vector_type, MathVector<dim> >(name, vec, &posvec[0], dim);
112 
113  }
114 
116  template <int dim>
117  void write_matrix_dim(const matrix_type& mat,
118  const char* filename)
119  {
120  std::string name = get_base_dir() + "/" + filename;
121  const std::vector<MathVector<dim> > &posvec = base_type::template get_positions<dim>();
122  // check size
123  if(mat.num_rows() > posvec.size() || mat.num_cols() > posvec.size())
124  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  ( name, mat, &base_type::template get_positions<dim>()[0], dim);
131 
132  }
133 
134 };
135 
136 } // end namespace ug
137 
138 #endif /* __H__LIB_ALGEBRA__OPERATOR__ALGEBRA_DEBUG_WRITER__ */
location name
Definition: checkpoint_util.lua:128
Debug writer for connection viewer (based on algebraic information + vector positions only)
Definition: algebra_debug_writer.h:46
virtual void write_matrix(const matrix_type &mat, const char *filename)
write matrix
Definition: algebra_debug_writer.h:79
AlgebraDebugWriter()
Constructor.
Definition: algebra_debug_writer.h:63
algebra_type::matrix_type matrix_type
type of matrix
Definition: algebra_debug_writer.h:55
void write_vector_dim(const vector_type &vec, const char *filename)
auxiliary function for vectors
Definition: algebra_debug_writer.h:100
algebra_type::vector_type vector_type
type of vector
Definition: algebra_debug_writer.h:52
IDebugWriter< TAlgebra > base_type
type of base
Definition: algebra_debug_writer.h:58
TAlgebra algebra_type
type of matrix
Definition: algebra_debug_writer.h:49
void write_matrix_dim(const matrix_type &mat, const char *filename)
auxiliary function for matrices
Definition: algebra_debug_writer.h:117
virtual void write_vector(const vector_type &vec, const char *filename)
write vector
Definition: algebra_debug_writer.h:66
base class for all debug writer
Definition: debug_writer.h:244
std::string get_base_dir()
Definition: debug_writer.h:192
int current_dimension() const
returns the current dimension
Definition: debug_writer.h:135
File utility functions.
static const int dim
bool FileTypeIs(const char *filename, const char *extension)
!!! Serial i/o version !!!
Definition: file_util.cpp:86
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
the ug namespace