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.
error_mesh_criteria.h
Go to the documentation of this file.
1 // KRATOS ___| | | |
2 // \___ \ __| __| | | __| __| | | __| _` | |
3 // | | | | | ( | | | | ( | |
4 // _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS
5 //
6 // License: BSD License
7 // license: StructuralMechanicsApplication/license.txt
8 //
9 // Main authors: Anna Rehr
10 // Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
20 #include "includes/model_part.h"
24 
25 // Processes
27 
28 namespace Kratos
29 {
32 
35 
39 
43 
47 
51 
61 template<class TSparseSpace, class TDenseSpace>
63  : public ConvergenceCriteria< TSparseSpace, TDenseSpace >
64 {
65 public:
68 
70 
72 
73  typedef TSparseSpace SparseSpaceType;
74 
75  typedef typename BaseType::TDataType TDataType;
76 
78 
80 
82 
84 
86 
87  typedef std::size_t KeyType;
88 
89  typedef std::size_t SizeType;
90 
94 
98 
100  explicit ErrorMeshCriteria(Parameters ThisParameters = Parameters(R"({})"))
101  : ConvergenceCriteria< TSparseSpace, TDenseSpace >(),
102  mThisParameters(ThisParameters)
103  {
111  Parameters default_parameters = Parameters(R"(
112  {
113  "error_mesh_tolerance" : 5.0e-3,
114  "error_mesh_constant" : 5.0e-3,
115  "compute_error_extra_parameters":
116  {
117  "echo_level" : 0
118  }
119  })" );
120 
121  mThisParameters.ValidateAndAssignDefaults(default_parameters);
122 
123  mErrorTolerance = mThisParameters["error_mesh_tolerance"].GetDouble();
124  mConstantError = mThisParameters["error_mesh_constant"].GetDouble();
125 
126  }
127 
130  :BaseType(rOther)
131  ,mErrorTolerance(rOther.mErrorTolerance)
132  ,mConstantError(rOther.mConstantError)
133  {
134  }
135 
137  ~ErrorMeshCriteria() override = default;
138 
142 
147  void Initialize(ModelPart& rModelPart) override
148  {
149  BaseType::Initialize(rModelPart);
150  }
151 
162  ModelPart& rModelPart,
163  DofsArrayType& rDofSet,
164  const TSystemMatrixType& A,
165  const TSystemVectorType& Dx,
166  const TSystemVectorType& b
167  ) override
168  {
169  // The process info
170  const ProcessInfo& process_info = rModelPart.GetProcessInfo();
171 
172  // Computing error
173  if (process_info[DOMAIN_SIZE] == 2) {
174  SPRErrorProcess<2> compute_error_process = SPRErrorProcess<2>(rModelPart, mThisParameters["compute_error_extra_parameters"]);
175  compute_error_process.Execute();
176  } else {
177  SPRErrorProcess<3> compute_error_process = SPRErrorProcess<3>(rModelPart, mThisParameters["compute_error_extra_parameters"]);
178  compute_error_process.Execute();
179  }
180 
181  // We get the estimated error
182  const double estimated_error = process_info[ERROR_RATIO];
183 
184  // We check if converged
185  const bool converged_error = (estimated_error > mErrorTolerance) ? false : true;
186 
187  if (converged_error) {
188  KRATOS_INFO_IF("ErrorMeshCriteria", rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) << "NL ITERATION: " << process_info[NL_ITERATION_NUMBER] << "\tThe error due to the mesh size: " << estimated_error << " is under the tolerance prescribed: " << mErrorTolerance << ". " << BOLDFONT(FGRN("No remeshing required")) << std::endl;
189  } else {
190  KRATOS_INFO_IF("ErrorMeshCriteria", rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0)
191  << "NL ITERATION: " << process_info[NL_ITERATION_NUMBER] << "\tThe error due to the mesh size: " << estimated_error << " is bigger than the tolerance prescribed: " << mErrorTolerance << ". "<< BOLDFONT(FRED("Remeshing required")) << std::endl;
192  }
193 
194  return converged_error;
195  }
196 
200 
204 
208 
212 
213 protected:
214 
217 
221 
225 
229 
233 
237 
242 
243 private:
246 
250 
251  Parameters mThisParameters;
252 
253  double mErrorTolerance;
254  double mConstantError;
255 
259 
263 
268 
272 
276 
280 
281 }; // Class ErrorMeshCriteria
282 
285 
286 } // namespace Kratos
287 
virtual int MyPID() const
Definition: communicator.cpp:91
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
virtual void Initialize(ModelPart &rModelPart)
This function initialize the convergence criteria.
Definition: convergence_criteria.h:276
TSparseSpace::DataType TDataType
Data type definition.
Definition: convergence_criteria.h:70
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
Custom convergence for used to check the convergence in the mesh error.
Definition: error_mesh_criteria.h:64
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
This class is can be used to compute the metrics of the model part with a superconvergent patch recov...
Definition: spr_error_process.h:63
void Execute() override
We initialize the metrics of the MMG sol using the Hessian metric matrix approach.
Definition: spr_error_process.cpp:42
#define FGRN(x)
Definition: color_utilities.h:27
#define FRED(x)
Definition: color_utilities.h:26
#define BOLDFONT(x)
Definition: color_utilities.h:34
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: error_mesh_criteria.h:83
KRATOS_CLASS_POINTER_DEFINITION(ErrorMeshCriteria)
ErrorMeshCriteria(Parameters ThisParameters=Parameters(R"({})"))
Default constructors.
Definition: error_mesh_criteria.h:100
ModelPart::NodesContainerType NodesArrayType
Definition: error_mesh_criteria.h:85
TSparseSpace SparseSpaceType
Definition: error_mesh_criteria.h:73
BaseType::TSystemVectorType TSystemVectorType
Definition: error_mesh_criteria.h:81
ErrorMeshCriteria(ErrorMeshCriteria const &rOther)
Copy constructor.
Definition: error_mesh_criteria.h:129
BaseType::DofsArrayType DofsArrayType
Definition: error_mesh_criteria.h:77
ConvergenceCriteria< TSparseSpace, TDenseSpace > BaseType
Definition: error_mesh_criteria.h:71
~ErrorMeshCriteria() override=default
Destructor.
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &A, const TSystemVectorType &Dx, const TSystemVectorType &b) override
Compute relative and absolute error.
Definition: error_mesh_criteria.h:161
std::size_t SizeType
Definition: error_mesh_criteria.h:89
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: error_mesh_criteria.h:147
BaseType::TDataType TDataType
Definition: error_mesh_criteria.h:75
std::size_t KeyType
Definition: error_mesh_criteria.h:87
BaseType::TSystemMatrixType TSystemMatrixType
Definition: error_mesh_criteria.h:79
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
A
Definition: sensitivityMatrix.py:70