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.
contact_error_mesh_criteria.h
Go to the documentation of this file.
1 // KRATOS ______ __ __ _____ __ __ __
2 // / ____/___ ____ / /_____ ______/ /_/ ___// /________ _______/ /___ ___________ _/ /
3 // / / / __ \/ __ \/ __/ __ `/ ___/ __/\__ \/ __/ ___/ / / / ___/ __/ / / / ___/ __ `/ /
4 // / /___/ /_/ / / / / /_/ /_/ / /__/ /_ ___/ / /_/ / / /_/ / /__/ /_/ /_/ / / / /_/ / /
5 // \____/\____/_/ /_/\__/\__,_/\___/\__//____/\__/_/ \__,_/\___/\__/\__,_/_/ \__,_/_/ MECHANICS
6 //
7 // License: BSD License
8 // license: ContactStructuralMechanicsApplication/license.txt
9 //
10 // Main authors: Anna Rehr
11 // Vicente Mataix Ferrandiz
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "includes/model_part.h"
26 
27 // Processes
29 
30 namespace Kratos
31 {
34 
37 
41 
45 
49 
53 
63 template<class TSparseSpace, class TDenseSpace>
65  : public ConvergenceCriteria< TSparseSpace, TDenseSpace >
66 {
67 public:
70 
73 
76 
79 
82 
85 
88 
92 
96 
101  : BaseType()
102  {
103  }
104 
106  explicit ContactErrorMeshCriteria(Parameters ThisParameters)
107  : BaseType()
108  {
109  // Validate and assign defaults
110  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
111  this->AssignSettings(ThisParameters);
112  }
113 
116  :BaseType(rOther)
117  ,mErrorTolerance(rOther.mErrorTolerance)
118  ,mConstantError(rOther.mConstantError)
119  {
120  }
121 
123  ~ContactErrorMeshCriteria() override = default;
124 
128 
132 
137  typename BaseType::Pointer Create(Parameters ThisParameters) const override
138  {
139  return Kratos::make_shared<ClassType>(ThisParameters);
140  }
141 
146  void Initialize(ModelPart& rModelPart) override
147  {
148  BaseType::Initialize(rModelPart);
149 
150  // Update normal of the conditions
151  ModelPart& r_contact_model_part = rModelPart.GetSubModelPart("Contact");
152  VariableUtils().SetFlag(CONTACT, true, r_contact_model_part.Nodes());
153  VariableUtils().SetFlag(CONTACT, true, r_contact_model_part.Conditions());
154  }
155 
166  ModelPart& rModelPart,
167  DofsArrayType& rDofSet,
168  const TSystemMatrixType& rA,
169  const TSystemVectorType& rDx,
170  const TSystemVectorType& rb
171  ) override
172  {
173  // The process info
174  const ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
175 
176  // Computing error
177  if (r_process_info[DOMAIN_SIZE] == 2) {
178  auto compute_error_process = ContactSPRErrorProcess<2>(rModelPart, mThisParameters["compute_error_extra_parameters"]);
179  compute_error_process.Execute();
180  } else {
181  auto compute_error_process = ContactSPRErrorProcess<3>(rModelPart, mThisParameters["compute_error_extra_parameters"]);
182  compute_error_process.Execute();
183  }
184 
185  // We get the estimated error
186  const double estimated_error = r_process_info[ERROR_RATIO];
187 
188  // We check if converged
189  const bool converged_error = (estimated_error > mErrorTolerance) ? false : true;
190 
191  if (converged_error) {
192  KRATOS_INFO_IF("ContactErrorMeshCriteria", rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) << "NL ITERATION: " << r_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;
193  } else {
194  KRATOS_INFO_IF("ContactErrorMeshCriteria", rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0)
195  << "NL ITERATION: " << r_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;
196  }
197 
198  return converged_error;
199  }
200 
206  {
207  Parameters default_parameters = Parameters(R"(
208  {
209  "name" : "contact_error_mesh_criteria",
210  "error_mesh_tolerance" : 5.0e-3,
211  "error_mesh_constant" : 5.0e-3,
212  "compute_error_extra_parameters":
213  {
214  "penalty_normal" : 1.0e4,
215  "penalty_tangential" : 1.0e4,
216  "echo_level" : 0
217  }
218  })" );
219 
220  // Getting base class default parameters
221  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
222  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
223  return default_parameters;
224  }
225 
230  static std::string Name()
231  {
232  return "contact_error_mesh_criteria";
233  }
234 
238 
242 
246 
248  std::string Info() const override
249  {
250  return "ContactErrorMeshCriteria";
251  }
252 
254  void PrintInfo(std::ostream& rOStream) const override
255  {
256  rOStream << Info();
257  }
258 
260  void PrintData(std::ostream& rOStream) const override
261  {
262  rOStream << Info();
263  }
264 
266 protected:
269 
273 
277 
281 
286  void AssignSettings(const Parameters ThisParameters) override
287  {
288  BaseType::AssignSettings(ThisParameters);
289  mThisParameters = ThisParameters;
290  mErrorTolerance = mThisParameters["error_mesh_tolerance"].GetDouble();
291  mConstantError = mThisParameters["error_mesh_constant"].GetDouble();
292  }
293 
295 private:
298 
302 
303  Parameters mThisParameters;
304 
305  double mErrorTolerance;
306  double mConstantError;
307 
309 }; // Class ContactErrorMeshCriteria
310 
313 
314 } // namespace Kratos
315 
virtual int MyPID() const
Definition: communicator.cpp:91
Custom convergence for used to check the convergence in the mesh error.
Definition: contact_error_mesh_criteria.h:66
This class is can be used to compute the metrics of the model part with a superconvergent patch recov...
Definition: contact_spr_error_process.h:62
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: convergence_criteria.h:466
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
ModelPart::DofsArrayType DofsArrayType
DoF array type definition.
Definition: convergence_criteria.h:81
virtual Parameters GetDefaultParameters() const
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: convergence_criteria.h:384
virtual void Initialize(ModelPart &rModelPart)
This function initialize the convergence criteria.
Definition: convergence_criteria.h:276
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: convergence_criteria.h:479
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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 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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetFlag(const Flags &rFlag, const bool FlagValue, TContainerType &rContainer)
Sets a flag according to a given status over a given container.
Definition: variable_utils.h:900
#define FGRN(x)
Definition: color_utilities.h:27
#define FRED(x)
Definition: color_utilities.h:26
#define BOLDFONT(x)
Definition: color_utilities.h:34
KRATOS_CLASS_POINTER_DEFINITION(ContactErrorMeshCriteria)
Pointer definition of ContactErrorMeshCriteria.
~ContactErrorMeshCriteria() override=default
Destructor.
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: contact_error_mesh_criteria.h:81
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: contact_error_mesh_criteria.h:87
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: contact_error_mesh_criteria.h:165
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: contact_error_mesh_criteria.h:84
std::string Info() const override
Turn back information as a string.
Definition: contact_error_mesh_criteria.h:248
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: contact_error_mesh_criteria.h:260
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: contact_error_mesh_criteria.h:137
ContactErrorMeshCriteria(Parameters ThisParameters)
Default constructors.
Definition: contact_error_mesh_criteria.h:106
ContactErrorMeshCriteria(ContactErrorMeshCriteria const &rOther)
Copy constructor.
Definition: contact_error_mesh_criteria.h:115
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: contact_error_mesh_criteria.h:254
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: contact_error_mesh_criteria.h:286
ContactErrorMeshCriteria()
Default constructor.
Definition: contact_error_mesh_criteria.h:100
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: contact_error_mesh_criteria.h:205
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: contact_error_mesh_criteria.h:146
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: contact_error_mesh_criteria.h:230
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21