ibgoutput.cxx

来自「有限元学习研究用源代码(老外的),供科研人员参考」· CXX 代码 · 共 190 行

CXX
190
字号
#include "wzgrid.hxx"
#include "cogwarnings.hxx"
// #include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

static int writeMaterial = 0;

void wzGrid::write(char* filename)
{
  int* cnum;
  int  ic,ncells,nfaces,u,t;
  cnum = (int*)calloc((cells.last()+1),sizeof(int));
  ncells = 0;
  nfaces = 0;
  wzRangeLoop(cells,ic){
    t   = cct(ic);
    u   = ccu(ic);   
    if(u<=0) continue;
    switch(wzCellTypeCODIM(t)){
    case wzIsRegion:
      if(writeMaterial){
	u = wzRegion(u).material();
	if(u<=0) continue;
      }
      cnum[ic] = ++ncells; break;
    case wzIsFace:
      if(writeMaterial){
	u = wzFace(u).type();
	if(u<=0) continue;
      }
      cnum[ic] = ++nfaces; break;
    default:
      continue;
    }
  };
  write(filename, cnum, ncells,nfaces);
}

void wzGrid::write(char* filename, wzSegmentDescription& d)
{
  d.use();
  writeMaterial = 1;
  write(filename);
  writeMaterial = 0;
}  

void wzGrid::write(char* filename, int* cnum, int ncells, int nfaces)
{
  FILE *file;
  int dim,sdim,d,ic,cc,t1,u,in,nn,n,*cs,*cn,*nnum,i,
    nnodes,
    cl,cr;
  time_t date,t;
  date=time(&t);
  cogInfoWriteGrid("\n<>D-Grid with <> points, <> cells, <> face cells ");
  file = fopen(filename,"w");
  fprintf(file,"SimplexGrid");
  fprintf(file," ");
  fprintf(file,"2.0\n");
  fprintf(file,"#created by wzgrid (c) I.Schmelzer\n");
  fprintf(file,"#%s",ctime(&date));
  fprintf(file,"DIMENSION\n%d\n",dim=gdim());

  cogInfoWriteGrid << dim;
  nnum = (int*)calloc((points.last()+1),sizeof(int));
  wzRangeLoop(cells,ic){
    if(cnum[ic]==0) continue;
    t   = cct(ic);
    cn = ccn(ic);
    for(n=0;n<wzCellTypePoints(t);n++){
      nnum[cn[n]] = 1;
    }
  };
  nnodes = 0;
  wzRangeLoop(points,in){
    if(nnum[in]) nnum[in] = ++nnodes;
  }
  cogInfoWriteGrid << nnodes,ncells,nfaces;
  sdim=dim;
  if(sdim==0) sdim=xdim();
  fprintf(file,"NODES\n%d %d\n",nnodes,sdim);
  wzRangeLoop(points,in){
    if(nnum[in]==0) continue;
    for(d=0;d<sdim;d++) fprintf(file,"%f ",(float)(cnx(in)[d]));
    fprintf(file,"\n");
  }

  if(ncells){
    fprintf(file,"CELLS\n%d\n",ncells);
    wzRangeLoop(cells,ic){
      t   = cct(ic);
      u   = ccu(ic);
      if(wzCellTypeCODIM(t) != wzIsRegion) continue;
      if(cnum[ic]==0) continue;
      if(writeMaterial) u = wzRegion(u).material();
      cn = ccn(ic);
      for(i=0;i<wzCellTypePoints(t);i++){
	nn = cn[i];
	nn = nnum[nn];
	fprintf(file,"%d ",nn);
      }
      fprintf(file,"%d ",u);
      cs = ccs(ic);
      for(i=0;i<wzCellTypeSides(t);i++)  {
	cc = cs[i];
	if(cc>0){
	  t1 = cct(cc);
	  if(wzCellTypeCODIM(t1)==wzIsRegion)	  {
	    fprintf(file,"%d ",cnum[cc]);
	  }else if(wzCellTypeCODIM(t1)==wzIsFace)	  {
	    fprintf(file,"-%d ",cnum[cc]);
	  }
	  else	wzAssert(0);
	}else{
	  fprintf(file,"-0 ");
	}
      }
      fprintf(file,"\n");
    }
  }
  if(nfaces){
    fprintf(file,"FACES\n%d\n",nfaces);
    wzRangeLoop(cells,ic){
      t   = cct(ic);
      u   = ccu(ic);
      if(wzCellTypeCODIM(t) != wzIsFace) continue;
      if(cnum[ic]==0) continue;
      if(writeMaterial) u = wzFace(u).type();
      cn = ccn(ic);
      for(i=0;i<wzCellTypePoints(t);i++){
	nn = cn[i];
	nn = nnum[nn];
	fprintf(file,"%d ",nn);
      }
      fprintf(file,"%d ",u);
      cl = wzGridCellLeft(*this,ic,t);
      cr = wzGridCellRight(*this,ic,t);
      if(ncells){
	if(cnum[cl]) fprintf(file,"%d ",cnum[cl]);
	else fprintf(file,"-%d ",ccu(cl));
	if(cnum[cr]) fprintf(file,"%d ",cnum[cr]);
	else fprintf(file,"-%d ",ccu(cr));
      }else{
	fprintf(file,"-%d ",ccu(cl));
	fprintf(file,"-%d ",ccu(cr));
      }
      cs = ccs(ic);
      for(i=0;i<wzCellTypeSides(t);i++){
	cc = cs[i];
	if(cc==0)
	  fprintf(file,"0 ");
	else if(wzCellTypeCODIM(t1 = cct(cc))==wzIsFace)  {
	  fprintf(file,"%d ",cnum[cc]);
	}else if(wzCellTypeCODIM(t1)==wzIsEdge){
	  fprintf(file,"0 ");
	}
	else	wzAssert(0);
      }
      fprintf(file,"\n");
    }
  }
  fprintf(file,"END\n");
  fclose(file);
  free(nnum);
  free(cnum);
  cogInfoWriteGrid("written into file <>;\n") << filename;
}
/*
wzGrid::wzGrid(char *filename)
  :points(sizeof(wzPoint))
  ,Point(points.base)
  ,PointCell(points)
  ,cells(3*sizeof(wzInteger))
  ,CellSegment(cells.base)
  ,CellType(cells.base,1,sizeof(wzInteger))
  ,CellData(cells.base,2,sizeof(wzInteger))
  ,data(sizeof(wzInteger))
  ,Data(data.base)
{
  FILE *file;
  file = fopen(filename,"r");
  firstRegion=firstFace=firstEdge=firstNode=1;
  lastRegion=lastFace=lastEdge=lastNode=0;
  sxConstructor();
  fclose(file);
}
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?