ProblemScal.cc 19.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "ProblemScal.h"
#include "AbstractFunction.h"
#include "DirichletBC.h"
#include "RobinBC.h"
#include "FixVec.h"
#include "Flag.h"
#include "Serializer.h"
#include "RecoveryEstimator.h"
#include "Operator.h"
#include "DOFMatrix.h"
#include "FiniteElemSpace.h"
#include "Estimator.h"
#include "OEMSolver.h"
#include "Preconditioner.h"
#include "MatVecMultiplier.h"
#include "DOFVector.h"
#include "Marker.h"
#include "AdaptInfo.h"
#include "ElInfo.h"
#include "FileWriter.h"
#include "RefinementManager.h"
#include "CoarseningManager.h"
#include "Lagrange.h"
#include "PeriodicBC.h"
#include "ValueReader.h"
26
#include "ElementFileWriter.h"
27
28
29
30
31
32

namespace AMDiS {

  ProblemScal *ProblemScal::traversePtr_ = NULL;

  void ProblemScal::writeFiles(AdaptInfo *adaptInfo, bool force) {
Thomas Witkowski's avatar
Thomas Witkowski committed
33
34
35
36
37
    for (int i = 0; i < static_cast<int>(fileWriters_.size()); i++) {
      fileWriters_[i]->writeFiles(adaptInfo, force);
    }
  }

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  void ProblemScal::interpolInitialSolution(AbstractFunction<double, WorldVector<double> > *fct) 
  {
    solution_->interpol(fct);
  }

  void ProblemScal::addMatrixOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
    systemMatrix_->addOperator(op, factor, estFactor);
  }

  void ProblemScal::addVectorOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
    rhs_->addOperator(op, factor, estFactor);
  }
  
  void ProblemScal::addDirichletBC(BoundaryType type, 
				   AbstractFunction<double, WorldVector<double> >* b) 
  {
    DirichletBC *dirichlet = new DirichletBC(type, b, feSpace_);
Thomas Witkowski's avatar
Thomas Witkowski committed
61
    if (systemMatrix_) 
62
      systemMatrix_->getBoundaryManager()->addBoundaryCondition(dirichlet);
Thomas Witkowski's avatar
Thomas Witkowski committed
63
    if (rhs_) 
64
      rhs_->getBoundaryManager()->addBoundaryCondition(dirichlet);
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    if (solution_)
66
67
68
69
70
71
72
      solution_->getBoundaryManager()->addBoundaryCondition(dirichlet);
  }

  void ProblemScal::addDirichletBC(BoundaryType type, 
				   DOFVector<double> *vec) 
  {
    DirichletBC *dirichlet = new DirichletBC(type, vec);
Thomas Witkowski's avatar
Thomas Witkowski committed
73
    if (systemMatrix_) 
74
      systemMatrix_->getBoundaryManager()->addBoundaryCondition(dirichlet);
Thomas Witkowski's avatar
Thomas Witkowski committed
75
    if (rhs_) 
76
      rhs_->getBoundaryManager()->addBoundaryCondition(dirichlet);
Thomas Witkowski's avatar
Thomas Witkowski committed
77
    if (solution_)
78
79
80
81
82
83
84
85
      solution_->getBoundaryManager()->addBoundaryCondition(dirichlet);
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       AbstractFunction<double, WorldVector<double> > *n,
			       AbstractFunction<double, WorldVector<double> > *r)
  {
    RobinBC *robin = new RobinBC(type, n, r, feSpace_);
Thomas Witkowski's avatar
Thomas Witkowski committed
86
    if (rhs_) 
87
      rhs_->getBoundaryManager()->addBoundaryCondition(robin);
Thomas Witkowski's avatar
Thomas Witkowski committed
88
    if (systemMatrix_)
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
      systemMatrix_->getBoundaryManager()->addBoundaryCondition(robin);
  }

  void ProblemScal::addNeumannBC(BoundaryType type, 
				 AbstractFunction<double, WorldVector<double> > *n)
  {
    NeumannBC *neumann = new NeumannBC(type, n, feSpace_);
    if(rhs_) 
      rhs_->getBoundaryManager()->addBoundaryCondition(neumann);
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       DOFVector<double> *n,
			       DOFVector<double> *r)
  {
    RobinBC *robin = new RobinBC(type, n, r, feSpace_);
Thomas Witkowski's avatar
Thomas Witkowski committed
105
    if (rhs_) 
106
      rhs_->getBoundaryManager()->addBoundaryCondition(robin);
Thomas Witkowski's avatar
Thomas Witkowski committed
107
    if (systemMatrix_)
108
109
110
111
112
113
114
      systemMatrix_->getBoundaryManager()->addBoundaryCondition(robin);
  }

  void ProblemScal::addPeriodicBC(BoundaryType type) 
  {
    PeriodicBC *periodic = new PeriodicBC(type, feSpace_);

Thomas Witkowski's avatar
Thomas Witkowski committed
115
    if (systemMatrix_) 
116
      systemMatrix_->getBoundaryManager()->addBoundaryCondition(periodic);
Thomas Witkowski's avatar
Thomas Witkowski committed
117
    if (rhs_) 
118
119
120
121
122
123
124
125
      rhs_->getBoundaryManager()->addBoundaryCondition(periodic);
  }

  void ProblemScal::createMesh()
  {
    TEST_EXIT(Parameters::initialized())("parameters not initialized\n");

    // === create problems mesh ===
Thomas Witkowski's avatar
Thomas Witkowski committed
126
    std::string meshName("");
127
128
129
130

    GET_PARAMETER(0, name_ + "->info", "%d", &info_);
    GET_PARAMETER(0, name_ + "->mesh", &meshName);

131
    TEST_EXIT(meshName != "")("no mesh name specified\n");
132
133
134
135

    // get problem dimension
    int dim = 0;
    GET_PARAMETER(0, name_ + "->dim", "%d", &dim);
136
    TEST_EXIT(dim)("no problem dimension specified!\n");
137
138
139
140

    // create the mesh
    mesh_ = NEW Mesh(meshName, dim);

Thomas Witkowski's avatar
Thomas Witkowski committed
141
    switch (dim) {
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    case 1:
      coarseningManager_ = NEW CoarseningManager1d();
      refinementManager_ = NEW RefinementManager1d();
      break;
    case 2:
      coarseningManager_ = NEW CoarseningManager2d();
      refinementManager_ = NEW RefinementManager2d();
      break;
    case 3:
      coarseningManager_ = NEW CoarseningManager3d();
      refinementManager_ = NEW RefinementManager3d();
      break;
    default:
      ERROR_EXIT("invalid dim!\n");
    }
  }

159
160
161
162
163
164
165
166
167

  void ProblemScal::setMeshFromProblemVec(ProblemVec* pv, int i) 
  { 
    mesh_ = pv->getMesh(i);
    coarseningManager_ = pv->getCoarseningManager(i);
    refinementManager_ = pv->getRefinementManager(i);
  }


168
169
  Flag ProblemScal::markElements(AdaptInfo *adaptInfo) 
  { 
Thomas Witkowski's avatar
Thomas Witkowski committed
170
    if (marker_)
171
172
173
      return marker_->markMesh(adaptInfo, mesh_);
    else
      WARNING("no marker\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
174

175
176
177
    return 0;
  }

178

179
180
181
182
183
  Flag ProblemScal::refineMesh(AdaptInfo *adaptInfo) 
  { 
    return refinementManager_->refineMesh(mesh_); 
  }

184

185
186
  Flag ProblemScal::coarsenMesh(AdaptInfo *adaptInfo) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
187
    if (adaptInfo->isCoarseningAllowed(0)) {
188
      return coarseningManager_->coarsenMesh(mesh_);
Thomas Witkowski's avatar
Thomas Witkowski committed
189
    } else {
190
191
192
193
194
195
196
197
      WARNING("coarsening not allowed\n");
      return 0;
    }
  }

  void ProblemScal::solve(AdaptInfo *adaptInfo) 
  {
    FUNCNAME("Problem::solve()");
Thomas Witkowski's avatar
Thomas Witkowski committed
198
    if (!solver_) {
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
      WARNING("no solver\n");
      return;
    }

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

    clock_t first = clock();
    int iter = solver_->solve(matVec_, solution_, rhs_, leftPrecon_, rightPrecon_); 

#ifdef _OPENMP
    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);
#else
    INFO(info_, 8)("solution of discrete system needed %.5f seconds\n",
		   TIME_USED(first, clock()));
#endif

    adaptInfo->setSolverIterations(iter);
    adaptInfo->setMaxSolverIterations(solver_->getMaxIterations());
    adaptInfo->setSolverTolerance(solver_->getTolerance());
    adaptInfo->setSolverResidual(solver_->getResidual());
  }

  void ProblemScal::initialize(Flag initFlag,
			       ProblemScal *adoptProblem,
			       Flag adoptFlag) 
  {
    FUNCNAME("Problem::initialize()");

    // === create mesh ===
232
    if (mesh_) { 
233
234
      WARNING("mesh already created\n");
    } else {
235
      if (initFlag.isSet(CREATE_MESH) || 
236
	 ((!adoptFlag.isSet(INIT_MESH))&&
Thomas Witkowski's avatar
Thomas Witkowski committed
237
238
239
240
	  (initFlag.isSet(INIT_SYSTEM)||initFlag.isSet(INIT_FE_SPACE)))) {
	createMesh();
      } 
      
241
      if (adoptProblem && 
242
243
	 (adoptFlag.isSet(INIT_MESH) || 
	  adoptFlag.isSet(INIT_SYSTEM) ||
Thomas Witkowski's avatar
Thomas Witkowski committed
244
245
246
247
248
249
	  adoptFlag.isSet(INIT_FE_SPACE))) {
	TEST_EXIT(!mesh_)("mesh already created\n");
	mesh_ = adoptProblem->getMesh();
	refinementManager_ = adoptProblem->refinementManager_;
	coarseningManager_ = adoptProblem->coarseningManager_;
      }
250
251
    }

252
253
    if (!mesh_) 
      WARNING("no mesh created\n");
254
255

    // === create fespace ===
256
    if (feSpace_) {
257
258
      WARNING("feSpace already created\n");
    } else {
259
      if (initFlag.isSet(INIT_FE_SPACE) || (initFlag.isSet(INIT_SYSTEM) && !adoptFlag.isSet(INIT_FE_SPACE))) {
260
261
	createFESpace();
      } 
Thomas Witkowski's avatar
Thomas Witkowski committed
262
263
264
265
      if (adoptProblem && (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
	TEST_EXIT(!feSpace_)("feSpace already created");
	feSpace_ = dynamic_cast<ProblemScal*>(adoptProblem)->getFESpace();
      }
266
267
    }

268
269
    if (!feSpace_) 
      WARNING("no feSpace created\n");
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

    // === create system ===
    if (initFlag.isSet(INIT_SYSTEM)) {
      createMatricesAndVectors();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
      TEST_EXIT(!solution_)("solution already created\n");
      TEST_EXIT(!rhs_)("rhs already created\n");
      TEST_EXIT(!systemMatrix_)("systemMatrix already created\n");
      solution_ = adoptProblem->getSolution();
      rhs_ = adoptProblem->getRHS();
      systemMatrix_  = adoptProblem->getSystemMatrix();
    }

    // === create solver ===
    if (solver_) {
      WARNING("solver already created\n");
    } else {
      if (initFlag.isSet(INIT_SOLVER)) {
	createSolver();
      } 
      if (adoptProblem && adoptFlag.isSet(INIT_SOLVER)) {
	TEST_EXIT(!solver_)("solver already created\n");
	solver_ = adoptProblem->getSolver();
      }
    }

    if (!solver_) 
      WARNING("no solver created\n");

    // === create estimator ===
Thomas Witkowski's avatar
Thomas Witkowski committed
301
    if (estimator_) {
302
303
      WARNING("estimator already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
304
      if (initFlag.isSet(INIT_ESTIMATOR)) {
305
306
	createEstimator();
      } 
Thomas Witkowski's avatar
Thomas Witkowski committed
307
      if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR)) {
308
309
310
311
312
	TEST_EXIT(!estimator_)("estimator already created\n");
	estimator_ = adoptProblem->getEstimator();
      } 
    }

313
314
    if (!estimator_) 
      WARNING("no estimator created\n");
315
316

    // === create marker ===
317
    if (marker_) {
318
319
      WARNING("marker already created\n");
    } else {
320
      if (initFlag.isSet(INIT_MARKER)) {
321
322
	createMarker();
      } 
323
      if (adoptProblem && adoptFlag.isSet(INIT_MARKER)) {
324
325
326
327
328
	TEST_EXIT(!marker_)("marker already created\n");
	marker_ = adoptProblem->getMarker();
      } 
    }

329
330
    if (!marker_) 
      WARNING("no marker created\n");
331
332

    // === create file writer ===
333
    if (initFlag.isSet(INIT_FILEWRITER)) {
334
335
336
337
338
339
340
341
342
343
344
345
346
347
      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;
Thomas Witkowski's avatar
Thomas Witkowski committed
348
    std::string serializationFilename = "";
349
350
351
352
353
354
355
356
357
358
359
360
361
    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("")) {
      GET_PARAMETER(0, name_ + "->input->read serialization", "%d", 
		    &readSerialization);
      if (readSerialization) {
	GET_PARAMETER(0, name_ + "->input->serialization filename", 
		      &serializationFilename);
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
Thomas Witkowski's avatar
Thomas Witkowski committed
362
	std::ifstream in(serializationFilename.c_str());
363
364
365
366
367
368
369
370
	deserialize(in);
	in.close();
      } else {
	if (initFlag.isSet(INIT_MESH) && mesh_ && !mesh_->isInitialized()) {
	  mesh_->initialize();
	}
    
	// === read value file and use it for the mesh values ===
Thomas Witkowski's avatar
Thomas Witkowski committed
371
	std::string valueFilename("");
372
373
374
375
376
377
378
379
380
	GET_PARAMETER(0, mesh_->getName() + "->value file name", &valueFilename);     
	if (valueFilename.length()) {     
	  ValueReader::readValue(valueFilename.c_str(),
				 mesh_,
				 solution_,
				 mesh_->getMacroFileInfo());
	  mesh_->clearMacroFileInfo();
	}
	
381
		
382
	// === do global refinements ===
383
384
385
386
387
	if (initFlag.isSet(INIT_GLOBAL_REFINES)) {
	  int globalRefinements = 0;
	  GET_PARAMETER(0, mesh_->getName() + "->global refinements", "%d", &globalRefinements);
	  refinementManager_->globalRefine(mesh_, globalRefinements);	
	}
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
      }
    }
  }

  void ProblemScal::createFESpace()
  {
    // create finite element space
    int degree = 1;
    GET_PARAMETER(0, name_ + "->polynomial degree" ,"%d", &degree);
    feSpace_ = FiniteElemSpace::provideFESpace(NULL,
					       Lagrange::getLagrange(mesh_->getDim(), degree),
					       mesh_,
					       name_ + "->feSpace");  

    // create dof admin for vertex dofs if neccessary
    if (mesh_->getNumberOfDOFs(VERTEX) == 0) {
      DimVec<int> ln_dof(mesh_->getDim(), DEFAULT_VALUE, 0);
      ln_dof[VERTEX]= 1;
      mesh_->createDOFAdmin("vertex dofs", ln_dof);
    }
  }

  void ProblemScal::createMatricesAndVectors()
  {
    // === create vectors and system matrix ===
    systemMatrix_ = NEW DOFMatrix(feSpace_, feSpace_, "system matrix");
414
415
    rhs_ = NEW DOFVector<double>(feSpace_, "rhs");
    solution_ = NEW DOFVector<double>(feSpace_, "solution");
416
417
418
419
420
421
422
423
424
425
426

    solution_->setCoarsenOperation(COARSE_INTERPOL);
    solution_->set(0.0);      /*  initialize u_h  !                      */

    // === create matVec ===
    matVec_ = NEW StandardMatVec<DOFMatrix, DOFVector<double> >(systemMatrix_);
  }

  void ProblemScal::createSolver()
  {
    // === create solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
427
    std::string solverType("no");
428
429
430
431
432
433
434
435
436
437
    GET_PARAMETER(0, name_ + "->solver", &solverType);
    OEMSolverCreator<DOFVector<double> > *solverCreator = 
      dynamic_cast<OEMSolverCreator<DOFVector<double> >*>(
							  CreatorMap<OEMSolver<DOFVector<double> > >::getCreator(solverType));
    TEST_EXIT(solverCreator)("no solver type\n");
    solverCreator->setName(name_ + "->solver");
    solver_ = solverCreator->create();
    solver_->initParameters();

    // === create preconditioners ===
Thomas Witkowski's avatar
Thomas Witkowski committed
438
    std::string preconType("no");
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    Preconditioner<DOFVector<double> > *precon;
    GET_PARAMETER(0, name_ + "->solver->left precon", &preconType);
    CreatorInterface<PreconditionerScal> *preconCreator = 
      CreatorMap<PreconditionerScal>::getCreator(preconType);

    if (!preconCreator->isNullCreator()) {
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setSizeAndRow(1, 0);
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setName(name_ + "->solver->left precon");
    }
  
    precon = preconCreator->create();

    if (precon) {
      dynamic_cast<PreconditionerScal*>(precon)->setMatrix(&systemMatrix_);
      leftPrecon_ = precon;
    }

    preconType.assign("no");
    GET_PARAMETER(0, name_ + "->solver->right precon", &preconType);
    preconCreator = CreatorMap<PreconditionerScal>::getCreator(preconType);

    if (!preconCreator->isNullCreator()) {
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setSizeAndRow(1, 0);
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setName(name_ + "->solver->left precon");
    }

    precon = preconCreator->create();
    if (precon) {
      dynamic_cast<PreconditionerScal*>(precon)->setMatrix(&systemMatrix_);
      rightPrecon_ = precon;
    }

    // === create vector creator ===
    solver_->setVectorCreator(new DOFVector<double>::Creator(feSpace_));

  }

  void ProblemScal::createEstimator()
  {
    // create and set leaf data prototype
    mesh_->
      setElementDataPrototype(NEW LeafDataEstimatable(NEW LeafDataCoarsenable));

    // create estimator
    //estimator = NEW ResidualEstimator(name + "->estimator");

    // === create estimator ===
Thomas Witkowski's avatar
Thomas Witkowski committed
486
    std::string estimatorType("no");
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
    GET_PARAMETER(0, name_ + "->estimator", &estimatorType);
    EstimatorCreator *estimatorCreator = 
      dynamic_cast<EstimatorCreator*>(
				      CreatorMap<Estimator>::getCreator(estimatorType));
    if(estimatorCreator) {
      estimatorCreator->setName(name_ + "->estimator");
      if(estimatorType == "recovery") {
	dynamic_cast<RecoveryEstimator::Creator*>(estimatorCreator)->setSolution(solution_);
      }
      estimator_ = estimatorCreator->create();

      // init estimator
      estimator_->addSystem(systemMatrix_, solution_, rhs_);
    }
  }

  void ProblemScal::createMarker()
  {
    marker_ = dynamic_cast<Marker*>(Marker::createMarker(name_ + "->marker", -1));
  }

  void ProblemScal::createFileWriter()
  {
    fileWriters_.push_back(NEW FileWriter(name_ + "->output", mesh_, solution_));
    int writeSerialization = 0;
    GET_PARAMETER(0, name_ + "->output->write serialization", "%d", 
		  &writeSerialization);
    if(writeSerialization) {
      fileWriters_.push_back(NEW Serializer<ProblemScal>(this));
    }
  }

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

    if(estimator_) {
      clock_t first = clock();
      estimator_->estimate(adaptInfo->getTimestep());
      INFO(info_,8)("estimation of the error needed %.5f seconds\n",
		    TIME_USED(first,clock()));

      adaptInfo->setEstSum(estimator_->getErrorSum(), 0);

      adaptInfo->
	setTimeEstSum(estimator_->getTimeEst(), 0);

      adaptInfo->
	setEstMax(estimator_->getErrorMax(), 0);

      adaptInfo->
	setTimeEstMax(estimator_->getTimeEstMax(), 0);

    } else {
      WARNING("no estimator\n");
    }
  }

  void ProblemScal::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag)
  {
547
    FUNCNAME("ProblemScal::buildAfterCoarsen()");
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586

    clock_t first = clock();

    mesh_->dofCompress();

    MSG("%d DOFs for %s\n", 
	feSpace_->getAdmin()->getUsedSize(), 
	feSpace_->getName().c_str());

    Flag assembleFlag = 
      flag | 
      systemMatrix_->getAssembleFlag() | 
      rhs_->getAssembleFlag();

    if (useGetBound_)
      assembleFlag |= Mesh::FILL_BOUND;

    systemMatrix_->clear();
    rhs_->set(0.0);

    traversePtr_ = this;
    mesh_->traverse(-1, assembleFlag, &buildAfterCoarsenFct);

    // fill boundary conditions
    if (systemMatrix_->getBoundaryManager())
      systemMatrix_->getBoundaryManager()->initMatrix(systemMatrix_);
    if (rhs_->getBoundaryManager())
      rhs_->getBoundaryManager()->initVector(rhs_);
    if (solution_->getBoundaryManager())
      solution_->getBoundaryManager()->initVector(solution_);

    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh_, -1, 
					 Mesh::CALL_LEAF_EL | 
					 Mesh::FILL_BOUND |
					 Mesh::FILL_COORDS |
					 Mesh::FILL_DET |
					 Mesh::FILL_GRD_LAMBDA |
					 Mesh::FILL_NEIGH);
Thomas Witkowski's avatar
Thomas Witkowski committed
587

588
589
    // for all elements ...
    while (elInfo) {
Thomas Witkowski's avatar
Thomas Witkowski committed
590
      if (systemMatrix_->getBoundaryManager()) 
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
	systemMatrix_->getBoundaryManager()->fillBoundaryConditions(elInfo, systemMatrix_);
      if (rhs_->getBoundaryManager())
	rhs_->getBoundaryManager()->fillBoundaryConditions(elInfo, rhs_);
      if (solution_->getBoundaryManager())
	solution_->getBoundaryManager()->fillBoundaryConditions(elInfo, solution_);
      elInfo = stack.traverseNext(elInfo);
    }

    if (systemMatrix_->getBoundaryManager())
      systemMatrix_->getBoundaryManager()->exitMatrix(systemMatrix_);
    if (rhs_->getBoundaryManager())
      rhs_->getBoundaryManager()->exitVector(rhs_);
    if (solution_->getBoundaryManager())
      solution_->getBoundaryManager()->exitVector(solution_);

    INFO(info_, 8)("buildAfterCoarsen needed %.5f seconds\n",
		   TIME_USED(first,clock()));

    return;
  }

  int ProblemScal::buildAfterCoarsenFct(ElInfo *elInfo) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
614
    BoundaryType *bound;
615

616
    if (traversePtr_->getBoundUsed()) {
Thomas Witkowski's avatar
Thomas Witkowski committed
617
618
      bound = GET_MEMORY(BoundaryType, traversePtr_->getFESpace()->getBasisFcts()->getNumber());
      traversePtr_->getFESpace()->getBasisFcts()->getBound(elInfo, bound);
619
    } else {
620
      bound = NULL;
621
    }
622
623
624
625
  
    traversePtr_->getSystemMatrix()->assemble(1.0, elInfo, bound);
    traversePtr_->getRHS()->assemble(1.0, elInfo, bound);

Thomas Witkowski's avatar
Thomas Witkowski committed
626
627
628
629
    if (traversePtr_->getBoundUsed()) {
      FREE_MEMORY(bound, BoundaryTyppe, traversePtr_->getFESpace()->getBasisFcts()->getNumber());
    }

630
631
632
    return 0;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
633
  void ProblemScal::writeResidualMesh(AdaptInfo *adaptInfo, const std::string name)
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
  {
    FUNCNAME("ProblemVec::writeResidualMesh()");

    Mesh *mesh = this->getMesh();
    FiniteElemSpace *fe = this->getFESpace();
    
    std::map<int, double> vec;
    
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh,
					 -1, 
					 Mesh::CALL_LEAF_EL | 
					 Mesh::FILL_COORDS);
    
    while (elInfo) {		  
      Element *el = elInfo->getElement();
      double lError = el->getEstimation(0);
      
      vec[elInfo->getElement()->getIndex()] = lError;
      elInfo = stack.traverseNext(elInfo);
    }
    
    ElementFileWriter fw(name, mesh, fe, vec);
    fw.writeFiles(adaptInfo, true);    
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
660
  void ProblemScal::serialize(std::ostream &out) 
661
662
663
664
665
666
667
  {
    FUNCNAME("ProblemScal::serialize()");

    mesh_->serialize(out);
    solution_->serialize(out);
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
668
  void ProblemScal::deserialize(std::istream &in) 
669
670
671
672
673
674
675
676
  {
    FUNCNAME("ProblemScal::deserialize()");

    mesh_->deserialize(in);    
    solution_->deserialize(in);
  }

}