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.
geo_mechanics_newton_raphson_strategy.hpp
Go to the documentation of this file.
1 // KRATOS___
2 // // ) )
3 // // ___ ___
4 // // ____ //___) ) // ) )
5 // // / / // // / /
6 // ((____/ / ((____ ((___/ / MECHANICS
7 //
8 // License: geo_mechanics_application/license.txt
9 //
10 // Main authors: Ignasi de Pouplana,
11 // Vahid Galavi
12 //
13 
14 #pragma once
15 
16 // Project includes
17 #include "includes/define.h"
19 #include "includes/model_part.h"
21 
22 // Application includes
24 
25 namespace Kratos
26 {
27 
28 template <class TSparseSpace, class TDenseSpace, class TLinearSolver>
30  : public ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
31 {
32 public:
34 
45  using MotherType::mpA; // Tangent matrix
46  using MotherType::mpb; // Residual vector of iteration i
48  using MotherType::mpDx; // Delta x of iteration i
50 
63  typename TSchemeType::Pointer pScheme,
64  typename TLinearSolver::Pointer pNewLinearSolver,
65  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
66  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
67  Parameters& rParameters,
68  int MaxIterations = 30,
69  bool CalculateReactions = false,
70  bool ReformDofSetAtEachStep = false,
71  bool MoveMeshFlag = false)
72  : ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(
73  model_part,
74  pScheme,
75  /*pNewLinearSolver,*/
76  pNewConvergenceCriteria,
77  pNewBuilderAndSolver,
78  MaxIterations,
79  CalculateReactions,
80  ReformDofSetAtEachStep,
82  {
83  // only include validation with c++11 since raw_literals do not exist in c++03
84  Parameters default_parameters(R"(
85  {
86  "min_iteration": 2,
87  "number_cycles": 5,
88  "increase_factor": 2.0,
89  "reduction_factor": 0.5,
90  "max_piping_iterations": 50,
91  "desired_iterations": 4,
92  "max_radius_factor": 20.0,
93  "min_radius_factor": 0.5,
94  "search_neighbours_step": false,
95  "body_domain_sub_model_part_list": [],
96  "loads_sub_model_part_list": [],
97  "loads_variable_list" : [],
98  "rebuild_level": 2
99  } )");
100 
101  // Validate against defaults -- this also ensures no type mismatch
102  rParameters.ValidateAndAssignDefaults(default_parameters);
103 
104  // Set Load SubModelParts and Variable names
105  if (rParameters["loads_sub_model_part_list"].size() > 0) {
106  mSubModelPartList.resize(rParameters["loads_sub_model_part_list"].size());
107  mVariableNames.resize(rParameters["loads_variable_list"].size());
108 
109  if (mSubModelPartList.size() != mVariableNames.size())
110  KRATOS_ERROR << "For each SubModelPart there must be a corresponding nodal Variable"
111  << std::endl;
112 
113  for (unsigned int i = 0; i < mVariableNames.size(); ++i) {
115  &(model_part.GetSubModelPart(rParameters["loads_sub_model_part_list"][i].GetString()));
116  mVariableNames[i] = rParameters["loads_variable_list"][i].GetString();
117  }
118  }
119  }
120 
121 protected:
123  std::vector<ModelPart*> mSubModelPartList;
124  std::vector<std::string> mVariableNames;
125 
126  int Check() override
127  {
128  KRATOS_TRY
129 
130  return MotherType::Check();
131 
132  KRATOS_CATCH("")
133  }
134 
136  {
137  double ReferenceDofsNorm = 0.0;
138 
139  int NumThreads = ParallelUtilities::GetNumThreads();
140  OpenMPUtils::PartitionVector DofSetPartition;
141  OpenMPUtils::DivideInPartitions(rDofSet.size(), NumThreads, DofSetPartition);
142 
143 #pragma omp parallel reduction(+ : ReferenceDofsNorm)
144  {
145  int k = OpenMPUtils::ThisThread();
146 
147  typename DofsArrayType::iterator DofsBegin = rDofSet.begin() + DofSetPartition[k];
148  typename DofsArrayType::iterator DofsEnd = rDofSet.begin() + DofSetPartition[k + 1];
149 
150  for (typename DofsArrayType::iterator itDof = DofsBegin; itDof != DofsEnd; ++itDof) {
151  if (itDof->IsFree()) {
152  const double& temp = itDof->GetSolutionStepValue();
153  ReferenceDofsNorm += temp * temp;
154  }
155  }
156  }
157 
158  return sqrt(ReferenceDofsNorm);
159  }
160 }; // Class GeoMechanicsNewtonRaphsonStrategy
161 
162 } // 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
Definition: geo_mechanics_newton_raphson_strategy.hpp:31
std::vector< std::string > mVariableNames
List of every SubModelPart associated to an external load.
Definition: geo_mechanics_newton_raphson_strategy.hpp:124
GeoMechanicsNewtonRaphsonStrategy(ModelPart &model_part, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, Parameters &rParameters, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Default constructor.
Definition: geo_mechanics_newton_raphson_strategy.hpp:62
double CalculateReferenceDofsNorm(DofsArrayType &rDofSet)
Definition: geo_mechanics_newton_raphson_strategy.hpp:135
std::vector< ModelPart * > mSubModelPartList
Member Variables.
Definition: geo_mechanics_newton_raphson_strategy.hpp:123
int Check() override
Name of the nodal variable associated to every SubModelPart.
Definition: geo_mechanics_newton_raphson_strategy.hpp:126
KRATOS_CLASS_POINTER_DEFINITION(GeoMechanicsNewtonRaphsonStrategy)
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
Scheme< TSparseSpace, TDenseSpace > TSchemeType
Definition: implicit_solving_strategy.h:82
BaseType::DofsArrayType DofsArrayType
Definition: implicit_solving_strategy.h:90
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
static void DivideInPartitions(const int NumTerms, const int NumThreads, PartitionVector &Partitions)
Divide an array of length NumTerms between NumThreads threads.
Definition: openmp_utils.h:158
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
std::vector< int > PartitionVector
Vector type for the output of DivideInPartitions method.
Definition: openmp_utils.h:53
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
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
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
This is the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
int Check() override
Function to perform expensive checks.
Definition: residualbased_newton_raphson_strategy.h:1048
unsigned int mMaxIterationNumber
Definition: residualbased_newton_raphson_strategy.h:1261
TSystemVectorPointerType mpb
The increment in the solution.
Definition: residualbased_newton_raphson_strategy.h:1237
TSystemMatrixPointerType mpA
The RHS vector of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1238
TSystemVectorPointerType mpDx
The pointer to the convergence criteria employed.
Definition: residualbased_newton_raphson_strategy.h:1236
TBuilderAndSolverType::Pointer mpBuilderAndSolver
The pointer to the time scheme employed.
Definition: residualbased_newton_raphson_strategy.h:1233
TSchemeType::Pointer mpScheme
Definition: residualbased_newton_raphson_strategy.h:1232
bool mInitializeWasPerformed
The maximum number of iterations, 30 by default.
Definition: residualbased_newton_raphson_strategy.h:1263
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
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
int k
Definition: quadrature.py:595
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17