// // 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 "AMDiS.h" #include "parallel/PetscSolverGlobalMatrix.h" #include "parallel/StdMpi.h" #include "parallel/MpiHelper.h" namespace AMDiS { void PetscSolverGlobalMatrix::fillPetscMatrix(Matrix *seqMat) { FUNCNAME("PetscSolverGlobalMatrix::fillPetscMatrix()"); petscData.init(interiorMap, coarseSpaceMap, subdomainLevel, mpiCommLocal, mpiCommGlobal, meshDistributor); petscData.create(*seqMat); if (coarseSpaceMap.size()) { updateSubdomainData(); fillPetscMatrixWithCoarseSpace(seqMat); return; } TEST_EXIT_DBG(meshDistributor)("No mesh distributor object defined!\n"); TEST_EXIT_DBG(interiorMap)("No parallel mapping object defined!\n"); TEST_EXIT_DBG(seqMat)("No DOF matrix defined!\n"); double wtime = MPI::Wtime(); // === Create PETSc vector (solution and a temporary vector). === int nRankRows = interiorMap->getRankDofs(); int nOverallRows = interiorMap->getOverallDofs(); VecCreateMPI(mpiCommGlobal, nRankRows, nOverallRows, &petscSolVec); #if (DEBUG != 0) MSG("Fill petsc matrix 1 needed %.5f seconds\n", MPI::Wtime() - wtime); #endif #if (DEBUG != 0) int a, b; MatGetOwnershipRange(petscData.getInteriorMat(), &a, &b); TEST_EXIT(a == interiorMap->getStartDofs())("Wrong matrix ownership range!\n"); TEST_EXIT(b == interiorMap->getStartDofs() + nRankRows) ("Wrong matrix ownership range!\n"); #endif // === Transfer values from DOF matrices to the PETSc matrix. === int nComponents = seqMat->getNumRows(); for (int i = 0; i < nComponents; i++) for (int j = 0; j < nComponents; j++) if ((*seqMat)[i][j]) setDofMatrix((*seqMat)[i][j], i, j); #if (DEBUG != 0) MSG("Fill petsc matrix 2 needed %.5f seconds\n", MPI::Wtime() - wtime); #endif petscData.assembly(); if (printMatInfo) { MatInfo matInfo; MatGetInfo(petscData.getInteriorMat(), MAT_GLOBAL_SUM, &matInfo); MSG("Matrix info:\n"); MSG(" memory usage: %e MB\n", matInfo.memory / (1024.0 * 1024.0)); MSG(" mallocs: %d\n", static_cast(matInfo.mallocs)); MSG(" nz allocated: %d\n", static_cast(matInfo.nz_allocated)); MSG(" nz used: %d\n", static_cast(matInfo.nz_used)); MSG(" nz unneeded: %d\n", static_cast(matInfo.nz_unneeded)); } // === Remove Dirichlet BC DOFs. === // removeDirichletBcDofs(mat); // === Init PETSc solver. === KSPCreate(mpiCommGlobal, &kspInterior); KSPGetPC(kspInterior, &pcInterior); KSPSetOperators(kspInterior, petscData.getInteriorMat(), petscData.getInteriorMat(), SAME_NONZERO_PATTERN); KSPSetTolerances(kspInterior, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT); KSPSetType(kspInterior, KSPBCGS); KSPSetOptionsPrefix(kspInterior, kspPrefix.c_str()); KSPSetFromOptions(kspInterior); initPreconditioner(pcInterior); // Do not delete the solution vector, use it for the initial guess. if (!zeroStartVector) KSPSetInitialGuessNonzero(kspInterior, PETSC_TRUE); #if (DEBUG != 0) MSG("Fill petsc matrix 3 needed %.5f seconds\n", MPI::Wtime() - wtime); #endif } void PetscSolverGlobalMatrix::fillPetscMatrix(DOFMatrix *mat) { Matrix m(1, 1); m[0][0] = mat; fillPetscMatrix(&m); } void PetscSolverGlobalMatrix::fillPetscMatrixWithCoarseSpace(Matrix *seqMat) { FUNCNAME("PetscSolverGlobalMatrix::fillPetscMatrixWithCoarseSpace()"); TEST_EXIT_DBG(interiorMap)("Should not happen!\n"); TEST_EXIT_DBG(coarseSpaceMap.size() == seqMat->getSize()) ("Wrong sizes %d %d\n", coarseSpaceMap.size(), seqMat->getSize()); vector feSpaces = AMDiS::getFeSpaces(*seqMat); int nRowsRankInterior = interiorMap->getRankDofs(); int nRowsOverallInterior = interiorMap->getOverallDofs(); // === Prepare traverse of sequentially created matrices. === using mtl::tag::row; using mtl::tag::nz; using mtl::begin; using mtl::end; namespace traits = mtl::traits; typedef DOFMatrix::base_matrix_type Matrix; typedef traits::range_generator::type cursor_type; typedef traits::range_generator::type icursor_type; vector cols, colsOther; vector values, valuesOther; cols.reserve(300); colsOther.reserve(300); values.reserve(300); valuesOther.reserve(300); // === Traverse all sequentially created matrices and add the values to === // === the global PETSc matrices. === int nComponents = seqMat->getSize(); for (int i = 0; i < nComponents; i++) { for (int j = 0; j < nComponents; j++) { if (!(*seqMat)[i][j]) continue; ParallelDofMapping *rowCoarseSpace = coarseSpaceMap[i]; ParallelDofMapping *colCoarseSpace = coarseSpaceMap[j]; traits::col::type col((*seqMat)[i][j]->getBaseMatrix()); traits::const_value::type value((*seqMat)[i][j]->getBaseMatrix()); // Traverse all rows. for (cursor_type cursor = begin((*seqMat)[i][j]->getBaseMatrix()), cend = end((*seqMat)[i][j]->getBaseMatrix()); cursor != cend; ++cursor) { bool isRowCoarse = isCoarseSpace(i, feSpaces[i], *cursor); cols.clear(); colsOther.clear(); values.clear(); valuesOther.clear(); // Traverse all columns. for (icursor_type icursor = begin(cursor), icend = end(cursor); icursor != icend; ++icursor) { bool isColCoarse = isCoarseSpace(j, feSpaces[j], col(*icursor)); if (isColCoarse) { if (isRowCoarse) { cols.push_back(col(*icursor)); values.push_back(value(*icursor)); } else { colsOther.push_back(col(*icursor)); valuesOther.push_back(value(*icursor)); } } else { if (isRowCoarse) { colsOther.push_back(col(*icursor)); valuesOther.push_back(value(*icursor)); } else { cols.push_back(col(*icursor)); values.push_back(value(*icursor)); } } } // for each nnz in row // === Set matrix values. === if (isRowCoarse) { int rowIndex = rowCoarseSpace->getMatIndex(i, *cursor); for (unsigned int k = 0; k < cols.size(); k++) cols[k] = colCoarseSpace->getMatIndex(j, cols[k]); // matCoarseCoarse MatSetValues(petscData.getCoarseMatComp(i), 1, &rowIndex, cols.size(), &(cols[0]), &(values[0]), ADD_VALUES); if (colsOther.size()) { if (subdomainLevel == 0) { for (unsigned int k = 0; k < colsOther.size(); k++) colsOther[k] = interiorMap->getMatIndex(j, colsOther[k]); } else { for (unsigned int k = 0; k < colsOther.size(); k++) colsOther[k] = interiorMap->getMatIndex(j, colsOther[k]) + rStartInterior; } // matCoarseInt MatSetValues(petscData.getCoarseIntMatComp(i), 1, &rowIndex, colsOther.size(), &(colsOther[0]), &(valuesOther[0]), ADD_VALUES); } } else { int localRowIndex = (subdomainLevel == 0 ? interiorMap->getLocalMatIndex(i, *cursor) : interiorMap->getMatIndex(i, *cursor)); for (unsigned int k = 0; k < cols.size(); k++) { if (subdomainLevel == 0) cols[k] = interiorMap->getLocalMatIndex(j, cols[k]); else cols[k] = interiorMap->getMatIndex(j, cols[k]); } MatSetValues(petscData.getInteriorMat(), 1, &localRowIndex, cols.size(), &(cols[0]), &(values[0]), ADD_VALUES); if (colsOther.size()) { int globalRowIndex = interiorMap->getMatIndex(i, *cursor); if (subdomainLevel != 0) globalRowIndex += rStartInterior; for (unsigned int k = 0; k < colsOther.size(); k++) colsOther[k] = colCoarseSpace->getMatIndex(j, colsOther[k]); // matIntCoarse MatSetValues(petscData.getIntCoarseMatComp(i), 1, &globalRowIndex, colsOther.size(), &(colsOther[0]), &(valuesOther[0]), ADD_VALUES); } } } } } petscData.assembly(); // === Create solver for the non primal (thus local) variables. === KSPCreate(mpiCommLocal, &kspInterior); KSPSetOperators(kspInterior, petscData.getInteriorMat(), petscData.getInteriorMat(), SAME_NONZERO_PATTERN); KSPSetOptionsPrefix(kspInterior, "interior_"); KSPSetType(kspInterior, KSPPREONLY); KSPGetPC(kspInterior, &pcInterior); PCSetType(pcInterior, PCLU); if (subdomainLevel == 0) PCFactorSetMatSolverPackage(pcInterior, MATSOLVERUMFPACK); else PCFactorSetMatSolverPackage(pcInterior, MATSOLVERMUMPS); KSPSetFromOptions(kspInterior); } void PetscSolverGlobalMatrix::fillPetscRhs(SystemVector *vec) { FUNCNAME("PetscSolverGlobalMatrix::fillPetscRhs()"); VecCreateMPI(mpiCommGlobal, interiorMap->getRankDofs(), nGlobalOverallInterior, &rhsInterior); if (coarseSpaceMap.size()) VecCreateMPI(mpiCommGlobal, coarseSpaceMap[0]->getRankDofs(), coarseSpaceMap[0]->getOverallDofs(), &rhsCoarseSpace); TEST_EXIT_DBG(vec)("No DOF vector defined!\n"); TEST_EXIT_DBG(interiorMap)("No parallel DOF map defined!\n"); // === Transfer values from DOF vector to the PETSc vector. === if (coarseSpaceMap.size()) { for (int i = 0; i < vec->getSize(); i++) setDofVector(rhsInterior, rhsCoarseSpace, vec->getDOFVector(i), i); } else { for (int i = 0; i < vec->getSize(); i++) setDofVector(rhsInterior, vec->getDOFVector(i), i); } VecAssemblyBegin(rhsInterior); VecAssemblyEnd(rhsInterior); if (coarseSpaceMap.size()) { VecAssemblyBegin(rhsCoarseSpace); VecAssemblyEnd(rhsCoarseSpace); } // === Remove Dirichlet BC DOFs. === // removeDirichletBcDofs(vec); } void PetscSolverGlobalMatrix::solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo) { FUNCNAME("PetscSolverGlobalMatrix::solvePetscMatrix()"); int nComponents = vec.getSize(); // === Set old solution to be initiual guess for PETSc solver. === if (!zeroStartVector) { VecSet(petscSolVec, 0.0); for (int i = 0; i < nComponents; i++) setDofVector(petscSolVec, vec.getDOFVector(i), i, true); VecAssemblyBegin(petscSolVec); VecAssemblyEnd(petscSolVec); } MatNullSpace matNullspace; Vec nullspaceBasis; if (nullspace.size() > 0 || hasConstantNullspace || constNullspaceComponent.size() > 0) { TEST_EXIT_DBG(nullspace.size() <= 1)("Not yet implemented!\n"); if (constNullspaceComponent.size() > 0) { nullspace.clear(); SystemVector *basisVec = new SystemVector(vec); basisVec->set(0.0); for (unsigned int i = 0; i < constNullspaceComponent.size(); i++) basisVec->getDOFVector(constNullspaceComponent[i])->set(1.0); nullspace.push_back(basisVec); } if (nullspace.size() > 0) { VecDuplicate(petscSolVec, &nullspaceBasis); for (int i = 0; i < nComponents; i++) setDofVector(nullspaceBasis, nullspace[0]->getDOFVector(i), i, true); VecAssemblyBegin(nullspaceBasis); VecAssemblyEnd(nullspaceBasis); VecNormalize(nullspaceBasis, PETSC_NULL); MatNullSpaceCreate(mpiCommGlobal, (hasConstantNullspace ? PETSC_TRUE : PETSC_FALSE), 1, &nullspaceBasis, &matNullspace); MatMult(petscData.getInteriorMat(), nullspaceBasis, petscSolVec); PetscReal n; VecNorm(petscSolVec, NORM_2, &n); MSG("NORM IS: %e\n", n); } else { MatNullSpaceCreate(mpiCommGlobal, PETSC_TRUE, 0, PETSC_NULL, &matNullspace); } MatSetNullSpace(petscData.getInteriorMat(), matNullspace); KSPSetNullSpace(kspInterior, matNullspace); // === Remove null space, if requested. === if (removeRhsNullspace) { TEST_EXIT_DBG(coarseSpaceMap.empty())("Not supported!\n"); MSG("Remove nullspace from rhs vector.\n"); MatNullSpaceRemove(matNullspace, rhsInterior, PETSC_NULL); } } else { TEST_EXIT(removeRhsNullspace == false) ("No nullspace provided that should be removed from rhs!\n"); } // PETSc. solve(rhsInterior, petscSolVec); if (nullspace.size() > 0) { MatNullSpaceDestroy(&matNullspace); VecDestroy(&nullspaceBasis); } // === Transfere values from PETSc's solution vectors to the DOF vectors. === PetscScalar *vecPointer; VecGetArray(petscSolVec, &vecPointer); int c = 0; for (int i = 0; i < nComponents; i++) { DOFVector &dv = *(vec.getDOFVector(i)); DofMap& d = (*interiorMap)[dv.getFeSpace()].getMap(); for (DofMap::iterator it = d.begin(); it != d.end(); ++it) if (it->second.local != -1) dv[it->first] = vecPointer[c++]; } VecRestoreArray(petscSolVec, &vecPointer); // === Synchronize DOFs at common DOFs, i.e., DOFs that correspond to === // === more than one partition. === meshDistributor->synchVector(vec); } void PetscSolverGlobalMatrix::solveGlobal(Vec &rhs, Vec &sol) { FUNCNAME("PetscSolverGlobalMatrix::solveGlobal()"); double wtime = MPI::Wtime(); double t0 = 0.0, t1 = 0.0; Vec tmp; if (mpiCommLocal.Get_size() == 1) VecCreateSeq(mpiCommLocal, interiorMap->getRankDofs(), &tmp); else VecCreateMPI(mpiCommLocal, interiorMap->getRankDofs(), interiorMap->getOverallDofs(), &tmp); PetscScalar *tmpValues, *rhsValues; VecGetArray(tmp, &tmpValues); VecGetArray(rhs, &rhsValues); for (int i = 0; i < interiorMap->getRankDofs(); i++) tmpValues[i] = rhsValues[i]; VecRestoreArray(rhs, &rhsValues); VecRestoreArray(tmp, &tmpValues); t0 = MPI::Wtime() - wtime; wtime = MPI::Wtime(); KSPSolve(kspInterior, tmp, tmp); t1 = MPI::Wtime() - wtime; wtime = MPI::Wtime(); VecGetArray(tmp, &tmpValues); VecGetArray(sol, &rhsValues); for (int i = 0; i < interiorMap->getRankDofs(); i++) rhsValues[i] = tmpValues[i]; VecRestoreArray(sol, &rhsValues); VecRestoreArray(tmp, &tmpValues); VecDestroy(&tmp); t0 += MPI::Wtime() - wtime; // MSG("TIMEING: %.5f %.5f\n", t0, t1); } void PetscSolverGlobalMatrix::destroyMatrixData() { FUNCNAME("PetscSolverGlobalMatrix::destroyMatrixData()"); exitPreconditioner(pcInterior); petscData.destroy(); KSPDestroy(&kspInterior); if (petscSolVec != PETSC_NULL) { VecDestroy(&petscSolVec); petscSolVec = PETSC_NULL; } } void PetscSolverGlobalMatrix::destroyVectorData() { FUNCNAME("PetscSolverGlobalMatrix::destroyVectorData()"); VecDestroy(&rhsInterior); if (coarseSpaceMap.size()) VecDestroy(&rhsCoarseSpace); } void PetscSolverGlobalMatrix::createFieldSplit(PC pc) { FUNCNAME("PetscSolverGlobalMatrix::createFieldSplit()"); vector isNames; Parameters::get("parallel->solver->is blocks", isNames); int nBlocks = isNames.size(); if (nBlocks == 0) return; for (int i = 0; i < nBlocks; i++) { MSG("Create for block %s\n", isNames[i].c_str()); vector blockComponents; Parameters::get("parallel->solver->is block " + lexical_cast(i), blockComponents); int nComponents = static_cast(blockComponents.size()); TEST_EXIT(nComponents > 0)("No is block for block %d defined!\n", i); // Check if blocks are continous for (int j = 0; j < nComponents; j++) { TEST_EXIT(blockComponents[j] == blockComponents[0] + j) ("Does not yet support not continous IS blocks! Block %s\n", isNames[i].c_str()); } IS is; interiorMap->createIndexSet(is, blockComponents[0], nComponents); PCFieldSplitSetIS(pc, isNames[i].c_str(), is); ISDestroy(&is); } } void PetscSolverGlobalMatrix::initPreconditioner(PC pc) { FUNCNAME("PetscSolverGlobalMatrix::initPreconditioner()"); PCSetFromOptions(pc); createFieldSplit(pc); } void PetscSolverGlobalMatrix::exitPreconditioner(PC pc) { FUNCNAME("PetscSolverGlobalMatrix::exitPreconditioner()"); } void PetscSolverGlobalMatrix::setDofMatrix(DOFMatrix* seqMat, int nRowMat, int nColMat) { FUNCNAME("PetscSolverGlobalMatrix::setDofMatrix()"); TEST_EXIT(seqMat)("No DOFMatrix!\n"); using mtl::tag::row; using mtl::tag::nz; using mtl::begin; using mtl::end; namespace traits = mtl::traits; typedef DOFMatrix::base_matrix_type Matrix; traits::col::type col(seqMat->getBaseMatrix()); traits::const_value::type value(seqMat->getBaseMatrix()); typedef traits::range_generator::type cursor_type; typedef traits::range_generator::type icursor_type; vector cols; vector values; cols.reserve(300); values.reserve(300); vector globalCols; // Get periodic mapping object PeriodicMap &perMap = meshDistributor->getPeriodicMap(); const FiniteElemSpace *rowFe = seqMat->getRowFeSpace(); const FiniteElemSpace *colFe = seqMat->getColFeSpace(); DofMap& rowMap = (*interiorMap)[rowFe].getMap(); DofMap& colMap = (*interiorMap)[colFe].getMap(); // === Traverse all rows of the DOF matrix and insert row wise the values === // === to the PETSc matrix. === for (cursor_type cursor = begin(seqMat->getBaseMatrix()), cend = end(seqMat->getBaseMatrix()); cursor != cend; ++cursor) { // Global index of the current row DOF. int globalRowDof = rowMap[*cursor].global; // Test if the current row DOF is a periodic DOF. bool periodicRow = perMap.isPeriodic(rowFe, globalRowDof); if (!periodicRow) { // === Row DOF index is not periodic. === // Get PETSc's mat row index. int rowIndex = interiorMap->getMatIndex(nRowMat, globalRowDof); cols.clear(); values.clear(); for (icursor_type icursor = begin(cursor), icend = end(cursor); icursor != icend; ++icursor) { // Global index of the current column index. int globalColDof = colMap[col(*icursor)].global; // Test if the current col dof is a periodic dof. bool periodicCol = perMap.isPeriodic(colFe, globalColDof); // Get PETSc's mat col index. int colIndex = interiorMap->getMatIndex(nColMat, globalColDof); // Ignore all zero entries, expect it is a diagonal entry. if (value(*icursor) == 0.0 && rowIndex != colIndex) continue; if (!periodicCol) { // Calculate the exact position of the column index in the PETSc matrix. cols.push_back(colIndex); values.push_back(value(*icursor)); } else { // === Row index is not periodic, but column index is. === // Create set of all periodic associations of the column index. std::set perAsc; perMap.fillAssociations(colFe, globalColDof, meshDistributor->getElementObjectDb(), perAsc); // Scale value to the number of periodic associations of the column index. double scaledValue = value(*icursor) * pow(0.5, static_cast(perAsc.size())); // === Create set of all matrix column indices due to the periodic === // === associations of the column DOF index. === vector newCols; perMap.mapDof(colFe, globalColDof, perAsc, newCols); for (unsigned int i = 0; i < newCols.size(); i++) { cols.push_back(interiorMap->getMatIndex(nColMat, newCols[i])); values.push_back(scaledValue); } } } MatSetValues(petscData.getInteriorMat(), 1, &rowIndex, cols.size(), &(cols[0]), &(values[0]), ADD_VALUES); } else { // === Row DOF index is periodic. === // Because this row is periodic, we will have to add the entries of this // matrix row to multiple rows. The following maps store to each row an // array of column indices and values of the entries that must be added to // the PETSc matrix. map > colsMap; map > valsMap; // Traverse all column entries. for (icursor_type icursor = begin(cursor), icend = end(cursor); icursor != icend; ++icursor) { // Global index of the current column index. int globalColDof = (*interiorMap)[colFe][col(*icursor)].global; // Ignore all zero entries, expect it is a diagonal entry. if (value(*icursor) == 0.0 && globalRowDof != globalColDof) continue; // === Add all periodic associations of both, the row and the column === // === indices to the set perAsc. === std::set perAsc; perMap.fillAssociations(colFe, globalColDof, meshDistributor->getElementObjectDb(), perAsc); perMap.fillAssociations(rowFe, globalRowDof, meshDistributor->getElementObjectDb(), perAsc); // Scale the value with respect to the number of periodic associations. double scaledValue = value(*icursor) * pow(0.5, static_cast(perAsc.size())); // === Create all matrix entries with respect to the periodic === // === associations of the row and column indices. === vector > entry; perMap.mapDof(rowFe, colFe, make_pair(globalRowDof, globalColDof), perAsc, entry); // === Translate the matrix entries to PETSc's matrix. for (unsigned int i = 0; i < entry.size(); i++) { int rowIdx = interiorMap->getMatIndex(nRowMat, entry[i].first); int colIdx = interiorMap->getMatIndex(nColMat, entry[i].second); colsMap[rowIdx].push_back(colIdx); valsMap[rowIdx].push_back(scaledValue); } } // === Finally, add all periodic rows to the PETSc matrix. === for (map >::iterator rowIt = colsMap.begin(); rowIt != colsMap.end(); ++rowIt) { TEST_EXIT_DBG(rowIt->second.size() == valsMap[rowIt->first].size()) ("Should not happen!\n"); int rowIndex = rowIt->first; MatSetValues(petscData.getInteriorMat(), 1, &rowIndex, rowIt->second.size(), &(rowIt->second[0]), &(valsMap[rowIt->first][0]), ADD_VALUES); } } } } void PetscSolverGlobalMatrix::setDofVector(Vec vecInterior, Vec vecCoarse, DOFVector* vec, int nRowVec, bool rankOnly) { FUNCNAME("PetscSolverGlobalMatrix::setDofVector()"); const FiniteElemSpace *feSpace = vec->getFeSpace(); PeriodicMap &perMap = meshDistributor->getPeriodicMap(); ParallelDofMapping *rowCoarseSpace = NULL; if (coarseSpaceMap.size()) rowCoarseSpace = coarseSpaceMap[nRowVec]; // Traverse all used DOFs in the dof vector. DOFVector::Iterator dofIt(vec, USED_DOFS); for (dofIt.reset(); !dofIt.end(); ++dofIt) { if (rankOnly && !(*interiorMap)[feSpace].isRankDof(dofIt.getDOFIndex())) continue; if (isCoarseSpace(nRowVec, feSpace, dofIt.getDOFIndex())) { TEST_EXIT_DBG(vecCoarse != PETSC_NULL)("Should not happen!\n"); int index = rowCoarseSpace->getMatIndex(nRowVec, dofIt.getDOFIndex()); VecSetValue(vecCoarse, index, *dofIt, ADD_VALUES); } else { // Calculate global row index of the DOF. DegreeOfFreedom globalRowDof = (*interiorMap)[feSpace][dofIt.getDOFIndex()].global; // Get PETSc's mat index of the row DOF. int index = 0; if (interiorMap->isMatIndexFromGlobal()) index = interiorMap->getMatIndex(nRowVec, globalRowDof) + rStartInterior; else index = interiorMap->getMatIndex(nRowVec, dofIt.getDOFIndex()) + rStartInterior; if (perMap.isPeriodic(feSpace, globalRowDof)) { std::set& perAsc = perMap.getAssociations(feSpace, globalRowDof); double value = *dofIt / (perAsc.size() + 1.0); VecSetValue(vecInterior, index, value, ADD_VALUES); for (std::set::iterator perIt = perAsc.begin(); perIt != perAsc.end(); ++perIt) { int mappedDof = perMap.map(feSpace, *perIt, globalRowDof); int mappedIndex = interiorMap->getMatIndex(nRowVec, mappedDof); VecSetValue(vecInterior, mappedIndex, value, ADD_VALUES); } } else { // The DOF index is not periodic. VecSetValue(vecInterior, index, *dofIt, ADD_VALUES); } } } } void PetscSolverGlobalMatrix::removeDirichletBcDofs(Matrix *mat) { FUNCNAME("PetscSolverGlobalMatrix::removeDirichletBcDofs()"); } void PetscSolverGlobalMatrix::removeDirichletBcDofs(SystemVector *vec) { FUNCNAME("PetscSolverGlobalMatrix::removeDirichletBcDofs()"); } }