MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
100  template<class Scalar = DefaultScalar,
103  class Node = DefaultNode>
105 #undef MUELU_VARIABLEDOFLAPLACIANFACTORY_SHORT
106 #include "MueLu_UseShortNames.hpp"
107 
108  public:
109 
111 
112 
115 
118 
120 
122 
124 
125 
126  void DeclareInput(Level &currentLevel) const;
127 
129 
130  void Build(Level &currentLevel) const; // Build
131 
132  private:
133 
134  void buildPaddedMap(const Teuchos::ArrayRCP<const LocalOrdinal> & dofPresent, std::vector<LocalOrdinal> & map, size_t nDofs) const;
135  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;
136  void squeezeOutNnzs(Teuchos::ArrayRCP<size_t> & rowPtr, Teuchos::ArrayRCP<LocalOrdinal> & cols, Teuchos::ArrayRCP<Scalar> & vals, const std::vector<bool>& keep) const;
137  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<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LocalOrdinal,GlobalOrdinal,Node> > & ghostedCoords) const;
138 
139  template <class listType>
140  void MueLu_az_sort(listType list[], size_t N, size_t list2[], Scalar list3[]) const {
141  /* local variables */
142 
143  listType RR, K;
144  size_t l, r, j, i;
145  int flag;
146  size_t RR2;
147  Scalar RR3;
148 
149  /*********************** execution begins ******************************/
150 
151  if (N <= 1) return;
152 
153  l = N / 2 + 1;
154  r = N - 1;
155  l = l - 1;
156  RR = list[l - 1];
157  K = list[l - 1];
158 
159  if ((list2 != NULL) && (list3 != NULL)) {
160  RR2 = list2[l - 1];
161  RR3 = list3[l - 1];
162  while (r != 0) {
163  j = l;
164  flag = 1;
165 
166  while (flag == 1) {
167  i = j;
168  j = j + j;
169 
170  if (j > r + 1)
171  flag = 0;
172  else {
173  if (j < r + 1)
174  if (list[j] > list[j - 1]) j = j + 1;
175 
176  if (list[j - 1] > K) {
177  list[ i - 1] = list[ j - 1];
178  list2[i - 1] = list2[j - 1];
179  list3[i - 1] = list3[j - 1];
180  }
181  else {
182  flag = 0;
183  }
184  }
185  }
186 
187  list[ i - 1] = RR;
188  list2[i - 1] = RR2;
189  list3[i - 1] = RR3;
190 
191  if (l == 1) {
192  RR = list [r];
193  RR2 = list2[r];
194  RR3 = list3[r];
195 
196  K = list[r];
197  list[r ] = list[0];
198  list2[r] = list2[0];
199  list3[r] = list3[0];
200  r = r - 1;
201  }
202  else {
203  l = l - 1;
204  RR = list[ l - 1];
205  RR2 = list2[l - 1];
206  RR3 = list3[l - 1];
207  K = list[l - 1];
208  }
209  }
210 
211  list[ 0] = RR;
212  list2[0] = RR2;
213  list3[0] = RR3;
214  }
215  else if (list2 != NULL) {
216  RR2 = list2[l - 1];
217  while (r != 0) {
218  j = l;
219  flag = 1;
220 
221  while (flag == 1) {
222  i = j;
223  j = j + j;
224 
225  if (j > r + 1)
226  flag = 0;
227  else {
228  if (j < r + 1)
229  if (list[j] > list[j - 1]) j = j + 1;
230 
231  if (list[j - 1] > K) {
232  list[ i - 1] = list[ j - 1];
233  list2[i - 1] = list2[j - 1];
234  }
235  else {
236  flag = 0;
237  }
238  }
239  }
240 
241  list[ i - 1] = RR;
242  list2[i - 1] = RR2;
243 
244  if (l == 1) {
245  RR = list [r];
246  RR2 = list2[r];
247 
248  K = list[r];
249  list[r ] = list[0];
250  list2[r] = list2[0];
251  r = r - 1;
252  }
253  else {
254  l = l - 1;
255  RR = list[ l - 1];
256  RR2 = list2[l - 1];
257  K = list[l - 1];
258  }
259  }
260 
261  list[ 0] = RR;
262  list2[0] = RR2;
263  }
264  else if (list3 != NULL) {
265  RR3 = list3[l - 1];
266  while (r != 0) {
267  j = l;
268  flag = 1;
269 
270  while (flag == 1) {
271  i = j;
272  j = j + j;
273 
274  if (j > r + 1)
275  flag = 0;
276  else {
277  if (j < r + 1)
278  if (list[j] > list[j - 1]) j = j + 1;
279 
280  if (list[j - 1] > K) {
281  list[ i - 1] = list[ j - 1];
282  list3[i - 1] = list3[j - 1];
283  }
284  else {
285  flag = 0;
286  }
287  }
288  }
289 
290  list[ i - 1] = RR;
291  list3[i - 1] = RR3;
292 
293  if (l == 1) {
294  RR = list [r];
295  RR3 = list3[r];
296 
297  K = list[r];
298  list[r ] = list[0];
299  list3[r] = list3[0];
300  r = r - 1;
301  }
302  else {
303  l = l - 1;
304  RR = list[ l - 1];
305  RR3 = list3[l - 1];
306  K = list[l - 1];
307  }
308  }
309 
310  list[ 0] = RR;
311  list3[0] = RR3;
312 
313  }
314  else {
315  while (r != 0) {
316  j = l;
317  flag = 1;
318 
319  while (flag == 1) {
320  i = j;
321  j = j + j;
322 
323  if (j > r + 1)
324  flag = 0;
325  else {
326  if (j < r + 1)
327  if (list[j] > list[j - 1]) j = j + 1;
328 
329  if (list[j - 1] > K) {
330  list[ i - 1] = list[ j - 1];
331  }
332  else {
333  flag = 0;
334  }
335  }
336  }
337 
338  list[ i - 1] = RR;
339 
340  if (l == 1) {
341  RR = list [r];
342 
343  K = list[r];
344  list[r ] = list[0];
345  r = r - 1;
346  }
347  else {
348  l = l - 1;
349  RR = list[ l - 1];
350  K = list[l - 1];
351  }
352  }
353 
354  list[ 0] = RR;
355  }
356  }
357 
358  }; //class CoalesceDropFactory
359 
360 } //namespace MueLu
361 
362 #define MUELU_VARIABLEDOFLAPLACIANFACTORY_SHORT
363 
364 
365 #endif /* PACKAGES_MUELU_SRC_GRAPH_MUELU_VARIABLEDOFLAPLACIANFACTORY_DECL_HPP_ */
void buildPaddedMap(const Teuchos::ArrayRCP< const LocalOrdinal > &dofPresent, std::vector< LocalOrdinal > &map, size_t nDofs) const
MueLu::DefaultLocalOrdinal LocalOrdinal
KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
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< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > &ghostedCoords) const
void DeclareInput(Level &currentLevel) const
Input.
MueLu::DefaultNode Node
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 MueLu_az_sort(listType list[], size_t N, size_t list2[], Scalar list3[]) const
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
void Build(Level &currentLevel) const
Build an object with this factory.
Factory for building scalar Laplace operator (that is used as fake operator for variable dof size pro...
void squeezeOutNnzs(Teuchos::ArrayRCP< size_t > &rowPtr, Teuchos::ArrayRCP< LocalOrdinal > &cols, Teuchos::ArrayRCP< Scalar > &vals, const std::vector< bool > &keep) const
Base class for factories that use one level (currentLevel).
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.