ProblemScal.cc 19.8 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

namespace AMDiS {

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  ProblemScal::~ProblemScal()
  {
    FUNCNAME("ProblemScal::~ProblemScal()");

    for (int i = 0; i < static_cast<int>(fileWriters.size()); i++) {
      DELETE fileWriters[i];
    }

    if (systemMatrix)
      DELETE systemMatrix;
    if (rhs) 
      DELETE rhs;
    if (solution)
      DELETE solution;
    if (estimator)
      DELETE estimator;
    if (marker)
      DELETE marker;
    if (solver)
      DELETE solver;
    if (leftPrecon)
      DELETE leftPrecon;
    if (rightPrecon)
      DELETE rightPrecon;
    if (mesh)
      DELETE mesh;

    FiniteElemSpace::clear();
    Lagrange::clear();
  }

61
  void ProblemScal::writeFiles(AdaptInfo *adaptInfo, bool force) {
62
63
    for (int i = 0; i < static_cast<int>(fileWriters.size()); i++) {
      fileWriters[i]->writeFiles(adaptInfo, force);
Thomas Witkowski's avatar
Thomas Witkowski committed
64
65
66
    }
  }

67
68
  void ProblemScal::interpolInitialSolution(AbstractFunction<double, WorldVector<double> > *fct) 
  {
69
    solution->interpol(fct);
70
71
72
73
74
75
  }

  void ProblemScal::addMatrixOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
76
    systemMatrix->addOperator(op, factor, estFactor);
77
78
79
80
81
82
  }

  void ProblemScal::addVectorOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
83
    rhs->addOperator(op, factor, estFactor);
84
85
86
87
88
89
  }
  
  void ProblemScal::addDirichletBC(BoundaryType type, 
				   AbstractFunction<double, WorldVector<double> >* b) 
  {
    DirichletBC *dirichlet = new DirichletBC(type, b, feSpace_);
90
91
92
93
94
95
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (solution)
      solution->getBoundaryManager()->addBoundaryCondition(dirichlet);
96
97
98
99
100
101
  }

  void ProblemScal::addDirichletBC(BoundaryType type, 
				   DOFVector<double> *vec) 
  {
    DirichletBC *dirichlet = new DirichletBC(type, vec);
102
103
104
105
106
107
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (solution)
      solution->getBoundaryManager()->addBoundaryCondition(dirichlet);
108
109
110
111
112
113
114
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       AbstractFunction<double, WorldVector<double> > *n,
			       AbstractFunction<double, WorldVector<double> > *r)
  {
    RobinBC *robin = new RobinBC(type, n, r, feSpace_);
115
116
117
118
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(robin);
    if (systemMatrix)
      systemMatrix->getBoundaryManager()->addBoundaryCondition(robin);
119
120
121
122
123
124
  }

  void ProblemScal::addNeumannBC(BoundaryType type, 
				 AbstractFunction<double, WorldVector<double> > *n)
  {
    NeumannBC *neumann = new NeumannBC(type, n, feSpace_);
Thomas Witkowski's avatar
Thomas Witkowski committed
125
    if (rhs) 
126
      rhs->getBoundaryManager()->addBoundaryCondition(neumann);
127
128
129
130
131
132
133
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       DOFVector<double> *n,
			       DOFVector<double> *r)
  {
    RobinBC *robin = new RobinBC(type, n, r, feSpace_);
134
135
136
137
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(robin);
    if (systemMatrix)
      systemMatrix->getBoundaryManager()->addBoundaryCondition(robin);
138
139
140
141
142
143
  }

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

144
145
146
147
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(periodic);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(periodic);
148
149
  }

150
151
152
153
154
155
156
157
158
159
160
#ifdef HAVE_PARALLEL_AMDIS
  void ProblemScal::useApplicationOrdering(AO *ao, int nDofs) 
  {
    applicationOrdering = ao;
    nRankDOFs = nDofs;
    systemMatrix->useApplicationOrdering(ao);
    rhs->useApplicationOrdering(ao);
  }
#endif


161
162
163
164
165
  void ProblemScal::createMesh()
  {
    TEST_EXIT(Parameters::initialized())("parameters not initialized\n");

    // === create problems mesh ===
Thomas Witkowski's avatar
Thomas Witkowski committed
166
    std::string meshName("");
167

Thomas Witkowski's avatar
Thomas Witkowski committed
168
169
    GET_PARAMETER(0, name + "->info", "%d", &info_);
    GET_PARAMETER(0, name + "->mesh", &meshName);
170

171
    TEST_EXIT(meshName != "")("no mesh name specified\n");
172
173
174

    // get problem dimension
    int dim = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
175
    GET_PARAMETER(0, name + "->dim", "%d", &dim);
176
    TEST_EXIT(dim)("no problem dimension specified!\n");
177
178

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

Thomas Witkowski's avatar
Thomas Witkowski committed
181
    switch (dim) {
182
    case 1:
183
184
      coarseningManager = NEW CoarseningManager1d();
      refinementManager = NEW RefinementManager1d();
185
186
      break;
    case 2:
187
188
      coarseningManager = NEW CoarseningManager2d();
      refinementManager = NEW RefinementManager2d();
189
190
      break;
    case 3:
191
192
      coarseningManager = NEW CoarseningManager3d();
      refinementManager = NEW RefinementManager3d();
193
194
195
196
197
198
      break;
    default:
      ERROR_EXIT("invalid dim!\n");
    }
  }

199
200
201

  void ProblemScal::setMeshFromProblemVec(ProblemVec* pv, int i) 
  { 
202
    mesh = pv->getMesh(i);
203
204
    coarseningManager = pv->getCoarseningManager(i);
    refinementManager = pv->getRefinementManager(i);
205
206
207
  }


208
209
  Flag ProblemScal::markElements(AdaptInfo *adaptInfo) 
  { 
210
211
    if (marker)
      return marker->markMesh(adaptInfo, mesh);
212
213
    else
      WARNING("no marker\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
214

215
216
217
    return 0;
  }

218

219
220
  Flag ProblemScal::refineMesh(AdaptInfo *adaptInfo) 
  { 
221
    return refinementManager->refineMesh(mesh); 
222
223
  }

224

225
226
  Flag ProblemScal::coarsenMesh(AdaptInfo *adaptInfo) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
227
    if (adaptInfo->isCoarseningAllowed(0)) {
228
      return coarseningManager->coarsenMesh(mesh);
Thomas Witkowski's avatar
Thomas Witkowski committed
229
    } else {
230
231
232
233
234
      WARNING("coarsening not allowed\n");
      return 0;
    }
  }

235
  void ProblemScal::solve(AdaptInfo *adaptInfo, bool fixedMatrix)
236
237
  {
    FUNCNAME("Problem::solve()");
238
    if (!solver) {
239
240
241
242
243
244
245
246
247
      WARNING("no solver\n");
      return;
    }

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

    clock_t first = clock();
Thomas Witkowski's avatar
Thomas Witkowski committed
248
    int iter = solver->solve(matVec, solution, rhs, leftPrecon, rightPrecon); 
249
250
251
252
253
254
255
256
257
258
259

#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);
260
261
262
    adaptInfo->setMaxSolverIterations(solver->getMaxIterations());
    adaptInfo->setSolverTolerance(solver->getTolerance());
    adaptInfo->setSolverResidual(solver->getResidual());
263
264
265
266
267
268
269
270
271
  }

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

    // === create mesh ===
272
    if (mesh) { 
273
274
      WARNING("mesh already created\n");
    } else {
275
      if (initFlag.isSet(CREATE_MESH) || 
276
	 ((!adoptFlag.isSet(INIT_MESH))&&
Thomas Witkowski's avatar
Thomas Witkowski committed
277
278
279
280
	  (initFlag.isSet(INIT_SYSTEM)||initFlag.isSet(INIT_FE_SPACE)))) {
	createMesh();
      } 
      
281
      if (adoptProblem && 
282
283
	 (adoptFlag.isSet(INIT_MESH) || 
	  adoptFlag.isSet(INIT_SYSTEM) ||
Thomas Witkowski's avatar
Thomas Witkowski committed
284
	  adoptFlag.isSet(INIT_FE_SPACE))) {
285
286
	TEST_EXIT(!mesh)("mesh already created\n");
	mesh = adoptProblem->getMesh();
287
288
	refinementManager = adoptProblem->refinementManager;
	coarseningManager = adoptProblem->coarseningManager;
Thomas Witkowski's avatar
Thomas Witkowski committed
289
      }
290
291
    }

292
    if (!mesh) 
293
      WARNING("no mesh created\n");
294
295

    // === create fespace ===
296
    if (feSpace_) {
297
298
      WARNING("feSpace already created\n");
    } else {
299
300
      if (initFlag.isSet(INIT_FE_SPACE) || 
	  (initFlag.isSet(INIT_SYSTEM) && !adoptFlag.isSet(INIT_FE_SPACE))) {
301
302
	createFESpace();
      } 
303
304
      if (adoptProblem && 
	  (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
Thomas Witkowski's avatar
Thomas Witkowski committed
305
306
307
	TEST_EXIT(!feSpace_)("feSpace already created");
	feSpace_ = dynamic_cast<ProblemScal*>(adoptProblem)->getFESpace();
      }
308
309
    }

310
311
    if (!feSpace_) 
      WARNING("no feSpace created\n");
312
313
314
315
316
317

    // === create system ===
    if (initFlag.isSet(INIT_SYSTEM)) {
      createMatricesAndVectors();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
318
319
320
321
322
323
      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();
324
325
326
    }

    // === create solver ===
327
    if (solver) {
328
329
330
331
332
333
      WARNING("solver already created\n");
    } else {
      if (initFlag.isSet(INIT_SOLVER)) {
	createSolver();
      } 
      if (adoptProblem && adoptFlag.isSet(INIT_SOLVER)) {
334
335
	TEST_EXIT(!solver)("solver already created\n");
	solver = adoptProblem->getSolver();
336
337
338
      }
    }

339
    if (!solver) 
340
341
342
      WARNING("no solver created\n");

    // === create estimator ===
343
    if (estimator) {
344
345
      WARNING("estimator already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
346
      if (initFlag.isSet(INIT_ESTIMATOR)) {
347
348
	createEstimator();
      } 
Thomas Witkowski's avatar
Thomas Witkowski committed
349
      if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR)) {
350
351
	TEST_EXIT(!estimator)("estimator already created\n");
	estimator = adoptProblem->getEstimator();
352
353
354
      } 
    }

355
    if (!estimator) 
356
      WARNING("no estimator created\n");
357
358

    // === create marker ===
359
    if (marker) {
360
361
      WARNING("marker already created\n");
    } else {
362
      if (initFlag.isSet(INIT_MARKER)) {
363
364
	createMarker();
      } 
365
      if (adoptProblem && adoptFlag.isSet(INIT_MARKER)) {
366
367
	TEST_EXIT(!marker)("marker already created\n");
	marker = adoptProblem->getMarker();
368
369
370
      } 
    }

371
    if (!marker) 
372
      WARNING("no marker created\n");
373
374

    // === create file writer ===
375
    if (initFlag.isSet(INIT_FILEWRITER)) {
376
377
378
379
380
381
382
383
384
385
386
387
388
389
      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
390
    std::string serializationFilename = "";
391
392
393
394
395
    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("")) {
Thomas Witkowski's avatar
Thomas Witkowski committed
396
      GET_PARAMETER(0, name + "->input->read serialization", "%d", 
397
398
		    &readSerialization);
      if (readSerialization) {
Thomas Witkowski's avatar
Thomas Witkowski committed
399
	GET_PARAMETER(0, name + "->input->serialization filename", 
400
401
402
403
		      &serializationFilename);
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
Thomas Witkowski's avatar
Thomas Witkowski committed
404
	std::ifstream in(serializationFilename.c_str());
405
406
407
	deserialize(in);
	in.close();
      } else {
408
409
	if (initFlag.isSet(INIT_MESH) && mesh && !mesh->isInitialized()) {
	  mesh->initialize();
410
411
412
	}
    
	// === read value file and use it for the mesh values ===
Thomas Witkowski's avatar
Thomas Witkowski committed
413
	std::string valueFilename("");
414
	GET_PARAMETER(0, mesh->getName() + "->value file name", &valueFilename);     
415
416
	if (valueFilename.length()) {     
	  ValueReader::readValue(valueFilename.c_str(),
417
418
419
420
				 mesh,
				 solution,
				 mesh->getMacroFileInfo());
	  mesh->clearMacroFileInfo();
421
422
	}
	
423
		
424
	// === do global refinements ===
425
426
	if (initFlag.isSet(INIT_GLOBAL_REFINES)) {
	  int globalRefinements = 0;
427
	  GET_PARAMETER(0, mesh->getName() + "->global refinements", "%d", &globalRefinements);
428
	  refinementManager->globalRefine(mesh, globalRefinements);	
429
	}
430
431
432
433
434
435
436
437
      }
    }
  }

  void ProblemScal::createFESpace()
  {
    // create finite element space
    int degree = 1;
Thomas Witkowski's avatar
Thomas Witkowski committed
438
    GET_PARAMETER(0, name + "->polynomial degree" ,"%d", &degree);
439
    feSpace_ = FiniteElemSpace::provideFESpace(NULL,
440
441
					       Lagrange::getLagrange(mesh->getDim(), degree),
					       mesh,
Thomas Witkowski's avatar
Thomas Witkowski committed
442
					       name + "->feSpace");  
443
444

    // create dof admin for vertex dofs if neccessary
445
446
    if (mesh->getNumberOfDOFs(VERTEX) == 0) {
      DimVec<int> ln_dof(mesh->getDim(), DEFAULT_VALUE, 0);
447
      ln_dof[VERTEX]= 1;
448
      mesh->createDOFAdmin("vertex dofs", ln_dof);
449
450
451
452
453
454
    }
  }

  void ProblemScal::createMatricesAndVectors()
  {
    // === create vectors and system matrix ===
455
456
457
    systemMatrix = NEW DOFMatrix(feSpace_, feSpace_, "system matrix");
    rhs = NEW DOFVector<double>(feSpace_, "rhs");
    solution = NEW DOFVector<double>(feSpace_, "solution");
458

459
460
    solution->setCoarsenOperation(COARSE_INTERPOL);
    solution->set(0.0);      /*  initialize u_h  !                      */
461
462

    // === create matVec ===
Thomas Witkowski's avatar
Thomas Witkowski committed
463
    matVec = NEW StandardMatVec<DOFMatrix, DOFVector<double> >(systemMatrix);
464
465
466
467
468
  }

  void ProblemScal::createSolver()
  {
    // === create solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
469
    std::string solverType("no");
Thomas Witkowski's avatar
Thomas Witkowski committed
470
    GET_PARAMETER(0, name + "->solver", &solverType);
471
    OEMSolverCreator<DOFVector<double> > *solverCreator = 
Thomas Witkowski's avatar
Thomas Witkowski committed
472
      dynamic_cast<OEMSolverCreator<DOFVector<double> >*>(CreatorMap<OEMSolver<DOFVector<double> > >::getCreator(solverType));
473
    TEST_EXIT(solverCreator)("no solver type\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
474
    solverCreator->setName(name + "->solver");
475
476
    solver = solverCreator->create();
    solver->initParameters();
477
478

    // === create preconditioners ===
Thomas Witkowski's avatar
Thomas Witkowski committed
479
    std::string preconType("no");
480
    Preconditioner<DOFVector<double> > *precon;
Thomas Witkowski's avatar
Thomas Witkowski committed
481
    GET_PARAMETER(0, name + "->solver->left precon", &preconType);
482
483
484
485
486
    CreatorInterface<PreconditionerScal> *preconCreator = 
      CreatorMap<PreconditionerScal>::getCreator(preconType);

    if (!preconCreator->isNullCreator()) {
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setSizeAndRow(1, 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
487
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setName(name + "->solver->left precon");
488
489
490
491
492
    }
  
    precon = preconCreator->create();

    if (precon) {
493
494
      dynamic_cast<PreconditionerScal*>(precon)->setMatrix(&systemMatrix);
      leftPrecon = precon;
495
496
497
    }

    preconType.assign("no");
Thomas Witkowski's avatar
Thomas Witkowski committed
498
    GET_PARAMETER(0, name + "->solver->right precon", &preconType);
499
500
501
502
    preconCreator = CreatorMap<PreconditionerScal>::getCreator(preconType);

    if (!preconCreator->isNullCreator()) {
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setSizeAndRow(1, 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
503
      dynamic_cast<PreconditionerScalCreator*>(preconCreator)->setName(name + "->solver->left precon");
504
505
506
507
    }

    precon = preconCreator->create();
    if (precon) {
508
509
      dynamic_cast<PreconditionerScal*>(precon)->setMatrix(&systemMatrix);
      rightPrecon = precon;
510
511
512
    }

    // === create vector creator ===
513
    solver->setVectorCreator(new DOFVector<double>::Creator(feSpace_));
514
515
516
517
518
519

  }

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

    // === create estimator ===
Thomas Witkowski's avatar
Thomas Witkowski committed
523
    std::string estimatorType("no");
Thomas Witkowski's avatar
Thomas Witkowski committed
524
    GET_PARAMETER(0, name + "->estimator", &estimatorType);
525
526
527
    EstimatorCreator *estimatorCreator = 
      dynamic_cast<EstimatorCreator*>(
				      CreatorMap<Estimator>::getCreator(estimatorType));
Thomas Witkowski's avatar
Thomas Witkowski committed
528
    if (estimatorCreator) {
Thomas Witkowski's avatar
Thomas Witkowski committed
529
      estimatorCreator->setName(name + "->estimator");
Thomas Witkowski's avatar
Thomas Witkowski committed
530
      if (estimatorType == "recovery") {
531
	dynamic_cast<RecoveryEstimator::Creator*>(estimatorCreator)->setSolution(solution);
532
      }
533
      estimator = estimatorCreator->create();
534
535

      // init estimator
536
      estimator->addSystem(systemMatrix, solution, rhs);
537
538
539
540
541
    }
  }

  void ProblemScal::createMarker()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
542
    marker = dynamic_cast<Marker*>(Marker::createMarker(name + "->marker", -1));
543
544
545
546
  }

  void ProblemScal::createFileWriter()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
547
    fileWriters.push_back(NEW FileWriter(name + "->output", mesh, solution));
548
    int writeSerialization = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
549
    GET_PARAMETER(0, name + "->output->write serialization", "%d", 
550
		  &writeSerialization);
Thomas Witkowski's avatar
Thomas Witkowski committed
551
    if (writeSerialization) {
552
      fileWriters.push_back(NEW Serializer<ProblemScal>(this));
553
554
555
556
557
558
559
    }
  }

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

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

566
      adaptInfo->setEstSum(estimator->getErrorSum(), 0);
567
568

      adaptInfo->
569
	setTimeEstSum(estimator->getTimeEst(), 0);
570
571

      adaptInfo->
572
	setEstMax(estimator->getErrorMax(), 0);
573
574

      adaptInfo->
575
	setTimeEstMax(estimator->getTimeEstMax(), 0);
576
577
578
579
580
581

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

582
583
  void ProblemScal::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
				      bool assembleMatrix, bool assembleVector)
584
  {
585
    FUNCNAME("ProblemScal::buildAfterCoarsen()");
586
587
588

    clock_t first = clock();

589
    mesh->dofCompress();
590
591

    MSG("%d DOFs for %s\n", 
592
593
594
#ifdef HAVE_PARALLEL_AMDIS
	nRankDOFs,
#else
595
	feSpace_->getAdmin()->getUsedSize(), 
596
#endif
597
598
599
600
	feSpace_->getName().c_str());

    Flag assembleFlag = 
      flag | 
601
602
      systemMatrix->getAssembleFlag() | 
      rhs->getAssembleFlag();
603

604
    if (useGetBound)
605
606
      assembleFlag |= Mesh::FILL_BOUND;

607
608
    systemMatrix->clear();
    rhs->set(0.0);
609
610

    // fill boundary conditions
611
612
613
614
615
616
    if (systemMatrix->getBoundaryManager())
      systemMatrix->getBoundaryManager()->initMatrix(systemMatrix);
    if (rhs->getBoundaryManager())
      rhs->getBoundaryManager()->initVector(rhs);
    if (solution->getBoundaryManager())
      solution->getBoundaryManager()->initVector(solution);
617

618
    BoundaryType *bound;
619
    TraverseStack stack;
620
621
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, assembleFlag);

622
    while (elInfo) {
623
624
625
626
627
628
629
630
631
632
633
634
635
636
      if (useGetBound) {
	bound = GET_MEMORY(BoundaryType, feSpace_->getBasisFcts()->getNumber());
	feSpace_->getBasisFcts()->getBound(elInfo, bound);
      } else {
	bound = NULL;
      }
      
      systemMatrix->assemble(1.0, elInfo, bound);
      rhs->assemble(1.0, elInfo, bound);
      
      if (useGetBound) {
	FREE_MEMORY(bound, BoundaryType, feSpace_->getBasisFcts()->getNumber());	    
      }
      
637
638
639
640
641
642
      if (systemMatrix->getBoundaryManager()) 
	systemMatrix->getBoundaryManager()->fillBoundaryConditions(elInfo, systemMatrix);
      if (rhs->getBoundaryManager())
	rhs->getBoundaryManager()->fillBoundaryConditions(elInfo, rhs);
      if (solution->getBoundaryManager())
	solution->getBoundaryManager()->fillBoundaryConditions(elInfo, solution);
643
644
645
      elInfo = stack.traverseNext(elInfo);
    }

646
    systemMatrix->removeRowsWithDBC(systemMatrix->getApplyDBCs());
Thomas Witkowski's avatar
Thomas Witkowski committed
647

648
649
650
651
652
653
    if (systemMatrix->getBoundaryManager())
      systemMatrix->getBoundaryManager()->exitMatrix(systemMatrix);
    if (rhs->getBoundaryManager())
      rhs->getBoundaryManager()->exitVector(rhs);
    if (solution->getBoundaryManager())
      solution->getBoundaryManager()->exitVector(solution);
654
655
656
657
658

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

Thomas Witkowski's avatar
Thomas Witkowski committed
659
  void ProblemScal::writeResidualMesh(AdaptInfo *adaptInfo, const std::string name)
660
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
661
    FUNCNAME("ProblemScal::writeResidualMesh()");
662

Thomas Witkowski's avatar
Thomas Witkowski committed
663
    std::map<int, double> vec;    
664
    TraverseStack stack;
Thomas Witkowski's avatar
Thomas Witkowski committed
665
666
    ElInfo *elInfo = stack.traverseFirst(this->getMesh(),  -1, 
					 Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
667
668
    
    while (elInfo) {		  
Thomas Witkowski's avatar
Thomas Witkowski committed
669
      vec[elInfo->getElement()->getIndex()] = elInfo->getElement()->getEstimation(0);
670
671
672
      elInfo = stack.traverseNext(elInfo);
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
673
    ElementFileWriter fw(name, this->getFESpace(), vec);
674
675
676
    fw.writeFiles(adaptInfo, true);    
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
677
  void ProblemScal::serialize(std::ostream &out) 
678
679
680
  {
    FUNCNAME("ProblemScal::serialize()");

681
682
    mesh->serialize(out);
    solution->serialize(out);
683
684
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
685
  void ProblemScal::deserialize(std::istream &in) 
686
687
688
  {
    FUNCNAME("ProblemScal::deserialize()");

689
690
    mesh->deserialize(in);    
    solution->deserialize(in);
691
692
693
  }

}