Debug.h 8.96 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25

/** \file Debug.h */

#ifndef AMDIS_DEBUG_H
#define AMDIS_DEBUG_H

26
#include <set>
27
28
29
30
31
32
#include "AMDiS_fwd.h"
#include "Global.h"

namespace AMDiS {
  
  namespace debug {
33
34
35
36
37
38
39
40
41
42

    struct DofPtrSortFct {
      bool operator() (const DegreeOfFreedom *dof0, const DegreeOfFreedom *dof1) 
      {
	return (*dof0 < *dof1);
      }
    };

    typedef std::map<int, DofContainer> ElementIdxToDofs;

43
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
44
45
46
    void writeLocalElementDofs(int rank, 
			       int elIdx, 
			       const FiniteElemSpace *feSpace);
47
    
48
49
50
    void writeMesh(const FiniteElemSpace *feSpace, 
		   int rank, 
		   std::string filename);
51
    
52
53
54
55
56
57
58
59
60
61
    /** \brief
     * Writes a vtu file with the mesh, where all DOFs are set to zero, and only
     * one given DOF is set to one. This can be used to easily identify DOFs in
     * a mesh.
     *
     * \param[in]  rank     If set to -1, the vtu files are written on all ranks.
     *                      Otherwise, only on the given rank the mesh is written. 
     * \param[in]  dof      Defines the DOF, which value is set to one in the mesh file.
     * \param[in]  feSpace  The FE space to be used.
     */
62
63
64
    void writeDofMesh(int rank, 
		      DegreeOfFreedom dof, 
		      const FiniteElemSpace *feSpace);
65
#endif
66
67
68

    /** \brief
     * Create a vtu file with name 'dofindex.vtu'. All nodes in the mesh are colored
69
     * by the global DOF index.
70
     *
71
72
     * \param[in]  feSpace   The FE space to be used.
     * \param[in]  filename  Name of the VTU file
73
     */
74
75
    void writeDofIndexMesh(const FiniteElemSpace *feSpace, 
			   string filename = "dofindex.vtu");
76

77
    void colorEdgeInMesh(const FiniteElemSpace *feSpace,
78
79
80
81
			 Element *el, 
			 int localEdgeNo, 
			 std::string filename);

82
    /** \brief
83
84
     * Creates a vtu file where all elements in the mesh are colored by the
     * global element indices.
85
86
87
     *
     * \param[in]  feSpace   The FE space to be used.
     * \param[in]  filename  Name of the file.
88
89
90
     * \param[in]  level     If level is -1, all leaf elements will be put to
     *                       the output file, otherwise the elements with the
     *                       given level.
91
     */
92
93
94
    void writeElementIndexMesh(Mesh *mesh, 
			       std::string filename, 
			       int level = -1);
95

96
97
98
99
100
101
102
103
104
105
    /** \brief
     * Creates a vtu file where all elements in the mesh are colored by the
     * macro element indices.
     *
     * \param[in]  feSpace   The FE space to be used.
     * \param[in]  filename  Name of the file.
     */
    void writeMacroElementIndexMesh(Mesh *mesh,
				    std::string filename);

106
    void highlightElementIndexMesh(Mesh *mesh, int idx, std::string filename);
107

108
109
    void colorMeshByMacroIndex(Mesh *mesh, std::string filename);

110
111
112
113
114
115
    void colorDofVectorByLocalElementDofs(DOFVector<double>& vec, Element *el);
    
    bool colorDofVectorByLocalElementDofs(DOFVector<double>& vec, 
					  Mesh *mesh, 
					  int elIndex);
    
116
117
    Element* getDofIndexElement(const FiniteElemSpace *feSpace, 
				DegreeOfFreedom dof);
118
119
    
    Element* getLevel0ParentElement(Mesh *mesh, Element *el);
120

121
122
    Element* getLevel0ParentElement(Mesh *mesh, int elIndex);

123
124
125
126
    Element* getParentElement(Mesh *mesh, Element *el);

    Element* getParentElement(Mesh *mesh, int elIndex);

Thomas Witkowski's avatar
Thomas Witkowski committed
127
128
    Element* getElement(Mesh *mesh, int elIndex);

129
    void printElementInfo(Element *el);
130
131

    void printElementCoords(const FiniteElemSpace *feSpace, Element *el);
132
    
133
    void printInfoByDof(const FiniteElemSpace *feSpace, DegreeOfFreedom dof);
Thomas Witkowski's avatar
Thomas Witkowski committed
134
135

    void printMatValuesStatistics(Matrix<DOFMatrix*> *mat);
136

137
    void printAllDofCoords(const FiniteElemSpace *feSpace);
138

139
140
    void getAllDofs(const FiniteElemSpace *feSpace, 
		    std::set<const DegreeOfFreedom*>& dofs);
141

Thomas Witkowski's avatar
Thomas Witkowski committed
142
143
144
145
146
147
148
149
150
    /** \brief
     * Creates a text file storing the value of a sparse matrix. Each line of the file
     * has three columns:
     *    row  col  value
     * This file can be used in Matlab using the command "spconvert".
     *
     * \param[in]  mat       The matrix which is used the write the text file.
     * \param[in]  filename  Name of the file to be created.
     */
151
152
    void writeMatlabMatrix(DOFMatrix &mat, std::string filename);

Thomas Witkowski's avatar
Thomas Witkowski committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    /** \brief
     * Creates a text file storing the value of a sparse matrix. Each line of the file
     * has three columns:
     *    row  col  value
     * This file can be used in Matlab using the command "spconvert". The function 
     * works only for a matrix of DOFMatrices, that are all defined from the same
     * FE spaces.
     *
     * \param[in]  mat       The matrix which is used the write the text file.
     * \param[in]  filename  Name of the file to be created.     
     */
    void writeMatlabMatrix(Matrix<DOFMatrix*> &mat, std::string filename);

    /** \brief
     *
     */
169
    void writeMatlabVector(DOFVector<double> &vec, std::string filename);
170

171
172
    void writeMatlabVector(SystemVector &vec, std::string filename);

Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
    void writeCoordsFile(const FiniteElemSpace *feSpace, std::string filename);

Thomas Witkowski's avatar
Thomas Witkowski committed
175
176
    void printElementHierarchie(Mesh *mesh, int elIndex);    

Thomas Witkowski's avatar
Thomas Witkowski committed
177
    void printElementRefinementSequence(Mesh *mesh, Element *el);
178

179
180
    int getLocalNeighbourIndex(Mesh *mesh, int elIndex, int neighIndex);

181
182
    void importDofVectorByCoords(DOFVector<double>* vec, std::string filename);

183
184
185
    void exportDofVectorByCoords(const DOFVector<double>* vec, 
				 std::string filename);

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    /** \brief
     * Traverse a mesh and store for each element all its vertex DOFs in local sorted 
     * order (by values).
     *
     * \param[in]   mesh    Mesh to be traversed.
     * \param[out]  elMap   Stores to each element the vertex DOFs in sorted order.
     */
    void createSortedDofs(Mesh *mesh, ElementIdxToDofs &elMap);

    /** \brief
     * Takes a map from element indices to lists of DOFs. Checks, if for each element
     * in the mesh the vertex value order is still valid.
     *
     * The element index map must be created by the function \createSortedDofs. Using
     * both functions it can be checked if a renumbering of dofs does not changes the
     * local vertex value order (which is required by AMDiS to be always equal on each
     * element).
     *
     * If the test fails, the function prints some debug information to screen and
     * terminates the programm.
     *
     * \param[in]  mesh   Mesh to be traversed.
     * \param[in]  elMap  Map from element indices to lists of DOFs. It is used to check
     *                    the validaty as described above.
     */
    void testSortedDofs(Mesh *mesh, ElementIdxToDofs &elMap);

    /// Takes tree dofs and returns a list with the dofs sorted by their values.
    void sortDofs(const DegreeOfFreedom* dof0,
		  const DegreeOfFreedom* dof1,
		  const DegreeOfFreedom* dof2,
		  DofContainer &vec);

    /// Takes four dofs and returns a list with the dofs sorted by their values.
    void sortDofs(const DegreeOfFreedom* dof0,
		  const DegreeOfFreedom* dof1,
		  const DegreeOfFreedom* dof2,
		  const DegreeOfFreedom* dof3,
		  DofContainer &vec);    

226
227
228
229
230
231
232
233
234
235
236
237
238
239
    /** \brief
     * Takes to vectors of DOF indices and tests if they pairwise equal. To test
     * for equality, coordinates are checked. This makes it possible to test 
     * internal algorithms that manipulate the mesh having two DOFs at the same
     * geometrical position.
     *
     * This function does not return any value but abort the execution if it
     * find two DOFs not to be equal.
     *
     * \param[in]   feSpace   Finite element space which is used to create
     *                        coordinates.
     * \param[in]   dofs0     First DOF container.
     * \paran[in]   dofs1     Second DOF container.
     */
240
    void testDofsByCoords(const FiniteElemSpace *feSpace,
241
242
			  DofContainer &dofs0, 
			  DofContainer &dofs1);
243

244
245
246
247
248
249
250
251
252
253
254
255
    /** \brief
     * Works in the same way as described above, but the calling function
     * must provide a DOFVector which contains all DOF coordinates. This is
     * more efficient if the function is called multiple times.
     *
     * \param[in]   coords    DOFVector of DOF coordinates.
     * \param[in]   dofs0     First DOF container.
     * \paran[in]   dofs1     Second DOF container.
     */
    void testDofsByCoords(DOFVector<WorldVector<double> > &coords,
			  DofContainer &dofs0, 
			  DofContainer &dofs1); 
256
257
258
259
  }
}

#endif