PetscSolver.cc 2.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// 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.


13
#include "AMDiS.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
14
#include "parallel/PetscSolver.h"
15
#include "parallel/StdMpi.h"
16
#include "parallel/MpiHelper.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
17
#include "parallel/ParallelDofMapping.h"
18

19
20
namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
21
22
  using namespace std;

23
  PetscSolver::PetscSolver()
24
25
26
    : meshDistributor(NULL),      
      subdomainLevel(0),
      interiorMap(NULL),
27
      mpiRank(-1),
28
      kspPrefix(""),
Thomas Witkowski's avatar
Thomas Witkowski committed
29
30
      removeRhsNullspace(false),
      hasConstantNullspace(false)
31
32
33
34
35
  {
    string kspStr = "";
    Parameters::get("parallel->solver->petsc->ksp", kspStr);
    if (kspStr != "")
      PetscOptionsInsertString(kspStr.c_str());
36

Thomas Witkowski's avatar
Thomas Witkowski committed
37
38
    Parameters::get("parallel->remove rhs null space", removeRhsNullspace);
    Parameters::get("parallel->has constant null space", hasConstantNullspace);
39
40
    Parameters::get("parallel->nullspace->const in comp", 
		    constNullspaceComponent);
41
42
43
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
44
  void PetscSolver::setCoarseSpaceDofMapping(ParallelDofMapping *coarseDofs, 
Thomas Witkowski's avatar
Thomas Witkowski committed
45
					     int component)
46
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
47
48
49
50
51
52
53
54
55
56
57
58
59
    FUNCNAME("PetscSolver::setCoarseSpaceDofMapping()");

    TEST_EXIT_DBG(coarseDofs)("Should not happen!\n");

    if (component == -1) {
      coarseSpaceMap.clear();

      int nComponents = coarseDofs->getNumberOfComponents();
      for (int i = 0; i < nComponents; i++)
	coarseSpaceMap[i] = coarseDofs;
    } else {
      coarseSpaceMap[component] = coarseDofs;
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
  }

62
63
64
65

  void PetscSolver::solve(Vec &rhs, Vec &sol)
  {
    FUNCNAME("PetscSolver::solve()");
66

67
68
69
70
    PetscErrorCode solverError = KSPSolve(kspInterior, rhs, sol);
    if (solverError != 0) {
      AMDiS::finalize();
      exit(-1);
71
72
73
    }
  }

74

75
76
77
78
79
80
81
82
  void PetscSolver::solveGlobal(Vec &rhs, Vec &sol)
  {
    FUNCNAME("PetscSolver::solveGlobal()");

    ERROR_EXIT("Not implemented!\n");
  }


83
84
85
86
87
88
  void PetscSolver::copyVec(Vec& originVec, Vec& destVec, 
			    vector<int>& originIndex, vector<int>& destIndex)
  {
    FUNCNAME("PetscSolver::copyVec()");

    IS originIs, destIs;
89
    ISCreateGeneral(mpiCommGlobal, 
90
91
92
93
94
		    originIndex.size(), 
		    &(originIndex[0]),
		    PETSC_USE_POINTER,
		    &originIs);

95
    ISCreateGeneral(mpiCommGlobal, 
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		    destIndex.size(), 
		    &(destIndex[0]),
		    PETSC_USE_POINTER,
		    &destIs);

    VecScatter scatter;
    VecScatterCreate(originVec, originIs, destVec, destIs, &scatter);
    VecScatterBegin(scatter, originVec, destVec,
		    INSERT_VALUES, SCATTER_FORWARD);
    VecScatterEnd(scatter, originVec, destVec,
		  INSERT_VALUES, SCATTER_FORWARD);

    ISDestroy(&originIs);
    ISDestroy(&destIs);    
    VecScatterDestroy(&scatter);
  }

113
}