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.
explicit_hamilton_builder_and_solver.hpp
Go to the documentation of this file.
1 // Project Name: KratosSolidMechanicsApplication $
2 // Last modified by: $Author: JMCarbonell $
3 // Date: $Date: December 2015 $
4 // Revision: $Revision: 0.1 $
5 //
6 //
7 
8 #if !defined(KRATOS_EXPLICIT_HAMILTON_BUILDER_AND_SOLVER )
9 #define KRATOS_EXPLICIT_HAMILTON_BUILDER_AND_SOLVER
10 
11 
12 /* System includes */
13 #include <set>
14 
15 #ifdef _OPENMP
16 #include <omp.h>
17 #endif
18 
19 /* External includes */
20 //#include "boost/smart_ptr.hpp"
21 #include "utilities/timer.h"
22 
23 /* Project includes */
24 #include "includes/define.h"
25 #include "includes/kratos_flags.h"
27 #include "includes/model_part.h"
29 
31 
32 namespace Kratos
33 {
34 
50 template<class TSparseSpace,
51  class TDenseSpace, //= DenseSpace<double>,
52  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
53  >
54 class ExplicitHamiltonBuilderAndSolver : public BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
55 {
56 public:
61 
63 
65 
66  typedef typename BaseType::TDataType TDataType;
67 
69 
71 
73 
75 
77 
79 
81 
83 
85 
87 
89 
91 
93 
95 
104  typename TLinearSolver::Pointer pNewLinearSystemSolver)
105  : BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >(pNewLinearSystemSolver)
106  {
107  //std::cout<<" EXPLICIT HAMILTON BUILDER AND SOLVER "<<std::endl;
108  }
109 
113  {
114  }
115 
116 
123  //**************************************************************************
124  //**************************************************************************
125 
126  void BuildLHS(
127  typename TSchemeType::Pointer pScheme,
128  ModelPart& r_model_part,
130  {
131  KRATOS_TRY
132 
133  //Set Nodal Mass to zero
134  NodesArrayType& pNodes = r_model_part.Nodes();
135  ElementsArrayType& pElements = r_model_part.Elements();
136  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
137 
138  #ifdef _OPENMP
139  int number_of_threads = omp_get_max_threads();
140  #else
141  int number_of_threads = 1;
142  #endif
143 
144  vector<unsigned int> node_partition;
145  OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
146 
147  vector<unsigned int> element_partition;
148  OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
149 
150 
151  #pragma omp parallel
152  {
153 
154  #pragma omp for
155 
156  for(int k=0; k<number_of_threads; k++)
157  {
158  typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[k];
159  typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[k+1];
160 
161  for(ModelPart::NodeIterator i=i_begin; i!= i_end; ++i)
162  {
163  double& nodal_mass = i->FastGetSolutionStepValue(NODAL_MASS);
164  Matrix& nodal_inertia_dyadic = i->FastGetSolutionStepValue(INERTIA_DYADIC);
165 
166  nodal_mass = 0.0;
167  nodal_inertia_dyadic = ZeroMatrix(3,3);
168  }
169  }
170 
171  }
172 
173  //Calculate and assemble Mass Matrix on nodes
174 
175  unsigned int index = 0;
176 
177  #pragma omp parallel
178  {
179  int k = OpenMPUtils::ThisThread();
180  typename ElementsArrayType::iterator ElemBegin = pElements.begin() + element_partition[k];
181  typename ElementsArrayType::iterator ElemEnd = pElements.begin() + element_partition[k + 1];
182 
183  for (typename ElementsArrayType::iterator itElem = ElemBegin; itElem != ElemEnd; itElem++)
184  {
185  Matrix MassMatrix;
186 
187  Element::GeometryType& geometry = itElem->GetGeometry(); //element nodes
188 
189  (itElem)->CalculateMassMatrix(MassMatrix, rCurrentProcessInfo);
190 
191  const unsigned int dimension = geometry.WorkingSpaceDimension();
192 
193  index = 0;
194  for (unsigned int i = 0; i <geometry.size(); i++)
195  {
196  index = i * ( dimension * 2 );
197 
198  double& mass = geometry(i)->FastGetSolutionStepValue(NODAL_MASS);
199  Matrix& nodal_inertia_dyadic = geometry(i)->FastGetSolutionStepValue(INERTIA_DYADIC);
200 
201  geometry(i)->SetLock();
202 
203  mass += MassMatrix(index,index);
204  for(unsigned int k=0; k<dimension; k++)
205  {
206  for(unsigned int l=0; l<dimension; l++)
207  {
208  nodal_inertia_dyadic(k,l) += MassMatrix(k+index+dimension, l+index+dimension);
209  }
210  }
211  geometry(i)->UnSetLock();
212  }
213  }
214  }
215 
216 
217 
218  #pragma omp parallel
219  {
220 
221  #pragma omp for
222 
223  for(int k=0; k<number_of_threads; k++)
224  {
225  typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[k];
226  typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[k+1];
227 
228  for(ModelPart::NodeIterator i=i_begin; i!= i_end; ++i)
229  {
230  double& nodal_mass = i->FastGetSolutionStepValue(NODAL_MASS);
231  Matrix& nodal_inertia_dyadic = i->FastGetSolutionStepValue(INERTIA_DYADIC);
232 
233  //inertia_dyadic is multiplied by the mass and divided by the total mass
234  //this is done to not increase the total inertia of the section
235  //the end is an average inertia for the nodal section
236  nodal_inertia_dyadic /= nodal_mass;
237 
238  //std::cout<<" Node ["<<i->Id()<<"] (mass:"<<nodal_mass<<", inertia:"<<nodal_inertia_dyadic<<") "<<std::endl;
239 
240  }
241  }
242 
243  }
244 
245  KRATOS_CATCH( "" )
246 
247  }
248 
249  //**************************************************************************
250  //**************************************************************************
251 
252  void BuildRHS(
253  typename TSchemeType::Pointer pScheme,
254  ModelPart& r_model_part,
256  {
257  KRATOS_TRY
258 
259 
260  //Set Nodal Liapunov variables to zero
261 
262  //getting nodes from the model
263  NodesArrayType& pNodes = r_model_part.Nodes();
264 
265  #ifdef _OPENMP
266  int number_of_threads = omp_get_max_threads();
267  #else
268  int number_of_threads = 1;
269  #endif
270 
271  vector<unsigned int> node_partition;
272  OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
273 
274  #pragma omp parallel
275  {
276 
277  #pragma omp for
278 
279  for(int k=0; k<number_of_threads; k++)
280  {
281  typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[k];
282  typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[k+1];
283 
284  for(ModelPart::NodeIterator i=i_begin; i!= i_end; ++i)
285  {
286  (i)->FastGetSolutionStepValue(FORCE_RESIDUAL).clear();
287  (i)->FastGetSolutionStepValue(MOMENT_RESIDUAL).clear();
288  }
289  }
290 
291  }
292 
293  // Compute condition contributions to RHS.
294  CalculateAndAddConditionsRHS(pScheme, r_model_part);
295 
296  // Compute element contributions to RHS.
297  CalculateAndAddElementsRHS(pScheme, r_model_part);
298 
299  KRATOS_CATCH( "" )
300  }
301 
302 
303  //**************************************************************************
304  //**************************************************************************
305 
307  typename TSchemeType::Pointer pScheme,
308  ModelPart& r_model_part,
310  TSystemVectorType& Dx,
312  {
313  KRATOS_TRY
314 
315  if (!pScheme)
316  KRATOS_THROW_ERROR( std::runtime_error, "No scheme provided!", "" )
317 
318  NodesArrayType& pNodes = r_model_part.Nodes();
319  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
320 
321  double DeltaTime = rCurrentProcessInfo[DELTA_TIME];
322  double Alpha = rCurrentProcessInfo[ALPHA_TRAPEZOIDAL_RULE];
323 
324  #ifdef _OPENMP
325  int number_of_threads = omp_get_max_threads();
326  #else
327  int number_of_threads = 1;
328  #endif
329 
330  vector<unsigned int> node_partition;
331  OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
332 
333  //initial build to initialize all
334  this->Build(pScheme, r_model_part, A, b);
335 
336  #pragma omp parallel
337  {
338 
339  #pragma omp for
340 
341  for(int k=0; k<number_of_threads; k++)
342  {
343  typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[k];
344  typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[k+1];
345 
346  for(ModelPart::NodeIterator i=i_begin; i!= i_end; ++i)
347  {
348  //is active by default
349  bool node_is_active = true;
350  if( (i)->IsDefined(ACTIVE) )
351  node_is_active = (i)->Is(ACTIVE);
352 
353  if(node_is_active)
354  {
355 
356  //Rotation
357  array_1d<double, 3 >& CurrentStepRotation = (i)->FastGetSolutionStepValue(STEP_ROTATION);
358 
359  //Moment and momentum: Rotation Part
360  array_1d<double,3>& moment_residual = (i)->FastGetSolutionStepValue(MOMENT_RESIDUAL);
361  array_1d<double,3>& rotation_momentum = (i)->FastGetSolutionStepValue(ROTATION_MOMENTUM);
362 
363  //moment_residual is (Mext-Mint) then the sign is changed respect the reference formulation
364  array_1d<double,3> Y = DeltaTime * ( rotation_momentum + Alpha * DeltaTime * moment_residual );
365 
366  // (0) Solving Lyapunov - type equation: WRONG it must be done at integration point!!
367 
368  int iter = 0;
369  int max_iters = 15;
370 
371  double residual = 1;
372  double tolerance = 1e-12;
373 
374  Vector Residual = ZeroVector(3); //current iteration residual vector
375  Vector Rotation = ZeroVector(3); //current step rotation vector
376  Vector ReferenceResidual = ZeroVector(3);
377 
378  for(unsigned int j=0; j<3; j++)
379  {
380  Rotation[j] = 1e-5; //CurrentStepRotation[j];
381  ReferenceResidual[j] = Y[j];
382  }
383 
384 
385  //std::cout<<" Node ["<<i->Id()<<"] (moment:"<<moment_residual<<",momentum:"<<rotation_momentum<<") norm residual "<<norm_2(ReferenceResidual)<<std::endl;
386 
387 
388  // if( norm_2(ReferenceResidual) <= tolerance ){
389 
390  // Rotation = ZeroVector(3);
391  // CurrentStepRotation.clear();
392 
393  // //std::cout<<" Node ["<<i->Id()<<"] (STEP_ROTATION:"<<Rotation<<") "<<iter<<" reference_residual "<<norm_2(ReferenceResidual)<<std::endl;
394 
395  // }
396  // else {
397 
398  Matrix Tangent = ZeroMatrix(3,3);
399  Matrix InverseTangent = ZeroMatrix(3,3);
400  double determinant = 0;
401 
402  for(unsigned int j=0; j<3; j++)
403  {
404  CurrentStepRotation[j] = Rotation[j];
405  }
406 
407 
408  while ( residual > tolerance && iter < max_iters )
409  {
410  // (1) Build the residual :
411 
412  // double BuildTimeStart = Timer::GetTime();
413  this->Build(*i.base(), pScheme, r_model_part, A, b);
414  // BuildTime = Timer::GetTime() - BuildTime;
415 
416  // if (this->GetEchoLevel() > 1)
417  // {
418  // std::cout<<"Time Building :"<<BuildTime<<std::endl;
419  // }
420 
421  array_1d<double,3>& LyapunovResidual = i->FastGetSolutionStepValue(RESIDUAL_LYAPUNOV);
422  Matrix& LyapunovTangent = i->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
423 
424 
425  //std::cout<<"(id:"<<i->Id()<<") LyapunovResidual "<<LyapunovResidual<<" LyapunovTangent "<<LyapunovTangent<<std::endl;
426 
427  for(unsigned int j=0; j<3; j++)
428  {
429  Residual[j] = ReferenceResidual[j] - LyapunovResidual[j];
430  }
431 
432  // (3) Solve the system:
433  MathUtils<double>::InvertMatrix( LyapunovTangent, InverseTangent, determinant );
434 
435  Rotation += prod( InverseTangent, Residual );
436 
437 
438  // (4) Update Step Rotations:
439  if( (i->pGetDof(ROTATION_X))->IsFree() )
440  CurrentStepRotation[0] = Rotation[0];
441  if( (i->pGetDof(ROTATION_Y))->IsFree() )
442  CurrentStepRotation[1] = Rotation[1];
443  if( (i->pGetDof(ROTATION_Z))->IsFree() )
444  CurrentStepRotation[2] = Rotation[2];
445 
446 
447  // (5) Update Rotations:
448  bool update_rotations = false;
449 
450  if( update_rotations ){
451 
452  array_1d<double, 3 >& PreviousRotation = (i)->FastGetSolutionStepValue(ROTATION,1);
453  array_1d<double, 3 >& CurrentRotation = (i)->FastGetSolutionStepValue(ROTATION);
454 
455  Vector CurrentRotationVector = ZeroVector(3);
456  for( unsigned int j=0; j<3; j++)
457  {
458  CurrentRotationVector[j] = PreviousRotation[j]; //previous iteration total rotation
459  }
460 
461  QuaternionType ReferenceRotationQuaternion = QuaternionType::FromRotationVector( CurrentRotationVector );
462  QuaternionType StepRotationQuaternion = QuaternionType::FromRotationVector( Rotation );
463  QuaternionType CurrentRotationQuaternion = StepRotationQuaternion * ReferenceRotationQuaternion;
464 
465  CurrentRotationQuaternion.ToRotationVector( CurrentRotationVector );
466 
467 
468 
469  for( unsigned int j=0; j<3; j++)
470  {
471  CurrentRotation[j] = CurrentRotationVector[j];
472  }
473 
474  }
475 
476  //(6) Check Residual:
477  residual = norm_2( Residual );
478 
479  if (this->GetEchoLevel() > 1){
480  std::cout<<" ("<<iter<<") : Rotation "<<CurrentStepRotation<<" Residual norm: "<<residual<<std::endl;
481  }
482 
483  iter++;
484 
485  }
486 
487 
488 
489  if( iter >= max_iters ){
490  std::cout<<" Node ["<<i->Id()<<"] : LYAPUNOV ROTATION EQUATION NOT CONVERGED, iters:"<<iter<<", residual: "<<residual<<" STEP_ROTATION:"<<Rotation<<std::endl;
491  }
492  else{
493  if (this->GetEchoLevel() > 1){
494  std::cout<<" Node ["<<i->Id()<<"] (STEP_ROTATION:"<<Rotation<<") iters: "<<iter<<" residual "<<residual<<std::endl;
495  }
496  }
497 
498  }
499  }
500  //}
501 
502  }
503  }
504 
505  KRATOS_CATCH("")
506 
507  }
508 
509  //***************************************************************************
510  //***************************************************************************
511 
512  void Build(
513  Node::Pointer pNode,
514  typename TSchemeType::Pointer pScheme,
515  ModelPart& r_model_part,
518  {
519 
520  KRATOS_TRY
521 
522  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
523 
524  //Set Nodal Liapunov variables to zero
525  array_1d<double,3>& LyapunovResidual = (pNode)->FastGetSolutionStepValue(RESIDUAL_LYAPUNOV);
526  Matrix& LyapunovTangent = (pNode)->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
527 
528  LyapunovResidual.clear();
529  LyapunovTangent = ZeroMatrix(3,3);
530 
531  //IT HAS TO BE MODIFIED TO ONLY COMPUTE THE NODE NEIGHBOUR ELEMENTS AND CONDITIONS:
532 
533  ElementWeakPtrVectorType& nElements = pNode->GetValue(NEIGHBOUR_ELEMENTS);
534 
535  //std::cout<<" node ("<<(pNode)->Id()<<"): "<<rE.size()<<std::endl;
536 
537  //vector containing the localization in the system of the different terms
539 
540  //contributions to the system
541  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
542  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
543 
544  for(auto i_nelem(nElements.begin()); i_nelem != nElements.end(); ++i_nelem)
545  {
546  //calculate elemental contribution
547  pScheme->CalculateSystemContributions(*i_nelem.base(), LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
548  }
549 
550 
551 
552  KRATOS_CATCH( "" )
553 
554  }
555 
556 
557  //***************************************************************************
558  //***************************************************************************
559 
560  void Build(
561  typename TSchemeType::Pointer pScheme,
562  ModelPart& r_model_part,
565  {
566 
567  KRATOS_TRY
568 
569  //Set Nodal Liapunov variables to zero
570 
571  //getting nodes from the model
572  NodesArrayType& pNodes = r_model_part.Nodes();
573  //getting elements from the model
574  ElementsArrayType& pElements = r_model_part.Elements();
575  //getting conditions from the model
576  ConditionsArrayType& pConditions = r_model_part.Conditions();
577 
578 
579  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
580 
581  #ifdef _OPENMP
582  int number_of_threads = omp_get_max_threads();
583  #else
584  int number_of_threads = 1;
585  #endif
586 
587  vector<unsigned int> node_partition;
588  OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
589 
590  #pragma omp parallel
591  {
592 
593  #pragma omp for
594 
595  for(int k=0; k<number_of_threads; k++)
596  {
597  typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[k];
598  typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[k+1];
599 
600  for(ModelPart::NodeIterator i=i_begin; i!= i_end; ++i)
601  {
602  array_1d<double,3>& LyapunovResidual = i->FastGetSolutionStepValue(RESIDUAL_LYAPUNOV);
603  Matrix& LyapunovTangent = i->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
604 
605  LyapunovResidual.clear();
606  LyapunovTangent = ZeroMatrix(3,3);
607  }
608  }
609 
610  }
611 
612  //IT HAS TO BE MODIFIED TO ONLY COMPUTE THE NODE NEIGHBOR ELEMENTS AND CONDITIONS:
613  bool compute_everything = false;
614  if( compute_everything ){
615 
616  //vector containing the localization in the system of the different terms
618 
619  //contributions to the system
620  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
621  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
622 
623 
624  for (typename ElementsArrayType::ptr_iterator it = pElements.ptr_begin(); it != pElements.ptr_end(); ++it)
625  {
626  //calculate elemental contribution
627  pScheme->CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
628  }
629 
630  LHS_Contribution.resize(0, 0, false);
631  RHS_Contribution.resize(0, false);
632 
633  // assemble all conditions
634  for (typename ConditionsArrayType::ptr_iterator it = pConditions.ptr_begin(); it != pConditions.ptr_end(); ++it)
635  {
636  //calculate condition contribution
637  pScheme->Condition_CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
638 
639  }
640  }
641 
642 
643  KRATOS_CATCH( "" )
644 
645  }
646 
647  //***************************************************************************
648  //***************************************************************************
649 
650 
651  void CalculateAndAddConditionsRHS(typename TSchemeType::Pointer pScheme, ModelPart& r_model_part )
652  {
653 
654  KRATOS_TRY
655 
656  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
657  ConditionsArrayType& pConditions = r_model_part.Conditions();
658 
659 #ifdef _OPENMP
660  int number_of_threads = omp_get_max_threads();
661 #else
662  int number_of_threads = 1;
663 #endif
664 
665  vector<unsigned int> condition_partition;
666  OpenMPUtils::CreatePartition(number_of_threads, pConditions.size(), condition_partition);
667 
668 
669  #pragma omp parallel for
670  for(int k=0; k<number_of_threads; k++)
671  {
672  typename ConditionsArrayType::ptr_iterator it_begin=pConditions.ptr_begin()+condition_partition[k];
673  typename ConditionsArrayType::ptr_iterator it_end=pConditions.ptr_begin()+condition_partition[k+1];
674 
675  for (typename ConditionsArrayType::ptr_iterator it= it_begin; it!=it_end; ++it)
676  {
677 
678  LocalSystemVectorType RHS_Condition_Contribution = LocalSystemVectorType(0);
679 
680  Element::EquationIdVectorType EquationId; //Dummy
681 
682  //is active by default
683  bool condition_is_active = true;
684  if( (*it)->IsDefined(ACTIVE) )
685  condition_is_active = (*it)->Is(ACTIVE);
686 
687  if(condition_is_active)
688  {
689  pScheme->Condition_Calculate_RHS_Contribution(*it, RHS_Condition_Contribution, EquationId, rCurrentProcessInfo);
690  }
691 
692 
693  }
694  }
695 
696  KRATOS_CATCH("")
697  }
698 
699 
700  //***************************************************************************
701  //***************************************************************************
702 
703 
704  void CalculateAndAddElementsRHS(typename TSchemeType::Pointer pScheme, ModelPart& r_model_part )
705  {
706 
707  KRATOS_TRY
708 
709  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
710  ElementsArrayType& pElements = r_model_part.Elements();
711 
712 #ifdef _OPENMP
713  int number_of_threads = omp_get_max_threads();
714 #else
715  int number_of_threads = 1;
716 #endif
717 
718  vector<unsigned int> element_partition;
719  OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
720 
721  #pragma omp parallel for
722  for(int k=0; k<number_of_threads; k++)
723  {
724  typename ElementsArrayType::ptr_iterator it_begin=pElements.ptr_begin()+element_partition[k];
725  typename ElementsArrayType::ptr_iterator it_end=pElements.ptr_begin()+element_partition[k+1];
726  for (typename ElementsArrayType::ptr_iterator it= it_begin; it!=it_end; ++it)
727  {
728 
729  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
730  Element::EquationIdVectorType EquationId; //Dummy
731 
732  //is active by default
733  bool element_is_active = true;
734  if( (*it)->IsDefined(ACTIVE) )
735  element_is_active = (*it)->Is(ACTIVE);
736 
737  if(element_is_active)
738  {
739  pScheme->Calculate_RHS_Contribution(*it, RHS_Contribution, EquationId, rCurrentProcessInfo);
740  }
741 
742  }
743  }
744 
745  KRATOS_CATCH("")
746  }
747 
748 
749  //**************************************************************************
750  //**************************************************************************
751 
752 
754  ModelPart& r_model_part,
756  TSystemVectorType& Dx,
758  {
759  KRATOS_TRY
760  KRATOS_CATCH( "" )
761  }
762 
763  //**************************************************************************
764  //**************************************************************************
765 
767  ModelPart& r_model_part,
769  TSystemVectorType& Dx,
771  {
772  KRATOS_TRY
773  KRATOS_CATCH( "" )
774  }
775 
776  //**************************************************************************
777  //**************************************************************************
778 
780  typename TSchemeType::Pointer pScheme,
781  ModelPart& r_model_part,
783  TSystemVectorType& Dx,
785  {
786  }
787 
788  //**************************************************************************
789  //**************************************************************************
790 
792  typename TSchemeType::Pointer pScheme,
793  ModelPart& r_model_part,
795  {
796  }
797 
802  void Clear()
803  {
804  this->mDofSet = DofsArrayType();
805 
806  if (this->mpReactionsVector != NULL)
807  TSparseSpace::Clear((this->mpReactionsVector));
808  // this->mReactionsVector = TSystemVectorType();
809 
810  this->mpLinearSystemSolver->Clear();
811 
812  if (this->GetEchoLevel() > 1)
813  {
814  std::cout << "ExplicitHamiltonBuilderAndSolver Clear Function called" << std::endl;
815  }
816  }
817 
825  virtual int Check(ModelPart& r_model_part)
826  {
827  KRATOS_TRY
828 
829  return 0;
830 
831  KRATOS_CATCH( "" )
832  }
833 
834 
849 protected:
859  //******************************************************************************************
860  //******************************************************************************************
861 
862 
877 private:
900 }; /* Class ExplicitHamiltonBuilderAndSolver */
901 
908 } /* namespace Kratos.*/
909 
910 #endif /* KRATOS_EXPLICIT_HAMILTON_BUILDER_AND_SOLVER defined */
Definition: beam_math_utilities.hpp:31
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
ModelPart::NodesContainerType NodesArrayType
The containers of the entities.
Definition: builder_and_solver.h:109
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: builder_and_solver.h:111
TSystemVectorPointerType mpReactionsVector
Definition: builder_and_solver.h:751
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition of the pointer to the vector.
Definition: builder_and_solver.h:91
TSparseSpace::DataType TDataType
Definition of the data type.
Definition: builder_and_solver.h:79
TLinearSolver::Pointer mpLinearSystemSolver
Definition: builder_and_solver.h:737
DofsArrayType mDofSet
Pointer to the linear solver.
Definition: builder_and_solver.h:739
TDenseSpace::VectorType LocalSystemVectorType
The local vector definition.
Definition: builder_and_solver.h:97
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition of the pointer to the sparse matrix.
Definition: builder_and_solver.h:88
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Definition: explicit_hamilton_builder_and_solver.hpp:55
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: explicit_hamilton_builder_and_solver.hpp:80
virtual int Check(ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:825
void ApplyPointLoads(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemVectorType &b)
Definition: explicit_hamilton_builder_and_solver.hpp:791
BaseType::NodesArrayType NodesArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:82
void FinalizeSolutionStep(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies certain operations at the system of equations at the end of the solution step.
Definition: explicit_hamilton_builder_and_solver.hpp:766
void Build(Node::Pointer pNode, typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &b)
Definition: explicit_hamilton_builder_and_solver.hpp:512
void Build(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &b)
equivalent (but generally faster) then performing BuildLHS and BuildRHS
Definition: explicit_hamilton_builder_and_solver.hpp:560
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemVectorType &b)
Function to perform the build of the RHS. The vector could be sized as the total number of dofs or as...
Definition: explicit_hamilton_builder_and_solver.hpp:252
BaseType::ElementsContainerType ElementsContainerType
Definition: explicit_hamilton_builder_and_solver.hpp:88
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:74
ExplicitHamiltonBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: explicit_hamilton_builder_and_solver.hpp:103
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: explicit_hamilton_builder_and_solver.hpp:78
BaseType::DofsArrayType DofsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:68
void BuildAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function to perform the building and solving phase at the same time.
Definition: explicit_hamilton_builder_and_solver.hpp:306
void CalculateAndAddConditionsRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:651
BaseType::TSystemMatrixType TSystemMatrixType
Definition: explicit_hamilton_builder_and_solver.hpp:70
BaseType::TSchemeType TSchemeType
Definition: explicit_hamilton_builder_and_solver.hpp:64
void CalculateAndAddElementsRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:704
KRATOS_CLASS_POINTER_DEFINITION(ExplicitHamiltonBuilderAndSolver)
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:94
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: explicit_hamilton_builder_and_solver.hpp:62
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: explicit_hamilton_builder_and_solver.hpp:76
BaseType::TDataType TDataType
Definition: explicit_hamilton_builder_and_solver.hpp:66
void InitializeSolutionStep(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies certain operations at the system of equations at the beginning of the solution step.
Definition: explicit_hamilton_builder_and_solver.hpp:753
void Clear()
Definition: explicit_hamilton_builder_and_solver.hpp:802
virtual ~ExplicitHamiltonBuilderAndSolver()
Definition: explicit_hamilton_builder_and_solver.hpp:112
BeamMathUtils< double > BeamMathUtilsType
Definition: explicit_hamilton_builder_and_solver.hpp:90
Quaternion< double > QuaternionType
Definition: explicit_hamilton_builder_and_solver.hpp:92
BaseType::ConditionsArrayType ConditionsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:86
BaseType::TSystemVectorType TSystemVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:72
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies the dirichlet conditions. This operation may be very heavy or completely unexpensive depen...
Definition: explicit_hamilton_builder_and_solver.hpp:779
BaseType::ElementsArrayType ElementsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:84
void BuildLHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A)
Function to perform the building of the LHS, depending on the implementation chosen the size of the m...
Definition: explicit_hamilton_builder_and_solver.hpp:126
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
ptr_iterator ptr_begin()
Definition: geometry.h:481
SizeType WorkingSpaceDimension() const
Definition: geometry.h:1287
iterator begin()
Definition: global_pointers_vector.h:221
iterator end()
Definition: global_pointers_vector.h:229
static BoundedMatrix< double, TDim, TDim > InvertMatrix(const BoundedMatrix< double, TDim, TDim > &rInputMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
Calculates the inverse of a 2x2, 3x3 and 4x4 matrices (using bounded matrix for performance)
Definition: math_utils.h:197
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
void ToRotationVector(T &rx, T &ry, T &rz) const
Definition: quaternion.h:262
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
BOOST_UBLAS_INLINE void clear()
Definition: array_1d.h:325
#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
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
residual
Definition: hinsberg_optimization_4.py:433
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
def Alpha(n, j)
Definition: quadrature.py:93
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31