PetscProblemStat.cc 3.11 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
#include "parallel/PetscSolverNavierStokes.h"
22
23
24
25
26
27

namespace AMDiS {

  using namespace std;


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

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

    tmp = "";
    Parameters::get(nameStr + "->solver->petsc prefix", tmp);
    petscSolver->setKspPrefix(tmp);    
62
63
64
  }


65
66
67
68
69
70
71
72
  PetscProblemStat::PetscProblemStat(string nameStr,
				     PetscSolver *solver)
    : ParallelProblemStatBase(nameStr, NULL),
      petscSolver(solver),
      deleteSolver(false)
  {}


73
74
75
76
  void PetscProblemStat::initialize(Flag initFlag, 
				    ProblemStatSeq* adoptProblem,
				    Flag adoptFlag)
  {
77
78
79
    ParallelProblemStatBase::initialize(initFlag, adoptProblem, adoptFlag);
    
    meshDistributor->setBoundaryDofRequirement(petscSolver->getBoundaryDofRequirement());
80

81
82
83
84
    petscSolver->setMeshDistributor(meshDistributor, 
				    meshDistributor->getMpiComm(),
				    PETSC_COMM_SELF);   
    petscSolver->init(this->getComponentSpaces(), this->getFeSpaces());
85
86
87
  }


88
89
90
  void PetscProblemStat::solve(AdaptInfo *adaptInfo,
			       bool createMatrixData,
			       bool storeMatrixData)
91
92
93
94
95
96
97
  {
    FUNCNAME("PetscProblemStat::solve()");

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

    double wtime = MPI::Wtime();

98
    if (createMatrixData)
99
100
101
102
      petscSolver->fillPetscMatrix(systemMatrix);

    petscSolver->fillPetscRhs(rhs);

Thomas Witkowski's avatar
Thomas Witkowski committed
103
104
105
    INFO(info, 8)("creation of parallel data structures needed %.5f seconds\n", 
		  MPI::Wtime() - wtime);
    wtime = MPI::Wtime();
106

107
    petscSolver->solvePetscMatrix(*solution, adaptInfo);   
108

Thomas Witkowski's avatar
Thomas Witkowski committed
109
110
111
    INFO(info, 8)("solution of discrete system needed %.5f seconds\n", 
		  MPI::Wtime() - wtime);

112
113
    petscSolver->destroyVectorData();

114
115
    if (!storeMatrixData)
      petscSolver->destroyMatrixData();
116
117
118
  }

}