CouplingProblemStat.h 8.28 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// ============================================================================
// ==                                                                        ==
// == 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 CouplingProblemStat.h */

#ifndef AMDIS_COUPLING_PROBLEM_STAT_H
#define AMDIS_COUPLING_PROBLEM_STAT_H

#include <vector>
#include <set>
#include <list>
#include "AMDiS_fwd.h"
#include "ProblemStat.h"
#include "Initfile.h"
#include <boost/lexical_cast.hpp>

namespace AMDiS {

  using namespace std;


  /** \brief
   * This class defines a coupled stationary problem definition in sequential
   * computations. 
   */
  class CouplingProblemStat
  {
  public:
    /// Constructor
    CouplingProblemStat(std::string name_)
      : name(name_),
        nComponents(0),
        nMeshes(0),
        refinementManager(NULL),
        coarseningManager(NULL)
    {}

    /// Destructor
    virtual ~CouplingProblemStat() {}

    /// add problem by number
    virtual void addProblem(ProblemStat* prob)
    {
      problems.push_back(prob);
    };

    /// Initialisation of the problem.
    virtual void initialize(Flag initFlag,
                            CouplingProblemStat *adoptProblem = NULL,
                            Flag adoptFlag = INIT_NOTHING)
    {

      // create one refinement-/coarseningmanager for all problems
      if (refinementManager != NULL && coarseningManager != NULL) { 
        WARNING("refinement-/coarseningmanager already created\n");
      } else {
        if (!adoptProblem)
          createRefCoarseManager();
        else {
          refinementManager = adoptProblem->refinementManager;
          coarseningManager = adoptProblem->coarseningManager;
        }
      }
  
      if (refinementManager == NULL || coarseningManager == NULL) 
        WARNING("no refinement-/coarseningmanager created\n");

      // create Meshes and FeSpaces

      // one global macro-mesh for all problems
      string meshName("");
      Parameters::get(name + "->mesh", meshName);
      TEST_EXIT(meshName != "")("No mesh name specified for \"%s->mesh\"!\n", 
                                name.c_str());

      // all problems must have the same dimension (?)
      int dim = 0;
      Parameters::get(name + "->dim", dim);
      TEST_EXIT(dim)("No problem dimension specified for \"%s->dim\"!\n",
                    name.c_str());

      map<int, Mesh*> meshForRefinementSet;
      vector< std::set<Mesh*> > meshesForProblems(problems.size());
      map<pair<Mesh*, int>, FiniteElemSpace*> feSpaceMap;
      for (size_t i = 0; i < problems.size(); ++i) {
        TEST_EXIT(problems[i])("problem[%d] does not exist!\n",i);
        nComponents += problems[i]->getNumComponents();
        for (size_t j = 0; j < problems[i]->getNumComponents(); j++) {
          // mesh
          int refSet = -1;
          Parameters::get(problems[i]->getName() + "->" +
                          "refinement set[" + boost::lexical_cast<string>(j) + "]", 
                          refSet);
          if (refSet < 0)
            refSet = 0;
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
          if (meshForRefinementSet.find(refSet) == meshForRefinementSet.end()) {
            Mesh *newMesh = new Mesh(meshName, dim);
            meshForRefinementSet[refSet] = newMesh;
            meshes.push_back(newMesh);
            meshesForProblems[i].insert(newMesh);
            nMeshes++;
          } else
            meshesForProblems[i].insert(meshForRefinementSet[refSet]);

          problems[i]->setComponentMesh(j, meshForRefinementSet[refSet]);
            
          // feSpace
          int degree = 1;
          Parameters::get(problems[i]->getName() + "->polynomial degree[" + 
                          boost::lexical_cast<string>(j) + "]", degree);
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
          if (feSpaceMap[pair<Mesh*, int>(meshForRefinementSet[refSet], degree)] == NULL) {
            stringstream s;
            s << problems[i]->getName() << "->feSpace[" << j << "]";
    
            FiniteElemSpace *newFeSpace = 
              FiniteElemSpace::provideFeSpace(NULL, Lagrange::getLagrange(dim, degree),
                                              meshForRefinementSet[refSet], s.str());
            feSpaceMap[pair<Mesh*, int>(meshForRefinementSet[refSet], degree)] = newFeSpace;
            feSpaces.push_back(newFeSpace);
          }
    
//           problems[i].setComponentSpace(i, feSpaceMap[pair<Mesh*, int>(meshForRefinementSet[refSet], degree)]);
        }
      }

      for (size_t i = 0; i < problems.size(); ++i) {
        vector<Mesh*> problemMeshes(meshesForProblems[i].begin(), meshesForProblems[i].end());
        problems[i]->setMeshes(problemMeshes);
        problems[i]->setRefinementManager(refinementManager);
        problems[i]->setCoarseningManager(coarseningManager);
        problems[i]->initialize(INIT_ALL);
      }
    }

    void 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());

      switch (dim) {
      case 1:
        coarseningManager = new CoarseningManager1d();
        refinementManager = new RefinementManager1d();
        break;
      case 2:
        coarseningManager = new CoarseningManager2d();
        refinementManager = new RefinementManager2d();
        break;
      case 3:
        coarseningManager = new CoarseningManager3d();
        refinementManager = new RefinementManager3d();
        break;
      default:
        ERROR_EXIT("invalid dim!\n");
      }
    }

    /// Returns number of managed problems
    virtual int getNumProblems() 
    { 
      return problems.size(); 
    }

    /// Implementation of ProblemStatBase::getNumComponents()
    virtual int getNumComponents() 
    { 
      return nComponents; 
    }

    /** \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.
     */
    virtual ProblemStat *getProblem(int number = 0) 
    { 
      return problems[number]; 
    }

    /// Returns \ref meshes[i]
    inline Mesh* getMesh(int number = 0) 
    {
      return meshes[number]; 
    }

    /// Returns \ref meshes
    inline vector<Mesh*> getMeshes() 
    {
      return meshes; 
    }

    /// Returns \ref refinementManager.
    inline RefinementManager* getRefinementManager(int comp = 0) 
    { 
      return refinementManager; 
    }

    /// Returns \ref refinementManager.
    inline CoarseningManager* getCoarseningManager(int comp = 0) 
    { 
      return coarseningManager; 
    }

    /// Returns the name of the problem
    inline virtual string getName() 
    { 
      return name; 
    }

  protected:
    
    /// Name of this problem.
    string name;

    /// Number of problem components
    int nComponents;

    /** \brief
     * Number of problem meshes. If all components are defined on the same mesh,
     * this number is 1. Otherwise, this variable is the number of different meshes
     * within the problem.
     */
    int nMeshes;

    /// FE spaces of this problem.
    vector<FiniteElemSpace*> feSpaces;

    /// Meshes of this problem.
    vector<Mesh*> meshes;

    /** \brief
     * All actions of mesh refinement are performed by refinementManager.
     * If new refinement algorithms should be realized, one has to override
     * RefinementManager and give one instance of it to AdaptStationary.
     */
    RefinementManager *refinementManager;

    /** \brief
     * All actions of mesh coarsening are performed by coarseningManager.
     * If new coarsening algorithms should be realized, one has to override
     * CoarseningManager and give one instance of it to AdaptStationary.
     */
    CoarseningManager *coarseningManager;

    vector<ProblemStat*> problems;
  };
}

#endif