void scale_matrix(double scalar, fei::Matrix& matrix) { fei::SharedPtr<fei::VectorSpace> vspace = matrix.getMatrixGraph()->getRowSpace(); int numRows = vspace->getNumIndices_Owned(); std::vector<int> rows(numRows); vspace->getIndices_Owned(numRows, &rows[0], numRows); std::vector<int> indices; std::vector<double> coefs; for(size_t i=0; i<rows.size(); ++i) { int rowlen = 0; matrix.getRowLength(rows[i], rowlen); if ((int)indices.size() < rowlen) { indices.resize(rowlen); coefs.resize(rowlen); } matrix.copyOutRow(rows[i], rowlen, &coefs[0], &indices[0]); for(int j=0; j<rowlen; ++j) { coefs[j] *= scalar; } double* coefPtr = &coefs[0]; matrix.copyIn(1, &rows[i], rowlen, &indices[0], &coefPtr); } }
int DirichletBCManager::finalizeBCEqns(fei::Matrix& matrix, bool throw_if_bc_slave_conflict) { fei::SharedPtr<fei::Reducer> reducer = matrix.getMatrixGraph()->getReducer(); bool haveSlaves = reducer.get()!=NULL; //copy the boundary-condition prescribed values into the matrix, in //an equation-number obtained by using the matrix' VectorSpace to map //from the BC's idtype,id,fieldID,component to an equation-number. The //bc values will go on the diagonal of the matrix, i.e., column-index //will be the same equation-number. bc_map::iterator iter = bcs_.begin(), iter_end = bcs_.end(); for(; iter!=iter_end; ++iter) { int eqn = iter->first; if (haveSlaves) { if (reducer->isSlaveEqn(eqn)) { if (throw_if_bc_slave_conflict) { FEI_OSTRINGSTREAM osstr; osstr << "fei BCManager::finalizeBCeqns ERROR, eqn="<<eqn << " is both a BC eqn and slave-constraint eqn."; throw std::runtime_error(osstr.str()); } continue; } } double* ptr = &iter->second; CHK_ERR( matrix.copyIn(1, &eqn, 1, &eqn, &ptr) ); } bcs_.clear(); return(0); }