AdaptStationary.cc 2.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
#include "AdaptStationary.h"
23
#include "Initfile.h"
24
#include "est/Estimator.h"
25
26
27
#include "ProblemIterationInterface.h"
#include <math.h>

28
29
#if HAVE_PARALLEL_DOMAIN_AMDIS
#include "parallel/MeshDistributor.h"
30
#ifdef HAVE_PARALLEL_PETSC
31
32
#include <petsc.h>
#endif
Naumann, Andreas's avatar
Naumann, Andreas committed
33
#endif
34

35
36
namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
37
  AdaptStationary::AdaptStationary(std::string name,
38
				   ProblemIterationInterface *prob,
Thomas Witkowski's avatar
Thomas Witkowski committed
39
				   AdaptInfo *info) 
40
41
    : AdaptBase(name, prob, info)
  {
42
43
    FUNCNAME("AdaptStationary::AdaptStationary()");

44
45
    MSG("You make use of the obsolete constructor AdaptStationary::AdaptStationary(...)!\n");
    MSG("Please use the constructor that uses references instead of pointers!\n");
46
47
48
49

    initialize();
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
50

51
52
53
54
55
  AdaptStationary::AdaptStationary(std::string name,
				   ProblemIterationInterface& prob,
				   AdaptInfo& info) 
    : AdaptBase(name, &prob, &info)
  {
56
57
58
    initialize();
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
59

60
61
  int AdaptStationary::adapt()
  {
62
#if HAVE_PARALLEL_DOMAIN_AMDIS
63
    Parallel::MeshDistributor::globalMeshDistributor->initParallelization(); 
64
65
#endif

66
    // initial iteration
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
67
    if (adaptInfo->getSpaceIteration() == -1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
68
69
70
      problemIteration->beginIteration(adaptInfo);
      problemIteration->oneIteration(adaptInfo, NO_ADAPTION);
      problemIteration->endIteration(adaptInfo);
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
71
      adaptInfo->incSpaceIteration();
72
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
73

74
    // adaption loop
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
75
76
77
    while (!adaptInfo->spaceToleranceReached() && 
	   (adaptInfo->getSpaceIteration() < adaptInfo->getMaxSpaceIteration() || 
	    adaptInfo->getMaxSpaceIteration() < 0) ) {
78

Thomas Witkowski's avatar
Thomas Witkowski committed
79
80
81
      problemIteration->beginIteration(adaptInfo);
      Flag adapted = problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
      problemIteration->endIteration(adaptInfo);
Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
84
85
86
87
88
89

#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
90
91
      if (!adapted) 
	break;
Thomas Witkowski's avatar
Thomas Witkowski committed
92
#endif
93
      
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
94
      adaptInfo->incSpaceIteration();
95
    }
96
97
98
99

    return 0;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
100

101
  void AdaptStationary::initialize()
102
  {
103
    Parameters::get(name + "->info", info);
104
105
106
  }

}