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.
line_search_contact_strategy.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: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
21 #include "includes/define.h"
22 #include "includes/model_part.h"
23 #include "includes/variables.h"
29 
30 /* Convergence criterias */
32 
33 /* Default builder and solver */
35 
36 namespace Kratos
37 {
38 
41 
45 
49 
53 
57 
69 template<class TSparseSpace,
70  class TDenseSpace, // = DenseSpace<double>,
71  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
72  >
74  public LineSearchStrategy< TSparseSpace, TDenseSpace, TLinearSolver >
75 {
76 public:
79 
82 
85 
88 
91 
94 
97 
100 
102  using TDataType = typename BaseType::TDataType;
103 
105  using SparseSpaceType = TSparseSpace;
106 
109 
112 
115 
118 
121 
124 
127 
130 
133 
136 
138  using IndexType = std::size_t;
139 
144  {
145  }
146 
152  explicit LineSearchContactStrategy(ModelPart& rModelPart, Parameters ThisParameters)
153  : BaseType(rModelPart, BaseType::GetDefaultParameters())
154  {
155  // Validate and assign defaults
156  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
157  this->AssignSettings(ThisParameters);
158  }
159 
172  ModelPart& rModelPart,
173  typename TSchemeType::Pointer pScheme,
174  typename TLinearSolver::Pointer pNewLinearSolver,
175  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
176  IndexType MaxIterations = 30,
177  bool CalculateReactions = false,
178  bool ReformDofSetAtEachStep = false,
179  bool MoveMeshFlag = false,
180  Parameters ThisParameters = Parameters(R"({})")
181  )
182  : BaseType(rModelPart, pScheme, pNewLinearSolver, pNewConvergenceCriteria, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag)
183  {
184  KRATOS_TRY;
185 
186  Parameters default_parameters = this->GetDefaultParameters();
187 
188  ThisParameters.ValidateAndAssignDefaults(default_parameters);
189 
190  KRATOS_CATCH("");
191  }
192 
206  ModelPart& rModelPart,
207  typename TSchemeType::Pointer pScheme,
208  typename TLinearSolver::Pointer pNewLinearSolver,
209  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
210  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
211  IndexType MaxIterations = 30,
212  bool CalculateReactions = false,
213  bool ReformDofSetAtEachStep = false,
214  bool MoveMeshFlag = false,
215  Parameters ThisParameters = Parameters(R"({})")
216  )
217  : BaseType(rModelPart, pScheme, pNewLinearSolver, pNewConvergenceCriteria, pNewBuilderAndSolver, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag )
218  {
219  KRATOS_TRY;
220 
221  Parameters default_parameters = this->GetDefaultParameters();
222 
223  ThisParameters.ValidateAndAssignDefaults(default_parameters);
224 
225  KRATOS_CATCH("");
226  }
227 
233  = default;
234 
238 
242 
248  typename SolvingStrategyType::Pointer Create(
249  ModelPart& rModelPart,
250  Parameters ThisParameters
251  ) const override
252  {
253  return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
254  }
255 
261  {
262  Parameters default_parameters = Parameters(R"(
263  {
264  "name" : "line_search_contact_strategy"
265  })" );
266 
267  // Getting base class default parameters
268  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
269  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
270  return default_parameters;
271  }
272 
277  static std::string Name()
278  {
279  return "line_search_contact_strategy";
280  }
281 
285 
289 
293 
295  std::string Info() const override
296  {
297  return "LineSearchContactStrategy";
298  }
299 
301  void PrintInfo(std::ostream& rOStream) const override
302  {
303  rOStream << Info();
304  }
305 
307  void PrintData(std::ostream& rOStream) const override
308  {
309  rOStream << Info();
310  }
311 
315 
316 protected:
317 
320 
324 
325  bool mRecalculateFactor; // To check if we recalculate or not the scale factor
326 
330 
334 
340  void InitializeSolutionStep() override
341  {
343 
344  // TODO: Add something if necessary
345  }
346 
352  TSystemVectorType& Dx,
354  const bool MoveMesh
355  ) override
356  {
357  typename TSchemeType::Pointer pScheme = this->GetScheme();
358  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = this->GetBuilderAndSolver(); // FIXME: Separate in the parts of LM and displacement
359 
360  TSystemVectorType aux(b.size()); //TODO: do it by using the space
361  TSparseSpace::Assign(aux, 0.5, Dx);
362 
363  TSystemVectorType DxDisp(b.size());
364  TSystemVectorType DxLM(b.size());
365  ComputeSplitDx(Dx, DxDisp, DxLM);
366 
367  // Compute residual without update
368  TSparseSpace::SetToZero(b);
369  pBuilderAndSolver->BuildRHS(pScheme, BaseType::GetModelPart(), b );
370  double roDisp;
371  double roLM;
372  ComputeMixedResidual(b, roDisp, roLM);
373 
374  // Compute half step residual
376  TSparseSpace::SetToZero(b);
377  pBuilderAndSolver->BuildRHS(pScheme, BaseType::GetModelPart(), b );
378  double rhDisp;
379  double rhLM;
380  ComputeMixedResidual(b, rhDisp, rhLM);
381 
382  // Compute full step residual (add another half Dx to the previous half)
384  TSparseSpace::SetToZero(b);
385  pBuilderAndSolver->BuildRHS(pScheme, BaseType::GetModelPart(), b );
386  double rfDisp;
387  double rfLM;
388  ComputeMixedResidual(b, rfDisp, rfLM);
389 
390  // We compute the parabola
391  double XminDisp = 1e-3;
392  double XmaxDisp = 1.0;
393  double XminLM = 1e-3;
394  double XmaxLM = 1.0;
395 
396  ComputeParabola(XminDisp, XmaxDisp, rfDisp, roDisp, rhDisp);
397  ComputeParabola(XminLM, XmaxLM, rfLM, roLM, rhLM);
398 
399  // Perform final update
400  TSparseSpace::Assign(aux,-(1.0 - XmaxDisp), DxDisp);
401  TSparseSpace::UnaliasedAdd(aux,-(1.0 - XmaxLM), DxLM);
403  }
404 
412  TSystemVectorType& Dx,
413  TSystemVectorType& DxDisp,
414  TSystemVectorType& DxLM
415  )
416  {
417  // Now we iterate over all the nodes
419  block_for_each(r_nodes_array, [&](Node& rNode) {
420  for(auto itDoF = rNode.GetDofs().begin() ; itDoF != rNode.GetDofs().end() ; itDoF++) {
421  const int j = (**itDoF).EquationId();
422  const std::size_t CurrVar = (**itDoF).GetVariable().Key();
423 
424  if ((CurrVar == DISPLACEMENT_X) || (CurrVar == DISPLACEMENT_Y) || (CurrVar == DISPLACEMENT_Z)) {
425  DxDisp[j] = Dx[j];
426  DxLM[j] = 0.0;
427  } else { // Corresponding with contact
428  DxDisp[j] = 0.0;
429  DxLM[j] = Dx[j];
430  }
431  }
432  });
433  }
434 
443  double& normDisp,
444  double& normLM
445  )
446  {
447  // Now we iterate over all the nodes
448  NodesArrayType& r_nodes_array = StrategyBaseType::GetModelPart().Nodes();
449  block_for_each(r_nodes_array, [&](Node& rNode) {
450  for(auto itDoF = rNode.GetDofs().begin() ; itDoF != rNode.GetDofs().end() ; itDoF++) {
451  const int j = (**itDoF).EquationId();
452  const std::size_t CurrVar = (**itDoF).GetVariable().Key();
453 
454  if ((CurrVar == DISPLACEMENT_X) || (CurrVar == DISPLACEMENT_Y) || (CurrVar == DISPLACEMENT_Z)) {
455  AtomicAdd(normDisp, b[j] * b[j]);
456  } else { // Corresponding with contact
457  AtomicAdd(normLM, b[j] * b[j]);
458  }
459  }
460  });
461 
462  normDisp = std::sqrt(normDisp);
463  normLM = std::sqrt(normLM);
464  }
465 
475  double& Xmax,
476  double& Xmin,
477  const double rf,
478  const double ro,
479  const double rh
480  )
481  {
482  // Compute optimal (limited to the range 0-1)
483  // Parabola is y = a*x^2 + b*x + c -> min/max for
484  // x=0 --> r=ro
485  // x=1/2 --> r=rh
486  // x=1 --> r =
487  // c= ro, b= 4*rh -rf -3*ro, a= 2*rf - 4*rh + 2*ro
488  // max found if a>0 at the position Xmax = (rf/4 - rh)/(rf - 2*rh);
489 
490  const double parabole_a = 2 * rf + 2 * ro - 4 * rh;
491  const double parabole_b = 4 * rh - rf - 3 * ro;
492 
493  if( parabole_a > 0.0) // If parabola has a local minima
494  {
495  Xmax = -0.5 * parabole_b/parabole_a; // -b / 2a
496  if( Xmax > 1.0)
497  Xmax = 1.0;
498  else if(Xmax < -1.0)
499  Xmax = -1.0;
500  }
501  else // Parabola degenerates to either a line or to have a local max. best solution on either extreme
502  {
503  if(rf < ro)
504  Xmax = 1.0;
505  else
506  Xmax = Xmin; // Should be zero, but otherwise it will stagnate
507  }
508  }
509 
514  void AssignSettings(const Parameters ThisParameters) override
515  {
516  BaseType::AssignSettings(ThisParameters);
517  }
518 
522 
526 
531 
537  {
538  };
539 
540 private:
541 
544 
548 
552 
556 
561 
565 
572 
573 }; /* Class LineSearchContactStrategy */
581 } // namespace Kratos
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
BaseType::NodesArrayType NodesArrayType
Definition: implicit_solving_strategy.h:92
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: implicit_solving_strategy.h:76
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: implicit_solving_strategy.h:74
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: implicit_solving_strategy.h:80
BaseType::ConditionsArrayType ConditionsArrayType
Definition: implicit_solving_strategy.h:96
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: implicit_solving_strategy.h:78
BaseType::TDataType TDataType
Definition: implicit_solving_strategy.h:68
A strategy for solving contact problems using a line search method.
Definition: line_search_contact_strategy.h:75
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: line_search_contact_strategy.h:307
~LineSearchContactStrategy() override=default
void ComputeSplitDx(TSystemVectorType &Dx, TSystemVectorType &DxDisp, TSystemVectorType &DxLM)
Definition: line_search_contact_strategy.h:411
LineSearchContactStrategy()
Default constructor.
Definition: line_search_contact_strategy.h:143
void InitializeSolutionStep() override
Definition: line_search_contact_strategy.h:340
std::string Info() const override
Turn back information as a string.
Definition: line_search_contact_strategy.h:295
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: line_search_contact_strategy.h:514
std::size_t IndexType
Index type definition.
Definition: line_search_contact_strategy.h:138
void ComputeParabola(double &Xmax, double &Xmin, const double rf, const double ro, const double rh)
Definition: line_search_contact_strategy.h:474
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: line_search_contact_strategy.h:277
void ComputeMixedResidual(TSystemVectorType &b, double &normDisp, double &normLM)
Definition: line_search_contact_strategy.h:441
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: line_search_contact_strategy.h:248
void UpdateDatabase(TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b, const bool MoveMesh) override
Definition: line_search_contact_strategy.h:350
LineSearchContactStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, IndexType MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false, Parameters ThisParameters=Parameters(R"({})"))
Definition: line_search_contact_strategy.h:171
KRATOS_CLASS_POINTER_DEFINITION(LineSearchContactStrategy)
Pointer definition of LineSearchContactStrategy.
bool mRecalculateFactor
Definition: line_search_contact_strategy.h:325
LineSearchContactStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: line_search_contact_strategy.h:152
LineSearchContactStrategy(const LineSearchContactStrategy &Other)
Definition: line_search_contact_strategy.h:536
LineSearchContactStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, IndexType MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false, Parameters ThisParameters=Parameters(R"({})"))
Definition: line_search_contact_strategy.h:205
Parameters GetDefaultParameters() const override
This method returns the defaulr parameters in order to avoid code duplication.
Definition: line_search_contact_strategy.h:260
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: line_search_contact_strategy.h:301
Short class definition.
Definition: line_search_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: line_search_strategy.h:109
BaseType::TSystemVectorType TSystemVectorType
Definition: line_search_strategy.h:111
TSparseSpace SparseSpaceType
Definition: line_search_strategy.h:101
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: line_search_strategy.h:306
BaseType::DofsArrayType DofsArrayType
Definition: line_search_strategy.h:107
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: line_search_strategy.h:113
BaseType::TSchemeType TSchemeType
Definition: line_search_strategy.h:103
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: line_search_strategy.h:97
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: line_search_strategy.h:115
BaseType::TDataType TDataType
Definition: line_search_strategy.h:99
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: line_search_strategy.h:118
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: line_search_strategy.h:117
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
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
DofsContainerType & GetDofs()
Definition: node.h:694
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 the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Get method for the builder and solver.
Definition: residualbased_newton_raphson_strategy.h:493
virtual void UpdateDatabase(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, const bool MoveMesh)
Here the database is updated.
Definition: residualbased_newton_raphson_strategy.h:1278
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_newton_raphson_strategy.h:475
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: residualbased_newton_raphson_strategy.h:781
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
Solving strategy base class This is the base class from which we will derive all the strategies (impl...
Definition: solving_strategy.h:64
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: solving_strategy.h:507
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
virtual void MoveMesh()
This function is designed to move the mesh.
Definition: solving_strategy.h:330
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
void Assign(const Expression &rExpression, const IndexType EntityIndex, const IndexType EntityDataBeginIndex, TDataType &rValue, std::index_sequence< TIndex... >)
Definition: variable_expression_data_io.cpp:41
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
A
Definition: sensitivityMatrix.py:70
e
Definition: run_cpp_mpi_tests.py:31