Exemple #1
0
TEST(BitopsTest, fill0){
  std::bitset<64> bitset;
  bitset.set();
  fill0(bitset);
  EXPECT_TRUE(bitset.none());
  bitset.set();
  fill0(bitset, 20, 41);
  for (size_t i = 0; i < bitset.size(); ++i) {
    if (i >= 20 && i <= 40){
      EXPECT_FALSE(bitset.test(i));
    } else {
      EXPECT_TRUE(bitset.test(i));
    }
  }
}
Exemple #2
0
//computes the tfce score of a 3D statistic map(dim_x*dim_y*dim_z)
float * tfce_score(float * map, int dim_x, int dim_y, int dim_z, float E, float H, float dh){
	int n = dim_x * dim_y * dim_z;
	float minData = 0; float maxData = 0; float rangeData = 0;
	float * posData; float * negData;
	float precision, increment;
	float h;
	int i,j;
	int * indexPosData; int * indexNegData; int * indexMatchingData;
	float * clustered_map;
	int num_clusters;
	int numOfElementsMatching;
	float * toReturn = fill0(n);
	float minPos = 0; float maxPos = 0;
	int steps = 0;

	findMinMax(map, n, &minData, &maxData, &rangeData);
	precision = rangeData/dh;

	if (precision > 200) {
		increment = rangeData/200;
	} else{
		increment = rangeData/precision;	
	}

	steps = ceil(rangeData / increment);
#pragma omp parallel for
	for (i = 0; i < steps; i++) {
		computeTfceIteration(minData + i*increment, map, n, dim_x, dim_y, dim_z, E, H, increment, toReturn);
	}
	
	return toReturn;
}
Exemple #3
0
void slvsml(double **u, double **rhs)
{
	void fill0(double **u, int n);
	double h=0.5;

	fill0(u,3);
	u[2][2] = -h*h*rhs[2][2]/4.0;
}
void slvsml(float ***u, float ***rhs)
/* 
   Solution of the model problem on the coarsest grid, where h = 1
   2 . The right-hand side is input
   in rhs[1..3][1..3] and the solution is returned in u[1..3][1..3].
*/
{
  void fill0(float ***u, int n);
  double h=0.5;
  double C = alpha/(h*h);
  fill0(u,3);
  u[2][2][2] = -rhs[2][2][2]/(6.0*C+1);
}
void slvsml(double **u, double **rhs, double c, double dt, double **s)
/* 
   Solution of the model problem on the coarsest grid, where h = 1
   2 . The right-hand side is input
   in rhs[1..3][1..3] and the solution is returned in u[1..3][1..3].
*/
{
  void fill0(double **u, int n);


  double h=0.5;
  c=c/(h*h);
  fill0(u,3);
  u[2][2] = (rhs[2][2]+dt*s[2][2])/(1+4.0*c);
}
void slvsml(double **u, double **rhs)
/* 
   Solution of the model problem on the coarsest grid, where h = 1
   2 . The right-hand side is input
   in rhs[1..3][1..3] and the solution is returned in u[1..3][1..3].
*/
{
  H("");
  float alpha = 1.1234e-4; // diffusivity of copper in m^2/s
  float dt = 0.00001;      // timestep chosen arbitrarily
  float dx = 0.5;          // domain is [0,1]; 2 intervals at this coarseness
  float C = alpha*dt/(dx*dx);
  void fill0(double **u, int n);
  fill0(u,3);
  u[2][2] = rhs[2][2]/(1+4.0*C);
}
Exemple #7
0
void mglin(float ***u, int n, int ncycle){
/*
  Full Multigrid Algorithm for solution of the steady state heat
  equation with forcing.  On input u[1..n][1..n] contains the
  right-hand side ρ, while on output it returns the solution.  The
  dimension n must be of the form 2j + 1 for some integer j. (j is
  actually the number of grid levels used in the solution, called ng
  below.) ncycle is the number of V-cycles to be used at each level.
*/
  unsigned int j,jcycle,jj,jpost,jpre,nf,ng=0,ngrid,nn;
  /*** setup multigrid jagged arrays ***/
  float ***iu[NGMAX+1];   /* stores solution at each grid level */
  float ***irhs[NGMAX+1]; /* stores rhs at each grid level */
  float ***ires[NGMAX+1]; /* stores residual at each grid level */
  float ***irho[NGMAX+1]; /* stores rhs during intial solution of FMG */
  
  /*** use bitshift to find the number of grid levels, stored in ng ***/
  nn=n;                   
  while (nn >>= 1) ng++;     
  
  /*** some simple input checks ***/
  if (n != 1+(1L << ng)) nrerror("n-1 must be a power of 2 in mglin.");
  if (ng > NGMAX) nrerror("increase NGMAX in mglin.");
  
  /***restrict solution to next coarsest grid (irho[ng-1])***/
  nn=n/2+1;
  ngrid=ng-1;
  irho[ngrid]=f3tensor(1,nn,1,nn,1,nn); 
  rstrct(irho[ngrid],u,nn);/* coarsens rhs (u at this point) to irho on mesh size nn */
  
  /***continue setting up coarser grids down to coarsest level***/
  while (nn > 3) { 
    nn=nn/2+1; 
    irho[--ngrid]=f3tensor(1,nn,1,nn,1,nn);
    rstrct(irho[ngrid],irho[ngrid+1],nn); 
  }
  
  /***now setup and solve coarsest level iu[1],irhs[1] ***/
  nn=3;
  iu[1]=f3tensor(1,nn,1,nn,1,nn);
  irhs[1]=f3tensor(1,nn,1,nn,1,nn);
  slvsml(iu[1],irho[1]);          /* solve the small system directly */
  free_f3tensor(irho[1],1,nn,1,nn,1,nn);
  ngrid=ng;                       /* reset ngrid to original size */

  for (j=2;j<=ngrid;j++) {        /* loop over coarse to fine, starting at level 2 */
    printf("at grid level %d\n",j);
    nn=2*nn-1;                     
    iu[j]=f3tensor(1,nn,1,nn,1,nn);     /* setup grids for lhs,rhs, and residual */
    irhs[j]=f3tensor(1,nn,1,nn,1,nn);
    ires[j]=f3tensor(1,nn,1,nn,1,nn);
    interp(iu[j],iu[j-1],nn);
    /* irho contains rhs except on fine grid where it is in u */
    copy(irhs[j],(j != ngrid ? irho[j] : u),nn); 
    /* v-cycle at current grid level */
    for (jcycle=1;jcycle<=ncycle;jcycle++) {  
      /* nf is # points on finest grid for current v-sweep */
      nf=nn;                                  
      for (jj=j;jj>=2;jj--) {                 
	for (jpre=1;jpre<=NPRE;jpre++)  /* NPRE g-s sweeps on the finest (relatively) scale */
	  relax(iu[jj],iu[jj-1],irhs[jj],nf); //need iu[jj-1] for jacobi
	resid(ires[jj],iu[jj],irhs[jj],nf); /* compute res on finest scale, store in ires */
	nf=nf/2+1;                        /* next coarsest scale */
	rstrct(irhs[jj-1],ires[jj],nf);  /* restrict residuals as rhs of next coarsest scale */
	fill0(iu[jj-1],nf);              /* set the initial solution guess to zero */
      } 
      slvsml(iu[1],irhs[1]);                  /* solve the small problem exactly */
      nf=3;                                   /* fine scale now n=3 */
      for (jj=2;jj<=j;jj++) {                 /* work way back up to current finest grid */
	nf=2*nf-1;                            /* next finest scale */
	addint(iu[jj],iu[jj-1],ires[jj],nf);  /* inter error and add to previous solution guess */
	for (jpost=1;jpost<=NPOST;jpost++)    /* do NPOST g-s sweeps */
	  relax(iu[jj],iu[jj-1],irhs[jj],nf);
      }
    }
  }

  copy(u,iu[ngrid],n);              /* copy solution into input array (implicitly returned) */

  /*** clean up memory ***/
  for (nn=n,j=ng;j>=2;j--,nn=nn/2+1) {       
    free_f3tensor(ires[j],1,nn,1,nn,1,nn);      
    free_f3tensor(irhs[j],1,nn,1,nn,1,nn);
    free_f3tensor(iu[j],1,nn,1,nn,1,nn);
    if (j != ng) free_f3tensor(irho[j],1,nn,1,nn,1,nn);
  }
  free_f3tensor(irhs[1],1,3,1,3,1,3);
  free_f3tensor(iu[1],1,3,1,3,1,3);
}
fixed_bit_vector* fixed_bit_vector_manager::allocate0() {
    fixed_bit_vector* result = allocate();
    fill0(*result);
    return result;
}
Exemple #9
0
void mglin(double **u, int n, int ncycle)
{
	void addint(double **uf, double **uc, double **res, int nf);
	void copy(double **aout, double **ain, int n);
	void fill0(double **u, int n);
	void interp(double **uf, double **uc, int nf);
	void relax(double **u, double **rhs, int n);
	void resid(double **res, double **u, double **rhs, int n);
	void rstrct(double **uc, double **uf, int nc);
	void slvsml(double **u, double **rhs);
	unsigned int j,jcycle,jj,jpost,jpre,nf,ng=0,ngrid,nn;
	double **ires[NGMAX+1],**irho[NGMAX+1],**irhs[NGMAX+1],**iu[NGMAX+1];

	nn=n;
	while (nn >>= 1) ng++;
	if (n != 1+(1L << ng)) nrerror("n-1 must be a power of 2 in mglin.");
	if (ng > NGMAX) nrerror("increase NGMAX in mglin.");
	nn=n/2+1;
	ngrid=ng-1;
	irho[ngrid]=dmatrix(1,nn,1,nn);
	rstrct(irho[ngrid],u,nn);
	while (nn > 3) {
		nn=nn/2+1;
		irho[--ngrid]=dmatrix(1,nn,1,nn);
		rstrct(irho[ngrid],irho[ngrid+1],nn);
	}
	nn=3;
	iu[1]=dmatrix(1,nn,1,nn);
	irhs[1]=dmatrix(1,nn,1,nn);
	slvsml(iu[1],irho[1]);
	free_dmatrix(irho[1],1,nn,1,nn);
	ngrid=ng;
	for (j=2;j<=ngrid;j++) {
		nn=2*nn-1;
		iu[j]=dmatrix(1,nn,1,nn);
		irhs[j]=dmatrix(1,nn,1,nn);
		ires[j]=dmatrix(1,nn,1,nn);
		interp(iu[j],iu[j-1],nn);
		copy(irhs[j],(j != ngrid ? irho[j] : u),nn);
		for (jcycle=1;jcycle<=ncycle;jcycle++) {
			nf=nn;
			for (jj=j;jj>=2;jj--) {
			for (jpre=1;jpre<=NPRE;jpre++)
				relax(iu[jj],irhs[jj],nf);
			resid(ires[jj],iu[jj],irhs[jj],nf);
			nf=nf/2+1;
			rstrct(irhs[jj-1],ires[jj],nf);
			fill0(iu[jj-1],nf);
			}
			slvsml(iu[1],irhs[1]);
			nf=3;
			for (jj=2;jj<=j;jj++) {
			nf=2*nf-1;
			addint(iu[jj],iu[jj-1],ires[jj],nf);
			for (jpost=1;jpost<=NPOST;jpost++)
				relax(iu[jj],irhs[jj],nf);
			}
		}
	}
	copy(u,iu[ngrid],n);
	for (nn=n,j=ng;j>=2;j--,nn=nn/2+1) {
		free_dmatrix(ires[j],1,nn,1,nn);
		free_dmatrix(irhs[j],1,nn,1,nn);
		free_dmatrix(iu[j],1,nn,1,nn);
		if (j != ng) free_dmatrix(irho[j],1,nn,1,nn);
	}
	free_dmatrix(irhs[1],1,3,1,3);
	free_dmatrix(iu[1],1,3,1,3);
}