PetscProblemStat.cc 2.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


#include <vector>
#include <set>

16
#include "io/VtkWriter.h"
17 18
#include "parallel/PetscProblemStat.h"
#include "parallel/PetscSolver.h"
19
#include "parallel/MpiHelper.h"
20
#include "parallel/BddcMlSolver.h"
21 22 23 24 25 26

namespace AMDiS {

  using namespace std;


27 28
  PetscProblemStat::PetscProblemStat(string nameStr,
				     ProblemIterationInterface *problemIteration)
29 30
    : ParallelProblemStatBase(nameStr, problemIteration),
      deleteSolver(true)
31 32 33
  {
    FUNCNAME("PetscProblemStat::PetscProblemStat()");

34 35
    string tmp("");
    Parameters::get("parallel->solver", tmp);
36
    
37
    if (tmp == "petsc-schur") {
38
      petscSolver = new PetscSolverSchur();
39
    } else if (tmp == "petsc-feti") {
40
      petscSolver = new PetscSolverFeti();
41
    } else if (tmp == "petsc-block") {
42
      petscSolver = new PetscSolverGlobalBlockMatrix();
43
    } else if (tmp == "petsc" || tmp == "") {
44
      petscSolver = new PetscSolverGlobalMatrix();
45
    } else if (tmp == "bddcml") {
46 47 48 49 50
#ifdef HAVE_BDDC_ML
      petscSolver = new BddcMlSolver();
#else
      ERROR_EXIT("AMDiS was compiled without BDDC-ML support!\n");
#endif
51
    } else {
52
      ERROR_EXIT("No parallel solver %s available!\n", tmp.c_str());
53
    }
54 55 56 57

    tmp = "";
    Parameters::get(nameStr + "->solver->petsc prefix", tmp);
    petscSolver->setKspPrefix(tmp);    
58 59 60
  }


61 62 63 64 65 66 67 68
  PetscProblemStat::PetscProblemStat(string nameStr,
				     PetscSolver *solver)
    : ParallelProblemStatBase(nameStr, NULL),
      petscSolver(solver),
      deleteSolver(false)
  {}


69 70 71 72 73 74 75 76 77 78
  void PetscProblemStat::initialize(Flag initFlag, 
				    ProblemStatSeq* adoptProblem,
				    Flag adoptFlag)
  {
      ParallelProblemStatBase::initialize(initFlag, adoptProblem, adoptFlag);

      meshDistributor->setBoundaryDofRequirement(petscSolver->getBoundaryDofRequirement());
  }


79 80 81
  void PetscProblemStat::solve(AdaptInfo *adaptInfo,
			       bool createMatrixData,
			       bool storeMatrixData)
82 83 84 85 86 87 88
  {
    FUNCNAME("PetscProblemStat::solve()");

    TEST_EXIT(meshDistributor)("Should not happen!\n");

    double wtime = MPI::Wtime();

89
    if (createMatrixData) {
90 91 92 93
      petscSolver->setMeshDistributor(meshDistributor, 
				      meshDistributor->getMpiComm(),
				      PETSC_COMM_SELF);
      petscSolver->setDofMapping(&(meshDistributor->getDofMap()));
94 95 96 97 98
      petscSolver->fillPetscMatrix(systemMatrix);
    }

    petscSolver->fillPetscRhs(rhs);

99
    petscSolver->solvePetscMatrix(*solution, adaptInfo);   
100

101 102
    petscSolver->destroyVectorData();

103 104 105
    if (!storeMatrixData)
      petscSolver->destroyMatrixData();

106 107 108 109 110
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  MPI::Wtime() - wtime);
  }

}