| 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_FACTORYMANAGER_DECL_HPP |
| 11 |
#define MUELU_FACTORYMANAGER_DECL_HPP |
| 12 |
|
| 13 |
#include "MueLu_ConfigDefs.hpp" |
| 14 |
#include "MueLu_FactoryManager_fwd.hpp" |
| 15 |
#include "MueLu_FactoryManagerBase.hpp" |
| 16 |
|
| 17 |
#include "MueLu_AmalgamationFactory_fwd.hpp" |
| 18 |
#include "MueLu_AggregateQualityEstimateFactory_fwd.hpp" |
| 19 |
#include "MueLu_CoalesceDropFactory_fwd.hpp" |
| 20 |
#include "MueLu_CoarseMapFactory_fwd.hpp" |
| 21 |
#include "MueLu_ConstraintFactory_fwd.hpp" |
| 22 |
#include "MueLu_DirectSolver_fwd.hpp" |
| 23 |
#include "MueLu_InitialBlockNumberFactory_fwd.hpp" |
| 24 |
#include "MueLu_LineDetectionFactory_fwd.hpp" |
| 25 |
#include "MueLu_NullspaceFactory_fwd.hpp" |
| 26 |
#include "MueLu_PatternFactory_fwd.hpp" |
| 27 |
#include "MueLu_RAPFactory_fwd.hpp" |
| 28 |
#include "MueLu_RepartitionHeuristicFactory_fwd.hpp" |
| 29 |
#include "MueLu_RepartitionFactory_fwd.hpp" |
| 30 |
#include "MueLu_SaPFactory_fwd.hpp" |
| 31 |
#include "MueLu_ScaledNullspaceFactory_fwd.hpp" |
| 32 |
#include "MueLu_SmootherFactory_fwd.hpp" |
| 33 |
#include "MueLu_StructuredAggregationFactory_fwd.hpp" |
| 34 |
#include "MueLu_TentativePFactory_fwd.hpp" |
| 35 |
#include "MueLu_TransPFactory_fwd.hpp" |
| 36 |
#include "MueLu_TrilinosSmoother_fwd.hpp" |
| 37 |
#include "MueLu_UncoupledAggregationFactory_fwd.hpp" |
| 38 |
#include "MueLu_ZoltanInterface_fwd.hpp" |
| 39 |
#include "MueLu_InterfaceMappingTransferFactory_fwd.hpp" |
| 40 |
#include "MueLu_InterfaceAggregationFactory_fwd.hpp" |
| 41 |
|
| 42 |
#include "MueLu_CoalesceDropFactory_kokkos_fwd.hpp" |
| 43 |
#include "MueLu_TentativePFactory_kokkos_fwd.hpp" |
| 44 |
|
| 45 |
namespace MueLu { |
| 46 |
|
| 47 |
/*! |
| 48 |
@class FactoryManager class. |
| 49 |
@brief This class specifies the default factory that should generate some data on a Level if the data does not exist and |
| 50 |
the generating factory has not been specified. |
| 51 |
|
| 52 |
Consider the following example. |
| 53 |
|
| 54 |
@code |
| 55 |
RCP<SingleLevelFactory> Afact; |
| 56 |
Level currentLevel; |
| 57 |
RCP<Matrix> thisLevelA; |
| 58 |
thisLevelA = currentLevel.Get<Matrix>("A", Afact.get()); |
| 59 |
@endcode |
| 60 |
|
| 61 |
@todo If Afact is null (actually, Teuchos::null), then the FactoryManager associated with currentLevel will determine whether a default factory has |
| 62 |
been specified for creating A. If "yes", then that factory will be called, A will be stored in currentLevel, and an RCP will be returned by |
| 63 |
the Get call. If "no", then the FactoryManager will <b>throw an exception indicating that it does not know how to generate A</b>. |
| 64 |
*/ |
| 65 |
|
| 66 |
template <class Scalar = DefaultScalar, |
| 67 |
class LocalOrdinal = DefaultLocalOrdinal, |
| 68 |
class GlobalOrdinal = DefaultGlobalOrdinal, |
| 69 |
class Node = DefaultNode> |
| 70 |
class FactoryManager : public FactoryManagerBase { |
| 71 |
#undef MUELU_FACTORYMANAGER_SHORT |
| 72 |
#include "MueLu_UseShortNames.hpp" |
| 73 |
|
| 74 |
public: |
| 75 |
//! @name Constructor/Destructors |
| 76 |
//@{ |
| 77 |
|
| 78 |
//! @brief Constructor. |
| 79 |
FactoryManager(); |
| 80 |
|
| 81 |
//! Constructor used by HierarchyFactory (temporary, will be removed) |
| 82 |
FactoryManager(const std::map<std::string, RCP<const FactoryBase> >& factoryTable); |
| 83 |
|
| 84 |
//! Destructor. |
| 85 |
virtual ~FactoryManager(); |
| 86 |
|
| 87 |
//@} |
| 88 |
|
| 89 |
//! @name Get/Set functions. |
| 90 |
//@{ |
| 91 |
|
| 92 |
/*! @brief Set Factory |
| 93 |
|
| 94 |
Register the factory that should generate data if said factory is not specified in the request. |
| 95 |
|
| 96 |
@param[in] name of variable |
| 97 |
@param[in] factory that generates the data |
| 98 |
*/ |
| 99 |
void SetFactory(const std::string& varName, const RCP<const FactoryBase>& factory); |
| 100 |
|
| 101 |
/*! @brief Get factory associated with a particular data name. |
| 102 |
|
| 103 |
@param[in] varName name of variable. |
| 104 |
|
| 105 |
*/ |
| 106 |
const RCP<const FactoryBase> GetFactory(const std::string& varName) const; |
| 107 |
|
| 108 |
/*! @brief Get factory associated with a particular data name (NONCONST version) |
| 109 |
|
| 110 |
@param[in] varName name of variable. |
| 111 |
|
| 112 |
*/ |
| 113 |
const RCP<FactoryBase> GetFactoryNonConst(const std::string& varName); |
| 114 |
|
| 115 |
//! Check |
| 116 |
// Return true if Factory associated with varName is registered |
| 117 |
bool hasFactory(const std::string& varName) const; |
| 118 |
|
| 119 |
//! |
| 120 |
const RCP<const FactoryBase> GetDefaultFactory(const std::string& varName) const; |
| 121 |
|
| 122 |
void SetKokkosRefactor(const bool useKokkos) { |
| 123 |
useKokkos_ = useKokkos; |
| 124 |
} |
| 125 |
|
| 126 |
bool GetKokkosRefactor() const { return useKokkos_; } |
| 127 |
|
| 128 |
//@} |
| 129 |
|
| 130 |
void Clean() const { defaultFactoryTable_.clear(); } |
| 131 |
|
| 132 |
#ifdef HAVE_MUELU_DEBUG |
| 133 |
void ResetDebugData() const; |
| 134 |
#endif |
| 135 |
|
| 136 |
void Print() const; |
| 137 |
|
| 138 |
private: |
| 139 |
//! @name Helper functions |
| 140 |
//@{ |
| 141 |
|
| 142 |
/*! Add a factory to the default factory list and return it. This helper function is used by GetDefaultFactory() |
| 143 |
|
| 144 |
@todo TODO factory->setObjectLabel("Default " + varName + "Factory"); |
| 145 |
*/ |
| 146 |
|
| 147 |
const RCP<const FactoryBase> SetAndReturnDefaultFactory(const std::string& varName, const RCP<const FactoryBase>& factory) const; |
| 148 |
//@} |
| 149 |
|
| 150 |
/*! @brief User-defined factories. |
| 151 |
* |
| 152 |
* User may overwrite default behaviour. The user provided factories are stored in a separate table. When we try to determine |
| 153 |
* which factory generates the data, this table is searched first. |
| 154 |
|
| 155 |
Note: we distinguish 'user defined factory' and 'default factory' to allow the deallocation of default factories separately. |
| 156 |
*/ |
| 157 |
std::map<std::string, RCP<const FactoryBase> > factoryTable_; |
| 158 |
|
| 159 |
/*! @brief Table that holds default factories. |
| 160 |
|
| 161 |
-# We distinguish 'user defined factory' and 'default factory' to allow the deallocation of default factories separately. |
| 162 |
-# <tt>defaultFactoryTable_</tt> is mutable because default factories are only added to the list when they are requested |
| 163 |
to avoid allocation of unused factories. |
| 164 |
*/ |
| 165 |
mutable std::map<std::string, RCP<const FactoryBase> > defaultFactoryTable_; |
| 166 |
|
| 167 |
//! Whether or not to use kokkos factories. |
| 168 |
bool useKokkos_; |
| 169 |
|
| 170 |
}; // class |
| 171 |
|
| 172 |
} // namespace MueLu |
| 173 |
|
| 174 |
#define MUELU_FACTORYMANAGER_SHORT |
| 175 |
#endif // MUELU_FACTORYMANAGER_DECL_HPP |