예제 #1
0
void main(void)
{
    int i;
    int index =301;
    int nf =1;
    int pdegree =1;
    int nX =4;
    int nY=2;
    int nZ =4;
    int qstride =5;
    int *ijklmn;
    double *qnodes;
    int *index1;
    double *xlo;
    double *dx;
    double *xyz;

    xlo=(double *)malloc(sizeof(double)*3);
    dx=(double *)malloc(sizeof(double)*3);
    index1=(int *)malloc(sizeof(int)*8);
    qnodes=(double *)malloc(sizeof(double)*2);
    xyz=(double *)malloc(sizeof(double)*8*3);
    for(i=0; i<3; i++)
    {
        xlo[i]=0.0;
        dx[i]=1.0;
    }
    qnodes[0]=-sqrt(1./3.0);
    qnodes[1]=-qnodes[0];
    ijklmn=(int *)malloc(sizeof(int)*6);
    get_amr_index_xyz(qstride,0,0,0,pdegree,nX,nY,nZ,nf,xlo,dx,qnodes,index1,xyz);
    for(i=0; i<8; i++) printf("%d ",index1[i]);
    printf("\n");
    for(i=0; i<8; i++)
    {
        amr_index_to_ijklmn(pdegree,nX,nY,nZ,nf,qstride,index1[i],ijklmn);
        printf("%d %d %d %d %d %d\n",ijklmn[0],ijklmn[1],ijklmn[2],ijklmn[3],ijklmn[4],ijklmn[5]);
    }
}
예제 #2
0
void CartBlock::getInterpolatedData(int *nints,int *nreals,int **intData,
				    double **realData,
				    int nvar)
{
  int i,n;
  int ploc;
  double *xtmp;
  int *index;
  double *qq;
  int *tmpint;
  double *tmpreal;
  int icount,dcount;
  int nintold,nrealold;
  int interpCount=0;
  double weight;
  listptr=interpList;
  while(listptr!=NULL)
    {
      interpCount++;
      listptr=listptr->next;
    }
  if (interpCount > 0) 
    {
      nintold=(*nints);
      nrealold=(*nreals);
      if (nintold > 0) {
      tmpint=(int *)malloc(sizeof(int)*3*(*nints));
      tmpreal=(double *)malloc(sizeof(double)*(*nreals));
      for(i=0;i<(*nints)*3;i++) tmpint[i]=(*intData)[i];
      for(i=0;i<(*nreals);i++) tmpreal[i]=(*realData)[i];
      }
      (*nints)+=interpCount;
      (*nreals)+=(interpCount*nvar);
      (*intData)=(int *)malloc(sizeof(int)*3*(*nints));
      (*realData)=(double *)malloc(sizeof(double)*(*nreals));
      if (nintold > 0) {
      for(i=0;i<nintold*3;i++) (*intData)[i]=tmpint[i];
      for(i=0;i<nrealold;i++) (*realData)[i]=tmpreal[i];      
      free(tmpint);
      free(tmpreal);
      }
      listptr=interpList;
      icount=3*nintold;
      dcount=nrealold;
      xtmp=(double *)malloc(sizeof(double)*p3*3);
      index=(int *)malloc(sizeof(int)*p3);
      ploc=(pdegree)*(pdegree+1)/2;
      qq=(double *)malloc(sizeof(double)*nvar);
      while(listptr!=NULL)
	{
	  get_amr_index_xyz(qstride,listptr->inode[0],listptr->inode[1],listptr->inode[2],
			    pdegree,dims[0],dims[1],dims[2],nf,
			    xlo,dx,&qnode[ploc],index,xtmp);
	  (*intData)[icount++]=listptr->receptorInfo[0];
	  (*intData)[icount++]=-1;
	  (*intData)[icount++]=listptr->receptorInfo[1];	  
	  for(n=0;n<nvar;n++)
           {
            qq[n]=0;
	    for(i=0;i<p3;i++)
	      {
		weight=listptr->weights[i];
		qq[n]+=q[index[i]+d3nf*n]*weight;
	      }
            }
          //writeqnode_(&myid,qq,&nvar);
	  for(n=0;n<nvar;n++)
	    (*realData)[dcount++]=qq[n];
	  listptr=listptr->next;
	}
      free(xtmp);
      free(index);
      free(qq);
    }
}
예제 #3
0
void CartBlock::processDonors(HOLEMAP *holemap, int nmesh)
{
  int i,j,k,l,m,n,h,p;
  int ibcount,idof,meshtagdonor,icount;
  DONORLIST *temp;
  int *iflag;
  int holeFlag;
  double *xtmp;
  int *index;
  int ploc,ibindex;
  //FILE*fp;
  char fname[80];
  char qstr[2];
  char intstring[7];
  int ni,nj,nk,ibcheck;
  //sprintf(intstring,"%d",100000+myid);
  //sprintf(fname,"fringes_%s.dat",&(intstring[1]));
  //if (local_id==0) 
  //  {
  //    fp=fopen(fname,"w");
  //  }
  //else
  //  {
  //    fp=fopen(fname,"a");
  //  }  

  //
  // first mark hole points
  //
  iflag=(int *)malloc(sizeof(int)*nmesh);
  index=(int *)malloc(sizeof(int)*p3);
  xtmp=(double *)malloc(sizeof(double)*p3*3);
  //
  ibcount=-1;
  idof=-1;
  //for(i=0;i<(dims[0]+2*nf)*(dims[1]+2*nf)*(dims[2]+2*nf);i++) ibl[i]=1;
  ploc=pdegree*(pdegree+1)/2;

  for(k=0;k<dims[2];k++)
    for(j=0;j<dims[1];j++)
      for(i=0;i<dims[0];i++)
	{
	  ibcount++;
	  get_amr_index_xyz(qstride,i,j,k,pdegree,dims[0],dims[1],dims[2],nf,
			    xlo,dx,&qnode[ploc],index,xtmp);
          holeFlag=1;
          idof=ibcount*p3-1;
	  for(p=0;p<p3 && holeFlag;p++)
	    {
	      idof++;
	      if (donorList[idof]==NULL)
		{
		  for(h=0;h<nmesh;h++)
		    if (holemap[h].existWall)
		      {
			if (checkHoleMap(&xtmp[3*p],holemap[h].nx,holemap[h].sam,holemap[h].extents))
			  {
	                    ibindex=(k+nf)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf)*(dims[0]+2*nf)+i+nf;
			    ibl[ibindex]=0;
                            holeFlag=0;
			    break;
			  }
		      }
		}
	      else
		{
		  temp=donorList[idof];
		  for(h=0;h<nmesh;h++) iflag[h]=0;
		  while(temp!=NULL) 
		    {
		      meshtagdonor=temp->donorData[1]-BASE;
		      iflag[meshtagdonor]=1;
		      temp=temp->next;
		    }
		  for(h=0;h<nmesh;h++)
		    {
		      if (holemap[h].existWall)
			{
			  if (!iflag[h])
			    if (checkHoleMap(&xtmp[3*p],holemap[h].nx,holemap[h].sam,holemap[h].extents))
			      {
	                        ibindex=(k+nf)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf)*(dims[0]+2*nf)+i+nf;
				ibl[ibindex]=0;
                                holeFlag=0;
				break;
			      }
			}
		    }
		}
	    }
	}
  ibcount=-1;
  idof=-1;
  for(k=0;k<dims[2];k++)
    for(j=0;j<dims[1];j++)
      for(i=0;i<dims[0];i++)
	{
	  ibcount++;
          ibindex=(k+nf)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf)*(dims[0]+2*nf)+i+nf;
          get_amr_index_xyz(qstride,i,j,k,pdegree,dims[0],dims[1],dims[2],nf,
                            xlo,dx,&qnode[ploc],index,xtmp);
	  if (ibl[ibindex]==0) 
	    {
              idof=ibcount*p3-1;
	      for(p=0;p<p3;p++)
		{
		  idof++;
		  if (donorList[idof]!=NULL)
		    {
		      temp=donorList[idof];
		      while(temp!=NULL)
			{
			  temp->cancel=1;
			  temp=temp->next;
			}
		    }
		}

	    }
	  else
	    {
	      icount=0;
              idof=ibcount*p3-1;
	      for(p=0;p<p3;p++)
		{
		  idof++;
		  if (donorList[idof]!=NULL)
		    {
		      temp=donorList[idof];
		      while(temp!=NULL)
			{
			  if (temp->donorRes < BIGVALUE)
			    {
			      icount++;
			      break;
			    }
			  temp=temp->next;
			}
		    }
		}
	      if (icount==p3) 
		{
		  ibl[ibindex]=-1;
                  //for(p=0;p<p3;p++)
	          // fprintf(fp,"%f %f %f\n",xtmp[3*p],xtmp[3*p+1],xtmp[3*p+2]);
		}
	      else
		{
                  idof=ibcount*p3-1;
		  for(p=0;p<p3;p++)
		    {
		      idof++;
		      if (donorList[idof]!=NULL)
			{
			  temp=donorList[idof];
			  while(temp!=NULL)
			    {
			      temp->cancel=1;
			      temp=temp->next;
			    }
			}
		    } 
		}
	    }
	}

  for(k=0;k<dims[2];k++)
    for(j=0;j<dims[1];j++)
      for(i=0;i<dims[0];i++)
        {
          ibindex=(k+nf)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf)*(dims[0]+2*nf)+i+nf;
          if (ibl[ibindex]==1)
            {
              ibcheck=1;
              for(nk=-1;nk<2;nk++)
                for(nj=-1;nj<2;nj++)
                  for(ni=-1;ni<2;ni++)
                    {
                      ibindex=(k+nf+nk)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf+nj)*(dims[0]+2*nf)+i+nf+ni;
                      ibcheck=ibcheck && (ibl[ibindex]!=0);
                    }
              if (!ibcheck)
                {
                  printf("fixing orphan: myid/globalid/localid/(i,j,k)=%d %d %d %d %d %d \n",
                         myid,global_id,local_id,i,j,k);
		  ibindex=(k+nf)*(dims[1]+2*nf)*(dims[0]+2*nf)+(j+nf)*(dims[0]+2*nf)+i+nf;
		  ibl[ibindex]=0;
                }
            }
        }

  // fclose(fp);
}
예제 #4
0
void MeshBlock::getCartReceptors(CartGrid *cg,parallelComm *pc)
{
  int i,j,k,l,m,ploc,c,n,ntm,jj,kk;
  int i3;
  int iflag;
  int icount,dcount;
  int nsend,nrecv;
  int *pmap;
  int *sndMap,*rcvMap;
  OBB *obcart;
  INTEGERLIST2 *head;
  INTEGERLIST2 *dataPtr;
  int *itm;
  double *xtm;
  double xd[3];
  //char qstr[2];
  //char fname[80];
  //char intstring[7];
  //FILE *fp;
  int intersectCount=0;

  //sprintf(intstring,"%d",100000+myid);
  //sprintf(fname,"zsearch_%s.dat",&(intstring[1]));
  //fp=fopen(fname,"w");
  //
  // limit case we communicate to everybody
  //
  pmap=(int *)malloc(sizeof(int)*pc->numprocs);
  for(i=0;i<pc->numprocs;i++) pmap[i]=0;
  //
  obcart=(OBB *)malloc(sizeof(OBB));
  for(j=0;j<3;j++)
    for(k=0;k<3;k++)
      obcart->vec[j][k]=0;
  obcart->vec[0][0]=obcart->vec[1][1]=obcart->vec[2][2]=1.0;
  //
  head=(INTEGERLIST2 *) malloc(sizeof(INTEGERLIST2));
  head->intData=NULL;
  head->realData=NULL;
  dataPtr=head;
  dataPtr->next=NULL;
  //
  nsearch=0;
  //
  //writeOBB(myid);
  //
  for(c=0;c<cg->ngrids;c++)
    {
      for(n=0;n<3;n++)
	{
	  obcart->dxc[n]=cg->dx[3*c+n]*(cg->dims[3*c+n])*0.5;
	  obcart->xc[n]=cg->xlo[3*c+n]+obcart->dxc[n];
	}
      if (obbIntersectCheck(obb->vec,obb->xc,obb->dxc,
			    obcart->vec,obcart->xc,obcart->dxc) ||
	  obbIntersectCheck(obcart->vec,obcart->xc,obcart->dxc,
			    obb->vec,obb->xc,obb->dxc))
	{
	  intersectCount++;
          //if (myid==0 && intersectCount==0) writeOBB2(obcart,c);
           
	  ntm=(cg->porder[c]+1)*(cg->porder[c]+1)*(cg->porder[c]+1);      
	  xtm=(double *)malloc(sizeof(double)*3*ntm);
	  itm=(int *) malloc(sizeof(int)*ntm);
	  ploc=(cg->porder[c])*(cg->porder[c]+1)/2;
	  for(j=0;j<cg->dims[3*c];j++)
	    for(k=0;k<cg->dims[3*c+1];k++)
	      for(l=0;l<cg->dims[3*c+2];l++)
		{
		  get_amr_index_xyz(cg->qstride,j,k,l,
				    cg->porder[c],cg->dims[3*c],cg->dims[3*c+1],cg->dims[3*c+2],
				    cg->nf,
				    &cg->xlo[3*c],
				    &cg->dx[3*c],
				    &cg->qnode[ploc],
				    itm,
				    xtm);
		  iflag=0;
		  for(n=0;n<ntm;n++)
		    {
		      i3=3*n;
                      //if (intersectCount==1 && myid==0) fprintf(fp,"%lf %lf %lf\n",xtm[i3],xtm[i3+1],xtm[i3+2]);
		      for(jj=0;jj<3;jj++) xd[jj]=0;
		      for(jj=0;jj<3;jj++)
			for(kk=0;kk<3;kk++)
			  xd[jj]+=(xtm[i3+kk]-obb->xc[kk])*obb->vec[jj][kk];
		      
		      if (fabs(xd[0]) <= obb->dxc[0] &&
			  fabs(xd[1]) <= obb->dxc[1] &&
			  fabs(xd[2]) <= obb->dxc[2])
			{
			  iflag++;
			}
		    }
		  
		  if (iflag==ntm) 
		    {
		      pmap[cg->proc_id[c]]=1;
		      dataPtr->next=(INTEGERLIST2 *) malloc(sizeof(INTEGERLIST2));
		      dataPtr=dataPtr->next;
		      dataPtr->realData=(double *) malloc(sizeof(double)*3*ntm);
		      dataPtr->intData=(int *) malloc(sizeof(int)*(ntm+2));
		      dataPtr->intData[0]=cg->proc_id[c];
		      dataPtr->intData[1]=cg->local_id[c];
		      dataPtr->intDataSize=ntm+2;
		      dataPtr->realDataSize=ntm;
		      nsearch+=ntm;
		      for(n=0;n<ntm;n++)
			{
			  for(kk=0;kk<3;kk++)
			    dataPtr->realData[3*n+kk]=xtm[3*n+kk];
			  dataPtr->intData[n+2]=itm[n];
			}
		      dataPtr->next=NULL;
		    }
		}
	  free(xtm);
	  free(itm);
	}
    }
  //
  // create the communication map
  //
  nsend=0;
  for(i=0;i<pc->numprocs;i++) if (pmap[i]==1) nsend++;
  nrecv=nsend;
  sndMap=(int *)malloc(sizeof(int)*nsend);
  rcvMap=(int *)malloc(sizeof(int)*nrecv);
  m=0;
  for(i=0;i<pc->numprocs;i++)
    {
      if (pmap[i]==1) 
	{
	  sndMap[m]=rcvMap[m]=i;
	  m++;
	}
    }
  pc->setMap(nsend,nrecv,sndMap,rcvMap);
  //
  // if these were already allocated
  // get rid of them
  //
  if (xsearch) free(xsearch);
  if (isearch) free(isearch);
  if (donorId) free(donorId);
  if (rst) free(rst);
  //
  xsearch=(double *)malloc(sizeof(double)*3*nsearch);
  isearch=(int *)malloc(3*sizeof(int)*nsearch);
  donorId=(int *)malloc(sizeof(int)*nsearch);
  rst=(double *) malloc(sizeof(double)*3*nsearch);
  //
  dataPtr=head->next;
  m=n=0;
  while(dataPtr!=NULL)
    {
      for(j=2;j<dataPtr->intDataSize;j++)
	{
	  isearch[m++]=dataPtr->intData[0];
	  isearch[m++]=dataPtr->intData[1];	  
	  isearch[m++]=dataPtr->intData[j];
	}
      for(j=0;j<3*dataPtr->realDataSize;j++)
	xsearch[n++]=dataPtr->realData[j];
       dataPtr=dataPtr->next;
    }
  deallocateLinkList3(head);
  //fclose(fp);
  free(obcart);
  free(pmap);
  free(sndMap);
  free(rcvMap);
}