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.
modified_linear_strategy.h
Go to the documentation of this file.
1 /* *********************************************************
2 *
3 * Last Modified by: $Author: rrossi $
4 * Date: $Date: 2008-11-10 14:23:32 $
5 * Revision: $Revision: 1.12 $
6 *
7 * ***********************************************************/
8 
9 
10 #if !defined(KRATOS_LAP_MODIFIED_LINEAR_STRATEGY)
11 #define KRATOS_LAP_MODIFIED_LINEAR_STRATEGY
12 
13 
14 /* System includes */
15 
16 
17 /* External includes */
18 // #include "boost/smart_ptr.hpp"
19 #include <cstdlib>
20 #include <boost/timer.hpp>
21 
22 
23 #include <pybind11/pybind11.h>
24 #include "includes/define.h"
25 #include "includes/define_python.h"
26 
27 /* Project includes */
28 #include "includes/define.h"
29 #include "includes/model_part.h"
30 
33 #include "ULF_application.h"
34 
35 
37 
38 
39 namespace Kratos
40 {
41 
68 
89 template<unsigned int TDim, class TSparseSpace,
90  class TDenseSpace, //= DenseSpace<double>,
91  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
92  >
94  : public ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>
95 {
96 public:
102 
104 
105  typedef typename BaseType::TDataType TDataType;
106 
107  typedef TSparseSpace SparseSpaceType;
108 
111 
112  //typedef typename BaseType::DofSetType DofSetType;
113 
115 
117 
119 
121 
123 
126 
128 
138  typename TSchemeType::Pointer pScheme,
139  typename TLinearSolver::Pointer pNewLinearSolver,
140  bool CalculateReactionFlag = false,
141  bool ReformDofSetAtEachStep = false,
142  bool CalculateNormDxFlag = false,
143  bool MoveMeshFlag = false
144  )
145  : ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>(model_part, MoveMeshFlag)
146  {
147  KRATOS_TRY
148 
149  mCalculateReactionsFlag = CalculateReactionFlag;
150  mReformDofSetAtEachStep = ReformDofSetAtEachStep;
151  mCalculateNormDxFlag = CalculateNormDxFlag;
152 
153 
154  //saving the scheme
155  mpScheme = pScheme;
156 
157  //saving the linear solver
158  mpLinearSolver = pNewLinearSolver;
159 
160  //setting up the default builder and solver
161  mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer
162  (
164  );
165 
166  //set flag to start correcty the calculations
167  mSolutionStepIsInitialized = false;
168  mInitializeWasPerformed = false;
169 
170  //tells to the builder and solver if the reactions have to be Calculated or not
171  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
172 
173  //tells to the Builder And Solver if the system matrix and vectors need to
174  //be reshaped at each step or not
175  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
176 
177  //set EchoLevel to the default value (only time is displayed)
178  this->SetEchoLevel(1);
179 
180  //by default the matrices are rebuilt at each solution step
182 
183  KRATOS_CATCH("")
184  }
185 
186  //constructor specifying the builder and solver
189  typename TSchemeType::Pointer pScheme,
190  typename TLinearSolver::Pointer pNewLinearSolver,
191  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
192  bool CalculateReactionFlag = false,
193  bool ReformDofSetAtEachStep = false,
194  bool CalculateNormDxFlag = false,
195  bool MoveMeshFlag = false
196  )
197  : ImplicitSolvingStrategy<TSparseSpace,TDenseSpace,TLinearSolver>(model_part,MoveMeshFlag)
198  {
199  KRATOS_TRY
200 
201  mCalculateReactionsFlag = CalculateReactionFlag;
202  mReformDofSetAtEachStep = ReformDofSetAtEachStep;
203  mCalculateNormDxFlag = CalculateNormDxFlag;
204 
205  //saving the scheme
206  mpScheme = pScheme;
207 
208  //saving the linear solver
209  mpLinearSolver = pNewLinearSolver;
210 
211  //setting up the builder and solver
212  mpBuilderAndSolver = pNewBuilderAndSolver;
213 
214  //set flag to start correcty the calculations
215  mSolutionStepIsInitialized = false;
216  mInitializeWasPerformed = false;
217 
218  //tells to the builder and solver if the reactions have to be Calculated or not
219  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
220 
221  //tells to the Builder And Solver if the system matrix and vectors need to
222  //be reshaped at each step or not
223  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
224 
225  //set EchoLevel to the default value (only time is displayed)
226  this->SetEchoLevel(1);
227 
228  //by default the matrices are rebuilt at each solution step
230 
231  KRATOS_CATCH("")
232  }
233 
237 
241  //Set and Get Scheme ... containing Builder, Update and other
242  void SetScheme(typename TSchemeType::Pointer pScheme )
243  {
244  mpScheme = pScheme;
245  };
246  typename TSchemeType::Pointer GetScheme()
247  {
248  return mpScheme;
249  };
250 
251  //Set and Get the BuilderAndSolver
252  void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver )
253  {
254  mpBuilderAndSolver = pNewBuilderAndSolver;
255  };
256  typename TBuilderAndSolverType::Pointer GetBuilderAndSolver()
257  {
258  return mpBuilderAndSolver;
259  };
260 
261 
262  void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
263  {
264  mCalculateReactionsFlag = CalculateReactionsFlag;
265  GetBuilderAndSolver()->SetCalculateReactionsFlag(mCalculateReactionsFlag);
266  }
268  {
269  return mCalculateReactionsFlag;
270  }
271 
273  {
274  mReformDofSetAtEachStep = flag;
275  GetBuilderAndSolver()->SetReshapeMatrixFlag(mReformDofSetAtEachStep);
276  }
278  {
279  return mReformDofSetAtEachStep;
280  }
281 
282  //level of echo for the solving strategy
283  // 0 -> mute... no echo at all
284  // 1 -> printing time and basic informations
285  // 2 -> printing linear solver data
286  // 3 -> Print of debug informations:
287  // Echo of stiffness matrix, Dx, b...
288  void SetEchoLevel(int Level)
289  {
290  BaseType::SetEchoLevel( Level );
291  GetBuilderAndSolver()->SetEchoLevel(Level);
292  }
293 
294 
295  //*********************************************************************************
302  void Predict()
303  {
304  KRATOS_TRY
305  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
306  //if the operations needed were already performed this does nothing
307  //if(mInitializeWasPerformed == false)
308  //{
309  // Initialize();
310  // mInitializeWasPerformed = true;
311  //}
312 
314  //if (mSolutionStepIsInitialized == false)
315  // InitializeSolutionStep();
316 
317 
318  TSystemMatrixType& mA = *mpA;
319  TSystemVectorType& mDx = *mpDx;
320  TSystemVectorType& mb = *mpb;
321 
322  DofsArrayType& rDofSet = GetBuilderAndSolver()->GetDofSet();
323 
324  this->GetScheme()->Predict(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
325 
326  KRATOS_CATCH("")
327  }
328 
329  //*********************************************************************************
334  //**********************************************************************
335  double Solve()
336  {
337  KRATOS_TRY
338 
339  //pointers needed in the solution
340  typename TSchemeType::Pointer pScheme = GetScheme();
341  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
343 
344  ProcessInfo& pCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
345 
346  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
347  //if the operations needed were already performed this does nothing
348  if(mInitializeWasPerformed == false)
349  {
350  Initialize();
351  mInitializeWasPerformed = true;
352  }
353 
354  //prints informations about the current time
355  if (BaseType::GetEchoLevel()!=0 && rank == 0)
356  {
357  std::cout << " " << std::endl;
358  std::cout << "CurrentTime = " << pCurrentProcessInfo[TIME] << std::endl;
359  }
360 
361  //initialize solution step
362  if (mSolutionStepIsInitialized == false)
363  {
364  InitializeSolutionStep();
365  mSolutionStepIsInitialized = true;
366  }
367 
368  //updates the database with a prediction of the solution
369  Predict();
370 
371  TSystemMatrixType& mA = *mpA;
372  TSystemVectorType& mDx = *mpDx;
373  TSystemVectorType& mb = *mpb;
374 
375  TSystemMatrixType& mD = mpD;
376 
378  {
379  TSparseSpace::SetToZero(mA);
380  TSparseSpace::SetToZero(mDx);
381  TSparseSpace::SetToZero(mb);
382 
383  TSparseSpace::SetToZero(mD);
384 
385  //pBuilderAndSolver->BuildAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
386 
387  pBuilderAndSolver->Build(pScheme,BaseType::GetModelPart(),mA,mb);
388  //ADD HERE THE INTERFACE LAPLACIAN
389  /*
390  ConstructMatrixStructure_FluidDivergenceMatrixD( mD, BaseType::GetModelPart());
391 
392  double density_str=10000.0;
393  BuildAuxiliariesFSI(mD, density_str, BaseType::GetModelPart());
394  mA+=mD;
395  */
396  pBuilderAndSolver->ApplyDirichletConditions(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
397  //solve!
398  pBuilderAndSolver->SystemSolve(mA,mDx,mb);
399 
400 
401  //pBuilderAndSolver->BuildAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
403  }
404  else
405  {
406  TSparseSpace::SetToZero(mDx);
407  TSparseSpace::SetToZero(mb);
408  pBuilderAndSolver->BuildRHSAndSolve(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
409  }
410 
411  if (BaseType::GetEchoLevel()==3) //if it is needed to print the debug info
412  {
413  std::cout << "SystemMatrix = " << mA << std::endl;
414  std::cout << "solution obtained = " << mDx << std::endl;
415  std::cout << "RHS = " << mb << std::endl;
416  }
417 
418  //update results
419  DofsArrayType& rDofSet = pBuilderAndSolver->GetDofSet();
420  pScheme->Update(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
421 
422  //move the mesh if needed
424 
425  //calculate if needed the norm of Dx
426  double normDx = 0.00;
427  if(mCalculateNormDxFlag == true)
428  {
429  normDx = TSparseSpace::TwoNorm(mDx);
430  }
431 
432  //calculate reactions if required
433  if (mCalculateReactionsFlag ==true)
434  {
435  pBuilderAndSolver->CalculateReactions(pScheme,BaseType::GetModelPart(),mA,mDx,mb);
436  }
437 
438  //Finalisation of the solution step,
439  //operations to be done after achieving convergence, for example the
440  //Final Residual Vector (mb) has to be saved in there
441  //to avoid error accumulation
442  pScheme->FinalizeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
443  pBuilderAndSolver->FinalizeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
444 
445  //deallocate the systemvectors if needed
446  if (mReformDofSetAtEachStep == true)
447  {
448  if(rank == 0) std::cout << "Clearing System" << std::endl;
449  this->Clear();
450  //std::cout << "Clearing System" << std::endl;
451  //TSparseSpace::ClearData(mA);
452  //TSparseSpace::ClearData(mDx);
453  //TSparseSpace::ClearData(mb);
454  }
455 
456  //Cleaning memory after the solution
457  pScheme->Clean();
458 
459  //reset flags for next step
460  mSolutionStepIsInitialized = false;
461 
462  return normDx;
463 
464  KRATOS_CATCH("")
465 
466  }
467 
469  {
470  TSystemMatrixType& mA = *mpA;
471 
472  return mA;
473  }
474  //*********************************************************************************
476  {
477  if(TSparseSpace::Size(*mpb) !=0)
478  return TSparseSpace::TwoNorm(*mpb);
479  else
480  return 0.0;
481 
482  }
483 
484  //*********************************************************************************
492  {
493  TSystemMatrixType& mA = *mpA;
494  TSystemVectorType& mDx = *mpDx;
495  TSystemVectorType& mb = *mpb;
496 
497  DofsArrayType& rDofSet = GetBuilderAndSolver()->GetDofSet();
498  GetScheme()->CalculateOutputData(BaseType::GetModelPart(),rDofSet,mA,mDx,mb);
499  }
500 
501  //*********************************************************************************
502 
503 
531 protected:
570 private:
579  typename TLinearSolver::Pointer mpLinearSolver;
580 
581  typename TSchemeType::Pointer mpScheme;
582 
583  typename TBuilderAndSolverType::Pointer mpBuilderAndSolver;
584 
585  TSystemMatrixType mpD;
586 
590 
599  bool mReformDofSetAtEachStep;
600 
601  //calculates if required the norm of the correction term Dx
602  bool mCalculateNormDxFlag;
603 
609  bool mCalculateReactionsFlag;
610 
611  bool mSolutionStepIsInitialized;
612 
613  bool mInitializeWasPerformed;
614 
616  unsigned int mMaxIterationNumber;
617 
618 
619 
623  //**********************************************************************
624  //**********************************************************************
625  void Initialize()
626  {
627  KRATOS_TRY
628 
629  if(BaseType::GetEchoLevel()>2)
630  std::cout << "entering in the Initialize of the LapModifiedLinearStrategy" << std::endl;
631 
632  //pointers needed in the solution
633  typename TSchemeType::Pointer pScheme = GetScheme();
634 
635  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
636  if (pScheme->SchemeIsInitialized() == false)
637  pScheme->Initialize(BaseType::GetModelPart());
638 
639  //Initialize The Elements - OPERATIONS TO BE DONE ONCE
640  if (pScheme->ElementsAreInitialized() == false)
641  pScheme->InitializeElements(BaseType::GetModelPart());
642 
643  if(BaseType::GetEchoLevel()>2)
644  std::cout << "exiting the Initialize of the LapModifiedLinearStrategy" << std::endl;
645 
646 
647  KRATOS_CATCH("")
648  }
649 
650 
651  //**********************************************************************
652  //**********************************************************************
653  void InitializeSolutionStep()
654  {
655  KRATOS_TRY
656 
657  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
658  typename TSchemeType::Pointer pScheme = GetScheme();
659 
661 
662  if(BaseType::GetEchoLevel()>2 && rank==0)
663  std::cout << "entering in the InitializeSolutionStep of the LapModifiedLinearStrategy" << std::endl;
664 
665 
666  //loop to reform the dofset
667  boost::timer system_construction_time;
668  if (pBuilderAndSolver->GetDofSetIsInitializedFlag() == false ||
669  mReformDofSetAtEachStep == true )
670  {
671  boost::timer setup_dofs_time;
672  //setting up the list of the DOFs to be solved
673  pBuilderAndSolver->SetUpDofSet(pScheme,BaseType::GetModelPart());
674  if(BaseType::GetEchoLevel()>0 && rank == 0)
675  std::cout << "setup_dofs_time : " << setup_dofs_time.elapsed() << std::endl;
676 
677  //shaping correctly the system
678  boost::timer setup_system_time;
679  pBuilderAndSolver->SetUpSystem(BaseType::GetModelPart());
680  if(BaseType::GetEchoLevel()>0 && rank == 0)
681  std::cout << "setup_system_time : " << setup_system_time.elapsed() << std::endl;
682 
683  //setting up the Vectors involved to the correct size
684  boost::timer system_matrix_resize_time;
685  pBuilderAndSolver->ResizeAndInitializeVectors(pScheme, mpA,mpDx,mpb,BaseType::GetModelPart());
686  if(BaseType::GetEchoLevel()>0 && rank == 0)
687  std::cout << "system_matrix_resize_time : " << system_matrix_resize_time.elapsed() << std::endl;
688  }
689  if(BaseType::GetEchoLevel()>0 && rank == 0)
690  std::cout << "System Construction Time : " << system_construction_time.elapsed() << std::endl;
691 
692 
693  TSystemMatrixType& mA = *mpA;
694  TSystemVectorType& mDx = *mpDx;
695  TSystemVectorType& mb = *mpb;
696 
697  //TSystemMatrixType& mD = mpD;
698 
699  //initial operations ... things that are constant over the Solution Step
700  pBuilderAndSolver->InitializeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
701 
702  //initial operations ... things that are constant over the Solution Step
703  pScheme->InitializeSolutionStep(BaseType::GetModelPart(),mA,mDx,mb);
704 
705 
706  KRATOS_CATCH("")
707  }
708 
709  //**********************************************************************
710  //**********************************************************************
711  void MaxIterationsExceeded()
712  {
713  std::cout << "***************************************************" << std::endl;
714  std::cout << "******* ATTENTION: max iterations exceeded ********" << std::endl;
715  std::cout << "***************************************************" << std::endl;
716  }
717 
718  //**********************************************************************
719  //**********************************************************************
720  void Clear()
721  {
722  KRATOS_TRY
723  std::cout << "strategy Clear function used" << std::endl;
724 
725 
726 
727 
728 
729  if(mpA != NULL)
730  {
731  TSystemMatrixType& mA = *mpA;
733  SparseSpaceType::Resize(mA,0,0);
734  }
735  if(mpDx != NULL)
736  {
737  TSystemVectorType& mDx = *mpDx;
740  }
741  if(mpb != NULL)
742  {
743  TSystemVectorType& mb = *mpb;
746  }
747  /*
748  if(mpD.size1() != 0 && mpD.size2()!=0) {
749  TSystemMatrixType& mD = mpD;
750  SparseSpaceType::Resize(mD,0,0);}
751  */
752 
753  //setting to zero the internal flag to ensure that the dof sets are recalculated
754  GetBuilderAndSolver()->SetDofSetIsInitializedFlag(false);
755 
756  GetBuilderAndSolver()->Clear();
757 
758 
759  KRATOS_CATCH("");
760  }
761 
763  void AddFSILaplacian()
764  {
765  std::cout<<"Now empty";
766  }
768  void ConstructMatrixStructure_FluidDivergenceMatrixD(
769  TSystemMatrixType& mD, ModelPart& r_model_part)
770  {
771  KRATOS_TRY
772  //KRATOS_WATCH("Constructing fluid div matrix")
773  unsigned int reduced_dim = this->mpb->size() / TDim;
774 
775  mD.resize(reduced_dim,this->mpb->size(),false);
776 
777  //KRATOS_WATCH(mD)
778 
779  std::vector<int> indices;
780  indices.reserve(1000);
781 
782  //count non zeros
783  int total_nnz = 0;
784  for (typename NodesArrayType::iterator it=r_model_part.NodesBegin(); it!=r_model_part.NodesEnd(); ++it)
785  {
786  //not to add lonely nodes to the system
787  if(it->FastGetSolutionStepValue(IS_FLUID)!=0 && (it->GetValue(NEIGHBOUR_NODES)).size() != 0 )
788  {
789  int count_fluid_neighb=0;
790  GlobalPointersVector< Node >& neighb_nodes = it->GetValue(NEIGHBOUR_NODES);
791  for( GlobalPointersVector< Node >::iterator i = neighb_nodes.begin();
792  i != neighb_nodes.end(); i++)
793  {
794  if (i->FastGetSolutionStepValue(IS_FLUID)!=0)
795  count_fluid_neighb++;
796  }
797  //we add one because we have to account for the contribution of the node itself
798  total_nnz += 1 + count_fluid_neighb;//(it->GetValue(NEIGHBOUR_NODES)).size();
799  }
800  }
801 
802  mD.reserve(total_nnz* TDim,false);
803  //KRATOS_WATCH("Constructing fluid div matrix 1")
804 
805  unsigned int row_index;
806  //fill the matrix row by row
807  //unsigned int dof_position = r_model_part.NodesBegin()->GetDofPosition(DISPLACEMENT_X);
808  unsigned int dof_position = r_model_part.NodesBegin()->GetDofPosition(PRESSURE);
809  //KRATOS_WATCH("Pressure DOF")
810  //KRATOS_WATCH(dof_position)
811 
812  for (typename NodesArrayType::iterator it=r_model_part.NodesBegin(); it!=r_model_part.NodesEnd(); ++it)
813  {
814  GlobalPointersVector< Node >& neighb_nodes = it->GetValue(NEIGHBOUR_NODES);
815  if( neighb_nodes.size() != 0 && it->FastGetSolutionStepValue(IS_FLUID)!=0)
816  {
817  //first row in the block
818  //row_index = it->GetDof(DISPLACEMENT_X,dof_position).EquationId();
819  row_index = it->GetDof(PRESSURE, dof_position).EquationId();
820 
821  //add id of the current node
822  //NOTE: here and in the following we ASSUME that the ids of DISPLACEMENT_X _Y and _Z are sequential
823  for(unsigned int kk = 0; kk<TDim; kk++)
824  {
825  indices.push_back(TDim*row_index + kk);
826  }
827 
828  //filling and order the first neighbours list
829  for( GlobalPointersVector< Node >::iterator i = neighb_nodes.begin();
830  i != neighb_nodes.end(); i++)
831  {
832  if ( i->FastGetSolutionStepValue(IS_FLUID)!=0)
833  {
834  //unsigned int tmp = (i->GetDof(DISPLACEMENT_X,dof_position)).EquationId();
835  unsigned int tmp = (i->GetDof(PRESSURE,dof_position)).EquationId();
836  //KRATOS_WATCH(tmp)
837  for(unsigned int kk = 0; kk<TDim; kk++)
838  {
839  indices.push_back(TDim*tmp + kk);
840  }
841  }
842  }
843  std::sort(indices.begin(),indices.end());
844 
845 
846  //fill D (the divergence matrix) - note that the "pressure index" is assumed to concide the DISPLACEMENT_X index divided by 3
847  /*
848  for(unsigned int j=0; j<indices.size(); j++)
849  {
850  //mD.push_back(row_index/TDim, indices[j] , 0.00);
851  mD.push_back(row_index, indices[j] , 0.00);
852  }
853  */
854 
855  //clean the indices (it is a work array)
856  indices.erase(indices.begin(),indices.end());
857  }
858  }
859 
860  //KRATOS_WATCH("FSI D")
861  //KRATOS_WATCH(mD)
862  KRATOS_CATCH("")
863 
864  }
865  void BuildAuxiliariesFSI(
866  TSystemMatrixType& mD, double density_str,
867  ModelPart& r_model_part) //TSystemMatrixType& WorkMatrix, double density_str, ModelPart& r_model_part)
868  {
869  KRATOS_TRY
870  //KRATOS_WATCH("BUILDING MATRIX DM-1G for the FSI interface nodes")
871  typename TBuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
872 
873  //mb-right hand side vector (global)
874  unsigned int reduced_dim = this->mpb->size() / TDim;
875 //mb.size()/
876 //this->mEquationSystemSize / TDim;
877 
878  //WorkMatrix.resize(reduced_dim, reduced_dim, false);
879 
880  TSystemMatrixType WorkMatrix(reduced_dim,reduced_dim);
881  //KRATOS_WATCH(WorkMatrix)
882 
883  BoundedMatrix<double,TDim+1,TDim> DN_DX;
884  array_1d<double,TDim+1> N;
885  array_1d<unsigned int ,TDim+1> local_indices;
886  //array_1d<double,TDim+1> rhs_contribution;
887  double Volume;
888  double temp;
889 
890  TSystemVectorType mMdiagInv(this->mpb->size());
891 //this->mEquationSystemSize);
892  //KRATOS_WATCH(mMdiagInv)
893 
894 
895  //getting the dof position
896  unsigned int dof_position = (r_model_part.NodesBegin())->GetDofPosition(DISPLACEMENT_X);
897  //unsigned int dof_position = TDim*((r_model_part.NodesBegin())->GetDofPosition(PRESSURE));
898 
899  double aaa = 1.0/(TDim+1.0);
900  //if the element is not having all the nodes IS_STRUCTURE, assemble it, otherwise do nothing
901  for(ModelPart::ElementsContainerType::iterator i = r_model_part.ElementsBegin();
902  i!=r_model_part.ElementsEnd(); i++)
903  {
904 
905 
906  Geometry< Node >& geom = i->GetGeometry();
907  //counting the n-r of structure nodes
908  unsigned int str_nr=0;
909 
910  //for (int k = 0;k<TDim+1;k++)
911  for (unsigned int k = 0; k<geom.size(); k++)
912  {
913  str_nr+=(unsigned int)(i->GetGeometry()[k].FastGetSolutionStepValue(IS_STRUCTURE));
914  }
916  //if the element is not having all the nodes IS_STRUCTURE, assemble it, otherwise do nothing
917  // that means, that the entries corresponding to the structural elements are zero
919  if (geom.size()!=str_nr)
920  {
921  GeometryUtils::CalculateGeometryData(geom, DN_DX, N, Volume);
922 
923  //finiding local indices
924  //for(int ii = 0; ii<TDim+1; ii++)
925  for(unsigned int ii = 0; ii<geom.size(); ii++)
926  {
927  local_indices[ii] = geom[ii].GetDof(DISPLACEMENT_X,dof_position).EquationId();
928  }
929  //building matrix D (transpose of the gradient integrated by parts)
930 
931  //now we check if this is an interface element (i.e. FSI element)
932 
933  int n_interface=0;
934  for(unsigned int ii = 0; ii<geom.size(); ii++)
935  {
936  n_interface = geom[ii].FastGetSolutionStepValue(IS_INTERFACE);
937  }
938  //if the element does not contain interface node, we set the matrix to be zero
939  if (n_interface!=0)
940  temp = Volume*aaa;
941  else
942  temp=0.0;
943 
944 
945  for(unsigned int row = 0; row<TDim+1; row++)
946  {
947  unsigned int row_index = local_indices[row] / (TDim);
948  //it is a structural mass matrix
949  mMdiagInv[2*row_index] += (density_str*temp);
950  mMdiagInv[(2*row_index)+1] +=(density_str*temp);
951 
952  //KRATOS_WATCH(row_index)
953  for(unsigned int col = 0; col<TDim+1; col++)
954  {
955  for(unsigned int kkk = 0; kkk<TDim; kkk++)
956  {
957  //check if the below is correct (copied it from Mass matrix)
958  unsigned int col_index = local_indices[col]+kkk;
959  //unsigned int col_index = col + kkk;
960  mD(row_index,col_index) += temp * DN_DX(col,kkk);
961  }
962  }
963 
964 
965  }
966  }
967 
968  }
969  //inverting the mass matrix
970  /*
971  KRATOS_WATCH(mMdiagInv.size())
972  KRATOS_WATCH(mD.size1())
973  KRATOS_WATCH(mD.size2())
974  */
975  for(unsigned int i = 0; i<TSparseSpace::Size(mMdiagInv); i++)
976  {
977  if (mMdiagInv[i]>1e-26)
978  mMdiagInv[i] = 1.0/mMdiagInv[i];
979  else //if (mMdiagInv[i]==0.0)
980  {
981  //KRATOS_WATCH(mMdiagInv[i])
982  //KRATOS_THROW_ERROR(std::logic_error,"something is wrong with the mass matrix entry - ZERO!!!","")
983  mMdiagInv[i] = 10000000000000000.0;
984  }
985  }
986  //finally we will compute the matrix DM-1G (interface Lapalcian)
987  //first we multiply G with Minv
988  TSystemMatrixType matG;
989 
990  //TSparseSpace::Transpose(mD, matG);
991  matG=trans(mD);
992  //KRATOS_WATCH(matG)
993  for (int i=0; i<mMdiagInv.size(); i++)
994  {
995  for (int j=0; j<matG.size2(); j++)
996  {
997  matG(i,j)*=mMdiagInv[i];
998  }
999  }
1000 
1001  TSparseSpace::SetToZero(WorkMatrix);
1002  //TSparseSpace::SetToZero(destination);
1003 
1004  //WorkMatrix = D * G
1005  //TSparseSpace::Mult(mD, matG, WorkMatrix);
1006  WorkMatrix=prod(mD, matG);
1007  //KRATOS_WATCH(WorkMatrix)
1008 
1009  KRATOS_CATCH (" ")
1010  }
1033 
1034 
1037 }; /* Class LapModifiedLinearStrategy */
1038 
1047 } /* namespace Kratos.*/
1048 #endif /* KRATOS_LAP_MODIFIED_LINEAR_STRATEGY defined */
1049 
virtual int MyPID() const
Definition: communicator.cpp:91
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
Scheme< TSparseSpace, TDenseSpace > TSchemeType
Definition: implicit_solving_strategy.h:82
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
int mRebuildLevel
Definition: implicit_solving_strategy.h:263
bool mStiffnessMatrixIsBuilt
The current rebuild level.
Definition: implicit_solving_strategy.h:264
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
Short class definition.
Definition: modified_linear_strategy.h:95
double Solve()
Definition: modified_linear_strategy.h:335
TSparseSpace SparseSpaceType
Definition: modified_linear_strategy.h:107
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
Definition: modified_linear_strategy.h:262
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: modified_linear_strategy.h:125
BaseType::TDataType TDataType
Definition: modified_linear_strategy.h:105
LapModifiedLinearStrategy(ModelPart &model_part, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Definition: modified_linear_strategy.h:136
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: modified_linear_strategy.h:110
void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
Definition: modified_linear_strategy.h:252
BaseType::TSystemVectorType TSystemVectorType
Definition: modified_linear_strategy.h:118
double GetResidualNorm()
Operations to get the residual norm.
Definition: modified_linear_strategy.h:475
void SetEchoLevel(int Level)
This sets the level of echo for the solving strategy.
Definition: modified_linear_strategy.h:288
bool GetCalculateReactionsFlag()
Definition: modified_linear_strategy.h:267
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: modified_linear_strategy.h:103
void SetReformDofSetAtEachStepFlag(bool flag)
Definition: modified_linear_strategy.h:272
void CalculateOutputData()
Definition: modified_linear_strategy.h:491
TSchemeType::Pointer GetScheme()
Definition: modified_linear_strategy.h:246
KRATOS_CLASS_POINTER_DEFINITION(LapModifiedLinearStrategy)
void Predict()
Definition: modified_linear_strategy.h:302
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: modified_linear_strategy.h:468
bool GetReformDofSetAtEachStepFlag()
Definition: modified_linear_strategy.h:277
BaseType::TSchemeType TSchemeType
Definition: modified_linear_strategy.h:109
ModelPart::NodesContainerType NodesArrayType
Definition: modified_linear_strategy.h:127
LapModifiedLinearStrategy(ModelPart &model_part, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Definition: modified_linear_strategy.h:187
void SetScheme(typename TSchemeType::Pointer pScheme)
Definition: modified_linear_strategy.h:242
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: modified_linear_strategy.h:122
~LapModifiedLinearStrategy() override
Definition: modified_linear_strategy.h:236
BaseType::DofsArrayType DofsArrayType
Definition: modified_linear_strategy.h:114
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: modified_linear_strategy.h:124
BaseType::TSystemMatrixType TSystemMatrixType
Definition: modified_linear_strategy.h:116
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Definition: modified_linear_strategy.h:256
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: modified_linear_strategy.h:120
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
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
Current class provides an implementation for standard elimination builder and solving operations.
Definition: residualbased_elimination_builder_and_solver.h:76
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition: solving_strategy.h:77
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
TSparseSpace::DataType TDataType
Definition: solving_strategy.h:69
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solving strategy.
Definition: solving_strategy.h:255
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: solving_strategy.h:271
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition: solving_strategy.h:75
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
virtual void MoveMesh()
This function is designed to move the mesh.
Definition: solving_strategy.h:330
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
static void Resize(MatrixType &rA, SizeType m, SizeType n)
Definition: ublas_space.h:558
static void Clear(MatrixPointerType &pA)
Definition: ublas_space.h:578
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
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
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
model_part
Definition: face_heat.py:14
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
float temp
Definition: rotating_cone.py:85
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17
double precision function mb(a)
Definition: TensorModule.f:849
e
Definition: run_cpp_mpi_tests.py:31