Memosa-FVM  0.2
LinearSystemMerger.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _LINEARSYSTEMMERGER_H_
6 #define _LINEARSYSTEMMERGER_H_
7 #ifdef FVM_PARALLEL
8 
9 #include <mpi.h>
10 #include "LinearSystem.h"
11 #include <cassert>
12 #include <set>
13 #include <map>
14 
15 // variable name convection
16 //XXXLocal = this variable is unique to that process and only make sense in its process
17 //XXXGlobl = this variable is meaningful value for all processes (all process has the same value)
18 //XXXX = this variable only make sense in target process
19 
20 class StorageSiteMerger;
21 
22 class LinearSystemMerger
23 {
24 public:
25 
26  typedef shared_ptr< Array<double> > ArrayDblePtr;
27  typedef shared_ptr< Array<int> > ArrayIntPtr;
28  typedef map<int,ArrayIntPtr> ArrayIntPtrMap;
29  friend class LinearSystem;
30 
31  LinearSystemMerger( int target_proc_id, const set<int>& group, LinearSystem& ls );
33 
34 
35  void gatherMatrix();
36  void gatherB();
37  void scatterDelta();
38  shared_ptr< LinearSystem > getLS() { return _mergeLS;}
39 
40  void debug_print();
41 
42  //get methods
43 
44  const map<int, ArrayIntPtr>& getLocalToGlobal() const { return _localToGlobal;}
45  const Array<int>& getGlobalToProc() const { return *_globalToProc;}
46  const Array<int>& getGlobalToLocal() const { return *_globalToLocal;}
47  const Array<int>& getSelfCounts() const { return *_selfCounts;}
48 
49  const map<int, ArrayDblePtr>& getDiag() const { return _diag; }
50  const map<int, ArrayDblePtr>& getOffDiag() const { return _offDiag;}
51  const map< int, ArrayIntPtr >& getLocalConnRow() const { return _row;}
52  const map< int, ArrayIntPtr >& getLocalConnCol() const { return _col;}
53  const vector< map<int,int> >& getGatherIDsLocalToGlobal() const { return _gatherIDsLocalToGlobalMap; } //[proc][localid] = globalID
54 
55  const CRConnectivity& getConnectivity() const { return *_mergeCR;}
56  const MPI::Intracomm& getComm() const { return _comm;}
57  const set<int>& getGroup() const { return _group;}
58 
59 
60 private:
62  void init();
63  void merge();
64  void get_neigh_mesh_counts();
65  void get_scatter_cells();
66  void get_gather_cells();
67  void get_crconnectivity();
68  void get_local_to_global_map();
69  void set_merged_crconnectivity();
70  void update_gatherCells_from_scatterCells();
71  void set_ls_vectors();
72  void update_col();
73 
74 
75  int _targetID;
76  int _groupID;
77  const set<int>& _group;
78  LinearSystem& _ls;
79 
80  shared_ptr<LinearSystem> _mergeLS;
81 
82  int _procID;
83  int _totalProcs;
84  int _totalInterfaces;
85  int _totalScatterCells;
86  int _totalScatterCellsLocal;
87  int _totalGatherCells;
88  int _totalGatherCellsLocal;
89  int _totalCells; //inner cells
90 
91  //mpi buffers
92  ArrayIntPtr _neighMeshCounts; //size = _totalProcs, access : [procid]
93  map<int, ArrayIntPtr> _scatterInterfaceCounts; //size = sum[_neightMeshCouns[procid]], access:[procid][ interface_id ]
94  ArrayIntPtr _scatterSize; //size = _totalProcs
95  vector< map<int, ArrayIntPtr> > _scatterCells; //(proc_id,interface_id) = cells
96  map<int, ArrayIntPtr> _scatterInterfaceIDs; //size = totalInterfaces, access to ids_array [procid]
97 
98  map<int, ArrayIntPtr> _gatherInterfaceCounts;
99  ArrayIntPtr _gatherSize; //size = _totalProcs
100  vector< map<int, ArrayIntPtr> > _gatherCells; //(proc_id,interface_id) = cells
101  map<int,ArrayIntPtr> _gatherInterfaceIDs; //size = totalInterfaces
102  vector< map<int,int> > _gatherIDsLocalToGlobalMap; //[proc][localid] = globalID
103  ArrayIntPtr _selfCounts; //size = totalProcs;
104 
105  ArrayIntPtr _rowLength; //CRConnecivity row_dimension, size = _totalProcs
106  ArrayIntPtr _colLength; //CRConnectivity col_dimension, size = _totalProcs
107  map< int, ArrayIntPtr > _row; //CRConnectivity _row, size = totalCells
108  map< int, ArrayIntPtr > _col; //CRConnectivity _col, size = ??
109  map< int, ArrayIntPtr > _colPos; //return cell position in col array
110  ArrayIntPtr _mergeColPos;
111 
112  map< int, ArrayIntPtr > _localToGlobal; //[procID][localID] = globalID
113  ArrayIntPtr _globalToProc; //[globalID] = procID
114  ArrayIntPtr _globalToLocal; //[globaID] = local id ( _globalToProc and _globalToLocal mostly need to be togethter)
115 
116  map<int, ArrayDblePtr > _diag;
117  map<int, ArrayDblePtr > _offDiag;
118 
119 
120  shared_ptr< StorageSite > _site;
121  shared_ptr< StorageSiteMerger > _siteMerger;
122  shared_ptr< CRConnectivity > _mergeCR;
123 
124 
125  MPI::Intracomm _comm;
126 
127 
128 };
129 
130 
131 #endif
132 #endif
friend class LinearSystemMerger
Definition: LinearSystem.h:15