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

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


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


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

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


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

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

    double wtime = MPI::Wtime();

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

    petscSolver->fillPetscRhs(rhs);

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

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

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

111
112
    petscSolver->destroyVectorData();

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

}