/****************************************************************************** * * Extension of 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 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. * * * See also license.opensource.txt in the distribution. * ******************************************************************************/ #ifndef BLOCK_PRECONDITIONER_H #define BLOCK_PRECONDITIONER_H #include "solver/ITL_Preconditioner.h" #include "solver/SolverMatrix.h" namespace AMDiS { struct BlockPreconditioner : BasePreconditioner { typedef SolverMatrix > BlockMatrix; BlockPreconditioner() : A(NULL), fullMatrix(NULL) {} virtual ~BlockPreconditioner() {} /// extract iranges from BlockMatrix to be used to extract sub-vectors and sub-matrices. void init(const BlockMatrix& A_, const MTLTypes::MTLMatrix& fullMatrix_) { A = &A_; fullMatrix = &fullMatrix_; VectorialMapper mapper(A_); rows.resize(mapper.getNumComponents()); int start = 0; for (int i = 0; i < mapper.getNumComponents(); i++) { mapper.setRow(i+1); int finish = mapper.row(0); rows[i].set(start, finish); start = finish; } } virtual void solve(const MTLTypes::MTLVector& b, MTLTypes::MTLVector& x) const { FUNCNAME("BlockPreconditioner::solve()"); TEST_EXIT(false)("Noch nicht implementiert!\n"); } virtual void adjoint_solve(const MTLTypes::MTLVector& x, MTLTypes::MTLVector& y) const { FUNCNAME("BlockPreconditioner::adjoint_solve()"); TEST_EXIT(false)("Noch nicht implementiert!\n"); } protected: template void createSubSolver(std::string param, SolverType*& solver, RunnerType*& runner, std::string solverType = "0") { // definition of standard-backends #if defined HAVE_PARALLEL_PETSC string backend("p_petsc"); #elif defined HAVE_PARALLEL_MTL string backend("p_mtl"); #elif defined HAVE_PETSC string backend("petsc"); #else string backend("mtl"); #endif // === read backend-name === string initFileStr = param + "->solver"; Parameters::get(initFileStr + "->backend", backend); // === read solver-name === Parameters::get(initFileStr, solverType); if (backend != "0" && backend != "no" && backend != "") solverType = backend + "_" + solverType; LinearSolverCreator *solverCreator = dynamic_cast(CreatorMap::getCreator(solverType, initFileStr)); TEST_EXIT(solverCreator) ("No valid solver type found in parameter \"%s\"\n", initFileStr.c_str()); solverCreator->setName(initFileStr); solver = dynamic_cast(solverCreator->create()); assert(solver != NULL); runner = dynamic_cast(solver->getRunner()); assert(runner != NULL); } const SolverMatrix >* A; const MTLTypes::MTLMatrix* fullMatrix; std::vector rows; }; } // end namespace #endif // BLOCK_PRECONDITIONER_H