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.
amgcl_solver.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Denis Demidov
11 // Riccardo Rossi
12 //
13 
14 #if !defined(KRATOS_AMGCL_SOLVER )
15 #define KRATOS_AMGCL_SOLVER
16 
17 #ifndef AMGCL_PARAM_UNKNOWN
18 #include "input_output/logger.h"
19 # define AMGCL_PARAM_UNKNOWN(name) \
20  Kratos::Logger("AMGCL") << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING << "Unknown parameter " << name << std::endl
21 #endif
22 
23 // System includes
24 #include <iostream>
25 #include <fstream>
26 #include <utility>
27 
28 // External includes
29 /* BOOST */
30 #include <boost/range/iterator_range.hpp>
31 #include <boost/property_tree/json_parser.hpp>
32 
33 // Project includes
34 #include "includes/define.h"
38 #include "spaces/ublas_space.h"
39 
40 #include <amgcl/coarsening/rigid_body_modes.hpp>
41 
42 namespace Kratos
43 {
46 
50 
55 {
57 };
58 
60 {
62 };
63 
65 {
67 };
68 
72 
82 void KRATOS_API(KRATOS_CORE) AMGCLSolve(
83  int block_size,
87  TUblasSparseSpace<double>::IndexType& rIterationNumber,
88  double& rResidual,
89  boost::property_tree::ptree amgclParams,
90  int verbosity_level,
91  bool use_gpgpu
92  );
93 
97 
108 template< class TSparseSpaceType, class TDenseSpaceType,
109  class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
110 class AMGCLSolver : public LinearSolver< TSparseSpaceType,
111  TDenseSpaceType, TReordererType>
112 {
113 public:
116 
119 
122 
125 
128 
131 
134 
137 
139  typedef std::size_t SizeType;
140 
144 
149  AMGCLSolver(Parameters ThisParameters = Parameters(R"({})"))
150  {
151  Parameters default_parameters( R"(
152  {
153  "preconditioner_type" : "amg",
154  "solver_type" : "AMGCL",
155  "smoother_type" : "ilu0",
156  "krylov_type" : "gmres",
157  "coarsening_type" : "aggregation",
158  "max_iteration" : 100,
159  "provide_coordinates" : false,
160  "gmres_krylov_space_dimension" : 100,
161  "verbosity" : 1,
162  "tolerance" : 1e-6,
163  "scaling" : false,
164  "block_size" : 1,
165  "use_block_matrices_if_possible" : true,
166  "coarse_enough" : 1000,
167  "max_levels" : -1,
168  "pre_sweeps" : 1,
169  "post_sweeps" : 1,
170  "use_gpgpu" : false
171  } )" );
172 
173  // Now validate agains defaults -- this also ensures no type mismatch
174  ThisParameters.ValidateAndAssignDefaults(default_parameters);
175 
176  // specify available options
177  std::set<std::string> available_smoothers = {"spai0","spai1","ilu0","ilut","iluk","damped_jacobi","gauss_seidel","chebyshev"};
178  std::set<std::string> available_solvers = {"gmres","bicgstab","cg","bicgstabl","lgmres","fgmres", "bicgstab_with_gmres_fallback","idrs"};
179  std::set<std::string> available_coarsening = {"ruge_stuben","aggregation","smoothed_aggregation","smoothed_aggr_emin"};
180  std::set<std::string> available_preconditioner = {"amg","relaxation","dummy"};
181 
182  // Validate if values are admissible
183  CheckIfSelectedOptionIsAvailable(ThisParameters, "smoother_type", available_smoothers);
184  CheckIfSelectedOptionIsAvailable(ThisParameters, "krylov_type", available_solvers);
185  CheckIfSelectedOptionIsAvailable(ThisParameters, "coarsening_type", available_coarsening);
186  CheckIfSelectedOptionIsAvailable(ThisParameters, "preconditioner_type", available_preconditioner);
187 
188  //selecting preconditioner type - default is AMG
189  mAMGCLParameters.put("precond.class", ThisParameters["preconditioner_type"].GetString());
190  if(ThisParameters["preconditioner_type"].GetString() != "amg"){
191  mUseAMGPreconditioning = false;
192  }
193 
194  if(ThisParameters["preconditioner_type"].GetString() == "relaxation") //this implies not using. Use a relaxation sweep as preconditioning. Relaxation type is taken from smoother_type
195  {
196  mAMGCLParameters.put("precond.type", ThisParameters["smoother_type"].GetString());
197  }
198 
199  mProvideCoordinates = ThisParameters["provide_coordinates"].GetBool();
200  mCoarseEnough = ThisParameters["coarse_enough"].GetInt();
201 
202  mBlockSize = ThisParameters["block_size"].GetInt(); //set the mndof to an inital number
203  mTolerance = ThisParameters["tolerance"].GetDouble();
204  mMaxIterationsNumber = ThisParameters["max_iteration"].GetInt();
205  mVerbosity=ThisParameters["verbosity"].GetInt();
206  mGMRESSize = ThisParameters["gmres_krylov_space_dimension"].GetInt();
207 
208  const std::string& solver_type = ThisParameters["krylov_type"].GetString();
209  mAMGCLParameters.put("solver.type", solver_type);
210  mFallbackToGMRES = false;
211 
212  if(solver_type == "bicgstab_with_gmres_fallback") {
213  mFallbackToGMRES = true;
214  mAMGCLParameters.put("solver.type", "bicgstab");
215  }
216 
217  //settings only needed if full AMG is used
219  {
220  mAMGCLParameters.put("precond.relax.type", ThisParameters["smoother_type"].GetString());
221  mAMGCLParameters.put("precond.coarsening.type", ThisParameters["coarsening_type"].GetString());
222 
223  int max_levels = ThisParameters["max_levels"].GetInt();
224  if(max_levels >= 0)
225  mAMGCLParameters.put("precond.max_levels", max_levels);
226 
227  mAMGCLParameters.put("precond.npre", ThisParameters["pre_sweeps"].GetInt());
228  mAMGCLParameters.put("precond.npost", ThisParameters["post_sweeps"].GetInt());
229  }
230 
231  mUseBlockMatricesIfPossible = ThisParameters["use_block_matrices_if_possible"].GetBool();
232 
233  mUseGPGPU = ThisParameters["use_gpgpu"].GetBool();
234  }
235 
246  AMGCLSmoother Smoother,
248  double Tolerance,
249  int MaxIterationsNumber,
250  int Verbosity,
251  int GMRESSize = 50
252  ) : mTolerance(Tolerance),
253  mMaxIterationsNumber(MaxIterationsNumber),
254  mVerbosity(Verbosity),
255  mBlockSize(1),
256  mGMRESSize(GMRESSize),
257  mCoarseEnough(1000),
258  mFallbackToGMRES(false),
259  mProvideCoordinates(false),
261  {
262  KRATOS_INFO_IF("AMGCL Linear Solver", mVerbosity > 0) << "Setting up AMGCL for iterative solve " << std::endl;
263 
264  // Choose smoother in the list "gauss_seidel, multicolor_gauss_seidel, ilu0, parallel_ilu0, ilut, damped_jacobi, spai0, chebyshev"
265  SetSmootherType(Smoother);
266  // Setting iterative solver
267  SetIterativeSolverType(Solver);
268 
269  mAMGCLParameters.put("precond.coarsening.type", "aggregation");
270  }
271 
283  AMGCLSmoother Smoother,
285  AMGCLCoarseningType Coarsening,
286  double Tolerance,
287  int MaxIterationsNumber,
288  int Verbosity,
289  int GMRESSize = 50,
290  bool ProvideCoordinates = false
291  ) : mTolerance(Tolerance),
292  mMaxIterationsNumber(MaxIterationsNumber),
293  mVerbosity(Verbosity),
294  mBlockSize(1),
295  mGMRESSize(GMRESSize),
296  mCoarseEnough(1000),
297  mFallbackToGMRES(false),
298  mProvideCoordinates(ProvideCoordinates),
300  {
301  KRATOS_INFO_IF("AMGCL Linear Solver", mVerbosity > 0) << "Setting up AMGCL for iterative solve " << std::endl;
302 
303  // Choose smoother in the list "gauss_seidel, multicolor_gauss_seidel, ilu0, parallel_ilu0, ilut, damped_jacobi, spai0, chebyshev"
304  SetSmootherType(Smoother);
305  // Setting iterative solver
306  SetIterativeSolverType(Solver);
307  // Setting coarsening type
308  SetCoarseningType(Coarsening);
309  }
310 
314  ~AMGCLSolver() override {};
315 
319 
323 
331  bool Solve(
332  SparseMatrixType& rA,
333  VectorType& rX,
334  VectorType& rB
335  ) override
336  {
337  // Initial checks
338  KRATOS_ERROR_IF(TSparseSpaceType::Size1(rA) != TSparseSpaceType::Size2(rA) ) << "matrix A is not square! sizes are "
339  << TSparseSpaceType::Size1(rA) << " and " << TSparseSpaceType::Size2(rA) << std::endl;
340  KRATOS_ERROR_IF(TSparseSpaceType::Size(rX) != TSparseSpaceType::Size1(rA)) << "size of x does not match the size of A. x size is " << TSparseSpaceType::Size(rX)
341  << " matrix size is " << TSparseSpaceType::Size1(rA) << std::endl;
342  KRATOS_ERROR_IF(TSparseSpaceType::Size(rB) != TSparseSpaceType::Size1(rA)) << "size of b does not match the size of A. b size is " << TSparseSpaceType::Size(rB)
343  << " matrix size is " << TSparseSpaceType::Size1(rA) << std::endl;
344 
345  mAMGCLParameters.put("solver.tol", mTolerance);
346  mAMGCLParameters.put("solver.maxiter", mMaxIterationsNumber);
347 
349  mAMGCLParameters.put("precond.coarse_enough",mCoarseEnough/mBlockSize);
350 
351  // Use rigid body modes or set block size
352  int static_block_size = mUseBlockMatricesIfPossible ? mBlockSize : 1;
353  std::vector<double> B;
355  int nmodes = amgcl::coarsening::rigid_body_modes(mBlockSize,
356  boost::make_iterator_range(
357  &mCoordinates[0][0],
359  B);
360 
361  if (static_block_size != 1 && static_block_size != 3) {
362  KRATOS_WARNING("AMGCL Linear Solver") << "Can only combine block matrices with coordinates in 3D. Falling back to scalar matrices" << std::endl;
363  static_block_size = 1;
364  }
365 
366  mAMGCLParameters.put("precond.coarsening.aggr.eps_strong", 0.0);
367  mAMGCLParameters.put("precond.coarsening.aggr.block_size", 1);
368  mAMGCLParameters.put("precond.coarsening.nullspace.cols", nmodes);
369  mAMGCLParameters.put("precond.coarsening.nullspace.rows", TSparseSpaceType::Size1(rA));
370  mAMGCLParameters.put("precond.coarsening.nullspace.B", &B[0]);
371  } else if(mUseAMGPreconditioning && mAMGCLParameters.get<std::string>("precond.coarsening.type") != std::string("ruge_stuben")) {
372  mAMGCLParameters.put("precond.coarsening.aggr.eps_strong", 0.0);
373  mAMGCLParameters.put("precond.coarsening.aggr.block_size", mBlockSize);
374  }
375 
376  if (mVerbosity > 2) {
377  write_json(std::cout, mAMGCLParameters);
378  }
379 
380  if(mVerbosity == 4) {
381  //output to matrix market
382  std::stringstream matrix_market_name;
383  matrix_market_name << "A" << ".mm";
384  TSparseSpaceType::WriteMatrixMarketMatrix((char*) (matrix_market_name.str()).c_str(), rA, false);
385 
386  std::stringstream matrix_market_vectname;
387  matrix_market_vectname << "b" << ".mm.rhs";
388  TSparseSpaceType::WriteMatrixMarketVector((char*) (matrix_market_vectname.str()).c_str(), rB);
389 
390  if(mProvideCoordinates) {
391  //output of coordinates
392  std::ofstream coordsfile;
393  coordsfile.open ("coordinates.txt");
394  for(unsigned int i=0; i<mCoordinates.size(); i++) {
395  coordsfile << mCoordinates[i][0] << " " << mCoordinates[i][1] << " " << mCoordinates[i][2] << "\n";
396  }
397  coordsfile.close();
398  }
399 
400  KRATOS_ERROR << " Verbosity = 4 prints the matrix and exits" << std::endl;
401  }
402 
403  size_t iters;
404  double resid;
405  {
406  if(mFallbackToGMRES) mAMGCLParameters.put("solver.type", "bicgstab"); //first we need to try with bicgstab
407 
408  if(mAMGCLParameters.get<std::string>("solver.type") == "gmres" ||
409  mAMGCLParameters.get<std::string>("solver.type") == "lgmres" ||
410  mAMGCLParameters.get<std::string>("solver.type") == "fgmres" )
411  mAMGCLParameters.put("solver.M", mGMRESSize);
412  else
413  mAMGCLParameters.erase("solver.M");
414 
416  KRATOS_ERROR_IF(TSparseSpaceType::Size1(rA)%mBlockSize != 0) << "The block size employed " << mBlockSize << " is not an exact multiple of the matrix size "
417  << TSparseSpaceType::Size1(rA) << std::endl;
418  }
419  AMGCLSolve(static_block_size, rA,rX,rB, iters, resid, mAMGCLParameters, mVerbosity, mUseGPGPU);
420  } //please do not remove this parenthesis!
421 
422  if(mFallbackToGMRES && resid > mTolerance ) {
423  mAMGCLParameters.put("solver.type", "gmres");
424  mAMGCLParameters.put("solver.M", mGMRESSize);
425  AMGCLSolve(1, rA,rX,rB, iters, resid, mAMGCLParameters, mVerbosity, mUseGPGPU);
426  }
427 
428  KRATOS_WARNING_IF("AMGCL Linear Solver", mTolerance < resid)<<"Non converged linear solution. ["<< resid << " > "<< mTolerance << "]" << std::endl;
429 
430  KRATOS_INFO_IF("AMGCL Linear Solver", mVerbosity > 1)
431  << "Iterations: " << iters << std::endl
432  << "Error: " << resid << std::endl;
433 
434  // Setting values
435  SetResidualNorm(resid);
436  SetIterationsNumber(iters);
437 
438  // We check the convergence
439  if(resid > mTolerance)
440  return false;
441 
442  return true;
443  }
444 
449  virtual void SetIterationsNumber(const IndexType IterationsNumber)
450  {
451  mIterationsNumber = IterationsNumber;
452  }
453 
458  virtual void SetResidualNorm(const double ResidualNorm)
459  {
460  mResidualNorm = ResidualNorm;
461  }
462 
468  {
469  return mIterationsNumber;
470  }
471 
476  virtual double GetResidualNorm()
477  {
478  return mResidualNorm;
479  }
480 
489  {
490  return false;
491  }
492 
501  {
502  return true;
503  }
504 
513  SparseMatrixType& rA,
514  VectorType& rX,
515  VectorType& rB,
516  DofsArrayType& rDofSet,
517  ModelPart& rModelPart
518  ) override
519  {
520  int old_ndof = -1;
521  int ndof=0;
522 
523  if (!rModelPart.IsDistributed())
524  {
525  unsigned int old_node_id = rDofSet.size() ? rDofSet.begin()->Id() : 0;
526  for (auto it = rDofSet.begin(); it!=rDofSet.end(); it++) {
527  if(it->EquationId() < TSparseSpaceType::Size1(rA) ) {
528  IndexType id = it->Id();
529  if(id != old_node_id) {
530  old_node_id = id;
531  if(old_ndof == -1) old_ndof = ndof;
532  else if(old_ndof != ndof) { //if it is different than the block size is 1
533  old_ndof = -1;
534  break;
535  }
536 
537  ndof=1;
538  } else {
539  ndof++;
540  }
541  }
542  }
543 
544  if(old_ndof == -1)
545  mBlockSize = 1;
546  else
547  mBlockSize = ndof;
548 
549  }
550  else //distribute
551  {
552  const std::size_t system_size = TSparseSpaceType::Size1(rA);
553  int current_rank = rModelPart.GetCommunicator().GetDataCommunicator().Rank();
554  unsigned int old_node_id = rDofSet.size() ? rDofSet.begin()->Id() : 0;
555  for (auto it = rDofSet.begin(); it!=rDofSet.end(); it++) {
556  if(it->EquationId() < system_size && it->GetSolutionStepValue(PARTITION_INDEX) == current_rank) {
557  IndexType id = it->Id();
558  if(id != old_node_id) {
559  old_node_id = id;
560  if(old_ndof == -1) old_ndof = ndof;
561  else if(old_ndof != ndof) { //if it is different than the block size is 1
562  old_ndof = -1;
563  break;
564  }
565 
566  ndof=1;
567  } else {
568  ndof++;
569  }
570  }
571  }
572 
573  if(old_ndof != -1)
574  mBlockSize = ndof;
575 
576  int max_block_size = rModelPart.GetCommunicator().GetDataCommunicator().MaxAll(mBlockSize);
577 
578  if( old_ndof == -1) {
579  mBlockSize = max_block_size;
580  }
581 
582  KRATOS_ERROR_IF(mBlockSize != max_block_size) << "Block size is not consistent. Local: " << mBlockSize << " Max: " << max_block_size << std::endl;
583  }
584 
585  KRATOS_INFO_IF("AMGCL Linear Solver", mVerbosity > 1) << "mndof: " << mBlockSize << std::endl;
586 
587  if(mProvideCoordinates) {
589  unsigned int i=0;
590  for (auto it_dof = rDofSet.begin(); it_dof!=rDofSet.end(); it_dof+=mBlockSize) {
591  if(it_dof->EquationId() < TSparseSpaceType::Size1(rA) ) {
592  auto it_node = rModelPart.Nodes().find(it_dof->Id());
593  mCoordinates[ i ] = it_node->Coordinates();
594  i++;
595  }
596  }
597  }
598  }
599 
603 
604 
608 
609 
613 
617  void PrintInfo(std::ostream& rOStream) const override
618  {
619  rOStream << "AMGCL solver:";
620  }
621 
625  void PrintData(std::ostream& rOStream) const override
626  {
627  rOStream << "Settings: ";
628  write_json(rOStream, mAMGCLParameters);
629  }
630 
634 
639 
641 
642 protected:
645 
649 
653 
657 
658  // Helper function for checking if a selected option is available
659  // and printing the available options
661  const Parameters ThisParameters,
662  const std::string& rOptionName,
663  const std::set<std::string>& rAvailableOptions)
664  {
665  if (rAvailableOptions.find(ThisParameters[rOptionName].GetString()) == rAvailableOptions.end()) {
666  std::stringstream msg;
667  msg << "Currently prescribed " << rOptionName << " : " << ThisParameters[rOptionName].GetString() << std::endl;
668  msg << "Admissible values are :";
669  for (const auto& r_name : rAvailableOptions) {
670  msg << std::endl << " " << r_name;
671  }
672  KRATOS_ERROR << "AMGCL Linear Solver : " << rOptionName << " is invalid!" << std::endl << msg.str() << std::endl;
673  }
674  }
675 
679 
683 
687 
689 
692 
696 
697  double mTolerance;
706  bool mUseGPGPU;
707 
708  std::vector<array_1d<double,3> > mCoordinates;
709 
710  boost::property_tree::ptree mAMGCLParameters;
711 
712  double mResidualNorm = 0.0;
715 
719 
724  void SetSmootherType(const AMGCLSmoother SmootherType)
725  {
726  switch(SmootherType)
727  {
728  case SPAI0:
729  {
730  mAMGCLParameters.put("precond.relax.type","spai0");
731  break;
732  }
733  case SPAI1:
734  {
735  mAMGCLParameters.put("precond.relax.type","spai1");
736  break;
737  }
738  case ILU0:
739  {
740  mAMGCLParameters.put("precond.relax.type","ilu0");
741  break;
742  }
743  case DAMPED_JACOBI:
744  {
745  mAMGCLParameters.put("precond.relax.type","damped_jacobi");
746  break;
747  }
748  case GAUSS_SEIDEL:
749  {
750  mAMGCLParameters.put("precond.relax.type","gauss_seidel");
751  break;
752  }
753  case CHEBYSHEV:
754  {
755  mAMGCLParameters.put("precond.relax.type","chebyshev");
756  break;
757  }
758  };
759  }
760 
766  {
767  switch(SolverType)
768  {
769  case GMRES:
770  {
771  mAMGCLParameters.put("solver.M", mGMRESSize);
772  mAMGCLParameters.put("solver.type", "gmres");
773  break;
774  }
775  case FGMRES:
776  {
777  mAMGCLParameters.put("solver.M", mGMRESSize);
778  mAMGCLParameters.put("solver.type", "fgmres");
779  break;
780  }
781  case LGMRES:
782  {
783  mAMGCLParameters.put("solver.M", mGMRESSize);
784  mAMGCLParameters.put("solver.type", "lgmres");
785  break;
786  }
787  case BICGSTAB:
788  {
789  mAMGCLParameters.put("solver.type", "bicgstab");
790  break;
791  }
792  case CG:
793  {
794  mAMGCLParameters.put("solver.type", "cg");
795  break;
796  }
797  case BICGSTAB2:
798  {
799  mAMGCLParameters.put("solver.type", "bicgstabl");
800  break;
801  }
803  {
804  mAMGCLParameters.put("solver.M", mGMRESSize);
805  mAMGCLParameters.put("solver.type", "bicgstab");
806  mFallbackToGMRES=true;
807  break;
808  }
809  };
810  }
811 
816  void SetCoarseningType(const AMGCLCoarseningType CoarseningType)
817  {
818  switch(CoarseningType)
819  {
820  case RUGE_STUBEN:
821  {
822  mAMGCLParameters.put("precond.coarsening.type", "ruge_stuben");
823  break;
824  }
825  case AGGREGATION:
826  {
827  mAMGCLParameters.put("precond.coarsening.type", "aggregation");
828  break;
829  }
830  case SA:
831  {
832  mAMGCLParameters.put("precond.coarsening.type", "smoothed_aggregation");
833  break;
834  }
835  case SA_EMIN:
836  {
837  mAMGCLParameters.put("precond.coarsening.type", "smoothed_aggr_emin");
838  break;
839  }
840  };
841  }
842 
843 
847 
848 
852 
853 
857 
861 
865  AMGCLSolver(const AMGCLSolver& Other);
866 
867 }; // Class AMGCLSolver
868 
869 
873 template<class TSparseSpaceType, class TDenseSpaceType,class TReordererType>
874 inline std::istream& operator >> (std::istream& rIStream, AMGCLSolver< TSparseSpaceType,
875  TDenseSpaceType, TReordererType>& rThis)
876 {
877  return rIStream;
878 }
879 
883 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType>
884 inline std::ostream& operator << (std::ostream& rOStream,
885  const AMGCLSolver<TSparseSpaceType,
886  TDenseSpaceType, TReordererType>& rThis)
887 {
888  rThis.PrintInfo(rOStream);
889  rOStream << std::endl;
890  rThis.PrintData(rOStream);
891 
892  return rOStream;
893 }
894 
895 } // namespace Kratos.
896 
897 
898 #endif // KRATOS_AMGCL_SOLVER defined
This is a multigrid solver based on the AMGCL library.
Definition: amgcl_solver.h:112
bool mUseBlockMatricesIfPossible
If the coordinates are provided (TODO: Local flag?)
Definition: amgcl_solver.h:705
~AMGCLSolver() override
Definition: amgcl_solver.h:314
virtual double GetResidualNorm()
This method returns the current residual norm.
Definition: amgcl_solver.h:476
void SetIterativeSolverType(const AMGCLIterativeSolverType SolverType)
This method sets the iterative solver to be considered.
Definition: amgcl_solver.h:765
std::vector< array_1d< double, 3 > > mCoordinates
Use GPGPU if available.
Definition: amgcl_solver.h:708
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Multi solve method for solving a set of linear systems with same coefficient matrix.
Definition: amgcl_solver.h:488
bool mUseGPGPU
If use the bloack matrices if possible (TODO: Local flag?)
Definition: amgcl_solver.h:706
AMGCLSolver(Parameters ThisParameters=Parameters(R"({})"))
This is the default constructor.
Definition: amgcl_solver.h:149
TSparseSpaceType::VectorType VectorType
Vector type definition.
Definition: amgcl_solver.h:127
int mBlockSize
The versoisty level.
Definition: amgcl_solver.h:700
void PrintData(std::ostream &rOStream) const override
Definition: amgcl_solver.h:625
AMGCLSolver(AMGCLSmoother Smoother, AMGCLIterativeSolverType Solver, AMGCLCoarseningType Coarsening, double Tolerance, int MaxIterationsNumber, int Verbosity, int GMRESSize=50, bool ProvideCoordinates=false)
Definition: amgcl_solver.h:282
LinearSolver< TSparseSpaceType, TDenseSpaceType, TReordererType > BaseType
The base class definition.
Definition: amgcl_solver.h:121
double mResidualNorm
The configuration parameters of the AMGCl.
Definition: amgcl_solver.h:712
double mTolerance
Definition: amgcl_solver.h:697
IndexType mMaxIterationsNumber
The tolerance considered.
Definition: amgcl_solver.h:698
KRATOS_CLASS_POINTER_DEFINITION(AMGCLSolver)
Pointer definition of AMGCLSolver.
SizeType mGMRESSize
The size of the dof block.
Definition: amgcl_solver.h:701
IndexType GetIterationsNumber() override
This method returns the current iteration number.
Definition: amgcl_solver.h:467
TSparseSpaceType::IndexType IndexType
The index type definition to be consistent.
Definition: amgcl_solver.h:136
bool mFallbackToGMRES
The level of coarsening allowed.
Definition: amgcl_solver.h:703
bool mUseAMGPreconditioning
The current iteration number.
Definition: amgcl_solver.h:714
AMGCLSolver(const AMGCLSolver &Other)
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Normal solve method.
Definition: amgcl_solver.h:331
virtual void SetIterationsNumber(const IndexType IterationsNumber)
This method sets the current iteration number.
Definition: amgcl_solver.h:449
void SetSmootherType(const AMGCLSmoother SmootherType)
This method sets the smother type to be considered.
Definition: amgcl_solver.h:724
AMGCLSolver(AMGCLSmoother Smoother, AMGCLIterativeSolverType Solver, double Tolerance, int MaxIterationsNumber, int Verbosity, int GMRESSize=50)
Default constructor - uses ILU+GMRES.
Definition: amgcl_solver.h:245
void CheckIfSelectedOptionIsAvailable(const Parameters ThisParameters, const std::string &rOptionName, const std::set< std::string > &rAvailableOptions)
Definition: amgcl_solver.h:660
int mVerbosity
The maximum number of iterations considered.
Definition: amgcl_solver.h:699
ModelPart::DofsArrayType DofsArrayType
DofArray type.
Definition: amgcl_solver.h:133
void PrintInfo(std::ostream &rOStream) const override
Definition: amgcl_solver.h:617
TDenseSpaceType::MatrixType DenseMatrixType
Dense matrix type.
Definition: amgcl_solver.h:130
SizeType mCoarseEnough
The size of the GMRES.
Definition: amgcl_solver.h:702
IndexType mIterationsNumber
The current residual norm.
Definition: amgcl_solver.h:713
void SetCoarseningType(const AMGCLCoarseningType CoarseningType)
This method sets the coarsening type to be considered.
Definition: amgcl_solver.h:816
bool mProvideCoordinates
Of consider GMRES as fallback (TODO: Local flag?)
Definition: amgcl_solver.h:704
std::size_t SizeType
The size type definition.
Definition: amgcl_solver.h:139
boost::property_tree::ptree mAMGCLParameters
The vector containing the local coordinates.
Definition: amgcl_solver.h:710
bool AdditionalPhysicalDataIsNeeded() override
Some solvers may require a minimum degree of knowledge of the structure of the matrix....
Definition: amgcl_solver.h:500
virtual void SetResidualNorm(const double ResidualNorm)
This method sets the current residual norm.
Definition: amgcl_solver.h:458
TSparseSpaceType::MatrixType SparseMatrixType
The sparse matric type.
Definition: amgcl_solver.h:124
void ProvideAdditionalData(SparseMatrixType &rA, VectorType &rX, VectorType &rB, DofsArrayType &rDofSet, ModelPart &rModelPart) override
Some solvers may require a minimum degree of knowledge of the structure of the matrix.
Definition: amgcl_solver.h:512
AMGCLSolver & operator=(const AMGCLSolver &Other)
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
bool IsDistributed() const
Definition: model_part.h:1898
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
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
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
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
std::size_t IndexType
The index type considered.
Definition: ublas_space.h:139
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
#define KRATOS_WARNING(label)
Definition: logger.h:265
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
std::size_t IndexType
Definition: binary_expression.cpp:25
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
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
void AMGCLSolve(int block_size, TUblasSparseSpace< double >::MatrixType &rA, TUblasSparseSpace< double >::VectorType &rX, TUblasSparseSpace< double >::VectorType &rB, TUblasSparseSpace< double >::IndexType &rIterationNumber, double &rResidual, boost::property_tree::ptree amgclParams, int verbosity_level, bool use_gpgpu)
This function solves with Ublas Matrix type.
Definition: amgcl_solver_impl.cpp:189
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
AMGCLSmoother
Definition: amgcl_solver.h:55
@ GAUSS_SEIDEL
Definition: amgcl_solver.h:56
@ CHEBYSHEV
Definition: amgcl_solver.h:56
@ ILU0
Definition: amgcl_solver.h:56
@ DAMPED_JACOBI
Definition: amgcl_solver.h:56
@ SPAI1
Definition: amgcl_solver.h:56
@ SPAI0
Definition: amgcl_solver.h:56
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
AMGCLCoarseningType
Definition: amgcl_solver.h:65
@ SA
Definition: amgcl_solver.h:66
@ RUGE_STUBEN
Definition: amgcl_solver.h:66
@ AGGREGATION
Definition: amgcl_solver.h:66
@ SA_EMIN
Definition: amgcl_solver.h:66
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
AMGCLIterativeSolverType
Definition: amgcl_solver.h:60
@ BICGSTAB
Definition: amgcl_solver.h:61
@ CG
Definition: amgcl_solver.h:61
@ BICGSTAB_WITH_GMRES_FALLBACK
Definition: amgcl_solver.h:61
@ FGMRES
Definition: amgcl_solver.h:61
@ LGMRES
Definition: amgcl_solver.h:61
@ BICGSTAB2
Definition: amgcl_solver.h:61
@ GMRES
Definition: amgcl_solver.h:61
string SolverType
Definition: fluid_only_var.py:5
int block_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:16
B
Definition: sensitivityMatrix.py:76
integer i
Definition: TensorModule.f:17