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.
linear_solver_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_LINEAR_SOLVER_FACTORY_H_INCLUDED )
15 #define KRATOS_LINEAR_SOLVER_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 
76 
78 
82 
86 
91  virtual bool Has(const std::string SolverType) const
92  {
94  }
95 
101  {
102  std::string solver_name = Settings["solver_type"].GetString();
103  // remove name of the application (if passed)
104  // e.g. "LinearSolversApplication.sparse_lu" => "sparse_lu"
105  solver_name = solver_name.substr(solver_name.find('.') + 1);
106 
107  KRATOS_ERROR_IF_NOT(Has(solver_name))
108  << "Trying to construct a Linear solver with solver_type:\n\""
109  << solver_name << "\" which does not exist.\n"
110  << "The list of available options (for currently loaded applications) is:\n"
111  << KratosComponents< FactoryType >() << std::endl;
112 
113  const auto& aux = KratosComponents< FactoryType >::Get(solver_name);
114  return aux.CreateSolver( Settings );
115  }
116 
118 protected:
121 
127  {
128  KRATOS_ERROR << "Calling the base class LinearSolverFactory" << std::endl;
129  }
130 
132 };
133 
135 
138 
142 
144 template< typename TSparseSpace, typename TLocalSpace>
145 inline std::ostream& operator << (std::ostream& rOStream,
147 {
148  rOStream << "LinearSolverFactory" << std::endl;
149 
150  return rOStream;
151 }
153 
156 
158 
160 
161 #ifdef KRATOS_REGISTER_LINEAR_SOLVER
162 #undef KRATOS_REGISTER_LINEAR_SOLVER
163 #endif
164 #define KRATOS_REGISTER_LINEAR_SOLVER(name, reference) \
165  KratosComponents<LinearSolverFactoryType>::Add(name, reference);
166 
169 
171 
173 
174 #ifdef KRATOS_REGISTER_COMPLEX_LINEAR_SOLVER
175 #undef KRATOS_REGISTER_COMPLEX_LINEAR_SOLVER
176 #endif
177 #define KRATOS_REGISTER_COMPLEX_LINEAR_SOLVER(name, reference) \
178  KratosComponents<ComplexLinearSolverFactoryType>::Add(name, reference);
179 
180 
181 } // namespace Kratos.
182 
183 #endif // KRATOS_LINEAR_SOLVER_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 linear solvers.
Definition: linear_solver_factory.h:62
KRATOS_CLASS_POINTER_DEFINITION(LinearSolverFactory)
Pointer definition of LinearSolverFactory.
virtual bool Has(const std::string SolverType) const
This method checks if the linear solver is registered.
Definition: linear_solver_factory.h:91
LinearSolverFactory< TSparseSpace, TLocalSpace > FactoryType
The definition of the custom class.
Definition: linear_solver_factory.h:68
virtual ~LinearSolverFactory()
Definition: linear_solver_factory.h:77
virtual LinearSolver< TSparseSpace, TLocalSpace >::Pointer CreateSolver(Kratos::Parameters Settings) const
This method is an auxiliar method to create a new solver.
Definition: linear_solver_factory.h:126
virtual LinearSolver< TSparseSpace, TLocalSpace >::Pointer Create(Kratos::Parameters Settings) const
This method creates a new solver.
Definition: linear_solver_factory.h:100
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
#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
TUblasSparseSpace< std::complex< double > > ComplexSparseSpaceType
Definition: linear_solver_factory.h:167
LinearSolverFactory< ComplexSparseSpaceType, ComplexLocalSparseSpaceType > ComplexLinearSolverFactoryType
Definition: linear_solver_factory.h:170
TUblasDenseSpace< std::complex< double > > ComplexLocalSparseSpaceType
Definition: linear_solver_factory.h:168
TUblasSparseSpace< double > SparseSpaceType
Definition: linear_solver_factory.h:154
LinearSolverFactory< SparseSpaceType, LocalSparseSpaceType > LinearSolverFactoryType
Definition: linear_solver_factory.h:157
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
string SolverType
Definition: fluid_only_var.py:5