PetscProblemStat.cc 3.52 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  void PetscProblemStat::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
					   bool assembleMatrix,
					   bool assembleVector)
  {
    FUNCNAME("ParallelProblemStatBase::buildAfterCoarsen()");

    TEST_EXIT_DBG(MeshDistributor::globalMeshDistributor != NULL)
      ("Should not happen!\n");

    MeshDistributor::globalMeshDistributor->checkMeshChange();
    MeshDistributor::globalMeshDistributor->setRankDofs(this, 
							petscSolver->getInteriorMap());
    ProblemStatSeq::buildAfterCoarsen(adaptInfo, flag, 
				      assembleMatrix, 
				      assembleVector);
  }


97
98
99
  void PetscProblemStat::solve(AdaptInfo *adaptInfo,
			       bool createMatrixData,
			       bool storeMatrixData)
100
101
102
103
104
105
106
  {
    FUNCNAME("PetscProblemStat::solve()");

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

    double wtime = MPI::Wtime();

107
    if (createMatrixData) {
108
109
110
111
      petscSolver->setMeshDistributor(meshDistributor, 
				      meshDistributor->getMpiComm(),
				      PETSC_COMM_SELF);
      petscSolver->setDofMapping(&(meshDistributor->getDofMap()));
112
113
114
115
116
      petscSolver->fillPetscMatrix(systemMatrix);
    }

    petscSolver->fillPetscRhs(rhs);

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

121
    petscSolver->solvePetscMatrix(*solution, adaptInfo);   
122

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

126
127
    petscSolver->destroyVectorData();

128
129
    if (!storeMatrixData)
      petscSolver->destroyMatrixData();
130
131
132
  }

}