Flow123d  release_2.2.0-914-gf1a3a4f
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  IdxInt *el_4_loc; //< array of idexes of local elements (in ordering matching the optimal global)
80  IdxInt *row_4_el; //< element index to matrix row
81  IdxInt *side_id_4_loc; //< array of ids of local sides
82  IdxInt *side_row_4_id; //< side id to matrix row
83  IdxInt *edge_4_loc; //< array of indexes of local edges
84  IdxInt *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:
115 
117  : dh(dh), local_ele_idx_(loc_ele_idx), ele(dh->mesh_->element(ele_global_idx()))
118  {}
119 
120  void reinit( uint loc_ele_idx)
121  {
122  local_ele_idx_=loc_ele_idx;
123  ele=dh->mesh_->element(ele_global_idx());
124  }
125 
126  uint dim() {
127  return ele->dim();
128  }
129 
131  return ele->n_sides();
132  }
133 
135  return ele;
136  }
137 
139  return ele->element_accessor();
140  }
141 
142  const arma::vec3 centre() const {
143  return ele->centre();
144  }
145 
146  double measure() const {
147  return ele->measure();
148  }
149 
150  Region region() const {
151  return ele->region();
152  }
153 
155  return dh->el_4_loc[local_ele_idx_];
156  }
157 
159  return local_ele_idx_;
160  }
161 
163  return dh->row_4_el[ele_global_idx()];
164  }
165 
167  return ele_row() - dh->rows_ds->begin(); // i_loc_el + side_ds->lsize();
168  }
169 
171  return ele->side(i)->edge_idx();
172  }
173 
175  return dh->edge_new_local_4_mesh_idx_[edge_global_idx(i)];
176  }
177 
179  return dh->row_4_edge[edge_global_idx(i)];
180  }
181 
183  return edge_row(i) - dh->rows_ds->begin();
184  }
185 
186  int *edge_rows() {
187  for(uint i=0; i< dim(); i++) edge_rows_[i] = edge_row(i);
188  return edge_rows_;
189  }
190 
192  return ele->side(i);
193  }
194 
196  return dh->elem_side_to_global[ ele->index() ][ i ];
197  }
198 
200  return dh->side_row_4_id[side_global_idx(i)] - dh->rows_ds->begin();
201  }
202 
204  return dh->side_row_4_id[side_global_idx(i)];
205  }
206 
208  return side_row(i) - dh->rows_ds->begin();
209  }
210 
211  int *side_rows() {
212  for(uint i=0; i< dim(); i++) side_rows_[i] = side_row(i);
213  return side_rows_;
214  }
215 
216 private:
217  int side_rows_[4];
218  int edge_rows_[4];
222 };
223 
224 /**
225  * This is prototype of further much more complex and general accessor templated by
226  * element dimension. In fact we shall need an accessor for every kind of element interaction integral.
227  */
228 template <int spacedim, int dim>
230 public:
232  : LocalElementAccessorBase<spacedim>(dh, loc_ele_idx)
233  {}
234 };
235 
236 
237 
238 #endif /* MH_DOFHANDLER_HH_ */
const arma::vec3 centre() const
Definition: sides.h:31
Distribution * side_ds
int IdxInt
Define integers that are indices into large arrays (elements, nodes, dofs etc.)
Definition: mesh.h:85
IdxInt * row_4_el
double time_changed() const
unsigned int uint
IdxInt * row_4_edge
void reinit(uint loc_ele_idx)
ElementAccessor< 3 > element_accessor()
Definition: mesh.h:99
Distribution * el_ds
IdxInt * side_row_4_id
IdxInt * el_4_loc
IdxInt * side_id_4_loc
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
LocalElementAccessorBase(MH_DofHandler *dh, uint loc_ele_idx=0)
IdxInt * edge_4_loc
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()