void LinearConstraintBC :: assemble(SparseMtrx *answer, TimeStep *tStep, EquationID eid, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s) { int size = this->weights.giveSize(); IntArray lambdaeq(1); FloatMatrix contrib(size, 1), contribt; IntArray locr(size), locc(size); if (!this->lhsType.contains((int) type)) return ; this->giveLocArray(r_s, locr, lambdaeq.at(1)); if (this->isImposed(tStep)) { for ( int _i = 1; _i <= size; _i++ ) { // loop over dofs double factor=1.; if(weightsLtf.giveSize()){ factor = domain->giveLoadTimeFunction(weightsLtf.at(_i))->__at(tStep->giveIntrinsicTime()); } contrib.at(_i, 1) = this->weights.at(_i)*factor; } contribt.beTranspositionOf(contrib); answer->assemble(lambdaeq, locr, contribt); answer->assemble(locr, lambdaeq, contrib); } else { // the bc is not imposed at specific time step, however in order to make the equation system regular // we initialize the allocated equation to the following form 1*labmda = 0, forcing lagrange multiplier // of inactive condition to be zero. FloatMatrix help(1,1); help.at(1,1) = 1.0; answer->assemble(lambdaeq, lambdaeq, help); } }
/***************************************************************** * TAG( findruns ) * * Find runs not a given color in the row. * Inputs: * row: Row of pixel values * rowlen: Number of pixels in the row. * color: Color to compare against. * nrun: Number of runs already found (in different colors). * brun: Runs found in other color channels already. * Outputs: * brun: Modified to reflect merging of runs in this color. * Returns number of runs in brun. * Assumptions: * * Algorithm: * Search for occurences of pixels not of the given color outside * the runs already found. When some are found, add a new run or * extend an existing one. Adjacent runs with fewer than two * pixels intervening are merged. */ static int findruns(rle_pixel * const row, int const rowlen, int const color, int const nrunAlready, short (* const brun)[2]) { int i = 0, lower, upper; int s, j; int nrun; #ifdef DEBUG fprintf( stderr, "findruns( " ); for ( s = 0; s < rowlen; s++ ) fprintf( stderr, "%2x.%s", row[s], (s % 20 == 19) ? "\n\t" : "" ); if ( s % 20 != 0 ) fprintf( stderr, "\n\t" ); fprintf( stderr, "%d, %d, %d, \n\t", rowlen, color, nrun ); for ( j = 0; j < nrun; j++ ) fprintf( stderr, "(%3d,%3d) %s", brun[j][0], brun[j][1], (j % 6 == 5) ? "\n\t" : "" ); fprintf( stderr, ")\n" ); #endif nrun = nrunAlready; while ( i <= nrun ) { /* Assert: 0 <= i <= rowlen * brun[i] is the run following the "blank" space being * searched. If i == rowlen, search after brun[i-1]. */ /* get lower and upper bounds of search */ if ( i == 0 ) lower = 0; else lower = brun[i-1][1] + 1; if ( i == nrun ) upper = rowlen - 1; else upper = brun[i][0] - 1; #ifdef DEBUG fprintf( stderr, "Searching before run %d from %d to %d\n", i, lower, upper ); #endif /* Search for beginning of run != color */ #if defined(LOCC)&defined(vax) s = upper - skpc( (char *)row + lower, upper - lower + 1, color ) + 1; #else for ( s = lower; s <= upper; s++ ) if ( row[s] != color ) break; #endif if ( s <= upper ) /* found a new run? */ { if ( s > lower + 1 || i == 0 ) /* disjoint from preceding run? */ { #ifdef DEBUG fprintf( stderr, "Found new run starting at %d\n", s ); #endif /* Shift following runs up */ for ( j = nrun; j > i; j-- ) { brun[j][0] = brun[j-1][0]; brun[j][1] = brun[j-1][1]; } brun[i][0] = s; nrun++; } else { i--; /* just add to preceding run */ #ifdef DEBUG fprintf( stderr, "Adding to previous run\n" ); #endif } #if defined(LOCC)&defined(vax) s = upper - locc( (char *)row + s, upper - s + 1, color ) + 1; #else for ( ; s <= upper; s++ ) if ( row[s] == color ) break; #endif brun[i][1] = s - 1; #ifdef DEBUG fprintf( stderr, "Ends at %d", s - 1 ); #endif if ( s >= upper && i < nrun - 1 ) /* merge with following run */ { brun[i][1] = brun[i+1][1]; /* move following runs back down */ for ( j = i + 2; j < nrun; j++ ) { brun[j-1][0] = brun[j][0]; brun[j-1][1] = brun[j][1]; } nrun--; #ifdef DEBUG fprintf( stderr, ", add to next run" ); #endif } #ifdef DEBUG putc( '\n', stderr ); #endif } /* Search in next space */ i++; } return nrun; }