NeoPZ
pzvisualmatrix.cpp
Go to the documentation of this file.
1 
6 #include "pzvisualmatrix.h"
7 #include "pzfmatrix.h"
8 
9 using namespace std;
10 
14 template<class TVar>
15 void VisualMatrix(TPZFMatrix<TVar> & matrix, const std::string &outfilename)
16 {
17  int posdx = outfilename.rfind(".dx");
18  int posvtk = outfilename.rfind(".vtk");
19  int filelength = outfilename.size();
20  if(filelength-posdx == 3) {
21  VisualMatrixDX(matrix,outfilename);
22  } else if(filelength-posvtk == 4) {
23  VisualMatrixVTK(matrix,outfilename);
24  } else {
25  cout << "visualmatrix output was not created\n";
26  }
27 }
28 
30 template<class TVar>
31 void VisualMatrixDX(TPZFMatrix<TVar> & matrix, const std::string &outfilename)
32 {
33  const int nelx = matrix.Cols();
34  const int nely = matrix.Rows();
35  const int neltotal = nelx * nely;
36  int i,j;
37  ofstream out(outfilename.c_str(), ofstream::out | ofstream::binary); // binary prevents translation of "\n" under windows
38  out << "# Graphical Visualization of Matrix.\n" ;
39  out << "# Positions as the indexes of the matrix, beginning by column.\n" ;
40  out << "# The number of elements in x direction correspond to the number of the columns of the matrix.\n" ;
41  out << "# The number of elements in y direction correspond to the number of the rows of the matrix.\n" ;
42 
43  out << "object 1 class gridpositions counts " << nelx+1 << " " << nely +1 << "\n";
44  out << "origin 0. 0.\n" ;
45  out << "delta 1. 0.\n" ;
46  out << "delta 0. 1.\n" ;
47  out << "attribute \"dep\" string \"positions\"" << "\n" ;
48  out << "\n" << std::flush;
49 
50 
51  out << "object 2 class gridconnections counts " << nelx+1 << " " << nely +1 << "\n" ;
52 
53  out << "attribute \"element type\" string \"quads\"" << "\n" ;
54  out << "attribute \"ref\" string \"positions\"" << "\n" ;
55 
56  out.precision(5);
57  out << "object 3 class array type float rank 0 items " << neltotal << " data follows\n" ;
58  for (i = 0; i < nelx; i++) {
59  for(j=0; j< nely ; j++) out << matrix(i,j) << "\n" ;
60  }
61  out << "attribute \"dep\" string \"connections\" " << "\n" << std::flush;
62  out << "\n" << std::flush;
63 
64  out << "object 4 class field\n" ;
65  out << "component \"data\" value 3\n" ;
66  out << "component \"positions\" value 1\n" ;
67  out << "component \"connections\" value 2\n" ;
68  out << "attribute \"name\" string \"Matrix\"" << "\n" << std::flush;
69 
70  out << "\n" ;
71  out << "end\n" << std::flush;
72 
73  out.close();
74 
75  cout << "Data Explorer file " << outfilename << " was created with success!\n";
76 }
77 
79 template<class TVar>
80 void VisualMatrixVTK(TPZFMatrix<TVar> & matrix, const std::string &outfilename)
81 {
82  const int nelx = matrix.Cols();
83  const int nely = matrix.Rows();
84  const int neltotal = nelx * nely;
85  int i,j;
86  ofstream out(outfilename.c_str());
87  out << "# vtk DataFile Version 3.0\n";
88  out << "Generated by PZ\n";
89  out << "ASCII\n";
90  out << "DATASET RECTILINEAR_GRID\n";
91  out << "DIMENSIONS " << (nelx+1) << " " << (nely+1) << " 1\n";
92  out << "X_COORDINATES " << nelx+1 << " float\n";
93  for (i=0; i<=nelx; i++) {
94  out << i << " ";
95  }
96  out << std::endl;
97  out << "Y_COORDINATES " << nely+1 << " float\n";
98  for (j=0; j<=nely; j++) {
99  out << j << " ";
100  }
101  out << std::endl;
102  out << "Z_COORDINATES " << 1 << " float\n0.\n";
103  out << "CELL_DATA " << nelx*nely << std::endl;
104  out << "SCALARS mat_value float 1\n";
105  out << "LOOKUP_TABLE default\n";
106  const TVar *elem = 0;
107  if (neltotal) {
108  elem = &matrix(0,0);
109  }
110  for (i=0; i<neltotal; i++) {
111  out << *(elem+i) << std::endl;
112  }
113 }
114 
115 template void VisualMatrix<float>(TPZFMatrix<float> & matrix, const std::string &outfilename);
116 template void VisualMatrix<double>(TPZFMatrix<double> & matrix, const std::string &outfilename);
117 template void VisualMatrix<long double>(TPZFMatrix<long double> & matrix, const std::string &outfilename);
118 
119 template void VisualMatrix<std::complex<float> >(TPZFMatrix<std::complex<float> > & matrix, const std::string &outfilename);
120 template void VisualMatrix<std::complex<double> >(TPZFMatrix<std::complex<double> > & matrix, const std::string &outfilename);
121 template void VisualMatrix<std::complex<long double> >(TPZFMatrix<std::complex<long double> > & matrix, const std::string &outfilename);
void VisualMatrix(TPZFMatrix< TVar > &matrix, const std::string &outfilename)
This function calls the function that create a Data Explorer file or VTK file that allow to visualiz...
template void VisualMatrix< long double >(TPZFMatrix< long double > &matrix, const std::string &outfilename)
template void VisualMatrix< float >(TPZFMatrix< float > &matrix, const std::string &outfilename)
Contains the declaration of the VisualMatrix functions to VTK and DX packages.
template void VisualMatrix< double >(TPZFMatrix< double > &matrix, const std::string &outfilename)
TPZSkylMatrix< REAL > matrix
Definition: numatst.cpp:255
void VisualMatrixDX(TPZFMatrix< TVar > &matrix, const std::string &outfilename)
This function creates a Data Explorer file that allow to visualization of the value of a matrix passe...
Contains TPZMatrixclass which implements full matrix (using column major representation).
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
void VisualMatrixVTK(TPZFMatrix< TVar > &matrix, const std::string &outfilename)
This function creates a VTK file that allow to visualization of the value of a matrix passed as param...
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809