From 7037634697d67f6c43f1f7f50caf05284df788c7 Mon Sep 17 00:00:00 2001 From: turcksin Date: Mon, 14 Jul 2014 15:15:42 +0000 Subject: [PATCH] Reindent some files. git-svn-id: https://svn.dealii.org/branches/branch_paralution@33167 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/lac/paralution_precondition.h | 3 +- .../include/deal.II/lac/paralution_solver.h | 10 +- .../include/deal.II/lac/paralution_vector.h | 19 +- deal.II/source/lac/paralution_precondition.cc | 172 ++++---- deal.II/source/lac/paralution_solver.cc | 400 +++++++++--------- deal.II/source/lac/paralution_vector.cc | 11 +- 6 files changed, 319 insertions(+), 296 deletions(-) diff --git a/deal.II/include/deal.II/lac/paralution_precondition.h b/deal.II/include/deal.II/lac/paralution_precondition.h index 4e94a075cc..d7c45ef4f1 100644 --- a/deal.II/include/deal.II/lac/paralution_precondition.h +++ b/deal.II/include/deal.II/lac/paralution_precondition.h @@ -48,7 +48,8 @@ namespace ParalutionWrappers * Preconditioner for the smoother of the multigrid. */ enum mg_preconditioner {jacobi, sgs, multicolored_sgs, multicolored_sor, ilu, - ilut, multicolored_ilu}; + ilut, multicolored_ilu + }; /** * Solver used as smoother and to solve the coarse system of the multigrid. diff --git a/deal.II/include/deal.II/lac/paralution_solver.h b/deal.II/include/deal.II/lac/paralution_solver.h index 9b3a738cdb..9d79808578 100644 --- a/deal.II/include/deal.II/lac/paralution_solver.h +++ b/deal.II/include/deal.II/lac/paralution_solver.h @@ -36,7 +36,7 @@ DEAL_II_NAMESPACE_OPEN namespace ParalutionWrappers { /** - * Base class for solver classes using the Paralution solvers except AMG which + * Base class for solver classes using the Paralution solvers except AMG which * is not derived from this class. * * @ingroup ParalutionWrappers @@ -71,7 +71,7 @@ namespace ParalutionWrappers /** * Reference to the object that controls convergence of the iterative * solver. In fact, for these Paralution wrappers, Paralution does so - * itself, but we copy the data from this object before starting solution + * itself, but we copy the data from this object before starting solution * process, and copy the data back into it afterwards. */ SolverControl &solver_control; @@ -514,7 +514,7 @@ namespace ParalutionWrappers * @ingroup ParalutionWrappers * @author Bruno Turcksin, 2014 */ - class SolverAMG + class SolverAMG { public: /** @@ -597,7 +597,7 @@ namespace ParalutionWrappers * flags for tuning this particular solver. */ SolverAMG (SolverControl &cn, - const AdditionalData &data = AdditionalData()); + const AdditionalData &data = AdditionalData()); /** * Solve the linear system Ax=b using the AMG solver of @@ -621,7 +621,7 @@ namespace ParalutionWrappers /** * Reference to the object that controls convergence of the iterative * solver. In fact, for these Paralution wrappers, Paralution does so - * itself, but we copy the data from this object before starting solution + * itself, but we copy the data from this object before starting solution * process, and copy the data back into it afterwards. */ SolverControl &solver_control; diff --git a/deal.II/include/deal.II/lac/paralution_vector.h b/deal.II/include/deal.II/lac/paralution_vector.h index 2d857a849c..8793763b3a 100644 --- a/deal.II/include/deal.II/lac/paralution_vector.h +++ b/deal.II/include/deal.II/lac/paralution_vector.h @@ -65,8 +65,11 @@ namespace ParalutionWrappers */ typedef dealii::types::global_dof_index size_type; typedef Number value_type; + typedef Number real_type; typedef Number *iterator; typedef const Number *const_iterator; + typedef value_type &reference; + typedef const value_type &const_reference; /** * A variable that indicates whether this vector supports distributed data @@ -450,9 +453,9 @@ namespace ParalutionWrappers * printed in a line, while if @p false then the elements are printed on a * separate line each. */ - void print (std::ostream &out, - const unsigned int precision, - const bool scientific, + void print (std::ostream &out, + const unsigned int precision, + const bool scientific, const bool across) const; /** @@ -461,6 +464,16 @@ namespace ParalutionWrappers */ void sync(); + /** + * Swap the contents of this vector and the other vector @p v. One could + * do this operation with a temporary variable and copying over the data + * elements, but this function is significantly more efficient since it + * only swaps the pointers to the data of the two vectors and therefore + * does not need to allocate temporary storage and move data around. Note + * that the vectors need to be of the same size and base on the same map. + */ + void swap (Vector &v); + /** * Determine an estimate for the memory consumption (in bytes) of this * object. diff --git a/deal.II/source/lac/paralution_precondition.cc b/deal.II/source/lac/paralution_precondition.cc index 2919a9c9c8..2577987c82 100644 --- a/deal.II/source/lac/paralution_precondition.cc +++ b/deal.II/source/lac/paralution_precondition.cc @@ -224,11 +224,11 @@ namespace ParalutionWrappers const mg_solver coarse_solver, const unsigned int n_unknowns_coarse_level, const unsigned int max_iter, - const mg_cycle cycle, + const mg_cycle cycle, const mg_interpolation interpolation, const double coupling_strength, const double relaxation_parameter, - const double over_interpolation) + const double over_interpolation) : verbose(verbose), coarse_solver(coarse_solver), @@ -269,8 +269,8 @@ namespace ParalutionWrappers { // Downcast the preconditioner pointer paralution::AMG,paralution::LocalVector, - Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); + Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); // Set the maximum number of iterations. downcasted_ptr->InitMaxIter(additional_data.max_iter); @@ -286,55 +286,55 @@ namespace ParalutionWrappers // Set the interpolation type. switch (additional_data.interpolation) - { + { case aggregation : - { - downcasted_ptr->SetInterpolation(paralution::Aggregation); - downcasted_ptr->SetOverInterp(additional_data.over_interpolation); - break; - } + { + downcasted_ptr->SetInterpolation(paralution::Aggregation); + downcasted_ptr->SetOverInterp(additional_data.over_interpolation); + break; + } case smoothed_aggregation : - { - downcasted_ptr->SetInterpolation(paralution::SmoothedAggregation); - downcasted_ptr->SetInterpRelax(additional_data.relaxation_parameter); - break; - } + { + downcasted_ptr->SetInterpolation(paralution::SmoothedAggregation); + downcasted_ptr->SetInterpRelax(additional_data.relaxation_parameter); + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown interpolation type for PreconditionAMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown interpolation type for PreconditionAMG.")); + } + } // Set the coupling strength downcasted_ptr->SetCouplingStrength(additional_data.coupling_strength); // Set the type of cycle switch (additional_data.cycle) - { + { case V_cycle : - { - downcasted_ptr->SetCycle(paralution::Vcycle); - break; - } + { + downcasted_ptr->SetCycle(paralution::Vcycle); + break; + } case W_cycle : - { - downcasted_ptr->SetCycle(paralution::Wcycle); - break; - } + { + downcasted_ptr->SetCycle(paralution::Wcycle); + break; + } case K_cycle : - { - downcasted_ptr->SetCycle(paralution::Kcycle); - break; - } + { + downcasted_ptr->SetCycle(paralution::Kcycle); + break; + } case F_cycle : - { - downcasted_ptr->SetCycle(paralution::Fcycle); - } + { + downcasted_ptr->SetCycle(paralution::Fcycle); + } default : - { - AssertThrow(false,ExcMessage("Unknown cycle type for PreconditionAMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown cycle type for PreconditionAMG.")); + } + } // Use manual coarse grid solver. downcasted_ptr->SetManualSolver(true); @@ -342,60 +342,60 @@ namespace ParalutionWrappers // Coarse solver switch (additional_data.coarse_solver) - { + { case richardson : - { - paralution::FixedPoint, paralution::LocalVector, - Number> *cs = new paralution::FixedPoint, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::FixedPoint, paralution::LocalVector, + Number> *cs = new paralution::FixedPoint, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case cg : - { - paralution::CG, paralution::LocalVector, - Number> *cs = new paralution::CG, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::CG, paralution::LocalVector, + Number> *cs = new paralution::CG, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case cr : - { - paralution::CR, paralution::LocalVector, - Number> *cs = new paralution::CR, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::CR, paralution::LocalVector, + Number> *cs = new paralution::CR, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case bicgstab : - { - paralution::BiCGStab, paralution::LocalVector, - Number> *cs = new paralution::BiCGStab, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::BiCGStab, paralution::LocalVector, + Number> *cs = new paralution::BiCGStab, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case gmres : - { - paralution::GMRES, paralution::LocalVector, - Number> *cs = new paralution::GMRES, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::GMRES, paralution::LocalVector, + Number> *cs = new paralution::GMRES, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case fgmres : - { - paralution::FGMRES, paralution::LocalVector, - Number> *cs = new paralution::FGMRES, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::FGMRES, paralution::LocalVector, + Number> *cs = new paralution::FGMRES, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown coarse solver for PreconditionAMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown coarse solver for PreconditionAMG.")); + } + } // Set the coarse solver and the verbosity of the coarse solver. coarse_solver->Verbose(additional_data.verbose); diff --git a/deal.II/source/lac/paralution_solver.cc b/deal.II/source/lac/paralution_solver.cc index aadf732b87..8c202d9ff2 100644 --- a/deal.II/source/lac/paralution_solver.cc +++ b/deal.II/source/lac/paralution_solver.cc @@ -29,7 +29,7 @@ namespace ParalutionWrappers - SolverControl& SolverBase::control() const + SolverControl &SolverBase::control() const { return solver_control; } @@ -73,7 +73,7 @@ namespace ParalutionWrappers // Let the deal.II SolverControl object know what has happened. If the solve // succeeded, the status of the solver control will turn into // SolverControl::success. solver_control only exists on the host so the solver - // needs to be on the most. + // needs to be on the most. solver->MoveToHost(); solver_control.check (solver->GetIterationCount(), solver->GetCurrentResidual()); @@ -407,71 +407,71 @@ namespace ParalutionWrappers // Set the system to solve. solver.SetOperator(A.paralution_matrix()); solver.SetOperatorFormat(CSR); - + // Set the verbosity of the multigrid. solver.Verbose(additional_data.verbose); - + // Set number of unknowns on coarsest level. solver.SetCoarsestLevel(additional_data.n_unknowns_coarse_level); // Set the interpolation type. switch (additional_data.interpolation) - { + { case aggregation : - { - solver.SetInterpolation(paralution::Aggregation); - solver.SetOverInterp(additional_data.over_interpolation); - break; - } + { + solver.SetInterpolation(paralution::Aggregation); + solver.SetOverInterp(additional_data.over_interpolation); + break; + } case smoothed_aggregation : - { - solver.SetInterpolation(paralution::SmoothedAggregation); - solver.SetInterpRelax(additional_data.relaxation_parameter); - break; - } + { + solver.SetInterpolation(paralution::SmoothedAggregation); + solver.SetInterpRelax(additional_data.relaxation_parameter); + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown interpolation type for PreconditionAMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown interpolation type for PreconditionAMG.")); + } + } // Set the coupling strength. solver.SetCouplingStrength(additional_data.coupling_strength); // Set the type of cycle switch (additional_data.cycle) - { + { case V_cycle : - { - solver.SetCycle(paralution::Vcycle); - break; - } + { + solver.SetCycle(paralution::Vcycle); + break; + } case W_cycle : - { - solver.SetCycle(paralution::Wcycle); - break; - } + { + solver.SetCycle(paralution::Wcycle); + break; + } case K_cycle : - { - solver.SetCycle(paralution::Kcycle); - break; - } + { + solver.SetCycle(paralution::Kcycle); + break; + } case F_cycle : - { - solver.SetCycle(paralution::Fcycle); - } + { + solver.SetCycle(paralution::Fcycle); + } default : - { - AssertThrow(false,ExcMessage("Unknown cycle type for PreconditionAMG.")); - } - } - + { + AssertThrow(false,ExcMessage("Unknown cycle type for PreconditionAMG.")); + } + } + // Manual smoothers solver.SetManualSmoothers(true); - + // Manual course grid solver solver.SetManualSolver(true); - + // Set grid transfer scaling solver.SetScaling(true); @@ -482,222 +482,222 @@ namespace ParalutionWrappers // Smoother for each level paralution::IterativeLinearSolver, - paralution::LocalVector,Number> **smoothers = NULL; + paralution::LocalVector,Number> **smoothers = NULL; smoothers = new paralution::IterativeLinearSolver, - paralution::LocalVector,Number>* [n_levels-1]; + paralution::LocalVector,Number>* [n_levels-1]; // Preconditioner for each smoother paralution::Preconditioner, - paralution::LocalVector,Number> **preconds = NULL; + paralution::LocalVector,Number> **preconds = NULL; preconds = new paralution::Preconditioner, - paralution::LocalVector,Number>* [n_levels-1]; + paralution::LocalVector,Number>* [n_levels-1]; // Coarse Grid Solver paralution::IterativeLinearSolver, - paralution::LocalVector,Number> *coarse_solver; + paralution::LocalVector,Number> *coarse_solver; // Smoother switch (additional_data.smoother) - { + { case richardson : - { - for (unsigned int i=0; i, - paralution::LocalVector,Number> *richardson = NULL; + paralution::LocalVector,Number> *richardson = NULL; richardson = new paralution::FixedPoint, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; smoothers[i] = richardson; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } case cg : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *cg = NULL; + Number> *cg = NULL; cg = new paralution::CG,paralution::LocalVector, - Number>; + Number>; smoothers[i] = cg; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } case cr : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *cr = NULL; + Number> *cr = NULL; cr = new paralution::CR,paralution::LocalVector, - Number>; + Number>; smoothers[i] = cr; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } case bicgstab : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *bicgstab = NULL; + Number> *bicgstab = NULL; bicgstab = new paralution::BiCGStab, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; smoothers[i] = bicgstab; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } case gmres : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *gmres = NULL; + Number> *gmres = NULL; gmres = new paralution::GMRES, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; smoothers[i] = gmres; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } case fgmres : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *fgmres = NULL; + Number> *fgmres = NULL; fgmres = new paralution::FGMRES, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; smoothers[i] = fgmres; smoothers[i]->Verbose(additional_data.verbose); } - break; - } + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown smoother for AMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown smoother for AMG.")); + } + } // Preconditioner switch (additional_data.preconditioner) - { + { case jacobi : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *jacobi = NULL; + Number> *jacobi = NULL; jacobi = new paralution::Jacobi, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; preconds[i] = jacobi; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case sgs : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *sgs = NULL; + Number> *sgs = NULL; sgs = new paralution::SGS,paralution::LocalVector, - Number>; + Number>; preconds[i] = sgs; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case multicolored_sgs : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *multicolored_sgs = NULL; + Number> *multicolored_sgs = NULL; multicolored_sgs = new paralution::MultiColoredSGS, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; multicolored_sgs->SetPrecondMatrixFormat(ELL); preconds[i] = multicolored_sgs; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case multicolored_sor : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *multicolored_sor = NULL; + Number> *multicolored_sor = NULL; multicolored_sor = new paralution::MultiColoredGS, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; multicolored_sor->SetPrecondMatrixFormat(ELL); preconds[i] = multicolored_sor; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case ilu : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *ilu = NULL; + Number> *ilu = NULL; ilu = new paralution::ILU,paralution::LocalVector, - Number>; + Number>; preconds[i] = ilu; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case ilut : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *ilut = NULL; + Number> *ilut = NULL; ilut = new paralution::ILUT, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; preconds[i] = ilut; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } case multicolored_ilu : - { - for (unsigned int i=0; i,paralution::LocalVector, - Number> *multicolored_ilu = NULL; + Number> *multicolored_ilu = NULL; multicolored_ilu = new paralution::MultiColoredILU, - paralution::LocalVector,Number>; + paralution::LocalVector,Number>; multicolored_ilu->SetPrecondMatrixFormat(ELL); preconds[i] = multicolored_ilu; smoothers[i]->SetPreconditioner(*preconds[i]); } - break; - } + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown preconditioner for the smoother for AMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown preconditioner for the smoother for AMG.")); + } + } // Set the smoothers. solver.SetSmoother(smoothers); @@ -706,60 +706,60 @@ namespace ParalutionWrappers // Coarse solver switch (additional_data.coarse_solver) - { + { case richardson : - { - paralution::FixedPoint, paralution::LocalVector, - Number> *cs = new paralution::FixedPoint, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::FixedPoint, paralution::LocalVector, + Number> *cs = new paralution::FixedPoint, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case cg : - { - paralution::CG, paralution::LocalVector, - Number> *cs = new paralution::CG, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::CG, paralution::LocalVector, + Number> *cs = new paralution::CG, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case cr : - { - paralution::CR, paralution::LocalVector, - Number> *cs = new paralution::CR, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::CR, paralution::LocalVector, + Number> *cs = new paralution::CR, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case bicgstab : - { - paralution::BiCGStab, paralution::LocalVector, - Number> *cs = new paralution::BiCGStab, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::BiCGStab, paralution::LocalVector, + Number> *cs = new paralution::BiCGStab, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case gmres : - { - paralution::GMRES, paralution::LocalVector, - Number> *cs = new paralution::GMRES, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::GMRES, paralution::LocalVector, + Number> *cs = new paralution::GMRES, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } case fgmres : - { - paralution::FGMRES, paralution::LocalVector, - Number> *cs = new paralution::FGMRES, - paralution::LocalVector, Number>; - coarse_solver = cs; - break; - } + { + paralution::FGMRES, paralution::LocalVector, + Number> *cs = new paralution::FGMRES, + paralution::LocalVector, Number>; + coarse_solver = cs; + break; + } default : - { - AssertThrow(false,ExcMessage("Unknown coarse solver for PreconditionAMG.")); - } - } + { + AssertThrow(false,ExcMessage("Unknown coarse solver for PreconditionAMG.")); + } + } solver.SetSolver(*coarse_solver); // Set absolute tolerance, relative tolerance, divergence tolerance, @@ -782,7 +782,7 @@ namespace ParalutionWrappers // Let the deal.II SolverControl object know what has happened. If the solve // succeeded, the status of the solver control will turn into // SolverControl::success. solver_control only exists on the host so the solver - // needs to be on the most. + // needs to be on the most. solver.MoveToHost(); solver_control.check (solver.GetIterationCount(), solver.GetCurrentResidual()); @@ -793,29 +793,29 @@ namespace ParalutionWrappers // Free the coarse solver, the preconditioners and the smoothers. if (coarse_solver!=NULL) - { - delete coarse_solver; - coarse_solver = NULL; - } + { + delete coarse_solver; + coarse_solver = NULL; + } if (preconds!=NULL) - { - for (unsigned int i=0; i + DEAL_II_NAMESPACE_OPEN namespace ParalutionWrappers @@ -251,7 +253,7 @@ namespace ParalutionWrappers { AssertThrow (out, ExcIO()); - // get a representation of the vector and loop over all the elements + // get a representation of the vector and loop over all the elements out.precision (precision); if (scientific) out.setf (std::ios::scientific, std::ios::floatfield); @@ -270,6 +272,13 @@ namespace ParalutionWrappers // of the vector AssertThrow (out, ExcIO()); } + + + template + void Vector::swap(Vector &v) + { + std::swap(&local_vector, &(v.paralution_vector())); + } } // Explicit instantiations -- 2.39.5