예제 #1
0
파일: matrix.c 프로젝트: danielfmva/ert
void matrix_set_many_on_column(matrix_type * matrix , int row_offset , int elements , const double * data , int column) {
  if ((row_offset + elements) <= matrix->rows) {
    if (matrix->row_stride == 1)  /* Memory is continous ... */
      memcpy( &matrix->data[ GET_INDEX( matrix , row_offset , column) ] , data , elements * sizeof * data);
    else {
      int i;
      for (i = 0; i < elements; i++)
        matrix->data[ row_offset + GET_INDEX( matrix , i , column) ] = data[i];
    }
  } else
    util_abort("%s: range violation \n" , __func__);
}
예제 #2
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_det2( const matrix_type * A) {
  if ((A->rows == 2) && (A->columns == 2)) {
    double a00 = A->data[GET_INDEX(A,0,0)];
    double a01 = A->data[GET_INDEX(A,0,1)];
    double a10 = A->data[GET_INDEX(A,1,0)];
    double a11 = A->data[GET_INDEX(A,1,1)];

    return a00 * a11 - a10 * a01;
  } else {
    util_abort("%s: hardcoded for 2x2 matrices A is: %d x %d \n",__func__, A->rows , A->columns);
    return 0;
  }
}
예제 #3
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_row_column_dot_product(const matrix_type * m1 , int row1 , const matrix_type * m2 , int col2) {
  if (m1->columns != m2->rows)
    util_abort("%s: size mismatch: m1:[%d,%d]   m2:[%d,%d] \n",__func__ , matrix_get_rows( m1 ) , matrix_get_columns( m1 ) , matrix_get_rows( m2 ) , matrix_get_columns( m2 ));

  {
    int k;
    double sum = 0;
    for( k = 0; k < m1->columns; k++)
      sum += m1->data[ GET_INDEX(m1 , row1 , k) ] * m2->data[ GET_INDEX(m2, k , col2) ];

    return sum;
  }
}
예제 #4
0
파일: matrix.c 프로젝트: YingfangZhou/ert
bool matrix_columns_equal( const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2) {
  if (m1->rows != m2->rows)
    return false;

  {
    int row;
    for (row=0; row < m1->rows; row++) {
      if (memcmp( &m1->data[ GET_INDEX(m1 , row , col1)]  , &m2->data[ GET_INDEX(m2 , row , col2)] , sizeof * m1->data) != 0)
        return false;
    }
  }

  return true;
}
예제 #5
0
파일: matrix.c 프로젝트: YingfangZhou/ert
void matrix_transpose(const matrix_type * A , matrix_type * T) {
  if ((A->columns == T->rows) && (A->rows == T->columns)) {
    int i,j;
    for (i=0; i < A->rows; i++) {
      for (j=0; j < A->columns; j++) {
        size_t src_index    = GET_INDEX(A , i , j );
        size_t target_index = GET_INDEX(T , j , i );

        T->data[ target_index ] = A->data[ src_index ];
      }
    }
  } else
    util_abort("%s: size mismatch\n",__func__);
}
int reset_pnodes(int curr, int pnode)
{
	struct msm_bus_inode_info *info;
	struct msm_bus_fabric_device *fabdev;
	int index, next_pnode;
	fabdev = msm_bus_get_fabric_device(GET_FABID(curr));
	index = GET_INDEX(pnode);
	info = fabdev->algo->find_node(fabdev, curr);
	if (!info) {
		MSM_BUS_ERR("Cannot find node info!\n");
		return -ENXIO;
	}

	MSM_BUS_DBG("Starting the loop--remove\n");
	do {
		struct msm_bus_inode_info *hop;
		fabdev = msm_bus_get_fabric_device(GET_FABID(curr));
		if (!fabdev) {
			MSM_BUS_ERR("Fabric not found\n");
				return -ENXIO;
		}

		next_pnode = info->pnode[index].next;
		info->pnode[index].next = -2;
		curr = GET_NODE(next_pnode);
		index = GET_INDEX(next_pnode);
		if (IS_NODE(curr))
			hop = fabdev->algo->find_node(fabdev, curr);
		else
			hop = fabdev->algo->find_gw_node(fabdev, curr);
		if (!hop) {
			MSM_BUS_ERR("Null Info found for hop\n");
			return -ENXIO;
		}

		MSM_BUS_DBG("%d[%d] = %d\n", info->node_info->priv_id, index,
			info->pnode[index].next);
		MSM_BUS_DBG("num_pnodes: %d: %d\n", info->node_info->priv_id,
			info->num_pnodes);
		info = hop;
	} while (GET_NODE(info->pnode[index].next) != info->node_info->priv_id);

	info->pnode[index].next = -2;
	MSM_BUS_DBG("%d[%d] = %d\n", info->node_info->priv_id, index,
		info->pnode[index].next);
	MSM_BUS_DBG("num_pnodes: %d: %d\n", info->node_info->priv_id,
		info->num_pnodes);
	return 0;
}
예제 #7
0
파일: matrix.c 프로젝트: YingfangZhou/ert
// Comment
void matrix_inplace_diag_sqrt(matrix_type *Cd)
{
  int nrows = Cd->rows;

  if (Cd->rows != Cd->columns) {
    util_abort("%s: size mismatch \n",__func__);
  }
  else{
    int i;
    for ( i=0; i<nrows; i++)
      {
        Cd->data[GET_INDEX(Cd , i , i)] = sqrt(Cd->data[GET_INDEX(Cd , i , i)]);
      }
  }
}
예제 #8
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_column_column_dot_product(const matrix_type * m1 , int col1 , const matrix_type * m2 , int col2) {
  if (m1->rows != m2->rows)
    util_abort("%s: size mismatch \n",__func__);

  if (col1 >= m1->columns || col2 >= m2->columns)
    util_abort("%s: size mismatch \n",__func__);
  {
    int row;
    double sum = 0;
    for( row = 0; row < m1->rows; row++)
      sum += m1->data[ GET_INDEX(m1 , row , col1) ] * m2->data[ GET_INDEX(m2, row , col2) ];

    return sum;
  }
}
예제 #9
0
파일: matrix.c 프로젝트: YingfangZhou/ert
/* Updates matrix A by subtracting matrix B - elementwise. */
void matrix_inplace_sub(matrix_type * A , const matrix_type * B) {
  if ((A->rows == B->rows) && (A->columns == B->columns)) {
    int i,j;

    for (j = 0; j < A->columns; j++)
      for (i=0; i < A->rows; i++)
        A->data[ GET_INDEX(A,i,j) ] -= B->data[ GET_INDEX(B,i,j) ];

  } else
    util_abort("%s: size mismatch  A:[%d,%d]   B:[%d,%d]\n",__func__ ,
               matrix_get_rows(A),
               matrix_get_columns(A),
               matrix_get_rows(B),
               matrix_get_columns(B));
}
예제 #10
0
파일: geo.nappe.c 프로젝트: Moeryn/PRCD-TP5
/*****************************************
 * Read nappe characterization in a file *
 *****************************************/
GEO *
file_geo_nappe (BYTE Type, FILE *File)
{
  GEO_NAPPE  *Geo;
  PNT        *Pnt, *PntA, *PntB, *PntC, *PntD;
  FCT        *Fct;
  VECTOR     U, V;
  REAL       Real;
  INDEX      Index;

  INIT_MEM (Geo, 1, GEO_NAPPE);
  Geo->Type = Type;
  GET_INDEX (Geo->NbrPnt);
  INIT_MEM (Geo->TabPnt, Geo->NbrPnt, PNT);
  GET_INDEX (Geo->NbrFct);
  INIT_MEM (Geo->TabFct, Geo->NbrFct, FCT);
  Geo->Min.x = Geo->Min.y = Geo->Min.z =  INFINITY;
  Geo->Max.x = Geo->Max.y = Geo->Max.z = -INFINITY;

  for (Index = 0, Pnt = Geo->TabPnt; Index < Geo->NbrPnt; Index++, Pnt++) {
    GET_VECTOR (Pnt->Point);
    VEC_MIN (Geo->Min, Pnt->Point);
    VEC_MAX (Geo->Max, Pnt->Point);
  }

  for (Index = 0, Fct = Geo->TabFct; Index < Geo->NbrFct; Index++, Fct++) {
    if (fscanf (File, " ( %d %d %d %d )", &Fct->i, &Fct->j, &Fct->k, &Fct->l) < 4)
      return (FALSE);
    Fct->NumFct = Index;
    PntA = Geo->TabPnt + Fct->i; 
    PntB = Geo->TabPnt + Fct->j;
    PntC = Geo->TabPnt + Fct->k;
    PntD = Geo->TabPnt + Fct->l;
    VEC_SUB (U, PntC->Point, PntA->Point);
    VEC_SUB (V, PntD->Point, PntB->Point);
    VEC_CROSS (Fct->Normal, U, V);
    VEC_UNIT (Fct->Normal, Real);
    VEC_INC (PntA->Normal, Fct->Normal);
    VEC_INC (PntB->Normal, Fct->Normal);
    VEC_INC (PntC->Normal, Fct->Normal);
    VEC_INC (PntD->Normal, Fct->Normal);
  }

  for (Index = 0, Pnt = Geo->TabPnt; Index < Geo->NbrPnt; Index++, Pnt++)
    VEC_UNIT (Pnt->Normal, Real);

  return ((GEO *) Geo);
}
예제 #11
0
U_CAPI UBiDiDirection U_EXPORT2
ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
                   int32_t *pLogicalStart, int32_t *pLength)
{
    int32_t start;
    UErrorCode errorCode = U_ZERO_ERROR;
    RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, errorCode, UBIDI_LTR);
    ubidi_getRuns(pBiDi, &errorCode);
    if(U_FAILURE(errorCode)) {
        return UBIDI_LTR;
    }
    RETURN_IF_BAD_RANGE(runIndex, 0, pBiDi->runCount, errorCode, UBIDI_LTR);

    start=pBiDi->runs[runIndex].logicalStart;
    if(pLogicalStart!=NULL) {
        *pLogicalStart=GET_INDEX(start);
    }
    if(pLength!=NULL) {
        if(runIndex>0) {
            *pLength=pBiDi->runs[runIndex].visualLimit-
                     pBiDi->runs[runIndex-1].visualLimit;
        } else {
            *pLength=pBiDi->runs[0].visualLimit;
        }
    }
    return (UBiDiDirection)GET_ODD_BIT(start);
}
예제 #12
0
static void output_line(FILE *out_file, DATA *data, DPOINT *where, 
		double *est, int n_outfl) {
	int i;

	assert(out_file != NULL);
	assert(out_file != stdout);

	if (data->mode & X_BIT_SET) {
		fprintf(out_file, " ");
		fprintf(out_file, gl_format, where->x);
	}
	if (data->mode & Y_BIT_SET) {
		fprintf(out_file, " ");
		fprintf(out_file, gl_format, where->y);
	}
	if (data->mode & Z_BIT_SET) {
		fprintf(out_file, " ");
		fprintf(out_file, gl_format, where->z);
	}
	if (data->mode & S_BIT_SET)
		fprintf(out_file, " %d", where->u.stratum + strata_min);
	if (data->colnvalue > 0) {
		fprintf(out_file, " ");
		fprintf(out_file, gl_format, where->attr);
	}
	for (i = 0; i < n_outfl; i++)
		fprintf(out_file, " %s", my_dtoa(gl_format, &(est[i])));

    if (data->point_ids)
        fprintf(out_file, " %s",data->point_ids[GET_INDEX(where)]);
    
	fprintf(out_file, "\n");
	return;
}
예제 #13
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_get_column_abssum(const matrix_type * matrix , int column) {
  double sum = 0;
  int i;
  for (i=0; i < matrix->rows; i++)
    sum += fabs( matrix->data[ GET_INDEX( matrix , i , column ) ] );
  return sum;
}
예제 #14
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_get_row_sum(const matrix_type * matrix , int row) {
  double sum = 0;
  int j;
  for (j=0; j < matrix->columns; j++)
    sum += matrix->data[ GET_INDEX( matrix , row , j ) ];
  return sum;
}
예제 #15
0
double run_experiment_ji ( mtype_t * matrix , mtype_t scalar , int buffer_size ) {
    int i, j, iter;
    hptimer_t start , end;
    double final_time ;
    
    start = get_time ();
    for ( iter = 0; iter < MAX_ITERS ; ++ iter ) {
        for (j = 0; j < buffer_size ; ++j ) {
            for (i = 0; i < buffer_size ; ++i ) {
                matrix [ GET_INDEX (i, j, buffer_size ) ] = scalar * matrix [ GET_INDEX (i, j, buffer_size ) ];
            }
        }
    }
    end = get_time ();
    return final_time = diff_timers (start , end) / MAX_ITERS ;
}
예제 #16
0
static
int
choice( void )
{
    int i, n;

    rb->yield();

    for( n = i = 0 ; i < 81 ; ++i )
        if( IS_EMPTY( i ) )
        {
            possible[ n ] = SET_INDEX( i ) | SET_DIGIT( numset( board[ i ] ) );

            /* Inconsistency if square unknown, but nothing possible */
            if( 9 == GET_DIGIT( possible[ n ] ) )
                return -2;
            ++n;
        }

    if( 0 == n )
        return -1;      /* All squares known */

    rb->qsort( possible, n, sizeof( possible[ 0 ] ), cmp );
    return GET_INDEX( possible[ 0 ] );
}
예제 #17
0
/***************************************************************
 * Ensures the velocity field is non divergent i.e. incompressible:
 * Solves a poisson equation to compute a gradient field and then
 * subtracts this from the current velocity field to obtain an
 * incompressible field. When solving for pressure it sets the
 * cells pressure field.
 ***************************************************************/
void FGS_Fluid_Solver2DS :: project (FLUID_DATA ux, FLUID_DATA uy, FLUID_DATA pressure, FLUID_DATA divergence){

    double h           = 1.0 / N * -0.5;
    double half_width  = width   * 0.5;
    double half_height = height  * 0.5;
    int    cell;
    double north, south, east, west;
    
    for (int i=1 ; i <= width; i++ )
        for (int j=1 ; j <= height; j++ ){
            cell  = GET_INDEX(i,j);
            north = grid[GET_INDEX(i,j-1)].data[uy];
            south = grid[GET_INDEX(i,j+1)].data[uy];
            east  = grid[GET_INDEX(i+1,j)].data[ux];
            west  = grid[GET_INDEX(i-1,j)].data[ux];
            
            grid[cell].data[divergence] = h * (east-west+south-north);
            grid[cell].data[pressure]   = 0;
        }
    
    set_boundary (SET_FOR_NON_VELOCITY_COMPONENT, divergence);
    set_boundary (SET_FOR_NON_VELOCITY_COMPONENT, pressure);
    
    computing_pressure = true;
    linear_solve (SET_FOR_NON_VELOCITY_COMPONENT, pressure, divergence, 1, 0.25);
    computing_pressure = false;
    
    for (int i = 1; i <= width; i++)
        for (int j = 1; j <= height; j++){
            
            cell  = GET_INDEX(i,j);
            north = grid[GET_INDEX(i,j-1)].data[pressure];
            south = grid[GET_INDEX(i,j+1)].data[pressure];
            east  = grid[GET_INDEX(i+1,j)].data[pressure];
            west  = grid[GET_INDEX(i-1,j)].data[pressure];
            
            double u_in_cell = grid[cell].data[ux],
                   v_in_cell = grid[cell].data[uy];
            
            grid[cell].data[ux] = u_in_cell - (half_width  * (east  - west));
            grid[cell].data[uy] = v_in_cell - (half_height * (south - north));
            
        }
    set_boundary(SET_FOR_HORIZONTAL_COMPONENT, ux);
    set_boundary(SET_FOR_VERTICAL_COMPONENT,   uy);

}
예제 #18
0
/*
 * Prevents PCI Express ASPM (Active State Power Management) being enabled.
 *
 * Save the register offset, where the ASPM control bits are located,
 * for each PCI Express device that is in the device list of
 * the root port in an array for fast indexing. Replace the bus ops
 * with the modified one.
 */
static void pcie_rootport_aspm_quirk(struct pci_dev *pdev)
{
    int i;
    struct pci_bus  *pbus;
    struct pci_dev *dev;

    if ((pbus = pdev->subordinate) == NULL)
        return;

    /*
     * Check if the DID of pdev matches one of the six root ports. This
     * check is needed in the case this function is called directly by the
     * hot-plug driver.
     */
    if ((pdev->device < PCI_DEVICE_ID_INTEL_MCH_PA) ||
            (pdev->device > PCI_DEVICE_ID_INTEL_MCH_PC1))
        return;

    if (list_empty(&pbus->devices)) {
        /*
         * If no device is attached to the root port at power-up or
         * after hot-remove, the pbus->devices is empty and this code
         * will set the offsets to zero and the bus ops to parent's bus
         * ops, which is unmodified.
         */
        for (i = GET_INDEX(pdev->device, 0); i <= GET_INDEX(pdev->device, 7); ++i)
            quirk_aspm_offset[i] = 0;

        pci_bus_set_ops(pbus, pbus->parent->ops);
    } else {
        /*
         * If devices are attached to the root port at power-up or
         * after hot-add, the code loops through the device list of
         * each root port to save the register offsets and replace the
         * bus ops.
         */
        list_for_each_entry(dev, &pbus->devices, bus_list)
        /* There are 0 to 8 devices attached to this bus */
        quirk_aspm_offset[GET_INDEX(pdev->device, dev->devfn)] =
            dev->pcie_cap + PCI_EXP_LNKCTL;

        pci_bus_set_ops(pbus, &quirk_pcie_aspm_ops);
        dev_info(&pbus->dev, "writes to ASPM control bits will be ignored\n");
    }

}
예제 #19
0
/***************************************************************
 * Computes a Gauss seidel relaxation to solve AX=B for the
 * unknowns X using forward substitution (the higher the number
 * of iterations the closer the resultant vector X will be
 * to convergence). 
 ***************************************************************/
void FGS_Fluid_Solver2DS :: linear_solve (BOUNDARY_CONDITION  b, FLUID_DATA to, FLUID_DATA from, double a, double coef){
    for (int k = 0 ; k < iterations; k++){
        for (int i = 1 ; i <= width; i++){
            for (int j = 1 ; j <= height; j++){
                int    cell_ij_index = GET_INDEX(i, j);
                double w             = grid[GET_INDEX(i-1, j)].data[to], e = grid[GET_INDEX(i+1, j)].data[to],
                       n             = grid[GET_INDEX(i, j-1)].data[to], s = grid[GET_INDEX(i, j+1)].data[to],
                       c0            = grid[cell_ij_index].data[from];
                
                grid[cell_ij_index].data[to] = coef * (c0 + a * (w+e+s+n));
                
                if (computing_pressure) grid[cell_ij_index].data[PRESSURE] = grid[cell_ij_index].data[to];
            }
        }
        set_boundary(b, to);
    }
}
예제 #20
0
파일: matrix.c 프로젝트: YingfangZhou/ert
void matrix_copy_row(matrix_type * target_matrix, const matrix_type * src_matrix , int target_row, int src_row) {
  matrix_assert_equal_columns( target_matrix , src_matrix );
  {
    int col;
    for(col = 0; col < target_matrix->columns; col++)
      target_matrix->data[ GET_INDEX( target_matrix , target_row , col)] = src_matrix->data[ GET_INDEX( src_matrix, src_row, col)];
  }
}
예제 #21
0
파일: matrix.c 프로젝트: YingfangZhou/ert
void matrix_copy_column(matrix_type * target_matrix, const matrix_type * src_matrix , int target_column, int src_column) {
  matrix_assert_equal_rows( target_matrix , src_matrix );
  {
    int row;
    for(row = 0; row < target_matrix->rows; row++)
      target_matrix->data[ GET_INDEX( target_matrix, row , target_column)] = src_matrix->data[ GET_INDEX( src_matrix, row, src_column)];
  }
}
/**
 * add_path_node: Adds the path information to the current node
 * @info: Internal node info structure
 * @next: Combination of the id and index of the next node
 * Function returns: Number of pnodes (path_nodes) on success,
 * error on failure.
 *
 * Every node maintains the list of path nodes. A path node is
 * reached by finding the node-id and index stored at the current
 * node. This makes updating the paths with requested bw and clock
 * values efficient, as it avoids lookup for each update-path request.
 */
static int add_path_node(struct msm_bus_inode_info *info, int next)
{
	struct path_node *pnode;
	int i;
	if (ZERO_OR_NULL_PTR(info)) {
		MSM_BUS_ERR("Cannot find node info!: id :%d\n",
				info->node_info->priv_id);
		return -ENXIO;
	}

	for (i = 0; i <= info->num_pnodes; i++) {
		if (info->pnode[i].next == -2) {
			MSM_BUS_DBG("Reusing pnode for info: %d at index: %d\n",
				info->node_info->priv_id, i);
			info->pnode[i].clk[DUAL_CTX] = 0;
			info->pnode[i].clk[ACTIVE_CTX] = 0;
			info->pnode[i].bw[DUAL_CTX] = 0;
			info->pnode[i].bw[ACTIVE_CTX] = 0;
			info->pnode[i].next = next;
			MSM_BUS_DBG("%d[%d] : (%d, %d)\n",
				info->node_info->priv_id, i, GET_NODE(next),
				GET_INDEX(next));
			return i;
		}
	}

	info->num_pnodes++;
	pnode = krealloc(info->pnode,
		((info->num_pnodes + 1) * sizeof(struct path_node))
		, GFP_KERNEL);
	if (ZERO_OR_NULL_PTR(pnode)) {
		MSM_BUS_ERR("Error creating path node!\n");
		info->num_pnodes--;
		return -ENOMEM;
	}
	info->pnode = pnode;
	info->pnode[info->num_pnodes].clk[DUAL_CTX] = 0;
	info->pnode[info->num_pnodes].clk[ACTIVE_CTX] = 0;
	info->pnode[info->num_pnodes].bw[DUAL_CTX] = 0;
	info->pnode[info->num_pnodes].bw[ACTIVE_CTX] = 0;
	info->pnode[info->num_pnodes].next = next;
	MSM_BUS_DBG("%d[%d] : (%d, %d)\n", info->node_info->priv_id,
		info->num_pnodes, GET_NODE(next), GET_INDEX(next));
	return info->num_pnodes;
}
예제 #23
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_get_row_abssum(const matrix_type * matrix , int row) {
  double sum_abs = 0;
  int j;
  for ( j=0; j < matrix->columns; j++) {
    double m = matrix->data[ GET_INDEX( matrix , row , j ) ];
    sum_abs += fabs( m );
  }
  return sum_abs;
}
예제 #24
0
파일: matrix.c 프로젝트: YingfangZhou/ert
double matrix_get_row_sum2(const matrix_type * matrix , int row) {
  double sum2 = 0;
  int j;
  for ( j=0; j < matrix->columns; j++) {
    double m = matrix->data[ GET_INDEX( matrix , row , j ) ];
    sum2 += m*m;
  }
  return sum2;
}
예제 #25
0
파일: matrix.c 프로젝트: YingfangZhou/ert
void matrix_diag_set_scalar(matrix_type * matrix , double value) {
  if (matrix->rows == matrix->columns) {
    int i;
        matrix_set(matrix , 0);
    for ( i=0; i < matrix->rows; i++)
      matrix->data[ GET_INDEX(matrix , i , i) ] = value;
  } else
    util_abort("%s: size mismatch \n",__func__);
}
예제 #26
0
파일: res-mgr.c 프로젝트: septag/darkhammer
/*************************************************************************************************
 * Inlines
 */
INLINE struct rs_resource* rs_resource_get(reshandle_t hdl) {
    uint idx = GET_INDEX(hdl);
    ASSERT(idx < (uint)g_rs.ress.item_cnt);

    struct rs_resource* r = &((struct rs_resource*)g_rs.ress.buffer)[idx];
    ASSERT(r->hdl != INVALID_HANDLE);
    ASSERT(GET_ID(r->hdl) == GET_ID(hdl));
    return r;
}
예제 #27
0
파일: matrix.c 프로젝트: YingfangZhou/ert
/**
   Return the sum of the squares on column.
*/
double matrix_get_column_sum2(const matrix_type * matrix , int column) {
  double sum2 = 0;
  int i;
  for ( i=0; i < matrix->rows; i++) {
    double m = matrix->data[ GET_INDEX( matrix , i , column ) ];
    sum2 += m*m;
  }
  return sum2;
}
예제 #28
0
파일: matrix.c 프로젝트: YingfangZhou/ert
void matrix_diag_set(matrix_type * matrix , const double * diag) {
  if (matrix->rows == matrix->columns) {
    int i;
        matrix_set(matrix , 0);
    for ( i=0; i < matrix->rows; i++)
      matrix->data[ GET_INDEX(matrix , i , i) ] = diag[i];
  } else
    util_abort("%s: size mismatch \n",__func__);
}
예제 #29
0
extern int
mem_blocks_pool_get_block_index(const MEMORY_BLOCKS_POOL *pool, int id) {
    int real_id = GET_ID(id);
    int index = GET_INDEX(id);

    if (pool->ids[index] == real_id)
        return index;

    return -1;
}
예제 #30
0
/***************************************************************
 * Computes for each cell a backwards particle trace: Linearly
 * interpolates a virtual particle from the center of each cell
 * backwards in time (dt) using the velocity in the cell (Uxy)
 * and copies the value (density or velocity) from this
 * 'previous' position into the cell. Also computes the average
 * density if called from the density step.
 ***************************************************************/
void FGS_Fluid_Solver2DS :: advect (BOUNDARY_CONDITION  b,  FLUID_DATA to, FLUID_DATA from, FLUID_DATA ux, FLUID_DATA uy){
    
    int      i0, j0, i1, j1;
    
    double   x,  y,  s0, t0,
             s1, t1, deltaT0,
             nw, ne, se, sw;
    
    deltaT0 = deltaT*N;
    
    for (int i = 1; i <= width; i++) {
        for (int j = 1; j <= height; j++) {
            
            int cell_ij_index = GET_INDEX(i,j);
            
            x = i-deltaT0 * grid[cell_ij_index].data[ux];
            y = j-deltaT0 * grid[cell_ij_index].data[uy];
            
            if      (x < 0.5         )   x = 0.5;
            else if (x > width + 0.5 )   x = width+0.5;
            if      (y < 0.5         )   y = 0.5;
            else if (y > height + 0.5)   y = height+0.5;
            
            i0 = ((int) x); j0 = ((int) y);
            i1 = i0 + 1;    j1 = j0 + 1;
            
            s1 = x-i0;      s0 = 1-s1;
            t1 = y-j0;      t0 = 1-t1;
            
            nw = grid[GET_INDEX(i0, j0)].data[from];
            ne = grid[GET_INDEX(i1, j0)].data[from];
            se = grid[GET_INDEX(i1, j1)].data[from];
            sw = grid[GET_INDEX(i0, j1)].data[from];
            
            grid[cell_ij_index].data[to] = s0 * (t0 * nw + t1 * sw) + s1 * (t0 * ne + t1 * se);
            if(computing_density)
                d_av += grid[cell_ij_index].data[to];
        }
    }
    if(computing_density)
        d_av *= inv_dims;
    set_boundary (b, to);
}