ProblemScal.cc 19.2 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
#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 "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"
24
#include "ElementFileWriter.h"
25
#include "ProblemVec.h"
26
27
28

namespace AMDiS {

29
30
31
32
  ProblemScal::~ProblemScal()
  {
    FUNCNAME("ProblemScal::~ProblemScal()");

33
34
    for (int i = 0; i < static_cast<int>(fileWriters.size()); i++)
      delete fileWriters[i];
35
36

    if (systemMatrix)
37
      delete systemMatrix;
38
    if (rhs) 
39
      delete rhs;
40
    if (solution)
41
      delete solution;
42
    if (estimator)
43
      delete estimator;
44
    if (marker)
45
      delete marker;
46
    if (solver)
47
      delete solver;
48
    if (mesh)
49
      delete mesh;
50
51
52
53
54

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

55
56
57
  void ProblemScal::writeFiles(AdaptInfo *adaptInfo, bool force) 
  {
    for (int i = 0; i < static_cast<int>(fileWriters.size()); i++)
58
      fileWriters[i]->writeFiles(adaptInfo, force);
Thomas Witkowski's avatar
Thomas Witkowski committed
59
60
  }

61
62
  void ProblemScal::interpolInitialSolution(AbstractFunction<double, WorldVector<double> > *fct) 
  {
63
    solution->interpol(fct);
64
65
66
67
68
69
  }

  void ProblemScal::addMatrixOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
70
    systemMatrix->addOperator(op, factor, estFactor);
71
72
73
74
75
76
  }

  void ProblemScal::addVectorOperator(Operator *op, 
				      double *factor,
				      double *estFactor) 
  {
77
    rhs->addOperator(op, factor, estFactor);
78
79
80
81
82
  }
  
  void ProblemScal::addDirichletBC(BoundaryType type, 
				   AbstractFunction<double, WorldVector<double> >* b) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
83
    DirichletBC *dirichlet = new DirichletBC(type, b, feSpace);
84
85
86
87
88
89
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (solution)
      solution->getBoundaryManager()->addBoundaryCondition(dirichlet);
90
91
92
93
94
95
  }

  void ProblemScal::addDirichletBC(BoundaryType type, 
				   DOFVector<double> *vec) 
  {
    DirichletBC *dirichlet = new DirichletBC(type, vec);
96
97
98
99
100
101
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(dirichlet);
    if (solution)
      solution->getBoundaryManager()->addBoundaryCondition(dirichlet);
102
103
104
105
106
107
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       AbstractFunction<double, WorldVector<double> > *n,
			       AbstractFunction<double, WorldVector<double> > *r)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
108
    RobinBC *robin = new RobinBC(type, n, r, feSpace);
109
110
111
112
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(robin);
    if (systemMatrix)
      systemMatrix->getBoundaryManager()->addBoundaryCondition(robin);
113
114
115
116
117
  }

  void ProblemScal::addNeumannBC(BoundaryType type, 
				 AbstractFunction<double, WorldVector<double> > *n)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
118
    NeumannBC *neumann = new NeumannBC(type, n, feSpace);
Thomas Witkowski's avatar
Thomas Witkowski committed
119
    if (rhs) 
120
      rhs->getBoundaryManager()->addBoundaryCondition(neumann);
121
122
123
124
125
126
  }

  void ProblemScal::addRobinBC(BoundaryType type, 
			       DOFVector<double> *n,
			       DOFVector<double> *r)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
127
    RobinBC *robin = new RobinBC(type, n, r, feSpace);
128
129
130
131
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(robin);
    if (systemMatrix)
      systemMatrix->getBoundaryManager()->addBoundaryCondition(robin);
132
133
134
135
  }

  void ProblemScal::addPeriodicBC(BoundaryType type) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
136
    PeriodicBC *periodic = new PeriodicBC(type, feSpace);
137

138
139
140
141
    if (systemMatrix) 
      systemMatrix->getBoundaryManager()->addBoundaryCondition(periodic);
    if (rhs) 
      rhs->getBoundaryManager()->addBoundaryCondition(periodic);
142
143
144
145
146
147
148
  }

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
151
    GET_PARAMETER(0, name + "->info", "%d", &info);
Thomas Witkowski's avatar
Thomas Witkowski committed
152
    GET_PARAMETER(0, name + "->mesh", &meshName);
153

154
    TEST_EXIT(meshName != "")("no mesh name specified\n");
155
156
157

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

    // create the mesh
162
    mesh = new Mesh(meshName, dim);
163

Thomas Witkowski's avatar
Thomas Witkowski committed
164
    switch (dim) {
165
    case 1:
166
167
      coarseningManager = new CoarseningManager1d();
      refinementManager = new RefinementManager1d();
168
169
      break;
    case 2:
170
171
      coarseningManager = new CoarseningManager2d();
      refinementManager = new RefinementManager2d();
172
173
      break;
    case 3:
174
175
      coarseningManager = new CoarseningManager3d();
      refinementManager = new RefinementManager3d();
176
177
178
179
180
181
      break;
    default:
      ERROR_EXIT("invalid dim!\n");
    }
  }

182
183
  void ProblemScal::setMeshFromProblemVec(ProblemVec* pv, int i) 
  { 
184
    mesh = pv->getMesh(i);
185
186
    coarseningManager = pv->getCoarseningManager(i);
    refinementManager = pv->getRefinementManager(i);
187
188
  }

189
190
  Flag ProblemScal::markElements(AdaptInfo *adaptInfo) 
  { 
191
192
    if (marker)
      return marker->markMesh(adaptInfo, mesh);
193
194
    else
      WARNING("no marker\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
195

196
197
198
199
200
    return 0;
  }

  Flag ProblemScal::refineMesh(AdaptInfo *adaptInfo) 
  { 
201
    return refinementManager->refineMesh(mesh); 
202
203
204
205
  }

  Flag ProblemScal::coarsenMesh(AdaptInfo *adaptInfo) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
206
    if (adaptInfo->isCoarseningAllowed(0)) {
207
      return coarseningManager->coarsenMesh(mesh);
Thomas Witkowski's avatar
Thomas Witkowski committed
208
    } else {
209
210
211
212
213
      WARNING("coarsening not allowed\n");
      return 0;
    }
  }

214
  void ProblemScal::solve(AdaptInfo *adaptInfo, bool fixedMatrix)
215
216
  {
    FUNCNAME("Problem::solve()");
217
    if (!solver) {
218
219
220
221
222
223
224
225
226
      WARNING("no solver\n");
      return;
    }

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

    clock_t first = clock();
227
228
229
230

    SolverMatrix<DOFMatrix> solverMatrix;
    solverMatrix.setMatrix(*systemMatrix);
    int iter = solver->solveSystem(solverMatrix, *solution, *rhs);
231
232

#ifdef _OPENMP
Thomas Witkowski's avatar
Thomas Witkowski committed
233
    INFO(info, 8)("solution of discrete system needed %.5f seconds system time / %.5f seconds wallclock time\n",
234
235
236
		   TIME_USED(first, clock()),
		   omp_get_wtime() - wtime);
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
237
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n",
238
239
240
241
		   TIME_USED(first, clock()));
#endif

    adaptInfo->setSolverIterations(iter);
242
243
244
    adaptInfo->setMaxSolverIterations(solver->getMaxIterations());
    adaptInfo->setSolverTolerance(solver->getTolerance());
    adaptInfo->setSolverResidual(solver->getResidual());
245
246
247
248
249
250
251
252
253
  }

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

    // === create mesh ===
254
    if (mesh) { 
255
256
      WARNING("mesh already created\n");
    } else {
257
      if(initFlag.isSet(CREATE_MESH) || 
258
	 ((!adoptFlag.isSet(INIT_MESH))&&
Thomas Witkowski's avatar
Thomas Witkowski committed
259
260
261
262
	  (initFlag.isSet(INIT_SYSTEM)||initFlag.isSet(INIT_FE_SPACE)))) {
	createMesh();
      } 
      
263
      if(adoptProblem && 
264
265
	 (adoptFlag.isSet(INIT_MESH) || 
	  adoptFlag.isSet(INIT_SYSTEM) ||
Thomas Witkowski's avatar
Thomas Witkowski committed
266
	  adoptFlag.isSet(INIT_FE_SPACE))) {
267
268
	TEST_EXIT(!mesh)("mesh already created\n");
	mesh = adoptProblem->getMesh();
269
270
	refinementManager = adoptProblem->refinementManager;
	coarseningManager = adoptProblem->coarseningManager;
Thomas Witkowski's avatar
Thomas Witkowski committed
271
      }
272
273
    }

274
    if (!mesh) 
275
      WARNING("no mesh created\n");
276
277

    // === create fespace ===
Thomas Witkowski's avatar
Thomas Witkowski committed
278
    if (feSpace) {
279
280
      WARNING("feSpace already created\n");
    } else {
281
282
      if (initFlag.isSet(INIT_FE_SPACE) || 
	  (initFlag.isSet(INIT_SYSTEM) && !adoptFlag.isSet(INIT_FE_SPACE))) {
283
284
	createFESpace();
      } 
285

286
287
      if (adoptProblem && 
	  (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
Thomas Witkowski's avatar
Thomas Witkowski committed
288
289
	TEST_EXIT(!feSpace)("feSpace already created");
	feSpace = dynamic_cast<ProblemScal*>(adoptProblem)->getFESpace();
Thomas Witkowski's avatar
Thomas Witkowski committed
290
      }
291
292
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
293
    if (!feSpace) 
294
      WARNING("no feSpace created\n");
295
296
297
298
299
300

    // === create system ===
    if (initFlag.isSet(INIT_SYSTEM)) {
      createMatricesAndVectors();
    } 
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
301
302
303
304
305
306
      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();
307
308
309
    }

    // === create solver ===
310
    if (solver) {
311
312
313
314
315
316
      WARNING("solver already created\n");
    } else {
      if (initFlag.isSet(INIT_SOLVER)) {
	createSolver();
      } 
      if (adoptProblem && adoptFlag.isSet(INIT_SOLVER)) {
317
318
	TEST_EXIT(!solver)("solver already created\n");
	solver = adoptProblem->getSolver();
319
320
321
      }
    }

322
    if (!solver) 
323
324
325
      WARNING("no solver created\n");

    // === create estimator ===
326
    if (estimator) {
327
328
      WARNING("estimator already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
329
      if (initFlag.isSet(INIT_ESTIMATOR)) {
330
331
	createEstimator();
      } 
Thomas Witkowski's avatar
Thomas Witkowski committed
332
      if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR)) {
333
334
	TEST_EXIT(!estimator)("estimator already created\n");
	estimator = adoptProblem->getEstimator();
335
336
337
      } 
    }

338
    if (!estimator) 
339
      WARNING("no estimator created\n");
340
341

    // === create marker ===
342
    if (marker) {
343
344
      WARNING("marker already created\n");
    } else {
345
      if(initFlag.isSet(INIT_MARKER)) {
346
347
	createMarker();
      } 
348
      if(adoptProblem && adoptFlag.isSet(INIT_MARKER)) {
349
350
	TEST_EXIT(!marker)("marker already created\n");
	marker = adoptProblem->getMarker();
351
352
353
      } 
    }

354
    if (!marker) 
355
      WARNING("no marker created\n");
356
357

    // === create file writer ===
358
    if(initFlag.isSet(INIT_FILEWRITER)) {
359
360
361
362
363
364
365
366
367
368
369
370
371
372
      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
373
    std::string serializationFilename = "";
374
375
376
377
378
    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
379
      GET_PARAMETER(0, name + "->input->read serialization", "%d", 
380
381
		    &readSerialization);
      if (readSerialization) {
Thomas Witkowski's avatar
Thomas Witkowski committed
382
	GET_PARAMETER(0, name + "->input->serialization filename", 
383
384
385
386
		      &serializationFilename);
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
Thomas Witkowski's avatar
Thomas Witkowski committed
387
	std::ifstream in(serializationFilename.c_str());
388
389
390
	deserialize(in);
	in.close();
      } else {
391
392
	if (initFlag.isSet(INIT_MESH) && mesh && !mesh->isInitialized()) {
	  mesh->initialize();
393
394
395
	}
    
	// === read value file and use it for the mesh values ===
Thomas Witkowski's avatar
Thomas Witkowski committed
396
	std::string valueFilename("");
397
	GET_PARAMETER(0, mesh->getName() + "->value file name", &valueFilename);     
398
	if (valueFilename.length()) {     
399
	  ValueReader::readValue(valueFilename,
400
401
402
403
				 mesh,
				 solution,
				 mesh->getMacroFileInfo());
	  mesh->clearMacroFileInfo();
404
	}
405
	
406
	// === do global refinements ===
407
408
	if (initFlag.isSet(INIT_GLOBAL_REFINES)) {
	  int globalRefinements = 0;
409
	  GET_PARAMETER(0, mesh->getName() + "->global refinements", "%d", &globalRefinements);
410
	  refinementManager->globalRefine(mesh, globalRefinements);	
411
	}
412
413
414
415
416
417
418
419
      }
    }
  }

  void ProblemScal::createFESpace()
  {
    // create finite element space
    int degree = 1;
Thomas Witkowski's avatar
Thomas Witkowski committed
420
    GET_PARAMETER(0, name + "->polynomial degree" ,"%d", &degree);
Thomas Witkowski's avatar
Thomas Witkowski committed
421
    feSpace = FiniteElemSpace::provideFESpace(NULL,
422
423
					       Lagrange::getLagrange(mesh->getDim(), degree),
					       mesh,
Thomas Witkowski's avatar
Thomas Witkowski committed
424
					       name + "->feSpace");  
425
426

    // create dof admin for vertex dofs if neccessary
427
428
    if (mesh->getNumberOfDOFs(VERTEX) == 0) {
      DimVec<int> ln_dof(mesh->getDim(), DEFAULT_VALUE, 0);
429
      ln_dof[VERTEX]= 1;
430
      mesh->createDOFAdmin("vertex dofs", ln_dof);
431
432
433
434
435
436
    }
  }

  void ProblemScal::createMatricesAndVectors()
  {
    // === create vectors and system matrix ===
437
438
439
    systemMatrix = new DOFMatrix(feSpace, feSpace, "system matrix");
    rhs = new DOFVector<double>(feSpace, "rhs");
    solution = new DOFVector<double>(feSpace, "solution");
440

441
442
    solution->setCoarsenOperation(COARSE_INTERPOL);
    solution->set(0.0);      /*  initialize u_h  !                      */
443
444
445
446
447
  }

  void ProblemScal::createSolver()
  {
    // === create solver ===
448
    std::string solverType("0");
Thomas Witkowski's avatar
Thomas Witkowski committed
449
    GET_PARAMETER(0, name + "->solver", &solverType);
450
451
    OEMSolverCreator *solverCreator = 
      dynamic_cast<OEMSolverCreator*>(CreatorMap<OEMSolver>::getCreator(solverType));
452
    TEST_EXIT(solverCreator)("no solver type\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
453
    solverCreator->setName(name + "->solver");
454
455
    solver = solverCreator->create();
    solver->initParameters();
456
457
458
459
460
  }

  void ProblemScal::createEstimator()
  {
    // create and set leaf data prototype
461
    mesh->setElementDataPrototype(new LeafDataEstimatable(new LeafDataCoarsenable));
462
463

    // === create estimator ===
464
    std::string estimatorType("0");
Thomas Witkowski's avatar
Thomas Witkowski committed
465
    GET_PARAMETER(0, name + "->estimator", &estimatorType);
466
467
468
    EstimatorCreator *estimatorCreator = 
      dynamic_cast<EstimatorCreator*>(
				      CreatorMap<Estimator>::getCreator(estimatorType));
Thomas Witkowski's avatar
Thomas Witkowski committed
469
    if (estimatorCreator) {
Thomas Witkowski's avatar
Thomas Witkowski committed
470
      estimatorCreator->setName(name + "->estimator");
Thomas Witkowski's avatar
Thomas Witkowski committed
471
      if (estimatorType == "recovery") {
472
	dynamic_cast<RecoveryEstimator::Creator*>(estimatorCreator)->setSolution(solution);
473
      }
474
      estimator = estimatorCreator->create();
475
476

      // init estimator
477
      estimator->addSystem(systemMatrix, solution, rhs);
478
479
480
481
482
    }
  }

  void ProblemScal::createMarker()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
483
    marker = dynamic_cast<Marker*>(Marker::createMarker(name + "->marker", -1));
484
485
486
487
  }

  void ProblemScal::createFileWriter()
  {
488
    fileWriters.push_back(new FileWriter(name + "->output", mesh, solution));
489
    int writeSerialization = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
490
    GET_PARAMETER(0, name + "->output->write serialization", "%d", 
491
		  &writeSerialization);
492
493
    if (writeSerialization)
      fileWriters.push_back(new Serializer<ProblemScal>(this));
494
495
496
497
498
499
  }

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

500
    if (estimator) {
501
      clock_t first = clock();
502
      estimator->estimate(adaptInfo->getTimestep());
Thomas Witkowski's avatar
Thomas Witkowski committed
503
      INFO(info,8)("estimation of the error needed %.5f seconds\n",
504
505
		    TIME_USED(first,clock()));

506
      adaptInfo->setEstSum(estimator->getErrorSum(), 0);
507
508
509
      adaptInfo->setTimeEstSum(estimator->getTimeEst(), 0);
      adaptInfo->setEstMax(estimator->getErrorMax(), 0);
      adaptInfo->setTimeEstMax(estimator->getTimeEstMax(), 0);
510
511
512
513
514
    } else {
      WARNING("no estimator\n");
    }
  }

515
516
  void ProblemScal::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
				      bool assembleMatrix, bool assembleVector)
517
  {
518
    FUNCNAME("ProblemScal::buildAfterCoarsen()");
519
520
521

    clock_t first = clock();

522
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
523
    mesh->dofCompress();
Thomas Witkowski's avatar
Thomas Witkowski committed
524
#endif
525
526

    MSG("%d DOFs for %s\n", 
Thomas Witkowski's avatar
Thomas Witkowski committed
527
	feSpace->getAdmin()->getUsedDOFs(), feSpace->getName().c_str());
528

529
    rhs->set(0.0);
530

531
532
533
534
535
536
    DOFMatrix::base_matrix_type& base_matrix= systemMatrix->getBaseMatrix(); 

    int nnz_per_row= 0;
    if (num_rows(base_matrix) != 0)
      nnz_per_row= int(double(base_matrix.nnz()) / num_rows(base_matrix) * 1.2); 
    if (nnz_per_row < 5) 
Thomas Witkowski's avatar
Thomas Witkowski committed
537
      nnz_per_row= 5;
538
539
540
541

    // Correct dimensionality of matrix
    base_matrix.change_dim(feSpace->getAdmin()->getUsedSize(), 
			   feSpace->getAdmin()->getUsedSize());
542
    set_to_zero(base_matrix);
543
544
545
546
   
    // Reuse old sparsity information (if available) or default
    systemMatrix->startInsertion(nnz_per_row);

547
    // fill boundary conditions
548
549
550
551
552
553
    if (systemMatrix->getBoundaryManager())
      systemMatrix->getBoundaryManager()->initMatrix(systemMatrix);
    if (rhs->getBoundaryManager())
      rhs->getBoundaryManager()->initVector(rhs);
    if (solution->getBoundaryManager())
      solution->getBoundaryManager()->initVector(solution);
554

555
    BoundaryType *bound;
556
    TraverseStack stack;
Thomas Witkowski's avatar
Thomas Witkowski committed
557
558
559
560
561
562
    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);
563

564
    while (elInfo) {
565
      if (useGetBound) {
Thomas Witkowski's avatar
Thomas Witkowski committed
566
	bound = new BoundaryType[feSpace->getBasisFcts()->getNumber()];
Thomas Witkowski's avatar
Thomas Witkowski committed
567
	feSpace->getBasisFcts()->getBound(elInfo, bound);
568
569
570
571
572
573
574
      } else {
	bound = NULL;
      }
      
      systemMatrix->assemble(1.0, elInfo, bound);
      rhs->assemble(1.0, elInfo, bound);
      
Thomas Witkowski's avatar
Thomas Witkowski committed
575
      if (useGetBound)
Thomas Witkowski's avatar
Thomas Witkowski committed
576
	delete [] bound;
577
      
578
579
580
581
582
583
      if (systemMatrix->getBoundaryManager()) 
	systemMatrix->getBoundaryManager()->fillBoundaryConditions(elInfo, systemMatrix);
      if (rhs->getBoundaryManager())
	rhs->getBoundaryManager()->fillBoundaryConditions(elInfo, rhs);
      if (solution->getBoundaryManager())
	solution->getBoundaryManager()->fillBoundaryConditions(elInfo, solution);
584
585
586
      elInfo = stack.traverseNext(elInfo);
    }

587
    systemMatrix->removeRowsWithDBC(systemMatrix->getApplyDBCs());
Thomas Witkowski's avatar
Thomas Witkowski committed
588

589
590
    systemMatrix->finishInsertion();

591
    // TODO: ExitMatrix should be called after finishInsertion!
592
593
594
595
596
597
    if (systemMatrix->getBoundaryManager())
      systemMatrix->getBoundaryManager()->exitMatrix(systemMatrix);
    if (rhs->getBoundaryManager())
      rhs->getBoundaryManager()->exitVector(rhs);
    if (solution->getBoundaryManager())
      solution->getBoundaryManager()->exitVector(solution);
598

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

601
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
Thomas Witkowski's avatar
Thomas Witkowski committed
602
603
604
605
606
607
//     PetscErrorCode ierr;
//     Mat A;

//     ierr = MatCreate(PETSC_COMM_WORLD, &A); CHKERRQ(ierr);
#endif
    
608
    createPrecon();
609
610
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
611
  void ProblemScal::writeResidualMesh(AdaptInfo *adaptInfo, const std::string name)
612
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
613
    FUNCNAME("ProblemScal::writeResidualMesh()");
614

Thomas Witkowski's avatar
Thomas Witkowski committed
615
    std::map<int, double> vec;    
616
    TraverseStack stack;
Thomas Witkowski's avatar
Thomas Witkowski committed
617
618
    ElInfo *elInfo = stack.traverseFirst(this->getMesh(),  -1, 
					 Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
619
620
    
    while (elInfo) {		  
Thomas Witkowski's avatar
Thomas Witkowski committed
621
      vec[elInfo->getElement()->getIndex()] = elInfo->getElement()->getEstimation(0);
622
623
624
      elInfo = stack.traverseNext(elInfo);
    }
    
Thomas Witkowski's avatar
Thomas Witkowski committed
625
    ElementFileWriter fw(name, this->getFESpace(), vec);
626
627
628
    fw.writeFiles(adaptInfo, true);    
  }

629
630
  void ProblemScal::createPrecon()
  {
631
    std::string preconType("no");
632
633
634
635
636
637
638
639
640
641
642
643
644
645
    GET_PARAMETER(0, name + "->solver->left precon", &preconType);

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

    solver->setLeftPrecon( preconCreator->create(systemMatrix->getBaseMatrix()) );

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

    preconCreator = CreatorMap<ITL_BasePreconditioner>::getCreator(preconType);
    solver->setRightPrecon( preconCreator->create(systemMatrix->getBaseMatrix()) );
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
646
  void ProblemScal::serialize(std::ostream &out) 
647
648
649
  {
    FUNCNAME("ProblemScal::serialize()");

650
651
    mesh->serialize(out);
    solution->serialize(out);
652
653
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
654
  void ProblemScal::deserialize(std::istream &in) 
655
656
657
  {
    FUNCNAME("ProblemScal::deserialize()");

658
659
    mesh->deserialize(in);    
    solution->deserialize(in);
660
661
662
  }

}