void CompCol :: timesT(const FloatArray &x, FloatArray &answer) const { int M = dim_ [ 0 ]; int N = dim_ [ 1 ]; // Check for compatible dimensions: if ( x.giveSize() != M ) { OOFEM_ERROR("Error in CompCol -- incompatible dimensions"); } answer.resize(N); answer.zero(); int i, t; double r; for ( i = 0; i < N; i++ ) { r = 0.0; for ( t = colptr_(i); t < colptr_(i + 1); t++ ) { r += val_(t) * x( rowind_(t) ); } answer(i) = r; } }
int SymCompCol :: buildInternalStructure(EngngModel *eModel, int di, EquationID ut, const UnknownNumberingScheme &s) { /* * IntArray loc; * Domain* domain = eModel->giveDomain(di); * int neq = eModel -> giveNumberOfDomainEquations (di); * int nelem = domain -> giveNumberOfElements() ; * int i,ii,j,jj,n, indx; * Element* elem; * // allocation map * int nmap = neq*neq-neq*(neq-1)/2; * char* map = new char[nmap]; * if (map == NULL) { * printf ("CompCol::buildInternalStructure - map creation failed"); * exit (1); * } * * for (i=0; i<nmap; i++) * map[i]=0; * * this->nz_ = 0; * * for (n=1 ; n<=nelem ; n++) { * elem = domain -> giveElement(n); * elem -> giveLocationArray (loc) ; * * for (i=1 ; i <= loc.giveSize() ; i++) { * if ((ii = loc.at(i))) { * for (j=1; j <= loc.giveSize() ; j++) { * if ((jj=loc.at(j)) && (ii>=jj)) { * if (MAP(ii-1,jj-1) == 0) { * MAP(ii-1,jj-1) = 1; * this->nz_ ++; * } * } * } * } * } * } * * rowind_.resize (nz_); * colptr_.resize (neq+1); * indx = 0; * for (j=0; j<neq; j++) { // column loop * colptr_(j) = indx; * for (i=j; i<neq; i++) { // row loop * if (MAP(i,j)) { * rowind_(indx) = i; * indx++; * } * } * } * colptr_(neq) = indx; * * // delete map * delete (map); * * // allocate value array * val_.resize(nz_); * val_.zero(); * * printf ("\nSymCompCol info: neq is %d, nwk is %d\n",neq,nz_); * * dim_[0] = dim_[1] = nColumns = nRows = neq; * * // increment version * this->version++; * * return true; */ IntArray loc; Domain *domain = eModel->giveDomain(di); int neq = eModel->giveNumberOfDomainEquations(di, ut); int nelem = domain->giveNumberOfElements(); int i, ii, j, jj, n, indx; Element *elem; // allocation map std :: vector< std :: set< int > >columns(neq); /* * std::set<int> **columns = new std::set<int>*[neq]; * for (j=0; j<neq; j++) { * columns[j] = new std::set<int>; * } */ this->nz_ = 0; for ( n = 1; n <= nelem; n++ ) { elem = domain->giveElement(n); elem->giveLocationArray(loc, ut, s); for ( i = 1; i <= loc.giveSize(); i++ ) { if ( ( ii = loc.at(i) ) ) { for ( j = 1; j <= loc.giveSize(); j++ ) { if ( ( jj = loc.at(j) ) && ( ii >= jj ) ) { columns [ jj - 1 ].insert(ii - 1); } } } } } for ( i = 0; i < neq; i++ ) { this->nz_ += columns [ i ].size(); } rowind_.resize(nz_); colptr_.resize(neq + 1); indx = 0; std :: set< int > :: iterator pos; for ( j = 0; j < neq; j++ ) { // column loop colptr_(j) = indx; for ( pos = columns [ j ].begin(); pos != columns [ j ].end(); ++pos ) { // row loop rowind_(indx++) = * pos; } } colptr_(neq) = indx; /* * // delete map * for (i=0; i< neq; i++) {columns[i]->clear(); delete columns[i];} * delete columns; */ // allocate value array val_.resize(nz_); val_.zero(); OOFEM_LOG_INFO("SymCompCol info: neq is %d, nwk is %d\n", neq, nz_); dim_ [ 0 ] = dim_ [ 1 ] = nColumns = nRows = neq; // increment version this->version++; return true; }
int CompCol :: buildInternalStructure(EngngModel *eModel, int di, const UnknownNumberingScheme &s) { /* * IntArray loc; * Domain* domain = eModel->giveDomain(di); * int neq = eModel -> giveNumberOfDomainEquations (di); * int nelem = domain -> giveNumberOfElements() ; * int i,ii,j,jj,n, indx; * Element* elem; * // allocation map * char* map = new char[neq*neq]; * if (map == NULL) { * printf ("CompCol::buildInternalStructure - map creation failed"); * exit (1); * } * * for (i=0; i<neq*neq; i++) * map[i]=0; * * * this->nz_ = 0; * * for (n=1 ; n<=nelem ; n++) { * elem = domain -> giveElement(n); * elem -> giveLocationArray (loc) ; * * for (i=1 ; i <= loc.giveSize() ; i++) { * if ((ii = loc.at(i))) { * for (j=1; j <= loc.giveSize() ; j++) { * if ((jj=loc.at(j))) { * if (map[(ii-1)*neq+jj-1] == 0) { * map[(ii-1)*neq+jj-1] = 1; * this->nz_ ++; * } * } * } * } * } * } * * rowind_.resize (nz_); * colptr_.resize (neq+1); * indx = 0; * for (j=0; j<neq; j++) { // column loop * colptr_(j) = indx; * for (i=0; i<neq; i++) { // row loop * if (map[i*neq+j]) { * rowind_(indx) = i; * indx++; * } * } * } * colptr_(neq) = indx; * * // delete map * delete (map); * * // allocate value array * val_.resize(nz_); * val_.zero(); * * printf ("\nCompCol info: neq is %d, nwk is %d\n",neq,nz_); * * dim_[0] = dim_[1] = nColumns = nRows = neq; * * // increment version * this->version++; * * return true; */ IntArray loc; Domain *domain = eModel->giveDomain(di); int neq = eModel->giveNumberOfDomainEquations(di, s); int nelem = domain->giveNumberOfElements(); int i, ii, j, jj, n, indx; Element *elem; // allocation map std :: vector< std :: set< int > > columns(neq); /* * std::set<int> **columns = new std::set<int>*[neq]; * for (j=0; j<neq; j++) { * columns[j] = new std::set<int>; * } */ this->nz_ = 0; for ( n = 1; n <= nelem; n++ ) { elem = domain->giveElement(n); elem->giveLocationArray(loc, s); for ( i = 1; i <= loc.giveSize(); i++ ) { if ( ( ii = loc.at(i) ) ) { for ( j = 1; j <= loc.giveSize(); j++ ) { if ( ( jj = loc.at(j) ) ) { columns [ jj - 1 ].insert(ii - 1); } } } } } // loop over active boundary conditions int nbc = domain->giveNumberOfBoundaryConditions(); std :: vector< IntArray >r_locs; std :: vector< IntArray >c_locs; for ( int i = 1; i <= nbc; ++i ) { ActiveBoundaryCondition *bc = dynamic_cast< ActiveBoundaryCondition * >( domain->giveBc(i) ); if ( bc != NULL ) { bc->giveLocationArrays(r_locs, c_locs, UnknownCharType, s, s); for ( std :: size_t k = 0; k < r_locs.size(); k++ ) { IntArray &krloc = r_locs [ k ]; IntArray &kcloc = c_locs [ k ]; for ( int i = 1; i <= krloc.giveSize(); i++ ) { if ( ( ii = krloc.at(i) ) ) { for ( int j = 1; j <= kcloc.giveSize(); j++ ) { if ( ( jj = kcloc.at(j) ) ) { columns [ jj - 1 ].insert(ii - 1); } } } } } } } for ( i = 0; i < neq; i++ ) { this->nz_ += columns [ i ].size(); } rowind_.resize(nz_); colptr_.resize(neq + 1); indx = 0; for ( j = 0; j < neq; j++ ) { // column loop colptr_(j) = indx; for ( int row: columns [ j ] ) { // row loop rowind_(indx++) = row; } } colptr_(neq) = indx; /* * // delete map * for (i=0; i< neq; i++) {columns[i]->clear(); delete columns[i];} * delete columns; */ // allocate value array val_.resize(nz_); val_.zero(); OOFEM_LOG_DEBUG("CompCol info: neq is %d, nwk is %d\n", neq, nz_); dim_ [ 0 ] = dim_ [ 1 ] = nColumns = nRows = neq; // increment version this->version++; return true; }