Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

ProblemStat.cc 54.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


Thomas Witkowski's avatar
Thomas Witkowski committed
13
#include <sstream>
Thomas Witkowski's avatar
Thomas Witkowski committed
14
#include <boost/lexical_cast.hpp>
15 16

#include "ProblemStat.h"
17 18 19 20 21 22 23 24
#include "Serializer.h"
#include "AbstractFunction.h"
#include "Operator.h"
#include "SystemVector.h"
#include "DOFMatrix.h"
#include "FiniteElemSpace.h"
#include "Marker.h"
#include "AdaptInfo.h"
25
#include "io/FileWriter.h"
26 27
#include "CoarseningManager.h"
#include "RefinementManager.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
28
#include "DualTraverse.h"
29 30 31 32 33 34
#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
35
#include "Flag.h"
36
#include "est/Estimator.h"
37 38
#include "io/VtkWriter.h"
#include "io/ValueReader.h"
39
#include "ProblemStatDbg.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
40
#include "Debug.h"
41 42 43

namespace AMDiS {

44
  using namespace std;
45 46
  using boost::lexical_cast;

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  ProblemStatSeq::ProblemStatSeq(string nameStr,
				 ProblemIterationInterface *problemIteration)
    : StandardProblemIteration(this),
      name(nameStr),
      nComponents(-1),
      nMeshes(0),
      traverseInfo(0),
      solver(NULL),
      solution(NULL),
      rhs(NULL),
      systemMatrix(NULL),
      useGetBound(true),
      refinementManager(NULL),
      coarseningManager(NULL),
      info(10),
      deserialized(false),
      computeExactError(false),
      boundaryConditionSet(false),
      writeAsmInfo(false)
  {
    Parameters::get(name + "->components", nComponents);
    TEST_EXIT(nComponents > 0)("components not set!\n");    
    estimator.resize(nComponents, NULL);
    marker.resize(nComponents, NULL);
    
    assembleMatrixOnlyOnce.resize(nComponents);
    assembledMatrix.resize(nComponents);
    for (int i = 0; i < nComponents; i++) {
      assembleMatrixOnlyOnce[i].resize(nComponents);
      assembledMatrix[i].resize(nComponents);
      for (int j = 0; j < nComponents; j++) {
	assembleMatrixOnlyOnce[i][j] = false;
	assembledMatrix[i][j] = false;
      }
    }
    
    exactSolutionFcts.resize(nComponents);


    // === Initialize name of components. ===

    componentNames.resize(nComponents, "");
    for (int i = 0; i < nComponents; i++)
      componentNames[i] = "solution[" + lexical_cast<string>(i) + "]";

    Parameters::get(name + "->name", componentNames);
93 94
    componentNames.resize(nComponents);

95 96 97 98 99
    for (int i = 0; i < nComponents; i++)
      Parameters::get(name + "->name[" + lexical_cast<string>(i) + "]",
		      componentNames[i]);
  }

100 101 102
  void ProblemStatSeq::initialize(Flag initFlag,
				  ProblemStatSeq *adoptProblem,
				  Flag adoptFlag)
103
  {
104
    FUNCNAME("ProblemStat::initialize()");
105

106
    // === create meshes ===
Thomas Witkowski's avatar
Thomas Witkowski committed
107
    if (meshes.size() != 0) { 
108 109 110
      WARNING("meshes already created\n");
    } else {
      if (initFlag.isSet(CREATE_MESH) || 
Thomas Witkowski's avatar
Thomas Witkowski committed
111
	  (!adoptFlag.isSet(INIT_MESH) &&
Thomas Witkowski's avatar
Thomas Witkowski committed
112
	   (initFlag.isSet(INIT_SYSTEM) || initFlag.isSet(INIT_FE_SPACE))))
113
	createMesh();      
Thomas Witkowski's avatar
Thomas Witkowski committed
114

115
      if (adoptProblem && 
Thomas Witkowski's avatar
Thomas Witkowski committed
116
	  (adoptFlag.isSet(INIT_MESH) ||
117 118
	   adoptFlag.isSet(INIT_SYSTEM) ||
	   adoptFlag.isSet(INIT_FE_SPACE))) {
Thomas Witkowski's avatar
Thomas Witkowski committed
119
	meshes = adoptProblem->getMeshes();
Thomas Witkowski's avatar
Thomas Witkowski committed
120
	componentMeshes = adoptProblem->componentMeshes;
121 122 123

	// 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
124
	if (adoptProblem->getNumComponents() < nComponents) {
Thomas Witkowski's avatar
Thomas Witkowski committed
125
	  TEST_EXIT(meshes.size() == 1)("Daran muss ich noch arbeiten!\n");
126
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
127
	  componentMeshes.resize(nComponents);
128
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
129
	    componentMeshes[i] = componentMeshes[0];
130
	}
131 132 133
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
134
    if (meshes.size() == 0) 
135 136
      WARNING("no mesh created\n");

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    // === create refinement/corasening-manager ===
    if (refinementManager != NULL && coarseningManager != NULL) { 
      WARNING("refinement-/coarseningmanager already created\n");
    } else {
      if (initFlag.isSet(CREATE_MESH) || 
          (!adoptFlag.isSet(INIT_MESH) &&
           (initFlag.isSet(INIT_SYSTEM) || initFlag.isSet(INIT_FE_SPACE))))
        createRefCoarseManager();

      if (adoptProblem && 
          (adoptFlag.isSet(INIT_MESH) ||
           adoptFlag.isSet(INIT_SYSTEM) ||
           adoptFlag.isSet(INIT_FE_SPACE))) {
        refinementManager = adoptProblem->refinementManager;
        coarseningManager = adoptProblem->coarseningManager;
      }
    }

    if (refinementManager == NULL || coarseningManager == NULL) 
      WARNING("no refinement-/coarseningmanager created\n");

158
    // === create fespace ===
159
    if (feSpaces.size() != 0) {
160 161 162
      WARNING("feSpaces already created\n");
    } else {
      if (initFlag.isSet(INIT_FE_SPACE) || 
163
	  (initFlag.isSet(INIT_SYSTEM) && !adoptFlag.isSet(INIT_FE_SPACE)))
164
	createFeSpace(NULL);
165

166 167
      if (adoptProblem &&
	  (adoptFlag.isSet(INIT_FE_SPACE) || adoptFlag.isSet(INIT_SYSTEM))) {
168
	feSpaces = adoptProblem->getFeSpaces();
169
	componentSpaces = adoptProblem->componentSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
170
	traverseInfo = adoptProblem->traverseInfo;
171 172 173

	// 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
174 175
	if (adoptProblem->getNumComponents() < nComponents) {
	  TEST_EXIT(feSpaces.size() == 1)("Daran muss ich noch arbeiten!\n");
176
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
177
	  componentSpaces.resize(nComponents);
Thomas Witkowski's avatar
Thomas Witkowski committed
178
	  for (int i = adoptProblem->getNumComponents(); i < nComponents; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
179
	    componentSpaces[i] = componentSpaces[0];
180 181
	}

182 183 184
      }
    }

185
    if (feSpaces.size() == 0) 
186 187 188
      WARNING("no feSpace created\n");

    // === create system ===
189
    if (initFlag.isSet(INIT_SYSTEM)) 
190
      createMatricesAndVectors();
191
    
192
    if (adoptProblem && adoptFlag.isSet(INIT_SYSTEM)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
193
      solution = adoptProblem->getSolution();
194
      rhs = adoptProblem->getRhs();
Thomas Witkowski's avatar
Thomas Witkowski committed
195
      systemMatrix = adoptProblem->getSystemMatrix();
196 197 198
    }

    // === create solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
199
    if (solver) {
200 201 202 203 204 205
      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
206 207
	TEST_EXIT(!solver)("solver already created\n");
	solver = adoptProblem->getSolver();
208 209 210
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
211
    if (!solver) 
212 213 214
      WARNING("no solver created\n");

    // === create estimator ===
Thomas Witkowski's avatar
Thomas Witkowski committed
215
    if (initFlag.isSet(INIT_ESTIMATOR))
216
      createEstimator();
Thomas Witkowski's avatar
Thomas Witkowski committed
217 218

    if (adoptProblem && adoptFlag.isSet(INIT_ESTIMATOR))
219
      estimator = adoptProblem->getEstimators();
220 221

    // === create marker ===
Thomas Witkowski's avatar
Thomas Witkowski committed
222
    if (initFlag.isSet(INIT_MARKER))
223
      createMarker();
Thomas Witkowski's avatar
Thomas Witkowski committed
224

Thomas Witkowski's avatar
Thomas Witkowski committed
225
    if (adoptProblem && adoptFlag.isSet(INIT_MARKER))
226
      marker = adoptProblem->getMarkers();
227 228

    // === create file writer ===
Thomas Witkowski's avatar
Thomas Witkowski committed
229
    if (initFlag.isSet(INIT_FILEWRITER))
230 231 232 233 234
      createFileWriter();
    
    // === read serialization and init mesh ===
    
    // There are two possiblities where the user can define a serialization
235 236 237 238
    // 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.
239 240

    int readSerialization = 0;
241 242
    string serializationFilename = "";
    Parameters::get("argv->rs", serializationFilename);
243 244 245 246 247 248

    // 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;

249 250 251
      Parameters::get(name + "->input->read serialization", readSerialization);
      Parameters::get(name + "->input->serialization with adaptinfo",
		      readSerializationWithAdaptInfo);
252 253 254 255 256 257

      // 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) {
258 259
	Parameters::get(name + "->input->serialization filename", 
			serializationFilename);
260 261
	TEST_EXIT(serializationFilename != "")("no serialization file\n");

262 263
	// If AMDiS is compiled for parallel computations, the deserialization is
	// controlled by the parallel problem object.
264
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
265
	MSG("Deserialization from file: %s\n", serializationFilename.c_str());
266
	ifstream in(serializationFilename.c_str());
267 268 269 270 271 272

	// Read the revision number of the AMDiS version which was used to create 
	// the serialization file.
	int revNumber = -1;
	SerUtil::deserialize(in, revNumber);

273 274
	deserialize(in);
	in.close();
275
#endif
276 277

	deserialized = true;
278
      } else {
279
	int globalRefinements = 0;
280

281
	// If AMDiS is compiled for parallel computations, the global refinements are
282 283 284
	// ignored here. Later, each rank will add the global refinements to its 
	// private mesh.
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
285 286
	Parameters::get(meshes[0]->getName() + "->global refinements", 
			globalRefinements);
287
#endif
288

289
	bool initMesh = initFlag.isSet(INIT_MESH);
290

Thomas Witkowski's avatar
Thomas Witkowski committed
291 292
	// Initialize the meshes if there is no serialization file.
	for (int i = 0; i < static_cast<int>(meshes.size()); i++)
293
	  if (initMesh && meshes[i] && !(meshes[i]->isInitialized()))
Thomas Witkowski's avatar
Thomas Witkowski committed
294
	    meshes[i]->initialize();	    	
295 296

	// === read value file and use it for the mesh values ===
297 298
	string valueFilename("");
	Parameters::get(meshes[0]->getName() + "->value file name", valueFilename); 
299
	if (valueFilename.length())
300 301 302 303 304 305
	  ValueReader::readValue(valueFilename,
				 meshes[0],
				 solution->getDOFVector(0),
				 meshes[0]->getMacroFileInfo());

	// === do global refinements ===
306

Thomas Witkowski's avatar
Thomas Witkowski committed
307
	for (unsigned int i = 0; i < meshes.size(); i++)
308
	  if (initMesh && meshes[i])
Thomas Witkowski's avatar
Thomas Witkowski committed
309
	    refinementManager->globalRefine(meshes[i], globalRefinements);	
310 311 312 313 314 315
      }
    }

    doOtherStuff();
  }

316

317
  void ProblemStatSeq::createMesh() 
318
  {
319
    FUNCNAME("ProblemStat::createMesh()");
320

Thomas Witkowski's avatar
Thomas Witkowski committed
321
    componentMeshes.resize(nComponents);
322 323 324 325 326 327
    map<int, Mesh*> meshForRefinementSet;

    string meshName("");
    Parameters::get(name + "->mesh", meshName);
    TEST_EXIT(meshName != "")("No mesh name specified for \"%s->mesh\"!\n", 
			      name.c_str());
328 329

    int dim = 0;
330 331 332
    Parameters::get(name + "->dim", dim);
    TEST_EXIT(dim)("No problem dimension specified for \"%s->dim\"!\n",
		   name.c_str());
333

334
    for (int i = 0; i < nComponents; i++) {
335
      int refSet = -1;
336 337
      Parameters::get(name + "->refinement set[" + lexical_cast<string>(i) + "]", 
		      refSet);
338
      if (refSet < 0)
339
	refSet = 0;
340
      
341
      if (meshForRefinementSet[refSet] == NULL) {
Thomas Witkowski's avatar
Thomas Witkowski committed
342
	Mesh *newMesh = new Mesh(meshName, dim);
343
	meshForRefinementSet[refSet] = newMesh;
Thomas Witkowski's avatar
Thomas Witkowski committed
344 345
	meshes.push_back(newMesh);
	nMeshes++;
346
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
347
      componentMeshes[i] = meshForRefinementSet[refSet];
348
    }
349 350 351 352 353 354 355 356 357 358 359
  }


  void ProblemStatSeq::createRefCoarseManager() 
  {
    FUNCNAME("ProblemStat::createRefCoarseManager()");

    int dim = 0;
    Parameters::get(name + "->dim", dim);
    TEST_EXIT(dim)("No problem dimension specified for \"%s->dim\"!\n",
                   name.c_str());
360 361

    switch (dim) {
362
    case 1:
Thomas Witkowski's avatar
Thomas Witkowski committed
363
      refinementManager = new RefinementManager1d();
364
      coarseningManager = new CoarseningManager1d();
365 366
      break;
    case 2:
Thomas Witkowski's avatar
Thomas Witkowski committed
367
      refinementManager = new RefinementManager2d();
368
      coarseningManager = new CoarseningManager2d();
369 370
      break;
    case 3:
Thomas Witkowski's avatar
Thomas Witkowski committed
371
      refinementManager = new RefinementManager3d();
372
      coarseningManager = new CoarseningManager3d();
373 374 375 376 377 378
      break;
    default:
      ERROR_EXIT("invalid dim!\n");
    }
  }

379

380
  void ProblemStatSeq::createFeSpace(DOFAdmin *admin)
381
  {
382
    FUNCNAME("ProblemStat::createFeSpace()");
383

384
    map<pair<Mesh*, int>, FiniteElemSpace*> feSpaceMap;
385
    int dim = -1;
386
    Parameters::get(name + "->dim", dim);
387
    TEST_EXIT(dim != -1)("no problem dimension specified!\n");
388

389
    componentSpaces.resize(nComponents, NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
390
    traverseInfo.resize(nComponents);
391

392
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
393
      int degree = 1;
394 395
      Parameters::get(name + "->polynomial degree[" + 
		      boost::lexical_cast<string>(i) + "]", degree);
396

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

399
      if (feSpaceMap[pair<Mesh*, int>(componentMeshes[i], degree)] == NULL) {
Thomas Witkowski's avatar
Thomas Witkowski committed
400 401 402
	stringstream s;
	s << name << "->feSpace[" << i << "]";

403 404
	FiniteElemSpace *newFeSpace = 
	  FiniteElemSpace::provideFeSpace(admin, Lagrange::getLagrange(dim, degree),
Thomas Witkowski's avatar
Thomas Witkowski committed
405
					  componentMeshes[i], s.str());
406
	feSpaceMap[pair<Mesh*, int>(componentMeshes[i], degree)] = newFeSpace;
407
	feSpaces.push_back(newFeSpace);
408
      }
409

410
      componentSpaces[i] = feSpaceMap[pair<Mesh*, int>(componentMeshes[i], degree)];
Thomas Witkowski's avatar
Thomas Witkowski committed
411 412 413
    }

    for (int i = 0; i < nComponents; i++) {
414
      for (int j = 0; j < nComponents; j++)
415
	traverseInfo.getMatrix(i, j).setFeSpace(componentSpaces[i], componentSpaces[j]);
416
      
417
      traverseInfo.getVector(i).setFeSpace(componentSpaces[i]);
418 419 420
    }

    // create dof admin for vertex dofs if neccessary
Thomas Witkowski's avatar
Thomas Witkowski committed
421
    for (int i = 0; i < static_cast<int>(meshes.size()); i++) {
422
      if (meshes[i]->getNumberOfDofs(VERTEX) == 0) {
Thomas Witkowski's avatar
Thomas Witkowski committed
423
	DimVec<int> ln_dof(meshes[i]->getDim(), DEFAULT_VALUE, 0);
424
	ln_dof[VERTEX] = 1;
Thomas Witkowski's avatar
Thomas Witkowski committed
425
	meshes[i]->createDOFAdmin("vertex dofs", ln_dof);      
426 427 428 429
      }
    }
  }

430

431
  void ProblemStatSeq::createMatricesAndVectors()
432
  {
433
    FUNCNAME("ProblemStat::createMatricesAndVectors()");
434 435 436

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

Thomas Witkowski's avatar
Thomas Witkowski committed
437
    systemMatrix = new Matrix<DOFMatrix*>(nComponents, nComponents);
Thomas Witkowski's avatar
Thomas Witkowski committed
438
    systemMatrix->set(NULL);
Thomas Witkowski's avatar
Thomas Witkowski committed
439 440
    rhs = new SystemVector("rhs", componentSpaces, nComponents);
    solution = new SystemVector("solution", componentSpaces, nComponents);
441

Thomas Witkowski's avatar
Thomas Witkowski committed
442
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
443
      (*systemMatrix)[i][i] = new DOFMatrix(componentSpaces[i], 
Thomas Witkowski's avatar
Thomas Witkowski committed
444
					    componentSpaces[i], "A_ii");
Thomas Witkowski's avatar
Thomas Witkowski committed
445
      (*systemMatrix)[i][i]->setCoupleMatrix(false);
Thomas Witkowski's avatar
Thomas Witkowski committed
446

447 448
      rhs->setDOFVector(i, new DOFVector<double>(componentSpaces[i], 
						 "rhs[" + lexical_cast<string>(i) + "]"));
449

Thomas Witkowski's avatar
Thomas Witkowski committed
450
      solution->setDOFVector(i, new DOFVector<double>(componentSpaces[i],
451
      						      componentNames[i]));
Thomas Witkowski's avatar
Thomas Witkowski committed
452 453
      solution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      solution->getDOFVector(i)->set(0.0);
454 455 456
    }
  }

457

458
  void ProblemStatSeq::createSolver()
459
  {
460
    FUNCNAME("ProblemStat::createSolver()");
461 462

    // === create solver ===
463
    string solverType("0");
464 465
    string initFileStr = name + "->solver";
    Parameters::get(initFileStr, solverType);
466
    OEMSolverCreator *solverCreator = 
467
      dynamic_cast<OEMSolverCreator*>(CreatorMap<OEMSolver>::getCreator(solverType, initFileStr));
468
    TEST_EXIT(solverCreator)("no solver type\n");
469
    solverCreator->setName(initFileStr);
Thomas Witkowski's avatar
Thomas Witkowski committed
470 471
    solver = solverCreator->create();
    solver->initParameters();
472 473
  }

474

475
  void ProblemStatSeq::createEstimator()
476
  {
477
    FUNCNAME("ProblemStat::createEstimator()");
478 479

    // create and set leaf data prototype
Thomas Witkowski's avatar
Thomas Witkowski committed
480
    for (unsigned int i = 0; i < meshes.size(); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
481
      meshes[i]->setElementDataPrototype
Thomas Witkowski's avatar
Thomas Witkowski committed
482
	(new LeafDataEstimatableVec(new LeafDataCoarsenableVec));
483

Thomas Witkowski's avatar
Thomas Witkowski committed
484 485
    for (int i = 0; i < nComponents; i++) {
      TEST_EXIT(estimator[i] == NULL)("estimator already created\n");
486 487
      string estName = 
	name + "->estimator[" + boost::lexical_cast<string>(i) + "]";
488 489

      // === create estimator ===
490 491
      string estimatorType("0");
      Parameters::get(estName, estimatorType);
492
      EstimatorCreator *estimatorCreator = 
493
	dynamic_cast<EstimatorCreator*>(CreatorMap<Estimator>::getCreator(estimatorType, estName));
Thomas Witkowski's avatar
Thomas Witkowski committed
494
      if (estimatorCreator) {
495 496
	estimatorCreator->setName(estName);
	estimatorCreator->setRow(i);
497
	estimatorCreator->setSolution(solution->getDOFVector(i));
Thomas Witkowski's avatar
Thomas Witkowski committed
498
	estimator[i] = estimatorCreator->create();
499 500 501
      }


Thomas Witkowski's avatar
Thomas Witkowski committed
502 503 504 505 506
      if (estimator[i])
	for (int j = 0; j < nComponents; j++)
	  estimator[i]->addSystem((*systemMatrix)[i][j], 
				  solution->getDOFVector(j), 
				  rhs->getDOFVector(j));      
507 508 509
    }
  }

510

511
  void ProblemStatSeq::createMarker()
512
  {
513
    FUNCNAME("ProblemStat::createMarker()");
514

Thomas Witkowski's avatar
Thomas Witkowski committed
515
    int nMarkersCreated = 0;
516

517
    for (int i = 0; i < nComponents; i++) {
518
      marker[i] = Marker::createMarker
519
	(name + "->marker[" + boost::lexical_cast<string>(i) + "]", i);
520

521
      if (marker[i]) {
Thomas Witkowski's avatar
Thomas Witkowski committed
522 523 524 525
	nMarkersCreated++;

	// If there is more than one marker, and all components are defined
	// on the same mesh, the maximum marking has to be enabled.
526
 	if (nMarkersCreated > 1 && nMeshes == 1)
Thomas Witkowski's avatar
Thomas Witkowski committed
527
 	  marker[i]->setMaximumMarking(true);
528 529 530 531
      }
    }
  }

532

533
  void ProblemStatSeq::createFileWriter()
534
  {
535
    FUNCNAME("ProblemStat::createFileWriter()");
536 537
  
    // Create one filewriter for all components of the problem
538 539 540
    string numberedName  = name + "->output";
    string filename = "";
    Parameters::get(numberedName + "->filename", filename);
541 542

    if (filename != "") {
543
      vector< DOFVector<double>* > solutionList(nComponents);
544

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

Thomas Witkowski's avatar
Thomas Witkowski committed
549
	solutionList[i] = solution->getDOFVector(i);
550 551
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
552
      fileWriters.push_back(new FileWriter(numberedName,
553 554
					   componentMeshes[0],
					   solutionList));
555 556 557
    }

    // Create own filewriters for each components of the problem
558
    for (int i = 0; i < nComponents; i++) {
559
      numberedName = name + "->output[" + boost::lexical_cast<string>(i) + "]";
560
      filename = "";
561
      Parameters::get(numberedName + "->filename", filename);
562

563
      if (filename != "")
Thomas Witkowski's avatar
Thomas Witkowski committed
564
	fileWriters.push_back(new FileWriter(numberedName, 
565
					     componentMeshes[i], 
566
					     solution->getDOFVector(i)));      
567 568 569
    }

    int writeSerialization = 0;
570
    Parameters::get(name + "->output->write serialization", writeSerialization);
571
    if (writeSerialization)
572
      fileWriters.push_back(new Serializer<ProblemStatSeq>(this));
573 574
  }

575

576
  void ProblemStatSeq::doOtherStuff()
577 578 579
  {
  }

580

581
  void ProblemStatSeq::solve(AdaptInfo *adaptInfo, bool, bool)
582 583 584
  {
    FUNCNAME("Problem::solve()");

Thomas Witkowski's avatar
Thomas Witkowski committed
585
    if (!solver) {
586 587 588 589 590
      WARNING("no solver\n");
      return;
    }

    clock_t first = clock();
591
    
592
    solver->solveSystem(solverMatrix, *solution, *rhs);
593

Thomas Witkowski's avatar
Thomas Witkowski committed
594 595
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  TIME_USED(first, clock()));
596

597
    adaptInfo->setSolverIterations(solver->getIterations());
Thomas Witkowski's avatar
Thomas Witkowski committed
598 599 600
    adaptInfo->setMaxSolverIterations(solver->getMaxIterations());
    adaptInfo->setSolverTolerance(solver->getTolerance());
    adaptInfo->setSolverResidual(solver->getResidual());
601 602
  }

603

604
  void ProblemStatSeq::estimate(AdaptInfo *adaptInfo) 
605
  {
606
    FUNCNAME("ProblemStat::estimate()");
607

608 609 610 611
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    double first = MPI::Wtime();
#else
    clock_t first = clock();
612 613
#endif

614
    if (computeExactError) {
Thomas Witkowski's avatar
Thomas Witkowski committed
615
      computeError(adaptInfo);
616 617
    } else {
      for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
618
	Estimator *scalEstimator = estimator[i];
619 620
	
	if (scalEstimator) {
621 622
	  traverseInfo.updateStatus();
	  scalEstimator->setTraverseInfo(traverseInfo);
623
	  scalEstimator->estimate(adaptInfo->getTimestep());
624

625 626
	  adaptInfo->setEstSum(scalEstimator->getErrorSum(), i);
	  adaptInfo->setEstMax(scalEstimator->getErrorMax(), i);
627 628 629 630 631

	  if (adaptInfo->getRosenbrockMode() == false) {
	    adaptInfo->setTimeEstSum(scalEstimator->getTimeEst(), i);
	    adaptInfo->setTimeEstMax(scalEstimator->getTimeEstMax(), i);
	  }
632
	}
633 634 635
      }
    }

636
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
637
    MPI::COMM_WORLD.Barrier();
638 639
    INFO(info, 8)("estimation of the error needed %.5f seconds\n", 
		  MPI::Wtime() - first);
640
#else
Thomas Witkowski's avatar
Thomas Witkowski committed
641 642
    INFO(info, 8)("estimation of the error needed %.5f seconds\n",
		  TIME_USED(first, clock()));
643
#endif
644 645
  }

646

647
  Flag ProblemStatSeq::markElements(AdaptInfo *adaptInfo) 
648
  {
649
    FUNCNAME("ProblemStat::markElements()");
650

651
    TEST_EXIT_DBG(static_cast<unsigned int>(nComponents) == marker.size())
Thomas Witkowski's avatar
Thomas Witkowski committed
652 653
      ("Wrong number of markers!\n");

654
    Flag markFlag = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
655
    for (int i = 0; i < nComponents; i++)
656
      if (marker[i])
Thomas Witkowski's avatar
Thomas Witkowski committed
657
	markFlag |= marker[i]->markMesh(adaptInfo, componentMeshes[i]);
658
    
659 660 661
    return markFlag;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
662

663
  Flag ProblemStatSeq::refineMesh(AdaptInfo *adaptInfo) 
664
  {
665
    FUNCNAME("ProblemStat::refineMesh()");
666

Thomas Witkowski's avatar
Thomas Witkowski committed
667
    int nMeshes = static_cast<int>(meshes.size());
668
    Flag refineFlag = 0;
669 670 671 672
    for (int i = 0; i < nMeshes; i++)
      if (adaptInfo->isRefinementAllowed(i))
	refineFlag |= refinementManager->refineMesh(meshes[i]);

673 674 675
    return refineFlag;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
676

677
  Flag ProblemStatSeq::coarsenMesh(AdaptInfo *adaptInfo) 
678
  {
679
    FUNCNAME("ProblemStat::coarsenMesh()");
680

Thomas Witkowski's avatar
Thomas Witkowski committed
681
    int nMeshes = static_cast<int>(meshes.size());
682
    Flag coarsenFlag = 0;
683 684
    for (int i = 0; i < nMeshes; i++)
      if (adaptInfo->isCoarseningAllowed(i))
Thomas Witkowski's avatar
Thomas Witkowski committed
685
	coarsenFlag |= coarseningManager->coarsenMesh(meshes[i]);
686 687 688 689

    return coarsenFlag;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
690

691
  Flag ProblemStatSeq::oneIteration(AdaptInfo *adaptInfo, Flag toDo)
692
  {
693
    FUNCNAME("ProblemStat::oneIteration()");
694

695 696
    for (int i = 0; i < nComponents; i++)
      if (adaptInfo->spaceToleranceReached(i))
697
 	adaptInfo->allowRefinement(false, i);
698
      else
699
 	adaptInfo->allowRefinement(true, i);	
700 701 702 703

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

Thomas Witkowski's avatar
Thomas Witkowski committed
704

705 706
  void ProblemStatSeq::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
					 bool asmMatrix, bool asmVector)
707
  {
708
    FUNCNAME("ProblemStat::buildAfterCoarsen()");
709

710 711 712
//     buildAfterCoarsen_sebastianMode(adaptInfo, flag);
//     return;

713
    if (dualMeshTraverseRequired()) {
714 715 716 717
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
      ERROR_EXIT("Dual mesh assemble does not work in parallel code!\n");
#endif

718
      dualAssemble(adaptInfo, flag, asmMatrix, asmVector);
719 720
      return;
    }
721

722 723 724 725
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    double first = MPI::Wtime();
#endif

726

Thomas Witkowski's avatar
Thomas Witkowski committed
727 728 729 730
    for (unsigned int i = 0; i < meshes.size(); i++)
      meshes[i]->dofCompress();


731 732 733 734 735 736 737 738 739
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    MPI::COMM_WORLD.Barrier();
    INFO(info, 8)("dof compression needed %.5f seconds\n", 
		  MPI::Wtime() - first);

    first = MPI::Wtime();
#else
    clock_t first = clock();
#endif
740

741 742 743

    Flag assembleFlag = 
      flag | 
Thomas Witkowski's avatar
Thomas Witkowski committed
744 745
      (*systemMatrix)[0][0]->getAssembleFlag() | 
      rhs->getDOFVector(0)->getAssembleFlag()  |
746 747 748 749
      Mesh::CALL_LEAF_EL                        | 
      Mesh::FILL_COORDS                         |
      Mesh::FILL_DET                            |
      Mesh::FILL_GRD_LAMBDA |
750 751
      Mesh::FILL_NEIGH;

Thomas Witkowski's avatar
Thomas Witkowski committed