Flow123d  release_2.2.0-19-g1279b7e
mh_dofhandler.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file mh_dofhandler.hh
15  * @brief
16  */
17 
18 #ifndef MH_DOFHANDLER_HH_
19 #define MH_DOFHANDLER_HH_
20 
21 #include <vector>
22 #include <memory>
23 #include <unordered_map>
24 
25 #include "mesh/mesh_types.hh"
26 #include "mesh/accessors.hh"
27 #include "mesh/sides.h"
28 #include "mesh/region.hh"
29 
30 #include "la/distribution.hh"
32 
33 using namespace std;
34 
35 class Mesh;
36 class Side;
37 class SideIter;
38 class MH_DofHandler;
39 
40 template <int spacedim>
42 
43 /// temporary solution to provide access to results
44 /// from DarcyFlowMH independent of mesh
46 public:
47  MH_DofHandler();
48  ~MH_DofHandler();
49  void reinit(Mesh *mesh);
50 
51  void prepare_parallel();
52  void make_row_numberings();
53  void prepare_parallel_bddc();
54 
55  void set_solution( double time, double * solution, double precision);
56 
57  inline double time_changed() const
58  { return time_; }
59 
60  unsigned int side_dof(const SideIter side) const;
61 
62  /// temporary replacement for DofHandler accessor, flux through given side
63  double side_flux(const Side &side) const;
64 
65  /// temporary replacement for DofHandler accessor, scalar (pressure) on edge of the side
66  double side_scalar(const Side &side) const;
67 
68  /// temporary replacement for DofHandler accessor, scalar (pressure) on element
69  double element_scalar( ElementFullIter &ele ) const;
70 
71  inline double precision() const { return solution_precision; };
72 
73  LocalElementAccessorBase<3> accessor(uint local_ele_idx);
74 
75 //protected:
77 
79  int *el_4_loc; //< array of idexes of local elements (in ordering matching the optimal global)
80  int *row_4_el; //< element index to matrix row
81  int *side_id_4_loc; //< array of ids of local sides
82  int *side_row_4_id; //< side id to matrix row
83  int *edge_4_loc; //< array of indexes of local edges
84  int *row_4_edge; //< edge index to matrix row
85 
86  // parallel
87  Distribution *edge_ds; //< optimal distribution of edges
88  Distribution *el_ds; //< optimal distribution of elements
89  Distribution *side_ds; //< optimal distribution of elements
90  std::shared_ptr<Distribution> rows_ds; //< final distribution of rows of MH matrix
91 
92 
93  /// Maps mesh index of the edge to the edge index in the mesh portion local to the processor.
94  /// Temporary solution until we have parallel mesh which should provide such information.
95  std::unordered_map<unsigned int, unsigned int> edge_new_local_4_mesh_idx_;
96 
97  /// Necessary only for BDDC solver.
98  std::shared_ptr<LocalToGlobalMap> global_row_4_sub_row; //< global dof index for subdomain index
99 
100 
101  double * mh_solution;
103  double time_;
104 
106 };
107 
108 
109 
110 typedef unsigned int uint;
111 
112 template <int spacedim>
114 public:
116  : dh(dh), local_ele_idx_(loc_ele_idx), ele(dh->mesh_->element(ele_global_idx()))
117  {}
118 
119  uint dim() {
120  return ele->dim();
121  }
122 
124  return ele->n_sides();
125  }
126 
128  return ele;
129  }
130 
132  return ele->element_accessor();
133  }
134 
135  const arma::vec3 centre() const {
136  return ele->centre();
137  }
138 
139  double measure() const {
140  return ele->measure();
141  }
142 
143  Region region() const {
144  return ele->region();
145  }
146 
148  return dh->el_4_loc[local_ele_idx_];
149  }
150 
152  return local_ele_idx_;
153  }
154 
156  return dh->row_4_el[ele_global_idx()];
157  }
158 
160  return ele_row() - dh->rows_ds->begin(); // i_loc_el + side_ds->lsize();
161  }
162 
164  return ele->side(i)->edge_idx();
165  }
166 
168  return dh->edge_new_local_4_mesh_idx_[edge_global_idx(i)];
169  }
170 
172  return dh->row_4_edge[edge_global_idx(i)];
173  }
174 
176  return edge_row(i) - dh->rows_ds->begin();
177  }
178 
179  int *edge_rows() {
180  for(uint i=0; i< dim(); i++) edge_rows_[i] = edge_row(i);
181  return edge_rows_;
182  }
183 
185  return ele->side(i);
186  }
187 
189  return dh->elem_side_to_global[ ele->index() ][ i ];
190  }
191 
193  return dh->side_row_4_id[side_global_idx(i)] - dh->rows_ds->begin();
194  }
195 
197  return dh->side_row_4_id[side_global_idx(i)];
198  }
199 
201  return side_row(i) - dh->rows_ds->begin();
202  }
203 
204  int *side_rows() {
205  for(uint i=0; i< dim(); i++) side_rows_[i] = side_row(i);
206  return side_rows_;
207  }
208 
209 private:
210  int side_rows_[4];
211  int edge_rows_[4];
215 };
216 
217 /**
218  * This is prototype of further much more complex and general accessor templated by
219  * element dimension. In fact we shall need an accessor for every kind of element interaction integral.
220  */
221 template <int spacedim, int dim>
223 public:
225  : LocalElementAccessorBase<spacedim>(dh, loc_ele_idx)
226  {}
227 };
228 
229 
230 
231 #endif /* MH_DOFHANDLER_HH_ */
const arma::vec3 centre() const
Definition: sides.h:31
Distribution * side_ds
double time_changed() const
LocalElementAccessorBase(MH_DofHandler *dh, uint loc_ele_idx)
unsigned int uint
ElementAccessor< 3 > element_accessor()
Definition: mesh.h:97
Distribution * el_ds
std::unordered_map< unsigned int, unsigned int > edge_new_local_4_mesh_idx_
std::shared_ptr< LocalToGlobalMap > global_row_4_sub_row
Necessary only for BDDC solver.
double precision() const
vector< vector< unsigned int > > elem_side_to_global
Distribution * edge_ds
Support classes for parallel programing.
LocalElementAccessor(MH_DofHandler &dh, uint loc_ele_idx)
std::shared_ptr< Distribution > rows_ds
double * mh_solution
double solution_precision
ElementFullIter full_iter()