13 #if !defined(KRATOS_SCALING_SOLVER_H_INCLUDED )
14 #define KRATOS_SCALING_SOLVER_H_INCLUDED
60 template<
class TSparseSpaceType,
class TDenseSpaceType,
61 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
63 :
public LinearSolver<TSparseSpaceType, TDenseSpaceType, TReordererType>
105 typename BaseType::Pointer pLinearSolver,
106 const bool SymmetricScaling =
true
108 mpLinearSolver(pLinearSolver),
109 mSymmetricScaling(SymmetricScaling)
122 KRATOS_ERROR_IF_NOT(ThisParameters.
Has(
"solver_type")) <<
"Solver_type must be specified to construct the ScalingSolver" << std::endl;
126 mSymmetricScaling = ThisParameters.
Has(
"symmetric_scaling") ? ThisParameters[
"symmetric_scaling"].
GetBool() :
true;
161 return mpLinearSolver->AdditionalPhysicalDataIsNeeded();
178 mpLinearSolver->ProvideAdditionalData(rA,rX,rB,rdof_set,r_model_part);
183 mpLinearSolver->InitializeSolutionStep(rA,rX,rB);
194 mpLinearSolver->FinalizeSolutionStep(rA,rX,rB);
203 mpLinearSolver->Clear();
222 GetScalingWeights(rA,scaling_vector);
225 if(mSymmetricScaling ==
false)
232 scaling_vector[
Index] = sqrt(std::abs(scaling_vector[
Index]));
235 SymmetricScaling(rA,scaling_vector);
247 bool is_solved = mpLinearSolver->Solve(rA,rX,rB);
250 if(mSymmetricScaling ==
true)
268 return mpLinearSolver->GetIterationsNumber();
282 std::string
Info()
const override
284 std::stringstream buffer;
285 buffer <<
"Composite Linear Solver. Uses internally the following linear solver " << mpLinearSolver->Info();
355 bool mSymmetricScaling;
374 int number_of_rows = partition[thread_id+1] - partition[thread_id];
375 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::iterator row_iter_begin =
A.index1_data().begin()+partition[thread_id];
376 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::iterator index_2_begin =
A.index2_data().begin()+*row_iter_begin;
377 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::value_array_type::iterator value_begin =
A.value_data().begin()+*row_iter_begin;
379 perform_matrix_scaling( number_of_rows,
383 partition[thread_id],
392 static void perform_matrix_scaling(
394 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::iterator row_begin,
395 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::iterator index2_begin,
396 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::value_array_type::iterator value_begin,
397 unsigned int output_begin_index,
402 typename SparseMatrixType::index_array_type::const_iterator row_it = row_begin;
403 int kkk = output_begin_index;
404 for(
int k = 0;
k < number_of_rows;
k++)
406 row_size= *(row_it+1)-*row_it;
408 const typename TDenseSpaceType::DataType row_weight = weights[kkk++];
410 for(
int i = 0;
i<row_size;
i++)
412 const typename TDenseSpaceType::DataType col_weight = weights[*index2_begin];
413 typename TDenseSpaceType::DataType
t = (*value_begin);
414 t /= (row_weight*col_weight);
438 int number_of_rows = partition[thread_id+1] - partition[thread_id];
439 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::const_iterator row_iter_begin =
A.index1_data().begin()+partition[thread_id];
440 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::const_iterator index_2_begin =
A.index2_data().begin()+*row_iter_begin;
441 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::value_array_type::const_iterator value_begin =
A.value_data().begin()+*row_iter_begin;
443 GS2weights( number_of_rows,
447 partition[thread_id],
456 static void GS2weights(
458 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::const_iterator row_begin,
459 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::index_array_type::const_iterator index2_begin,
460 typename boost::numeric::ublas::compressed_matrix<typename TDenseSpaceType::DataType>::value_array_type::const_iterator value_begin,
461 unsigned int output_begin_index,
466 typename SparseMatrixType::index_array_type::const_iterator row_it = row_begin;
467 int kkk = output_begin_index;
468 for(
int k = 0;
k < number_of_rows;
k++)
470 row_size= *(row_it+1)-*row_it;
474 for(
int i = 0;
i<row_size;
i++)
476 double tmp = std::abs(*value_begin);
522 template<
class TSparseSpaceType,
class TDenseSpaceType,
523 class TPreconditionerType,
524 class TReordererType>
527 TReordererType>& rThis)
533 template<
class TSparseSpaceType,
class TDenseSpaceType,
534 class TPreconditionerType,
535 class TReordererType>
538 TReordererType>& rThis)
540 rThis.PrintInfo(OStream);
541 OStream << std::endl;
542 rThis.PrintData(OStream);
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
Here we add the functions needed for the registration of linear solvers.
Definition: linear_solver_factory.h:62
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: linear_solver.h:388
LinearSolver & operator=(const LinearSolver &Other)
Assignment operator.
Definition: linear_solver.h:112
virtual bool IsNotConsistent(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
This method checks if the dimensions of the system of equations are not consistent.
Definition: linear_solver.h:346
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
static void DivideInPartitions(const int NumTerms, const int NumThreads, PartitionVector &Partitions)
Divide an array of length NumTerms between NumThreads threads.
Definition: openmp_utils.h:158
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
std::vector< int > PartitionVector
Vector type for the output of DivideInPartitions method.
Definition: openmp_utils.h:53
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
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
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
This solvers rescales in order to improve the conditioning of the system.
Definition: scaling_solver.h:64
TDenseSpaceType::MatrixType DenseMatrixType
The definition of the spaces (dense matrix)
Definition: scaling_solver.h:82
KRATOS_CLASS_POINTER_DEFINITION(ScalingSolver)
Pointer definition of ScalingSolver.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: scaling_solver.h:290
TSparseSpaceType::IndexType IndexType
The index type definition to be consistent.
Definition: scaling_solver.h:88
void ProvideAdditionalData(SparseMatrixType &rA, VectorType &rX, VectorType &rB, typename ModelPart::DofsArrayType &rdof_set, ModelPart &r_model_part) override
Definition: scaling_solver.h:170
void Clear() override
Definition: scaling_solver.h:201
~ScalingSolver() override
Destructor.
Definition: scaling_solver.h:136
TSparseSpaceType::VectorType VectorType
The definition of the spaces (vector)
Definition: scaling_solver.h:79
std::string Info() const override
Turn back information as a string.
Definition: scaling_solver.h:282
void InitializeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: scaling_solver.h:181
void FinalizeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: scaling_solver.h:192
ScalingSolver()
Default constructor.
Definition: scaling_solver.h:95
IndexType GetIterationsNumber() override
Definition: scaling_solver.h:266
ScalingSolver(const ScalingSolver &Other)
Copy constructor.
Definition: scaling_solver.h:132
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: scaling_solver.h:296
bool AdditionalPhysicalDataIsNeeded() override
Definition: scaling_solver.h:159
ScalingSolver & operator=(const ScalingSolver &Other)
Assignment operator.
Definition: scaling_solver.h:144
TSparseSpaceType::MatrixType SparseMatrixType
The definition of the spaces (sparse matrix)
Definition: scaling_solver.h:76
LinearSolver< TSparseSpaceType, TDenseSpaceType, TReordererType > BaseType
Definition of the base type.
Definition: scaling_solver.h:73
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: scaling_solver.h:214
ScalingSolver(Parameters ThisParameters)
Constructor with parameters.
Definition: scaling_solver.h:117
LinearSolverFactory< TSparseSpaceType, TDenseSpaceType > LinearSolverFactoryType
The definition of the linear solver factory type.
Definition: scaling_solver.h:85
ScalingSolver(typename BaseType::Pointer pLinearSolver, const bool SymmetricScaling=true)
Constructor without parameters.
Definition: scaling_solver.h:104
#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
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
std::size_t IndexType
Definition: binary_expression.cpp:25
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
int t
Definition: ode_solve.py:392
int k
Definition: quadrature.py:595
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17