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_block_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 
18 // External includes
19 
20 // Project includes
22 
23 namespace Kratos
24 {
25 
28 
32 
36 
40 
44 
57 template<class TSparseSpace,
58  class TDenseSpace, //= DenseSpace<double>,
59  class TLinearSolver, //= LinearSolver<TSparseSpace,TDenseSpace>
60  class TBuilderAndSolver = ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
61  >
63  : public TBuilderAndSolver
64 {
65 public:
68 
71 
74 
76  using BaseType = TBuilderAndSolver;
77 
80 
83 
85  using TDataType = typename BaseType::TDataType;
86 
89 
92 
95 
99 
104  {
105  }
106 
111  typename TLinearSolver::Pointer pNewLinearSystemSolver,
112  Parameters ThisParameters
113  ) : BaseType(pNewLinearSystemSolver)
114  {
115  // Validate and assign defaults
116  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
117  this->AssignSettings(ThisParameters);
118  }
119 
123  typename TLinearSolver::Pointer pNewLinearSystemSolver)
124  : BaseType(pNewLinearSystemSolver)
125  {
126  }
127 
131  {
132  }
133 
137 
141 
147  typename BaseBuilderAndSolverType::Pointer Create(
148  typename TLinearSolver::Pointer pNewLinearSystemSolver,
149  Parameters ThisParameters
150  ) const override
151  {
152  return Kratos::make_shared<ClassType>(pNewLinearSystemSolver,ThisParameters);
153  }
154 
164  typename TSchemeType::Pointer pScheme,
165  ModelPart& rModelPart,
167  TSystemVectorType& Dx,
169  ) override
170  {
171  FixIsolatedNodes(rModelPart);
172 
173  BaseType::ApplyDirichletConditions(pScheme, rModelPart, A, Dx, b);
174 
175  FreeIsolatedNodes(rModelPart);
176  }
177 
184  void BuildRHS(
185  typename TSchemeType::Pointer pScheme,
186  ModelPart& rModelPart,
188  ) override
189  {
190  FixIsolatedNodes(rModelPart);
191 
192  BaseType::BuildRHS(pScheme, rModelPart, b);
193 
194  FreeIsolatedNodes(rModelPart);
195  }
196 
202  {
203  Parameters default_parameters = Parameters(R"(
204  {
205  "name" : "contact_block_builder_and_solver"
206  })");
207 
208  // Getting base class default parameters
209  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
210  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
211  return default_parameters;
212  }
213 
218  static std::string Name()
219  {
220  return "contact_block_builder_and_solver";
221  }
222 
226 
230 
234 
236 
237 protected:
240 
244 
248 
252 
257  void AssignSettings(const Parameters ThisParameters) override
258  {
259  BaseType::AssignSettings(ThisParameters);
260  }
261 
265 
269 
273 
275 
276 private:
279 
283 
287 
292  void FixIsolatedNodes(ModelPart& rModelPart)
293  {
294  KRATOS_ERROR_IF_NOT(rModelPart.HasSubModelPart("Contact")) << "CONTACT MODEL PART NOT CREATED" << std::endl;
295  KRATOS_ERROR_IF_NOT(rModelPart.HasSubModelPart("ComputingContact")) << "CONTACT COMPUTING MODEL PART NOT CREATED" << std::endl;
296  ModelPart& r_contact_model_part = rModelPart.GetSubModelPart("Contact");
297  ModelPart& r_computing_contact_model_part = rModelPart.GetSubModelPart("ComputingContact");
298 
299  // We reset the flag
300  auto& r_nodes_array = r_contact_model_part.Nodes();
301  block_for_each(r_nodes_array, [&](Node& rNode) {
302  rNode.Set(VISITED, false);
303  rNode.Set(ISOLATED, false);
304  });
305 
306  // Now we set the flag in the nodes
307  auto& r_conditions_array = r_computing_contact_model_part.Conditions();
308  block_for_each(r_conditions_array, [&](Condition& rCond) {
309  auto& r_parent_geometry = rCond.GetGeometry().GetGeometryPart(0);
310  for (std::size_t i_node = 0; i_node < r_parent_geometry.size(); ++i_node) {
311  r_parent_geometry[i_node].SetLock();
312  if (r_parent_geometry[i_node].Is(VISITED) == false) {
313  r_parent_geometry[i_node].Set(ISOLATED, rCond.Is(ISOLATED));
314  r_parent_geometry[i_node].Set(VISITED, true);
315  } else {
316  r_parent_geometry[i_node].Set(ISOLATED, r_parent_geometry[i_node].Is(ISOLATED) && rCond.Is(ISOLATED));
317  }
318  r_parent_geometry[i_node].UnSetLock();
319  }
320  });
321 
322  // We fix the LM
323  block_for_each(r_nodes_array, [&](Node& rNode) {
324  if (rNode.Is(ISOLATED)) {
325  if (rNode.SolutionStepsDataHas(LAGRANGE_MULTIPLIER_CONTACT_PRESSURE)) {
326  rNode.Fix(LAGRANGE_MULTIPLIER_CONTACT_PRESSURE);
327  } else if (rNode.SolutionStepsDataHas(VECTOR_LAGRANGE_MULTIPLIER_X)) {
328  rNode.Fix(VECTOR_LAGRANGE_MULTIPLIER_X);
329  rNode.Fix(VECTOR_LAGRANGE_MULTIPLIER_Y);
330  rNode.Fix(VECTOR_LAGRANGE_MULTIPLIER_Z);
331  }
332  }
333  });
334  }
335 
340  void FreeIsolatedNodes(ModelPart& rModelPart)
341  {
342  KRATOS_ERROR_IF_NOT(rModelPart.HasSubModelPart("Contact")) << "CONTACT MODEL PART NOT CREATED" << std::endl;
343  ModelPart& r_contact_model_part = rModelPart.GetSubModelPart("Contact");
344 
345  // We release the LM
346  auto& r_nodes_array = r_contact_model_part.Nodes();
347  block_for_each(r_nodes_array, [&](Node& rNode) {
348  if (rNode.Is(ISOLATED)) {
349  if (rNode.SolutionStepsDataHas(LAGRANGE_MULTIPLIER_CONTACT_PRESSURE)) {
350  rNode.Free(LAGRANGE_MULTIPLIER_CONTACT_PRESSURE);
351  } else if (rNode.SolutionStepsDataHas(VECTOR_LAGRANGE_MULTIPLIER_X)) {
352  rNode.Free(VECTOR_LAGRANGE_MULTIPLIER_X);
353  rNode.Free(VECTOR_LAGRANGE_MULTIPLIER_Y);
354  rNode.Free(VECTOR_LAGRANGE_MULTIPLIER_Z);
355  }
356  }
357  });
358  }
359 
363 
367 
371 
375 
377 
378 }; /* Class ContactResidualBasedBlockBuilderAndSolver */
379 
381 
384 
385 
387 
388 } /* namespace Kratos.*/
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
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
Current class provides an implementation for contact builder and solving operations.
Definition: contact_residualbased_block_builder_and_solver.h:64
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: contact_residualbased_block_builder_and_solver.h:201
BaseBuilderAndSolverType::Pointer Create(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters) const override
Create method.
Definition: contact_residualbased_block_builder_and_solver.h:147
ContactResidualBasedBlockBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: contact_residualbased_block_builder_and_solver.h:122
ContactResidualBasedBlockBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: contact_residualbased_block_builder_and_solver.h:110
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &b) override
This method buils the RHS of the system of equations.
Definition: contact_residualbased_block_builder_and_solver.h:184
ContactResidualBasedBlockBuilderAndSolver()
Default constructor.
Definition: contact_residualbased_block_builder_and_solver.h:103
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: contact_residualbased_block_builder_and_solver.h:218
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
This method imposses the BC of Dirichlet. It will fill with 0 the corresponding DoF.
Definition: contact_residualbased_block_builder_and_solver.h:163
KRATOS_CLASS_POINTER_DEFINITION(ContactResidualBasedBlockBuilderAndSolver)
Pointer definition of ContactResidualBasedBlockBuilderAndSolver.
~ContactResidualBasedBlockBuilderAndSolver() override
Definition: contact_residualbased_block_builder_and_solver.h:130
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: contact_residualbased_block_builder_and_solver.h:257
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
bool HasSubModelPart(std::string const &ThisSubModelPartName) const
Definition: model_part.cpp:2142
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
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 class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
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