Flow123d  JS_before_hm-2-g912b55d
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 <ext/alloc_traits.h> // for __alloc_traits<>::value_...
22 #include <sys/types.h> // for uint
23 #include <memory> // for shared_ptr, __shared_ptr
24 #include <unordered_map> // for unordered_map
25 #include <vector> // for vector
26 #include <armadillo>
27 #include "la/distribution.hh" // for Distribution
28 #include "mesh/long_idx.hh" // for LongIdx
29 #include "mesh/accessors.hh" // for ElementAccessor, Side::edge_idx
30 #include "mesh/elements.h" // for Element::side, Element::dim
31 #include "mesh/mesh.h" // for Mesh
32 #include "mesh/region.hh" // for Region
33 
34 class LocalToGlobalMap;
35 template <int spacedim> class LocalElementAccessorBase;
36 
37 using namespace std;
38 
39 /// temporary solution to provide access to results
40 /// from DarcyFlowMH independent of mesh
42 public:
43  MH_DofHandler();
44  ~MH_DofHandler();
45  void reinit(Mesh *mesh);
46 
47  void prepare_parallel();
48  void make_row_numberings();
49  void prepare_parallel_bddc();
50 
51  void set_solution( double time, double * solution, double precision);
52 
53  inline double time_changed() const
54  { return time_; }
55 
56  unsigned int side_dof(const SideIter side) const;
57 
58  /// temporary replacement for DofHandler accessor, flux through given side
59  double side_flux(const Side &side) const;
60 
61  /// temporary replacement for DofHandler accessor, scalar (pressure) on edge of the side
62  double side_scalar(const Side &side) const;
63 
64  /// temporary replacement for DofHandler accessor, scalar (pressure) on element
65  double element_scalar( ElementAccessor<3> &ele ) const;
66 
67  inline double precision() const { return solution_precision; };
68 
69  LocalElementAccessorBase<3> accessor(uint local_ele_idx);
70 
71 //protected:
73 
75  LongIdx *el_4_loc; //< array of idexes of local elements (in ordering matching the optimal global)
76  LongIdx *row_4_el; //< element index to matrix row
77  LongIdx *side_id_4_loc; //< array of ids of local sides
78  LongIdx *side_row_4_id; //< side id to matrix row
79  LongIdx *edge_4_loc; //< array of indexes of local edges
80  LongIdx *row_4_edge; //< edge index to matrix row
81 
82  // parallel
83  Distribution *edge_ds; //< optimal distribution of edges
84  Distribution *el_ds; //< optimal distribution of elements
85  Distribution *side_ds; //< optimal distribution of elements
86  std::shared_ptr<Distribution> rows_ds; //< final distribution of rows of MH matrix
87 
88 
89  /// Maps mesh index of the edge to the edge index in the mesh portion local to the processor.
90  /// Temporary solution until we have parallel mesh which should provide such information.
91  std::unordered_map<unsigned int, unsigned int> edge_new_local_4_mesh_idx_;
92 
93  /// Necessary only for BDDC solver.
94  std::shared_ptr<LocalToGlobalMap> global_row_4_sub_row; //< global dof index for subdomain index
95 
96 
97  double * mh_solution;
99  double time_;
100 
102 };
103 
104 
105 
106 typedef unsigned int uint;
107 
108 template <int spacedim>
110 public:
111 
113  : dh(dh), local_ele_idx_(loc_ele_idx), ele( dh->mesh_->element_accessor(ele_global_idx()) )
114  {}
115 
116  void reinit( uint loc_ele_idx)
117  {
118  local_ele_idx_=loc_ele_idx;
119  ele=dh->mesh_->element_accessor(ele_global_idx());
120  }
121 
122  uint dim() {
123  return ele->dim();
124  }
125 
127  return ele->n_sides();
128  }
129 
131  return ele;
132  }
133 
134  const arma::vec3 centre() const {
135  return ele.centre();
136  }
137 
138  double measure() const {
139  return ele.measure();
140  }
141 
142  Region region() const {
143  return ele.region();
144  }
145 
147  return dh->el_4_loc[local_ele_idx_];
148  }
149 
151  return local_ele_idx_;
152  }
153 
155  return dh->row_4_el[ele_global_idx()];
156  }
157 
159  return ele_row() - dh->rows_ds->begin(); // i_loc_el + side_ds->lsize();
160  }
161 
163  return ele.side(i)->edge_idx();
164  }
165 
167  return dh->edge_new_local_4_mesh_idx_[edge_global_idx(i)];
168  }
169 
171  return dh->row_4_edge[edge_global_idx(i)];
172  }
173 
175  return edge_row(i) - dh->rows_ds->begin();
176  }
177 
178  int *edge_rows() {
179  for(uint i=0; i< dim(); i++) edge_rows_[i] = edge_row(i);
180  return edge_rows_;
181  }
182 
184  return ele.side(i);
185  }
186 
188  return dh->elem_side_to_global[ ele.idx() ][ i ];
189  }
190 
192  return dh->side_row_4_id[side_global_idx(i)] - dh->rows_ds->begin();
193  }
194 
196  return dh->side_row_4_id[side_global_idx(i)];
197  }
198 
200  return side_row(i) - dh->rows_ds->begin();
201  }
202 
203  int *side_rows() {
204  for(uint i=0; i< dim(); i++) side_rows_[i] = side_row(i);
205  return side_rows_;
206  }
207 
208 private:
209  int side_rows_[4];
210  int edge_rows_[4];
214 };
215 
216 /**
217  * This is prototype of further much more complex and general accessor templated by
218  * element dimension. In fact we shall need an accessor for every kind of element interaction integral.
219  */
220 template <int spacedim, int dim>
222 public:
224  : LocalElementAccessorBase<spacedim>(dh, loc_ele_idx)
225  {}
226 };
227 
228 
229 
230 #endif /* MH_DOFHANDLER_HH_ */
const arma::vec3 centre() const
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: long_idx.hh:22
Distribution * side_ds
double time_changed() const
unsigned int uint
LongIdx * el_4_loc
ElementAccessor< 3 > ele
void reinit(uint loc_ele_idx)
ElementAccessor< 3 > element_accessor()
LongIdx * side_row_4_id
Definition: mesh.h:76
Distribution * el_ds
LongIdx * row_4_el
LongIdx * side_id_4_loc
class to manage local indices on sub-domain to global indices on domain
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)
Distribution * edge_ds
Support classes for parallel programing.
LongIdx * row_4_edge
LongIdx * edge_4_loc
LocalElementAccessor(MH_DofHandler &dh, uint loc_ele_idx)
std::shared_ptr< Distribution > rows_ds
double * mh_solution
double solution_precision