13 #ifndef KRATOS_TRILINOS_BLOCK_BUILDER_AND_SOLVER_PERIODIC_H
14 #define KRATOS_TRILINOS_BLOCK_BUILDER_AND_SOLVER_PERIODIC_H
22 #include "Epetra_MpiComm.h"
23 #include "Epetra_Map.h"
24 #include "Epetra_Vector.h"
25 #include "Epetra_FECrsGraph.h"
26 #include "Epetra_FECrsMatrix.h"
27 #include "Epetra_IntSerialDenseVector.h"
28 #include "Epetra_SerialDenseMatrix.h"
29 #include "Epetra_SerialDenseVector.h"
67 template<
class TSparseSpace,
115 typename TLinearSolver::Pointer pNewLinearSystemSolver,
118 mPeriodicIdVar(PeriodicIdVar)
144 const int Rank = this->
mrComm.MyPID();
150 if ( (itDof->GetSolutionStepValue(PARTITION_INDEX) == Rank) && ( itDof->GetSolutionStepValue(mPeriodicIdVar) <
static_cast<int>(itDof->Id())) )
154 unsigned int ExtraDofs = SetUpEdgeDofs(rModelPart);
155 DofCount += ExtraDofs;
160 int ierr = this->
mrComm.ScanSum(&DofCount,&DofOffset,1);
162 KRATOS_THROW_ERROR(std::runtime_error,
"In TrilinosBlockBuilderAndSolverPeriodic::SetUpSystem: Found Epetra_MpiComm::ScanSum failure with error code ",ierr);
164 DofOffset -= DofCount;
169 if ( (itDof->GetSolutionStepValue(PARTITION_INDEX) == Rank) && ( itDof->GetSolutionStepValue(mPeriodicIdVar) <
static_cast<int>(itDof->Id()) ) )
170 itDof->SetEquationId(DofOffset++);
174 itDof->SetEquationId(0);
185 int Node0 = rGeom[0].
Id();
186 int Node0Pair = rGeom[0].FastGetSolutionStepValue(mPeriodicIdVar);
188 int Node1 = rGeom[1].
Id();
189 int Node1Pair = rGeom[1].FastGetSolutionStepValue(mPeriodicIdVar);
190 if ( Node0Pair == 0 || Node1Pair == 0 )
191 KRATOS_THROW_ERROR(std::runtime_error,
"ERROR: a periodic condition has no periodic pair ids assigned. Condition Id is: ",itCond->Id());
194 if ( ( Node0 == Node1Pair ) && ( Node1 == Node0Pair ) )
196 if ( Node0 < Node0Pair )
197 CopyEquationId(rGeom[1],rGeom[0]);
199 CopyEquationId(rGeom[0],rGeom[1]);
204 for (
unsigned int i = 1;
i < 4;
i++)
205 CopyEquationId(rGeom[0],rGeom[
i]);
209 for (
unsigned int i = 1;
i < 8;
i++)
210 CopyEquationId(rGeom[0],rGeom[
i]);
221 this->CleanEdgeDofData(rModelPart);
225 ierr = this->
mrComm.SumAll(&DofCount,&TotalDofNum,1);
227 KRATOS_THROW_ERROR(std::runtime_error,
"In TrilinosBlockBuilderAndSolverPeriodic::SetUpSystem: Found Epetra_MpiComm::SumAll failure with error code ",ierr);
327 for ( Node::DofsContainerType::iterator itDof = rOrigin.
GetDofs().begin(); itDof != rOrigin.
GetDofs().end(); itDof++)
332 void CommunicateEquationId(Communicator& rComm)
335 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
341 for (
unsigned int i_color = 0; i_color < neighbours_indices.size(); i_color++)
342 if ((destination = neighbours_indices[i_color]) >= 0)
348 unsigned int send_buffer_size = 0;
349 unsigned int receive_buffer_size = 0;
352 send_buffer_size += i_node->GetDofs().
size();
355 receive_buffer_size += i_node->GetDofs().size();
357 unsigned int position = 0;
358 int* send_buffer =
new int[send_buffer_size];
359 int* receive_buffer =
new int[receive_buffer_size];
364 for (ModelPart::NodeType::DofsContainerType::iterator i_dof = i_node->GetDofs().begin(); i_dof != i_node->GetDofs().end(); i_dof++)
365 send_buffer[position++] = (*i_dof)->EquationId();
370 if (position > send_buffer_size)
371 std::cout << rank <<
" Error in estimating send buffer size...." << std::endl;
374 int send_tag = i_color;
375 int receive_tag = i_color;
377 MPI_Sendrecv(send_buffer, send_buffer_size, MPI_INT, destination, send_tag, receive_buffer, receive_buffer_size, MPI_INT, destination, receive_tag,
378 MPI_COMM_WORLD, &status);
383 i_node != r_dest_nodes.end(); i_node++)
384 for (ModelPart::NodeType::DofsContainerType::iterator i_dof = i_node->GetDofs().begin(); i_dof != i_node->GetDofs().end(); i_dof++)
386 unsigned int NewId =
static_cast<unsigned int>(receive_buffer[position++]);
387 if (NewId > (*i_dof)->EquationId())
388 (*i_dof)->SetEquationId(NewId);
391 if (position > receive_buffer_size)
392 std::cout << rank <<
" Error in estimating receive buffer size...." << std::endl;
394 delete [] send_buffer;
395 delete [] receive_buffer;
399 rComm.SynchronizeDofs();
406 unsigned int SetUpEdgeDofs(ModelPart& rModelPart)
408 int LocalNodesNum = rModelPart.GetCommunicator().LocalMesh().Nodes().size();
409 int GlobalNodesNum = 0;
410 this->
mrComm.SumAll(&LocalNodesNum,&GlobalNodesNum,1);
412 int NumProcs = this->
mrComm.NumProc();
413 int* ExtraDofs =
new int[NumProcs];
414 for (
int i = 0;
i < NumProcs;
i++) ExtraDofs[
i] = 0;
417 const ProcessInfo& rProcessInfo = rModelPart.GetProcessInfo();
421 const unsigned int NumNodes = rGeom.PointsNumber();
423 if ( ( NumNodes == 4 || NumNodes == 8 ) && rGeom[0].FastGetSolutionStepValue(mPeriodicIdVar) > GlobalNodesNum )
425 unsigned int FirstNode = rGeom[0].Id();
427 itCond->GetDofList(DofList,rProcessInfo);
428 for(
typename Condition::DofsVectorType::iterator iDof = DofList.begin() ; iDof != DofList.end() ; ++iDof)
429 if ( (*iDof)->Id() == FirstNode)
430 ExtraDofs[(*iDof)->GetSolutionStepValue(PARTITION_INDEX)]++;
432 rGeom[0].GetValue(mPeriodicIdVar) = rGeom[0].FastGetSolutionStepValue(mPeriodicIdVar);
436 int* TotalExtraDofs =
new int[NumProcs];
437 for (
int i = 0;
i < NumProcs;
i++) TotalExtraDofs[
i] = 0;
439 this->
mrComm.SumAll(ExtraDofs,TotalExtraDofs,NumProcs);
442 int LocalExtraDofs = TotalExtraDofs[this->
mrComm.MyPID()];
444 delete [] TotalExtraDofs;
447 rModelPart.GetCommunicator().AssembleNonHistoricalData(mPeriodicIdVar);
449 if ( iNode->GetValue(mPeriodicIdVar) != 0)
450 iNode->FastGetSolutionStepValue(mPeriodicIdVar) = 0;
452 return LocalExtraDofs;
458 void CleanEdgeDofData(ModelPart& rModelPart)
461 if ( iNode->GetValue(mPeriodicIdVar) != 0)
463 iNode->FastGetSolutionStepValue(mPeriodicIdVar) = iNode->GetValue(mPeriodicIdVar);
464 iNode->GetValue(mPeriodicIdVar) = 0;
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
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
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
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: communicator.h:99
virtual bool SynchronizeDofs()
Definition: communicator.cpp:352
DenseVector< int > NeighbourIndicesContainerType
Definition: communicator.h:92
std::vector< DofType::Pointer > DofsVectorType
Definition: condition.h:100
Geometry< NodeType > GeometryType
definition of the geometry type with given NodeType
Definition: condition.h:83
void SetEquationId(EquationIdType NewEquationId)
Definition: dof.h:331
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
Communicator & GetCommunicator()
Definition: model_part.h:1821
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
MeshType::ConditionIterator ConditionIterator
Definition: model_part.h:189
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This class defines the node.
Definition: node.h:65
DofsContainerType & GetDofs()
Definition: node.h:694
DofType::Pointer pGetDof(TVariableType const &rDofVariable) const
Get DoF counted pointer for a given variable.
Definition: node.h:711
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
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
Current class provides an implementation for trilinos builder and solving operations.
Definition: trilinos_block_builder_and_solver.h:85
EpetraCommunicatorType & mrComm
Definition: trilinos_block_builder_and_solver.h:1175
int mFirstMyId
The local system size.
Definition: trilinos_block_builder_and_solver.h:1178
IndexType mLocalSystemSize
The guess row size.
Definition: trilinos_block_builder_and_solver.h:1177
int mLastMyId
Auxiliary Id (the first row of the local system)
Definition: trilinos_block_builder_and_solver.h:1179
Definition: trilinos_block_builder_and_solver_periodic.h:73
#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
BaseType::TSystemVectorType TSystemVectorType
Definition: trilinos_block_builder_and_solver_periodic.h:92
BaseType::TSchemeType TSchemeType
Definition: trilinos_block_builder_and_solver_periodic.h:84
BaseType::ElementsContainerType ElementsContainerType
Definition: trilinos_block_builder_and_solver_periodic.h:104
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: trilinos_block_builder_and_solver_periodic.h:94
void SetUpSystem(ModelPart &rModelPart) override
Assign an Equation Id to all degrees of freedom in the system.
Definition: trilinos_block_builder_and_solver_periodic.h:140
BaseType::NodesArrayType NodesArrayType
Definition: trilinos_block_builder_and_solver_periodic.h:100
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: trilinos_block_builder_and_solver_periodic.h:96
BaseType::TSystemMatrixType TSystemMatrixType
Definition: trilinos_block_builder_and_solver_periodic.h:90
TSparseSpace SparseSpaceType
Definition: trilinos_block_builder_and_solver_periodic.h:82
TrilinosBlockBuilderAndSolverPeriodic(Epetra_MpiComm &Comm, int guess_row_size, typename TLinearSolver::Pointer pNewLinearSystemSolver, const Kratos::Variable< int > &PeriodicIdVar)
Definition: trilinos_block_builder_and_solver_periodic.h:113
TrilinosBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: trilinos_block_builder_and_solver_periodic.h:80
BaseType::TDataType TDataType
Definition: trilinos_block_builder_and_solver_periodic.h:86
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: trilinos_block_builder_and_solver_periodic.h:97
virtual ~TrilinosBlockBuilderAndSolverPeriodic()
Definition: trilinos_block_builder_and_solver_periodic.h:125
BaseType::ConditionsArrayType ConditionsArrayType
Definition: trilinos_block_builder_and_solver_periodic.h:102
BaseType::DofsArrayType DofsArrayType
Definition: trilinos_block_builder_and_solver_periodic.h:88
BaseType::ElementsArrayType ElementsArrayType
Definition: trilinos_block_builder_and_solver_periodic.h:101
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: trilinos_block_builder_and_solver_periodic.h:98
KRATOS_CLASS_POINTER_DEFINITION(TrilinosBlockBuilderAndSolverPeriodic)
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
ProcessInfo
Definition: edgebased_PureConvection.py:116
integer i
Definition: TensorModule.f:17