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_residualbased_elimination_builder_and_solver.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 
14 #pragma once
15 
16 // System includes
17 #include <unordered_set>
18 #include <unordered_map>
19 
20 // External includes
21 
22 // Project includes
24 
25 namespace Kratos
26 {
27 
30 
34 
38 
42 
46 
57 template<class TSparseSpace,
58  class TDenseSpace, //= DenseSpace<double>,
59  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
60  >
62  : public ResidualBasedEliminationBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
63 {
64 public:
67 
70 
73 
76 
79 
82  using TDataType = typename BaseType::TDataType;
86 
88  using DofType = typename ModelPart::DofType;
89 
91  using SizeType = std::size_t;
92 
94  using IndexType= std::size_t;
95 
97  using IndexSetType = std::unordered_set<IndexType>;
98 
102 
106 
107 
112  {
113  }
114 
119  typename TLinearSolver::Pointer pNewLinearSystemSolver,
120  Parameters ThisParameters
121  ) : BaseType(pNewLinearSystemSolver)
122  {
123  // Validate and assign defaults
124  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
125  this->AssignSettings(ThisParameters);
126  }
127 
131  typename TLinearSolver::Pointer pNewLinearSystemSolver)
132  : BaseType(pNewLinearSystemSolver)
133  {
134  }
135 
139  {
140  }
141 
145 
149 
155  typename BaseBuilderAndSolverType::Pointer Create(
156  typename TLinearSolver::Pointer pNewLinearSystemSolver,
157  Parameters ThisParameters
158  ) const override
159  {
160  return Kratos::make_shared<ClassType>(pNewLinearSystemSolver,ThisParameters);
161  }
162 
168  ModelPart& rModelPart
169  ) override
170  {
175  // We create a set of dofs of the displacement slave dofs with LM associated
176  std::unordered_map<IndexType, IndexSetType> set_nodes_with_lm_associated;
177  if (rModelPart.HasSubModelPart("Contact"))
178  set_nodes_with_lm_associated.reserve(rModelPart.GetSubModelPart("Contact").NumberOfNodes());
179  // Allocating auxiliary parameters
181  // We start the dof loop
182  for (auto& i_dof : BaseType::mDofSet) {
183  node_id = i_dof.Id();
184  if (IsLMDof(i_dof))
185  set_nodes_with_lm_associated.insert({node_id, IndexSetType({})});
186  }
187 
188  // Auxiliary keys
189  const IndexType key_lm_x = VECTOR_LAGRANGE_MULTIPLIER_X.Key();
190  const IndexType key_lm_y = VECTOR_LAGRANGE_MULTIPLIER_Y.Key();
191  const IndexType key_lm_z = VECTOR_LAGRANGE_MULTIPLIER_Z.Key();
192 
193  // We see which LM block
194  for (auto& i_dof : BaseType::mDofSet) {
195  node_id = i_dof.Id();
196  auto it = set_nodes_with_lm_associated.find(node_id);
197  if ( it != set_nodes_with_lm_associated.end()) {
198  const auto& r_variable = i_dof.GetVariable();
199  auto& aux_set = (it->second);
200  if (i_dof.IsFixed()) {
201  if (r_variable == DISPLACEMENT_X) {
202  aux_set.insert(key_lm_x);
203  } else if (r_variable == DISPLACEMENT_Y) {
204  aux_set.insert(key_lm_y);
205  } else if (r_variable == DISPLACEMENT_Z) {
206  aux_set.insert(key_lm_z);
207  }
208  }
209  }
210  }
211 
212  // We do now the loop over the dofs
213  for (auto& i_dof : BaseType::mDofSet) {
214  if (i_dof.IsFree()) {
215  node_id = i_dof.Id();
216  auto it = set_nodes_with_lm_associated.find(node_id);
217  if (it != set_nodes_with_lm_associated.end()) {
218  auto& aux_set = it->second;
219  if (aux_set.find((i_dof.GetVariable()).Key()) != aux_set.end()) {
220  i_dof.FixDof();
221  }
222  }
223  }
224  }
225 
226  BaseType::SetUpSystem(rModelPart);
227  }
228 
234  {
235  Parameters default_parameters = Parameters(R"(
236  {
237  "name" : "contact_residual_elimination_builder_and_solver"
238  })");
239 
240  // Getting base class default parameters
241  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
242  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
243  return default_parameters;
244  }
245 
250  static std::string Name()
251  {
252  return "contact_residual_elimination_builder_and_solver";
253  }
254 
258 
262 
266 
268 
269 protected:
272 
276 
280 
284 
289  void AssignSettings(const Parameters ThisParameters) override
290  {
291  BaseType::AssignSettings(ThisParameters);
292  }
293 
297 
301 
305 
307 private:
310 
314 
318 
322 
328  static inline bool IsDisplacementDof(const DofType& rDoF)
329  {
330  const auto& r_variable = rDoF.GetVariable();
331  if (r_variable == DISPLACEMENT_X ||
332  r_variable == DISPLACEMENT_Y ||
333  r_variable == DISPLACEMENT_Z) {
334  return true;
335  }
336 
337  return false;
338  }
339 
345  static inline bool IsLMDof(const DofType& rDoF)
346  {
347  const auto& r_variable = rDoF.GetVariable();
348  if (r_variable == VECTOR_LAGRANGE_MULTIPLIER_X ||
349  r_variable == VECTOR_LAGRANGE_MULTIPLIER_Y ||
350  r_variable == VECTOR_LAGRANGE_MULTIPLIER_Z) {
351  return true;
352  }
353 
354  return false;
355  }
356 
360 
364 
368 
370 
371 }; /* Class ContactResidualBasedEliminationBuilderAndSolver */
372 
374 
377 
378 
380 
381 } /* namespace Kratos.*/
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
std::size_t IndexType
Definition of the index type.
Definition: builder_and_solver.h:76
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
TSparseSpace::DataType TDataType
Definition of the data type.
Definition: builder_and_solver.h:79
DofsArrayType mDofSet
Pointer to the linear solver.
Definition: builder_and_solver.h:739
std::size_t SizeType
Definition of the size type.
Definition: builder_and_solver.h:73
Current class provides an implementation for contact builder and solving operations....
Definition: contact_residualbased_elimination_builder_and_solver.h:63
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: contact_residualbased_elimination_builder_and_solver.h:233
KRATOS_CLASS_POINTER_DEFINITION(ContactResidualBasedEliminationBuilderAndSolver)
Pointer definition of ContactResidualBasedEliminationBuilderAndSolver.
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: contact_residualbased_elimination_builder_and_solver.h:250
ContactResidualBasedEliminationBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: contact_residualbased_elimination_builder_and_solver.h:130
ContactResidualBasedEliminationBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: contact_residualbased_elimination_builder_and_solver.h:118
ContactResidualBasedEliminationBuilderAndSolver()
Default constructor.
Definition: contact_residualbased_elimination_builder_and_solver.h:111
std::unordered_set< IndexType > IndexSetType
Index set definition.
Definition: contact_residualbased_elimination_builder_and_solver.h:97
typename ModelPart::DofType DofType
The definition of the dof type.
Definition: contact_residualbased_elimination_builder_and_solver.h:88
BaseBuilderAndSolverType::Pointer Create(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters) const override
Create method.
Definition: contact_residualbased_elimination_builder_and_solver.h:155
~ContactResidualBasedEliminationBuilderAndSolver() override
Definition: contact_residualbased_elimination_builder_and_solver.h:138
void SetUpSystem(ModelPart &rModelPart) override
It organises the dofset in order to speed up the building phase.
Definition: contact_residualbased_elimination_builder_and_solver.h:167
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: contact_residualbased_elimination_builder_and_solver.h:289
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Dof< double > DofType
Definition: model_part.h:109
bool HasSubModelPart(std::string const &ThisSubModelPartName) const
Definition: model_part.cpp:2142
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
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
Current class provides an implementation for standard elimination builder and solving operations.
Definition: residualbased_elimination_builder_and_solver.h:76
BaseType::TSchemeType TSchemeType
Definition: residualbased_elimination_builder_and_solver.h:93
BaseType::TDataType TDataType
Definition: residualbased_elimination_builder_and_solver.h:94
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_elimination_builder_and_solver.h:97
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_elimination_builder_and_solver.h:942
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_elimination_builder_and_solver.h:95
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_elimination_builder_and_solver.h:1314
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_elimination_builder_and_solver.h:96
void SetUpSystem(ModelPart &rModelPart) override
Organises the dofset in order to speed up the building phase.
Definition: residualbased_elimination_builder_and_solver.h:759
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int node_id
Definition: read_stl.py:12