HypreSolver.h 2.81 KB
 Praetorius, Simon committed Aug 02, 2013 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 /****************************************************************************** * * AMDiS - Adaptive multidimensional simulations * * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved. * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis * * Authors: * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * This file is part of AMDiS * * See also license.opensource.txt in the distribution. * ******************************************************************************/ /** \file HypreSolver.h */ #ifndef AMDIS_HYPRE_SOLVER_H #define AMDIS_HYPRE_SOLVER_H #ifdef MTL_HAS_HYPRE #include "solver/MTL4Solver.h" #include "solver/ITL_Preconditioner.h" #include "MTL4Types.h" #include "solver/itl/hypre.hpp" #include #include namespace AMDiS {  Praetorius, Simon committed Oct 23, 2013 40  struct Hypre_Runner : public MTL4Runner< MTLTypes::MTLMatrix, MTLTypes::MTLVector >  Praetorius, Simon committed Aug 02, 2013 41 42 43 44 45 46 47  { typedef MTLTypes::MTLMatrix MatrixType; typedef MTLTypes::MTLVector VectorType; typedef MTL4Runner< MatrixType, VectorType > super; Hypre_Runner(LinearSolver* oemPtr) : oem(*oemPtr),  Praetorius, Simon committed Oct 23, 2013 48  solver(nullptr)  Praetorius, Simon committed Aug 02, 2013 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64  { int cycleMode = 1, interpolation = 0; Parameters::get(oem.getName() + "->cycle mode", cycleMode); Parameters::get(oem.getName() + "->interpolation type", interpolation); config.maxIter(oem.getMaxIterations()); config.interpolation(interpolation); config.cycle(cycleMode); config.tolerance(oem.getTolerance()); config.printLevel(oem.getInfo()); } ~Hypre_Runner() { if (solver) { delete solver;  Praetorius, Simon committed Oct 23, 2013 65  solver = nullptr;  Praetorius, Simon committed Aug 02, 2013 66 67 68  } }  Praetorius, Simon committed Oct 23, 2013 69 70  /// Implementation of \ref MTL4Runner::init() void init(const typename super::BlockMatrix& A, const MatrixType& fullMatrix) override  Praetorius, Simon committed Aug 02, 2013 71 72 73 74  { solver = new mtl::HypreSolverWrapper(fullMatrix); }  Praetorius, Simon committed Oct 23, 2013 75 76  /// Implementation of \ref MTL4Runner::solve() int solve(const MatrixType& A , VectorType& x, const VectorType& b) override  Praetorius, Simon committed Aug 02, 2013 77 78 79 80 81  { int error = (*solver)(x, b, config); return error; }  Praetorius, Simon committed Oct 23, 2013 82 83  /// Implementation of \ref OEMRunner::exit() void exit()  Praetorius, Simon committed Aug 02, 2013 84 85 86  { if (solver) { delete solver;  Praetorius, Simon committed Oct 23, 2013 87  solver = nullptr;  Praetorius, Simon committed Aug 02, 2013 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110  } } protected: LinearSolver& oem; mtl::HypreSolverWrapper *solver; mtl::AMGConfigurator config; }; /** * \ingroup Solver * \class AMDiS::HypreSolver * \brief * Wrapper for the external HYPRE-AMG solver */ typedef MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, Hypre_Runner > HypreSolver; } // namespace AMDiS #endif // MTL_HAS_HYPRE #endif // AMDIS_HYPRE_SOLVER_H