13 #if !defined(KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVERCOMPONENTWISE )
14 #define KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVERCOMPONENTWISE
20 #ifdef KRATOS_SMP_OPENMP
88 template<
class TSparseSpace,
137 typename TLinearSolver::Pointer pNewLinearSystemSolver,
144 "name" : "ResidualBasedEliminationBuilderAndSolverComponentwise",
145 "components_wise_variable" : "SCALAR_VARIABLE_OR_COMPONENT"
157 typename TLinearSolver::Pointer pNewLinearSystemSolver,TVariableType
const& Var)
182 typename TSchemeType::Pointer pScheme,
204 int A_size =
A.size1();
207 std::vector< omp_lock_t > lock_array(
A.size1());
209 for(
int i = 0;
i<A_size;
i++)
210 omp_init_lock(&lock_array[
i]);
214 CreatePartition(number_of_threads, pElements.
size(), element_partition);
223 #pragma omp parallel for firstprivate(number_of_threads) schedule(static,1)
224 for(
int k=0;
k<number_of_threads;
k++)
237 unsigned int pos = (r_model_part.
Nodes().begin())->GetDofPosition(rVar);
245 (*it)->CalculateLocalSystem(LHS_Contribution,RHS_Contribution,CurrentProcessInfo);
248 if(EquationId.size() != geom.
size()) EquationId.resize(geom.
size(),
false);
250 for(
unsigned int i=0;
i<geom.
size();
i++)
251 EquationId[
i] = geom[
i].GetDof(rVar,pos).EquationId();
254 #ifdef USE_LOCKS_IN_ASSEMBLY
255 this->
Assemble(A,
b,LHS_Contribution,RHS_Contribution,EquationId,lock_array);
257 this->
Assemble(A,
b,LHS_Contribution,RHS_Contribution,EquationId);
263 CreatePartition(number_of_threads, ConditionsArray.
size(), condition_partition);
265 #pragma omp parallel for firstprivate(number_of_threads) schedule(static,1)
266 for(
int k=0;
k<number_of_threads;
k++)
279 unsigned int pos = (r_model_part.
Nodes().begin())->GetDofPosition(rVar);
286 (*it)->CalculateLocalSystem(LHS_Contribution,RHS_Contribution,CurrentProcessInfo);
289 if(EquationId.size() != geom.
size()) EquationId.resize(geom.
size(),
false);
291 for(
unsigned int i=0;
i<geom.
size();
i++)
293 EquationId[
i] = geom[
i].GetDof(rVar,pos).EquationId();
296 #ifdef USE_LOCKS_IN_ASSEMBLY
297 this->
Assemble(A,
b,LHS_Contribution,RHS_Contribution,EquationId,lock_array);
299 this->
Assemble(A,
b,LHS_Contribution,RHS_Contribution,EquationId);
304 std::cout <<
"parallel building time: " <<
timer.ElapsedSeconds() << std::endl;
308 for(
int i = 0;
i<A_size;
i++)
309 omp_destroy_lock(&lock_array[
i]);
322 typename TSchemeType::Pointer pScheme,
331 mActiveNodes.clear();
332 mActiveNodes.reserve(r_model_part.
Nodes().size() );
335 if( (it->GetValue(NEIGHBOUR_NODES)).size() != 0 )
337 mActiveNodes.push_back(*(it.base() ));
366 KRATOS_ERROR_IF_NOT(dof_iterator->HasReaction()) <<
"Reaction variable not set for the following : " <<std::endl
367 <<
"Node : "<<dof_iterator->Id()<< std::endl
368 <<
"Dof : "<<(*dof_iterator)<<std::endl<<
"Not possible to calculate reactions."<<std::endl;
381 typename TSchemeType::Pointer pScheme,
420 ParallelConstructGraph(
A);
430 KRATOS_ERROR <<
"The equation system size has changed during the simulation. This is not permitted."<<std::endl;
433 ParallelConstructGraph(
A);
442 TSparseSpace::SetToZero(Dx);
446 TSparseSpace::SetToZero(
b);
480 KRATOS_WATCH(
"ResidualBasedEliminationBuilderAndSolver Clear Function called");
502 std::string
Info()
const override
504 return "ResidualBasedEliminationBuilderAndSolverComponentwise";
551 unsigned int pos = (mActiveNodes.begin())->GetDofPosition(rVar);
555 in!=mActiveNodes.end(); in++)
558 if( current_dof.
IsFixed() ==
false)
560 index_i = (current_dof).EquationId();
563 std::vector<int>& indices = index_list[index_i];
567 indices.push_back(index_i);
569 i != neighb_nodes.
end();
i++)
572 if(neighb_dof.
IsFixed() == false )
574 int index_j = (neighb_dof).EquationId();
575 indices.push_back(index_j);
580 std::sort(indices.begin(),indices.end());
581 typename std::vector<int>::iterator new_end = std::unique(indices.begin(),indices.end());
583 indices.erase(new_end,indices.end());
585 total_size += indices.size();
589 A.reserve(total_size,
false);
594 std::vector<int>& indices = index_list[
i];
595 for(
unsigned int j=0;
j<indices.size();
j++)
597 A.push_back(
i,indices[
j] , 0.00);
616 int number_of_threads = omp_get_max_threads();
618 unsigned int pos = (mActiveNodes.begin())->GetDofPosition(rVar);
623 for(
int i=0;
i<number_of_threads;
i++)
626 CreatePartition(number_of_threads, mActiveNodes.size(), partition);
628 #pragma omp parallel for firstprivate(number_of_threads,pos) schedule(static,1)
629 for(
int k=0;
k<number_of_threads;
k++)
638 if( current_dof.
IsFixed() ==
false)
640 int index_i = (current_dof).EquationId();
643 std::vector<int>& indices = index_list[index_i];
647 indices.push_back(index_i);
649 i != neighb_nodes.
end();
i++)
653 if(neighb_dof.
IsFixed() == false )
655 int index_j = (neighb_dof).EquationId();
656 indices.push_back(index_j);
661 std::sort(indices.begin(),indices.end());
662 typename std::vector<int>::iterator new_end = std::unique(indices.begin(),indices.end());
663 indices.erase(new_end,indices.end());
665 local_sizes[
k] += indices.size();
671 int total_size = 0.0;
672 for(
int i=0;
i<number_of_threads;
i++)
673 total_size += local_sizes[
i];
675 A.reserve(total_size,
false);
680 std::vector<int>& indices = index_list[
i];
681 for(
unsigned int j=0;
j<indices.size();
j++)
683 A.push_back(
i,indices[
j] , 0.00);
725 TVariableType
const & rVar;
726 GlobalPointersVector<Node > mActiveNodes;
733 inline void CreatePartition(
unsigned int number_of_threads,
const int number_of_rows, DenseVector<unsigned int>& partitions)
735 partitions.resize(number_of_threads+1);
736 int partition_size = number_of_rows / number_of_threads;
738 partitions[number_of_threads] = number_of_rows;
739 for(
unsigned int i = 1;
i<number_of_threads;
i++)
740 partitions[
i] = partitions[
i-1] + partition_size ;
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
bool mDofSetIsInitialized
If the matrix is reshaped each step.
Definition: builder_and_solver.h:743
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
bool GetCalculateReactionsFlag() const
This method returns the flag mCalculateReactionsFlag.
Definition: builder_and_solver.h:184
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
TSystemVectorPointerType mpReactionsVector
Definition: builder_and_solver.h:751
bool GetReshapeMatrixFlag() const
This method returns the flag mReshapeMatrixFlag.
Definition: builder_and_solver.h:220
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
bool mCalculateReactionsFlag
Flag taking care if the dof set was initialized ot not.
Definition: builder_and_solver.h:745
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
Definition: builtin_timer.h:26
std::vector< std::size_t > EquationIdVectorType
Definition: condition.h:98
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
bool IsFixed() const
Definition: dof.h:376
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
iterator begin()
Definition: global_pointers_vector.h:221
void reserve(int dim)
Definition: global_pointers_vector.h:375
size_type size() const
Definition: global_pointers_vector.h:307
iterator end()
Definition: global_pointers_vector.h:229
Definition: amatrix_interface.h:41
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
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
void clear()
Clear the set, removing all elements.
Definition: pointer_vector_set.h:663
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
ptr_iterator ptr_begin()
Returns an iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:386
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
typename TContainerType::iterator ptr_iterator
Definition: pointer_vector_set.h:104
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Definition: residualbased_elimination_builder_and_solver_componentwise.h:95
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:115
BaseType::TSchemeType TSchemeType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:105
void Build(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &b) override
Function to perform the build of the RHS. The vector could be sized as the total number of dofs or as...
Definition: residualbased_elimination_builder_and_solver_componentwise.h:181
BaseType::TDataType TDataType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:107
std::string Info() const override
Turn back information as a string.
Definition: residualbased_elimination_builder_and_solver_componentwise.h:502
void SetUpDofSet(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part) override
Builds the list of the DofSets involved in the problem by "asking" to each element and condition its ...
Definition: residualbased_elimination_builder_and_solver_componentwise.h:321
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:120
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_elimination_builder_and_solver_componentwise.h:514
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:111
BaseType::NodesArrayType NodesArrayType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:123
ResidualBasedEliminationBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > ResidualBasedEliminationBuilderAndSolverType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:103
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:109
ResidualBasedEliminationBuilderAndSolverComponentwise(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_elimination_builder_and_solver_componentwise.h:136
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:117
void ResizeAndInitializeVectors(typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType &pA, TSystemVectorPointerType &pDx, TSystemVectorPointerType &pb, ModelPart &rModelPart) override
This method resize and initializes the system of euqations.
Definition: residualbased_elimination_builder_and_solver_componentwise.h:380
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedEliminationBuilderAndSolverComponentwise)
ResidualBasedEliminationBuilderAndSolverComponentwise(typename TLinearSolver::Pointer pNewLinearSystemSolver, TVariableType const &Var)
Default constructor. Constructor.
Definition: residualbased_elimination_builder_and_solver_componentwise.h:156
BaseType::ElementsContainerType ElementsContainerType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:127
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:124
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:113
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:102
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:125
void ConstructGraph(TSystemMatrixType &A)
Definition: residualbased_elimination_builder_and_solver_componentwise.h:543
~ResidualBasedEliminationBuilderAndSolverComponentwise() override
Definition: residualbased_elimination_builder_and_solver_componentwise.h:169
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: residualbased_elimination_builder_and_solver_componentwise.h:468
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_elimination_builder_and_solver_componentwise.h:119
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_elimination_builder_and_solver_componentwise.h:508
Current class provides an implementation for standard elimination builder and solving operations.
Definition: residualbased_elimination_builder_and_solver.h:76
void Assemble(TSystemMatrixType &rA, TSystemVectorType &rb, const LocalSystemMatrixType &rLHSContribution, const LocalSystemVectorType &rRHSContribution, const Element::EquationIdVectorType &rEquationId)
This method assembles the system.
Definition: residualbased_elimination_builder_and_solver.h:1037
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17