Flow123d  release_3.0.0-955-g4db4b48
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
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 #include "mesh/side_impl.hh" // for Side::edge_idx
34 #include "mesh/sides.h" // for SideIter, Side
35 
36 class LocalToGlobalMap;
37 template <int spacedim> class LocalElementAccessorBase;
38 
39 using namespace std;
40 
41 /// temporary solution to provide access to results
42 /// from DarcyFlowMH independent of mesh
44 public:
45  MH_DofHandler();
46  ~MH_DofHandler();
47  void reinit(Mesh *mesh);
48 
49  void prepare_parallel();
50  void make_row_numberings();
51  void prepare_parallel_bddc();
52 
53  void set_solution( double time, double * solution, double precision);
54 
55  inline double time_changed() const
56  { return time_; }
57 
58  unsigned int side_dof(const SideIter side) const;
59 
60  /// temporary replacement for DofHandler accessor, flux through given side
61  double side_flux(const Side &side) const;
62 
63  /// temporary replacement for DofHandler accessor, scalar (pressure) on edge of the side
64  double side_scalar(const Side &side) const;
65 
66  /// temporary replacement for DofHandler accessor, scalar (pressure) on element
67  double element_scalar( ElementAccessor<3> &ele ) const;
68 
69  inline double precision() const { return solution_precision; };
70 
71  LocalElementAccessorBase<3> accessor(uint local_ele_idx);
72 
73 //protected:
75 
77  LongIdx *el_4_loc; //< array of idexes of local elements (in ordering matching the optimal global)
78  LongIdx *row_4_el; //< element index to matrix row
79  LongIdx *side_id_4_loc; //< array of ids of local sides
80  LongIdx *side_row_4_id; //< side id to matrix row
81  LongIdx *edge_4_loc; //< array of indexes of local edges
82  LongIdx *row_4_edge; //< edge index to matrix row
83 
84  // parallel
85  Distribution *edge_ds; //< optimal distribution of edges
86  Distribution *el_ds; //< optimal distribution of elements
87  Distribution *side_ds; //< optimal distribution of elements
88  std::shared_ptr<Distribution> rows_ds; //< final distribution of rows of MH matrix
89 
90 
91  /// Maps mesh index of the edge to the edge index in the mesh portion local to the processor.
92  /// Temporary solution until we have parallel mesh which should provide such information.
93  std::unordered_map<unsigned int, unsigned int> edge_new_local_4_mesh_idx_;
94 
95  /// Necessary only for BDDC solver.
96  std::shared_ptr<LocalToGlobalMap> global_row_4_sub_row; //< global dof index for subdomain index
97 
98 
99  double * mh_solution;
101  double time_;
102 
104 };
105 
106 
107 
108 typedef unsigned int uint;
109 
110 template <int spacedim>
112 public:
113 
115  : dh(dh), local_ele_idx_(loc_ele_idx), ele( dh->mesh_->element_accessor(ele_global_idx()) )
116  {}
117 
118  void reinit( uint loc_ele_idx)
119  {
120  local_ele_idx_=loc_ele_idx;
121  ele=dh->mesh_->element_accessor(ele_global_idx());
122  }
123 
124  uint dim() {
125  return ele->dim();
126  }
127 
129  return ele->n_sides();
130  }
131 
133  return ele;
134  }
135 
136  const arma::vec3 centre() const {
137  return ele.centre();
138  }
139 
140  double measure() const {
141  return ele.measure();
142  }
143 
144  Region region() const {
145  return ele.region();
146  }
147 
149  return dh->el_4_loc[local_ele_idx_];
150  }
151 
153  return local_ele_idx_;
154  }
155 
157  return dh->row_4_el[ele_global_idx()];
158  }
159 
161  return ele_row() - dh->rows_ds->begin(); // i_loc_el + side_ds->lsize();
162  }
163 
165  return ele.side(i)->edge_idx();
166  }
167 
169  return dh->edge_new_local_4_mesh_idx_[edge_global_idx(i)];
170  }
171 
173  return dh->row_4_edge[edge_global_idx(i)];
174  }
175 
177  return edge_row(i) - dh->rows_ds->begin();
178  }
179 
180  int *edge_rows() {
181  for(uint i=0; i< dim(); i++) edge_rows_[i] = edge_row(i);
182  return edge_rows_;
183  }
184 
186  return ele.side(i);
187  }
188 
190  return dh->elem_side_to_global[ ele.idx() ][ i ];
191  }
192 
194  return dh->side_row_4_id[side_global_idx(i)] - dh->rows_ds->begin();
195  }
196 
198  return dh->side_row_4_id[side_global_idx(i)];
199  }
200 
202  return side_row(i) - dh->rows_ds->begin();
203  }
204 
205  int *side_rows() {
206  for(uint i=0; i< dim(); i++) side_rows_[i] = side_row(i);
207  return side_rows_;
208  }
209 
210 private:
211  int side_rows_[4];
212  int edge_rows_[4];
216 };
217 
218 /**
219  * This is prototype of further much more complex and general accessor templated by
220  * element dimension. In fact we shall need an accessor for every kind of element interaction integral.
221  */
222 template <int spacedim, int dim>
224 public:
226  : LocalElementAccessorBase<spacedim>(dh, loc_ele_idx)
227  {}
228 };
229 
230 
231 
232 #endif /* MH_DOFHANDLER_HH_ */
const arma::vec3 centre() const
Definition: sides.h:39
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:80
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