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.
aitken_relaxation_femdem_utility.hpp
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ \.
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics FemDem Application
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Alejandro Cornejo
11 // Ruben Zorrilla
12 //
13 
14 #if !defined(KRATOS_AITKEN_RELAXATION_UTILITY)
15 #define KRATOS_AITKEN_RELAXATION_UTILITY
16 
17 // System includes
18 
19 // External includes
20 #include "utilities/math_utils.h"
21 #include "spaces/ublas_space.h"
23 
24 namespace Kratos
25 {
29 
33 
37 
41 
44 
48 {
49 public:
50 
54 
56 
57  typedef typename TSpace::VectorType VectorType;
58 
60 
61  static constexpr unsigned int Dimension = 3;
62 
66 
71  AitkenRelaxationFEMDEMUtility(const double OmegaOld = 0.825, const double MaximumOmega = 0.825, const double MinimumOmega = 0.825)
72  {
73  mOmegaOld = OmegaOld;
74  mOmegaMax = MaximumOmega;
75  mOmegaMin = MinimumOmega;
76  }
77 
82  {
83  mOmegaOld = rOther.mOmegaOld;
84  }
85 
90 
91 
95 
98 
103  {
104  KRATOS_TRY
106  mOmegaNew = 0.825;
107  KRATOS_CATCH( "" )
108  }
109 
117  const Vector& rResidualVector,
118  Vector& rIterationGuess
119  )
120  {
121  KRATOS_TRY
122  VectorPointerType pAux(new VectorType(rResidualVector));
123  std::swap(mpResidualVectorNew, pAux);
124 
127  } else {
128  VectorType Aux1minus0(*mpResidualVectorNew); // Auxiliar copy of mpResidualVectorNew
129  TSpace::UnaliasedAdd(Aux1minus0, -1.0, *mpResidualVectorOld); // mpResidualVectorNew - mpResidualVectorOld
130 
131  const double denominator = TSpace::Dot(Aux1minus0, Aux1minus0);
132  const double numerator = TSpace::Dot(*mpResidualVectorOld, Aux1minus0);
133 
134  mOmegaNew = -mOmegaOld * (numerator / denominator);
135 
138 
141  }
142  KRATOS_CATCH("")
143  }
144 
149  {
150  KRATOS_TRY
153  KRATOS_CATCH("")
154  }
155 
160  {
161  KRATOS_TRY
163  mVectorSize = 0;
164  KRATOS_CATCH("")
165  }
166 
170  double ComputeNorm(const Vector& rVector)
171  {
172  return MathUtils<double>::Norm(rVector);
173  }
174 
179  {
180  mVectorSize = 0;
181  if (rSolidModelPart.HasSubModelPart("fsi_interface_model_part")) {
182  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
183  r_interface_sub_model.Nodes().clear();
184  } else {
185  auto &r_interface_sub_model = rSolidModelPart.CreateSubModelPart("fsi_interface_model_part");
186  }
187 
188  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
189  auto &r_solid_skin_sub_model = rSolidModelPart.GetSubModelPart("SkinDEMModelPart");
190 
191  const auto it_node_begin = r_solid_skin_sub_model.NodesBegin();
192  // #pragma omp parallel for
193  for (int i = 0; i < static_cast<int>(r_solid_skin_sub_model.Nodes().size()); i++) {
194  auto it_node = it_node_begin + i;
195  if (it_node->FastGetSolutionStepValue(PRESSURE) != 0.0) {
196  r_interface_sub_model.AddNode(*(it_node.base()));
197  mVectorSize++;
198  }
199  }
201  }
202 
206  void ResetNodalValues(ModelPart &rSolidModelPart)
207  {
208  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
209  const Vector& r_zero_vector = ZeroVector(Dimension);
210 
211  const auto it_node_begin = r_interface_sub_model.NodesBegin();
212  #pragma omp parallel for
213  for (int i = 0; i < static_cast<int>(r_interface_sub_model.Nodes().size()); i++) {
214  auto it_node = it_node_begin + i;
215  auto &r_var_1 = it_node->FastGetSolutionStepValue(RELAXED_VELOCITY);
216  auto &r_var_2 = it_node->FastGetSolutionStepValue(OLD_RELAXED_VELOCITY);
217  auto &r_var_3 = it_node->FastGetSolutionStepValue(FSI_INTERFACE_RESIDUAL);
218  r_var_1 = r_zero_vector;
219  r_var_2 = r_zero_vector;
220  r_var_3 = r_zero_vector;
221  }
222 
223  mpResidualVectorOld.reset();
224  mpResidualVectorNew.reset();
225  }
226 
230  void SavePreviousRelaxedValues(ModelPart &rSolidModelPart)
231  {
232  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
233  const auto it_node_begin = r_interface_sub_model.NodesBegin();
234 
235  #pragma omp parallel for
236  for (int i = 0; i < static_cast<int>(r_interface_sub_model.Nodes().size()); i++) {
237  auto it_node = it_node_begin + i;
238  const auto &r_relaxed_velocity = it_node->FastGetSolutionStepValue(RELAXED_VELOCITY);
239  auto &r_old_relaxed_velocity = it_node->GetSolutionStepValue(OLD_RELAXED_VELOCITY);
240  noalias(r_old_relaxed_velocity) = r_relaxed_velocity;
241  }
242  }
243 
247  unsigned int GetVectorSize()
248  {
249  return mVectorSize;
250  }
251 
256  ModelPart &rSolidModelPart,
257  Vector& rIterationValueVector
258  )
259  {
260  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
261  const auto it_node_begin = r_interface_sub_model.NodesBegin();
262 
263  if (rIterationValueVector.size() != mVectorSize) {
264  rIterationValueVector.resize(mVectorSize);
265  noalias(rIterationValueVector) = ZeroVector(mVectorSize);
266  }
267 
268  #pragma omp parallel for firstprivate(it_node_begin)
269  for (int i = 0; i < static_cast<int>(r_interface_sub_model.Nodes().size()); i++) {
270  auto it_node = it_node_begin + i;
271  const auto &r_value = it_node->FastGetSolutionStepValue(OLD_RELAXED_VELOCITY);
272 
273  // Assemble the vector
274  const unsigned int base_i = i * Dimension;
275  for (unsigned int jj = 0; jj < Dimension; ++jj) {
276  rIterationValueVector[base_i + jj] = r_value[jj];
277  }
278  }
279  }
280 
286  ModelPart &rSolidModelPart,
287  Vector& rInterfaceResidualVector
288  )
289  {
290  if (rInterfaceResidualVector.size() != mVectorSize) {
291  rInterfaceResidualVector.resize(mVectorSize);
292  noalias(rInterfaceResidualVector) = ZeroVector(mVectorSize);
293  }
294 
295  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
296  const auto it_node_begin = r_interface_sub_model.NodesBegin();
297 
298  TSpace::SetToZero(rInterfaceResidualVector);
299 
300  #pragma omp parallel for firstprivate(it_node_begin)
301  for (int i = 0; i < static_cast<int>(r_interface_sub_model.Nodes().size()); i++) {
302  auto it_node = it_node_begin + i;
303 
304  const auto &r_origin_value = it_node->FastGetSolutionStepValue(VELOCITY);
305  const auto &r_modified_value = it_node->FastGetSolutionStepValue(OLD_RELAXED_VELOCITY);
306  auto& r_interface_residual = it_node->FastGetSolutionStepValue(FSI_INTERFACE_RESIDUAL);
307  noalias(r_interface_residual) = r_origin_value - r_modified_value;
308 
309  // Assemble the vector
310  const unsigned int base_i = i * Dimension;
311  for (unsigned int jj = 0; jj < Dimension; ++jj)
312  rInterfaceResidualVector[base_i + jj] = r_interface_residual[jj];
313  }
314  return MathUtils<double>::Norm(rInterfaceResidualVector);
315  }
316 
321  ModelPart &rSolidModelPart,
322  const Vector& rRelaxedValuesVector
323  )
324  {
325  auto &r_interface_sub_model = rSolidModelPart.GetSubModelPart("fsi_interface_model_part");
326  const auto it_node_begin = r_interface_sub_model.NodesBegin();
327 
328  #pragma omp parallel for firstprivate(it_node_begin)
329  for (int i = 0; i < static_cast<int>(r_interface_sub_model.Nodes().size()); i++) {
330  auto it_node = it_node_begin + i;
331  auto &r_value = it_node->FastGetSolutionStepValue(VELOCITY);
332  auto &r_value_relaxed = it_node->FastGetSolutionStepValue(RELAXED_VELOCITY);
333 
334  const int base_i = i * Dimension;
335  for (unsigned int jj = 0; jj < Dimension; ++jj) {
336  r_value[jj] = rRelaxedValuesVector[base_i + jj];
337  r_value_relaxed[jj] = rRelaxedValuesVector[base_i + jj];
338  }
339  }
340  }
341 
346  ModelPart &rFluidModelPart
347  )
348  {
349  const auto it_node_begin = rFluidModelPart.NodesBegin();
350 
351  #pragma omp parallel for
352  for (int i = 0; i < static_cast<int>(rFluidModelPart.Nodes().size()); ++i) {
353  auto it_node = it_node_begin + i;
354 
355  if (it_node->IsNot(SOLID)) { // We update only the fluid part
356  auto &r_current_displ = it_node->FastGetSolutionStepValue(DISPLACEMENT, 0);
357  auto &r_current_vel = it_node->FastGetSolutionStepValue(VELOCITY, 0);
358  auto &r_current_acc = it_node->FastGetSolutionStepValue(ACCELERATION, 0);
359 
360  auto &r_old_displ = it_node->FastGetSolutionStepValue(DISPLACEMENT, 1);
361  auto &r_old_vel = it_node->FastGetSolutionStepValue(VELOCITY, 1);
362  auto &r_old_acc = it_node->FastGetSolutionStepValue(ACCELERATION, 1);
363 
364  auto copy_old_displ = r_old_displ;
365  auto copy_old_vel = r_old_vel;
366  auto copy_old_acc = r_old_acc;
367 
368  auto& r_coordinates = it_node->Coordinates();
369  const auto& r_initial_coordinates = it_node->GetInitialPosition();
370  noalias(r_coordinates) = r_initial_coordinates + copy_old_displ;
371 
372  noalias(r_current_displ) = copy_old_displ;
373  noalias(r_current_vel) = copy_old_vel;
374  noalias(r_current_acc) = copy_old_acc;
375  }
376  }
377  }
378 
380 
384 
388 
392 
396 
397 protected:
398 
402 
405 
407 
408  double mOmegaOld;
409  double mOmegaNew;
410 
411  double mOmegaMax;
412  double mOmegaMin;
413 
416 
417  unsigned int mVectorSize;
418 
420 
424 
428 
432 
436 
440 
441 private:
442 
446 
450 
454 
458 
462 
466 
470 
474 
475 }; /* Class AitkenConvergenceAccelerator */
476 
478 
482 
486 
487 } // namespace Kratos
488 
489 #endif /* KRATOS_AITKEN_RELAXATION_UTILITY defined */
Aitken relaxation technique for FSI PFEM-FEM-DEM coupling.
Definition: aitken_relaxation_femdem_utility.hpp:48
void ResetPFEMkinematicValues(ModelPart &rFluidModelPart)
Definition: aitken_relaxation_femdem_utility.hpp:345
double mOmegaMin
Definition: aitken_relaxation_femdem_utility.hpp:412
UblasSpace< double, Matrix, Vector > TSpace
Definition: aitken_relaxation_femdem_utility.hpp:55
void InitializeSolutionStep()
Definition: aitken_relaxation_femdem_utility.hpp:102
double ComputeNorm(const Vector &rVector)
Definition: aitken_relaxation_femdem_utility.hpp:170
void FillOldRelaxedValuesVector(ModelPart &rSolidModelPart, Vector &rIterationValueVector)
Definition: aitken_relaxation_femdem_utility.hpp:255
TSpace::VectorPointerType VectorPointerType
Definition: aitken_relaxation_femdem_utility.hpp:59
double mOmegaNew
Definition: aitken_relaxation_femdem_utility.hpp:409
double mOmegaOld
Definition: aitken_relaxation_femdem_utility.hpp:408
void FinalizeSolutionStep()
Definition: aitken_relaxation_femdem_utility.hpp:159
TSpace::VectorType VectorType
Definition: aitken_relaxation_femdem_utility.hpp:57
void InitializeInterfaceSubModelPart(ModelPart &rSolidModelPart)
Definition: aitken_relaxation_femdem_utility.hpp:178
VectorPointerType mpResidualVectorNew
Definition: aitken_relaxation_femdem_utility.hpp:415
void SavePreviousRelaxedValues(ModelPart &rSolidModelPart)
Definition: aitken_relaxation_femdem_utility.hpp:230
AitkenRelaxationFEMDEMUtility(const AitkenRelaxationFEMDEMUtility &rOther)
Definition: aitken_relaxation_femdem_utility.hpp:81
VectorPointerType mpResidualVectorOld
Definition: aitken_relaxation_femdem_utility.hpp:414
void UpdateInterfaceValues(ModelPart &rSolidModelPart, const Vector &rRelaxedValuesVector)
Definition: aitken_relaxation_femdem_utility.hpp:320
void ResetNodalValues(ModelPart &rSolidModelPart)
Definition: aitken_relaxation_femdem_utility.hpp:206
double ComputeInterfaceResidualVector(ModelPart &rSolidModelPart, Vector &rInterfaceResidualVector)
Definition: aitken_relaxation_femdem_utility.hpp:285
virtual ~AitkenRelaxationFEMDEMUtility()
Definition: aitken_relaxation_femdem_utility.hpp:89
void FinalizeNonLinearIteration()
Definition: aitken_relaxation_femdem_utility.hpp:148
unsigned int GetVectorSize()
Definition: aitken_relaxation_femdem_utility.hpp:247
void UpdateSolution(const Vector &rResidualVector, Vector &rIterationGuess)
Definition: aitken_relaxation_femdem_utility.hpp:116
static constexpr unsigned int Dimension
Definition: aitken_relaxation_femdem_utility.hpp:61
AitkenRelaxationFEMDEMUtility(const double OmegaOld=0.825, const double MaximumOmega=0.825, const double MinimumOmega=0.825)
Definition: aitken_relaxation_femdem_utility.hpp:71
double mOmegaMax
Definition: aitken_relaxation_femdem_utility.hpp:411
unsigned int mVectorSize
Definition: aitken_relaxation_femdem_utility.hpp:417
unsigned int mConvergenceAcceleratorIteration
Definition: aitken_relaxation_femdem_utility.hpp:406
KRATOS_CLASS_POINTER_DEFINITION(AitkenRelaxationFEMDEMUtility)
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
static double Norm(const Vector &a)
Calculates the norm of vector "a".
Definition: math_utils.h:703
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
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ModelPart & CreateSubModelPart(std::string const &NewSubModelPartName)
Definition: model_part.cpp:2000
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
typename Kratos::shared_ptr< TVectorType > VectorPointerType
The pointer to the vector type.
Definition: ublas_space.h:148
static void UnaliasedAdd(VectorType &rX, const double A, const VectorType &rY)
Definition: ublas_space.h:485
static void SetToZero(TOtherMatrixType &rA)
Definition: ublas_space.h:632
static TDataType Dot(VectorType const &rX, VectorType const &rY)
rX * rY
Definition: ublas_space.h:259
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
integer i
Definition: TensorModule.f:17