CouplingIterationInterface.cc 4.51 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
26
27
28
29
30
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// 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.



/** \file CouplingIterationInterface.h */

#include "Flag.h"
#include "CouplingIterationInterface.h"

namespace AMDiS {

  /// add problem by number
  void CouplingIterationInterface::addIterationInterface(ProblemIterationInterface* probIter, int number)
  {
31
    size_t idx = std::min(problems.size(), static_cast<size_t>(number)); 
32
33
34
    if (number < 0)
      idx = problems.size();
    std::vector<ProblemIterationInterface*>::iterator pos = problems.begin() + idx;
35
    std::vector<bool>::iterator pos2 = solveProblem.begin() + idx;
36
37

    problems.insert(pos, probIter);
38
    solveProblem.insert(pos2, true);
39
  }
40
41
42
43
44
45


  /// Called before each adaption loop iteration.
  void CouplingIterationInterface::beginIteration(AdaptInfo *adaptInfo)
  { FUNCNAME("CouplingIterationInterface::beginIteration()");
    MSG("\n");
Praetorius, Simon's avatar
Praetorius, Simon committed
46
47
48
49
    int nTimesteps = (adaptInfo->getNumberOfTimesteps()
			? adaptInfo->getNumberOfTimesteps()
			: static_cast<int>((adaptInfo->getEndTime()-adaptInfo->getStartTime())/adaptInfo->getTimestep())
		     );
50
51
    MSG("begin of iteration number: %d/%d\n", 
      adaptInfo->getTimestepNumber() + 1,
52
      nTimesteps);
53
    MSG("==================================================\n");
54
  }
55
56
57
58
59
60
61
62


  /** \brief
    * Determines the execution order of the single adaption steps. If adapt is
    * true, mesh adaption will be performed. This allows to avoid mesh adaption,
    * e.g. in timestep adaption loops of timestep adaptive strategies.
    */
  Flag CouplingIterationInterface::oneIteration(AdaptInfo *adaptInfo, Flag toDo)
63
  {
64
65
    Flag flag = 0;

66
67
68
69
70
71
    for (size_t i = 0; i < problems.size(); ++i) {
      if (solveProblem[i]) {
        problems[i]->beginIteration(adaptInfo);
        flag |= problems[i]->oneIteration(adaptInfo, toDo);
        problems[i]->endIteration(adaptInfo);
      }
72
73
74
    }

    return flag;
75
  }
76
77
78
79
80
81
82
83
84


  /// Called after each adaption loop iteration.
  void CouplingIterationInterface::endIteration(AdaptInfo *adaptInfo)
  { FUNCNAME("CouplingIterationInterface::endIteration()");
    MSG("\n");
    MSG("end of iteration number: %d\n", 
      adaptInfo->getTimestepNumber() + 1);
    MSG("==================================================\n");
85
  }
86
87
88
89
90


  /// Returns number of managed problems
  int CouplingIterationInterface::getNumProblems()
  {
91
92
    size_t num= 0;
    for (size_t i = 0; i < problems.size(); ++i)
93
94
      num += problems[i]->getNumProblems();
    return num;
95
  }
96
97
98
99
100
101
102
103


  /** \brief
    * Returns the problem with the given number. If only one problem
    * is managed by this master problem, the number hasn't to be given.
    */
  ProblemStatBase *CouplingIterationInterface::getProblem(int number)
  {
104
105
    size_t maxNum = getNumProblems();
    if (maxNum <= static_cast<size_t>(number))
106
107
      throw(std::runtime_error("Problem number out of range."));
    
108
    size_t sum = 0;
109
    ProblemStatBase *probIter = NULL;
110
111
    for (size_t i = 0; i < problems.size(); ++i) {
      if (sum + problems[i]->getNumProblems() <= static_cast<size_t>(number))
112
113
114
115
116
117
118
        sum += problems[i]->getNumProblems();
      else
        probIter = problems[i]->getProblem(number - sum);
    }
    if (probIter == NULL)
      throw(std::runtime_error("Problem not found. Should not happen, since number is in range."));
    return probIter;
119
  }
120
121
122


  /// Returns the name of the problem.
123
  std::string CouplingIterationInterface::getName(size_t number)
124
  {
125
    if (static_cast<size_t>(problems.size()) <= number)
126
127
128
      throw(std::runtime_error("Problem number out of range."));

    return problems[number]->getName();
129
  }
130

131
132
133
134
135
136
137
138
139

  void CouplingIterationInterface::setSolveProblem(std::string name, bool flag)
  {
    for (size_t i = 0; i < problems.size(); ++i) {
      if (problems[i]->getName() == name) {
        setSolveProblem(i, flag);
        break;
      }
    }
140
  }
141

142
} // namespace AMDiS