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.
residual_based_bdf_displacement_scheme.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 
14 #if !defined(KRATOS_RESIDUAL_BASED_BDF_DISPLACEMENT_SCHEME )
15 #define KRATOS_RESIDUAL_BASED_BDF_DISPLACEMENT_SCHEME
16 
17 /* System includes */
18 
19 /* External includes */
20 
21 /* Project includes */
23 #include "includes/variables.h"
24 #include "includes/checks.h"
25 
26 namespace Kratos
27 {
42 
52 template<class TSparseSpace, class TDenseSpace>
54  : public ResidualBasedBDFScheme<TSparseSpace, TDenseSpace>
55 {
56 public:
59 
62 
68 
79 
84 
91 
92  typedef double ComponentType;
93 
97 
103  : BDFBaseType()
104  {
105  // Validate and assign defaults
106  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
107  this->AssignSettings(ThisParameters);
108  }
109 
115  explicit ResidualBasedBDFDisplacementScheme(const std::size_t Order = 2)
116  :BDFBaseType(Order)
117  {
118  }
119 
123  :BDFBaseType(rOther)
124  {
125  }
126 
130  typename BaseType::Pointer Clone() override
131  {
132  return Kratos::make_shared<ResidualBasedBDFDisplacementScheme>(*this);
133  }
134 
138  () override {}
139 
143 
147 
152  typename BaseType::Pointer Create(Parameters ThisParameters) const override
153  {
154  return Kratos::make_shared<ClassType>(ThisParameters);
155  }
156 
165  ModelPart& rModelPart,
166  TSystemMatrixType& rA,
167  TSystemVectorType& rDx,
169  ) override
170  {
171  KRATOS_TRY;
172 
173  // The current process info
174  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
175 
176  BDFBaseType::InitializeSolutionStep(rModelPart, rA, rDx, rb);
177 
178  // Updating time derivatives (nodally for efficiency)
179  const auto it_node_begin = rModelPart.Nodes().begin();
180 
181  // Getting dimension
182  KRATOS_WARNING_IF("ResidualBasedBDFDisplacementScheme", !r_current_process_info.Has(DOMAIN_SIZE)) << "DOMAIN_SIZE not defined. Please define DOMAIN_SIZE. 3D case will be assumed" << std::endl;
183  const std::size_t dimension = r_current_process_info.Has(DOMAIN_SIZE) ? r_current_process_info.GetValue(DOMAIN_SIZE) : 3;
184 
185  // Getting position
186  const int velpos = it_node_begin->HasDofFor(VELOCITY_X) ? static_cast<int>(it_node_begin->GetDofPosition(VELOCITY_X)) : -1;
187  const int accelpos = it_node_begin->HasDofFor(ACCELERATION_X) ? static_cast<int>(it_node_begin->GetDofPosition(ACCELERATION_X)) : -1;
188 
189  std::array<bool, 3> fixed = {false, false, false};
190  const std::array<const Variable<ComponentType>*, 3> disp_components = {&DISPLACEMENT_X, &DISPLACEMENT_Y, &DISPLACEMENT_Z};
191  const std::array<const Variable<ComponentType>*, 3> vel_components = {&VELOCITY_X, &VELOCITY_Y, &VELOCITY_Z};
192  const std::array<const Variable<ComponentType>*, 3> accel_components = {&ACCELERATION_X, &ACCELERATION_Y, &ACCELERATION_Z};
193 
194  block_for_each(rModelPart.Nodes(), fixed, [&](Node& rNode, std::array<bool,3>& rFixedTLS){
195  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
196  rFixedTLS[i_dim] = false;
197  }
198 
199  if (accelpos > -1) {
200  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
201  if (rNode.GetDof(*accel_components[i_dim], accelpos + i_dim).IsFixed()) {
202  rNode.Fix(*disp_components[i_dim]);
203  rFixedTLS[i_dim] = true;
204  }
205  }
206  }
207  if (velpos > -1) {
208  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
209  if (rNode.GetDof(*vel_components[i_dim], velpos + i_dim).IsFixed() && !rFixedTLS[i_dim]) {
210  rNode.Fix(*disp_components[i_dim]);
211  }
212  }
213  }
214  });
215 
216  KRATOS_CATCH("ResidualBasedBDFDisplacementScheme.InitializeSolutionStep");
217  }
218 
228  void Predict(
229  ModelPart& rModelPart,
230  DofsArrayType& rDofSet,
232  TSystemVectorType& Dx,
234  ) override
235  {
236  KRATOS_TRY;
237 
238  // The current process info
239  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
240  const double delta_time = r_current_process_info[DELTA_TIME];
241 
242  // Updating time derivatives (nodally for efficiency)
243  const int num_nodes = static_cast<int>( rModelPart.Nodes().size() );
244  const auto it_node_begin = rModelPart.Nodes().begin();
245 
246  // Getting position
247  KRATOS_ERROR_IF_NOT(it_node_begin->HasDofFor(DISPLACEMENT_X)) << "ResidualBasedBDFDisplacementScheme:: DISPLACEMENT is not added" << std::endl;
248  const int disppos = it_node_begin->GetDofPosition(DISPLACEMENT_X);
249  const int velpos = it_node_begin->HasDofFor(VELOCITY_X) ? static_cast<int>(it_node_begin->GetDofPosition(VELOCITY_X)) : -1;
250  const int accelpos = it_node_begin->HasDofFor(ACCELERATION_X) ? static_cast<int>(it_node_begin->GetDofPosition(ACCELERATION_X)) : -1;
251 
252  // Getting dimension
253  KRATOS_WARNING_IF("ResidualBasedBDFDisplacementScheme", !r_current_process_info.Has(DOMAIN_SIZE)) << "DOMAIN_SIZE not defined. Please define DOMAIN_SIZE. 3D case will be assumed" << std::endl;
254  const std::size_t dimension = r_current_process_info.Has(DOMAIN_SIZE) ? r_current_process_info.GetValue(DOMAIN_SIZE) : 3;
255 
256  // Auxiliar variables
257  std::array<bool, 3> predicted = {false, false, false};
258  const std::array<const Variable<ComponentType>*, 3> disp_components = {&DISPLACEMENT_X, &DISPLACEMENT_Y, &DISPLACEMENT_Z};
259  const std::array<const Variable<ComponentType>*, 3> vel_components = {&VELOCITY_X, &VELOCITY_Y, &VELOCITY_Z};
260  const std::array<const Variable<ComponentType>*, 3> accel_components = {&ACCELERATION_X, &ACCELERATION_Y, &ACCELERATION_Z};
261 
262  IndexPartition<int>(num_nodes).for_each(predicted, [&](int Index, std::array<bool, 3>& rPredictedTLS){
263  auto it_node = it_node_begin + Index;
264 
265  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
266  rPredictedTLS[i_dim] = false;
267  }
268 
269  const array_1d<double, 3>& dot2un1 = it_node->FastGetSolutionStepValue(ACCELERATION, 1);
270  const array_1d<double, 3>& dotun1 = it_node->FastGetSolutionStepValue(VELOCITY, 1);
271  const array_1d<double, 3>& un1 = it_node->FastGetSolutionStepValue(DISPLACEMENT, 1);
272  const array_1d<double, 3>& dot2un0 = it_node->FastGetSolutionStepValue(ACCELERATION);
273  array_1d<double, 3>& dotun0 = it_node->FastGetSolutionStepValue(VELOCITY);
274  array_1d<double, 3>& un0 = it_node->FastGetSolutionStepValue(DISPLACEMENT);
275 
276  if (accelpos > -1) {
277  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
278  if (it_node->GetDof(*accel_components[i_dim], accelpos + i_dim).IsFixed()) {
279  dotun0[i_dim] = dot2un0[i_dim];
280  for (std::size_t i_order = 1; i_order < this->mOrder + 1; ++i_order)
281  dotun0[i_dim] -= this->mBDF[i_order] * it_node->FastGetSolutionStepValue(*vel_components[i_dim], i_order);
282  dotun0[i_dim] /= this->mBDF[i_dim];
283 
284  un0[i_dim] = dotun0[i_dim];
285  for (std::size_t i_order = 1; i_order < this->mOrder + 1; ++i_order)
286  un0[i_dim] -= this->mBDF[i_order] * it_node->FastGetSolutionStepValue(*disp_components[i_dim], i_order);
287  un0[i_dim] /= this->mBDF[i_dim];
288  rPredictedTLS[i_dim] = true;
289  }
290  }
291  }
292  if (velpos > -1) {
293  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
294  if (it_node->GetDof(*vel_components[i_dim], velpos + i_dim).IsFixed() && !rPredictedTLS[i_dim]) {
295  un0[i_dim] = dotun0[i_dim];
296  for (std::size_t i_order = 1; i_order < this->mOrder + 1; ++i_order)
297  un0[i_dim] -= this->mBDF[i_order] * it_node->FastGetSolutionStepValue(*disp_components[i_dim], i_order);
298  un0[i_dim] /= this->mBDF[i_dim];
299  rPredictedTLS[i_dim] = true;
300  }
301  }
302  }
303  for (std::size_t i_dim = 0; i_dim < dimension; ++i_dim) {
304  if (!it_node->GetDof(*disp_components[i_dim], disppos + i_dim).IsFixed() && !rPredictedTLS[i_dim]) {
305  un0[i_dim] = un1[i_dim] + delta_time * dotun1[i_dim] + 0.5 * std::pow(delta_time, 2) * dot2un1[i_dim];
306  }
307  }
308 
309  // Updating time derivatives
310  UpdateFirstDerivative(it_node);
311  UpdateSecondDerivative(it_node);
312  });
313 
314  KRATOS_CATCH( "" );
315  }
316 
325  int Check(const ModelPart& rModelPart) const override
326  {
327  KRATOS_TRY;
328 
329  const int err = BDFBaseType::Check(rModelPart);
330  if(err!=0) return err;
331 
332  // Check that variables are correctly allocated
333  for(auto& rnode : rModelPart.Nodes()) {
334  KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(DISPLACEMENT,rnode)
336  KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(ACCELERATION,rnode)
337 
338  KRATOS_CHECK_DOF_IN_NODE(DISPLACEMENT_X, rnode)
339  KRATOS_CHECK_DOF_IN_NODE(DISPLACEMENT_Y, rnode)
340  KRATOS_CHECK_DOF_IN_NODE(DISPLACEMENT_Z, rnode)
341  }
342 
343  KRATOS_CATCH( "" );
344 
345  return 0;
346  }
347 
353  {
354  Parameters default_parameters = Parameters(R"(
355  {
356  "name" : "bdf_displacement_scheme",
357  "integration_order" : 2
358  })");
359 
360  // Getting base class default parameters
361  const Parameters base_default_parameters = BDFBaseType::GetDefaultParameters();
362  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
363  return default_parameters;
364  }
365 
370  static std::string Name()
371  {
372  return "bdf_displacement_scheme";
373  }
374 
378 
382 
386 
388  std::string Info() const override
389  {
390  return "ResidualBasedBDFDisplacementScheme";
391  }
392 
394  void PrintInfo(std::ostream& rOStream) const override
395  {
396  rOStream << Info();
397  }
398 
400  void PrintData(std::ostream& rOStream) const override
401  {
402  rOStream << Info();
403  }
404 
408 
409 protected:
410 
413 
417 
421 
425 
430  inline void UpdateFirstDerivative(NodesArrayType::iterator itNode) override
431  {
432  array_1d<double, 3>& dotun0 = itNode->FastGetSolutionStepValue(VELOCITY);
433  noalias(dotun0) = this->mBDF[0] * itNode->FastGetSolutionStepValue(DISPLACEMENT);
434  for (std::size_t i_order = 1; i_order < this->mOrder + 1; ++i_order)
435  noalias(dotun0) += this->mBDF[i_order] * itNode->FastGetSolutionStepValue(DISPLACEMENT, i_order);
436  }
437 
443  {
444  array_1d<double, 3>& dot2un0 = itNode->FastGetSolutionStepValue(ACCELERATION);
445  noalias(dot2un0) = this->mBDF[0] * itNode->FastGetSolutionStepValue(VELOCITY);
446  for (std::size_t i_order = 1; i_order < this->mOrder + 1; ++i_order)
447  noalias(dot2un0) += this->mBDF[i_order] * itNode->FastGetSolutionStepValue(VELOCITY, i_order);
448  }
449 
453 
457 
462 
463 private:
464 
470 
474 
478 
483 
487 
494 }; /* Class ResidualBasedBDFDisplacementScheme */
502 } /* namespace Kratos.*/
503 
504 #endif /* KRATOS_RESIDUAL_BASED_BDF_DISPLACEMENT_SCHEME defined */
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
bool IsFixed() const
Definition: dof.h:376
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
const DofType & GetDof(TVariableType const &rDofVariable, int pos) const
Get dof with a given position. If not found it is search.
Definition: node.h:649
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
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
BDF integration scheme (displacement based)
Definition: residual_based_bdf_displacement_scheme.h:55
std::string Info() const override
Turn back information as a string.
Definition: residual_based_bdf_displacement_scheme.h:388
BDFBaseType::TDataType TDataType
Data type definition.
Definition: residual_based_bdf_displacement_scheme.h:70
BDFBaseType::LocalSystemMatrixType LocalSystemMatrixType
Local system vector type definition.
Definition: residual_based_bdf_displacement_scheme.h:78
BDFBaseType::DofsArrayType DofsArrayType
DoF array type definition.
Definition: residual_based_bdf_displacement_scheme.h:81
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: residual_based_bdf_displacement_scheme.h:152
ModelPart::ConditionsContainerType ConditionsArrayType
Conditions containers definition.
Definition: residual_based_bdf_displacement_scheme.h:90
ResidualBasedBDFDisplacementScheme(const std::size_t Order=2)
Constructor. The BDF method.
Definition: residual_based_bdf_displacement_scheme.h:115
Element::DofsVectorType DofsVectorType
DoF vector type definition.
Definition: residual_based_bdf_displacement_scheme.h:83
ResidualBasedBDFDisplacementScheme(ResidualBasedBDFDisplacementScheme &rOther)
Definition: residual_based_bdf_displacement_scheme.h:122
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residual_based_bdf_displacement_scheme.h:370
ResidualBasedImplicitTimeScheme< TSparseSpace, TDenseSpace > ImplicitBaseType
Definition: residual_based_bdf_displacement_scheme.h:65
void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
It initializes time step solution. Only for reasons if the time step solution is restarted.
Definition: residual_based_bdf_displacement_scheme.h:164
void Predict(ModelPart &rModelPart, DofsArrayType &rDofSet, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Performing the prediction of the solution.
Definition: residual_based_bdf_displacement_scheme.h:228
double ComponentType
Definition: residual_based_bdf_displacement_scheme.h:92
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBDFDisplacementScheme)
Pointer definition of ResidualBasedBDFDisplacementScheme.
void UpdateSecondDerivative(NodesArrayType::iterator itNode) override
Updating second time derivative (acceleration)
Definition: residual_based_bdf_displacement_scheme.h:442
ResidualBasedBDFDisplacementScheme< TSparseSpace, TDenseSpace > ClassType
Definition: residual_based_bdf_displacement_scheme.h:67
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residual_based_bdf_displacement_scheme.h:394
~ResidualBasedBDFDisplacementScheme() override
Definition: residual_based_bdf_displacement_scheme.h:138
BDFBaseType::LocalSystemVectorType LocalSystemVectorType
Local system matrix type definition.
Definition: residual_based_bdf_displacement_scheme.h:76
BDFBaseType::TSystemMatrixType TSystemMatrixType
Matrix type definition.
Definition: residual_based_bdf_displacement_scheme.h:72
ResidualBasedBDFScheme< TSparseSpace, TDenseSpace > BDFBaseType
Definition: residual_based_bdf_displacement_scheme.h:66
ModelPart::NodesContainerType NodesArrayType
Nodes containers definition.
Definition: residual_based_bdf_displacement_scheme.h:86
BDFBaseType::TSystemVectorType TSystemVectorType
Vector type definition.
Definition: residual_based_bdf_displacement_scheme.h:74
ModelPart::ElementsContainerType ElementsArrayType
Elements containers definition.
Definition: residual_based_bdf_displacement_scheme.h:88
Scheme< TSparseSpace, TDenseSpace > BaseType
Base class definition.
Definition: residual_based_bdf_displacement_scheme.h:64
BaseType::Pointer Clone() override
Definition: residual_based_bdf_displacement_scheme.h:130
void UpdateFirstDerivative(NodesArrayType::iterator itNode) override
Updating first time derivative (velocity)
Definition: residual_based_bdf_displacement_scheme.h:430
int Check(const ModelPart &rModelPart) const override
This function is designed to be called once to perform all the checks needed on the input provided.
Definition: residual_based_bdf_displacement_scheme.h:325
ResidualBasedBDFDisplacementScheme(Parameters ThisParameters)
Constructor. The BDF method (parameters)
Definition: residual_based_bdf_displacement_scheme.h:102
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residual_based_bdf_displacement_scheme.h:400
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residual_based_bdf_displacement_scheme.h:352
BDF integration scheme (for dynamic problems)
Definition: residual_based_bdf_scheme.h:83
ImplicitBaseType::TDataType TDataType
Definition: residual_based_bdf_scheme.h:95
ImplicitBaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residual_based_bdf_scheme.h:105
void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
It initializes time step solution. Only for reasons if the time step solution is restarted.
Definition: residual_based_bdf_scheme.h:236
ImplicitBaseType::TSystemVectorType TSystemVectorType
Definition: residual_based_bdf_scheme.h:103
ImplicitBaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residual_based_bdf_scheme.h:107
ImplicitBaseType::TSystemMatrixType TSystemMatrixType
Definition: residual_based_bdf_scheme.h:101
This is the base class for the implicit time schemes.
Definition: residual_based_implicit_time_scheme.h:55
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: scheme.h:773
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: scheme.h:786
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_CHECK_DOF_IN_NODE(TheVariable, TheNode)
Definition: checks.h:176
#define KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode)
Definition: checks.h:171
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
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
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
delta_time
Definition: generate_frictional_mortar_condition.py:130
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
def Index()
Definition: hdf5_io_tools.py:38
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
A
Definition: sensitivityMatrix.py:70