ParallelDofMapping.h 20.7 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
// ============================================================================
// ==                                                                        ==
// == 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 FeSpaceMapping.h */

23
24
25
26
#ifndef AMDIS_FE_SPACE_MAPPING_H
#define AMDIS_FE_SPACE_MAPPING_H

#include <mpi.h>
27
#include <vector>
28
#include <map>
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
29
#include <set>
30
31
#include <petsc.h>
#include <petscis.h>
32
33
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
34
35

#include "AMDiS_fwd.h"
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
36
#include "parallel/DofComm.h"
37
38
#include "parallel/MpiHelper.h"
#include "parallel/ParallelTypes.h"
39
#include "parallel/StdMpi.h"
40
41

namespace AMDiS {
Thomas Witkowski's avatar
Thomas Witkowski committed
42

43
44
  using namespace std;

45
  /** \brief
46
47
48
   * Is used to store matrix indices to all DOFs in rank's subdomain. Thus, the
   * class defines a mapping from component number and DOF index to a global
   * matrix index. This class does not calculate the indices by itself!
49
50
51
52
53
54
55
56
57
58
59
60
   */
  class DofToMatIndex
  {
  public:
    DofToMatIndex() {}

    /// Reset the data structure.
    inline void clear()
    {
      data.clear();
    }

61
62
63
64
65
66
67
    /** Add a new mapping for a given DOF.
     * 
     * \param[in]   component       Component number for which the mapping 
     *                              is defined.
     * \param[in]   dof             DOF index
     * \param[in]   globalMatIndex  Global matrix index.
     */
68
69
70
71
72
    inline void add(int component, DegreeOfFreedom dof, int globalMatIndex)
    {
      data[component][dof] = globalMatIndex;
    }

73
    /// Maps a global DOF index to the global matrix index for a specific 
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    /// system component number.
    inline int get(int component, DegreeOfFreedom dof)
    {
      FUNCNAME("DofToMatIndex::get()");

      TEST_EXIT_DBG(data.count(component))
	("No mapping data for component %d available!\n", component);

      TEST_EXIT_DBG(data[component].count(dof))
	("Mapping for DOF %d in component %d does not exists!\n",
	 dof, component);

      return data[component][dof];
    }

89
90
91
92
93
    /// Returns for a given matrix index the component and (local or global) DOF
    /// index. As the data structure is not made for this kind of reverse
    /// search, this is very slow and should be only used for debugging.
    void getReverse(int rowIndex, int &component, int &dofIndex);

94
95
96
  private:
    /// The mapping data. For each system component there is a specific map that
    /// maps global DOF indices to global matrix indices.
97
98
    //    map<int, map<DegreeOfFreedom, int> > data;
    map<int, boost::container::flat_map<DegreeOfFreedom, int> > data;
99
100
101
  };


102
103
104
105
106
  /**
   * This class defines the parallel mapping of DOFs for one FE space. It is used
   * by the class \ref ParallelDofMapping to specifiy the mapping for a set of 
   * FE spaces.
   */
107
  class ComponentDofMap
108
109
  {
  public:
110
111
    /// This constructor exists only to create std::map of this class and make
    /// use of the operator [] for read access. Should never be called.
112
    ComponentDofMap() 
113
114
115
    {
      ERROR_EXIT("Should not be called!\n");
    }
116
117
     
    /// This is the only valid constructur to be used. 
118
    ComponentDofMap(MeshLevelData* ld);
119
120

    /// Clears all data of the mapping.
121
    void clear();
122

123
124
    /// Maps a DOF index to both, the local and global index of the mapping. The
    /// global index must not be set.
Thomas Witkowski's avatar
Thomas Witkowski committed
125
    MultiIndex& operator[](DegreeOfFreedom d)
126
    {
127
      TEST_EXIT_DBG(dofMap.count(d))("DOF %d is not in map!\n", d);
128

129
      return dofMap[d];
130
    }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

    /** \brief
     * Searchs the map for a given DOF. It does not fail, if the DOF is not 
     * mapped by this mapping. In this case, it returns false. If the DOF is 
     * mapped, the result is stored and the function returns true.
     *
     * \param[in]    dof     DOF index for which a mapping is searched.
     * \param[out]   index   In the case that the DOF is mapped, the result
     *                       is stored here.
     */
    inline bool find(DegreeOfFreedom dof, MultiIndex& index)
    {
      DofMap::iterator it = dofMap.find(dof);
      if (it == dofMap.end())
	return false;

      index = it->second;
      return true;
    }
150
    
151
152
    /// Inserts a new DOF to rank's mapping. The DOF is assumed to be owend by
    /// the rank.
153
    void insertRankDof(DegreeOfFreedom dof0, DegreeOfFreedom dof1 = -1)
154
    {
155
      FUNCNAME("ComponentDofMap::insertRankDof()");
156
      
157
      TEST_EXIT_DBG(dofMap.count(dof0) == 0)("Should not happen!\n");
158
      
159
160
      dofMap[dof0].local = dof1;
      nLocalDofs++;
Thomas Witkowski's avatar
Thomas Witkowski committed
161
      if (dof1 != -1)
162
	nRankDofs++;
163
164
    }
    
165
166
    /// Inserts a new DOF to rank's mapping. The DOF exists in rank's subdomain
    /// but is owned by a different rank, thus it is part of an interior boundary.
167
    void insertNonRankDof(DegreeOfFreedom dof0, DegreeOfFreedom dof1 = -1)
168
    {
169
      FUNCNAME("ComponentDofMap::insertNonRankDof()");
170
      
171
      TEST_EXIT_DBG(dofMap.count(dof0) == 0)("Should not happen!\n");
172
      
173
174
175
      dofMap[dof0].local = dof1;
      nLocalDofs++;
      nonRankDofs.insert(dof0);
176
177
    }
    
178
    /// Checks if a given DOF is in the DOF mapping.
179
    bool isSet(DegreeOfFreedom dof)
180
    {
181
      return static_cast<bool>(dofMap.count(dof));
182
    }
183

Thomas Witkowski's avatar
Blbu  
Thomas Witkowski committed
184
185
186
    /// Checks if a given DOF is a rank owned DOF of the DOF mapping. The DOF
    /// must be a DOF of the mapping (this is not checked here), otherwise the
    /// result is meaningsless.
187
    bool isRankDof(DegreeOfFreedom dof)
188
    {
189
      return !(static_cast<bool>(nonRankDofs.count(dof)));
190
    }
Thomas Witkowski's avatar
Blbu  
Thomas Witkowski committed
191
192
193
194
195

    bool isRankGlobalDof(int dof)
    {
      return (dof >= rStartDofs && dof < rStartDofs + nRankDofs);
    }
196
    
197
    /// Returns number of DOFs in the mapping.
198
    unsigned int size()
199
    {
200
      return dofMap.size();
201
202
    }
    
203
    /// Returns the raw data of the mapping.
204
    DofMap& getMap()
205
    {
206
      return dofMap;
207
    }
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
208

209
210
211
212
213
214
215
216
217
218
    DofMap::iterator begin()
    {
      return dofMap.begin();
    }

    DofMap::iterator end()
    {
      return dofMap.end();
    }

219
220
    /// Recomputes the mapping.
    void update();
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
221

222
    /// Sets the FE space this mapping corresponds to.
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
223
224
225
226
227
    void setFeSpace(const FiniteElemSpace *fe)
    {
      feSpace = fe;
    }

228
229
    /// Informs the mapping whether the mapping will include DOFs that are not
    /// owned by the rank.
230
    void setNonLocal(bool b)
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
231
    {
232
      isNonLocal = b;
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
233
234
    }

235
    /// Informs the mapping whether a global index must be computed.
236
    void setNeedGlobalMapping(bool b)
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
237
    {
238
      needGlobalMapping = b;
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
239
240
    }

241
    /// Sets the DOF communicator.
242
    void setDofComm(DofComm &dc)
Thomas Witkowski's avatar
Thomas Witkowski committed
243
    {
244
      dofComm = &dc;
Thomas Witkowski's avatar
Thomas Witkowski committed
245
246
    }

247
248
249
250
251
252
    void setMpiComm(MPI::Intracomm &m, int l)
    {
      mpiComm = m;
      meshLevel = l;
    }

253
  private:
254
    /// Computes a global mapping from the local one.
255
    void computeGlobalMapping();
256
257
258

    /// Computes the global indices of all DOFs in the mapping that are not owned
    /// by the rank.
259
    void computeNonLocalIndices();
260
261

  private:
262
    MeshLevelData *levelData;
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
263

264
265
    /// DOF communicator for all DOFs on interior boundaries.
    DofComm *dofComm;
266

267
268
269
270
    MPI::Intracomm mpiComm;

    int meshLevel;

271
    /// The FE space this mapping belongs to. This is used only the get the
272
    /// correct DOF communicator in \ref dofComm.
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
273
274
    const FiniteElemSpace *feSpace;

275
    /// Mapping data from DOF indices to local and global indices.
276
    DofMap dofMap;
277

278
    /// Set of all DOFs that are in mapping but are not owned by the rank.
279
    boost::container::flat_set<DegreeOfFreedom> nonRankDofs;
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
280

281
    /// If true, a global index mapping will be computed for all DOFs.
Thomas Witkowski's avatar
Thomas Witkowski committed
282
    bool needGlobalMapping;
Thomas Witkowski's avatar
FETI-DP  
Thomas Witkowski committed
283

284
285
286
    /// Is true if there are DOFs in at least one subdomain that are not owned
    /// by the rank. If the value is false, each rank contains only DOFs that
    /// are also owned by this rank.
287
    bool isNonLocal;
288

289
290
  public:
    /// 
291
    int nRankDofs, nLocalDofs, nOverallDofs, rStartDofs;
292
  };
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

  class ComponentIterator {
  public:
    virtual ComponentDofMap& operator*() = 0;

    virtual bool end() = 0;
    
    virtual void next() = 0;

    virtual void reset() = 0;
  };

  class ComponentDataInterface
  {
  public:
    virtual ComponentDofMap& operator[](int compNumber) = 0;

    virtual ComponentDofMap& operator[](const FiniteElemSpace *feSpace) = 0;

    virtual bool isDefinedFor(int compNumber) const = 0;

    virtual ComponentIterator& getIteratorData() = 0;
    
    virtual ComponentIterator& getIteratorComponent() = 0;

    virtual void init(vector<const FiniteElemSpace*> &f0,
		      vector<const FiniteElemSpace*> &f1,
		      bool isNonLocal) = 0;

  protected:
    /// The FE spaces for all components.
    vector<const FiniteElemSpace*> feSpaces;

    /// The set of all FE spaces. It uniquly contains all different FE spaces
    /// from \ref feSpaces.
    vector<const FiniteElemSpace*> feSpacesUnique;
  };


  class ComponentDataEqFeSpace : ComponentDataInterface
  {
  public:
    ComponentDofMap& operator[](int compNumber)
    {
      const FiniteElemSpace *feSpace = feSpaces[compNumber];
      return componentData.find(feSpace)->second;
    }

    ComponentDofMap& operator[](const FiniteElemSpace *feSpace)
    {
      TEST_EXIT_DBG(componentData.count(feSpace))("No data for FE space!\n");;
      
      return componentData.find(feSpace)->second;
    }

    bool isDefinedFor(int compNumber) const
    {
      const FiniteElemSpace *feSpace = feSpaces[compNumber];
      return static_cast<bool>(componentData.count(feSpace));
    }

    ComponentIterator& getIteratorData()
    {
      iterData.reset();
      return iterData;
    }
    
    ComponentIterator& getIteratorComponent()
    {
      iterComponent.reset();
      return iterComponent;
    }

    void init(vector<const FiniteElemSpace*> &f0,
	      vector<const FiniteElemSpace*> &f1,
	      bool isNonLocal)
    {
    // === Init the mapping for all different FE spaces. ===

    // for (vector<const FiniteElemSpace*>::iterator it = feSpacesUnique.begin();
    // 	 it != feSpacesUnique.end(); ++it) {
    //   addFeSpace(*it);
    //   data[*it].setNeedGlobalMapping(isNonLocal);
    //   data[*it].setNonLocal(isNonLocal);
    // }

  // void ParallelDofMapping::addFeSpace(const FiniteElemSpace* feSpace)
  // {
  //   FUNCNAME("ParallelDofMapping::addFeSpace()");
    
  //   if (data.count(feSpace))
  //     data.find(feSpace)->second.clear();
  //   else
  //     data.insert(make_pair(feSpace, ComponentDofMap(levelData)));
    
  //   data.find(feSpace)->second.setFeSpace(feSpace);
  // }    

    }


  protected:
    class IteratorData : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }

      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    class IteratorComponent : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }
      
      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };
    

    map<const FiniteElemSpace*, ComponentDofMap> componentData;

    IteratorData iterData;

    IteratorComponent iterComponent;
  };


  class ComponentDataDiffFeSpace : ComponentDataInterface
  {
  public:
    ComponentDofMap& operator[](int compNumber)
    {
      TEST_EXIT_DBG(componentData.count(compNumber))("No data for component %d!\n", compNumber);

      return componentData.find(compNumber)->second;
    }

    ComponentDofMap& operator[](const FiniteElemSpace *feSpace)
    {
      ERROR_EXIT("BLUB\n");
    }
    
    ComponentIterator& getIteratorData()
    {
      iterData.reset();
      return iterData;
    }
    
    ComponentIterator& getIteratorComponent()
    {
      iterComponent.reset();
      return iterComponent;
    }

    bool isDefinedFor(int compNumber) const
    {
      return (static_cast<unsigned int>(compNumber) < componentData.size());
    }

  protected:
    class IteratorData : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }

      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    class IteratorComponent : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }
      
      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    map<unsigned int, ComponentDofMap> componentData;

    IteratorData iterData;

    IteratorComponent iterComponent;
  };


521
522
523
524
525
  /**
   * Implements the mapping from sets of distributed DOF indices to local and
   * global indices. The mapping works for a given set of FE spaces. Furthermore,
   * this class may compute the matrix indices of the set of DOF indices.
   */
Thomas Witkowski's avatar
Thomas Witkowski committed
526
  class ParallelDofMapping
527
528
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
529
    ParallelDofMapping() 
530
      : levelData(NULL),
531
	dofComm(NULL),
532
	isNonLocal(true),
533
	needMatIndexFromGlobal(false),
534
535
536
537
538
	nRankDofs(1),
	nLocalDofs(1),
	nOverallDofs(1),
	rStartDofs(1)
    {
539
540
541
542
      nRankDofs = -1;
      nLocalDofs = -1;
      nOverallDofs = -1;
      rStartDofs = -1;
543
    } 
544

545
546
547
548
    /** \brief Initialize the parallel DOF mapping.
     *
     * \param[in]  m                  MPI communicator.
     * \param[in]  fe                 The FE spaces of all components of the 
549
550
551
552
     *                                PDE to be solved.
     * \param[in]  uniqueFe           Unique list of FE spaces. Thus, two
     *                                arbitrary elements of this list are always
     *                                different.
553
     * \param[in]  isNonLocal         If true, at least one rank's mapping con-
554
555
     *                                taines DOFs that are not owend by the rank.
     */
556
    void init(MeshLevelData& mld,
557
	      vector<const FiniteElemSpace*> &fe,
558
	      vector<const FiniteElemSpace*> &uniqueFe,
559
560
561
562
563
564
565
566
567
568
569
570
	      bool isNonLocal = true);

    /// In the case of having only one FE space, this init function can be used.
    void init(MeshLevelData& mld,
	      const FiniteElemSpace *feSpace,
	      bool isNonLocal = true)
    {
      vector<const FiniteElemSpace*> feSpaces;
      feSpaces.push_back(feSpace);
      init(mld, feSpaces, feSpaces, isNonLocal);
    }

571
    void setMpiComm(MPI::Intracomm &m, int l);
572
573
574
    
    /// Clear all data.
    void clear();
575
576
577

    /// Set the DOF communicator objects that are required to exchange information
    /// about DOFs that are on interior boundaries.
578
    void setDofComm(DofComm &dofComm);
579

580
581
582
    /// Returns the DOF communicator.
    DofComm& getDofComm()
    {
583
584
585
      FUNCNAME("ParallelDofMapping::getDofComm()");

      TEST_EXIT_DBG(dofComm)("No DOF communicator object defined!\n");
586
587
588
589

      return *dofComm;
    }

590
591
592
    /// Changes the computation of matrix indices based of either local or
    /// global DOF indices, see \ref needMatIndexFromGlobal
    void setComputeMatIndex(bool global)
593
594
595
596
    {
      needMatIndexFromGlobal = global;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
597
598
599
600
601
    inline bool isMatIndexFromGlobal()
    {
      return needMatIndexFromGlobal;
    }

602

603
604
605
606
    /// Access the DOF mapping for a given component number.
    inline ComponentDofMap& operator[](int compNumber)
    {
      return (*data)[compNumber];
607
608
    }

609
610
    /// Access the DOF mapping for a given FE space    
    inline ComponentDofMap& operator[](const FiniteElemSpace *feSpace) 
Thomas Witkowski's avatar
Thomas Witkowski committed
611
    {
612
      return (*data)[feSpace];
Thomas Witkowski's avatar
Thomas Witkowski committed
613
614
    }

615
    inline bool isDefinedFor(int compNumber) const
Thomas Witkowski's avatar
Thomas Witkowski committed
616
    {
617
      return data->isDefinedFor(compNumber);
Thomas Witkowski's avatar
Thomas Witkowski committed
618
619
    }

620
621
622
623
624
625
626
    /// Returns the number of solution components the mapping is defined on.
    // inline int getNumberOfComponents() const
    // {
    //   ERROR_EXIT("WRITE SOMETHING MEANINGFUL!\n");
    //   //      return static_cast<int>(feSpaces.size());
    // }

627
    /// Returns \ref nRankDofs, thus the number of DOFs owned by the rank.
628
    inline int getRankDofs()
629
    {
630
      TEST_EXIT_DBG(nRankDofs >= 0)("Should not happen!\n");
631

632
      return nRankDofs;
633
634
    }

635
    /// Returns \ref nLocalDofs, thus the number of DOFs in ranks subdomain.
636
    inline int getLocalDofs()
Thomas Witkowski's avatar
Thomas Witkowski committed
637
    {
638
      TEST_EXIT_DBG(nLocalDofs >= 0)("Should not happen!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
639

640
      return nLocalDofs;
Thomas Witkowski's avatar
Thomas Witkowski committed
641
642
    }

643
    /// Returns \ref nOverallDofs, thus the number of all DOFs in this mapping.
644
    inline int getOverallDofs()
645
    {
646
      TEST_EXIT_DBG(nOverallDofs >= 0)("Should not happen!\n");
647

648
      return nOverallDofs;
649
650
    }

651
652
    /// Returns \ref rStartDofs, thus the smallest global index of a DOF that is
    /// owned by the rank.
653
    inline int getStartDofs()
654
    {
655
      TEST_EXIT_DBG(rStartDofs >= 0)("Should not happen!\n");
656

657
      return rStartDofs;
658
659
    }

660
    /// Update the mapping.
Thomas Witkowski's avatar
Thomas Witkowski committed
661
    void update();
662

663
664
665
    /// Update the mapping.
    void update(vector<const FiniteElemSpace*>& feSpaces);

666
667
    /// Returns the global matrix index of a given DOF for a given 
    /// component number.
668
    inline int getMatIndex(int ithComponent, DegreeOfFreedom d)
Thomas Witkowski's avatar
Thomas Witkowski committed
669
    {
670
      return dofToMatIndex.get(ithComponent, d);
Thomas Witkowski's avatar
Thomas Witkowski committed
671
672
    }

673
674
675
676
677
678
679
    /// Returns the component number and local/global DOF index for a given
    /// matrix row index. Should be used for debugging only!
    inline void getReverseMatIndex(int index, int &component, int &dofIndex)
    {
      dofToMatIndex.getReverse(index, component, dofIndex);
    }

680
681
    /// Returns the local matrix index of a given DOF for a given 
    /// component number.
682
    inline int getLocalMatIndex(int ithComponent, DegreeOfFreedom d)
683
    {
684
      return dofToMatIndex.get(ithComponent, d) - rStartDofs;
685
686
    }

687
688
689
690
691
    // inline const FiniteElemSpace* getFeSpace(int i = 0)
    // {      
    //   TEST_EXIT_DBG(i < feSpacesUnique.size())("Wrong component number!\n");
    //   return feSpacesUnique[i];
    // }
Thomas Witkowski's avatar
Thomas Witkowski committed
692

Thomas Witkowski's avatar
Thomas Witkowski committed
693
694
695
696
697
698
699
700
701
702
703
704
    // Writes all data of this object to an output stream.
    void serialize(ostream &out)
    {
      ERROR_EXIT("MUST BE IMPLEMENTED!\n");
    }

    // Reads the object data from an input stream.
    void deserialize(istream &in)
    {
      ERROR_EXIT("MUST BE IMPLEMENTED!\n");
    }

705
    /// Compute local and global matrix indices.
706
    void computeMatIndex(bool globalIndex);
707

708
709
710
711
    void createIndexSet(IS &is, 
			int firstComponent, 
			int nComponents);

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
    /// Create a parallel distributed PETSc vector based on this mapping.
    inline void createVec(Vec &vec)
    {
      VecCreateMPI(mpiComm, getRankDofs(), getOverallDofs(), &vec);
    }

    /// Create a parallel distributed PETsc vector based on this mapping but
    /// with a different (larger) global size. This is used in multi-level 
    /// method to embed a local vector into a subdomain spaned by several
    /// ranks.
    inline void createVec(Vec &vec, int nGlobalRows)
    {
      VecCreateMPI(mpiComm, getRankDofs(), nGlobalRows, &vec);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
727
728
729
730
731
    inline void createLocalVec(Vec &vec)
    {
      VecCreateSeq(PETSC_COMM_SELF, getRankDofs(), &vec);
    }

732
733
  protected:
    /// Compute \ref nRankDofs.
734
    int computeRankDofs();
735
736

    /// Compute \ref nLocalDofs.
737
    int computeLocalDofs();
738
739

    /// Compute \ref nOverallDofs.
740
    int computeOverallDofs();
741
742

    /// Compute \ref rStartDofs.
743
    int computeStartDofs();
744

745
  private:
746
747
748
749
    MPI::Intracomm mpiComm;

    int meshLevel;

750
    MeshLevelData *levelData;
751

752
753
    /// DOF communicator for all DOFs on interior boundaries.
    DofComm *dofComm;
754

755
756
757
    /// Is true if there are DOFs in at least one subdomain that are not owned
    /// by the rank. If the value is false, each rank contains only DOFs that
    /// are also owned by this rank.
758
    bool isNonLocal;
759
760
761
762
763

    /// If matrix indices should be computed, this variable defines if the
    /// mapping from DOF indices to matrix row indices is defined on local
    /// or global DOF indices. If true, the mapping is to specify and to use
    /// on global ones, otherwise on local DOF indices.
Thomas Witkowski's avatar
Thomas Witkowski committed
764
765
766
767
768
    /// In most scenarios the mapping stored on local DOF indices is what we
    /// want to have. Only when periodic boundary conditions are used together
    /// with some global matrix approache, the matrix indices must be stored
    /// also for DOFs that are not part of the local subdomain. Thus, the
    /// mapping will be stored on global DOF indices.
769
770
    bool needMatIndexFromGlobal;

771
772
    /// Maps from components to DOF mappings.
    ComponentDataInterface *data;
Thomas Witkowski's avatar
Thomas Witkowski committed
773

774
    /// Number of DOFs owned by rank.
775
    int nRankDofs;
776
777

    /// Number of DOFs in rank's subdomain.
778
    int nLocalDofs;
779
780

    /// Number of global DOFs (this value is thus the same on all ranks).
781
    int nOverallDofs;
782
783

    /// Smallest global index of a DOF owned by the rank.
784
    int rStartDofs;
785
786
787

    /// Mapping from global DOF indices to global matrix indices under 
    /// consideration of possibly multiple components.
788
    DofToMatIndex dofToMatIndex;
789
790
791
792
  };
}

#endif