| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef MUELU_IPCFACTORY_DECL_HPP |
| 11 |
#define MUELU_IPCFACTORY_DECL_HPP |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include "MueLu_ConfigDefs.hpp" |
| 17 |
#include "MueLu_IntrepidPCoarsenFactory_fwd.hpp" |
| 18 |
|
| 19 |
#include "MueLu_Level_fwd.hpp" |
| 20 |
#include "MueLu_ParameterListAcceptor.hpp" |
| 21 |
#include "MueLu_PerfUtils_fwd.hpp" |
| 22 |
#include "MueLu_PFactory.hpp" |
| 23 |
#include "MueLu_Utilities_fwd.hpp" |
| 24 |
|
| 25 |
#include "Intrepid2_Basis.hpp" |
| 26 |
|
| 27 |
#include "Kokkos_DynRankView.hpp" |
| 28 |
|
| 29 |
#include <Xpetra_Import_fwd.hpp> |
| 30 |
|
| 31 |
namespace MueLu { |
| 32 |
|
| 33 |
/*! |
| 34 |
@class IntrepidPCoarsenFactory class. |
| 35 |
@ingroup MueLuTransferClasses |
| 36 |
@brief Factory for building transfer operators based on coarsening in polynomial degree, following the Intrepid basis functions |
| 37 |
|
| 38 |
## Input/output of IntrepidPCoarsenFactory ## |
| 39 |
|
| 40 |
### User parameters of IntrepidPCoarsenFactory ### |
| 41 |
Parameter | type | default | master.xml | validated | requested | description |
| 42 |
----------|------|---------|:----------:|:---------:|:---------:|------------ |
| 43 |
| pcoarsen: schedule | string | "" | * | * | | String describing the higher order coarsening scheme to use | |
| 44 |
| pcoarsen: element | string | "" | * | * | | String describing the class of element to use for higher order coarsening | |
| 45 |
| pcoarsen: hi basis | string | "" | * | * | | String describing higher-order basis function used | |
| 46 |
| pcoarsen: lo basis | string | "" | * | * | | String describing lower-order basis function to be used for coarse grid | |
| 47 |
| pcoarsen: element to node map | RCP<Intrepid::FieldContainer<LocalOrdinal> > | null | * | * | | A FieldContainer with the element-to-node map in local ids compatible with the matrix column map | |
| 48 |
| A | Factory | null | * | * | | Generating factory of the matrix A used during the prolongator smoothing process | |
| 49 |
|
| 50 |
|
| 51 |
The * in the @c master.xml column denotes that the parameter is defined in the @c master.xml file.<br> |
| 52 |
The * in the @c validated column means that the parameter is declared in the list of valid input parameters (see IntrepidPCoarsen::GetValidParameters).<br> |
| 53 |
The * in the @c requested column states that the data is requested as input with all dependencies (see IntrepidPCoarsen::DeclareInput). |
| 54 |
|
| 55 |
### Variables provided by IntrepidPCoarsen ### |
| 56 |
|
| 57 |
After IntrepidPCoarsen::Build the following data is available (if requested) |
| 58 |
|
| 59 |
Parameter | generated by | description |
| 60 |
----------|--------------|------------ |
| 61 |
| P | IntrepidPCoarsenFactory | Smoothed prolongator |
| 62 |
|
| 63 |
|
| 64 |
NOTE: The prolongator generated by this routine strips Dirichlet unknowns out of the coarse grid. This means that the prolongator cannot |
| 65 |
transfer *solutions* between grids, only updates (because the update at a Dirichlet node is zero). This is a subtle distinction, but an |
| 66 |
important one for testing purposes. |
| 67 |
|
| 68 |
FIXME: There may be implications for the correctness of the nullspace transfer from fine to coarse that I need to understand. |
| 69 |
|
| 70 |
|
| 71 |
*/ |
| 72 |
|
| 73 |
template <class Scalar = DefaultScalar, |
| 74 |
class LocalOrdinal = DefaultLocalOrdinal, |
| 75 |
class GlobalOrdinal = DefaultGlobalOrdinal, |
| 76 |
class Node = DefaultNode> |
| 77 |
class IntrepidPCoarsenFactory : public PFactory { |
| 78 |
#undef MUELU_INTREPIDPCOARSENFACTORY_SHORT |
| 79 |
#include "MueLu_UseShortNames.hpp" |
| 80 |
|
| 81 |
public: |
| 82 |
typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> LOFieldContainer; |
| 83 |
typedef Kokkos::DynRankView<double, typename Node::device_type> SCFieldContainer; |
| 84 |
typedef Intrepid2::Basis<typename Node::device_type::execution_space, double, double> Basis; // Hardwired on purpose |
| 85 |
|
| 86 |
//! @name Constructors/Destructors. |
| 87 |
//@{ |
| 88 |
|
| 89 |
/*! @brief Constructor. |
| 90 |
User can supply a factory for generating the tentative prolongator. |
| 91 |
*/ |
| 92 |
IntrepidPCoarsenFactory() {} |
| 93 |
|
| 94 |
//! Destructor. |
| 95 |
virtual ~IntrepidPCoarsenFactory() {} |
| 96 |
|
| 97 |
RCP<const ParameterList> GetValidParameterList() const; |
| 98 |
|
| 99 |
//@} |
| 100 |
|
| 101 |
//! Input |
| 102 |
//@{ |
| 103 |
|
| 104 |
void DeclareInput(Level &fineLevel, Level &coarseLevel) const; |
| 105 |
|
| 106 |
//@} |
| 107 |
|
| 108 |
//! @name Build methods. |
| 109 |
//@{ |
| 110 |
|
| 111 |
/*! |
| 112 |
@brief Build method. |
| 113 |
|
| 114 |
Builds IPC prolongator and returns it in <tt>coarseLevel</tt>. |
| 115 |
*/ |
| 116 |
void Build(Level &fineLevel, Level &coarseLevel) const; |
| 117 |
|
| 118 |
void BuildP(Level &fineLevel, Level &coarseLevel) const; // Build() |
| 119 |
|
| 120 |
//@} |
| 121 |
private: |
| 122 |
//! @name Internal Utilities |
| 123 |
//@{ |
| 124 |
// NOTE: This is hardwired to double on purpose. |
| 125 |
void GenerateLinearCoarsening_pn_kirby_to_p1(const LOFieldContainer &hi_elemToNode, |
| 126 |
const std::vector<bool> &hi_nodeIsOwned, |
| 127 |
const SCFieldContainer &hi_DofCoords, |
| 128 |
const std::vector<size_t> &lo_node_in_hi, |
| 129 |
const Basis &lo_Basis, |
| 130 |
const std::vector<LocalOrdinal> &hi_to_lo_map, |
| 131 |
const Teuchos::RCP<const Map> &lo_colMap, |
| 132 |
const Teuchos::RCP<const Map> &lo_domainMap, |
| 133 |
const Teuchos::RCP<const Map> &hi_map, |
| 134 |
Teuchos::RCP<Matrix> &P) const; |
| 135 |
//@} |
| 136 |
|
| 137 |
// NOTE: This is hardwired to double on purpose. |
| 138 |
void GenerateLinearCoarsening_pn_kirby_to_pm(const LOFieldContainer &hi_elemToNode, |
| 139 |
const std::vector<bool> &hi_nodeIsOwned, |
| 140 |
const SCFieldContainer &hi_DofCoords, |
| 141 |
const LOFieldContainer &lo_elemToHiRepresentativeNode, |
| 142 |
const Basis &lo_basis, |
| 143 |
const std::vector<LocalOrdinal> &hi_to_lo_map, |
| 144 |
const Teuchos::RCP<const Map> &lo_colMap, |
| 145 |
const Teuchos::RCP<const Map> &lo_domainMap, |
| 146 |
const Teuchos::RCP<const Map> &hi_map, |
| 147 |
Teuchos::RCP<Matrix> &P) const; |
| 148 |
|
| 149 |
}; // class IntrepidPCoarsenFactory |
| 150 |
|
| 151 |
/* Utility functions for use with Intrepid */ |
| 152 |
namespace MueLuIntrepid { |
| 153 |
|
| 154 |
template <class Scalar, class KokkosExecutionSpace> |
| 155 |
Teuchos::RCP<Intrepid2::Basis<KokkosExecutionSpace, Scalar, Scalar> > BasisFactory(const std::string &name, int °ree); |
| 156 |
|
| 157 |
template <class Scalar, class KokkosDeviceType> |
| 158 |
void IntrepidGetLoNodeInHi(const Teuchos::RCP<Intrepid2::Basis<typename KokkosDeviceType::execution_space, Scalar, Scalar> > &hi_basis, |
| 159 |
const Teuchos::RCP<Intrepid2::Basis<typename KokkosDeviceType::execution_space, Scalar, Scalar> > &lo_basis, |
| 160 |
std::vector<size_t> &lo_node_in_hi, |
| 161 |
Kokkos::DynRankView<Scalar, KokkosDeviceType> &hi_DofCoords); |
| 162 |
|
| 163 |
template <class LocalOrdinal, class GlobalOrdinal, class Node, class LOFieldContainer> |
| 164 |
void GenerateLoNodeInHiViaGIDs(const std::vector<std::vector<size_t> > &candidates, const LOFieldContainer &hi_elemToNode, |
| 165 |
RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > &hi_columnMap, |
| 166 |
LOFieldContainer &lo_elemToHiRepresentativeNode); |
| 167 |
|
| 168 |
template <class LocalOrdinal, class LOFieldContainer> |
| 169 |
void BuildLoElemToNode(const LOFieldContainer &hi_elemToNode, |
| 170 |
const std::vector<bool> &hi_nodeIsOwned, |
| 171 |
const std::vector<size_t> &lo_node_in_hi, |
| 172 |
const Teuchos::ArrayRCP<const int> &hi_isDirichlet, |
| 173 |
LOFieldContainer &lo_elemToNode, |
| 174 |
std::vector<bool> &lo_nodeIsOwned, |
| 175 |
std::vector<LocalOrdinal> &hi_to_lo_map, |
| 176 |
int &lo_numOwnedNodes); |
| 177 |
|
| 178 |
template <class LocalOrdinal, class LOFieldContainer> |
| 179 |
void BuildLoElemToNodeViaRepresentatives(const LOFieldContainer &hi_elemToNode, |
| 180 |
const std::vector<bool> &hi_nodeIsOwned, |
| 181 |
const LOFieldContainer &lo_elemToHiRepresentativeNode, |
| 182 |
LOFieldContainer &lo_elemToNode, |
| 183 |
std::vector<bool> &lo_nodeIsOwned, |
| 184 |
std::vector<LocalOrdinal> &hi_to_lo_map, |
| 185 |
int &lo_numOwnedNodes); |
| 186 |
|
| 187 |
template <class LocalOrdinal, class GlobalOrdinal, class Node> |
| 188 |
void GenerateColMapFromImport(const Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node> &hi_importer, const std::vector<LocalOrdinal> &hi_to_lo_map, const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> &lo_domainMap, const size_t &lo_columnMapLength, RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > &lo_columnMap); |
| 189 |
|
| 190 |
template <class Basis, class SCFieldContainer> |
| 191 |
void GenerateRepresentativeBasisNodes(const Basis &basis, const SCFieldContainer &ReferenceNodeLocations, const double threshold, std::vector<std::vector<size_t> > &representative_node_candidates); |
| 192 |
|
| 193 |
// ! Given an element to (global) node map and a basis, determine one global ordinal per geometric entity (vertex, edge, face, |
| 194 |
// ! interior). On exit, seeds container is of dimension (spaceDim+1), and contains a sorted vector of local ordinals |
| 195 |
// ! belonging to entities of that dimension. Only locally-owned degrees of freedom (as determined by rowMap and columnMap) |
| 196 |
// ! will be stored in seeds. |
| 197 |
template <class Basis, class LOFieldContainer, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 198 |
void FindGeometricSeedOrdinals(Teuchos::RCP<Basis> basis, const LOFieldContainer &elementToNodeMap, |
| 199 |
std::vector<std::vector<LocalOrdinal> > &seeds, |
| 200 |
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> &rowMap, |
| 201 |
const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> &columnMap); |
| 202 |
|
| 203 |
} // namespace MueLuIntrepid |
| 204 |
} // namespace MueLu |
| 205 |
|
| 206 |
#define MUELU_INTREPIDPCOARSENFACTORY_SHORT |
| 207 |
#endif // MUELU_INTREPIDPCOARSENFACTORY_DECL_HPP |