10 #if !defined(KRATOS_LAP_MODIFIED_LINEAR_STRATEGY)
11 #define KRATOS_LAP_MODIFIED_LINEAR_STRATEGY
20 #include <boost/timer.hpp>
23 #include <pybind11/pybind11.h>
89 template<
unsigned int TDim,
class TSparseSpace,
138 typename TSchemeType::Pointer pScheme,
139 typename TLinearSolver::Pointer pNewLinearSolver,
140 bool CalculateReactionFlag =
false,
141 bool ReformDofSetAtEachStep =
false,
142 bool CalculateNormDxFlag =
false,
149 mCalculateReactionsFlag = CalculateReactionFlag;
150 mReformDofSetAtEachStep = ReformDofSetAtEachStep;
151 mCalculateNormDxFlag = CalculateNormDxFlag;
158 mpLinearSolver = pNewLinearSolver;
161 mpBuilderAndSolver =
typename TBuilderAndSolverType::Pointer
167 mSolutionStepIsInitialized =
false;
168 mInitializeWasPerformed =
false;
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,
201 mCalculateReactionsFlag = CalculateReactionFlag;
202 mReformDofSetAtEachStep = ReformDofSetAtEachStep;
203 mCalculateNormDxFlag = CalculateNormDxFlag;
209 mpLinearSolver = pNewLinearSolver;
212 mpBuilderAndSolver = pNewBuilderAndSolver;
215 mSolutionStepIsInitialized =
false;
216 mInitializeWasPerformed =
false;
254 mpBuilderAndSolver = pNewBuilderAndSolver;
258 return mpBuilderAndSolver;
264 mCalculateReactionsFlag = CalculateReactionsFlag;
269 return mCalculateReactionsFlag;
274 mReformDofSetAtEachStep = flag;
279 return mReformDofSetAtEachStep;
340 typename TSchemeType::Pointer pScheme =
GetScheme();
348 if(mInitializeWasPerformed ==
false)
351 mInitializeWasPerformed =
true;
357 std::cout <<
" " << std::endl;
358 std::cout <<
"CurrentTime = " << pCurrentProcessInfo[TIME] << std::endl;
362 if (mSolutionStepIsInitialized ==
false)
364 InitializeSolutionStep();
365 mSolutionStepIsInitialized =
true;
379 TSparseSpace::SetToZero(mA);
380 TSparseSpace::SetToZero(mDx);
381 TSparseSpace::SetToZero(
mb);
383 TSparseSpace::SetToZero(mD);
398 pBuilderAndSolver->SystemSolve(mA,mDx,
mb);
406 TSparseSpace::SetToZero(mDx);
407 TSparseSpace::SetToZero(
mb);
413 std::cout <<
"SystemMatrix = " << mA << std::endl;
414 std::cout <<
"solution obtained = " << mDx << std::endl;
415 std::cout <<
"RHS = " <<
mb << std::endl;
426 double normDx = 0.00;
427 if(mCalculateNormDxFlag ==
true)
433 if (mCalculateReactionsFlag ==
true)
446 if (mReformDofSetAtEachStep ==
true)
448 if(rank == 0) std::cout <<
"Clearing System" << std::endl;
460 mSolutionStepIsInitialized =
false;
579 typename TLinearSolver::Pointer mpLinearSolver;
581 typename TSchemeType::Pointer mpScheme;
583 typename TBuilderAndSolverType::Pointer mpBuilderAndSolver;
599 bool mReformDofSetAtEachStep;
602 bool mCalculateNormDxFlag;
609 bool mCalculateReactionsFlag;
611 bool mSolutionStepIsInitialized;
613 bool mInitializeWasPerformed;
616 unsigned int mMaxIterationNumber;
630 std::cout <<
"entering in the Initialize of the LapModifiedLinearStrategy" << std::endl;
633 typename TSchemeType::Pointer pScheme =
GetScheme();
636 if (pScheme->SchemeIsInitialized() ==
false)
640 if (pScheme->ElementsAreInitialized() ==
false)
644 std::cout <<
"exiting the Initialize of the LapModifiedLinearStrategy" << std::endl;
653 void InitializeSolutionStep()
658 typename TSchemeType::Pointer pScheme =
GetScheme();
663 std::cout <<
"entering in the InitializeSolutionStep of the LapModifiedLinearStrategy" << std::endl;
667 boost::timer system_construction_time;
668 if (pBuilderAndSolver->GetDofSetIsInitializedFlag() ==
false ||
669 mReformDofSetAtEachStep ==
true )
671 boost::timer setup_dofs_time;
675 std::cout <<
"setup_dofs_time : " << setup_dofs_time.elapsed() << std::endl;
678 boost::timer setup_system_time;
681 std::cout <<
"setup_system_time : " << setup_system_time.elapsed() << std::endl;
684 boost::timer system_matrix_resize_time;
687 std::cout <<
"system_matrix_resize_time : " << system_matrix_resize_time.elapsed() << std::endl;
690 std::cout <<
"System Construction Time : " << system_construction_time.elapsed() << std::endl;
711 void MaxIterationsExceeded()
713 std::cout <<
"***************************************************" << std::endl;
714 std::cout <<
"******* ATTENTION: max iterations exceeded ********" << std::endl;
715 std::cout <<
"***************************************************" << std::endl;
723 std::cout <<
"strategy Clear function used" << std::endl;
763 void AddFSILaplacian()
765 std::cout<<
"Now empty";
768 void ConstructMatrixStructure_FluidDivergenceMatrixD(
773 unsigned int reduced_dim = this->mpb->size() / TDim;
775 mD.resize(reduced_dim,this->mpb->size(),
false);
779 std::vector<int> indices;
780 indices.reserve(1000);
784 for (
typename NodesArrayType::iterator it=r_model_part.NodesBegin(); it!=r_model_part.NodesEnd(); ++it)
787 if(it->FastGetSolutionStepValue(IS_FLUID)!=0 && (it->GetValue(NEIGHBOUR_NODES)).size() != 0 )
789 int count_fluid_neighb=0;
790 GlobalPointersVector< Node >& neighb_nodes = it->GetValue(NEIGHBOUR_NODES);
792 i != neighb_nodes.end();
i++)
794 if (
i->FastGetSolutionStepValue(IS_FLUID)!=0)
795 count_fluid_neighb++;
798 total_nnz += 1 + count_fluid_neighb;
802 mD.reserve(total_nnz* TDim,
false);
805 unsigned int row_index;
808 unsigned int dof_position = r_model_part.NodesBegin()->GetDofPosition(PRESSURE);
812 for (
typename NodesArrayType::iterator it=r_model_part.NodesBegin(); it!=r_model_part.NodesEnd(); ++it)
814 GlobalPointersVector< Node >& neighb_nodes = it->GetValue(NEIGHBOUR_NODES);
815 if( neighb_nodes.size() != 0 && it->FastGetSolutionStepValue(IS_FLUID)!=0)
819 row_index = it->GetDof(PRESSURE, dof_position).EquationId();
823 for(
unsigned int kk = 0; kk<TDim; kk++)
825 indices.push_back(TDim*row_index + kk);
830 i != neighb_nodes.end();
i++)
832 if (
i->FastGetSolutionStepValue(IS_FLUID)!=0)
835 unsigned int tmp = (
i->GetDof(PRESSURE,dof_position)).EquationId();
837 for(
unsigned int kk = 0; kk<TDim; kk++)
839 indices.push_back(TDim*
tmp + kk);
843 std::sort(indices.begin(),indices.end());
856 indices.erase(indices.begin(),indices.end());
865 void BuildAuxiliariesFSI(
867 ModelPart& r_model_part)
874 unsigned int reduced_dim = this->mpb->size() / TDim;
883 BoundedMatrix<double,TDim+1,TDim> DN_DX;
884 array_1d<double,TDim+1>
N;
885 array_1d<unsigned int ,TDim+1> local_indices;
896 unsigned int dof_position = (r_model_part.NodesBegin())->GetDofPosition(DISPLACEMENT_X);
899 double aaa = 1.0/(TDim+1.0);
901 for(ModelPart::ElementsContainerType::iterator
i = r_model_part.ElementsBegin();
902 i!=r_model_part.ElementsEnd();
i++)
906 Geometry< Node >& geom =
i->GetGeometry();
908 unsigned int str_nr=0;
911 for (
unsigned int k = 0;
k<geom.size();
k++)
913 str_nr+=(
unsigned int)(
i->GetGeometry()[
k].FastGetSolutionStepValue(IS_STRUCTURE));
919 if (geom.size()!=str_nr)
925 for(
unsigned int ii = 0; ii<geom.size(); ii++)
927 local_indices[ii] = geom[ii].GetDof(DISPLACEMENT_X,dof_position).EquationId();
934 for(
unsigned int ii = 0; ii<geom.size(); ii++)
936 n_interface = geom[ii].FastGetSolutionStepValue(IS_INTERFACE);
945 for(
unsigned int row = 0;
row<TDim+1;
row++)
947 unsigned int row_index = local_indices[
row] / (TDim);
949 mMdiagInv[2*row_index] += (density_str*
temp);
950 mMdiagInv[(2*row_index)+1] +=(density_str*
temp);
953 for(
unsigned int col = 0; col<TDim+1; col++)
955 for(
unsigned int kkk = 0; kkk<TDim; kkk++)
958 unsigned int col_index = local_indices[col]+kkk;
960 mD(row_index,col_index) +=
temp * DN_DX(col,kkk);
977 if (mMdiagInv[
i]>1
e-26)
978 mMdiagInv[
i] = 1.0/mMdiagInv[
i];
983 mMdiagInv[
i] = 10000000000000000.0;
993 for (
int i=0;
i<mMdiagInv.size();
i++)
995 for (
int j=0;
j<matG.size2();
j++)
997 matG(
i,
j)*=mMdiagInv[
i];
1001 TSparseSpace::SetToZero(WorkMatrix);
1006 WorkMatrix=
prod(mD, matG);
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