AdaptStationary.cc 2.32 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.


13
#include "AdaptStationary.h"
14
#include "Initfile.h"
15
#include "est/Estimator.h"
16
17
18
#include "ProblemIterationInterface.h"
#include <math.h>

19
20
#if HAVE_PARALLEL_DOMAIN_AMDIS
#include "parallel/MeshDistributor.h"
Naumann, Andreas's avatar
Naumann, Andreas committed
21
#ifndef HAVE_PARALLEL_MTL4
22
23
#include <petsc.h>
#endif
Naumann, Andreas's avatar
Naumann, Andreas committed
24
#endif
25

26
27
namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
28
  AdaptStationary::AdaptStationary(std::string name,
29
				   ProblemIterationInterface *prob,
Thomas Witkowski's avatar
Thomas Witkowski committed
30
				   AdaptInfo *info) 
31
32
    : AdaptBase(name, prob, info)
  {
33
34
    FUNCNAME("AdaptStationary::AdaptStationary()");

35
36
    MSG("You make use of the obsolete constructor AdaptStationary::AdaptStationary(...)!\n");
    MSG("Please use the constructor that uses references instead of pointers!\n");
37
38
39
40

    initialize();
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
41

42
43
44
45
46
  AdaptStationary::AdaptStationary(std::string name,
				   ProblemIterationInterface& prob,
				   AdaptInfo& info) 
    : AdaptBase(name, &prob, &info)
  {
47
48
49
    initialize();
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
50

51
52
  int AdaptStationary::adapt()
  {
53
54
55
56
#if HAVE_PARALLEL_DOMAIN_AMDIS
    MeshDistributor::globalMeshDistributor->initParallelization(); 
#endif

57
    // initial iteration
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
58
    if (adaptInfo->getSpaceIteration() == -1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
59
60
61
      problemIteration->beginIteration(adaptInfo);
      problemIteration->oneIteration(adaptInfo, NO_ADAPTION);
      problemIteration->endIteration(adaptInfo);
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
62
      adaptInfo->incSpaceIteration();
63
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
64

65
    // adaption loop
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
66
67
68
    while (!adaptInfo->spaceToleranceReached() && 
	   (adaptInfo->getSpaceIteration() < adaptInfo->getMaxSpaceIteration() || 
	    adaptInfo->getMaxSpaceIteration() < 0) ) {
69

Thomas Witkowski's avatar
Thomas Witkowski committed
70
71
72
      problemIteration->beginIteration(adaptInfo);
      Flag adapted = problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
      problemIteration->endIteration(adaptInfo);
Thomas Witkowski's avatar
Thomas Witkowski committed
73
74
75
76
77
78
79
80

#if HAVE_PARALLEL_DOMAIN_AMDIS
      int recvAllValues = 0;
      int isAdapted = static_cast<bool>(adapted);
      MPI::COMM_WORLD.Allreduce(&isAdapted, &recvAllValues, 1, MPI_INT, MPI_SUM);
      if (recvAllValues == 0)
	break;
#else
81
82
      if (!adapted) 
	break;
Thomas Witkowski's avatar
Thomas Witkowski committed
83
#endif
84
      
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
85
      adaptInfo->incSpaceIteration();
86
    }
87
88
89
90

    return 0;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
91

92
  void AdaptStationary::initialize()
93
  {  
94
    Parameters::get(name + "->info", info);
95
96
97
  }

}