ProblemVec.cc 52.5 KB
Newer Older
<
Thomas Witkowski's avatar
Thomas Witkowski committed
1
#include <sstream>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#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
16
#include "DualTraverse.h"
17
18
19
20
21
22
#include "Mesh.h"
#include "OEMSolver.h"
#include "DirichletBC.h"
#include "RobinBC.h"
#include "PeriodicBC.h"
#include "Lagrange.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
23
#include "Flag.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
24
#include "TraverseParallel.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
25
#include "VtkWriter.h"
26
#include "ValueReader.h"
27
28
29
30
31
32
33
34

namespace AMDiS {

  void ProblemVec::initialize(Flag initFlag,
			      ProblemVec *adoptProblem,
			      Flag adoptFlag)
  {
    FUNCNAME("ProblemVec::initialize()");
35

36
    // === create meshes ===
Thomas Witkowski's avatar
Thomas Witkowski committed
37
    if (meshes.size() != 0) { 
38
39
40
      WARNING("meshes already created\n");
    } else {
      if (initFlag.isSet(CREATE_MESH) || 
Thomas Witkowski's avatar
Thomas Witkowski committed
41
	  (!adoptFlag.isSet(INIT_MESH) &&
42
43
44
45
46
47
48
	   (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
49
	meshes = adoptProblem->getMeshes();
Thomas Witkowski's avatar
Thomas Witkowski committed
50
	componentMeshes = adoptProblem->componentMeshes;
Thomas Witkowski's avatar
Thomas Witkowski committed
51
52
	refinementManager = adoptProblem->refinementManager;
	coarseningManager = adoptProblem->coarseningManager;
53
54
55

	// 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
56
	if (adoptProblem->getNumComponents() < nComponents) {
Thomas Witkowski's avatar
Thomas Witkowski committed
57
	  TEST_EXIT(meshes.size() == 1)("Daran muss ich noch arbeiten!\n");
58
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
59
	  componentMeshes.resize(nComponents);
60
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
61
	    componentMeshes[i] = componentMeshes[0];
62
63
	}

64
65
66
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
67
    if (meshes.size() == 0) 
68
69
70
      WARNING("no mesh created\n");

    // === create fespace ===
71
    if (feSpaces.size() != 0) {
72
73
74
      WARNING("feSpaces already created\n");
    } else {
      if (initFlag.isSet(INIT_FE_SPACE) || 
75
76
	  (initFlag.isSet(INIT_SYSTEM) && !adoptFlag.isSet(INIT_FE_SPACE)))
	createFESpace(NULL);
77

78
79
      if (adoptProblem &&
	  (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
80
81
	feSpaces = adoptProblem->getFESpaces();
	componentSpaces = adoptProblem->componentSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
82
	traverseInfo = adoptProblem->traverseInfo;
83
84
85

	// 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
86
87
	if (adoptProblem->getNumComponents() < nComponents) {
	  TEST_EXIT(feSpaces.size() == 1)("Daran muss ich noch arbeiten!\n");
88
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
89
	  componentSpaces.resize(nComponents);
Thomas Witkowski's avatar
Thomas Witkowski committed
90
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
91
	    componentSpaces[i] = componentSpaces[0];
92
93
	}

94
95
96
      }
    }

97
    if (feSpaces.size() == 0) 
98
99
100
      WARNING("no feSpace created\n");

    // === create system ===
101
    if (initFlag.isSet(INIT_SYSTEM)) 
102
      createMatricesAndVectors();
103
    
104
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
105
106
107
      solution = adoptProblem->getSolution();
      rhs = adoptProblem->getRHS();
      systemMatrix = adoptProblem->getSystemMatrix();
108
109
110
    }

    // === create solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
111
    if (solver) {
112
113
114
115
116
117
      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
118
119
	TEST_EXIT(!solver)("solver already created\n");
	solver = adoptProblem->getSolver();
120
121
122
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
123
    if (!solver) 
124
125
126
      WARNING("no solver created\n");

    // === create estimator ===
Thomas Witkowski's avatar
Thomas Witkowski committed
127
    if (initFlag.isSet(INIT_ESTIMATOR))
128
      createEstimator();
Thomas Witkowski's avatar
Thomas Witkowski committed
129
130

    if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR))
Thomas Witkowski's avatar
Thomas Witkowski committed
131
      estimator = adoptProblem->getEstimator();
132
133

    // === create marker ===
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    if (initFlag.isSet(INIT_MARKER))
135
      createMarker();
Thomas Witkowski's avatar
Thomas Witkowski committed
136
    if (adoptProblem && adoptFlag.isSet(INIT_MARKER))
137
      marker = adoptProblem->getMarker();
138
139

    // === create file writer ===
Thomas Witkowski's avatar
Thomas Witkowski committed
140
    if (initFlag.isSet(INIT_FILEWRITER))
141
142
143
144
145
146
147
148
149
150
151
      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;
152
    std::string serializationFilename = "";
153
154
155
156
157
158
159
    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
160
      GET_PARAMETER(0, name + "->input->read serialization", "%d", 
161
		    &readSerialization);
Thomas Witkowski's avatar
Thomas Witkowski committed
162
      GET_PARAMETER(0, name + "->input->serialization with adaptinfo", "%d",
163
164
165
166
167
168
169
		    &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
170
	GET_PARAMETER(0, name + "->input->serialization filename", 
171
172
173
174
		      &serializationFilename);
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
175
	std::ifstream in(serializationFilename.c_str());
176
177
178
	deserialize(in);
	in.close();
      } else {
179
	int globalRefinements = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
180
	GET_PARAMETER(0, meshes[0]->getName() + "->global refinements", "%d", 
181
182
		      &globalRefinements);

183
	// Initialize the meshes if there is no serialization file.
184
185
186
187
188
	for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
	  bool initMesh = initFlag.isSet(INIT_MESH) ||
	    (adoptProblem && adoptFlag.isSet(INIT_MESH));

	  if (initMesh && meshes[i] && !(meshes[i]->isInitialized()))
Thomas Witkowski's avatar
Thomas Witkowski committed
189
	    meshes[i]->initialize();	    
190
	}
191
192
193
194

	// === read value file and use it for the mesh values ===
	std::string valueFilename("");
	GET_PARAMETER(0, meshes[0]->getName() + "->value file name", &valueFilename); 
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
195
	if (valueFilename.length()) {
196
197
198
199
200
201
202
203
204
205
	  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
206
	    refinementManager->globalRefine(meshes[i], globalRefinements);
207
208
209
210
211
212
213
214
215
216
      }
    }

    doOtherStuff();
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
217
    componentMeshes.resize(nComponents);
218
    std::map<int, Mesh*> meshForRefinementSet;
219
220
    char number[3];

221
    std::string meshName("");
Thomas Witkowski's avatar
Thomas Witkowski committed
222
    GET_PARAMETER(0, name + "->mesh", &meshName);
223
    TEST_EXIT(meshName != "")("no mesh name specified\n");
224
    int dim = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
225
    GET_PARAMETER(0, name + "->dim", "%d", &dim);
226
    TEST_EXIT(dim)("no problem dimension specified!\n");
227

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

261
  void ProblemVec::createFESpace(DOFAdmin *admin)
262
263
264
  {
    FUNCNAME("ProblemVec::createFESpace()");

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

270
    componentSpaces.resize(nComponents, NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
271
    traverseInfo.resize(nComponents);
272

273
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
274
      char number[3];
275
      sprintf(number, "%d", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
276
277
      int degree = 1;
      GET_PARAMETER(0, name + "->polynomial degree[" + number + "]","%d", &degree);
278

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

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

285
	FiniteElemSpace *newFESpace = 
286
	  FiniteElemSpace::provideFESpace(admin, Lagrange::getLagrange(dim, degree),
Thomas Witkowski's avatar
Thomas Witkowski committed
287
					  componentMeshes[i], s.str());
Thomas Witkowski's avatar
Thomas Witkowski committed
288
	feSpaceMap[std::pair<Mesh*, int>(componentMeshes[i], degree)] = newFESpace;
289
	feSpaces.push_back(newFESpace);
290
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
291
292
293
294
      componentSpaces[i] = feSpaceMap[std::pair<Mesh*, int>(componentMeshes[i], degree)];
    }

    for (int i = 0; i < nComponents; i++) {
295
      for (int j = 0; j < nComponents; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
296
	traverseInfo.getMatrix(i, j).setFESpace(componentSpaces[i], componentSpaces[j]);
297
      
Thomas Witkowski's avatar
Thomas Witkowski committed
298
      traverseInfo.getVector(i).setFESpace(componentSpaces[i]);
299
300
301
    }

    // create dof admin for vertex dofs if neccessary
Thomas Witkowski's avatar
Thomas Witkowski committed
302
303
304
    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);
305
	ln_dof[VERTEX] = 1;
Thomas Witkowski's avatar
Thomas Witkowski committed
306
	meshes[i]->createDOFAdmin("vertex dofs", ln_dof);      
307
308
309
310
311
312
313
314
315
316
      }
    }
  }

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
317
    systemMatrix = new Matrix<DOFMatrix*>(nComponents, nComponents);
Thomas Witkowski's avatar
Thomas Witkowski committed
318
    systemMatrix->set(NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
319
320
    rhs = new SystemVector("rhs", componentSpaces, nComponents);
    solution = new SystemVector("solution", componentSpaces, nComponents);
321

Thomas Witkowski's avatar
Thomas Witkowski committed
322
323
    char number[10] = "";
    std::string numberedName = "";
Thomas Witkowski's avatar
Thomas Witkowski committed
324
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
325
      (*systemMatrix)[i][i] = new DOFMatrix(componentSpaces[i], 
Thomas Witkowski's avatar
Thomas Witkowski committed
326
					    componentSpaces[i], "A_ii");
Thomas Witkowski's avatar
Thomas Witkowski committed
327
      (*systemMatrix)[i][i]->setCoupleMatrix(false);
Thomas Witkowski's avatar
Thomas Witkowski committed
328

329
      sprintf(number, "[%d]", i);
330
      numberedName = "rhs" + std::string(number);
Thomas Witkowski's avatar
Thomas Witkowski committed
331
      rhs->setDOFVector(i, new DOFVector<double>(componentSpaces[i], numberedName));
Thomas Witkowski's avatar
Thomas Witkowski committed
332
      numberedName = name + std::string(number);
Thomas Witkowski's avatar
Thomas Witkowski committed
333
334
      solution->setDOFVector(i, new DOFVector<double>(componentSpaces[i],
      						      numberedName));
Thomas Witkowski's avatar
Thomas Witkowski committed
335
336
      solution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      solution->getDOFVector(i)->set(0.0);
337
338
339
340
341
342
343
344
    }
  }

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

    // === create solver ===
345
    std::string solverType("0");
Thomas Witkowski's avatar
Thomas Witkowski committed
346
    GET_PARAMETER(0, name + "->solver", &solverType);
347
348
    OEMSolverCreator *solverCreator = 
      dynamic_cast<OEMSolverCreator*>(CreatorMap<OEMSolver>::getCreator(solverType));
349
    TEST_EXIT(solverCreator)("no solver type\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
350
351
352
    solverCreator->setName(name + "->solver");
    solver = solverCreator->create();
    solver->initParameters();
353
354
355
356
357
358
359
  }

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

    // create and set leaf data prototype
Thomas Witkowski's avatar
Thomas Witkowski committed
360
361
    for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
      meshes[i]->setElementDataPrototype
Thomas Witkowski's avatar
Thomas Witkowski committed
362
	(new LeafDataEstimatableVec(new LeafDataCoarsenableVec));
363
364
365
    }  

    char number[3];
366
    std::string estName;
367

Thomas Witkowski's avatar
Thomas Witkowski committed
368
369
    for (int i = 0; i < nComponents; i++) {
      TEST_EXIT(estimator[i] == NULL)("estimator already created\n");
370
      sprintf(number, "%d", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
371
      estName = name + "->estimator[" + std::string(number) + "]";
372
373

      // === create estimator ===
374
      std::string estimatorType("0");
375
376
      GET_PARAMETER(0, estName, &estimatorType);
      EstimatorCreator *estimatorCreator = 
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
377
	dynamic_cast<EstimatorCreator*>(CreatorMap<Estimator>::getCreator(estimatorType));
Thomas Witkowski's avatar
Thomas Witkowski committed
378
      if (estimatorCreator) {
379
380
	estimatorCreator->setName(estName);
	estimatorCreator->setRow(i);
Thomas Witkowski's avatar
Thomas Witkowski committed
381
	if (estimatorType == "recovery") {
382
	  dynamic_cast<RecoveryEstimator::Creator*>(estimatorCreator)->
Thomas Witkowski's avatar
Thomas Witkowski committed
383
	    setSolution(solution->getDOFVector(i));
384
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
385
	estimator[i] = estimatorCreator->create();
386
387
388
      }


Thomas Witkowski's avatar
Thomas Witkowski committed
389
390
391
392
393
      if (estimator[i]) {
	for (int j = 0; j < nComponents; j++) {
	  estimator[i]->addSystem((*systemMatrix)[i][j], 
				   solution->getDOFVector(j), 
				   rhs->getDOFVector(j));
394
395
396
397
398
399
400
401
402
	}
      }
    }
  }

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

403
    std::string numberedName;
404
    char number[10];
Thomas Witkowski's avatar
Thomas Witkowski committed
405
    int nMarkersCreated = 0;
406

407
    for (int i = 0; i < nComponents; i++) {
408
      sprintf(number, "[%d]", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
409
      numberedName = name + "->marker" + std::string(number);
410
411
      marker[i] = Marker::createMarker(numberedName, i);
      if (marker[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
412
413
414
415
416
417
	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);
418
419
420
421
422
423
424
425
426
427
      }
    }
  }

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

    // Create one filewriter for all components of the problem
Thomas Witkowski's avatar
Thomas Witkowski committed
428
    std::string numberedName  = name + "->output";
429
    std::string filename = "";
430
431
432
    GET_PARAMETER(0, numberedName + "->filename", &filename);

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
439
	solutionList[i] = solution->getDOFVector(i);
440
441
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
442
      fileWriters.push_back(new FileWriter(numberedName,
Thomas Witkowski's avatar
Thomas Witkowski committed
443
					    componentMeshes[0],
444
445
446
447
448
449
					    solutionList));
    }


    // Create own filewriters for each components of the problem
    char number[10];
450
    for (int i = 0; i < nComponents; i++) {
451
      sprintf(number, "[%d]", i);
Thomas Witkowski's avatar
Thomas Witkowski committed
452
      numberedName  = name + "->output" + std::string(number);
453
454
455
      filename = "";
      GET_PARAMETER(0, numberedName + "->filename", &filename);

456
      if (filename != "")
Thomas Witkowski's avatar
Thomas Witkowski committed
457
	fileWriters.push_back(new FileWriter(numberedName, 
458
459
					     componentMeshes[i], 
					     solution->getDOFVector(i)));
460
461
462
463
464
    }


    // Check for serializer
    int writeSerialization = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
465
    GET_PARAMETER(0, name + "->write serialization", "%d", &writeSerialization);
466
    if (writeSerialization) {
Thomas Witkowski's avatar
Thomas Witkowski committed
467
468
      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());
469
470
471
      ERROR_EXIT("Usage of an obsolete parameter (see message above)!\n");
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
472
    GET_PARAMETER(0, name + "->output->write serialization", "%d", &writeSerialization);
473
    if (writeSerialization)
Thomas Witkowski's avatar
Thomas Witkowski committed
474
      fileWriters.push_back(new Serializer<ProblemVec>(this));
475
476
477
478
479
480
  }

  void ProblemVec::doOtherStuff()
  {
  }

481
  void ProblemVec::solve(AdaptInfo *adaptInfo, bool fixedMatrix)
482
483
484
  {
    FUNCNAME("Problem::solve()");

Thomas Witkowski's avatar
Thomas Witkowski committed
485
    if (!solver) {
486
487
488
489
490
491
492
493
494
      WARNING("no solver\n");
      return;
    }

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

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

497
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
498
499
    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);
500
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
501
502
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  TIME_USED(first, clock()));
503
504
505
#endif

    adaptInfo->setSolverIterations(iter);
Thomas Witkowski's avatar
Thomas Witkowski committed
506
507
508
    adaptInfo->setMaxSolverIterations(solver->getMaxIterations());
    adaptInfo->setSolverTolerance(solver->getTolerance());
    adaptInfo->setSolverResidual(solver->getResidual());
509
510
511
512
513
514
515
516
  }

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

    clock_t first = clock();

517
518
519
520
#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

521
    if (computeExactError) {
Thomas Witkowski's avatar
Thomas Witkowski committed
522
      computeError(adaptInfo);
523
524
    } else {
      for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
525
	Estimator *scalEstimator = estimator[i];
526
527
528
529
530
531
532
533
534
535
	
	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);
	}
536
537
538
      }
    }

539
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
540
541
    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);
542
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
543
544
    INFO(info, 8)("estimation of the error needed %.5f seconds\n",
		  TIME_USED(first, clock()));
545
546
547

#endif

548
549
550
551
552
553
554
555
556
557
558
  }

  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;
559
    for (int i = 0; i < nComponents; i++) {
560
      if (marker[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
561
	markFlag |= marker[i]->markMesh(adaptInfo, componentMeshes[i]);
562
563
564
565
      } else {
	WARNING("no marker for component %d\n", i);
      }
    }
566
    
567
568
569
570
571
572
573
    return markFlag;
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
574
    int nMeshes = static_cast<int>(meshes.size());
575
    Flag refineFlag = 0;
576
577
578
579
    for (int i = 0; i < nMeshes; i++)
      if (adaptInfo->isRefinementAllowed(i))
	refineFlag |= refinementManager->refineMesh(meshes[i]);

580
581
582
583
584
585
586
    return refineFlag;
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
587
    int nMeshes = static_cast<int>(meshes.size());
588
    Flag coarsenFlag = 0;
589
590
    for (int i = 0; i < nMeshes; i++)
      if (adaptInfo->isCoarseningAllowed(i))
Thomas Witkowski's avatar
Thomas Witkowski committed
591
	coarsenFlag |= coarseningManager->coarsenMesh(meshes[i]);
592
593
594
595
596
597
598
599

    return coarsenFlag;
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
600
    if (allowFirstRef) {
Thomas Witkowski's avatar
Thomas Witkowski committed
601
      for (int i = 0; i < nComponents; i++)
602
	adaptInfo->allowRefinement(true, i);
Thomas Witkowski's avatar
Thomas Witkowski committed
603

Thomas Witkowski's avatar
Thomas Witkowski committed
604
      allowFirstRef = false;
605
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
606
607
      for (int i = 0; i < nComponents; i++)
	if (adaptInfo->spaceToleranceReached(i))
608
	  adaptInfo->allowRefinement(false, i);
Thomas Witkowski's avatar
Thomas Witkowski committed
609
	else
610
611
612
613
614
615
	  adaptInfo->allowRefinement(true, i);	
    }

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

616
617
  void ProblemVec::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
				     bool asmMatrix, bool asmVector)
618
619
620
621
622
  {
    FUNCNAME("ProblemVec::buildAfterCoarsen()");

    clock_t first = clock();

623
624
625
626
#ifdef _OPENMP
    double wtime = omp_get_wtime();
#endif

627
    for (int i = 0; i < static_cast<int>(meshes.size()); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
628
      meshes[i]->dofCompress();
629
630
631

    Flag assembleFlag = 
      flag | 
Thomas Witkowski's avatar
Thomas Witkowski committed
632
633
      (*systemMatrix)[0][0]->getAssembleFlag() | 
      rhs->getDOFVector(0)->getAssembleFlag()  |
634
635
636
637
638
639
      Mesh::CALL_LEAF_EL                        | 
      Mesh::FILL_COORDS                         |
      Mesh::FILL_DET                            |
      Mesh::FILL_GRD_LAMBDA |
      Mesh::FILL_NEIGH;

Thomas Witkowski's avatar
Thomas Witkowski committed
640
    if (useGetBound)
641
      assembleFlag |= Mesh::FILL_BOUND;
Thomas Witkowski's avatar
Thomas Witkowski committed
642

Thomas Witkowski's avatar
Thomas Witkowski committed
643
644
    traverseInfo.updateStatus();

645
646
647
    // Used to calculate the overall number of non zero entries.
    int nnz = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
648
    for (int i = 0; i < nComponents; i++) {
649
650
651
652
653
654
655
656

#if 0
      std::vector<int> nnzInRow;
      int overallNnz, averageNnz;
      componentSpaces[i]->getMesh()->computeMatrixFillin(componentSpaces[i],
							 nnzInRow, overallNnz, averageNnz);     
#endif

657
658
659
660
661
662
      MSG("%d DOFs for %s\n", 
	  componentSpaces[i]->getAdmin()->getUsedSize(), 
	  componentSpaces[i]->getName().c_str());

      rhs->getDOFVector(i)->set(0.0);

663
      for (int j = 0; j < nComponents; j++) {
664

665
666
667
668
	// 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
669
	DOFMatrix *matrix = (*systemMatrix)[i][j];
670

671
672
673
	if (matrix) 
	  matrix->calculateNnz();
	
674
675
	// If the matrix was assembled before and it is marked to be assembled
	// only once, it will not be assembled.
676
	if (assembleMatrixOnlyOnce[i][j] && assembledMatrix[i][j]) {
677
	  assembleMatrix = false;
678
679
680
681
682
683
684
	} else if (matrix) {
	  matrix->getBaseMatrix().
	    change_dim(componentSpaces[i]->getAdmin()->getUsedSize(), 
		       componentSpaces[j]->getAdmin()->getUsedSize());

	  set_to_zero(matrix->getBaseMatrix());
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
685
686

	// If there is no DOFMatrix, e.g., if it is completly 0, do not assemble.
687
	if (!matrix || !assembleMatrix)
688
689
	  assembleMatrix = false;

690
691
692
	// 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.
693
694
695
696
	if (!assembleMatrix && i != j) {
	  if (matrix)
	    nnz += matrix->getBaseMatrix().nnz();

697
	  continue;
698
	}
699

700
701
702
	if (assembleMatrix && matrix->getBoundaryManager())
	  matrix->getBoundaryManager()->initMatrix(matrix);

Thomas Witkowski's avatar
Thomas Witkowski committed
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
	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
722
	    // least one another aux fe space. 
Thomas Witkowski's avatar
Thomas Witkowski committed
723
724
725
726
727
728

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

729
730
	    assembleOnDifMeshes2(componentSpaces[i], 
				 traverseInfo.getAuxFESpace(i, j),
Thomas Witkowski's avatar
Thomas Witkowski committed
731
732
				 assembleFlag,
				 NULL,
733
				 ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
734
735
736
737
738
739
740

	  } 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
741
742
743
	  assembleOnOneMesh(componentSpaces[i],
			    assembleFlag,
			    assembleMatrix ? matrix : NULL,
Thomas Witkowski's avatar
Thomas Witkowski committed
744
			    ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
745
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
746
747
748
749
	  assembleOnDifMeshes2(componentSpaces[i],
			       traverseInfo.getAuxFESpace(i, j),
			       assembleFlag,
			       assembleMatrix ? matrix : NULL,
750
			       ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
751
752
753
754

	} 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
755
756
757
	  assembleOnDifMeshes(componentSpaces[i], componentSpaces[j],
			      assembleFlag,
			      assembleMatrix ? matrix : NULL,
Thomas Witkowski's avatar
Thomas Witkowski committed
758
759
760
			      ((i == j) && asmVector) ? rhs->getDOFVector(i) : NULL);	  
	} else {
	  ERROR_EXIT("Not yet implemented!\n");
761
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
762

Thomas Witkowski's avatar
Thomas Witkowski committed
763
	assembledMatrix[i][j] = true;
764
765
766

	if (assembleMatrix)
	  matrix->finishInsertion();
767
768
769
770

	// TODO: ExitMatrix should be called after finishInsertion!
 	if (assembleMatrix && matrix->getBoundaryManager())
 	  matrix->getBoundaryManager()->exitMatrix(matrix);	  
771
772
773
	
	if (matrix)
	  nnz += matrix->getBaseMatrix().nnz();
774
775
      }

776
      // And now assemble boundary conditions on the vectors
Thomas Witkowski's avatar
Thomas Witkowski committed
777
778
      assembleBoundaryConditions(rhs->getDOFVector(i),
				 solution->getDOFVector(i),
779
				 componentMeshes[i],
780
				 assembleFlag);      
781
    }
782

783
    solverMatrix.setMatrix(*systemMatrix);
784

Thomas Witkowski's avatar
Thomas Witkowski committed
785
    createPrecon();
786

787
    INFO(info, 8)("fillin of assembled matrix: %d\n", nnz);
788

789
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
790
791
    INFO(info, 8)("buildAfterCoarsen needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()), omp_get_wtime() - wtime);
792
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
793
794
    INFO(info, 8)("buildAfterCoarsen needed %.5f seconds\n", 
		  TIME_USED(first, clock()));
Thomas Witkowski's avatar
Thomas Witkowski committed
795
#endif     
796
797
  }

798
799
  void ProblemVec::createPrecon()
  {
800
    std::string preconType("no");
801
802
803
804
805
    GET_PARAMETER(0, name + "->solver->left precon", &preconType);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
806
    solver->setLeftPrecon(preconCreator->create(solverMatrix.getMatrix()));
807
808
809
810
811

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

    preconCreator = CreatorMap<ITL_BasePreconditioner>::getCreator(preconType);
Thomas Witkowski's avatar
Thomas Witkowski committed
812
    solver->setRightPrecon(preconCreator->create(solverMatrix.getMatrix()));
813
814
815
  }


816
817
818
819
  void ProblemVec::writeFiles(AdaptInfo *adaptInfo, bool force) 
  {
    FUNCNAME("ProblemVec::writeFiles()");

820
821
822
823
824
825
826
    clock_t first = clock();

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

    int i;
Thomas Witkowski's avatar
Thomas Witkowski committed
827
    int size = static_cast<int>(fileWriters.size());
828
829
830
831
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1)
#endif
    for (i = 0; i < size; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
832
      fileWriters[i]->writeFiles(adaptInfo, force);
833
    }
834
835
    
#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
836
837
838
    INFO(info, 8)("writeFiles needed %.5f seconds system time / %.5f seconds wallclock time\n",
		  TIME_USED(first, clock()),
		  omp_get_wtime() - wtime);
839
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
840
841
    INFO(info, 8)("writeFiles needed %.5f seconds\n",
		  TIME_USED(first, clock()));
842
#endif
843
844
  }

845
  void ProblemVec::interpolInitialSolution(std::vector<AbstractFunction<double, WorldVector<double> >*> *fct) 
846
847
848
  {
    FUNCNAME("ProblemVec::interpolInitialSolution()");

Thomas Witkowski's avatar
Thomas Witkowski committed
849
    solution->interpol(fct);
850
851
852
853
854
  }

  void ProblemVec::addMatrixOperator(Operator *op, 
				     int i, int j,
				     double *factor,
855
856
				     double *estFactor,
				     bool fake)
857
858
  {
    FUNCNAME("ProblemVec::addMatrixOperator()");
Thomas Witkowski's avatar
Thomas Witkowski committed
859
   
Thomas Witkowski's avatar
Thomas Witkowski committed
860
    if (!(*systemMatrix)[i][j]) {
861
      TEST_EXIT(i != j)("should have been created already\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
862
      (*systemMatrix)[i][j] = new DOFMatrix(componentSpaces[i], componentSpaces[j], "");
Thomas Witkowski's avatar
Thomas Witkowski committed
863
864
865
      (*systemMatrix)[i][j]->setCoupleMatrix(true);
      (*systemMatrix)[i][j]->getBoundaryManager()->
	setBoundaryConditionMap((*systemMatrix)[i][i]->getBoundaryManager()->
866
				getBoundaryConditionMap());
Thomas Witkowski's avatar
Thomas Witkowski committed
867
868
869

      if (estimator[i])
	estimator[i]->setNewMatrix(j, (*systemMatrix)[i][j]);
870
    }    
Thomas Witkowski's avatar
Thomas Witkowski committed
871

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

874
875
876
877
878
879
880
881
882
883
884
    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;
	}
      }    
    } 
885
886
887
888
  }

  void ProblemVec::addVectorOperator(Operator *op, int i,
				     double *factor,
889
890
				     double *estFactor,
				     bool fake)
891
892
893
  {
    FUNCNAME("ProblemVec::addVectorOperator()");

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

896
897
898
899
900
901
902
903
904
905
    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;
	}
      }    
    }
906
907
  }

908
  void ProblemVec::addDirichletBC(BoundaryType type, int row, int col,
909
910
911
912
				  AbstractFunction<double, WorldVector<double> >* b)
  {
    FUNCNAME("ProblemVec::addDirichletBC()");

913
914
915
916
917
918
919
920
921
922
923
924
    DirichletBC *dirichletApply = 
      new DirichletBC(type, b, componentSpaces[row], componentSpaces[col], true);
    DirichletBC *dirichletNotApply = 
      new DirichletBC(type, b, componentSpaces[row], componentSpaces[col], false);

    for (int i = 0; i < nComponents; i++) 
      if (systemMatrix && (*systemMatrix)[row][i])
	if (i == col)
	  (*systemMatrix)[row][i]->getBoundaryManager()->addBoundaryCondition(dirichletApply);
	else
	  (*systemMatrix)[row][i]->getBoundaryManager()->addBoundaryCondition(dirichletNotApply);

Thomas Witkowski's avatar
Thomas Witkowski committed
925
    if (rhs)
926
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(dirichletApply);
Thomas Witkowski's avatar
Thomas Witkowski committed
927
    if (solution)
928
      solution->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(dirichletApply);
929
930
931
932
933
934
935
936
  }

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

    NeumannBC *neumann = 
937
938
      new NeumannBC(type, n, componentSpaces[row], componentSpaces[col]);

Thomas Witkowski's avatar
Thomas Witkowski committed
939
940
    if (rhs)
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(neumann);
941
942
943
944
945
946
947
948
949
  }

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

    RobinBC *robin = 
950
      new RobinBC(type, n, r, componentSpaces[row], componentSpaces[col]);
951

952
    if (systemMatrix && (*systemMatrix)[row][col])
Thomas Witkowski's avatar
Thomas Witkowski committed
953
      (*systemMatrix)[row][col]->getBoundaryManager()->addBoundaryCondition(robin);
954
955
    if (rhs)
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(robin);
956
957
958
959
960
961
  }

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

962
    FiniteElemSpace *feSpace = componentSpaces[row];
963
964
965

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

Thomas Witkowski's avatar
Thomas Witkowski committed
966
967
    if (systemMatrix && (*systemMatrix)[row][col]) 
      (*systemMatrix)[row][col]->getBoundaryManager()->addBoundaryCondition(periodic);
968

969
    if (rhs && row == col) 
Thomas Witkowski's avatar
Thomas Witkowski committed
970
      rhs->getDOFVector(row)->getBoundaryManager()->addBoundaryCondition(periodic);
971
972
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
973
974
  void ProblemVec::assembleOnOneMesh(FiniteElemSpace *feSpace, 
				     Flag assembleFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
975
976
977
978
				     DOFMatrix *matrix, DOFVector<double> *vector)
  {
    Mesh *mesh = feSpace->getMesh();
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
979
980

#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
981
    TraverseParallelStack stack;
982
983
984
#else
    TraverseStack stack;
#endif