Esempio n. 1
0
extern "C" void equ_init(SuperEqState *state, int wb, int channels)
{
  int i,j;

  if (state->lires1 != NULL)   free(state->lires1);
  if (state->lires2 != NULL)   free(state->lires2);
  if (state->irest != NULL)    free(state->irest);
  if (state->fsamples != NULL) free(state->fsamples);
  if (state->finbuf != NULL)    free(state->finbuf);
  if (state->outbuf != NULL)   free(state->outbuf);
  if (state->ditherbuf != NULL) free(state->ditherbuf);


  memset (state, 0, sizeof (SuperEqState));
  state->channels = channels;
  state->enable = 1;

  state->winlen = (1 << (wb-1))-1;
  state->winlenbit = wb;
  state->tabsize  = 1 << wb;
  state->fft_bits = wb;

  state->lires1   = (REAL *)equ_malloc(sizeof(REAL)*state->tabsize * state->channels);
  state->lires2   = (REAL *)equ_malloc(sizeof(REAL)*state->tabsize * state->channels);
  state->irest    = (REAL *)equ_malloc(sizeof(REAL)*state->tabsize);
  state->fsamples = (REAL *)equ_malloc(sizeof(REAL)*state->tabsize);
  state->finbuf    = (REAL *)equ_malloc(state->winlen*state->channels*sizeof(REAL));
  state->outbuf   = (REAL *)equ_malloc(state->tabsize*state->channels*sizeof(REAL));
  state->ditherbuf = (REAL *)equ_malloc(sizeof(REAL)*DITHERLEN);

  memset (state->lires1, 0, sizeof(REAL)*state->tabsize * state->channels);
  memset (state->lires2, 0, sizeof(REAL)*state->tabsize * state->channels);
  memset (state->irest, 0, sizeof(REAL)*state->tabsize);
  memset (state->fsamples, 0, sizeof(REAL)*state->tabsize);
  memset (state->finbuf, 0, state->winlen*state->channels*sizeof(REAL));
  memset (state->outbuf, 0, state->tabsize*state->channels*sizeof(REAL));
  memset (state->ditherbuf, 0, sizeof(REAL)*DITHERLEN);

  state->lires = state->lires1;
  state->cur_ires = 1;
  state->chg_ires = 1;

  for(i=0;i<DITHERLEN;i++)
	state->ditherbuf[i] = (float(rand())/RAND_MAX-0.5);

  if (fact[0] < 1) {
      for(i=0;i<=M;i++)
      {
          fact[i] = 1;
          for(j=1;j<=i;j++) fact[i] *= j;
      }
      iza = izero(alpha(aa));
  }
}
Esempio n. 2
0
static int Check_range(Element *E){
  int elmtid;
  static int init = 1;
  if(rnge){
    register int i;
    int cnt = 0;
    if(E->dim() == 3)
      for(i = 0; i < E->Nverts; ++i){
  if(      (E->vert[i].x > rnge->x[0])&&(E->vert[i].x < rnge->x[1])
        && (E->vert[i].y > rnge->y[0])&&(E->vert[i].y < rnge->y[1])
        && (E->vert[i].z > rnge->z[0])&&(E->vert[i].z < rnge->z[1])) ++cnt;
      }
    else
      for(i = 0; i < E->Nverts; ++i){
  if(   (E->vert[i].x > rnge->x[0])&&(E->vert[i].x < rnge->x[1])
     && (E->vert[i].y > rnge->y[0])&&(E->vert[i].y < rnge->y[1])) ++cnt;
      }
    return (cnt == E->Nverts) ? 1:0;
  }
  else if(elmtid = option("ELMTID")){
    static int *eids;

    if(init){
      Edge *e,*e1;
      Element *U;
      int nel = countelements(E),i;
      eids = ivector(0,nel-1);

      izero(nel,eids,1);

      eids[elmtid-1] = 1;
      /* find element */
      for(U = E; U; U = U->next)
  if(U->id == elmtid-1)
    break;

      for(i = 0; i < U->Nedges; ++i)
  for(e = U->edge[i].base; e; e = e->link)
    eids[e->eid] = 1;
      init = 0;
    }

    return eids[E->id];
  } else
    return 1;
}
Esempio n. 3
0
void equ_init(int wb)
{
  int i,j;

  if (lires1 != NULL) free(lires1);
  if (lires2 != NULL) free(lires2);
  if (rires1 != NULL) free(rires1);
  if (rires2 != NULL) free(rires2);
  if (irest != NULL) free(irest);
  if (fsamples != NULL) free(fsamples);
  if (inbuf != NULL) free(inbuf);
  if (outbuf != NULL) free(outbuf);
  if (ditherbuf != NULL) free(ditherbuf);

  winlen = (1 << (wb-1))-1;
  winlenbit = wb;
  tabsize  = 1 << wb;

  lires1   = (REAL *)malloc(sizeof(REAL)*tabsize);
  lires2   = (REAL *)malloc(sizeof(REAL)*tabsize);
  rires1   = (REAL *)malloc(sizeof(REAL)*tabsize);
  rires2   = (REAL *)malloc(sizeof(REAL)*tabsize);
  irest    = (REAL *)malloc(sizeof(REAL)*tabsize);
  fsamples = (REAL *)malloc(sizeof(REAL)*tabsize);
  inbuf    = (short *)calloc(winlen*NCH,sizeof(int));
  outbuf   = (REAL *)calloc(tabsize*NCH,sizeof(REAL));
  ditherbuf = (REAL *)malloc(sizeof(REAL)*DITHERLEN);

  lires = lires1;
  rires = rires1;
  cur_ires = 1;
  chg_ires = 1;

  for(i=0;i<DITHERLEN;i++)
	ditherbuf[i] = (float(rand())/RAND_MAX-0.5);

  for(i=0;i<=M;i++)
    {
      fact[i] = 1;
      for(j=1;j<=i;j++) fact[i] *= j;
    }

  iza = izero(alpha(aa));
}
Esempio n. 4
0
// -(N-1)/2 <= n <= (N-1)/2
static REAL win(REAL n,int N)
{
  return izero(alpha(aa)*sqrt(1-4*n*n/((N-1)*(N-1))))/iza;
}
Esempio n. 5
0
void genSurfFile(Element *E, double *x, double *y, double *z, Curve *curve)
{
	register int i;
	int      info,l,lm[4];
	int      q1 = E->qa, q2 = E->qb,*vertid,fid, cnt, cnt1;
	int      ntot = Snp*(Snp+1)/2;
	double   **sj;
	static int *chkfid;

	if(!chkfid)
	{
		chkfid = ivector(0,Snface-1);
		izero(Snface,chkfid,1);
	}

	vertid = curve->info.file.vert;

	if(E->identify() == Nek_Prism)
		q2 = E->qc;

	// find face id;
	cnt = vertid[0] + vertid[1] + vertid[2];
	for(i = 0; i < Snface; ++i)
		if(surfids[i][3] == cnt)
		{ // just search vertices with same vertex id sum
			if(vertid[0] == surfids[i][0])
			{
				if((vertid[1] == surfids[i][1])||(vertid[1] == surfids[i][2]))
				{

					chkfid[i]++;
					if(chkfid[i] > 1) // check form mutiple calls to same face
						fprintf(stderr,"gensurfFile: Error face %d is being "
						        "operated on multiple times\n",i);

					if(vertid[1] == surfids[i][2])
					{
						Rotate(i,1);
						Reflect(i);
					}
					fid = i;
					break;
				}
			}
			else if(vertid[0] == surfids[i][1])
			{
				if((vertid[1] == surfids[i][0])||(vertid[1] == surfids[i][2]))
				{
					chkfid[i]++;
					if(chkfid[i] > 1) // check form mutiple calls to same face
						fprintf(stderr,"gensurfFile: Error face %d is being "
						        "operated on multiple times\n",i);

					if(vertid[1] == surfids[i][0])
						Reflect(i);
					else
						Rotate(i,2);

					fid = i;
					break;
				}
			}
			else if(vertid[0] == surfids[i][2])
			{
				if((vertid[1] == surfids[i][0])||(vertid[1] == surfids[i][1]))
				{

					chkfid[i]++;
					if(chkfid[i] > 1) // check form mutiple calls to same face
						fprintf(stderr,"gensurfFile: Error face %d is being "
						        "operated on multiple times\n",i);

					if(vertid[1] == surfids[i][1])
					{
						Rotate(i,2);
						Reflect(i);
					}
					else
						Rotate(i,1); // set up to rotate Feisal to Nektar
					fid = i;
					break;
				}
			}
		}

	// invert basis
	dgetrs('T', ntot, 1, *CollMat,ntot,CollMatIpiv,SurXpts[fid],ntot,info);
	if(info)
		fprintf(stderr,"Trouble solve collocation X matrix\n");
	dgetrs('T', ntot, 1, *CollMat,ntot,CollMatIpiv,SurYpts[fid],ntot,info);
	if(info)
		fprintf(stderr,"Trouble solve collocation Y matrix\n");
	dgetrs('T', ntot, 1, *CollMat,ntot,CollMatIpiv,SurZpts[fid],ntot,info);
	if(info)
		fprintf(stderr,"Trouble solve collocation Z matrix\n");

	// Take out require modes and Backward transformation

	// base it on LGmax at present although might cause problems with
	// trijbwd if LGmax > qa

	sj = dmatrix(0,2,0,LGmax*(LGmax+1)/2-1);
	dzero(3*LGmax*(LGmax+1)/2,sj[0],1);

	lm[0] = LGmax-2;
	lm[1] = LGmax-2;
	lm[2] = LGmax-2;
	lm[3] = max(LGmax-3,0);

	dcopy(3,SurXpts[fid],1,sj[0],1);
	dcopy(3,SurYpts[fid],1,sj[1],1);
	dcopy(3,SurZpts[fid],1,sj[2],1);

	cnt = cnt1 = 3;
	for(i=0;i<3;++i)
	{
		l   = lm[i];
		dcopy(min(Snp-2,l), SurXpts[fid]+cnt,1,sj[0]+cnt1,1);
		dcopy(min(Snp-2,l), SurYpts[fid]+cnt,1,sj[1]+cnt1,1);
		dcopy(min(Snp-2,l), SurZpts[fid]+cnt,1,sj[2]+cnt1,1);
		cnt  += Snp-2;
		cnt1 += l;
	}

	l = lm[3];

	for(i=0;i<l;++i)
	{
		dcopy(min(Snp-3,l)-i,SurXpts[fid]+cnt,1,sj[0]+cnt1,1);
		dcopy(min(Snp-3,l)-i,SurYpts[fid]+cnt,1,sj[1]+cnt1,1);
		dcopy(min(Snp-3,l)-i,SurZpts[fid]+cnt,1,sj[2]+cnt1,1);
		cnt  += Snp-3-i;
		cnt1 += l-i;
	}

	JbwdTri(q1,q2,LGmax,lm,sj[0],x);
	JbwdTri(q1,q2,LGmax,lm,sj[1],y);
	JbwdTri(q1,q2,LGmax,lm,sj[2],z);

	free_dmatrix(sj,0,0);
}
Esempio n. 6
0
// -(N-1)/2 <= n <= (N-1)/2
static REAL win(REAL n, int N)
{
  return izero(AlphaAA * sqrt(1 - 4 * n * n / ((N - 1) * (N - 1)))) / ZerroA;
}
Esempio n. 7
0
main (int argc, char *argv[]){
  int  i,j,k;

  manager_init();
  parse_util_args(argc, argv);

  iparam_set("LQUAD",3);
  iparam_set("MQUAD",3);
  iparam_set("NQUAD",3);
  iparam_set("MODES",iparam("LQUAD")-1);

  char *buf = (char*) calloc(BUFSIZ, sizeof(char));
  char *fname = (char*) calloc(BUFSIZ, sizeof(char));
  get_string("Enter name of input file", buf);
  sprintf(fname, strtok(buf, "\n"));

  Grid *grid  = new Grid(fname);
  Grid *grida = new Grid(grid);

  grida->RenumberPrisms();
  grida->FixPrismOrientation();
  grid->ImportPrismOrientation(grida);
  grida->RemovePrisms();

  grida->RemoveHexes();
  grida->FixTetOrientation();
  grid->ImportTetOrientation(grida);

  Element_List *U =  grid->gen_aux_field();
  int nel = U->nel;

  get_string("Enter name of output file", buf);
  sprintf(fname, strtok(buf, "\n"));
  FILE *fout = fopen(fname, "w");


  int Nfields, Nbdry;
  get_int   ("Enter number of fields", &Nfields);
  get_int   ("Enter number of boundaries (including default)", &Nbdry);

  char **eqn = (char**) calloc(Nfields, sizeof(char*));

  for(i=0;i<Nfields;++i){
    eqn[i] = (char*)calloc(BUFSIZ, sizeof(char));
  }

  Bndry *Bc;
  Bndry **Vbc = (Bndry**) calloc(Nfields, sizeof(Bndry*));
  char *bndryeqn = (char*) calloc(BUFSIZ, sizeof(char));
  int **bcmatrix = imatrix(0, U->nel-1, 0, Max_Nfaces-1);
  izero(U->nel*Max_Nfaces, bcmatrix[0], 1);

  int nb;
  char type;
  char curved, curvetype;
  Curve *cur;
  int curveid = 0;

  for(nb=0;nb<Nbdry;++nb){
    if(nb != Nbdry-1){
      fprintf(stderr, "#\nBoundary: %d\n#\n", nb+1);
      get_string("Enter function which has roots at boundary", bndryeqn);
      fprintf(stderr, "#\n");
    }
    else{
      fprintf(stderr, "#\nDefault Boundary:\n#\n");
    }
    get_char("Enter character type\n(v=velocity)\n"
       "(W=wall)\n(O=outflow)\n(s=flux (Compressible only))\n",
       &type);
    fprintf(stderr, "#\n");
    switch(type){
    case 'W': case 'O':
      break;
    case 'v': case 's':
      for(i=0;i<Nfields;++i){
  get_string("Enter function definition", eqn[i]);
  fprintf(stderr, "\n");
      }
    }

    get_char("Is this boundary curved (y/n)?", &curved);
    if(curved == 'y'){
      ++curveid;
      get_char("Enter curve type\n(S=sphere)\n(C=cylinder)\n(T=taurus)\n",
         &curvetype);
      switch(curvetype){
      case 'S':{
  double cx, cy, cz, cr;
  get_double("Enter center x-coord", &cx);
  get_double("Enter center y-coord", &cy);
  get_double("Enter center z-coord", &cz);
  get_double("Enter radius", &cr);
  cur = (Curve*) calloc(1, sizeof(Curve));
  cur->type = T_Sphere;
  cur->info.sph.xc = cx;
  cur->info.sph.yc = cy;
  cur->info.sph.zc = cz;
  cur->info.sph.radius = cr;
  cur->id = curveid;
  break;
      }
      case 'C':{
  double cx, cy, cz, cr;
  double ax, ay, az;
  get_double("Enter point on axis x-coord", &cx);
  get_double("Enter point on axis y-coord", &cy);
  get_double("Enter point on axis z-coord", &cz);
  get_double("Enter axis vector x-coord", &ax);
  get_double("Enter axis vector y-coord", &ay);
  get_double("Enter axis vector z-coord", &az);
  get_double("Enter radius", &cr);

  cur = (Curve*) calloc(1, sizeof(Curve));
  cur->type = T_Cylinder;
  cur->info.cyl.xc = cx;
  cur->info.cyl.yc = cy;
  cur->info.cyl.zc = cz;
  cur->info.cyl.ax = ax;
  cur->info.cyl.ay = ay;
  cur->info.cyl.az = az;
  cur->info.cyl.radius = cr;
  cur->id = curveid;
  break;
      }
      }

    }
    if(nb == Nbdry-1)
      break;

    double res;
    Element *E;
    for(E=U->fhead;E;E=E->next){
      for(i=0;i<E->Nfaces;++i){
  for(j=0;j<E->Nfverts(i);++j){
    vector_def("x y z",bndryeqn);
    vector_set(1,
         &(E->vert[E->fnum(i,j)].x),
         &(E->vert[E->fnum(i,j)].y),
         &(E->vert[E->fnum(i,j)].z),
         &res);
    if(fabs(res)> TOL)
      break;
  }
  if(j==E->Nfverts(i)){
    if(curved == 'y'){
      E->curve = (Curve*) calloc(1, sizeof(Curve));
      memcpy(E->curve, cur, sizeof(Curve));
      E->curve->face = i;
    }
    switch(type){
    case 'W': case 'O':
      for(j=0;j<Nfields;++j){
        Bc = E->gen_bndry(type, i, 0.);
        Bc->type = type;
        add_bc(&Vbc[j], Bc);
      }
      bcmatrix[E->id][i] = 1;
      break;
    case 'v': case 's':
      for(j=0;j<Nfields;++j){
        Bc = E->gen_bndry(type, i, eqn[j]);
        Bc->type = type;
        add_bc(&Vbc[j], Bc);
      }
      bcmatrix[E->id][i] = 1;
      break;
    }
  }
      }
    }
  }

  char is_periodic;
  get_char("Is there periodicity in the x-direction (y/n)?", &is_periodic);
  if(is_periodic == 'y')
    get_double("Enter periodic length",&XPERIOD);
  get_char("Is there periodicity in the y-direction (y/n)?", &is_periodic);
  if(is_periodic == 'y')
    get_double("Enter periodic length",&YPERIOD);
  get_char("Is there periodicity in the z-direction (y/n)?", &is_periodic);
  if(is_periodic == 'y')
    get_double("Enter periodic length",&ZPERIOD);

  // Do remaining connections
  Element *E, *F;
  for(E=U->fhead;E;E=E->next)
    for(i=0;i<E->Nfaces;++i)
      if(!bcmatrix[E->id][i])
  for(F=E;F;F=F->next)
    for(j=0;j<F->Nfaces;++j)
      if(!bcmatrix[F->id][j])
        if(neighbourtest(E,i,F,j) && !(E->id == F->id && i==j)){
    bcmatrix[E->id][i] = 2;
    bcmatrix[F->id][j] = 2;
    set_link(E,i,F,j);
    break;
        }

  // if the default bc is curved the make default bndries curved
  if(curved == 'y'){
    for(E=U->fhead;E;E=E->next)
      for(i=0;i<E->Nfaces;++i)
  if(!bcmatrix[E->id][i]){
    E->curve = (Curve*) calloc(1, sizeof(Curve));
    memcpy(E->curve, cur, sizeof(Curve));
    E->curve->face = i;
  }
  }

  fprintf(fout, "****** PARAMETERS *****\n");
  fprintf(fout, " SolidMes \n");
  fprintf(fout, " 3 DIMENSIONAL RUN\n");
  fprintf(fout, " 0 PARAMETERS FOLLOW\n");
  fprintf(fout, "0  Lines of passive scalar data follows2 CONDUCT; 2RHOCP\n");
  fprintf(fout, " 0  LOGICAL SWITCHES FOLLOW\n");
  fprintf(fout, "Dummy line from old nekton file\n");
  fprintf(fout, "**MESH DATA** x,y,z, values of vertices 1,2,3,4.\n");
  fprintf(fout, "%d   3       1   NEL NDIM NLEVEL\n", U->nel);


  for(E=U->fhead;E;E=E->next){
    switch(E->identify()){
    case Nek_Tet:
      fprintf(fout, "Element %d Tet\n", E->id+1);
      break;
    case Nek_Pyr:
      fprintf(fout, "Element %d Pyr\n", E->id+1);
      break;
    case Nek_Prism:
      fprintf(fout, "Element %d Prism\n", E->id+1);
      break;
    case Nek_Hex:
      fprintf(fout, "Element %d Hex\n", E->id+1);
      break;
    }

    for(i=0;i<E->Nverts;++i)
      fprintf(fout, "%lf ", E->vert[i].x);
    fprintf(fout, "\n");
    for(i=0;i<E->Nverts;++i)
      fprintf(fout, "%lf ", E->vert[i].y);
    fprintf(fout, "\n");
    for(i=0;i<E->Nverts;++i)
      fprintf(fout, "%lf ", E->vert[i].z);
    fprintf(fout, "\n");
  }

  fprintf(fout, "***** CURVED SIDE DATA ***** \n");

  fprintf(fout, "%d Number of curve types\n", curveid);

  for(i=0;i<curveid;++i){
    int flag = 0;
    for(E=U->fhead;!flag && E;E=E->next){
      if(E->curve && E->curve->type != T_Straight){
  if(E->curve->id == i+1){
    switch(E->curve->type){
    case T_Sphere:
      fprintf(fout, "Sphere\n");
      fprintf(fout, "%lf %lf %lf %lf %c\n",
        E->curve->info.sph.xc,
        E->curve->info.sph.yc,
        E->curve->info.sph.zc,
        E->curve->info.sph.radius,
        'a'+i+1);
      flag = 1;
      break;
    case T_Cylinder:
      fprintf(fout, "Cylinder\n");
      fprintf(fout, "%lf %lf %lf   %lf %lf %lf %lf %c\n",
        E->curve->info.cyl.xc,
          E->curve->info.cyl.yc,
        E->curve->info.cyl.zc,
        E->curve->info.cyl.ax,
        E->curve->info.cyl.ay,
        E->curve->info.cyl.az,
        E->curve->info.cyl.radius,
          'a'+i+1);
      flag = 1;
      break;
    }
  }
      }
    }
  }
  int ncurvedsides = 0;
  for(E=U->fhead;E;E=E->next){
    if(E->curve && E->curve->type != T_Straight)
      ++ncurvedsides;
  }

  fprintf(fout, "%d Curved sides follow\n", ncurvedsides);
  for(E=U->fhead;E;E=E->next)
    if(E->curve && E->curve->type != T_Straight)
      fprintf(fout, "%d %d %c\n", E->curve->face+1, E->id+1, 'a'+E->curve->id);

  fprintf(fout, "***** BOUNDARY CONDITIONS ***** \n");
  fprintf(fout, "***** FLUID BOUNDARY CONDITIONS ***** \n");
  for(E=U->fhead;E;E=E->next){
    for(j=0;j<E->Nfaces;++j){
      if(bcmatrix[E->id][j] == 2){
  fprintf(fout, "E %d %d %d %d\n", E->id+1, j+1,
    E->face[j].link->eid+1, E->face[j].link->id+1);
      }
      else if(bcmatrix[E->id][j] == 1){
  for(i=0;i<Nfields;++i)
    for(Bc=Vbc[i];Bc;Bc=Bc->next){
      if(Bc->elmt == E && Bc->face == j){
        if(i==0)
    switch(Bc->type){
    case 'W':
      fprintf(fout, "W %d %d 0. 0. 0.\n", E->id+1, j+1);
      break;
    case 'O':
      fprintf(fout, "O %d %d 0. 0. 0.\n", E->id+1, j+1);
      break;
    case 'v':
      fprintf(fout, "v %d %d 0. 0. 0.\n", E->id+1, j+1);
      break;
    case 's':
      fprintf(fout, "s %d %d 0. 0. 0.\n", E->id+1, j+1);
      break;
    }
        if(Bc->type == 's' || Bc->type == 'v')
    fprintf(fout, "%c=%s\n", 'u'+i,Bc->bstring);
        break;
      }
    }
      }
      else{
  switch(type){
  case 'W':
    fprintf(fout, "W %d %d 0. 0. 0.\n", E->id+1, j+1);
    break;
  case 'O':
    fprintf(fout, "O %d %d 0. 0. 0.\n", E->id+1, j+1);
    break;
  case 'v':
    fprintf(fout, "v %d %d 0. 0. 0.\n", E->id+1, j+1);
    break;
  case 's':
    fprintf(fout, "s %d %d 0. 0. 0.\n", E->id+1, j+1);
    break;
  }
  if(type == 's' || type == 'v')
    for(i=0;i<Nfields;++i)
      fprintf(fout, "%c=%s\n", 'u'+i,eqn[i]);
      }
    }
  }
  char bufa[BUFSIZ];

  fprintf(fout, "***** NO THERMAL BOUNDARY CONDITIONS *****\n");
  get_char("Are you using a field file restart (y/n)?", &type);

  if(type == 'y'){
    fprintf(fout, "%d         INITIAL CONDITIONS *****\n",1);

    get_string("Enter name of restart file:", buf);
    fprintf(fout, "Restart\n");
    fprintf(fout, "%s\n", buf);
  }
  else{
    fprintf(fout, "%d         INITIAL CONDITIONS *****\n",1+Nfields);
    fprintf(fout, "Given\n");

    for(i=0;i<Nfields;++i){
      sprintf(bufa, "Field %d ", i+1);
      get_string(bufa, buf);
      fprintf(fout, "%s\n",  buf);
    }
  }

  fprintf(fout, "***** DRIVE FORCE DATA ***** PRESSURE GRAD, FLOW, Q\n");
  get_char("Are you using a forcing function (y/n)?", &type);

  if(type == 'y'){
    fprintf(fout, "%d                Lines of Drive force data follow\n",
      Nfields);

    for(i=0;i<Nfields;++i){
      sprintf(bufa, "FF%c = ", 'X'+i);
      get_string(bufa,buf);
      fprintf(fout, "FF%c = %s\n",'X'+i, buf);
    }
  }
  else{
    fprintf(fout, "0                 Lines of Drive force data follow\n");
  }

  fprintf(fout, "***** Variable Property Data ***** Overrrides Parameter data.\n");
  fprintf(fout, " 1 Lines follow.\n");
  fprintf(fout, " 0 PACKETS OF DATA FOLLOW\n");
  fprintf(fout, "***** HISTORY AND INTEGRAL DATA *****\n");
   get_char("Are you using history points (y/n)?", &type);
  if(type == 'y'){
    int npoints;

    get_int ("Enter number of points", &npoints);
    fprintf(fout, " %d   POINTS.  Hcode, I,J,H,IEL\n", npoints);
    for(i=0;i<npoints;++i){
      sprintf(bufa, "Enter element number for point %d", i+1);
      get_int(bufa,&j);
      sprintf(bufa, "Enter vertex  number for point %d", i+1);
      get_int(bufa, &k);
      fprintf(fout, "UVWP H %d 1 1 %d\n", k, j);
    }
  }
  else{
    fprintf(fout, " 0   POINTS.  Hcode, I,J,H,IEL\n");
  }

  fprintf(fout, " ***** OUTPUT FIELD SPECIFICATION *****\n");
  fprintf(fout, "  0 SPECIFICATIONS FOLLOW\n");

  return 0;
}
Esempio n. 8
0
void Grid::Connect(){
  flag = ivector(0, Ntet-1);
  izero( Ntet, flag, 1);
  fprintf(stderr, "Doing the conn. job\n");
  for(i=0;i<Ntet;++i){

    if(!(i%100))
      fprintf(stderr, ".");

    va = emap[i][0]-1;
    vb = emap[i][1]-1;
    vc = emap[i][2]-1;

    for(j=0;j<cnt[va];++j)
      flag[vertintet[va][j]] = 0;

    for(j=0;j<cnt[vb];++j)
      flag[vertintet[vb][j]] = 0;

    for(j=0;j<cnt[vc];++j)
      flag[vertintet[vc][j]] = 0;

    for(j=0;j<cnt[va];++j)
      ++flag[vertintet[va][j]];

    for(j=0;j<cnt[vb];++j)
      ++flag[vertintet[vb][j]];

    for(j=0;j<cnt[vc];++j)
      ++flag[vertintet[vc][j]];

    fl = 0;
    for(j=0;j<cnt[va];++j)
      if(flag[vertintet[va][j]] == 3 && vertintet[va][j] != i ){
  conn[i][0] = vertintet[va][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vb];++j)
      if(flag[vertintet[vb][j]] == 3 && vertintet[vb][j] != i ){
  conn[i][0] = vertintet[vb][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vc];++j)
      if(flag[vertintet[vc][j]] == 3 && vertintet[vc][j] != i ){
  conn[i][0] = vertintet[vc][j];
  fl = 1;
  break;
      }

    va = emap[i][0]-1;
    vb = emap[i][1]-1;
    vc = emap[i][3]-1;

    for(j=0;j<cnt[va];++j)
      flag[vertintet[va][j]] = 0;

    for(j=0;j<cnt[vb];++j)
      flag[vertintet[vb][j]] = 0;

    for(j=0;j<cnt[vc];++j)
      flag[vertintet[vc][j]] = 0;


    for(j=0;j<cnt[va];++j)
      ++flag[vertintet[va][j]];

    for(j=0;j<cnt[vb];++j)
      ++flag[vertintet[vb][j]];

    for(j=0;j<cnt[vc];++j)
      ++flag[vertintet[vc][j]];


    fl = 0;
    for(j=0;j<cnt[va];++j)
      if(flag[vertintet[va][j]] == 3 && vertintet[va][j] != i ){
  conn[i][1] = vertintet[va][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vb];++j)
      if(flag[vertintet[vb][j]] == 3 && vertintet[vb][j] != i ){
  conn[i][1] = vertintet[vb][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vc];++j)
      if(flag[vertintet[vc][j]] == 3 && vertintet[vc][j] != i ){
  conn[i][1] = vertintet[vc][j];
  fl = 1;
  break;
      }

    va = emap[i][1]-1;
    vb = emap[i][2]-1;
    vc = emap[i][3]-1;

    for(j=0;j<cnt[va];++j)
      flag[vertintet[va][j]] = 0;

    for(j=0;j<cnt[vb];++j)
      flag[vertintet[vb][j]] = 0;

    for(j=0;j<cnt[vc];++j)
      flag[vertintet[vc][j]] = 0;


    for(j=0;j<cnt[va];++j)
      ++flag[vertintet[va][j]];

    for(j=0;j<cnt[vb];++j)
      ++flag[vertintet[vb][j]];

    for(j=0;j<cnt[vc];++j)
      ++flag[vertintet[vc][j]];

    fl = 0;
    for(j=0;j<cnt[va];++j)
      if(flag[vertintet[va][j]] == 3 && vertintet[va][j] != i ){
  conn[i][2] = vertintet[va][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vb];++j)
      if(flag[vertintet[vb][j]] == 3 && vertintet[vb][j] != i ){
  conn[i][2] = vertintet[vb][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vc];++j)
      if(flag[vertintet[vc][j]] == 3 && vertintet[vc][j] != i ){
  conn[i][2] = vertintet[vc][j];
  fl = 1;
  break;
      }

    va = emap[i][0]-1;
    vb = emap[i][2]-1;
    vc = emap[i][3]-1;

    for(j=0;j<cnt[va];++j)
      flag[vertintet[va][j]] = 0;

    for(j=0;j<cnt[vb];++j)
      flag[vertintet[vb][j]] = 0;

    for(j=0;j<cnt[vc];++j)
      flag[vertintet[vc][j]] = 0;


    for(j=0;j<cnt[va];++j)
      ++flag[vertintet[va][j]];

    for(j=0;j<cnt[vb];++j)
      ++flag[vertintet[vb][j]];

    for(j=0;j<cnt[vc];++j)
      ++flag[vertintet[vc][j]];

        fl = 0;
    for(j=0;j<cnt[va];++j)
      if(flag[vertintet[va][j]] == 3 && vertintet[va][j] != i ){
  conn[i][3] = vertintet[va][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vb];++j)
      if(flag[vertintet[vb][j]] == 3 && vertintet[vb][j] != i ){
  conn[i][3] = vertintet[vb][j];
  fl = 1;
  break;
      }
    if(!fl)
    for(j=0;j<cnt[vc];++j)
      if(flag[vertintet[vc][j]] == 3 && vertintet[vc][j] != i ){
  conn[i][3] = vertintet[vc][j];
  fl = 1;
  break;
      }
  }
}
Esempio n. 9
0
void  GatherScatterIvert(Bsystem *Bsys){

  int i,j;
  int *BLACS_PARAMS;
  double **ivert_local;
  SMatrix *SM,SM_cont;

  double start_time_GatherScatterIvert, end_time_GatherScatterIvert;
    //start_time_GatherScatterIvert_tmp, end_time_GatherScatterIvert_tmp;

  BLACS_PARAMS = Bsys->Pmat->info.lenergy.BLACS_PARAMS;
  ivert_local = Bsys->Pmat->info.lenergy.ivert_local;
  SM = Bsys->Pmat->info.lenergy.SM_local;


  /*  copy values from  SM_local  to invert_local  */
  update_inva_LOC(SM, BLACS_PARAMS, ivert_local, 'L');


  /***************************/
  /* innitialize ring pattern communication */
  /* create two send buffers - one for indeces and one for values*/
  /* communicate over all CPUs to get the "nnz" value */
  /* copy values from sparse matrix to this buffers and send them */


  int *nnz_per_rank,*temp_nnz_per_rank;
  nnz_per_rank = ivector(0,pllinfo[get_active_handle()].nprocs-1);
  izero(pllinfo[get_active_handle()].nprocs,nnz_per_rank,1);
  nnz_per_rank[pllinfo[get_active_handle()].procid] = SM[0].nz;

  temp_nnz_per_rank = ivector(0,pllinfo[get_active_handle()].nprocs-1);
  izero(pllinfo[get_active_handle()].nprocs,temp_nnz_per_rank,1);

  gisum (nnz_per_rank,pllinfo[get_active_handle()].nprocs,temp_nnz_per_rank);
  free(temp_nnz_per_rank);


  int *send_buf_Index,*send_buf_Jndex;
  double *send_buf_value;
  int index,partner_to_send_data,partner_to_receive_data;

  start_time_GatherScatterIvert = dclock();

  SM_cont.allocate_SMatrix_cont(SM[0].nz,1,1);
  memcpy(SM_cont.AA,SM[0].AA,SM[0].nz*sizeof(double));
  memcpy(SM_cont.IA,SM[0].IA,SM[0].nz*sizeof(int));
  memcpy(SM_cont.JA,SM[0].JA,SM[0].nz*sizeof(int));
  SM[0].deallocate_SMatrix();

  for (i = 1; i < pllinfo[get_active_handle()].nprocs; i++){
    send_buf_Index = ivector(0,SM_cont.nz*2-1);
    send_buf_Jndex = send_buf_Index + SM_cont.nz;
    send_buf_value = dvector(0,SM_cont.nz-1);

    memcpy (send_buf_Index,SM_cont.IA,SM_cont.nz*2*sizeof(int));
    memcpy (send_buf_value,SM_cont.AA,SM_cont.nz*sizeof(double));

    partner_to_send_data = pllinfo[get_active_handle()].procid+1;
    partner_to_receive_data =  pllinfo[get_active_handle()].procid-1;
    if (partner_to_send_data == pllinfo[get_active_handle()].nprocs)
      partner_to_send_data = 0;
    if (partner_to_receive_data == -1)
      partner_to_receive_data = pllinfo[get_active_handle()].nprocs-1;

    /* trace number of SM transfers in order to get nz value right */
    index = pllinfo[get_active_handle()].procid-i;
    if (index < 0)
      index = index+pllinfo[get_active_handle()].nprocs;

    j = SM_cont.nz; //length of massege to be sent

    SM_cont.deallocate_SMatrix_cont();
    SM_cont.allocate_SMatrix_cont(nnz_per_rank[index],1,1);

    if (pllinfo[get_active_handle()].procid == 0){
      mpi_isend (send_buf_Index,j*2,partner_to_send_data ,0);
      mpi_irecv (SM_cont.IA,SM_cont.nz*2,partner_to_receive_data,0);
    }
    else{
      mpi_irecv (SM_cont.IA,SM_cont.nz*2,partner_to_receive_data,0);
      mpi_isend (send_buf_Index,j*2,partner_to_send_data ,0);
    }

    if (pllinfo[get_active_handle()].procid == 0){
      mpi_dsend (send_buf_value,j,partner_to_send_data ,2);
      mpi_drecv (SM_cont.AA,SM_cont.nz,partner_to_receive_data,2);
    }
    else{
      mpi_drecv (SM_cont.AA,SM_cont.nz,partner_to_receive_data,2);
      mpi_dsend (send_buf_value,j,partner_to_send_data ,2);
    }


    /*  copy values from  SM_local  to invert_local  */
    update_inva_LOC(&SM_cont, BLACS_PARAMS, ivert_local, 'L');

    //if (pllinfo[get_active_handle()].procid == 0)
    //    printf(" pass No. %d completed ! \n", i);

    free(send_buf_Index);free(send_buf_value);

  }
  free(nnz_per_rank);
  SM_cont.deallocate_SMatrix_cont();

  end_time_GatherScatterIvert = dclock();
  ROOTONLY
     fprintf(stderr,"ring communication was done in : %f sec \n", end_time_GatherScatterIvert-start_time_GatherScatterIvert);


#if 0
            static int FLAG_INDEX_IVERT_M = 0;
            int itmp, jtmp;
            FILE *Fivert_local;
            char fname_ivert_local[128];
            sprintf(fname_ivert_local,"ivert_localM_%d_%d.dat",FLAG_INDEX_IVERT_M,mynode());
            Fivert_local = fopen(fname_ivert_local,"w");
            for (itmp = 0; itmp < BLACS_PARAMS[12]; itmp++){
              for (jtmp = 0; jtmp < BLACS_PARAMS[11]; jtmp++)
                fprintf(Fivert_local," %2.16f ",ivert_local[itmp][jtmp]);
              fprintf(Fivert_local," \n");
            }
            fclose(Fivert_local);


#endif

  /* compute LU decompisition and pivot vector,
     LU stored in "ivert_local", pivot stored in "ivert_ipvt  */

  start_time_GatherScatterIvert = dclock();

  blacs_pdgetrf_nektar(BLACS_PARAMS,
           Bsys->Pmat->info.lenergy.DESC_ivert,
           Bsys->Pmat->info.lenergy.ivert_ipvt,
                       ivert_local);

  end_time_GatherScatterIvert = dclock();

  ROOTONLY
     fprintf(stderr,"Parallel LU was done in : %f sec \n", end_time_GatherScatterIvert-start_time_GatherScatterIvert);



#if 1

/* invert operator  */

   start_time_GatherScatterIvert = dclock();
   blacs_pdgetri_nektar(BLACS_PARAMS,
                       Bsys->Pmat->info.lenergy.DESC_ivert,
                       Bsys->Pmat->info.lenergy.ivert_ipvt,
                       Bsys->Pmat->info.lenergy.ivert_local);

   end_time_GatherScatterIvert = dclock();

   ROOTONLY
     fprintf(stderr,"Operator Inversion was done in : %f sec \n", end_time_GatherScatterIvert-start_time_GatherScatterIvert);

#endif


#if 0
            sprintf(fname_ivert_local,"ivert_localIM_%d_%d.dat",FLAG_INDEX_IVERT_M,mynode());
            Fivert_local = fopen(fname_ivert_local,"w");
            for (itmp = 0; itmp < BLACS_PARAMS[12]; itmp++){
              for (jtmp = 0; jtmp < BLACS_PARAMS[11]; jtmp++)
                fprintf(Fivert_local," %2.16f ",Bsys->Pmat->info.lenergy.invA_local[itmp][jtmp]);
              fprintf(Fivert_local," \n");
            }
            fclose(Fivert_local);

            FLAG_INDEX_IVERT_M++;
#endif

}
Esempio n. 10
0
static int Cuthill(Fctcon *ptcon, int *newmap, int *initmap, int nsols,
       int initpt){
  register int i,j,k;
  int      bw=0,start=0,end=1;
  int      cnt,len,jtmp,beg;
  int      next,cand,*mark;
  Facet    *f;

  if(nsols <= 1) return bw;

  mark = ivector(0,nsols);

  ifill(nsols,1,mark,1);
  izero(nsols,newmap,1);

  cnt = 1;
  newmap[0] = initmap[initpt];
  mark[initmap[initpt]]=0;

  while(cnt < nsols){
    for(i = start; i < end; ++i){
      next = newmap[i];
      beg = cnt;
      for(f = ptcon[next].f; f; f = f->next){
  cand = f->id;
  if(mark[cand]){
    mark[cand]   = 0;
    newmap[cnt] = cand;
    ++cnt;
  }
      }
      for(j = beg; j < cnt; ++j){
  len  = ptcon[newmap[beg]].ncon;
  jtmp = beg;
  for(k = beg; k < cnt+beg-j; ++k){
    if(ptcon[newmap[k]].ncon > len){
      len  = ptcon[newmap[k]].ncon;
      jtmp = k;
    }
  }
  k  = newmap[jtmp];
  newmap[jtmp] = newmap[cnt+beg-j-1];
  newmap[cnt+beg-j-1] = k;
      }
      if((cnt-beg) > bw) bw = cnt-beg;
    }
    start= end;
    end  = cnt;

    /* check to see if the tree leaves have been reached
       and if so start a new tree */
    if(start == end){
      i = 0;
      while(!mark[initmap[i]]) ++i;
      newmap[cnt] = initmap[i];
      mark[initmap[i]]=0;
      start = cnt;
      end   = start+1;
      ++cnt;
    }
  }
  free(mark);

  return bw;
}