9 #include <fei_macros.hpp>
11 #include <fei_EqnBuffer.hpp>
12 #include <fei_CSVec.hpp>
14 #include <fei_TemplateUtils.hpp>
25 setNumRHSsCalled_(false),
26 rhsCoefsAllocated_(false),
40 setNumRHSsCalled_(false),
41 rhsCoefsAllocated_(false),
50 int i, len = src.eqnNumbers_.size();
52 eqnNumbers_ = src.eqnNumbers_;
53 eqns_.resize(src.eqns_.size());
55 numRHSs_ = src.numRHSs_;
57 for(i=0; i<len; i++) {
69 std::vector<double>* rhsCoefs = src.rhsCoefs_[i];
71 rhsCoefs_.push_back(
new std::vector<double>(*rhsCoefs) );
93 void EqnBuffer::deleteMemory() {
114 if (n <= 0) {
return;}
121 std::vector<double>* rhsCoefs = rhsCoefs_[i];
122 rhsCoefs->assign(numRHSs_, 0.0);
133 fei::console_out() <<
"(deep in FEI) EqnBuffer::addRHS: ERROR, eqnNumber " << eqnNumber
134 <<
" not found in send eqns." << FEI_ENDL;
138 std::vector<double>* rhsCoefs = rhsCoefs_[index];
140 if ( (
int)rhsCoefs->size() <= rhsIndex)
setNumRHSs(rhsIndex+1);
142 if (accumulate==
true) (*rhsCoefs)[rhsIndex] += value;
143 else (*rhsCoefs)[rhsIndex] = value;
155 if (indices_union_.size() > 0) {
157 if (index < 0)
return(-1);
162 for(
int i=0; i<numEqns; i++) {
163 std::vector<int>& indices = eqnsPtr[i]->indices();
165 if (index > -1)
return(i);
173 int len,
bool accumulate,
bool create_indices_union)
175 if (len <= 0)
return(0);
177 int err, insertPoint = -1;
183 err = insertNewEqn(eqnNumber, insertPoint);
184 if (err) {
return(err);}
189 err = internalAddEqn(index, coefs, indices, len, accumulate);
191 if (create_indices_union) {
192 for(
int i=0; i<len; ++i) {
204 if (eqnLoc < 0)
return(-1);
207 if (colLoc < 0)
return(-1);
209 coef = eqns_[eqnLoc]->coefs()[colLoc];
217 if (eqnLoc < 0)
return(-1);
220 if (colLoc < 0)
return(0);
222 std::vector<int>& indices = eqns_[eqnLoc]->indices();
223 std::vector<double>& coefs= eqns_[eqnLoc]->coefs();
225 int len = indices.size();
227 int* indPtr = &indices[0];
228 double* coefPtr = &coefs[0];
230 for(
int i=len-1; i>colLoc; --i) {
231 indPtr[i-1] = indPtr[i];
232 coefPtr[i-1] = coefPtr[i];
235 indices.resize(len-1);
245 if (eqnLoc < 0)
return(-1);
248 if (colLoc < 0)
return(-1);
250 std::vector<int>& indices = eqns_[eqnLoc]->indices();
251 std::vector<double>& coefs= eqns_[eqnLoc]->coefs();
253 coef = coefs[colLoc];
254 int len = indices.size();
256 int* indPtr = &indices[0];
257 double* coefPtr = &coefs[0];
259 for(
int i=len-1; i>colLoc; --i) {
260 indPtr[i-1] = indPtr[i];
261 coefPtr[i-1] = coefPtr[i];
264 indices.resize(len-1);
281 std::vector<double>** rhsCoefs = &((*(inputEqns.
rhsCoefsPtr()))[0]);
284 std::vector<int>& indices_i = eqs[i]->indices();
285 std::vector<double>& coefs_i = eqs[i]->coefs();
287 int err =
addEqn(eqnNums[i], &coefs_i[0], &indices_i[0],
288 eqs[i]->size(), accumulate);
289 if (err)
return(err);
292 for(
int j=0; j<numRHSs; ++j) {
293 addRHS(eqnNums[i], j, (*(rhsCoefs[i]))[j], accumulate);
302 int EqnBuffer::insertNewEqn(
int eqn,
int insertPoint)
307 eqnNumbers_.insert(eqnNumbers_.begin()+insertPoint, eqn);
310 eqns_.insert(eqns_.begin()+insertPoint, newEqn);
312 if (numRHSs_ <= 0)
return(-1);
314 std::vector<double>* newRhsCoefRow =
new std::vector<double>(numRHSs_, 0.0);
315 rhsCoefs_.insert(rhsCoefs_.begin()+insertPoint, newRhsCoefRow);
317 catch (std::runtime_error& exc) {
326 int EqnBuffer::internalAddEqn(
int index,
const double* coefs,
327 const int* indices,
int len,
bool accumulate)
337 for(
int i=0; i<len; ++i) {
338 fei::add_entry(eqn, indices[i], coefs[i]);
342 for(
int i=0; i<len; ++i) {
343 fei::put_entry(eqn, indices[i], coefs[i]);
354 fei::set_values(*eqns_[i], 0.0);
361 int err = 0, insertPoint = -1;
367 if ((
int)dummyCoefs_.size() < len) {
368 dummyCoefs_.assign(len, 0.0);
374 err = insertNewEqn(eqnNumber, insertPoint);
375 if (err) {
return(err);}
380 err = internalAddEqn(index, &dummyCoefs_[0], indices, len,
true);
388 std::vector<std::vector<double>*>& rhsCoefs = *(eq.
rhsCoefsPtr());
390 os <<
"#ereb num-eqns: " << eqnNums.size() << FEI_ENDL;
391 for(
size_t i=0; i<eqnNums.size(); i++) {
392 os <<
"#ereb eqn " << eqnNums[i] <<
": ";
394 std::vector<int>& inds = eq.
eqns()[i]->indices();
395 std::vector<double>& cfs = eq.
eqns()[i]->coefs();
397 for(
size_t j=0; j<inds.size(); j++) {
398 os <<
"("<<inds[j] <<
"," << cfs[j] <<
") ";
402 std::vector<double>& rhs = *(rhsCoefs[i]);
403 for(
size_t k=0; k<rhs.size(); k++) {
404 os << rhs[k] <<
", ";
int sortedListInsert(const T &item, std::vector< T > &list)
std::ostream & operator<<(std::ostream &os, const Teuchos::SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
int addEqn(int eqnNumber, const double *coefs, const int *indices, int len, bool accumulate, bool create_indices_union=false)
std::vector< fei::CSVec * > & eqns()
EqnBuffer & operator=(const EqnBuffer &src)
std::vector< int > & eqnNumbers()
int addRHS(int eqnNumber, int rhsIndex, double value, bool accumulate=true)
std::vector< std::vector< double > * > * rhsCoefsPtr()
int binarySearch(const T &item, const T *list, int len)
int getCoefAndRemoveIndex(int eqnNumber, int colIndex, double &coef)
int addEqns(EqnBuffer &inputEqns, bool accumulate)
int addIndices(int eqnNumber, const int *indices, int len)
std::ostream & console_out()
int removeIndex(int eqnNumber, int colIndex)
int getCoef(int eqnNumber, int colIndex, double &coef)