wzgrid.cxx

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

CXX
149
字号
#include <stdio.h>
#include "wzoutput.hxx"
#include "wzgrid.hxx"

const wzIndex sxGridMaterials = 100;

extern wzName  wzNameFile;

void wzGrid::test()
{
  ;
}

void wzGrid::pn(ibgInteger n)
{
  wzOutput& pout = wzOutput::Default;
  char* name[4]={"region","face","line","vertex"};

  if(n<=0 || n> points.last()){
    pout("node <> invalid - last node is <>;\n"),n,points.last();
    return;
  }
  wzPoint& p = Point[n];
  pout("<> (<>) node <> [<>,<>,<>]\n")<<name[p.codim()],p.segment().index(),
    n,p[0],p[1],p[2];
}

void wzGrid::pc(ibgInteger c)
{
  int i; ibg2CellType t;
  wzOutput& pout = wzOutput::Default;
  if(c<=0 || c> cells.last()){
    pout("cell <> invalid - last cell is <>;\n"),c,cells.last();
    return;
  }
  pout("<> <> with nodes"),wzCellTypename[t=cct(c)],c;
  for(i=0;i<wzCellTypepoints[t];i++){
    pout(" <>")<<ccn(c)[i];
  }
  pout("<>")<< " and neighbours ";
  for(i=0;i<wzCellTypesides[t];i++){
    pout(" <>")<<ccs(c)[i];
  }
  pout("<>\n")<< " ";
}


wzDelaunayGenerator::wzDelaunayGenerator(wzIndex griddim, wzIndex spacedim)
  //  :_grid(new wzGrid(griddim,spacedim))
  :wzGrid(griddim,spacedim)
  ,Grid(*this)
  ,CellSphere(Grid.cells)
  ,st(Grid.cells)
{
  for(int i=0;i<IBG2CTMAX;i++) CFree[i] = 0;
}

wzGrid::wzGrid(wzIndex griddim, wzIndex spacedim)
  :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)
{
  gridDim  = griddim;
  spaceDim = spacedim;
  firstRegion=firstFace=firstEdge=firstNode=1;
  lastRegion=lastFace=lastEdge=lastNode=0;
  sxConstructor();
}

//void	ibg2OtSimplex(wzGrid* gg, FILE *file);

wzGrid::wzGrid(char *file)
{
  FILE *ff = fopen(file,"r");
  sxConstructor();
  //  ibg2OtSimplex(this,ff);
  fclose(ff);
  sxRefresh();
}

void wzDelaunayGenerator::setOutsideBoundaryMode(wzBoolean i)
{
}


extern "C"{
void sxDefaultInitLoop(sxGrid g, sxSimplex s);
void sxDefaultDestroyGrid(sxGrid g);
int wzGridDefineSimplex(sxGrid g, sxSimplex s);
}

wzIndex wzGrid::sxConstructor()
{
  int i,t;
  boxNotDefined = 1;
  for(t=0;t<sxIteratorTypes;t++){
    numOfSimplices[t] = 0;
    numOfMaterials[t] = sxGridMaterials;
    material[t] = new int[numOfMaterials[t]];
    for(i=0;i<=numOfMaterials[t];i++) material[t][i] = 1;
  }
  //  initLoop	= sxDefaultInitLoop;
  destroyGrid	= 0;  // C mechanism should cause an error. C++ - allocation!!!
  //  setSimplexData= wzGridDefineSimplex;
  return 0;
}

wzIndex wzGrid::sxRefresh()
{
  numOfSimplices[sxCells] = cells.last();
  numOfSimplices[sxNodes] = points.last();
  return 0;
}

extern "C" int wzGridDefineSimplex(sxGrid grid, sxSimplex s)
{
  wzgrid g = (wzGrid *)(grid);
  int i,j;
begin:
  i=s->index;
  switch(s->iterator_type){
  case sxCells:
    if(i > g->lastRegion) goto end_of_loop;
    s->material = g->CellSegment[i];
    if(!g->material[sxCells][s->material]){s->index++; goto begin;}
    s->node = g->ccn(i) - 1;
    for(j=1;j<=s->numberOfNodes;i++){
      s->coordinates[j]=((double*)&(g->Point[s->node[j]]))-1;
    }
    break;
  case sxNodes:
    if(i > g->points.last()) goto end_of_loop;
    s->material = (int) g->Point[i].segment().region();
    if(!g->material[sxNodes][s->material]){s->index++; goto begin;}
    s->priv.node_space[1] = i;
    s->coordinates[1] = ((double*)&(g->Point[s->node[i]]))-1;
  }
  return sxDefined;
  end_of_loop:
  return sxEndOfLoop;
}

⌨️ 快捷键说明

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