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_bossak_scheme.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: July 2013 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_RESIDUAL_BASED_BOSSAK_SCHEME )
11 #define KRATOS_RESIDUAL_BASED_BOSSAK_SCHEME
12 
13 // System includes
14 
15 // External includes
16 #include "boost/smart_ptr.hpp"
17 
18 // Project includes
19 #include "includes/define.h"
20 #include "includes/model_part.h"
22 #include "includes/variables.h"
23 #include "containers/array_1d.h"
24 #include "includes/element.h"
26 
27 namespace Kratos
28 {
29 
32 
33 template<class TSparseSpace, class TDenseSpace >
34 class ResidualBasedBossakScheme: public Scheme<TSparseSpace,TDenseSpace>
35 {
36 protected:
37 
39  {
40 
41  double f; //alpha Hilbert
42  double m; //alpha Bosssak
43 
44  };
45 
47  {
48 
49  double beta;
50  double gamma;
51 
52  //system constants
53  double c0;
54  double c1;
55  double c2;
56  double c3;
57  double c4;
58  double c5;
59  double c6;
60 
61  //static-dynamic parameter
63 
64  };
65 
66 
68  {
69 
70  std::vector< Matrix > M; //first derivative matrix (usually mass matrix)
71  std::vector< Matrix > D; //second derivative matrix (usually damping matrix)
72 
73  };
74 
76  {
77 
78  std::vector< Vector > v; //velocity
79  std::vector< Vector > a; //acceleration
80  std::vector< Vector > ap; //previous acceleration
81 
82  };
83 
84 
85 
86 public:
87 
88 
92 
94 
95  typedef typename BaseType::TDataType TDataType;
96 
98 
100 
102 
104 
106 
108 
110 
112 
113  typedef typename BaseType::Pointer BaseTypePointer;
114 
116 
117  ResidualBasedBossakScheme(double rAlpham=0,double rDynamic=1)
118  :Scheme<TSparseSpace,TDenseSpace>()
119  {
120  //For pure Newmark Scheme
121  mAlpha.f= 0;
122  mAlpha.m= rAlpham;
123 
124  mNewmark.beta= (1.0+mAlpha.f-mAlpha.m)*(1.0+mAlpha.f-mAlpha.m)*0.25;
125  mNewmark.gamma= 0.5+mAlpha.f-mAlpha.m;
126 
127  mNewmark.static_dynamic= rDynamic;
128 
129  //std::cout << " MECHANICAL SCHEME: The Bossak Time Integration Scheme [alpha_m= "<<mAlpha.m<<" beta= "<<mNewmark.beta<<" gamma= "<<mNewmark.gamma<<"]"<<std::endl;
130 
131 
132  //Allocate auxiliary memory
133  int NumThreads = OpenMPUtils::GetNumThreads();
134 
135  mMatrix.M.resize(NumThreads);
136  mMatrix.D.resize(NumThreads);
137 
138  mVector.v.resize(NumThreads);
139  mVector.a.resize(NumThreads);
140  mVector.ap.resize(NumThreads);
141 
142 
143  }
144 
145 
147  :BaseType(rOther)
148  ,mAlpha(rOther.mAlpha)
149  ,mNewmark(rOther.mNewmark)
150  ,mMatrix(rOther.mMatrix)
151  ,mVector(rOther.mVector)
152  {
153  }
154 
155 
157  () {}
158 
162 
163 
165  {
166  return BaseTypePointer( new ResidualBasedBossakScheme(*this) );
167  }
168 
169 
170 
171  //***************************************************************************
172  //***************************************************************************
173 
183  void Update(
184  ModelPart& r_model_part,
185  DofsArrayType& rDofSet,
187  TSystemVectorType& Dx,
188  TSystemVectorType& b ) override
189  {
190  KRATOS_TRY
191 
192  //std::cout << " Update " << std::endl;
193  //update of displacement (by DOF)
194  for (typename DofsArrayType::iterator i_dof = rDofSet.begin(); i_dof != rDofSet.end(); ++i_dof)
195  {
196  if (i_dof->IsFree() )
197  {
198  i_dof->GetSolutionStepValue() += Dx[i_dof->EquationId()];
199  }
200  }
201 
202  //updating time derivatives (nodally for efficiency)
203  array_1d<double, 3 > DeltaDisplacement;
204  for (ModelPart::NodeIterator i = r_model_part.NodesBegin();
205  i != r_model_part.NodesEnd(); ++i)
206  {
207 
208  noalias(DeltaDisplacement) = (i)->FastGetSolutionStepValue(DISPLACEMENT) - (i)->FastGetSolutionStepValue(DISPLACEMENT, 1);
209 
210 
211  array_1d<double, 3 > & CurrentVelocity = (i)->FastGetSolutionStepValue(VELOCITY, 0);
212  array_1d<double, 3 > & PreviousVelocity = (i)->FastGetSolutionStepValue(VELOCITY, 1);
213 
214  array_1d<double, 3 > & CurrentAcceleration = (i)->FastGetSolutionStepValue(ACCELERATION, 0);
215  array_1d<double, 3 > & PreviousAcceleration = (i)->FastGetSolutionStepValue(ACCELERATION, 1);
216 
217  UpdateVelocity (CurrentVelocity, DeltaDisplacement, PreviousVelocity, PreviousAcceleration);
218 
219  UpdateAcceleration (CurrentAcceleration, DeltaDisplacement, PreviousVelocity, PreviousAcceleration);
220 
221  }
222 
223  KRATOS_CATCH( "" )
224  }
225 
226 
227  //***************************************************************************
228  //***************************************************************************
229 
232  void Predict(
233  ModelPart& r_model_part,
234  DofsArrayType& rDofSet,
236  TSystemVectorType& Dx,
238  ) override
239  {
240  //std::cout << " Prediction " << std::endl;
241  array_1d<double, 3 > DeltaDisplacement;
242 
243  //double DeltaTime = r_model_part.GetProcessInfo()[DELTA_TIME];
244 
245 
246  for (ModelPart::NodeIterator i = r_model_part.NodesBegin();
247  i != r_model_part.NodesEnd(); ++i)
248  {
249  //predicting displacement = PreviousDisplacement + PreviousVelocity * DeltaTime;
250  //ATTENTION::: the prediction is performed only on free nodes
251 
252  array_1d<double, 3 > & PreviousVelocity = (i)->FastGetSolutionStepValue(VELOCITY, 1);
253  array_1d<double, 3 > & PreviousDisplacement = (i)->FastGetSolutionStepValue(DISPLACEMENT, 1);
254  array_1d<double, 3 > & CurrentDisplacement = (i)->FastGetSolutionStepValue(DISPLACEMENT);
255  array_1d<double, 3 > & ImposedDisplacement = (i)->FastGetSolutionStepValue(IMPOSED_DISPLACEMENT);
256 
257 
258  if ((i->pGetDof(DISPLACEMENT_X))->IsFixed() == false)
259  {
260  CurrentDisplacement[0] = PreviousDisplacement[0];// + DeltaTime * PreviousVelocity[0];
261  }
262  else
263  {
264  CurrentDisplacement[0] = PreviousDisplacement[0] + ImposedDisplacement[0];//to impose fixed displacements;
265  //PreviousDisplacement[0] = 0;
266  }
267 
268  if (i->pGetDof(DISPLACEMENT_Y)->IsFixed() == false)
269  {
270  CurrentDisplacement[1] = PreviousDisplacement[1]; //+ DeltaTime * PreviousVelocity[1];
271  }
272  else
273  {
274  CurrentDisplacement[1] = PreviousDisplacement[1] + ImposedDisplacement[1];//to impose fixed displacements;
275  //PreviousDisplacement[1] = 0;
276  }
277 
278 
279  if (i->HasDofFor(DISPLACEMENT_Z))
280  {
281  if (i->pGetDof(DISPLACEMENT_Z)->IsFixed() == false)
282  {
283  CurrentDisplacement[2] = PreviousDisplacement[2]; // + DeltaTime * PreviousVelocity[2];
284  }
285  else
286  {
287  CurrentDisplacement[2] = PreviousDisplacement[2] + ImposedDisplacement[2];//to impose fixed displacements;
288  //PreviousDisplacement[2] = 0;
289  }
290  }
291 
292 
293  // std::cout<<" DispPre "<<PreviousDisplacement<<" ID "<<i->Id()<<std::endl;
294  // std::cout<<" DispCur "<<CurrentDisplacement<<" ID "<<i->Id()<<std::endl;
295 
296  if (i->HasDofFor(PRESSURE))
297  {
298  double& PreviousPressure = (i)->FastGetSolutionStepValue(PRESSURE, 1);
299  double& CurrentPressure = (i)->FastGetSolutionStepValue(PRESSURE);
300 
301  if ((i->pGetDof(PRESSURE))->IsFixed() == false)
302  CurrentPressure = PreviousPressure;
303 
304  //std::cout<<" PressureCur [1] "<<CurrentPressure<<" PressurePre [1] "<<PreviousPressure<<" ID "<<i->Id()<<std::endl;
305  }
306 
307 
308 
309  //updating time derivatives ::: please note that displacements and its time derivatives
310  //can not be consistently fixed separately
311 
312  noalias(DeltaDisplacement) = CurrentDisplacement - PreviousDisplacement;
313 
314  array_1d<double, 3 > & PreviousAcceleration = (i)->FastGetSolutionStepValue(ACCELERATION, 1);
315  array_1d<double, 3 > & CurrentVelocity = (i)->FastGetSolutionStepValue(VELOCITY);
316  array_1d<double, 3 > & CurrentAcceleration = (i)->FastGetSolutionStepValue(ACCELERATION);
317 
318  UpdateVelocity (CurrentVelocity, DeltaDisplacement, PreviousVelocity, PreviousAcceleration);
319 
320  UpdateAcceleration (CurrentAcceleration, DeltaDisplacement, PreviousVelocity, PreviousAcceleration);
321 
322  }
323 
324  }
325 
326  //***************************************************************************
327  //***************************************************************************
328 
332  void InitializeElements(ModelPart& rModelPart) override
333  {
334  KRATOS_TRY
335 
336  int NumThreads = OpenMPUtils::GetNumThreads();
337  OpenMPUtils::PartitionVector ElementPartition;
338  OpenMPUtils::DivideInPartitions(rModelPart.Elements().size(), NumThreads, ElementPartition);
339 
340  #pragma omp parallel
341  {
342  int k = OpenMPUtils::ThisThread();
343  ElementsArrayType::iterator ElemBegin = rModelPart.Elements().begin() + ElementPartition[k];
344  ElementsArrayType::iterator ElemEnd = rModelPart.Elements().begin() + ElementPartition[k + 1];
345 
346  for (ElementsArrayType::iterator itElem = ElemBegin; itElem != ElemEnd; itElem++)
347  {
348  itElem->Initialize(); //function to initialize the element
349  }
350 
351  }
352 
353  this->mElementsAreInitialized = true;
354 
355  //std::cout<<" mechanical elements are initialized "<<std::endl;
356 
357  KRATOS_CATCH( "" )
358  }
359 
360  //***************************************************************************
361  //***************************************************************************
362 
366  void InitializeConditions(ModelPart& rModelPart) override
367  {
368  KRATOS_TRY
369 
370  if(this->mElementsAreInitialized==false)
371  KRATOS_THROW_ERROR( std::logic_error, "Before initilizing Conditions, initialize Elements FIRST", "" )
372 
373  int NumThreads = OpenMPUtils::GetNumThreads();
374  OpenMPUtils::PartitionVector ConditionPartition;
375  OpenMPUtils::DivideInPartitions(rModelPart.Conditions().size(), NumThreads, ConditionPartition);
376 
377  #pragma omp parallel
378  {
379  int k = OpenMPUtils::ThisThread();
380  ConditionsArrayType::iterator CondBegin = rModelPart.Conditions().begin() + ConditionPartition[k];
381  ConditionsArrayType::iterator CondEnd = rModelPart.Conditions().begin() + ConditionPartition[k + 1];
382 
383  for (ConditionsArrayType::iterator itCond = CondBegin; itCond != CondEnd; itCond++)
384  {
385  itCond->Initialize(); //function to initialize the condition
386  }
387 
388  }
389 
390  this->mConditionsAreInitialized = true;
391  KRATOS_CATCH( "" )
392  }
393 
394  //***************************************************************************
395  //***************************************************************************
396 
404  ModelPart& r_model_part,
406  TSystemVectorType& Dx,
407  TSystemVectorType& b) override
408  {
409  KRATOS_TRY
410 
411  ProcessInfo CurrentProcessInfo= r_model_part.GetProcessInfo();
412 
413 
415 
416 
417  double DeltaTime = CurrentProcessInfo[DELTA_TIME];
418 
419  //if (DeltaTime == 0)
420  //KRATOS_THROW_ERROR( std::logic_error, "detected delta_time = 0 in the Solution Scheme ... check if the time step is created correctly for the current model part", "" )
421 
422  if (DeltaTime == 0){
423  std::cout<<" WARNING: detected delta_time = 0 in the Solution Scheme "<<std::endl;
424  std::cout<<" DELTA_TIME set to 1 considering a Quasistatic step with one step only "<<std::endl;
425  std::cout<<" PLEASE : check if the time step is created correctly for the current model part "<<std::endl;
426 
427  CurrentProcessInfo[DELTA_TIME] = 1;
428  DeltaTime = CurrentProcessInfo[DELTA_TIME];
429  }
430 
431 
432  //initializing Newmark constants
433  mNewmark.c0 = ( 1.0 / (mNewmark.beta * DeltaTime * DeltaTime) );
434  mNewmark.c1 = ( mNewmark.gamma / (mNewmark.beta * DeltaTime) );
435  mNewmark.c2 = ( 1.0 / (mNewmark.beta * DeltaTime) );
436  mNewmark.c3 = ( 0.5 / (mNewmark.beta) - 1.0 );
437  mNewmark.c4 = ( (mNewmark.gamma / mNewmark.beta) - 1.0 );
438  mNewmark.c5 = ( DeltaTime * 0.5 * ( ( mNewmark.gamma / mNewmark.beta ) - 2 ) );
439 
440 
441  //std::cout<<" Newmark Variables "<<mNewmark.c0<<" "<<mNewmark.c1<<" "<<mNewmark.c2<<" "<<mNewmark.c3<<" "<<mNewmark.c4<<" "<<mNewmark.c5<<std::endl;
442 
443  KRATOS_CATCH( "" )
444  }
445 
446  //***************************************************************************
447  //***************************************************************************
448 
451  ModelPart& rModelPart,
453  TSystemVectorType& Dx,
454  TSystemVectorType& b) override
455  {
456  KRATOS_TRY
457  //finalizes solution step for all of the elements
458  ElementsArrayType& rElements = rModelPart.Elements();
459  ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo();
460 
461  int NumThreads = OpenMPUtils::GetNumThreads();
462  OpenMPUtils::PartitionVector ElementPartition;
463  OpenMPUtils::DivideInPartitions(rElements.size(), NumThreads, ElementPartition);
464 
465  #pragma omp parallel
466  {
467  int k = OpenMPUtils::ThisThread();
468 
469  ElementsArrayType::iterator ElementsBegin = rElements.begin() + ElementPartition[k];
470  ElementsArrayType::iterator ElementsEnd = rElements.begin() + ElementPartition[k + 1];
471 
472  for (ElementsArrayType::iterator itElem = ElementsBegin; itElem != ElementsEnd; itElem++)
473  {
474  itElem->FinalizeSolutionStep(CurrentProcessInfo);
475  }
476  }
477 
478  ConditionsArrayType& rConditions = rModelPart.Conditions();
479 
480  OpenMPUtils::PartitionVector ConditionPartition;
481  OpenMPUtils::DivideInPartitions(rConditions.size(), NumThreads, ConditionPartition);
482 
483  #pragma omp parallel
484  {
485  int k = OpenMPUtils::ThisThread();
486 
487  ConditionsArrayType::iterator ConditionsBegin = rConditions.begin() + ConditionPartition[k];
488  ConditionsArrayType::iterator ConditionsEnd = rConditions.begin() + ConditionPartition[k + 1];
489 
490  for (ConditionsArrayType::iterator itCond = ConditionsBegin; itCond != ConditionsEnd; itCond++)
491  {
492  itCond->FinalizeSolutionStep(CurrentProcessInfo);
493  }
494  }
495  KRATOS_CATCH( "" )
496  }
497 
498  //***************************************************************************
499  //***************************************************************************
500 
503  TSystemVectorType& Dx,
504  TSystemVectorType& b) override
505  {
506  KRATOS_TRY
507  ElementsArrayType& pElements = r_model_part.Elements();
508  ProcessInfo& CurrentProcessInfo = r_model_part.GetProcessInfo();
509 
510  for (ElementsArrayType::iterator it = pElements.begin(); it != pElements.end(); ++it)
511  {
512  (it) -> InitializeNonLinearIteration(CurrentProcessInfo);
513  }
514 
515  ConditionsArrayType& pConditions = r_model_part.Conditions();
516  for (ConditionsArrayType::iterator it = pConditions.begin(); it != pConditions.end(); ++it)
517  {
518  (it) -> InitializeNonLinearIteration(CurrentProcessInfo);
519  }
520  KRATOS_CATCH( "" )
521  }
522 
523  //***************************************************************************
524  //***************************************************************************
525 
526  void InitializeNonLinearIteration(Condition::Pointer rCurrentCondition,
527  ProcessInfo& CurrentProcessInfo) override
528  {
529  (rCurrentCondition) -> InitializeNonLinearIteration(CurrentProcessInfo);
530  }
531 
532 
533  //***************************************************************************
534  //***************************************************************************
535 
536  void InitializeNonLinearIteration(Element::Pointer rCurrentElement,
537  ProcessInfo& CurrentProcessInfo) override
538  {
539  (rCurrentElement) -> InitializeNonLinearIteration(CurrentProcessInfo);
540  }
541 
542  //***************************************************************************
543  //***************************************************************************
544 
548  Element::Pointer rCurrentElement,
549  LocalSystemMatrixType& LHS_Contribution,
550  LocalSystemVectorType& RHS_Contribution,
552  ProcessInfo& CurrentProcessInfo) override
553  {
554  KRATOS_TRY
555 
556  int thread = OpenMPUtils::ThisThread();
557 
558  //(rCurrentElement) -> InitializeNonLinearIteration(CurrentProcessInfo);
559 
560  (rCurrentElement) -> CalculateLocalSystem(LHS_Contribution,RHS_Contribution,CurrentProcessInfo);
561 
562  if(mNewmark.static_dynamic !=0)
563  {
564 
565  (rCurrentElement) -> CalculateMassMatrix(mMatrix.M[thread],CurrentProcessInfo);
566 
567  (rCurrentElement) -> CalculateDampingMatrix(mMatrix.D[thread],CurrentProcessInfo);
568 
569  }
570 
571  (rCurrentElement) -> EquationIdVector(EquationId,CurrentProcessInfo);
572 
573  if(mNewmark.static_dynamic !=0)
574  {
575 
576  AddDynamicsToLHS (LHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
577 
578  AddDynamicsToRHS (rCurrentElement, RHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
579 
580  }
581 
582  //AssembleTimeSpaceLHS(rCurrentElement, LHS_Contribution, DampMatrix, MassMatrix,CurrentProcessInfo);
583 
584  KRATOS_CATCH( "" )
585  }
586 
587  //***************************************************************************
588  //***************************************************************************
589 
591  Element::Pointer rCurrentElement,
592  LocalSystemVectorType& RHS_Contribution,
594  ProcessInfo& CurrentProcessInfo) override
595  {
596 
597  KRATOS_TRY
598 
599  int thread = OpenMPUtils::ThisThread();
600 
601  //Initializing the non linear iteration for the current element
602  //(rCurrentElement) -> InitializeNonLinearIteration(CurrentProcessInfo);
603 
604  //basic operations for the element considered
605  (rCurrentElement) -> CalculateRightHandSide(RHS_Contribution,CurrentProcessInfo);
606 
607  if(mNewmark.static_dynamic !=0)
608  {
609 
610  (rCurrentElement) -> CalculateMassMatrix(mMatrix.M[thread], CurrentProcessInfo);
611 
612  (rCurrentElement) -> CalculateDampingMatrix(mMatrix.D[thread],CurrentProcessInfo);
613  }
614 
615  (rCurrentElement) -> EquationIdVector(EquationId,CurrentProcessInfo);
616 
617  if(mNewmark.static_dynamic !=0)
618  {
619 
620  AddDynamicsToRHS (rCurrentElement, RHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
621  }
622 
623  KRATOS_CATCH( "" )
624 
625  }
626 
627  //***************************************************************************
628  //***************************************************************************
629 
631  Condition::Pointer rCurrentCondition,
632  LocalSystemMatrixType& LHS_Contribution,
633  LocalSystemVectorType& RHS_Contribution,
635  ProcessInfo& CurrentProcessInfo) override
636  {
637 
638 
639  KRATOS_TRY
640 
641  int thread = OpenMPUtils::ThisThread();
642 
643  //Initializing the non linear iteration for the current element
644  //(rCurrentCondition) -> InitializeNonLinearIteration(CurrentProcessInfo);
645 
646  //basic operations for the element considered
647  (rCurrentCondition) -> CalculateLocalSystem(LHS_Contribution,RHS_Contribution,CurrentProcessInfo);
648 
649 
650  if(mNewmark.static_dynamic !=0)
651  {
652 
653  (rCurrentCondition) -> CalculateMassMatrix(mMatrix.M[thread], CurrentProcessInfo);
654 
655  (rCurrentCondition) -> CalculateDampingMatrix(mMatrix.D[thread],CurrentProcessInfo);
656 
657  }
658 
659  (rCurrentCondition) -> EquationIdVector(EquationId,CurrentProcessInfo);
660 
661  if(mNewmark.static_dynamic !=0)
662  {
663 
664  AddDynamicsToLHS (LHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
665 
666  AddDynamicsToRHS (rCurrentCondition, RHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
667  }
668 
669  //AssembleTimeSpaceLHS_Condition(rCurrentCondition, LHS_Contribution,DampMatrix, MassMatrix,CurrentProcessInfo);
670 
671 
672  KRATOS_CATCH( "" )
673  }
674 
675  //***************************************************************************
676  //***************************************************************************
677 
679  Condition::Pointer rCurrentCondition,
680  LocalSystemVectorType& RHS_Contribution,
682  ProcessInfo& CurrentProcessInfo) override
683  {
684  KRATOS_TRY
685 
686  int thread = OpenMPUtils::ThisThread();
687 
688  //Initializing the non linear iteration for the current condition
689  //(rCurrentCondition) -> InitializeNonLinearIteration(CurrentProcessInfo);
690 
691  //basic operations for the element considered
692  (rCurrentCondition) -> CalculateRightHandSide(RHS_Contribution, CurrentProcessInfo);
693 
694  if(mNewmark.static_dynamic !=0)
695  {
696 
697  (rCurrentCondition) -> CalculateMassMatrix(mMatrix.M[thread], CurrentProcessInfo);
698 
699  (rCurrentCondition) -> CalculateDampingMatrix(mMatrix.D[thread], CurrentProcessInfo);
700 
701  }
702 
703  (rCurrentCondition) -> EquationIdVector(EquationId, CurrentProcessInfo);
704 
705  //adding the dynamic contributions (static is already included)
706 
707  if(mNewmark.static_dynamic !=0)
708  {
709 
710  AddDynamicsToRHS (rCurrentCondition, RHS_Contribution, mMatrix.D[thread], mMatrix.M[thread], CurrentProcessInfo);
711 
712  }
713 
714  KRATOS_CATCH( "" )
715  }
716 
717  //***************************************************************************
718  //***************************************************************************
719 
722  Element::Pointer rCurrentElement,
723  Element::DofsVectorType& ElementalDofList,
724  ProcessInfo& CurrentProcessInfo) override
725  {
726  rCurrentElement->GetDofList(ElementalDofList, CurrentProcessInfo);
727  }
728 
729  //***************************************************************************
730  //***************************************************************************
731 
734  Condition::Pointer rCurrentCondition,
735  Element::DofsVectorType& ConditionDofList,
736  ProcessInfo& CurrentProcessInfo) override
737  {
738  rCurrentCondition->GetDofList(ConditionDofList, CurrentProcessInfo);
739  }
740 
741  //***************************************************************************
742  //***************************************************************************
743 
751  int Check(ModelPart& r_model_part) override
752  {
753  KRATOS_TRY
754 
755  int err = Scheme<TSparseSpace, TDenseSpace>::Check(r_model_part);
756  if(err!=0) return err;
757 
758  //check for variables keys
759  //verify that the variables are correctly initialized
760  if(DISPLACEMENT.Key() == 0)
761  KRATOS_THROW_ERROR( std::invalid_argument,"DISPLACEMENT has Key zero! (check if the application is correctly registered", "" )
762  if(VELOCITY.Key() == 0)
763  KRATOS_THROW_ERROR( std::invalid_argument,"VELOCITY has Key zero! (check if the application is correctly registered", "" )
764  if(ACCELERATION.Key() == 0)
765  KRATOS_THROW_ERROR( std::invalid_argument,"ACCELERATION has Key zero! (check if the application is correctly registered", "" )
766 
767  //check that variables are correctly allocated
768  for(ModelPart::NodesContainerType::iterator it=r_model_part.NodesBegin();
769  it!=r_model_part.NodesEnd(); it++)
770  {
771  if (it->SolutionStepsDataHas(DISPLACEMENT) == false)
772  KRATOS_THROW_ERROR( std::logic_error, "DISPLACEMENT variable is not allocated for node ", it->Id() )
773  if (it->SolutionStepsDataHas(VELOCITY) == false)
774  KRATOS_THROW_ERROR( std::logic_error, "DISPLACEMENT variable is not allocated for node ", it->Id() )
775  if (it->SolutionStepsDataHas(ACCELERATION) == false)
776  KRATOS_THROW_ERROR( std::logic_error, "DISPLACEMENT variable is not allocated for node ", it->Id() )
777  }
778 
779  //check that dofs exist
780  for(ModelPart::NodesContainerType::iterator it=r_model_part.NodesBegin();
781  it!=r_model_part.NodesEnd(); it++)
782  {
783  if(it->HasDofFor(DISPLACEMENT_X) == false)
784  KRATOS_THROW_ERROR( std::invalid_argument,"missing DISPLACEMENT_X dof on node ",it->Id() )
785  if(it->HasDofFor(DISPLACEMENT_Y) == false)
786  KRATOS_THROW_ERROR( std::invalid_argument,"missing DISPLACEMENT_Y dof on node ",it->Id() )
787  if(it->HasDofFor(DISPLACEMENT_Z) == false)
788  KRATOS_THROW_ERROR( std::invalid_argument,"missing DISPLACEMENT_Z dof on node ",it->Id() )
789  }
790 
791 
792  //check for admissible value of the AlphaBossak
793  if(mAlpha.m > 0.0 || mAlpha.m < -0.3)
794  KRATOS_THROW_ERROR( std::logic_error,"Value not admissible for AlphaBossak. Admissible values should be between 0.0 and -0.3. Current value is ", mAlpha.m )
795 
796  //check for minimum value of the buffer index
797  //verify buffer size
798  if (r_model_part.GetBufferSize() < 2)
799  KRATOS_THROW_ERROR( std::logic_error, "insufficient buffer size. Buffer size should be greater than 2. Current size is", r_model_part.GetBufferSize() )
800 
801 
802  return 0;
803  KRATOS_CATCH( "" )
804  }
805 
807 
808 protected:
811 
814 
817 
821 
822  //*********************************************************************************
823  //Updating first time Derivative
824  //*********************************************************************************
825 
826  inline void UpdateVelocity(array_1d<double, 3 > & CurrentVelocity,
827  const array_1d<double, 3 > & DeltaDisplacement,
828  const array_1d<double, 3 > & PreviousVelocity,
829  const array_1d<double, 3 > & PreviousAcceleration)
830  {
831 
832  noalias(CurrentVelocity) = (mNewmark.c1 * DeltaDisplacement - mNewmark.c4 * PreviousVelocity
833  - mNewmark.c5 * PreviousAcceleration) * mNewmark.static_dynamic;
834 
835  }
836 
837 
838  //*********************************************************************************
839  //Updating second time Derivative
840  //*********************************************************************************
841 
842  inline void UpdateAcceleration(array_1d<double, 3 > & CurrentAcceleration,
843  const array_1d<double, 3 > & DeltaDisplacement,
844  const array_1d<double, 3 > & PreviousVelocity,
845  const array_1d<double, 3 > & PreviousAcceleration)
846  {
847 
848  noalias(CurrentAcceleration) = (mNewmark.c0 * DeltaDisplacement - mNewmark.c2 * PreviousVelocity
849  - mNewmark.c3 * PreviousAcceleration) * mNewmark.static_dynamic;
850 
851 
852  }
853 
854 
855  //Elements:
856  //****************************************************************************
857 
860  LocalSystemMatrixType& LHS_Contribution,
863  ProcessInfo& CurrentProcessInfo)
864  {
865 
866  // adding mass contribution to the dynamic stiffness
867  if (M.size1() != 0) // if M matrix declared
868  {
869  noalias(LHS_Contribution) += M * (1-mAlpha.m) * mNewmark.c0 * mNewmark.static_dynamic;
870 
871  //std::cout<<" Mass Matrix "<<M<<" coeficient "<<(1-mAlpha.m)*mNewmark.c0<<std::endl;
872  }
873 
874  //adding damping contribution
875  if (D.size1() != 0) // if M matrix declared
876  {
877  noalias(LHS_Contribution) += D * (1-mAlpha.f) * mNewmark.c1 * mNewmark.static_dynamic;
878 
879  }
880 
881  }
882 
883  //Elements:
884  //****************************************************************************
885 
888  Element::Pointer rCurrentElement,
889  LocalSystemVectorType& RHS_Contribution,
892  ProcessInfo& CurrentProcessInfo)
893  {
894  int thread = OpenMPUtils::ThisThread();
895 
896  //adding inertia contribution
897  if (M.size1() != 0)
898  {
899  rCurrentElement->GetSecondDerivativesVector(mVector.a[thread], 0);
900 
901  (mVector.a[thread]) *= (1.00 - mAlpha.m) * mNewmark.static_dynamic ;
902 
903  rCurrentElement->GetSecondDerivativesVector(mVector.ap[thread], 1);
904 
905  noalias(mVector.a[thread]) += mAlpha.m * mVector.ap[thread] * mNewmark.static_dynamic;
906 
907  noalias(RHS_Contribution) -= prod(M, mVector.a[thread]);
908  //KRATOS_WATCH( prod(M, macc[thread] ) )
909 
910  }
911 
912  //adding damping contribution
913  if (D.size1() != 0)
914  {
915  rCurrentElement->GetFirstDerivativesVector(mVector.v[thread], 0);
916 
917  (mVector.v[thread]) *= mNewmark.static_dynamic ;
918 
919  noalias(RHS_Contribution) -= prod(D, mVector.v[thread]);
920  }
921 
922 
923  }
924 
925 
926  //Conditions:
927  //****************************************************************************
928 
930  Condition::Pointer rCurrentCondition,
931  LocalSystemVectorType& RHS_Contribution,
934  ProcessInfo& CurrentProcessInfo)
935  {
936  int thread = OpenMPUtils::ThisThread();
937 
938  //adding inertia contribution
939  if (M.size1() != 0)
940  {
941  rCurrentCondition->GetSecondDerivativesVector(mVector.a[thread], 0);
942 
943  (mVector.a[thread]) *= (1.00 - mAlpha.m) * mNewmark.static_dynamic;
944 
945  rCurrentCondition->GetSecondDerivativesVector(mVector.ap[thread], 1);
946 
947  noalias(mVector.a[thread]) += mAlpha.m * mVector.ap[thread] * mNewmark.static_dynamic;
948 
949  noalias(RHS_Contribution) -= prod(M, mVector.a[thread]);
950  }
951 
952  //adding damping contribution
953  //damping contribution
954  if (D.size1() != 0)
955  {
956  rCurrentCondition->GetFirstDerivativesVector(mVector.v[thread], 0);
957 
958  (mVector.v[thread]) *= mNewmark.static_dynamic ;
959 
960  noalias(RHS_Contribution) -= prod(D, mVector.v [thread]);
961  }
962 
963  }
964 
966 }; // Class ResidualBasedBossakScheme
967 
969 
970 } // namespace Kratos.
971 
972 #endif // KRATOS_RESIDUAL_BASED_BOSSAK_SCHEME defined
973 
974 
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
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
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
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Definition: residual_based_bossak_scheme.hpp:35
ResidualBasedBossakScheme(ResidualBasedBossakScheme &rOther)
Definition: residual_based_bossak_scheme.hpp:146
void InitializeNonLinearIteration(Condition::Pointer rCurrentCondition, ProcessInfo &CurrentProcessInfo) override
Definition: residual_based_bossak_scheme.hpp:526
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: residual_based_bossak_scheme.hpp:111
BaseType::TSystemVectorType TSystemVectorType
Definition: residual_based_bossak_scheme.hpp:103
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residual_based_bossak_scheme.hpp:107
virtual ~ResidualBasedBossakScheme()
Definition: residual_based_bossak_scheme.hpp:157
void Condition_Calculate_RHS_Contribution(Condition::Pointer rCurrentCondition, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, ProcessInfo &CurrentProcessInfo) override
Definition: residual_based_bossak_scheme.hpp:678
void GetConditionDofList(Condition::Pointer rCurrentCondition, Element::DofsVectorType &ConditionDofList, ProcessInfo &CurrentProcessInfo) override
Get the list of Degrees of freedom to be assembled in the system for a Given Condition.
Definition: residual_based_bossak_scheme.hpp:733
BaseType::Pointer BaseTypePointer
Definition: residual_based_bossak_scheme.hpp:113
void Calculate_RHS_Contribution(Element::Pointer rCurrentElement, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, ProcessInfo &CurrentProcessInfo) override
Definition: residual_based_bossak_scheme.hpp:590
void InitializeSolutionStep(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Prepare state variables for a new step.
Definition: residual_based_bossak_scheme.hpp:403
Scheme< TSparseSpace, TDenseSpace > BaseType
Definition: residual_based_bossak_scheme.hpp:93
void CalculateSystemContributions(Element::Pointer rCurrentElement, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, ProcessInfo &CurrentProcessInfo) override
Compute local contributions.
Definition: residual_based_bossak_scheme.hpp:547
ModelPart::ElementsContainerType ElementsArrayType
Definition: residual_based_bossak_scheme.hpp:109
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBossakScheme)
void AddDynamicsToRHS(Condition::Pointer rCurrentCondition, LocalSystemVectorType &RHS_Contribution, LocalSystemMatrixType &D, LocalSystemMatrixType &M, ProcessInfo &CurrentProcessInfo)
Definition: residual_based_bossak_scheme.hpp:929
GeneralAlphaMethod mAlpha
Definition: residual_based_bossak_scheme.hpp:812
void UpdateVelocity(array_1d< double, 3 > &CurrentVelocity, const array_1d< double, 3 > &DeltaDisplacement, const array_1d< double, 3 > &PreviousVelocity, const array_1d< double, 3 > &PreviousAcceleration)
Definition: residual_based_bossak_scheme.hpp:826
BaseType::TDataType TDataType
Definition: residual_based_bossak_scheme.hpp:95
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residual_based_bossak_scheme.hpp:105
NewmarkMethod mNewmark
Definition: residual_based_bossak_scheme.hpp:813
void AddDynamicsToRHS(Element::Pointer rCurrentElement, LocalSystemVectorType &RHS_Contribution, LocalSystemMatrixType &D, LocalSystemMatrixType &M, ProcessInfo &CurrentProcessInfo)
Definition: residual_based_bossak_scheme.hpp:887
BaseTypePointer Clone() override
Clone method.
Definition: residual_based_bossak_scheme.hpp:164
void UpdateAcceleration(array_1d< double, 3 > &CurrentAcceleration, const array_1d< double, 3 > &DeltaDisplacement, const array_1d< double, 3 > &PreviousVelocity, const array_1d< double, 3 > &PreviousAcceleration)
Definition: residual_based_bossak_scheme.hpp:842
void InitializeNonLinIteration(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
unction to be called when it is needed to initialize an iteration. It is designed to be called at the...
Definition: residual_based_bossak_scheme.hpp:501
Element::DofsVectorType DofsVectorType
Definition: residual_based_bossak_scheme.hpp:99
void InitializeElements(ModelPart &rModelPart) override
Initialize all Element s in the provided ModelPart.
Definition: residual_based_bossak_scheme.hpp:332
GeneralVectors mVector
Definition: residual_based_bossak_scheme.hpp:816
GeneralMatrices mMatrix
Definition: residual_based_bossak_scheme.hpp:815
void InitializeNonLinearIteration(Element::Pointer rCurrentElement, ProcessInfo &CurrentProcessInfo) override
Definition: residual_based_bossak_scheme.hpp:536
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residual_based_bossak_scheme.hpp:101
int Check(ModelPart &r_model_part) override
Check whether the scheme was configured correctly for the provided ModelPart.
Definition: residual_based_bossak_scheme.hpp:751
void Predict(ModelPart &r_model_part, DofsArrayType &rDofSet, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Predict the solution for the current step.
Definition: residual_based_bossak_scheme.hpp:232
void AddDynamicsToLHS(LocalSystemMatrixType &LHS_Contribution, LocalSystemMatrixType &D, LocalSystemMatrixType &M, ProcessInfo &CurrentProcessInfo)
Definition: residual_based_bossak_scheme.hpp:859
ResidualBasedBossakScheme(double rAlpham=0, double rDynamic=1)
Definition: residual_based_bossak_scheme.hpp:117
void FinalizeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Finish the current time step.
Definition: residual_based_bossak_scheme.hpp:450
void Condition_CalculateSystemContributions(Condition::Pointer rCurrentCondition, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, ProcessInfo &CurrentProcessInfo) override
Definition: residual_based_bossak_scheme.hpp:630
void InitializeConditions(ModelPart &rModelPart) override
Initialize all Condition s in the provided ModelPart.
Definition: residual_based_bossak_scheme.hpp:366
void GetElementalDofList(Element::Pointer rCurrentElement, Element::DofsVectorType &ElementalDofList, ProcessInfo &CurrentProcessInfo) override
Get the list of Degrees of freedom to be assembled in the system for a given Element.
Definition: residual_based_bossak_scheme.hpp:721
BaseType::DofsArrayType DofsArrayType
Definition: residual_based_bossak_scheme.hpp:97
void Update(ModelPart &r_model_part, DofsArrayType &rDofSet, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Update the solution within the newton iteration.
Definition: residual_based_bossak_scheme.hpp:183
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
typename TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: scheme.h:71
bool mConditionsAreInitialized
Flag taking in account if the elements were initialized correctly or not.
Definition: scheme.h:757
ModelPart::ElementsContainerType ElementsArrayType
Elements containers definition.
Definition: scheme.h:89
virtual void EquationId(const Element &rElement, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo)
This method gets the eqaution id corresponding to the current element.
Definition: scheme.h:636
typename TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: scheme.h:74
typename TDenseSpace::VectorType LocalSystemVectorType
Local system vector type definition.
Definition: scheme.h:80
virtual void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function called once at the beginning of each solution step.
Definition: scheme.h:272
typename TSparseSpace::DataType TDataType
Data type definition.
Definition: scheme.h:68
typename TDenseSpace::MatrixType LocalSystemMatrixType
Local system matrix type definition.
Definition: scheme.h:77
virtual int Check(const ModelPart &rModelPart) const
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: scheme.h:508
bool mElementsAreInitialized
Flag to be used in controlling if the Scheme has been initialized or not.
Definition: scheme.h:756
ModelPart::ConditionsContainerType ConditionsArrayType
Conditions containers definition.
Definition: scheme.h:92
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int k
Definition: quadrature.py:595
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17
Definition: residual_based_bossak_scheme.hpp:39
double m
Definition: residual_based_bossak_scheme.hpp:42
double f
Definition: residual_based_bossak_scheme.hpp:41
Definition: residual_based_bossak_scheme.hpp:68
std::vector< Matrix > D
Definition: residual_based_bossak_scheme.hpp:71
std::vector< Matrix > M
Definition: residual_based_bossak_scheme.hpp:70
Definition: residual_based_bossak_scheme.hpp:76
std::vector< Vector > v
Definition: residual_based_bossak_scheme.hpp:78
std::vector< Vector > ap
Definition: residual_based_bossak_scheme.hpp:80
std::vector< Vector > a
Definition: residual_based_bossak_scheme.hpp:79
Definition: residual_based_bossak_scheme.hpp:47
double c6
Definition: residual_based_bossak_scheme.hpp:59
double beta
Definition: residual_based_bossak_scheme.hpp:49
double static_dynamic
Definition: residual_based_bossak_scheme.hpp:62
double c4
Definition: residual_based_bossak_scheme.hpp:57
double c5
Definition: residual_based_bossak_scheme.hpp:58
double c1
Definition: residual_based_bossak_scheme.hpp:54
double c3
Definition: residual_based_bossak_scheme.hpp:56
double c2
Definition: residual_based_bossak_scheme.hpp:55
double gamma
Definition: residual_based_bossak_scheme.hpp:50
double c0
Definition: residual_based_bossak_scheme.hpp:53