예제 #1
0
	float Animator::_calculateValue(float k)
	{
		if (this->delay > 0.0f)
		{
			return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
		}
		float time = this->timer;
		if (this->isExpired())
		{
			if (this->reset)
			{
				return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
			}
			time = this->periods / habs(this->speed);
		}
		float result = 0.0f;
		switch (this->animationFunction)
		{
		case Object::Linear:
			result = time * this->speed * this->amplitude;
			break;
		case Object::Sine:
			result = (float)dsin(time * this->speed * 360) * this->amplitude;
			break;
		case Object::Square:
			result = (hmodf(time * this->speed, 1.0f) < 0.5f ? this->amplitude : -this->amplitude);
			break;
		case Object::Saw:
			result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 2 * this->amplitude;
			break;
		case Object::Triangle:
			result = hmodf(time * this->speed, 1.0f);
			if (!is_in_range(result, 0.25f, 0.75f))
			{
				result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 4 * this->amplitude;
			}
			else
			{
				result = -(hmodf(time * this->speed - 0.25f, 1.0f) - 0.25f) * 4 * this->amplitude;
			}
			break;
		case Object::Random:
			result = hrandf(-this->speed * this->amplitude, this->speed * this->amplitude);
			break;
		case Object::Hover:
			if ((this->amplitude >= 0.0f) == this->parent->isCursorInside())
			{
				result = hmin(this->value - this->offset + k * this->speed, (float)habs(this->amplitude));
			}
			else
			{
				result = hmax(this->value - this->offset - k * this->speed, -(float)habs(this->amplitude));
			}
			break;
		case Object::Custom:
			result = (this->customFunction != NULL ? this->customFunction(this, time) : this->value);
			break;
		}
		return (this->discreteStep != 0 ? (float)((int)((result + this->offset) / this->discreteStep) * this->discreteStep) : (result + this->offset));
	}
예제 #2
0
int HYPRE_LSI_ILUTDecompose( HYPRE_LSI_Schwarz *sch_ptr )
{

   int    i, j, k, blk, nrows, rleng, *cols, *track_array, track_leng;
   int    nblocks, max_blk_size, *mat_ia, *mat_ja, *new_ia, *new_ja;
   int    index, first, sortcnt, *sortcols, Lcount, Ucount, nnz, new_nnz;
   int    colIndex, mypid, output_level, printflag, printflag2;
   double fillin, *vals, *dble_buf, *rowNorms, *diagonal, *mat_aa, *new_aa;
   double *sortvals, ddata, tau, rel_tau, absval;

   /* --------------------------------------------------------- */
   /* preparation phase                                         */
   /* --------------------------------------------------------- */

   MPI_Comm_rank(sch_ptr->comm, &mypid);
   output_level = sch_ptr->output_level;
   nblocks = sch_ptr->nblocks;
   max_blk_size = 0;
   for ( blk = 0; blk < nblocks; blk++ )
      if ( sch_ptr->blk_sizes[blk] > max_blk_size ) 
         max_blk_size = sch_ptr->blk_sizes[blk];
   fillin = sch_ptr->fillin;
   tau    = sch_ptr->threshold;

   track_array = (int *)    malloc( max_blk_size * sizeof(int) );
   sortcols    = (int *)    malloc( max_blk_size * sizeof(int) );
   sortvals    = (double *) malloc( max_blk_size * sizeof(double) );
   dble_buf    = (double *) malloc( max_blk_size * sizeof(double) );
   diagonal    = (double *) malloc( max_blk_size * sizeof(double) );
   rowNorms    = (double *) malloc( max_blk_size * sizeof(double) );
   for ( i = 0; i < max_blk_size; i++ ) dble_buf[i] = 0.0;

   /* --------------------------------------------------------- */
   /* process the rows                                          */
   /* --------------------------------------------------------- */

   printflag = nblocks / 10 + 1;
   for ( blk = 0; blk < nblocks; blk++ )
   {
      if ( output_level > 0 && blk % printflag == 0 && blk != 0 ) 
         printf("%4d : Schwarz : processing block %6d (%6d)\n",mypid,blk,nblocks);
      mat_ia  = sch_ptr->bmat_ia[blk];
      mat_ja  = sch_ptr->bmat_ja[blk];
      mat_aa  = sch_ptr->bmat_aa[blk];
      nrows   = sch_ptr->blk_sizes[blk];
      nnz     = mat_ia[nrows];
      new_nnz = (int) (nnz * ( 1.0 + fillin ));
      new_ia  = (int *)    malloc( (nrows + 1 ) * sizeof(int) );
      new_ja  = (int *)    malloc( new_nnz * sizeof(int) );
      new_aa  = (double *) malloc( new_nnz * sizeof(double) );
      nnz       = 0;
      new_ia[0] = nnz;
      for ( i = 0; i < nrows; i++ )
      {
         index = mat_ia[i];
         cols = &(mat_ja[index]);
         vals = &(mat_aa[index]);
         rleng = mat_ia[i+1] - index;
         ddata = 0.0;
         for ( j = 0; j < rleng; j++ ) ddata += habs( vals[j] ); 
         rowNorms[i] = ddata;
      }
      printflag2 = nrows / 10 + 1;
      for ( i = 0; i < nrows; i++ )
      {
         if ( output_level > 0 && i % printflag2 == 0 && i != 0 ) 
            printf("%4d : Schwarz : block %6d row %6d (%6d)\n",mypid,blk,
                   i, nrows);
         track_leng = 0;
         index = mat_ia[i];
         cols = &(mat_ja[index]);
         vals = &(mat_aa[index]);
         rleng = mat_ia[i+1] - index;
         for ( j = 0; j < rleng; j++ ) 
         {
            dble_buf[cols[j]] = vals[j];
            track_array[track_leng++] = cols[j];
         }
         Lcount = Ucount = first = 0;
         first  = nrows;
         for ( j = 0; j < track_leng; j++ )
         {
            index = track_array[j];
            if ( dble_buf[index] != 0 ) 
            {
               if ( index < i ) Lcount++;
               else if ( index > i ) Ucount++;
               else if ( index == i ) diagonal[i] = dble_buf[index];
               if ( index < first ) first = index;
            }
         }
         Lcount  = Lcount * fillin;
         Ucount  = Ucount * fillin;
         rel_tau = tau * rowNorms[i];
         for ( j = first; j < i; j++ )
         {
            if ( habs(dble_buf[j]) > rel_tau )
            {
               ddata = dble_buf[j] / diagonal[j];
               for ( k = new_ia[j]; k < new_ia[j+1]; k++ )
               {
                  colIndex = new_ja[k];
                  if ( colIndex > j ) 
                  {
                     if ( dble_buf[colIndex] != 0.0 )
                        dble_buf[colIndex] -= (ddata * new_aa[k]);
                     else
                     {
                        dble_buf[colIndex] = - (ddata * new_aa[k]);
                        if ( dble_buf[colIndex] != 0.0 ) 
                           track_array[track_leng++] = colIndex;
                     }
                  }
               }
               dble_buf[j] = ddata;
            } 
            else dble_buf[j] = 0.0;
         }
         for ( j = 0; j < rleng; j++ ) 
         {
            vals[j] = dble_buf[cols[j]]; 
            if ( cols[j] != i ) dble_buf[cols[j]] = 0.0; 
         }
         sortcnt = 0;
         for ( j = 0; j < track_leng; j++ )
         {
            index = track_array[j];
            if ( index < i )
            {
               absval = habs( dble_buf[index] );
               if ( absval > rel_tau )
               {
                  sortcols[sortcnt] = index;
                  sortvals[sortcnt++] = absval * rowNorms[index];
               }
               else dble_buf[index] = 0.0;
            }
         }
         if ( sortcnt > Lcount ) 
         {
            HYPRE_LSI_SplitDSort(sortvals,sortcnt,sortcols,Lcount);
            for ( j = Lcount; j < sortcnt; j++ ) dble_buf[sortcols[j]] = 0.0;
         }
         for ( j = 0; j < rleng; j++ ) 
         {
            if ( cols[j] < i && vals[j] != 0.0 )
            {
               new_aa[nnz] = vals[j];
               new_ja[nnz++] = cols[j];
            }
         }
         for ( j = 0; j < track_leng; j++ )
         {
            index = track_array[j];
            if ( index < i && dble_buf[index] != 0.0 )
            {
               new_aa[nnz] = dble_buf[index];
               new_ja[nnz++] = index;
               dble_buf[index] = 0.0;
            }
         }
         diagonal[i] = dble_buf[i];
         if ( habs(diagonal[i]) < 1.0e-12 ) diagonal[i] = 1.0E-12;
         new_aa[nnz] = diagonal[i];
         new_ja[nnz++] = i;
         sortcnt = 0;
         for ( j = 0; j < track_leng; j++ )
         {
            index = track_array[j];
            if ( index > i )
            {
               absval = habs( dble_buf[index] );
               if ( absval > rel_tau )
               {
                  sortcols[sortcnt] = index;
                  sortvals[sortcnt++] = absval * rowNorms[index];
               }
               else dble_buf[index] = 0.0;
            }
         }
         if ( sortcnt > Ucount )
         {
            HYPRE_LSI_SplitDSort(sortvals,sortcnt,sortcols,Ucount);
            for ( j = Ucount; j < sortcnt; j++ ) dble_buf[sortcols[j]] = 0.0;
         }
         for ( j = 0; j < rleng; j++ ) 
         {
            if ( cols[j] > i && vals[j] != 0.0 )
            {
               new_aa[nnz] = vals[j];
               new_ja[nnz++] = cols[j];
            }
         }
         for ( j = 0; j < track_leng; j++ )
         {
            index = track_array[j];
            if ( index > i && dble_buf[index] != 0.0 )
            {
               new_aa[nnz] = dble_buf[index];
               new_ja[nnz++] = index;
               dble_buf[index] = 0.0;
            }
         }
         dble_buf[i] = 0.0;
         new_ia[i+1] = nnz;
      }
      free( mat_ia );
      free( mat_ja );
      free( mat_aa );
      sch_ptr->bmat_ia[blk] = new_ia;
      sch_ptr->bmat_ja[blk] = new_ja;
      sch_ptr->bmat_aa[blk] = new_aa;
      if ( nnz > new_nnz )
      {
         printf("ERROR : nnz (%d) > new_nnz (%d) \n", nnz, new_nnz);
         exit(1);
      }
      for ( j = 0; j < new_ia[sch_ptr->blk_sizes[blk]]; j++ )
      {
         if ( new_ja[j] < 0 || new_ja[j] >= sch_ptr->blk_sizes[blk] )
         {
            printf("(2) block %d has index %d\n", blk, new_ja[j]);
            exit(1);
         }
      }
   }
   free( track_array );
   free( dble_buf );
   free( diagonal );
   free( rowNorms );
   free( sortcols );
   free( sortvals );
   return 0;
}
예제 #3
0
	void ScrollBar::addScrollValueEnd(float multiplier)
	{
		this->addScrollValue(hmax(habs(this->gridSize), (float)(int)(habs(ScrollBar::ScrollDistance) * multiplier)));
	}
예제 #4
0
	bool Animator::isExpired()
	{
		return (!this->enabled || this->periods >= 0.0f && this->timer * habs(this->speed) > this->periods);
	}
예제 #5
0
int HYPRE_LSI_MatrixInverse( double **Amat, int ndim, double ***Cmat )
{
   int    i, j, k;
   double denom, **Bmat, dmax;

   (*Cmat) = NULL;
   if ( ndim == 1 ) 
   {
      if ( habs(Amat[0][0]) <= 1.0e-16 ) return -1;
      Bmat = (double **) malloc( ndim * sizeof(double*) );
      for ( i = 0; i < ndim; i++ ) 
         Bmat[i] = (double *) malloc( ndim * sizeof(double) ); 
      Bmat[0][0] = 1.0 / Amat[0][0];
      (*Cmat) = Bmat;
      return 0;
   }
   if ( ndim == 2 )
   {
      denom = Amat[0][0] * Amat[1][1] - Amat[0][1] * Amat[1][0];
      if ( habs( denom ) <= 1.0e-16 ) return -1;
      Bmat = (double **) malloc( ndim * sizeof(double*) );
      for ( i = 0; i < ndim; i++ ) 
         Bmat[i] = (double *) malloc( ndim * sizeof(double) ); 
      Bmat[0][0] = Amat[1][1] / denom;
      Bmat[1][1] = Amat[0][0] / denom;
      Bmat[0][1] = - ( Amat[0][1] / denom );
      Bmat[1][0] = - ( Amat[1][0] / denom );
      (*Cmat) = Bmat;
      return 0;
   }
   else
   {
      Bmat = (double **) malloc( ndim * sizeof(double*) );
      for ( i = 0; i < ndim; i++ ) 
      { 
         Bmat[i] = (double *) malloc( ndim * sizeof(double) ); 
         for ( j = 0; j < ndim; j++ ) Bmat[i][j] = 0.0;
         Bmat[i][i] = 1.0;
      } 
      for ( i = 1; i < ndim; i++ ) 
      {
         for ( j = 0; j < i; j++ ) 
         {
            if ( habs(Amat[j][j]) < 1.0e-16 ) return -1;
            denom = Amat[i][j] / Amat[j][j];
            for ( k = 0; k < ndim; k++ ) 
            {
               Amat[i][k] -= denom * Amat[j][k];
               Bmat[i][k] -= denom * Bmat[j][k];
            }
         }
      }
      for ( i = ndim-2; i >= 0; i-- ) 
      {
         for ( j = ndim-1; j >= i+1; j-- ) 
         {
            if ( habs(Amat[j][j]) < 1.0e-16 ) return -1;
            denom = Amat[i][j] / Amat[j][j];
            for ( k = 0; k < ndim; k++ ) 
            {
               Amat[i][k] -= denom * Amat[j][k];
               Bmat[i][k] -= denom * Bmat[j][k];
            }
         }
      }
      for ( i = 0; i < ndim; i++ ) 
      {
         denom = Amat[i][i];
         if ( habs(denom) < 1.0e-16 ) return -1;
         for ( j = 0; j < ndim; j++ ) Bmat[i][j] /= denom;
      }

      for ( i = 0; i < ndim; i++ ) 
         for ( j = 0; j < ndim; j++ ) 
            if ( habs(Bmat[i][j]) < 1.0e-17 ) Bmat[i][j] = 0.0;
      dmax = 0.0;
      for ( i = 0; i < ndim; i++ ) 
      {
         for ( j = 0; j < ndim; j++ ) 
            if ( habs(Bmat[i][j]) > dmax ) dmax = habs(Bmat[i][j]);
/*
         for ( j = 0; j < ndim; j++ ) 
            if ( habs(Bmat[i][j]/dmax) < 1.0e-15 ) Bmat[i][j] = 0.0;
*/
      }
      (*Cmat) = Bmat;
      if ( dmax > 1.0e6 ) return 1;
      else                return 0;
   }
}
예제 #6
0
int HYPRE_LSI_PolySetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A_csr,
                        HYPRE_ParVector b,   HYPRE_ParVector x )
{
   int            i, j, my_id, startRow, endRow, order;
   int            pos_diag, neg_diag;
   int            rowLeng, *colInd, *row_partition;
   double         *coefs=NULL, rowsum, max_norm, *colVal;
   HYPRE_LSI_Poly *poly_ptr = (HYPRE_LSI_Poly *) solver;
#ifndef HYPRE_SEQUENTIAL
   double         dtemp;
#endif

   /* ---------------------------------------------------------------- */
   /* initialize structure                                             */
   /* ---------------------------------------------------------------- */

   order = poly_ptr->order;
   coefs = (double *) malloc((order+1) * sizeof(double));
   poly_ptr->coefficients = coefs;

   /* ---------------------------------------------------------------- */
   /* compute matrix norm                                              */
   /* ---------------------------------------------------------------- */

   HYPRE_ParCSRMatrixGetRowPartitioning( A_csr, &row_partition );
#ifdef HYPRE_SEQUENTIAL
   my_id = 0;
#else
   MPI_Comm_rank(poly_ptr->comm, &my_id);
#endif

   startRow  = row_partition[my_id];
   endRow    = row_partition[my_id+1] - 1;
   hypre_TFree( row_partition ); 
   poly_ptr->Nrows = endRow - startRow + 1;

   max_norm = 0.0;
   pos_diag = neg_diag = 0;
   for ( i = startRow; i <= endRow; i++ )
   {
      HYPRE_ParCSRMatrixGetRow(A_csr, i, &rowLeng, &colInd, &colVal);
      rowsum = 0.0;
      for (j = 0; j < rowLeng; j++)
      {
         rowsum += habs(colVal[j]);
         if ( colInd[j] == i && colVal[j] > 0.0 ) pos_diag++;
         if ( colInd[j] == i && colVal[j] < 0.0 ) neg_diag++;
      }
      if ( rowsum > max_norm ) max_norm = rowsum;
      HYPRE_ParCSRMatrixRestoreRow(A_csr, i, &rowLeng, &colInd, &colVal);
   }
#ifndef HYPRE_SEQUENTIAL
   MPI_Allreduce(&max_norm, &dtemp, 1, MPI_INT, MPI_MAX, poly_ptr->comm); 
#endif
   if ( pos_diag == 0 && neg_diag > 0 ) max_norm = - max_norm;

   /* ---------------------------------------------------------------- */
   /* fill in the coefficient table                                    */
   /* ---------------------------------------------------------------- */

   switch ( order ) 
   {
       case 0: coefs[0] = 1.0;     break;
       case 1: coefs[0] = 5.0;     coefs[1] = -1.0;   break;
       case 2: coefs[0] = 14.0;    coefs[1] = -7.0;   coefs[2] = 1.0; 
               break;
       case 3: coefs[0] = 30.0;    coefs[1] = -27.0;  coefs[2] = 9.0; 
               coefs[3] = -1.0;    break;
       case 4: coefs[0] = 55.0;    coefs[1] = -77.0;   coefs[2] = 44.0;
               coefs[3] = -11.0;   coefs[4] = 1.0;     break;
       case 5: coefs[0] = 91.0;    coefs[1] = -182.0;  coefs[2] = 156.0;
               coefs[3] = -65.0;   coefs[4] = 13.0;    coefs[5] = -1.0;
               break;
       case 6: coefs[0] = 140.0;   coefs[1] = -378.0;  coefs[2] = 450.0;
               coefs[3] = -275.0;  coefs[4] = 90.0;    coefs[5] = -15.0;
               coefs[6] = 1.0;     break;
       case 7: coefs[0] = 204.0;   coefs[1] = -714.0;  coefs[2] = 1122.0; 
               coefs[3] = -935.0;  coefs[4] = 442.0;   coefs[5] = -119.0;
               coefs[6] = 17.0;    coefs[7] = -1.0;    break;
       case 8: coefs[0] = 285.0;   coefs[1] = -1254.0; coefs[2] = 2508.0;
               coefs[3] = -2717.0; coefs[4] = 1729.0;  coefs[5] = -665.0;
               coefs[6] = 152.0;   coefs[7] = -19.0;   coefs[8] = 1.0;
               break;
   }
   for( i = 0; i <= order; i++ )
      coefs[i] *= pow( 4.0 / max_norm, (double) i);

   return 0;
}