ProblemVec.cc 41.8 KB
Newer Older
Thomas Witkowski's avatar
Thomas Witkowski committed
1
2
#include <sstream>

3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "ProblemVec.h"
#include "RecoveryEstimator.h"
#include "Serializer.h"
#include "AbstractFunction.h"
#include "Operator.h"
#include "SystemVector.h"
#include "DOFMatrix.h"
#include "FiniteElemSpace.h"
#include "Estimator.h"
#include "Marker.h"
#include "AdaptInfo.h"
#include "FileWriter.h"
#include "CoarseningManager.h"
#include "RefinementManager.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
17
#include "DualTraverse.h"
18
19
20
21
22
23
24
#include "Mesh.h"
#include "OEMSolver.h"
#include "MatVecMultiplier.h"
#include "DirichletBC.h"
#include "RobinBC.h"
#include "PeriodicBC.h"
#include "Lagrange.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
25
#include "Flag.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
26
#include "TraverseParallel.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include "VtkWriter.h"
28
#include "ValueReader.h"
29
30
31
32
33
34
35
36
37
38

namespace AMDiS {

  void ProblemVec::initialize(Flag initFlag,
			      ProblemVec *adoptProblem,
			      Flag adoptFlag)
  {
    FUNCNAME("ProblemVec::initialize()");
    
    // === create meshes ===
Thomas Witkowski's avatar
Thomas Witkowski committed
39
    if (meshes.size() != 0) { 
40
41
42
43
44
45
46
47
48
49
50
      WARNING("meshes already created\n");
    } else {
      if (initFlag.isSet(CREATE_MESH) || 
	  ((!adoptFlag.isSet(INIT_MESH))&&
	   (initFlag.isSet(INIT_SYSTEM) || initFlag.isSet(INIT_FE_SPACE)))) {
	createMesh();
      } 
      if (adoptProblem && 
	  (adoptFlag.isSet(INIT_MESH) || 
	   adoptFlag.isSet(INIT_SYSTEM) ||
	   adoptFlag.isSet(INIT_FE_SPACE))) {
Thomas Witkowski's avatar
Thomas Witkowski committed
51
	meshes = adoptProblem->getMeshes();
Thomas Witkowski's avatar
Thomas Witkowski committed
52
	componentMeshes = adoptProblem->componentMeshes;
Thomas Witkowski's avatar
Thomas Witkowski committed
53
54
	refinementManager = adoptProblem->refinementManager;
	coarseningManager = adoptProblem->coarseningManager;
55
56
57

	// If the adopt problem has fewer components than this problem, but only one
	// mesh for all component, than scal up the componentMeshes array.
Thomas Witkowski's avatar
Thomas Witkowski committed
58
	if (adoptProblem->getNumComponents() < nComponents) {
Thomas Witkowski's avatar
Thomas Witkowski committed
59
	  TEST_EXIT(meshes.size() == 1)("Daran muss ich noch arbeiten!\n");
60
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
61
62
63
	  componentMeshes.resize(nComponents);
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++) {
	    componentMeshes[i] = componentMeshes[0];
64
65
66
	  }
	}

67
68
69
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
70
    if (meshes.size() == 0) 
71
72
73
      WARNING("no mesh created\n");

    // === create fespace ===
74
    if (feSpaces.size() != 0) {
75
76
77
78
79
80
81
82
      WARNING("feSpaces already created\n");
    } else {
      if (initFlag.isSet(INIT_FE_SPACE) || 
	  (initFlag.isSet(INIT_SYSTEM)&&!adoptFlag.isSet(INIT_FE_SPACE))) {
	createFESpace();
      } 
      if (adoptProblem &&
	  (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
83
84
	feSpaces = adoptProblem->getFESpaces();
	componentSpaces = adoptProblem->componentSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
85
	traverseInfo = adoptProblem->traverseInfo;
86
87
88

	// If the adopt problem has fewer components than this problem, but only one
	// fe space for all component, than scal up the componentSpaces array.
Thomas Witkowski's avatar
Thomas Witkowski committed
89
90
	if (adoptProblem->getNumComponents() < nComponents) {
	  TEST_EXIT(feSpaces.size() == 1)("Daran muss ich noch arbeiten!\n");
91
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
92
93
94
	  componentSpaces.resize(nComponents);
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++) {
	    componentSpaces[i] = componentSpaces[0];
95
96
97
	  }
	}

98
99
100
      }
    }

101
    if (feSpaces.size() == 0) 
102
103
104
105
106
107
108
      WARNING("no feSpace created\n");

    // === create system ===
    if (initFlag.isSet(INIT_SYSTEM)) {
      createMatricesAndVectors();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
109
110
111
      solution = adoptProblem->getSolution();
      rhs = adoptProblem->getRHS();
      systemMatrix = adoptProblem->getSystemMatrix();
112
113
114
    }

    // === create solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
115
    if (solver) {
116
117
118
119
120
121
      WARNING("solver already created\n");
    } else {
      if (initFlag.isSet(INIT_SOLVER)) {
	createSolver();
      } 
      if (adoptProblem && adoptFlag.isSet(INIT_SOLVER)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
122
123
	TEST_EXIT(!solver)("solver already created\n");
	solver = adoptProblem->getSolver();
124
125
126
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
127
    if (!solver) 
128
129
130
131
132
133
134
      WARNING("no solver created\n");

    // === create estimator ===
    if (initFlag.isSet(INIT_ESTIMATOR)) {
      createEstimator();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
135
      estimator = adoptProblem->getEstimator();
136
137
138
139
140
141
142
    } 

    // === create marker ===
    if (initFlag.isSet(INIT_MARKER)) {
      createMarker();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_MARKER)) {
143
      marker = adoptProblem->getMarker();
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    } 


    // === create file writer ===
    if (initFlag.isSet(INIT_FILEWRITER)) {
      createFileWriter();
    }

    
    // === read serialization and init mesh ===
    
    // There are two possiblities where the user can define a serialization
    // to be read from disk. Either by providing the parameter -rs when executing
    // the program or in the init file. The -rs parameter is always checked first,
    // because it can be added automatically when  rescheduling the program
    // before timeout of the runqueue.

    int readSerialization = 0;
162
    std::string serializationFilename = "";
163
164
165
166
167
168
169
    GET_PARAMETER(0, "argv->rs", &serializationFilename);

    // If the parameter -rs is set, we do nothing here, because the problem will be
    // deserialized in the constructor of a following AdaptInstationary initialization.
    if (!serializationFilename.compare("")) {
      int readSerializationWithAdaptInfo = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
170
      GET_PARAMETER(0, name + "->input->read serialization", "%d", 
171
		    &readSerialization);
Thomas Witkowski's avatar
Thomas Witkowski committed
172
      GET_PARAMETER(0, name + "->input->serialization with adaptinfo", "%d",
173
174
175
176
177
178
179
		    &readSerializationWithAdaptInfo);

      // The serialization file is only read, if the adaptInfo part should not be used.
      // If the adaptInfo part should be also read, the serialization file will be read
      // in the constructor of the AdaptInstationary problem, because we do not have here
      // the adaptInfo object.
      if (readSerialization && !readSerializationWithAdaptInfo) {
Thomas Witkowski's avatar
Thomas Witkowski committed
180
	GET_PARAMETER(0, name + "->input->serialization filename", 
181
182
183
184
		      &serializationFilename);
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
185
	std::ifstream in(serializationFilename.c_str());
186
187
188
	deserialize(in);
	in.close();
      } else {
189
	int globalRefinements = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
190
	GET_PARAMETER(0, meshes[0]->getName() + "->global refinements", "%d", 
191
192
		      &globalRefinements);

193
	// Initialize the meshes if there is no serialization file.
194
195
	for (int i = 0; i < static_cast<int>(meshes.size()); i++)
	  if (initFlag.isSet(INIT_MESH) && meshes[i] && !(meshes[i]->isInitialized()))
Thomas Witkowski's avatar
Thomas Witkowski committed
196
	    meshes[i]->initialize();	    
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

	// === read value file and use it for the mesh values ===
	std::string valueFilename("");
	GET_PARAMETER(0, meshes[0]->getName() + "->value file name", &valueFilename); 
	if (valueFilename.length()) {     
	  ValueReader::readValue(valueFilename,
				 meshes[0],
				 solution->getDOFVector(0),
				 meshes[0]->getMacroFileInfo());
	  meshes[0]->clearMacroFileInfo();
	}

	// === do global refinements ===
	for (int i = 0; i < static_cast<int>(meshes.size()); i++)
	  if (initFlag.isSet(INIT_MESH) && meshes[i])
Thomas Witkowski's avatar
Thomas Witkowski committed
212
	    refinementManager->globalRefine(meshes[i], globalRefinements);
213
214
215
216
217
218
219
220
221
222
      }
    }

    doOtherStuff();
  }

  void ProblemVec::createMesh() 
  {
    FUNCNAME("ProblemVec::createMesh()");

Thomas Witkowski's avatar
Thomas Witkowski committed
223
    componentMeshes.resize(nComponents);
224
    std::map<int, Mesh*> meshForRefinementSet;
225
226
    char number[3];

227
    std::string meshName("");
Thomas Witkowski's avatar
Thomas Witkowski committed
228
    GET_PARAMETER(0, name + "->mesh", &meshName);
229
    TEST_EXIT(meshName != "")("no mesh name specified\n");
230
    int dim = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
231
    GET_PARAMETER(0, name + "->dim", "%d", &dim);
232
    TEST_EXIT(dim)("no problem dimension specified!\n");
233

234
    for (int i = 0; i < nComponents; i++) {
235
      sprintf(number, "%d", i);
236
      int refSet = -1;
Thomas Witkowski's avatar
Thomas Witkowski committed
237
      GET_PARAMETER(0, name + "->refinement set[" + number + "]", "%d", &refSet);
238
      if (refSet < 0) {
239
240
	refSet = 0;
      }
241
      if (meshForRefinementSet[refSet] == NULL) {
242
243
	Mesh *newMesh = NEW Mesh(meshName, dim);
	meshForRefinementSet[refSet] = newMesh;
Thomas Witkowski's avatar
Thomas Witkowski committed
244
245
	meshes.push_back(newMesh);
	nMeshes++;
246
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
247
      componentMeshes[i] = meshForRefinementSet[refSet];
248
249
250
    }
    switch(dim) {
    case 1:
Thomas Witkowski's avatar
Thomas Witkowski committed
251
252
      coarseningManager = NEW CoarseningManager1d();
      refinementManager = NEW RefinementManager1d();
253
254
      break;
    case 2:
Thomas Witkowski's avatar
Thomas Witkowski committed
255
256
      coarseningManager = NEW CoarseningManager2d();
      refinementManager = NEW RefinementManager2d();
257
258
      break;
    case 3:
Thomas Witkowski's avatar
Thomas Witkowski committed
259
260
      coarseningManager = NEW CoarseningManager3d();
      refinementManager = NEW RefinementManager3d();
261
262
263
264
265
266
267
268
269
270
      break;
    default:
      ERROR_EXIT("invalid dim!\n");
    }
  }

  void ProblemVec::createFESpace()
  {
    FUNCNAME("ProblemVec::createFESpace()");

271
    std::map< std::pair<Mesh*, int>, FiniteElemSpace*> feSpaceMap;
272
    int dim = -1;
Thomas Witkowski's avatar
Thomas Witkowski committed
273
    GET_PARAMETER(0, name + "->dim", "%d", &dim);
274
    TEST_EXIT(dim != -1)("no problem dimension specified!\n");
275

276
    componentSpaces.resize(nComponents, NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
277
    traverseInfo.resize(nComponents);
278

279
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
280
      char number[3];
281
      sprintf(number, "%d", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
282
283
      int degree = 1;
      GET_PARAMETER(0, name + "->polynomial degree[" + number + "]","%d", &degree);
284

285
      TEST_EXIT(componentSpaces[i] == NULL)("feSpace already created\n");
286

Thomas Witkowski's avatar
Thomas Witkowski committed
287
      if (feSpaceMap[std::pair<Mesh*, int>(componentMeshes[i], degree)] == NULL) {
Thomas Witkowski's avatar
Thomas Witkowski committed
288
289
290
	stringstream s;
	s << name << "->feSpace[" << i << "]";

291
	FiniteElemSpace *newFESpace = 
Thomas Witkowski's avatar
Thomas Witkowski committed
292
293
	  FiniteElemSpace::provideFESpace(NULL, Lagrange::getLagrange(dim, degree),
					  componentMeshes[i], s.str());
Thomas Witkowski's avatar
Thomas Witkowski committed
294
	feSpaceMap[std::pair<Mesh*, int>(componentMeshes[i], degree)] = newFESpace;
295
	feSpaces.push_back(newFESpace);
296
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
297
298
299
300
301
302
303
304
      componentSpaces[i] = feSpaceMap[std::pair<Mesh*, int>(componentMeshes[i], degree)];
    }

    for (int i = 0; i < nComponents; i++) {
      for (int j = 0; j < nComponents; j++) {
	traverseInfo.getMatrix(i, j).setFESpace(componentSpaces[i], componentSpaces[j]);
      }
      traverseInfo.getVector(i).setFESpace(componentSpaces[i]);
305
306
307
    }

    // create dof admin for vertex dofs if neccessary
Thomas Witkowski's avatar
Thomas Witkowski committed
308
309
310
    for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
      if (meshes[i]->getNumberOfDOFs(VERTEX) == 0) {
	DimVec<int> ln_dof(meshes[i]->getDim(), DEFAULT_VALUE, 0);
311
	ln_dof[VERTEX]= 1;
Thomas Witkowski's avatar
Thomas Witkowski committed
312
	meshes[i]->createDOFAdmin("vertex dofs", ln_dof);      
313
314
315
316
317
318
319
320
321
322
      }
    }
  }

  void ProblemVec::createMatricesAndVectors()
  {
    FUNCNAME("ProblemVec::createMatricesAndVectors()");

    // === create vectors and system matrix ===

Thomas Witkowski's avatar
Thomas Witkowski committed
323
324
325
326
    systemMatrix = NEW Matrix<DOFMatrix*>(nComponents, nComponents);
    systemMatrix->set(NULL);
    rhs = NEW SystemVector("rhs", componentSpaces, nComponents);
    solution = NEW SystemVector("solution", componentSpaces, nComponents);
327
328

    char number[10];
329
    std::string numberedName;
Thomas Witkowski's avatar
Thomas Witkowski committed
330
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
331
      (*systemMatrix)[i][i] = NEW DOFMatrix(componentSpaces[i], 
332
					     componentSpaces[i], "A_ii");
Thomas Witkowski's avatar
Thomas Witkowski committed
333
      (*systemMatrix)[i][i]->setCoupleMatrix(false);
334
      sprintf(number, "[%d]", i);
335
      numberedName = "rhs" + std::string(number);
Thomas Witkowski's avatar
Thomas Witkowski committed
336
337
338
      rhs->setDOFVector(i, NEW DOFVector<double>(componentSpaces[i], numberedName));
      numberedName = name + std::string(number);
      solution->setDOFVector(i, NEW DOFVector<double>(componentSpaces[i], 
339
						       numberedName));
Thomas Witkowski's avatar
Thomas Witkowski committed
340
341
      solution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      solution->getDOFVector(i)->set(0.0);
342
343
344
    }

    // === create matVec ===
Thomas Witkowski's avatar
Thomas Witkowski committed
345
    matVec = NEW StandardMatVec<Matrix<DOFMatrix*>, SystemVector>(systemMatrix);
346
347
348
349
350
351
352
  }

  void ProblemVec::createSolver()
  {
    FUNCNAME("ProblemVec::createSolver()");

    // === create solver ===
353
    std::string solverType("no");
Thomas Witkowski's avatar
Thomas Witkowski committed
354
    GET_PARAMETER(0, name + "->solver", &solverType);
355
356
    OEMSolverCreator *solverCreator = 
      dynamic_cast<OEMSolverCreator*>(CreatorMap<OEMSolver>::getCreator(solverType));
357
    TEST_EXIT(solverCreator)("no solver type\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
358
359
360
    solverCreator->setName(name + "->solver");
    solver = solverCreator->create();
    solver->initParameters();
361
362
363
364
365
366
367
  }

  void ProblemVec::createEstimator()
  {
    FUNCNAME("ProblemVec::createEstimator()");

    // create and set leaf data prototype
Thomas Witkowski's avatar
Thomas Witkowski committed
368
369
    for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
      meshes[i]->setElementDataPrototype
370
371
372
373
	(NEW LeafDataEstimatableVec(NEW LeafDataCoarsenableVec));
    }  

    char number[3];
374
    std::string estName;
375

Thomas Witkowski's avatar
Thomas Witkowski committed
376
377
    for (int i = 0; i < nComponents; i++) {
      TEST_EXIT(estimator[i] == NULL)("estimator already created\n");
378
      sprintf(number, "%d", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
379
      estName = name + "->estimator[" + std::string(number) + "]";
380
381

      // === create estimator ===
382
      std::string estimatorType("no");
383
384
385
386
      GET_PARAMETER(0, estName, &estimatorType);
      EstimatorCreator *estimatorCreator = 
	dynamic_cast<EstimatorCreator*>(
					CreatorMap<Estimator>::getCreator(estimatorType));
Thomas Witkowski's avatar
Thomas Witkowski committed
387
      if (estimatorCreator) {
388
389
	estimatorCreator->setName(estName);
	estimatorCreator->setRow(i);
Thomas Witkowski's avatar
Thomas Witkowski committed
390
	if (estimatorType == "recovery") {
391
	  dynamic_cast<RecoveryEstimator::Creator*>(estimatorCreator)->
Thomas Witkowski's avatar
Thomas Witkowski committed
392
	    setSolution(solution->getDOFVector(i));
393
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
394
	estimator[i] = estimatorCreator->create();
395
396
397
      }


Thomas Witkowski's avatar
Thomas Witkowski committed
398
399
400
401
402
      if (estimator[i]) {
	for (int j = 0; j < nComponents; j++) {
	  estimator[i]->addSystem((*systemMatrix)[i][j], 
				   solution->getDOFVector(j), 
				   rhs->getDOFVector(j));
403
404
405
406
407
408
409
410
411
	}
      }
    }
  }

  void ProblemVec::createMarker()
  {
    FUNCNAME("ProblemVec::createMarker()");

412
    std::string numberedName;
413
    char number[10];
Thomas Witkowski's avatar
Thomas Witkowski committed
414
    int nMarkersCreated = 0;
415

416
    for (int i = 0; i < nComponents; i++) {
417
      sprintf(number, "[%d]", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
418
      numberedName = name + "->marker" + std::string(number);
419
420
      marker[i] = Marker::createMarker(numberedName, i);
      if (marker[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
421
422
423
424
425
426
	nMarkersCreated++;

	// If there is more than one marker, and all components are defined
	// on the same mesh, the maximum marking has to be enabled.
 	if ((nMarkersCreated > 1) && (nMeshes == 1))
 	  marker[i]->setMaximumMarking(true);
427
428
429
430
431
432
433
434
435
436
      }
    }
  }

  void ProblemVec::createFileWriter()
  {
    FUNCNAME("ProblemVec::createFileWriter()");
  

    // Create one filewriter for all components of the problem
Thomas Witkowski's avatar
Thomas Witkowski committed
437
    std::string numberedName  = name + "->output";
438
    std::string filename = "";
439
440
441
    GET_PARAMETER(0, numberedName + "->filename", &filename);

    if (filename != "") {
442
      std::vector< DOFVector<double>* > solutionList(nComponents);
443

444
      for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
445
	TEST_EXIT(componentMeshes[0] == componentMeshes[i])
446
447
	  ("All Meshes have to be equal to write a vector file.\n");

Thomas Witkowski's avatar
Thomas Witkowski committed
448
	solutionList[i] = solution->getDOFVector(i);
449
450
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
451
      fileWriters.push_back(NEW FileWriter(numberedName,
Thomas Witkowski's avatar
Thomas Witkowski committed
452
					    componentMeshes[0],
453
454
455
456
457
458
					    solutionList));
    }


    // Create own filewriters for each components of the problem
    char number[10];
459
    for (int i = 0; i < nComponents; i++) {
460
      sprintf(number, "[%d]", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
461
      numberedName  = name + "->output" + std::string(number);
462
463
464
465
      filename = "";
      GET_PARAMETER(0, numberedName + "->filename", &filename);

      if (filename != "") {
Thomas Witkowski's avatar
Thomas Witkowski committed
466
	fileWriters.push_back(NEW FileWriter(numberedName, 
Thomas Witkowski's avatar
Thomas Witkowski committed
467
					      componentMeshes[i], 
Thomas Witkowski's avatar
Thomas Witkowski committed
468
					      solution->getDOFVector(i)));
469
470
471
472
473
474
      }
    }


    // Check for serializer
    int writeSerialization = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
475
    GET_PARAMETER(0, name + "->write serialization", "%d", &writeSerialization);
476
    if (writeSerialization) {
Thomas Witkowski's avatar
Thomas Witkowski committed
477
478
      MSG("Use are using the obsolete parameter: %s->write serialization\n", name.c_str());
      MSG("Please use instead the following parameter: %s->output->write serialization\n", name.c_str());
479
480
481
      ERROR_EXIT("Usage of an obsolete parameter (see message above)!\n");
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
482
    GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization);
483
    if (writeSerialization) {
Thomas Witkowski's avatar
Thomas Witkowski committed
484
      fileWriters.push_back(NEW Serializer<ProblemVec>(this));
485
486
487
488
489
490
491
    }
  }

  void ProblemVec::doOtherStuff()
  {
  }

492
  void ProblemVec::solve(AdaptInfo *adaptInfo, bool fixedMatrix)
493
494
495
  {
    FUNCNAME("Problem::solve()");

Thomas Witkowski's avatar
Thomas Witkowski committed
496
    if (!solver) {
497
498
499
500
501
502
503
504
505
      WARNING("no solver\n");
      return;
    }

#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

    clock_t first = clock();
506
507
    int iter = solver->solveSystem(solverMatrix, *solution, *rhs);

508
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
509
510
    INFO(info, 8)("solution of discrete system needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()), omp_get_wtime() - wtime);
511
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
512
513
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  TIME_USED(first, clock()));
514
515
516
517
#endif


    adaptInfo->setSolverIterations(iter);
Thomas Witkowski's avatar
Thomas Witkowski committed
518
519
520
    adaptInfo->setMaxSolverIterations(solver->getMaxIterations());
    adaptInfo->setSolverTolerance(solver->getTolerance());
    adaptInfo->setSolverResidual(solver->getResidual());
521
522
523
524
525
526
  }

  void ProblemVec::estimate(AdaptInfo *adaptInfo) 
  {
    FUNCNAME("ProblemVec::estimate()");

Thomas Witkowski's avatar
Thomas Witkowski committed
527
528
    VtkWriter::writeFile(solution->getDOFVector(0), "test.vtu");

529
530
    clock_t first = clock();

531
532
533
534
#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

535
    if (computeExactError) {
Thomas Witkowski's avatar
Thomas Witkowski committed
536
      computeError(adaptInfo);
537
538
    } else {
      for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
539
	Estimator *scalEstimator = estimator[i];
540
541
542
543
544
545
546
547
548
549
	
	if (scalEstimator) {
	  scalEstimator->estimate(adaptInfo->getTimestep());
	  adaptInfo->setEstSum(scalEstimator->getErrorSum(), i);
	  adaptInfo->setEstMax(scalEstimator->getErrorMax(), i);
	  adaptInfo->setTimeEstSum(scalEstimator->getTimeEst(), i);
	  adaptInfo->setTimeEstMax(scalEstimator->getTimeEstMax(), i);
	} else {
	  WARNING("no estimator for component %d\n" , i);
	}
550
551
552
      }
    }

553
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
554
555
    INFO(info, 8)("estimation of the error needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()), omp_get_wtime() - wtime);
556
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
557
558
    INFO(info, 8)("estimation of the error needed %.5f seconds\n",
		  TIME_USED(first, clock()));
559
560
561

#endif

562
563
564
565
566
567
568
569
570
571
572
  }

  Flag ProblemVec::markElements(AdaptInfo *adaptInfo) 
  {
    FUNCNAME("ProblemVec::markElements()");

    // to enforce albert-like behavior: refinement even if space tolerance
    // here is reached already because of time adaption
    allowFirstRefinement();

    Flag markFlag = 0;
573
    for (int i = 0; i < nComponents; i++) {
574
      if (marker[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
575
	markFlag |= marker[i]->markMesh(adaptInfo, componentMeshes[i]);
576
577
578
579
      } else {
	WARNING("no marker for component %d\n", i);
      }
    }
580
    
581
582
583
584
585
586
587
    return markFlag;
  }

  Flag ProblemVec::refineMesh(AdaptInfo *adaptInfo) 
  {
    FUNCNAME("ProblemVec::refineMesh()");

Thomas Witkowski's avatar
Thomas Witkowski committed
588
    int nMeshes = static_cast<int>(meshes.size());
589
    Flag refineFlag = 0;
590
    for (int i = 0; i < nMeshes; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
591
      refineFlag |= refinementManager->refineMesh(meshes[i]);
592
593
594
595
596
597
598
599
    }
    return refineFlag;
  }

  Flag ProblemVec::coarsenMesh(AdaptInfo *adaptInfo) 
  {
    FUNCNAME("ProblemVec::coarsenMesh()");

Thomas Witkowski's avatar
Thomas Witkowski committed
600
    int nMeshes = static_cast<int>(meshes.size());
601
    Flag coarsenFlag = 0;
602
603
    for (int i = 0; i < nMeshes; i++) {
      if (adaptInfo->isCoarseningAllowed(i)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
604
	coarsenFlag |= coarseningManager->coarsenMesh(meshes[i]);
605
606
607
608
609
610
611
612
613
614
615

	WARNING("coarsening for component %d no allowed\n", i);
      }
    }
    return coarsenFlag;
  }

  Flag ProblemVec::oneIteration(AdaptInfo *adaptInfo, Flag toDo)
  {
    FUNCNAME("ProblemVec::oneIteration()");

Thomas Witkowski's avatar
Thomas Witkowski committed
616
    if (allowFirstRef) {
617
      for (int i = 0; i < nComponents; i++) {
618
619
	adaptInfo->allowRefinement(true, i);
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
620
      allowFirstRef = false;
621
    } else {
622
      for (int i = 0; i < nComponents; i++) {
623
624
625
626
627
628
629
630
631
632
633
	if (adaptInfo->spaceToleranceReached(i)) {
	  adaptInfo->allowRefinement(false, i);
	} else {
	  adaptInfo->allowRefinement(true, i);	
	}
      }
    }

    return StandardProblemIteration::oneIteration(adaptInfo, toDo);
  }

634
635
  void ProblemVec::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
				     bool asmMatrix, bool asmVector)
636
637
638
639
640
  {
    FUNCNAME("ProblemVec::buildAfterCoarsen()");

    clock_t first = clock();

641
642
643
644
#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

Thomas Witkowski's avatar
Thomas Witkowski committed
645
646
    for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
      meshes[i]->dofCompress();
647
648
649
650
    }

    Flag assembleFlag = 
      flag | 
Thomas Witkowski's avatar
Thomas Witkowski committed
651
652
      (*systemMatrix)[0][0]->getAssembleFlag() | 
      rhs->getDOFVector(0)->getAssembleFlag()  |
653
654
655
656
657
658
      Mesh::CALL_LEAF_EL                        | 
      Mesh::FILL_COORDS                         |
      Mesh::FILL_DET                            |
      Mesh::FILL_GRD_LAMBDA |
      Mesh::FILL_NEIGH;

Thomas Witkowski's avatar
Thomas Witkowski committed
659
    if (useGetBound) {
660
661
662
      assembleFlag |= Mesh::FILL_BOUND;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
663

664
    for (int i = 0; i < nComponents; i++) {
665
      MSG("%d DOFs for %s\n", 
666
667
	  componentSpaces[i]->getAdmin()->getUsedSize(), 
	  componentSpaces[i]->getName().c_str());
668

Thomas Witkowski's avatar
Thomas Witkowski committed
669
      rhs->getDOFVector(i)->set(0.0);
670
      for (int j = 0; j < nComponents; j++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
671
	if ((*systemMatrix)[i][j]) {
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
	  DOFMatrix*                   dof_matrix= (*systemMatrix)[i][j];
	  DOFMatrix::base_matrix_type& base_matrix= dof_matrix->getBaseMatrix();

	  int nnz_per_row= 0;
	  if (num_rows(base_matrix) != 0)
	      nnz_per_row= int(double(base_matrix.nnz()) / num_rows(base_matrix) * 1.2); 
	  if (nnz_per_row < 5) 
	      nnz_per_row= 5;

	  // Correct dimensionality of matrix
	  base_matrix.change_dim(componentSpaces[i]->getAdmin()->getUsedSize(), 
				 componentSpaces[j]->getAdmin()->getUsedSize());
	  
	  // Reuse old sparsity information (if available) or default
	  dof_matrix->startInsertion(nnz_per_row);
687
	}
688
689
690
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
691
692
    traverseInfo.updateStatus();

Thomas Witkowski's avatar
Thomas Witkowski committed
693
    for (int i = 0; i < nComponents; i++) {
694
      for (int j = 0; j < nComponents; j++) {
695
696
697
698
	// Only if this variable is true, the current matrix will be assembled.	
	bool assembleMatrix = true;
	// The DOFMatrix which should be assembled (or not, if assembleMatrix
	// will be set to false).
Thomas Witkowski's avatar
Thomas Witkowski committed
699
	DOFMatrix *matrix = (*systemMatrix)[i][j];
700

701
702
	// If the matrix was assembled before and it is marked to be assembled
	// only once, it will not be assembled.
Thomas Witkowski's avatar
Thomas Witkowski committed
703
	if (assembleMatrixOnlyOnce[i][j] && assembledMatrix[i][j]) {
704
705
	  assembleMatrix = false;
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
706
707

	// If there is no DOFMatrix, e.g., if it is completly 0, do not assemble.
708
709
710
711
	if (!matrix) {
	  assembleMatrix = false;
	}

712
713
714
715
	if (!asmMatrix) {
	  assembleMatrix = false;
	}

716
717
718
719
720
721
722
	// If the matrix should not be assembled, the rhs vector has to be considered.
	// This will be only done, if i == j. So, if both is not true, we can jump
	// to the next matrix.
	if (!assembleMatrix && i != j) {
	  continue;
	}

723
724
725
	if (assembleMatrix && matrix->getBoundaryManager())
	  matrix->getBoundaryManager()->initMatrix(matrix);

Thomas Witkowski's avatar
Thomas Witkowski committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
	if (traverseInfo.getStatus(i, j) == SingleComponentInfo::EQ_SPACES_NO_AUX ||
	    traverseInfo.getStatus(i, j) == SingleComponentInfo::EQ_SPACES_WITH_AUX) {

	  // Row fe space and col fe space are both equal

	  if (traverseInfo.getStatus(i) == SingleComponentInfo::EQ_SPACES_NO_AUX ||
	      traverseInfo.getStatus(i) == SingleComponentInfo::EQ_SPACES_WITH_AUX) {

	    // The simplest case: either the right hand side has no operaters, no aux
	    // fe spaces, or all aux fe spaces are equal to the row and col fe space.

	    assembleOnOneMesh(componentSpaces[i],
			      assembleFlag,
			      assembleMatrix ? matrix : NULL,
			      ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);

	  } else if (traverseInfo.getStatus(i) == SingleComponentInfo::EQ_SPACES_WITH_DIF_AUX) {

	    // Row fe space and col fe space are both equal, but right hand side has at
745
	    // least one another aux fe space. 
Thomas Witkowski's avatar
Thomas Witkowski committed
746
747
748
749
750
751

	    assembleOnOneMesh(componentSpaces[i],
			      assembleFlag,
			      assembleMatrix ? matrix : NULL,
			      ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);

752
753
	    assembleOnDifMeshes2(componentSpaces[i], 
				 traverseInfo.getAuxFESpace(i, j),
Thomas Witkowski's avatar
Thomas Witkowski committed
754
755
				 assembleFlag,
				 NULL,
756
				 ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
757
758
759
760
761
762
763

	  } else {
	    ERROR_EXIT("Possible? If yes, not yet implemented!\n");
	  }

	} else if (traverseInfo.getStatus(i, j) == SingleComponentInfo::EQ_SPACES_WITH_DIF_AUX) {
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
764
765
766
	  assembleOnOneMesh(componentSpaces[i],
			    assembleFlag,
			    assembleMatrix ? matrix : NULL,
Thomas Witkowski's avatar
Thomas Witkowski committed
767
			    ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
768
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
769
770
771
772
	  assembleOnDifMeshes2(componentSpaces[i],
			       traverseInfo.getAuxFESpace(i, j),
			       assembleFlag,
			       assembleMatrix ? matrix : NULL,
773
			       ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
774
775
776
777

	} else if (traverseInfo.getStatus(i, j) ==  SingleComponentInfo::DIF_SPACES_NO_AUX ||
		   traverseInfo.getStatus(i, j) ==  SingleComponentInfo::DIF_SPACES_WITH_AUX) {

Thomas Witkowski's avatar
Thomas Witkowski committed
778
779
780
	  assembleOnDifMeshes(componentSpaces[i], componentSpaces[j],
			      assembleFlag,
			      assembleMatrix ? matrix : NULL,
Thomas Witkowski's avatar
Thomas Witkowski committed
781
782
783
			      ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);	  

	  TEST_EXIT_DBG(matrix->getUsedSize() == componentSpaces[i]->getAdmin()->getUsedSize())
784
	    ("Assembled matrix has wrong dimension!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
785
786
787
788
789
	  TEST_EXIT_DBG(matrix->getNumCols() == componentSpaces[j]->getAdmin()->getUsedSize())
	    ("Assembled matrix has wrong dimension!\n");	  

	} else {
	  ERROR_EXIT("Not yet implemented!\n");
790
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
791

792
793
794
	if (assembleMatrix && matrix->getBoundaryManager())
	  matrix->getBoundaryManager()->exitMatrix(matrix);	  
	
Thomas Witkowski's avatar
Thomas Witkowski committed
795
	assembledMatrix[i][j] = true;
796
797
      }

798
      // And now assemble boundary conditions on the vectors
Thomas Witkowski's avatar
Thomas Witkowski committed
799
800
      assembleBoundaryConditions(rhs->getDOFVector(i),
				 solution->getDOFVector(i),
801
802
				 componentMeshes[i],
				 assembleFlag);
803
    }
804

805
806
807
808
809
810
811
812
813
    // Finish insertion
    for (int i = 0; i < nComponents; i++) 
      for (int j = 0; j < nComponents; j++) 
	if ((*systemMatrix)[i][j]) 
	  (*systemMatrix)[i][j]->finishInsertion();

    solverMatrix.setMatrix(*systemMatrix);
    createPrecon();

814
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
815
816
    INFO(info, 8)("buildAfterCoarsen needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()), omp_get_wtime() - wtime);
817
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
818
819
    INFO(info, 8)("buildAfterCoarsen needed %.5f seconds\n", 
		  TIME_USED(first, clock()));
820
#endif
821
822
  }

823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  void ProblemVec::createPrecon()
  {
    ::std::string preconType("no");
    GET_PARAMETER(0, name + "->solver->left precon", &preconType);

    CreatorInterface<ITL_BasePreconditioner> *preconCreator = 
      CreatorMap<ITL_BasePreconditioner>::getCreator(preconType);

    solver->setLeftPrecon( preconCreator->create(solverMatrix.getMatrix()) );

    preconType= "no";
    GET_PARAMETER(0, name + "->solver->right precon", &preconType);

    preconCreator = CreatorMap<ITL_BasePreconditioner>::getCreator(preconType);
    solver->setRightPrecon( preconCreator->create(solverMatrix.getMatrix()) );
  }


841
842
843
844
  void ProblemVec::writeFiles(AdaptInfo *adaptInfo, bool force) 
  {
    FUNCNAME("ProblemVec::writeFiles()");

845
846
847
848
849
850
851
    clock_t first = clock();

#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

    int i;
Thomas Witkowski's avatar
Thomas Witkowski committed
852
    int size = static_cast<int>(fileWriters.size());
853
854
855
856
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1)
#endif
    for (i = 0; i < size; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
857
      fileWriters[i]->writeFiles(adaptInfo, force);
858
    }
859
860
    
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
861
862
863
    INFO(info, 8)("writeFiles needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()),
		  omp_get_wtime() - wtime);
864
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
865
866
    INFO(info, 8)("writeFiles needed %.5f seconds\n",
		  TIME_USED(first, clock()));
867
#endif
868
869
  }

870
  void ProblemVec::interpolInitialSolution(std::vector<AbstractFunction<double, WorldVector<double> >*> *fct) 
871
872
873
  {
    FUNCNAME("ProblemVec::interpolInitialSolution()");

Thomas Witkowski's avatar
Thomas Witkowski committed
874
    solution->interpol(fct);
875
876
877
878
879
  }

  void ProblemVec::addMatrixOperator(Operator *op, 
				     int i, int j,
				     double *factor,
880
881
				     double *estFactor,
				     bool fake)
882
883
  {
    FUNCNAME("ProblemVec::addMatrixOperator()");
Thomas Witkowski's avatar
Thomas Witkowski committed
884
   
Thomas Witkowski's avatar
Thomas Witkowski committed
885
    if (!(*systemMatrix)[i][j]) {
886
      TEST_EXIT(i != j)("should have been created already\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
887
888
889
890
      (*systemMatrix)[i][j] = NEW DOFMatrix(componentSpaces[i], componentSpaces[j], "");
      (*systemMatrix)[i][j]->setCoupleMatrix(true);
      (*systemMatrix)[i][j]->getBoundaryManager()->
	setBoundaryConditionMap((*systemMatrix)[i][i]->getBoundaryManager()->
891
892
				getBoundaryConditionMap());
    }    
Thomas Witkowski's avatar
Thomas Witkowski committed
893

894
    (*systemMatrix)[i][j]->addOperator(op, factor, estFactor);
Thomas Witkowski's avatar
Thomas Witkowski committed
895

896
897
898
899
900
901
902
903
904
905
906
    if (!fake) {    
      traverseInfo.getMatrix(i, j).setAuxFESpaces(op->getAuxFESpaces()); 
      
      for (int k = 0; k < static_cast<int>(op->getAuxFESpaces().size()); k++) {
	if ((op->getAuxFESpaces())[k]->getMesh() != componentSpaces[i]->getMesh() ||
	    (op->getAuxFESpaces())[k]->getMesh() != componentSpaces[j]->getMesh()) {
	  op->setNeedDualTraverse(true);
	  break;
	}
      }    
    } 
907
908
909
910
  }

  void ProblemVec::addVectorOperator(Operator *op, int i,
				     double *factor,
911
912
				     double *estFactor,
				     bool fake)
913
914
915
  {
    FUNCNAME("ProblemVec::addVectorOperator()");

Thomas Witkowski's avatar
Thomas Witkowski committed
916
917
    rhs->getDOFVector(i)->addOperator(op, factor, estFactor);

918
919
920
921
922
923
924
925
926
927
    if (!fake) {
      traverseInfo.getVector(i).setAuxFESpaces(op->getAuxFESpaces()); 
      
      for (int j = 0; j < static_cast<int>(op->getAuxFESpaces().size()); j++) {
	if ((op->getAuxFESpaces())[j]->getMesh() != componentSpaces[i]->getMesh()) {
	  op->setNeedDualTraverse(true);
	  break;
	}
      }    
    }
928
929
930
931
932
933
934
935
936
  }

  void ProblemVec::addDirichletBC(BoundaryType type, int system,
				  AbstractFunction<double, WorldVector<double> >* b)
  {
    FUNCNAME("ProblemVec::addDirichletBC()");

    DirichletBC *dirichlet = new DirichletBC(type, 
					     b, 
937
					     componentSpaces[system]);
938
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
939
940
      if (systemMatrix && (*systemMatrix)[system][i]) {
	(*systemMatrix)[system][i]->getBoundaryManager()->addBoundaryCondition(dirichlet);
941
942
      }
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
943
944
945
946
    if (rhs)
      rhs->getDOFVector(system)->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (solution)
      solution->getDOFVector(system)->getBoundaryManager()->addBoundaryCondition(dirichlet);
947
948
949
950
951
952
953
954
955
  }

  void ProblemVec::addNeumannBC(BoundaryType type, int row, int col, 
				AbstractFunction<double, WorldVector<double> > *n)
  {
    FUNCNAME("ProblemVec::addNeumannBC()");

    NeumannBC *neumann = 
      new NeumannBC(type, n, 
956
957
		    componentSpaces[row], 
		    componentSpaces[col]);
Thomas Witkowski's avatar
Thomas Witkowski committed
958
959
    if (rhs)
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(neumann);
960
961
962
963
964
965
966
967
968
969
  }

  void ProblemVec::addRobinBC(BoundaryType type, int row, int col, 
			      AbstractFunction<double, WorldVector<double> > *n,
			      AbstractFunction<double, WorldVector<double> > *r)
  {
    FUNCNAME("ProblemVec::addRobinBC()");

    RobinBC *robin = 
      new RobinBC(type, n, r, 
970
971
		  componentSpaces[row], 
		  componentSpaces[col]);
Thomas Witkowski's avatar
Thomas Witkowski committed
972
973
    if (rhs)
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(robin);
974

Thomas Witkowski's avatar
Thomas Witkowski committed
975
976
    if (systemMatrix && (*systemMatrix)[row][col]) {
      (*systemMatrix)[row][col]->getBoundaryManager()->addBoundaryCondition(robin);
977
978
979
980
981
982
983
    }
  }

  void ProblemVec::addPeriodicBC(BoundaryType type, int row, int col) 
  {
    FUNCNAME("ProblemVec::addPeriodicBC()");

984
    FiniteElemSpace *feSpace = componentSpaces[row];
985
986
987

    PeriodicBC *periodic = new PeriodicBC(type, feSpace);

Thomas Witkowski's avatar
Thomas Witkowski committed
988
989
    if (systemMatrix && (*systemMatrix)[row][col]) 
      (*systemMatrix)[row][col]->getBoundaryManager()->addBoundaryCondition(periodic);
990

Thomas Witkowski's avatar
Thomas Witkowski committed
991
992
    if (rhs) 
      rhs->getDOFVector(row)->getBoundaryManager()->
993
994
995
	addBoundaryCondition(periodic);
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
996
997
  void ProblemVec::assembleOnOneMesh(FiniteElemSpace *feSpace, 
				     Flag assembleFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
998
999
1000
1001
				     DOFMatrix *matrix, DOFVector<double> *vector)
  {
    Mesh *mesh = feSpace->getMesh();
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
1002
1003

#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
1004
    TraverseParallelStack stack;
1005
1006
1007
#else
    TraverseStack stack;
#endif   
Thomas Witkowski's avatar
Thomas Witkowski committed
1008

1009
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
1010
#pragma omp parallel
1011
#endif
Thomas Witkowski's avatar
Thomas Witkowski committed
1012
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
1013
      BoundaryType *bound = useGetBound ? GET_MEMORY(BoundaryType, basisFcts->getNumber()) : NULL;
Thomas Witkowski's avatar
Thomas Witkowski committed
1014
1015
1016
1017
1018