PetscSolverSchur.cc 15 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
Thomas Witkowski's avatar
Thomas Witkowski committed
20
21
22
23
24
25


#include "parallel/PetscSolverSchur.h"
#include "parallel/StdMpi.h"
#include "parallel/MpiHelper.h"

26
namespace AMDiS { namespace Parallel {
Thomas Witkowski's avatar
Thomas Witkowski committed
27
28
29
30
31
32
33
34

  using namespace std;

  void PetscSolverSchur::updateDofData(int nComponents)
  {
    FUNCNAME("PetscSolverSchur::updateDofData()");

    TEST_EXIT_DBG(meshDistributor)("No mesh distributor object defined!\n");
35
    TEST_EXIT_DBG(interiorMap)("No parallel DOF map defined!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
36

37
    const FiniteElemSpace *feSpace = componentSpaces[0];
38
    Mesh* mesh = feSpace->getMesh();
39
40
//     typedef map<int, DofContainer> RankToDofContainer;
#if 0
Thomas Witkowski's avatar
Thomas Witkowski committed
41
    typedef map<DegreeOfFreedom, bool> DofIndexToBool;
42
#endif
Thomas Witkowski's avatar
Thomas Witkowski committed
43
44
45

    boundaryDofs.clear();
    std::set<DegreeOfFreedom> boundaryLocalDofs;
46
    for (DofComm::Iterator it(meshDistributor->getDofComm(mesh, 0).getSendDofs(), feSpace);
47
48
	 !it.end(); it.nextRank())
      for (; !it.endDofIter(); it.nextDof()) {
49
	boundaryLocalDofs.insert(it.getDofIndex());
50
	boundaryDofs.insert((*interiorMap)[feSpace][it.getDofIndex()].global);
Thomas Witkowski's avatar
Thomas Witkowski committed
51
      }
52

53

Thomas Witkowski's avatar
Thomas Witkowski committed
54
    nBoundaryDofs = boundaryDofs.size();
55
    mpi::getDofNumbering(domainComm, nBoundaryDofs,
Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
			 rStartBoundaryDofs, nOverallBoundaryDofs);

58

59
    DofContainerSet& edgeDofs =
60
      meshDistributor->getBoundaryDofInfo(feSpace, 0).geoDofs[EDGE];
61
    DofContainerSet& vertexDofs =
62
      meshDistributor->getBoundaryDofInfo(feSpace, 0).geoDofs[VERTEX];
63
64
65
66
67
68
69
    int nEdgeDofs = edgeDofs.size();
    int nVertexDofs = vertexDofs.size();

    TEST_EXIT_DBG(nEdgeDofs + nVertexDofs == nBoundaryDofs)
      ("Should not happen!\n");

    int rStartEdgeDofs, nOverallEdgeDofs;
70
    mpi::getDofNumbering(domainComm, nEdgeDofs,
71
72
73
			 rStartEdgeDofs, nOverallEdgeDofs);

    int rStartVertexDofs, nOverallVertexDofs;
74
    mpi::getDofNumbering(domainComm, nVertexDofs,
75
76
77
78
			 rStartVertexDofs, nOverallVertexDofs);

    TEST_EXIT_DBG(nOverallEdgeDofs + nOverallVertexDofs == nOverallBoundaryDofs)
      ("Should not happen!\n");
79

80

Thomas Witkowski's avatar
Thomas Witkowski committed
81
    mapGlobalBoundaryDof.clear();
82
83
84
85
86
#if 1
    {
      int counter = rStartEdgeDofs;
      for (DofContainerSet::iterator it = edgeDofs.begin();
	   it != edgeDofs.end(); ++it)
87
	mapGlobalBoundaryDof[(*interiorMap)[feSpace][**it].global] =
88
89
90
91
92
93
	  counter++;
    }
    {
      int counter = nOverallEdgeDofs + rStartVertexDofs;
      for (DofContainerSet::iterator it = vertexDofs.begin();
	   it != vertexDofs.end(); ++it)
94
	mapGlobalBoundaryDof[(*interiorMap)[feSpace][**it].global] =
95
96
97
98
99
	  counter++;
    }
#else
 {
    int counter = rStartBoundaryDofs;
Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
102
    for (std::set<DegreeOfFreedom>::iterator it = boundaryDofs.begin();
	 it != boundaryDofs.end(); ++it)
      mapGlobalBoundaryDof[*it] = counter++;
103
104
 }
#endif
Thomas Witkowski's avatar
Thomas Witkowski committed
105
106
107


    std::set<DegreeOfFreedom> otherBoundaryLocalDofs;
108
    for (DofComm::Iterator it(meshDistributor->getDofComm(mesh, 0).getRecvDofs(), feSpace);
109
110
111
	 !it.end(); it.nextRank())
      for (; !it.endDofIter(); it.nextDof())
	otherBoundaryLocalDofs.insert(it.getDofIndex());
112

Thomas Witkowski's avatar
Thomas Witkowski committed
113
    interiorDofs.clear();
Thomas Witkowski's avatar
Thomas Witkowski committed
114
115
116

    ERROR_EXIT("Rewrite the following code block!\n");
#if 0
117
    DofIndexToBool& isRankDof = meshDistributor->getIsRankDof(feSpace);
118
    for (DofIndexToBool::iterator dofIt = isRankDof.begin();
Thomas Witkowski's avatar
Thomas Witkowski committed
119
	 dofIt != isRankDof.end(); ++dofIt) {
120
121
      if (dofIt->second &&
	  boundaryLocalDofs.count(dofIt->first) == 0 &&
Thomas Witkowski's avatar
Thomas Witkowski committed
122
	  otherBoundaryLocalDofs.count(dofIt->first) == 0)
123
	interiorDofs.insert(meshDistributor->mapDofToGlobal(feSpace, dofIt->first));
Thomas Witkowski's avatar
Thomas Witkowski committed
124
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
125
#endif
126

Thomas Witkowski's avatar
Thomas Witkowski committed
127
    nInteriorDofs = interiorDofs.size();
128
    mpi::getDofNumbering(domainComm, nInteriorDofs,
Thomas Witkowski's avatar
Thomas Witkowski committed
129
130
			 rStartInteriorDofs, nOverallInteriorDofs);

131
132
133
134
135
136
137
    {
      int counter = rStartInteriorDofs;
      mapGlobalInteriorDof.clear();
      for (std::set<DegreeOfFreedom>::iterator it = interiorDofs.begin();
	   it != interiorDofs.end(); ++it)
	mapGlobalInteriorDof[*it] = counter++;
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
138
139
140
141
142


    TEST_EXIT_DBG(nInteriorDofs > 0)("Should not happen!\n");


143
    StdMpi<vector<DegreeOfFreedom> > stdMpi(domainComm);
144
    for (DofComm::Iterator it(meshDistributor->getDofComm(mesh, 0).getSendDofs(), feSpace);
145
146
147
148
149
	 !it.end(); it.nextRank()) {
      stdMpi.getSendData(it.getRank()).resize(0);
      stdMpi.getSendData(it.getRank()).reserve(it.getDofs().size());

      for (; !it.endDofIter(); it.nextDof()) {
150
	int globalSendDof = (*interiorMap)[feSpace][it.getDofIndex()].global;
Thomas Witkowski's avatar
Thomas Witkowski committed
151
152
153
154

	TEST_EXIT_DBG(mapGlobalBoundaryDof.count(globalSendDof))
	  ("No mapping for boundary DOF %d!\n", globalSendDof);

155
	stdMpi.getSendData(it.getRank()).push_back(mapGlobalBoundaryDof[globalSendDof]);
Thomas Witkowski's avatar
Thomas Witkowski committed
156
      }
157
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
158
159

    stdMpi.updateSendDataSize();
160

161
    for (DofComm::Iterator it(meshDistributor->getDofComm(mesh, 0).getRecvDofs(), feSpace);
162
163
	 !it.end(); it.nextRank())
      stdMpi.recv(it.getRank());
Thomas Witkowski's avatar
Thomas Witkowski committed
164

165
    stdMpi.startCommunication();
166

167
    for (DofComm::Iterator it(meshDistributor->getDofComm(mesh, 0).getRecvDofs(), feSpace);
168
169
	 !it.end(); it.nextRank())
      for (; !it.endDofIter(); it.nextDof()) {
170
	int globalRecvDof = (*interiorMap)[feSpace][it.getDofIndex()].global;
171
	mapGlobalBoundaryDof[globalRecvDof] =
172
	  stdMpi.getRecvData(it.getRank())[it.getDofCounter()];
Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
175
176
177
178
	boundaryDofs.insert(globalRecvDof);
      }


    // === Create PETSc IS structurs for interior and boundary DOFs. ===

179
    ISCreateStride(domainComm,
Thomas Witkowski's avatar
Thomas Witkowski committed
180
		   nInteriorDofs * nComponents,
181
		   (rStartInteriorDofs + rStartBoundaryDofs) * nComponents,
Thomas Witkowski's avatar
Thomas Witkowski committed
182
183
		   1, &interiorIs);

184
    ISCreateStride(domainComm,
Thomas Witkowski's avatar
Thomas Witkowski committed
185
		   nBoundaryDofs * nComponents,
186
		   (rStartInteriorDofs + rStartBoundaryDofs + nInteriorDofs) * nComponents,
Thomas Witkowski's avatar
Thomas Witkowski committed
187
188
189
190
		   1, &boundaryIs);
  }


Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
191
  void PetscSolverSchur::fillPetscMatrix(Matrix<DOFMatrix*> *seqMat)
Thomas Witkowski's avatar
Thomas Witkowski committed
192
  {
193
//     FUNCNAME("PetscSolverSchur::fillPetscMatrix()");
194

195
    createMatVec(*seqMat);
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
196

197
    const FiniteElemSpace *feSpace = componentSpaces[0];
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
198
    int nComponents = seqMat->getNumRows();
Thomas Witkowski's avatar
Thomas Witkowski committed
199
200
201
202
203
204
205
206
    updateDofData(nComponents);

    int nInteriorRows = nInteriorDofs * nComponents;
    int nOverallInteriorRows = nOverallInteriorDofs * nComponents;
    int nBoundaryRows = nBoundaryDofs * nComponents;
    int nOverallBoundaryRows = nOverallBoundaryDofs * nComponents;


207
208
    MatCreateAIJ(domainComm,
		 nInteriorRows, nInteriorRows,
209
210
211
		 nOverallInteriorRows, nOverallInteriorRows,
		 100, PETSC_NULL, 100, PETSC_NULL, &matA11);

212
213
    MatCreateAIJ(domainComm,
		 nBoundaryRows, nBoundaryRows,
214
215
216
		 nOverallBoundaryRows, nOverallBoundaryRows,
		 100, PETSC_NULL, 100, PETSC_NULL, &matA22);

217
218
    MatCreateAIJ(domainComm,
		 nInteriorRows, nBoundaryRows,
219
		 nOverallInteriorRows, nOverallBoundaryRows,
220
		 100, PETSC_NULL, 100, PETSC_NULL, &matA12);
221

222
223
    MatCreateAIJ(domainComm,
		 nBoundaryRows, nInteriorRows,
224
225
		 nOverallBoundaryRows, nOverallInteriorRows,
		 100, PETSC_NULL, 100, PETSC_NULL, &matA21);
Thomas Witkowski's avatar
Thomas Witkowski committed
226
227
228
229


    for (int i = 0; i < nComponents; i++)
      for (int j = 0; j < nComponents; j++)
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
230
231
	if ((*seqMat)[i][j])
	  setDofMatrix((*seqMat)[i][j], nComponents, i, j);
Thomas Witkowski's avatar
Thomas Witkowski committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

    MatAssemblyBegin(matA11, MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(matA11, MAT_FINAL_ASSEMBLY);

    MatAssemblyBegin(matA12, MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(matA12, MAT_FINAL_ASSEMBLY);

    MatAssemblyBegin(matA21, MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(matA21, MAT_FINAL_ASSEMBLY);

    MatAssemblyBegin(matA22, MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(matA22, MAT_FINAL_ASSEMBLY);

    Mat tmpMat[2][2];
    tmpMat[0][0] = matA11;
    tmpMat[0][1] = matA12;
    tmpMat[1][0] = matA21;
    tmpMat[1][1] = matA22;

    IS tmpIS[2];
    tmpIS[0] = interiorIs;
    tmpIS[1] = boundaryIs;

255
    MatCreateNest(domainComm, 2, &tmpIS[0], 2, &tmpIS[0], &tmpMat[0][0],
256
257
		  &getMatInterior());
    MatNestSetVecType(getMatInterior(), VECNEST);
Thomas Witkowski's avatar
Thomas Witkowski committed
258

259
    matAssembly();
Thomas Witkowski's avatar
Thomas Witkowski committed
260

261
262
    int nRankRows = (*interiorMap)[feSpace].nRankDofs * nComponents;
    int nOverallRows = (*interiorMap)[feSpace].nOverallDofs * nComponents;
Thomas Witkowski's avatar
Thomas Witkowski committed
263

264
    VecCreateMPI(domainComm, nRankRows, nOverallRows, &petscSolVec);
265
266
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
267

268
269
  void PetscSolverSchur::fillPetscRhs(SystemVector *vec)
  {
270
//     FUNCNAME("PetscSolverSchur::fillPetscRhs()");
Thomas Witkowski's avatar
Thomas Witkowski committed
271

272
    const FiniteElemSpace *feSpace = componentSpaces[0];
273
    int nComponents = vec->getSize();
274
275
    int nRankRows = (*interiorMap)[feSpace].nRankDofs * nComponents;
    int nOverallRows = (*interiorMap)[feSpace].nOverallDofs * nComponents;
Thomas Witkowski's avatar
Thomas Witkowski committed
276

277
    VecCreateMPI(domainComm, nRankRows, nOverallRows, &(getVecRhsInterior()));
Thomas Witkowski's avatar
Thomas Witkowski committed
278
279

    for (int i = 0; i < nComponents; i++)
280
      setDofVector(getVecRhsInterior(), vec->getDOFVector(i), nComponents, i);
Thomas Witkowski's avatar
Thomas Witkowski committed
281

282
    vecRhsAssembly();
Thomas Witkowski's avatar
Thomas Witkowski committed
283
284
285
  }


286
  void PetscSolverSchur::solvePetscMatrix(SystemVector &vec,
287
					  AdaptInfo *adaptInfo)
Thomas Witkowski's avatar
Thomas Witkowski committed
288
  {
289
//     FUNCNAME("PetscSolverSchur::solvePetscMatrix()");
Thomas Witkowski's avatar
Thomas Witkowski committed
290

291
    const FiniteElemSpace *feSpace = componentSpaces[0];
Thomas Witkowski's avatar
Thomas Witkowski committed
292
293
    int nComponents = vec.getSize();

294
    KSPCreate(domainComm, &kspInterior);
Thomas Witkowski's avatar
Thomas Witkowski committed
295

296
    petsc::ksp_set_operators(kspInterior, getMatInterior(), getMatInterior());
297
298
    KSPSetTolerances(kspInterior, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
    KSPSetFromOptions(kspInterior);
Thomas Witkowski's avatar
Thomas Witkowski committed
299

300
301
302
303
304
    KSPGetPC(kspInterior, &pcInterior);
    PCSetType(pcInterior, PCFIELDSPLIT);
    PCFieldSplitSetIS(pcInterior, "interior", interiorIs);
    PCFieldSplitSetIS(pcInterior, "boundary", boundaryIs);
    PCSetFromOptions(pcInterior);
Thomas Witkowski's avatar
Thomas Witkowski committed
305
306


307
    KSPSolve(kspInterior, getVecRhsInterior(), petscSolVec);
Thomas Witkowski's avatar
Thomas Witkowski committed
308
309
310
311
312
313
314
315
316

    // === Transfere values from PETSc's solution vectors to AMDiS vectors. ===

    PetscScalar *vecPointer;
    VecGetArray(petscSolVec, &vecPointer);

    for (int i = 0; i < nComponents; i++) {
      DOFVector<double>::Iterator dofIt(vec.getDOFVector(i), USED_DOFS);
      for (dofIt.reset(); !dofIt.end(); ++dofIt) {
317
	DegreeOfFreedom globalRowDof = (*interiorMap)[feSpace][dofIt.getDOFIndex()].global;
Thomas Witkowski's avatar
Thomas Witkowski committed
318
319
320
321
322
	if (boundaryDofs.count(globalRowDof)) {
	  int index =
	    (mapGlobalBoundaryDof[globalRowDof] - rStartBoundaryDofs + nInteriorDofs) * (i + 1);
	  *dofIt = vecPointer[index];
	} else {
323
	  int index =
Thomas Witkowski's avatar
Thomas Witkowski committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
	    (mapGlobalInteriorDof[globalRowDof] - rStartInteriorDofs) * (i + 1);
	  *dofIt = vecPointer[index];
	}
      }
    }

    VecRestoreArray(petscSolVec, &vecPointer);


    // === Synchronize DOFs at common DOFs, i.e., DOFs that correspond to ===
    // === more than one partition.                                       ===
    meshDistributor->synchVector(vec);


    // === Destroy PETSC's variables. ===

340
341
342
343
    MatDestroy(&matA11);
    MatDestroy(&matA12);
    MatDestroy(&matA21);
    MatDestroy(&matA22);
344

345
346
    matDestroy();
    vecDestroy();
Thomas Witkowski's avatar
Thomas Witkowski committed
347

348
    KSPDestroy(&kspInterior);
Thomas Witkowski's avatar
Thomas Witkowski committed
349
350
  }

351
352

  void PetscSolverSchur::setDofMatrix(DOFMatrix* seqMat, int dispMult,
Thomas Witkowski's avatar
Thomas Witkowski committed
353
354
355
356
				      int dispAddRow, int dispAddCol)
  {
    FUNCNAME("PetscSolverSchur::setDofMatrix()");

Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
357
    TEST_EXIT(seqMat)("No DOFMatrix!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
358

359
    const FiniteElemSpace* feSpace = componentSpaces[0];
Thomas Witkowski's avatar
Thomas Witkowski committed
360
361
362
363
    using mtl::tag::row; using mtl::tag::nz; using mtl::begin; using mtl::end;
    namespace traits= mtl::traits;
    typedef DOFMatrix::base_matrix_type Matrix;

Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
364
365
    traits::col<Matrix>::type col(seqMat->getBaseMatrix());
    traits::const_value<Matrix>::type value(seqMat->getBaseMatrix());
Thomas Witkowski's avatar
Thomas Witkowski committed
366
367
368
369
370
371
372
373
374
375
376

    typedef traits::range_generator<row, Matrix>::type cursor_type;
    typedef traits::range_generator<nz, cursor_type>::type icursor_type;

    vector<int> colsBoundary, colsInterior;
    vector<double> valuesBoundary, valuesInterior;
    colsBoundary.reserve(300);
    colsInterior.reserve(300);
    valuesBoundary.reserve(300);
    valuesInterior.reserve(300);

377
    for (cursor_type cursor = begin<row>(seqMat->getBaseMatrix()),
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
378
	   cend = end<row>(seqMat->getBaseMatrix()); cursor != cend; ++cursor) {
Thomas Witkowski's avatar
Thomas Witkowski committed
379
380

      // Global index of the current row DOF.
381
      int globalRowDof = (*interiorMap)[feSpace][cursor.value()].global;
382

Thomas Witkowski's avatar
Thomas Witkowski committed
383
384
385
386
      colsBoundary.clear();
      colsInterior.clear();
      valuesBoundary.clear();
      valuesInterior.clear();
387
388

      for (icursor_type icursor = begin<nz>(cursor), icend = end<nz>(cursor);
Thomas Witkowski's avatar
Thomas Witkowski committed
389
	   icursor != icend; ++icursor) {
390
	int globalColDof = (*interiorMap)[feSpace][col(*icursor)].global;
Thomas Witkowski's avatar
Thomas Witkowski committed
391
392
393
394
395

	if (boundaryDofs.count(globalColDof)) {
	  TEST_EXIT_DBG(mapGlobalBoundaryDof.count(globalColDof))
	    ("Should not happen!\n");

396
	  int colIndex =
Thomas Witkowski's avatar
Thomas Witkowski committed
397
	    mapGlobalBoundaryDof[globalColDof] * dispMult + dispAddCol;
398

Thomas Witkowski's avatar
Thomas Witkowski committed
399
400
401
402
	  colsBoundary.push_back(colIndex);
	  valuesBoundary.push_back(value(*icursor));
	} else {
	  TEST_EXIT_DBG(mapGlobalInteriorDof.count(globalColDof))
403
	    ("Cannot find global interior mapping for global column DOF %d!\n",
Thomas Witkowski's avatar
Thomas Witkowski committed
404
405
	     globalColDof);

406
	  int colIndex =
Thomas Witkowski's avatar
Thomas Witkowski committed
407
408
409
410
411
412
413
414
415
416
417
	    mapGlobalInteriorDof[globalColDof] * dispMult + dispAddCol;

	  colsInterior.push_back(colIndex);
	  valuesInterior.push_back(value(*icursor));
	}
      }

      if (boundaryDofs.count(globalRowDof)) {
	TEST_EXIT_DBG(mapGlobalBoundaryDof.count(globalRowDof))
	  ("Should not happen!\n");

418
	int rowIndex =
Thomas Witkowski's avatar
Thomas Witkowski committed
419
420
	  mapGlobalBoundaryDof[globalRowDof] * dispMult + dispAddRow;

421
 	MatSetValues(matA22, 1, &rowIndex, colsBoundary.size(),
Thomas Witkowski's avatar
Thomas Witkowski committed
422
 		     &(colsBoundary[0]), &(valuesBoundary[0]), ADD_VALUES);
423
 	MatSetValues(matA21, 1, &rowIndex, colsInterior.size(),
Thomas Witkowski's avatar
Thomas Witkowski committed
424
425
426
 		     &(colsInterior[0]), &(valuesInterior[0]), ADD_VALUES);
      } else {
	TEST_EXIT_DBG(mapGlobalInteriorDof.count(globalRowDof))
427
	  ("Cannot find global interior mapping for global row DOF %d!\n",
Thomas Witkowski's avatar
Thomas Witkowski committed
428
429
	   globalRowDof);

430
	int rowIndex =
Thomas Witkowski's avatar
Thomas Witkowski committed
431
432
	  mapGlobalInteriorDof[globalRowDof] * dispMult + dispAddRow;

433
  	MatSetValues(matA11, 1, &rowIndex, colsInterior.size(),
Thomas Witkowski's avatar
Thomas Witkowski committed
434
  		     &(colsInterior[0]), &(valuesInterior[0]), ADD_VALUES);
435
  	MatSetValues(matA12, 1, &rowIndex, colsBoundary.size(),
Thomas Witkowski's avatar
Thomas Witkowski committed
436
437
438
439
440
441
442
443
444
  		     &(colsBoundary[0]), &(valuesBoundary[0]), ADD_VALUES);
      }
    }
  }


  void PetscSolverSchur::setDofVector(Vec& petscVec, DOFVector<double>* vec,
				      int dispMult, int dispAdd, bool rankOnly)
  {
445
    FUNCNAME_DBG("PetscSolverSchur::setDofVector()");
446

447
    const FiniteElemSpace *feSpace = componentSpaces[0];
448

Thomas Witkowski's avatar
Thomas Witkowski committed
449
450
    DOFVector<double>::Iterator dofIt(vec, USED_DOFS);
    for (dofIt.reset(); !dofIt.end(); ++dofIt) {
451
      if (rankOnly && !(*interiorMap)[feSpace].isRankDof(dofIt.getDOFIndex()))
Thomas Witkowski's avatar
Thomas Witkowski committed
452
453
	continue;

454
      // Calculate global row index of the DOF.
455
      DegreeOfFreedom globalRowDof =
456
	(*interiorMap)[feSpace][dofIt.getDOFIndex()].global;
Thomas Witkowski's avatar
Thomas Witkowski committed
457
458
459
460
461
462
      double value = *dofIt;

      if (boundaryDofs.count(globalRowDof)) {
	TEST_EXIT_DBG(mapGlobalBoundaryDof.count(globalRowDof))
	  ("Should not happen!\n");

463
464
	int index =
	  (rStartInteriorDofs +
Thomas Witkowski's avatar
Thomas Witkowski committed
465
466
	   nInteriorDofs +
	   mapGlobalBoundaryDof[globalRowDof]) * dispMult + dispAdd;
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
467
	VecSetValues(petscVec, 1, &index, &value, ADD_VALUES);
Thomas Witkowski's avatar
Thomas Witkowski committed
468
469
470
      } else {
	TEST_EXIT_DBG(mapGlobalInteriorDof.count(globalRowDof))
	  ("Should not happen!\n");
471
472
473

	int index =
	  (rStartBoundaryDofs +
Thomas Witkowski's avatar
Thomas Witkowski committed
474
	   mapGlobalInteriorDof[globalRowDof]) * dispMult + dispAdd;
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
475
	VecSetValues(petscVec, 1, &index, &value, ADD_VALUES);
Thomas Witkowski's avatar
Thomas Witkowski committed
476
477
478
479
      }
    }
  }

480
} } // end namespace Parallel, AMDiS