MueLu  Version of the Day
MueLu_VariableDofLaplacianFactory_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Tobias Wiesner (tawiesn@sandia.gov)
42 // Ray Tuminaro (rstumin@sandia.gov)
43 //
44 // ***********************************************************************
45 //
46 // @HEADER
47 #ifndef PACKAGES_MUELU_SRC_GRAPH_MUELU_VARIABLEDOFLAPLACIANFACTORY_DECL_HPP_
48 #define PACKAGES_MUELU_SRC_GRAPH_MUELU_VARIABLEDOFLAPLACIANFACTORY_DECL_HPP_
49 
50 
51 #include "MueLu_ConfigDefs.hpp"
54 #include "MueLu_Level_fwd.hpp"
55 
56 #include "MueLu_Utilities_fwd.hpp"
57 
58 namespace MueLu {
59 
85  template <class Scalar = double,
86  class LocalOrdinal = int,
87  class GlobalOrdinal = LocalOrdinal,
88  class Node = KokkosClassic::DefaultNode::DefaultNodeType>
90 #undef MUELU_VARIABLEDOFLAPLACIANFACTORY_SHORT
91 #include "MueLu_UseShortNames.hpp"
92 
93  public:
94 
96 
97 
100 
103 
104  RCP<const ParameterList> GetValidParameterList() const;
105 
107 
109 
110 
111  void DeclareInput(Level &currentLevel) const;
112 
114 
115  void Build(Level &currentLevel) const; // Build
116 
117  private:
118 
119  void buildPaddedMap(const Teuchos::ArrayRCP<const LocalOrdinal> & dofPresent, std::vector<LocalOrdinal> & map, size_t nDofs) const;
120  void assignGhostLocalNodeIds(const Teuchos::RCP<const Map> & rowDofMap, const Teuchos::RCP<const Map> & colDofMap, std::vector<LocalOrdinal> & myLocalNodeIds, const std::vector<LocalOrdinal> & dofMap, size_t maxDofPerNode, size_t& nLocalNodes, size_t& nLocalPlusGhostNodes, Teuchos::RCP< const Teuchos::Comm< int > > comm) const;
121  void squeezeOutNnzs(Teuchos::ArrayRCP<size_t> & rowPtr, Teuchos::ArrayRCP<LocalOrdinal> & cols, Teuchos::ArrayRCP<Scalar> & vals, const std::vector<bool>& keep) const;
122  void buildLaplacian(const Teuchos::ArrayRCP<size_t>& rowPtr, const Teuchos::ArrayRCP<LocalOrdinal>& cols, Teuchos::ArrayRCP<Scalar>& vals, const size_t& numdim, const RCP<Xpetra::MultiVector<double,LocalOrdinal,GlobalOrdinal,Node> > & ghostedCoords) const;
123 
124  template <class listType>
125  void MueLu_az_sort(listType list[], size_t N, size_t list2[], Scalar list3[]) const {
126  /* local variables */
127 
128  listType RR, K;
129  size_t l, r, j, i;
130  int flag;
131  size_t RR2;
132  Scalar RR3;
133 
134  /*********************** execution begins ******************************/
135 
136  if (N <= 1) return;
137 
138  l = N / 2 + 1;
139  r = N - 1;
140  l = l - 1;
141  RR = list[l - 1];
142  K = list[l - 1];
143 
144  if ((list2 != NULL) && (list3 != NULL)) {
145  RR2 = list2[l - 1];
146  RR3 = list3[l - 1];
147  while (r != 0) {
148  j = l;
149  flag = 1;
150 
151  while (flag == 1) {
152  i = j;
153  j = j + j;
154 
155  if (j > r + 1)
156  flag = 0;
157  else {
158  if (j < r + 1)
159  if (list[j] > list[j - 1]) j = j + 1;
160 
161  if (list[j - 1] > K) {
162  list[ i - 1] = list[ j - 1];
163  list2[i - 1] = list2[j - 1];
164  list3[i - 1] = list3[j - 1];
165  }
166  else {
167  flag = 0;
168  }
169  }
170  }
171 
172  list[ i - 1] = RR;
173  list2[i - 1] = RR2;
174  list3[i - 1] = RR3;
175 
176  if (l == 1) {
177  RR = list [r];
178  RR2 = list2[r];
179  RR3 = list3[r];
180 
181  K = list[r];
182  list[r ] = list[0];
183  list2[r] = list2[0];
184  list3[r] = list3[0];
185  r = r - 1;
186  }
187  else {
188  l = l - 1;
189  RR = list[ l - 1];
190  RR2 = list2[l - 1];
191  RR3 = list3[l - 1];
192  K = list[l - 1];
193  }
194  }
195 
196  list[ 0] = RR;
197  list2[0] = RR2;
198  list3[0] = RR3;
199  }
200  else if (list2 != NULL) {
201  RR2 = list2[l - 1];
202  while (r != 0) {
203  j = l;
204  flag = 1;
205 
206  while (flag == 1) {
207  i = j;
208  j = j + j;
209 
210  if (j > r + 1)
211  flag = 0;
212  else {
213  if (j < r + 1)
214  if (list[j] > list[j - 1]) j = j + 1;
215 
216  if (list[j - 1] > K) {
217  list[ i - 1] = list[ j - 1];
218  list2[i - 1] = list2[j - 1];
219  }
220  else {
221  flag = 0;
222  }
223  }
224  }
225 
226  list[ i - 1] = RR;
227  list2[i - 1] = RR2;
228 
229  if (l == 1) {
230  RR = list [r];
231  RR2 = list2[r];
232 
233  K = list[r];
234  list[r ] = list[0];
235  list2[r] = list2[0];
236  r = r - 1;
237  }
238  else {
239  l = l - 1;
240  RR = list[ l - 1];
241  RR2 = list2[l - 1];
242  K = list[l - 1];
243  }
244  }
245 
246  list[ 0] = RR;
247  list2[0] = RR2;
248  }
249  else if (list3 != NULL) {
250  RR3 = list3[l - 1];
251  while (r != 0) {
252  j = l;
253  flag = 1;
254 
255  while (flag == 1) {
256  i = j;
257  j = j + j;
258 
259  if (j > r + 1)
260  flag = 0;
261  else {
262  if (j < r + 1)
263  if (list[j] > list[j - 1]) j = j + 1;
264 
265  if (list[j - 1] > K) {
266  list[ i - 1] = list[ j - 1];
267  list3[i - 1] = list3[j - 1];
268  }
269  else {
270  flag = 0;
271  }
272  }
273  }
274 
275  list[ i - 1] = RR;
276  list3[i - 1] = RR3;
277 
278  if (l == 1) {
279  RR = list [r];
280  RR3 = list3[r];
281 
282  K = list[r];
283  list[r ] = list[0];
284  list3[r] = list3[0];
285  r = r - 1;
286  }
287  else {
288  l = l - 1;
289  RR = list[ l - 1];
290  RR3 = list3[l - 1];
291  K = list[l - 1];
292  }
293  }
294 
295  list[ 0] = RR;
296  list3[0] = RR3;
297 
298  }
299  else {
300  while (r != 0) {
301  j = l;
302  flag = 1;
303 
304  while (flag == 1) {
305  i = j;
306  j = j + j;
307 
308  if (j > r + 1)
309  flag = 0;
310  else {
311  if (j < r + 1)
312  if (list[j] > list[j - 1]) j = j + 1;
313 
314  if (list[j - 1] > K) {
315  list[ i - 1] = list[ j - 1];
316  }
317  else {
318  flag = 0;
319  }
320  }
321  }
322 
323  list[ i - 1] = RR;
324 
325  if (l == 1) {
326  RR = list [r];
327 
328  K = list[r];
329  list[r ] = list[0];
330  r = r - 1;
331  }
332  else {
333  l = l - 1;
334  RR = list[ l - 1];
335  K = list[l - 1];
336  }
337  }
338 
339  list[ 0] = RR;
340  }
341  }
342 
343  }; //class CoalesceDropFactory
344 
345 } //namespace MueLu
346 
347 #define MUELU_VARIABLEDOFLAPLACIANFACTORY_SHORT
348 
349 
350 #endif /* PACKAGES_MUELU_SRC_GRAPH_MUELU_VARIABLEDOFLAPLACIANFACTORY_DECL_HPP_ */
void buildLaplacian(const Teuchos::ArrayRCP< size_t > &rowPtr, const Teuchos::ArrayRCP< LocalOrdinal > &cols, Teuchos::ArrayRCP< Scalar > &vals, const size_t &numdim, const RCP< Xpetra::MultiVector< double, LocalOrdinal, GlobalOrdinal, Node > > &ghostedCoords) const
Namespace for MueLu classes and methods.
void assignGhostLocalNodeIds(const Teuchos::RCP< const Map > &rowDofMap, const Teuchos::RCP< const Map > &colDofMap, std::vector< LocalOrdinal > &myLocalNodeIds, const std::vector< LocalOrdinal > &dofMap, size_t maxDofPerNode, size_t &nLocalNodes, size_t &nLocalPlusGhostNodes, Teuchos::RCP< const Teuchos::Comm< int > > comm) const
void buildPaddedMap(const Teuchos::ArrayRCP< const LocalOrdinal > &dofPresent, std::vector< LocalOrdinal > &map, size_t nDofs) const
void squeezeOutNnzs(Teuchos::ArrayRCP< size_t > &rowPtr, Teuchos::ArrayRCP< LocalOrdinal > &cols, Teuchos::ArrayRCP< Scalar > &vals, const std::vector< bool > &keep) const
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
Factory for building scalar Laplace operator (that is used as fake operator for variable dof size pro...
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Input.
Base class for factories that use one level (currentLevel).
void MueLu_az_sort(listType list[], size_t N, size_t list2[], Scalar list3[]) const