ParallelDofMapping.h 21 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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
298
299
    virtual ComponentDofMap* operator->() = 0;

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    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;

Thomas Witkowski's avatar
Thomas Witkowski committed
324
325
326
327
328
    vector<const FiniteElemSpace*>& getFeSpaces()
    {
      return feSpaces;
    }

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
  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*()
      {
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
408
409
410
411
      ComponentDofMap* operator->()
      {
      }

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    class IteratorComponent : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
430
431
432
433
434

      ComponentDofMap* operator->()
      {
      }

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
      
      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*()
      {
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
497
498
499
500
501
      ComponentDofMap* operator->()
      {
      }


502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    class IteratorComponent : public ComponentIterator {
    public:
      ComponentDofMap& operator*()
      {
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
520
521
522
523
524

      ComponentDofMap* operator->()
      {
      }

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      
      bool end()
      {
      }

      void next()
      {
      }

      void reset()
      {
      }
    };

    map<unsigned int, ComponentDofMap> componentData;

    IteratorData iterData;

    IteratorComponent iterComponent;
  };


547
548
549
550
551
  /**
   * 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
552
  class ParallelDofMapping
553
554
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
555
    ParallelDofMapping() 
556
      : levelData(NULL),
557
	dofComm(NULL),
558
	isNonLocal(true),
559
	needMatIndexFromGlobal(false),
560
561
562
563
564
	nRankDofs(1),
	nLocalDofs(1),
	nOverallDofs(1),
	rStartDofs(1)
    {
565
566
567
568
      nRankDofs = -1;
      nLocalDofs = -1;
      nOverallDofs = -1;
      rStartDofs = -1;
569
    } 
570

571
572
573
574
    /** \brief Initialize the parallel DOF mapping.
     *
     * \param[in]  m                  MPI communicator.
     * \param[in]  fe                 The FE spaces of all components of the 
575
576
577
578
     *                                PDE to be solved.
     * \param[in]  uniqueFe           Unique list of FE spaces. Thus, two
     *                                arbitrary elements of this list are always
     *                                different.
579
     * \param[in]  isNonLocal         If true, at least one rank's mapping con-
580
581
     *                                taines DOFs that are not owend by the rank.
     */
582
    void init(MeshLevelData& mld,
583
	      vector<const FiniteElemSpace*> &fe,
584
	      vector<const FiniteElemSpace*> &uniqueFe,
585
586
587
588
589
590
591
592
593
594
595
596
	      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);
    }

597
    void setMpiComm(MPI::Intracomm &m, int l);
598
599
600
    
    /// Clear all data.
    void clear();
601
602
603

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

606
607
608
    /// Returns the DOF communicator.
    DofComm& getDofComm()
    {
609
610
611
      FUNCNAME("ParallelDofMapping::getDofComm()");

      TEST_EXIT_DBG(dofComm)("No DOF communicator object defined!\n");
612
613
614
615

      return *dofComm;
    }

616
617
618
    /// Changes the computation of matrix indices based of either local or
    /// global DOF indices, see \ref needMatIndexFromGlobal
    void setComputeMatIndex(bool global)
619
620
621
622
    {
      needMatIndexFromGlobal = global;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
623
624
625
626
627
    inline bool isMatIndexFromGlobal()
    {
      return needMatIndexFromGlobal;
    }

628

629
630
631
632
    /// Access the DOF mapping for a given component number.
    inline ComponentDofMap& operator[](int compNumber)
    {
      return (*data)[compNumber];
633
634
    }

635
636
    /// Access the DOF mapping for a given FE space    
    inline ComponentDofMap& operator[](const FiniteElemSpace *feSpace) 
Thomas Witkowski's avatar
Thomas Witkowski committed
637
    {
638
      return (*data)[feSpace];
Thomas Witkowski's avatar
Thomas Witkowski committed
639
640
    }

641
    inline bool isDefinedFor(int compNumber) const
Thomas Witkowski's avatar
Thomas Witkowski committed
642
    {
643
      return data->isDefinedFor(compNumber);
Thomas Witkowski's avatar
Thomas Witkowski committed
644
645
    }

646
    /// Returns the number of solution components the mapping is defined on.
Thomas Witkowski's avatar
Thomas Witkowski committed
647
648
649
650
    inline int getNumberOfComponents() const
    {      
      return static_cast<int>(data->getFeSpaces().size());
    }
651

652
    /// Returns \ref nRankDofs, thus the number of DOFs owned by the rank.
653
    inline int getRankDofs()
654
    {
655
      TEST_EXIT_DBG(nRankDofs >= 0)("Should not happen!\n");
656

657
      return nRankDofs;
658
659
    }

660
    /// Returns \ref nLocalDofs, thus the number of DOFs in ranks subdomain.
661
    inline int getLocalDofs()
Thomas Witkowski's avatar
Thomas Witkowski committed
662
    {
663
      TEST_EXIT_DBG(nLocalDofs >= 0)("Should not happen!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
664

665
      return nLocalDofs;
Thomas Witkowski's avatar
Thomas Witkowski committed
666
667
    }

668
    /// Returns \ref nOverallDofs, thus the number of all DOFs in this mapping.
669
    inline int getOverallDofs()
670
    {
671
      TEST_EXIT_DBG(nOverallDofs >= 0)("Should not happen!\n");
672

673
      return nOverallDofs;
674
675
    }

676
677
    /// Returns \ref rStartDofs, thus the smallest global index of a DOF that is
    /// owned by the rank.
678
    inline int getStartDofs()
679
    {
680
      TEST_EXIT_DBG(rStartDofs >= 0)("Should not happen!\n");
681

682
      return rStartDofs;
683
684
    }

685
    /// Update the mapping.
Thomas Witkowski's avatar
Thomas Witkowski committed
686
    void update();
687

688
689
690
    /// Update the mapping.
    void update(vector<const FiniteElemSpace*>& feSpaces);

691
692
    /// Returns the global matrix index of a given DOF for a given 
    /// component number.
693
    inline int getMatIndex(int ithComponent, DegreeOfFreedom d)
Thomas Witkowski's avatar
Thomas Witkowski committed
694
    {
695
      return dofToMatIndex.get(ithComponent, d);
Thomas Witkowski's avatar
Thomas Witkowski committed
696
697
    }

698
699
700
701
702
703
704
    /// 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);
    }

705
706
    /// Returns the local matrix index of a given DOF for a given 
    /// component number.
707
    inline int getLocalMatIndex(int ithComponent, DegreeOfFreedom d)
708
    {
709
      return dofToMatIndex.get(ithComponent, d) - rStartDofs;
710
711
    }

712
713
714
715
716
    // 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
717

Thomas Witkowski's avatar
Thomas Witkowski committed
718
719
720
721
722
723
724
725
726
727
728
729
    // 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");
    }

730
    /// Compute local and global matrix indices.
731
    void computeMatIndex(bool globalIndex);
732

733
734
735
736
    void createIndexSet(IS &is, 
			int firstComponent, 
			int nComponents);

737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
    /// 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
752
753
754
755
756
    inline void createLocalVec(Vec &vec)
    {
      VecCreateSeq(PETSC_COMM_SELF, getRankDofs(), &vec);
    }

757
758
  protected:
    /// Compute \ref nRankDofs.
759
    int computeRankDofs();
760
761

    /// Compute \ref nLocalDofs.
762
    int computeLocalDofs();
763
764

    /// Compute \ref nOverallDofs.
765
    int computeOverallDofs();
766
767

    /// Compute \ref rStartDofs.
768
    int computeStartDofs();
769

770
  private:
771
772
773
774
    MPI::Intracomm mpiComm;

    int meshLevel;

775
    MeshLevelData *levelData;
776

777
778
    /// DOF communicator for all DOFs on interior boundaries.
    DofComm *dofComm;
779

780
781
782
    /// 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.
783
    bool isNonLocal;
784
785
786
787
788

    /// 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
789
790
791
792
793
    /// 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.
794
795
    bool needMatIndexFromGlobal;

796
797
    /// Maps from components to DOF mappings.
    ComponentDataInterface *data;
Thomas Witkowski's avatar
Thomas Witkowski committed
798

799
    /// Number of DOFs owned by rank.
800
    int nRankDofs;
801
802

    /// Number of DOFs in rank's subdomain.
803
    int nLocalDofs;
804
805

    /// Number of global DOFs (this value is thus the same on all ranks).
806
    int nOverallDofs;
807
808

    /// Smallest global index of a DOF owned by the rank.
809
    int rStartDofs;
810
811
812

    /// Mapping from global DOF indices to global matrix indices under 
    /// consideration of possibly multiple components.
813
    DofToMatIndex dofToMatIndex;
814
815
816
817
  };
}

#endif