OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
XFEMDebugTools.C
Go to the documentation of this file.
1 /*
2  * XFEMDebugTools.C
3  *
4  * Created on: Jun 5, 2013
5  * Author: svennine
6  */
7 
8 #include "XFEMDebugTools.h"
9 
10 namespace oofem {
12 
14 
15 void XFEMDebugTools :: WriteTrianglesToVTK(const std :: string &iName, const std :: vector< Triangle > &iTriangles)
16 {
17  //printf("Entering XFEMDebugTools::WriteTrianglesToVTK().\n");
18  size_t numTri = iTriangles.size();
19 
20 
21  std :: ofstream file;
22  file.open( iName.data() );
23 
24  // Write header
25  file << "# vtk DataFile Version 2.0\n";
26  file << "Geometry of a PolygonLine\n";
27  file << "ASCII\n";
28 
29  file << "DATASET UNSTRUCTURED_GRID\n";
30 
31  int numPoints = numTri * 3;
32  // Write points
33  file << "POINTS " << numPoints << "double\n";
34 
35  for ( size_t i = 0; i < numTri; i++ ) {
36  for ( int j = 1; j <= 3; j++ ) {
37  const double &x = iTriangles.at(i).giveVertex(j).at(1);
38  const double &y = iTriangles.at(i).giveVertex(j).at(2);
39  file << x << " " << y << " 0.0\n";
40  }
41  }
42 
43 
44  // Write segments
45  file << "CELLS " << numTri << " " << numTri * 4 << "\n";
46 
47  for ( size_t i = 0; i < numTri; i++ ) {
48  file << 3 << " " << 3 * i << " " << 3 * i + 1 << " " << 3 * i + 2 << "\n";
49  }
50 
51 
52  // Write cell types
53  file << "CELL_TYPES " << numTri << "\n";
54  int vtkCellType = 5; // triangle
55  for ( size_t i = 0; i < numTri; i++ ) {
56  file << vtkCellType << "\n";
57  }
58 
59  file.close();
60 }
61 
62 void XFEMDebugTools :: WritePointsToVTK(const std :: string &iName, const std :: vector< FloatArray > &iPoints)
63 {
64  //printf("Entering XFEMDebugTools::WriteTrianglesToVTK().\n");
65 
66 
67  std :: ofstream file;
68  file.open( iName.data() );
69 
70  // Write header
71  file << "# vtk DataFile Version 2.0\n";
72  file << "Gauss points\n";
73  file << "ASCII\n";
74 
75  file << "DATASET UNSTRUCTURED_GRID\n";
76 
77  int numPoints = iPoints.size();
78  // Write points
79  file << "POINTS " << numPoints << " double\n";
80 
81  for ( int i = 1; i <= numPoints; i++ ) {
82  //for(int j = 1; j <= 3; j++) {
83  const double &x = iPoints [ i - 1 ].at(1);
84  const double &y = iPoints [ i - 1 ].at(2);
85  double z = 0.0;
86  if ( iPoints [ i - 1 ].giveSize() == 3 ) {
87  z = iPoints [ i - 1 ].at(3);
88  }
89 
90  file << x << " " << y << " " << z << "\n";
91  //}
92  }
93 
94 
95  // Write segments
96  file << "CELLS " << numPoints << " " << numPoints * 2 << "\n";
97 
98  for ( int i = 0; i < numPoints; i++ ) {
99  file << 1 << " " << i << "\n";
100  }
101 
102 
103  // Write cell types
104  file << "CELL_TYPES " << numPoints << "\n";
105  int vtkCellType = 1; // vertex
106  for ( int i = 0; i < numPoints; i++ ) {
107  file << vtkCellType << "\n";
108  }
109 
110  file.close();
111 }
112 
113 void XFEMDebugTools :: WriteArrayToMatlab(const std :: string &iName, const std :: vector< double > &iX, const std :: vector< double > &iY)
114 {
115  std :: ofstream file;
116  file.open( iName.data() );
117 
118  file << "x = [";
119 
120  for ( size_t i = 0; i < iX.size(); i++ ) {
121  file << iX [ i ] << "\n";
122  }
123 
124  file << "];\n\n";
125 
126 
127 
128  file << "y = [";
129 
130  for ( size_t i = 0; i < iY.size(); i++ ) {
131  file << iY [ i ] << "\n";
132  }
133 
134  file << "];\n\n";
135 
136  file.close();
137 }
138 
139 void XFEMDebugTools :: WriteArrayToGnuplot(const std :: string &iName, const std :: vector< double > &iX, const std :: vector< double > &iY)
140 {
141  if ( iX.size() != iY.size() ) {
142 // OOFEM_ERROR("iX.size() != iY.size().")
143  printf("Warning: iX.size() != iY.size()\n");
144  return;
145  }
146 
147  std :: ofstream file;
148  file.open( iName.data() );
149 
150  // Set some output options
151  file << std :: scientific;
152 
153  file << "# x y\n";
154 
155  for ( size_t i = 0; i < iX.size(); i++ ) {
156  file << iX [ i ] << " " << iY [ i ] << "\n";
157  }
158 
159  file.close();
160 }
161 } /* namespace oofem */
static void WriteTrianglesToVTK(const std::string &iName, const std::vector< Triangle > &iTriangles)
static void WritePointsToVTK(const std::string &iName, const std::vector< FloatArray > &iPoints)
static void WriteArrayToGnuplot(const std::string &iName, const std::vector< double > &iX, const std::vector< double > &iY)
static void WriteArrayToMatlab(const std::string &iName, const std::vector< double > &iX, const std::vector< double > &iY)
the oofem namespace is to define a context or scope in which all oofem names are defined.

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:32 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011