KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
preconditioner_factory.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 // Vicente Mataix Ferrandiz
12 //
13 
14 #if !defined(KRATOS_PRECONDITIONER_FACTORY_H_INCLUDED )
15 #define KRATOS_PRECONDITIONER_FACTORY_H_INCLUDED
16 
17 // System includes
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
26 #include "spaces/ublas_space.h"
27 
28 namespace Kratos
29 {
30 
33 
37 
41 
45 
49 
60 template< typename TSparseSpace, typename TLocalSpace>
62 {
63 public:
66 
69 
72 
75 
79 
81 
85 
89 
94  virtual bool Has(const std::string& rSolverType) const
95  {
96  return KratosComponents< FactoryType >::Has( rSolverType );
97  }
98 
103  virtual typename PreconditionerType::Pointer Create(const std::string& rPreconditionerType) const
104  {
105  // remove name of the application (if passed)
106  // e.g. "LinearSolversApplication.sparse_lu" => "sparse_lu"
107  const std::string raw_precond_name = rPreconditionerType.substr(rPreconditionerType.find('.') + 1);
108 
109  KRATOS_ERROR_IF_NOT(Has(raw_precond_name))
110  << "Trying to construct a preconditioner with preconditioner_type:\n\""
111  << raw_precond_name << "\" which does not exist.\n"
112  << "The list of available options (for currently loaded applications) is:\n"
113  << KratosComponents< FactoryType >() << std::endl;
114 
115  const auto& aux = KratosComponents< FactoryType >::Get(raw_precond_name);
116  return aux.CreatePreconditioner();
117  }
119 protected:
122 
127  virtual typename PreconditionerType::Pointer CreatePreconditioner() const
128  {
129  KRATOS_ERROR << "calling the base class PreconditionerFactory" << std::endl;
130  }
131 };
132 
136 
140 
142 template< typename TSparseSpace, typename TLocalSpace>
143 inline std::ostream& operator << (std::ostream& rOStream,
145 {
146  rOStream << "PreconditionerFactory" << std::endl;
147 
148  return rOStream;
149 }
150 
152 
153 typedef TUblasSparseSpace<double> SparseSpaceType;
154 typedef TUblasDenseSpace<double> LocalSparseSpaceType;
155 
157 
159 
160 #ifdef KRATOS_REGISTER_PRECONDITIONER
161 #undef KRATOS_REGISTER_PRECONDITIONER
162 #endif
163 #define KRATOS_REGISTER_PRECONDITIONER(name, reference) \
164  KratosComponents<PreconditionerFactoryType>::Add(name, reference);
165 
166 } // namespace Kratos.
167 
168 #endif // KRATOS_PRECONDITIONER_FACTORY_H_INCLUDED defined
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
static bool Has(const std::string &rName)
Check if the given name exists in the set of components.
Definition: kratos_components.h:161
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
Here we add the functions needed for the registration of preconditioners.
Definition: preconditioner_factory.h:62
virtual ~PreconditionerFactory()
Definition: preconditioner_factory.h:80
virtual bool Has(const std::string &rSolverType) const
This method checks if the linear solver is registered.
Definition: preconditioner_factory.h:94
virtual PreconditionerType::Pointer CreatePreconditioner() const
This method is an auxiliar method to create a new solver.
Definition: preconditioner_factory.h:127
PreconditionerFactory< TSparseSpace, TLocalSpace > FactoryType
The definition of the custom class.
Definition: preconditioner_factory.h:68
KRATOS_CLASS_POINTER_DEFINITION(PreconditionerFactory)
Pointer definition of PreconditionerFactory.
virtual PreconditionerType::Pointer Create(const std::string &rPreconditionerType) const
This method creates a new solver.
Definition: preconditioner_factory.h:103
Preconditioner< TSparseSpace, TLocalSpace > PreconditionerType
The definition of the preconditioner.
Definition: preconditioner_factory.h:71
Preconditioner class.
Definition: preconditioner.h:75
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_API_EXTERN
Definition: kratos_export_api.h:57
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
PreconditionerFactory< SparseSpaceType, LocalSparseSpaceType > PreconditionerFactoryType
Definition: preconditioner_factory.h:156
TUblasSparseSpace< double > SparseSpaceType
Definition: linear_solver_factory.h:154
TUblasDenseSpace< double > LocalSparseSpaceType
Definition: linear_solver_factory.h:155
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432