MacroWriter.cc 6.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>

#include "MacroWriter.h"
#include "DataCollector.h"
#include "Mesh.h"
#include "DOFAdmin.h"
#include "FiniteElemSpace.h"
#include "DOFVector.h"
#include "DOFIterator.h"
#include "ElInfo.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"
#include <string>
#include "Traverse.h"

namespace AMDiS {

18
19
  DOFVector< std::list<VertexInfo> >* MacroWriter::vertexInfos = NULL;
  std::list<ElementInfo> MacroWriter::elements;
20
21
22
23
24
25
26
27
28
29
  
  Mesh *MacroWriter::mesh                          = NULL;
  FILE *MacroWriter::macroFile                     = NULL;
  FILE *MacroWriter::periodicFile                  = NULL;
  int   MacroWriter::n0                            = 0;
  int   MacroWriter::nv                            = 0;
  int   MacroWriter::ne                            = 0;
  int   MacroWriter::nc                            = 0;
  int   MacroWriter::dim                           = 0;

30
  std::map<int, int> MacroWriter::outputIndices;
31
  
32
  std::vector<DimVec<bool> > MacroWriter::periodicConnections;
33
34
35
36
37
38
39
40
41
42

  bool (*MacroWriter::writeElement)(ElInfo*) = NULL;
  
  int MacroWriter::writeMacro(DataCollector *dc,
			      const char *name, 			     
			      double time,
			      int level,
			      Flag traverseFlag,
			      bool (*writeElem)(ElInfo*))
  {
43
44
    FUNCNAME("MacroWroter::writeFile()");

45
46
47
48
    TEST_EXIT(dc)("no data collector\n");

    writeElement = writeElem;

49
50
51
    std::ofstream file;
    std::list<ElementInfo> *elements = dc->getElementInfos();
    DOFVector< std::list<VertexInfo> > *vertexInfos = dc->getVertexInfos();
52
53
54
55
56
57
58
59
60
61

    int dow = Global::getGeo(WORLD);
    int dim = dc->getMesh()->getDim();
    int nv = dc->getNumberVertices();
    int ne = dc->getNumberElements();
    int vertices = dc->getMesh()->getGeo(VERTEX);

    file.open(name);

    // === print file header ===
62
63
    file << "mesh name: " << dc->getMesh()->getName() << std::endl << std::endl;
    file << "time: " << std::scientific << time << std::endl << std::endl;
64
    
65
66
    file << "DIM: " << dim << std::endl;
    file << "DIM_OF_WORLD: " << dow << std::endl << std::endl;
67

68
69
    file << "number of vertices: " << nv << std::endl;
    file << "number of elements: " << ne << std::endl << std::endl;
70
71

    // === print vertex coords and remember global output indices ===
72
    file << "vertex coordinates:" << std::endl;
73

74
    DOFVector< std::list<VertexInfo> >::Iterator it(vertexInfos, USED_DOFS);
75
76
77
    int i, counter = 0;

    // for all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
78
    for (it.reset(); !it.end(); ++it) {
79
      // for all vertex infos of this DOF
80
      std::list<VertexInfo>::iterator it2;
Thomas Witkowski's avatar
Thomas Witkowski committed
81
      for (it2 = it->begin(); it2 != it->end(); ++it2) {
82
	it2->outputIndex = counter++;
Thomas Witkowski's avatar
Thomas Witkowski committed
83
84
	for (i = 0; i < dow; i++)
	  file << std::scientific << it2->coords[i] << " ";	
85
	file << std::endl;
86
87
88
89
      }
    }

    // === print element vertices ===
90
    file << std::endl << "element vertices:" << std::endl;
91
92

    // iterate the element list
93
    std::list<ElementInfo>::iterator elementIt;
94

Thomas Witkowski's avatar
Thomas Witkowski committed
95
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
96
      // for all vertices
Thomas Witkowski's avatar
Thomas Witkowski committed
97
98
99
      for (i = 0; i < vertices; i++)
	file << elementIt->vertexInfo[i]->outputIndex << " ";      
      file << "\n";
100
101
102
    }

    // === print boundaries ===
103
    file << std::endl << "element boundaries:" << std::endl;
104

Thomas Witkowski's avatar
Thomas Witkowski committed
105
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
106
      // for all vertices
Thomas Witkowski's avatar
Thomas Witkowski committed
107
108
109
      for (i = 0; i < vertices; i++)
	file << elementIt->boundary[i] << " ";      
      file << "\n";
110
111
112
    }
    
    // === print neighbours ===
113
    file << std::endl << "element neighbours:" << std::endl;
114

Thomas Witkowski's avatar
Thomas Witkowski committed
115
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
116
      // for all vertices
Thomas Witkowski's avatar
Thomas Witkowski committed
117
118
119
      for (i = 0; i < vertices; i++)
	file << elementIt->neighbour[i] << " ";      
      file << "\n";
120
121
122
    }

    // === print boundary projections ===
123
    file << std::endl << "projections:" << std::endl;
124

Thomas Witkowski's avatar
Thomas Witkowski committed
125
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
126
      // for all vertices
Thomas Witkowski's avatar
Thomas Witkowski committed
127
      for (i = 0; i < vertices; i++) {
128
129
130
131
132
	if(elementIt->projection[i])
	  file << elementIt->projection[i]->getID() << " ";
	else
	  file << "0 ";
      }
133
      file << std::endl;
134
135
136
    }

    // === print element regions ===
137
    file << std::endl << "element region:" << std::endl;
138
    
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt)
140
      file << elementIt->elementRegion << std::endl;
141
142

    // === print surface regions ===
143
    file << std::endl << "surface region:" << std::endl;
144

Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
    for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
      for (i = 0; i < vertices; i++)
147
	file << elementIt->surfaceRegions[i] << " ";
Thomas Witkowski's avatar
Thomas Witkowski committed
148
     
149
      file << std::endl;
150
151
152
153
    }

    // === print element types if necessary ===
    if (dim == 3) {
154
      file << std::endl << "element type:" << std::endl;
155
	
Thomas Witkowski's avatar
Thomas Witkowski committed
156
      for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt)
Thomas Witkowski's avatar
Thomas Witkowski committed
157
	file << (int)(elementIt->type) << " ";      
158
159
160
161
    } 
  
    file.close();

Thomas Witkowski's avatar
Thomas Witkowski committed
162
    return 0;
163
164
165
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
166
  void MacroWriter::writePeriodicFile(DataCollector *dc, std::string filename)
167
168
169
170
  {
    FUNCNAME("MacroWriter::writePeriodicFile2");
    TEST_EXIT(dc)("no data collector\n");
  
171
    std::ofstream file;
172
173
174

    file.open(filename.c_str());
  
175
    file << "associations: " << dc->getNumberConnections() << std::endl;
Thomas Witkowski's avatar
Thomas Witkowski committed
176
177
    file << std::endl << "mode  bc  el1 - local vertices <->  el2 - local vertices" 
	 << std::endl;
178

179
    std::list<PeriodicInfo>::iterator periodicIt;
180
181

    // Iterate on all periodic connections
Thomas Witkowski's avatar
Thomas Witkowski committed
182
    for (periodicIt = dc->getPeriodicInfos()->begin(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
183
	 periodicIt != dc->getPeriodicInfos()->end(); ++periodicIt) {
184

185
      std::map<int, int>::iterator mapIt;
186
187
188
189
190
191
192
193

      // Write mode and type of periodic connection
      file << periodicIt->mode << " " << periodicIt->type << " ";    

      // Write index of the first element
      file << periodicIt->outputIndex << " ";

      // Write local indices of the first element
Thomas Witkowski's avatar
Thomas Witkowski committed
194
195
      for (mapIt = periodicIt->vertexMap.begin(); mapIt != periodicIt->vertexMap.end();
	   ++mapIt)
196
197
198
199
200
201
	file << mapIt->first << " ";

      // Write index of the second element
      file << periodicIt->neighIndex << " ";

      // Write local indices of the second element
Thomas Witkowski's avatar
Thomas Witkowski committed
202
203
      for (mapIt = periodicIt->vertexMap.begin(); mapIt != periodicIt->vertexMap.end();
	   ++mapIt)
204
205
	file << mapIt->second << " ";

206
      file << std::endl;
207
208
209
210
211
212
213
    }
  
  
    file.close();
  }

}