Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

DataCollector.cc 13.3 KB
Newer Older
1 2 3 4 5 6 7 8
#include "DataCollector.h"
#include "Traverse.h"
#include "DOFVector.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"
#include "Projection.h"

namespace AMDiS {
9

10 11 12 13 14 15 16 17 18
  DataCollector::DataCollector(const FiniteElemSpace *fe,
			       DOFVector<double> *val,
			       int l,
			       Flag flag,
			       bool (*writeElemFct)(ElInfo*))
    : values(val),
      level(l),
      traverseFlag(flag),
      feSpace(fe),
19 20 21 22 23 24 25
      nVertices(0),
      nElements(0),
      nInterpPoints(0),
      nConnection(0),
      elementDataCollected(false),
      valueDataCollected(false),
      periodicDataCollected(false),
26
      writeElem(writeElemFct)
27
  {
28
    FUNCNAME("DataCollector::DataCollector()");
29

30
    TEST_EXIT(feSpace)("No finite elem space defined!\n");
31
   
32
    // === get mesh  ===    
33
    mesh = feSpace->getMesh();
34 35

    // === get admin ===    
36
    localAdmin = const_cast<DOFAdmin*>(feSpace->getAdmin());
37
    // === create vertex info vector ===
38
    vertexInfos = new DOFVector<std::list<VertexInfo> >(feSpace, "vertex infos");
39

40 41 42
    interpPointInd = new DOFVector<int>(feSpace, "interpolation point indices");
    interpPointCoords = new DOFVector< std::list<WorldVector<double> > >(feSpace, "interpolation point coordinates");
    dofCoord = new DOFVector< std::list<WorldVector<double> > >(feSpace, "dof coords");
43

44
    dim = mesh->getDim();    
45
    nPreDofs = localAdmin->getNumberOfPreDOFs(VERTEX);
Thomas Witkowski's avatar
Thomas Witkowski committed
46
  } 
47

48

49 50
  DataCollector::~DataCollector()
  {
51 52 53 54
    delete vertexInfos;
    delete interpPointInd;
    delete interpPointCoords;
    delete dofCoord;
55 56
  }

57

Thomas Witkowski's avatar
Thomas Witkowski committed
58 59
  void DataCollector::fillAllData()
  {
60
    if (!elementDataCollected)
Thomas Witkowski's avatar
Thomas Witkowski committed
61
      startCollectingElementData();
62

63
    if (!periodicDataCollected)
Thomas Witkowski's avatar
Thomas Witkowski committed
64
      startCollectingPeriodicData();
65

66
    if (!valueDataCollected)
Thomas Witkowski's avatar
Thomas Witkowski committed
67 68 69
      startCollectingValueData();
  }

70

71
  void DataCollector::startCollectingElementData()
72
  {
73
    FUNCNAME("DataCollector::startCollectingElementData()");
74

75
    Flag flag = traverseFlag;
76 77 78 79 80 81
    flag |= 
      Mesh::FILL_NEIGH      | 
      Mesh::FILL_COORDS     |
      Mesh::FILL_OPP_COORDS |
      Mesh::FILL_BOUND;

82
    elements.resize(0, dim);
83 84 85 86

    TraverseStack stack;

    // Traverse elements to create continuous element indices
87
    ElInfo *elInfo = stack.traverseFirst(mesh, level, flag);
88
    while (elInfo) {
89 90
      if (!writeElem || writeElem(elInfo))
	outputIndices[elInfo->getElement()->getIndex()] = nElements++;
91 92 93 94
      elInfo = stack.traverseNext(elInfo);
    }

    // Traverse elements to create element information
95
    elInfo = stack.traverseFirst(mesh, level, flag);
96

97
    while (elInfo) {
98
      if (!writeElem || writeElem(elInfo))
99
	addElementData(elInfo);
100

101 102 103
      elInfo = stack.traverseNext(elInfo);
    }

104
    elementDataCollected = true;
105 106
  }

107

108
  void DataCollector::startCollectingValueData()
109
  {
110
    FUNCNAME("DataCollector::startCollectingValueData()");
111

112
    DOFVector<int>::Iterator intPointIt(interpPointInd, USED_DOFS);
113
    for (intPointIt.reset(); !intPointIt.end(); ++intPointIt)
114 115
      (*intPointIt) = -1;

116
    interpPoints.clear();
117

118 119 120
    basisFcts = const_cast<BasisFunction*>(feSpace->getBasisFcts());
    nBasisFcts = basisFcts->getNumber();
    localDOFs = new DegreeOfFreedom[nBasisFcts];
121
  
122 123 124 125
    TraverseStack stack;

    // Traverse elements to add value information and to mark
    // interpolation points.
126 127
    ElInfo *elInfo = stack.traverseFirst(mesh, level, 
					 traverseFlag | Mesh::FILL_COORDS);
128
    while (elInfo) {
129
      if (!writeElem || writeElem(elInfo))
Thomas Witkowski's avatar
Thomas Witkowski committed
130
	addValueData(elInfo);
131 132 133
      elInfo = stack.traverseNext(elInfo);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
134 135
    // If there are interpolation points, add them to the corresponding 
    // data array.
136
    if (nInterpPoints > 0) {
Thomas Witkowski's avatar
Thomas Witkowski committed
137 138 139
      // Remove all interpolation marks and, instead, set to each
      // interpolation point its continous index starting from 0.
      int i = 0;
140 141
      for (intPointIt.reset(); !intPointIt.end(); ++intPointIt)
	if (*intPointIt == -3)
Thomas Witkowski's avatar
Thomas Witkowski committed
142 143 144
	  *intPointIt = i++;
      
      // Traverse elements to create interpolation values.
145
      elInfo = stack.traverseFirst(mesh, level, traverseFlag | Mesh::FILL_COORDS);
Thomas Witkowski's avatar
Thomas Witkowski committed
146
      while (elInfo) {
147
	if (!writeElem || writeElem(elInfo))
Thomas Witkowski's avatar
Thomas Witkowski committed
148 149 150
	  addInterpData(elInfo);
	elInfo = stack.traverseNext(elInfo);
      }
151
    }
152
   
153 154
    delete [] localDOFs;
    valueDataCollected = true;
155 156
  }

157

158
  void DataCollector::startCollectingPeriodicData()
159
  {    
160
    FUNCNAME("DataCollector::startCollectingPeriodicData()");
161

162
    periodicConnections.clear();
163 164
    
    TraverseStack stack;
165
    ElInfo *elInfo = stack.traverseFirst(mesh, level, traverseFlag);
166
    while (elInfo) {
167
      if (!writeElem || writeElem(elInfo)) {
168 169 170 171 172
	LeafDataPeriodic *ldp = dynamic_cast<LeafDataPeriodic*>
	  (elInfo->getElement()->
	   getElementData()->
	   getElementData(PERIODIC));
	
173
	if (ldp)
174
	  nConnection += dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().size();
175

176
	periodicConnections.push_back(DimVec<bool>(dim, DEFAULT_VALUE, false));
177 178 179 180
      }
      elInfo = stack.traverseNext(elInfo);
    }   

181
    nConnection /= 2;
182

183
    periodicInfos.clear();
184

185
    Flag flag = traverseFlag;
186 187 188 189 190 191
    flag |= 
      Mesh::FILL_COORDS    |
      Mesh::FILL_OPP_COORDS|
      Mesh::FILL_NEIGH     | 
      Mesh::FILL_BOUND;

192
    elInfo = stack.traverseFirst(mesh, level, flag);
193
    while (elInfo) {
194
      if (!writeElem || writeElem(elInfo))
195 196 197 198
	addPeriodicData(elInfo);
      elInfo = stack.traverseNext(elInfo);
    }   

199
    periodicDataCollected = true;
200 201
  }

202

203
  void DataCollector::addElementData(ElInfo* elInfo)
204
  {
205
    FUNCNAME("DataCollector::addElementData()");
206

207
    const DegreeOfFreedom **dof = elInfo->getElement()->getDof();
208 209
    DegreeOfFreedom vertexDOF;
    WorldVector<double> vertexCoords;
210

211
    // create ElementInfo
212
    ElementInfo elementInfo(dim);
213 214
    
    // read element region
215
    ElementData *ed = elInfo->getElement()->getElementData(ELEMENT_REGION);
216
    
Thomas Witkowski's avatar
Thomas Witkowski committed
217
    if (ed)
218
      elementInfo.elementRegion = dynamic_cast<ElementRegion_ED*>(ed)->getRegion();
Thomas Witkowski's avatar
Thomas Witkowski committed
219 220
    else 
      elementInfo.elementRegion = -1;    
221
   
222 223 224
    // read surface regions to element info
    ed = elInfo->getElement()->getElementData(SURFACE_REGION);
    elementInfo.surfaceRegions.set(-1);
225
    while (ed) {
226 227 228 229 230 231
      SurfaceRegion_ED *sr = dynamic_cast<SurfaceRegion_ED*>(ed);
      elementInfo.surfaceRegions[sr->getSide()] = sr->getRegion();
      ed = ed->getDecorated(SURFACE_REGION);
    }

    // for all vertices
232
    for (int i = 0; i < dim + 1; i++) {
233 234 235 236
      // get coords of this vertex
      vertexCoords = elInfo->getCoord(i);
      
      // get dof index of this vertex
237
      vertexDOF = dof[i][nPreDofs];
238

239
      // search for coords at this dof
Thomas Witkowski's avatar
Thomas Witkowski committed
240
      std::list<VertexInfo>::iterator it =
241
	  find((*vertexInfos)[vertexDOF].begin(), (*vertexInfos)[vertexDOF].end(),
242 243 244
	       vertexCoords);
      
      // coords not yet in list?
245
      if (it == (*vertexInfos)[vertexDOF].end()) {
246
	// create new vertex info and increment number of vertices
247
	VertexInfo newVertexInfo = {vertexCoords, nVertices};
248 249

	// add new vertex info to list
250
	(*vertexInfos)[vertexDOF].push_front(newVertexInfo);
251

252
	// set iterator to new vertex info
253
	it = (*vertexInfos)[vertexDOF].begin();	
254

255
	nVertices++;
256 257 258 259 260 261 262 263
      }
      
      // fill element info
      elementInfo.vertexInfo[i] = it;
      elementInfo.boundary[i] = elInfo->getBoundary(i);
      elementInfo.projection[i] = elInfo->getProjection(i);
      elementInfo.neighbour[i] = 
	elInfo->getNeighbour(i) ?
264
	outputIndices[elInfo->getNeighbour(i)->getIndex()] :
265 266 267
	-1;
    }
    
268
    if (dim == 3)
269
      elementInfo.type = elInfo->getType();
270 271

    // remember element info
272
    elements.push_back(elementInfo);
273 274
  }

275

276
  void DataCollector::addValueData(ElInfo *elInfo)
277
  {
278
    FUNCNAME("DataCollector::addValueData()");
279
    
280
    WorldVector<double> vertexCoords;
281
    basisFcts->getLocalIndices(elInfo->getElement(), localAdmin, localDOFs);
282 283

    // First, traverse all DOFs at the vertices of the element, determine
284 285 286
    // their coordinates and add them to the corresponding entry in dofCoords.
    for (int i = 0; i < mesh->getGeo(VERTEX); i++) {
      DegreeOfFreedom dofi = localDOFs[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
287

288
      (*interpPointInd)[dofi] = -2; // mark as vertex
289 290
      
      // get coords of this vertex
291
      vertexCoords = elInfo->getCoord(i);
292

293
      // search for coords at this dof
Thomas Witkowski's avatar
Thomas Witkowski committed
294
      std::list<WorldVector<double> >::iterator it =
295 296
	  find((*dofCoord)[dofi].begin(),
	       (*dofCoord)[dofi].end(),
297
	       vertexCoords);
298 299
      
      // coords not yet in list?
300
      if (it == (*dofCoord)[dofi].end()) {
301
	// add new coords to list
302
	(*dofCoord)[dofi].push_back(vertexCoords);
303 304
      }
    }
305
   
306 307
    // Then, traverse all interpolation DOFs of the element, determine
    // their coordinates and add them to the corresponding entry in 
308 309 310
    // interpPointCoords.
    for (int i = mesh->getGeo(VERTEX); i < nBasisFcts; i++) {
      DegreeOfFreedom dofi = localDOFs[i];
311

312
      elInfo->coordToWorld(*basisFcts->getCoords(i), vertexCoords);
313
      
314
      if ((*interpPointInd)[dofi] == -1) {
315
	// mark as interpolation point
316
	(*interpPointInd)[dofi] = -3; 
317 318 319
	
	// search for interpolation point coordinates, and insert them to the 
	// dof-entry, if not contained in the list
Thomas Witkowski's avatar
Thomas Witkowski committed
320
	std::list<WorldVector<double> >::iterator it =
321
		find((*interpPointCoords)[dofi].begin(), 
322
		     (*interpPointCoords)[dofi].end(),
323
		     vertexCoords);
324
	
325
	if (it == (*interpPointCoords)[dofi].end()) {
326
	  (*interpPointCoords)[dofi].push_back(vertexCoords); 
327
	  nInterpPoints++;
328
	}
329
      }      
330
    }  
331 332
  }

333

334
  void DataCollector::addInterpData(ElInfo *elInfo)
335
  {
336
    FUNCNAME("DataCollector::addInterpData()");
337
    
338
    basisFcts->getLocalIndices(elInfo->getElement(), localAdmin, localDOFs);
339

340
    std::vector<int> elemInterpPoints(0);
341 342
    for (int i = mesh->getGeo(VERTEX); i < nBasisFcts; i++)
      elemInterpPoints.push_back((*interpPointInd)[localDOFs[i]]);
Thomas Witkowski's avatar
Thomas Witkowski committed
343
    
344
    interpPoints.push_back(elemInterpPoints); 
345 346
  }

347

348 349
  void DataCollector::addPeriodicData(ElInfo *elInfo) 
  {
350 351 352 353 354 355 356
    FUNCNAME("DataCollector::addPeriodicData");

    LeafDataPeriodic *ldp = dynamic_cast<LeafDataPeriodic*>
      (elInfo->getElement()->
       getElementData()->
       getElementData(PERIODIC));
    
357
    if (ldp) {
Thomas Witkowski's avatar
Thomas Witkowski committed
358
      std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
359
      
360 361 362 363
      for (it = dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().begin();
	   it != dynamic_cast<LeafDataPeriodic*>(ldp)->getInfoList().end();
	   ++it) {

364 365
	int outputIndex = outputIndices[elInfo->getElement()->getIndex()];
	int neighIndex  = outputIndices[elInfo->
366 367 368
					 getNeighbour(it->elementSide)->
					 getIndex()];
	
369
	if (!periodicConnections[outputIndex][it->elementSide]) {
370
	  PeriodicInfo periodicInfo;
371
	  
372 373 374 375 376 377
	  periodicInfo.mode = it->periodicMode;
	  periodicInfo.type = it->type;
	  periodicInfo.outputIndex = outputIndex;
	  periodicInfo.neighIndex = neighIndex;
	  periodicInfo.vertexMap.clear();
	  
378 379
	  periodicConnections[outputIndex][it->elementSide] = true;
	  periodicConnections
380 381 382
	    [neighIndex][elInfo->getOppVertex(it->elementSide)] = true;
	    
  
383 384
	  for (int i = 0; i < dim; i++) {
	    int index1 = elInfo->getElement()->getVertexOfPosition(INDEX_OF_DIM(dim - 1, dim),
385 386
								   it->elementSide,
								   i);
387
	    int dof1 = elInfo->getElement()->getDof(index1, nPreDofs);
388
	    
389 390
	    for (int j = 0; j < dim; j++) {
	      int index2 = elInfo->getElement()->getVertexOfPosition(INDEX_OF_DIM(dim - 1, dim),
391 392
								     elInfo->getOppVertex(it->elementSide),
								     j);
393
	      int dof2 = elInfo->getNeighbour(it->elementSide)->getDof(index2, nPreDofs);
394
	      
395
	      if ((dof1 == dof2) || (mesh->associated(dof1, dof2))) {
396 397 398
		periodicInfo.vertexMap[index1] = index2;
		break;
	      } 
399 400
	    }
	  }
401
	  
402
	  periodicInfos.push_back(periodicInfo);
403
	}
404
      }
405 406 407
    }
  }

408

Thomas Witkowski's avatar
Thomas Witkowski committed
409
  std::list<ElementInfo>* DataCollector::getElementInfos()
410
  {        
411
    if (!elementDataCollected)
412 413
      startCollectingElementData();
      
414
    return &elements;
415 416
  }

417

Thomas Witkowski's avatar
Thomas Witkowski committed
418
  DOFVector< std::list<VertexInfo> >* DataCollector::getVertexInfos()
419
  {
420
    if (!elementDataCollected)
421 422
      startCollectingElementData();

423
    return vertexInfos;
424 425
  }

426

Thomas Witkowski's avatar
Thomas Witkowski committed
427
  std::list<PeriodicInfo>* DataCollector::getPeriodicInfos()
428
  {
429
    if (!periodicDataCollected)
430 431
      startCollectingPeriodicData();

432
    return &periodicInfos;
433 434
  }

435

436 437
  int DataCollector::getNumberVertices()
  {
438
    if (!elementDataCollected)
439 440
      startCollectingElementData();

441
    return nVertices;
442 443
  }

444

445 446
  int DataCollector::getNumberElements()
  {
447
    if (!elementDataCollected)
448 449
      startCollectingElementData();

450
    return nElements;
451 452
  }

453

454 455
  int DataCollector::getNumberInterpPoints()
  {
456
    if (!valueDataCollected)
457 458
      startCollectingValueData();

459
    return nInterpPoints;
460
  }
461

462 463 464
  
  int DataCollector::getNumberConnections()
  {
465
    if (!periodicDataCollected)
466 467
      startCollectingPeriodicData();

468
    return nConnection;
469 470 471 472 473
  }


  DOFVector<double>* DataCollector::getValues()
  {
474
    if (!valueDataCollected)
475 476
      startCollectingValueData();

477
    return values;
478 479
  }

480

Thomas Witkowski's avatar
Thomas Witkowski committed
481
  DOFVector< std::list<WorldVector<double> > >* DataCollector::getDofCoords()
482
  {
483
    if (!valueDataCollected)
484 485
      startCollectingValueData();

486
    return dofCoord;
487 488
  }

489

490 491
  DOFVector<int>* DataCollector::getInterpPointInd()
  {
492
    if (!valueDataCollected)
493 494
      startCollectingValueData();

495
    return interpPointInd;
496 497
  }

498

Thomas Witkowski's avatar
Thomas Witkowski committed
499
  DOFVector< std::list<WorldVector<double> > >* DataCollector::getInterpPointCoords()
500
  {
501
    if (!valueDataCollected)
502 503
      startCollectingValueData();

504
    return interpPointCoords;
505 506
  }

507

Thomas Witkowski's avatar
Thomas Witkowski committed
508
  std::vector< std::vector<int> >* DataCollector::getInterpPoints()
509
  {
510
    if (!valueDataCollected)
511 512
      startCollectingValueData();

513
    return &interpPoints;
514 515
  }
}