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.
trilinos_residual_criteria.h
Go to the documentation of this file.
1 // KRATOS _____ _ _ _
2 // |_ _| __(_) (_)_ __ ___ ___
3 // | || '__| | | | '_ \ / _ \/ __|
4 // | || | | | | | | | | (_) \__
5 // |_||_| |_|_|_|_| |_|\___/|___/ APPLICATION
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Jordi Cotela
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
21 
22 namespace Kratos
23 {
26 
29 
38 template<class TSparseSpace,
39  class TDenseSpace
40  >
42  : public ResidualCriteria< TSparseSpace, TDenseSpace >
43 {
44 public:
47 
50 
53 
56 
59 
61  using TDataType = typename BaseType::TDataType;
62 
65 
67  using DofType = typename Node::DofType;
68 
71 
74 
76  using IndexType = std::size_t;
77 
81 
84  : BaseType()
85  {
86  }
87 
93  : BaseType(ThisParameters)
94  {
95  }
96 
102  explicit TrilinosResidualCriteria(TDataType NewRatioTolerance,TDataType AlwaysConvergedNorm):
103  BaseType(NewRatioTolerance, AlwaysConvergedNorm)
104  {
105  }
106 
112  BaseType(rOther)
113  {
114  }
115 
118 
122 
125 
129 
134  typename BaseConvergenceCriteriaType::Pointer Create(Parameters ThisParameters) const override
135  {
136  return Kratos::make_shared<ClassType>(ThisParameters);
137  }
138 
148  ModelPart& rModelPart,
149  DofsArrayType& rDofSet,
150  const TSystemMatrixType& rA,
151  const TSystemVectorType& rDx,
152  const TSystemVectorType& rb
153  ) override
154  {
155  // We set the initial Id
156  const auto& r_data_communicator = rModelPart.GetCommunicator().GetDataCommunicator();
157  const int rank = r_data_communicator.Rank();
158  for (auto& r_dof : rDofSet) {
159  if (r_dof.GetSolutionStepValue(PARTITION_INDEX) == rank) {
160  BaseType::mInitialDoFId = r_dof.EquationId();
161  break;
162  }
163  }
164 
165  // Calling base class
166  BaseType::InitializeSolutionStep(rModelPart, rDofSet, rA, rDx, rb);
167  }
168 
174  {
175  Parameters default_parameters = Parameters(R"(
176  {
177  "name" : "trilinos_residual_criteria",
178  "residual_absolute_tolerance" : 1.0e-4,
179  "residual_relative_tolerance" : 1.0e-9
180  })");
181 
182  // Getting base class default parameters
183  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
184  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
185  return default_parameters;
186  }
187 
192  static std::string Name()
193  {
194  return "trilinos_residual_criteria";
195  }
196 
200 
204 
208 
210  std::string Info() const override
211  {
212  return "TrilionosResidualCriteria";
213  }
214 
216  void PrintInfo(std::ostream& rOStream) const override
217  {
218  rOStream << Info();
219  }
220 
222  void PrintData(std::ostream& rOStream) const override
223  {
224  rOStream << Info();
225  }
226 
230 
232 protected:
235 
242  ModelPart& rModelPart,
243  const ModelPart::DofsArrayType& rDofSet
244  ) override
245  {
246  // Filling mActiveDofs when MPC exist
248  }
249 
251 }; // Class TrilinosResidualCriteria
252 
254 
256 
257 } // namespace Kratos.
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
TSparseSpace::DataType TDataType
Data type definition.
Definition: convergence_criteria.h:70
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
Dof< double > DofType
Dof type.
Definition: node.h:83
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void RecursivelyAddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1457
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
This is a convergence criteria that considers the residual as criteria.
Definition: residual_criteria.h:60
std::size_t IndexType
Definition of the IndexType.
Definition: residual_criteria.h:90
typename BaseType::TDataType TDataType
The data type.
Definition: residual_criteria.h:75
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: residual_criteria.h:87
IndexType mInitialDoFId
This vector contains the dofs that are active.
Definition: residual_criteria.h:355
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: residual_criteria.h:234
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: residual_criteria.h:84
std::vector< int > mActiveDofs
The norm at the beginning of the iterations.
Definition: residual_criteria.h:353
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residual_criteria.h:276
typename Node::DofType DofType
The definition of the DoF data type.
Definition: residual_criteria.h:81
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: residual_criteria.h:78
MPI version of the ResidualCriteria.
Definition: trilinos_residual_criteria.h:43
TrilinosResidualCriteria(const TrilinosResidualCriteria &rOther)
Copy constructor.
Definition: trilinos_residual_criteria.h:111
KRATOS_CLASS_POINTER_DEFINITION(TrilinosResidualCriteria)
Pointer definition of TrilinosResidualCriteria.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: trilinos_residual_criteria.h:216
void ComputeActiveDofs(ModelPart &rModelPart, const ModelPart::DofsArrayType &rDofSet) override
This method computes the active dofs.
Definition: trilinos_residual_criteria.h:241
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: trilinos_residual_criteria.h:173
TrilinosResidualCriteria()
Default constructor.
Definition: trilinos_residual_criteria.h:83
BaseConvergenceCriteriaType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: trilinos_residual_criteria.h:134
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: trilinos_residual_criteria.h:147
std::string Info() const override
Turn back information as a string.
Definition: trilinos_residual_criteria.h:210
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: trilinos_residual_criteria.h:222
~TrilinosResidualCriteria() override
Destructor.
Definition: trilinos_residual_criteria.h:117
TrilinosResidualCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: trilinos_residual_criteria.h:92
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: trilinos_residual_criteria.h:192
TrilinosResidualCriteria(TDataType NewRatioTolerance, TDataType AlwaysConvergedNorm)
Constructor 2 arguments.
Definition: trilinos_residual_criteria.h:102
TrilinosResidualCriteria & operator=(TrilinosResidualCriteria const &rOther)=delete
Deleted assignment operator.
void DistributedComputeActiveDofs(ModelPart &rModelPart, std::vector< int > &rActiveDofs, const ModelPart::DofsArrayType &rDofSet, const std::size_t InitialDofId)
This method computes the active dofs.
Definition: constraint_utilities.cpp:70
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21