⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sg-cog.cxx

📁 有限元学习研究用源代码(老外的),供科研人员参考
💻 CXX
字号:
static char *rcsid= "$Id: sg-cog.cxx,v 1.2 1997/11/05 15:40:13 fuhrmann Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sg-cog.hxx"
#include "sg-dump.hxx"

int sgNx=0;
int sgNy=0;
int sgNz=0;

ibgFloat sgCxmin=1.0;
ibgFloat sgCxmax=0.0;
ibgFloat sgCymin=1.0;
ibgFloat sgCymax=0.0;
ibgFloat sgCzmin=1.0;
ibgFloat sgCzmax=0.0;




ibgFloat sgCx[sgCOORDMAX]={0.0, 0.5, 1.0};
ibgFloat sgCy[sgCOORDMAX]={0.0, 0.5, 1.0};
ibgFloat sgCz[sgCOORDMAX]={0.0, 0.5, 1.0};

int sgCMaterialTable[sgCMAX];
int sgFMaterialTable[sgFMAX];

wzRegion (*sgCMatFunction)(const cogPoint&p)=NULL;
wzFace (*sgFMatFunction)(const cogPoint&p)=NULL;



void sgCreateCoordinates(int n,ibgFloat coord[], ibgFloat min, ibgFloat max)
{
  int i;
  ibgFloat h;
  if (n>sgCOORDMAX) { printf("E-Wrong, wrong coordinate number %d\n",n); exit(1);}
  if (n<1)        { printf("E-Wrong, wrong coordinate number %d\n",n); exit(1);}

  if (n>1) h=(max-min)/(double)(n-1);
  coord[0]=min;
  for(i=1;i<n-1;i++)
       coord[i]=coord[i-1]+h;
  coord[n-1]=max;
}




static char sgFileName[64];

void sgInitGrid(int argc, char *argv[])
{
  int i;
  
  sgCMatFunction=0;
  sgFMatFunction=0;

  sprintf(sgFileName,"%s.%s",argv[0],"sgz");
  
  i=1;
  while (i<argc)
    {
      if      (strcmp(argv[i],"-o")==0)     {  sprintf(sgFileName,"%s",argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-nx")==0)    {  sgNx=   atoi(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-ny")==0)    {  sgNy=   atoi(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-nz")==0)    {  sgNz=   atoi(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-xmin")==0)  {  sgCxmin=atof(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-xmax")==0)  {  sgCxmax=atof(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-ymin")==0)  {  sgCymin=atof(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-ymax")==0)  {  sgCymax=atof(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-zmin")==0)  {  sgCzmin=atof(argv[i+1]); i+=2;}
      else if (strcmp(argv[i],"-zmax")==0)  {  sgCzmax=atof(argv[i+1]); i+=2;}
      else {printf("I-Arg, Argument %s not parsed\n",argv[i++]); }
    }
  
  sgCreateCoordinates(sgNx,sgCx,sgCxmin,sgCxmax);
  sgCreateCoordinates(sgNy,sgCy,sgCymin,sgCymax);
  sgCreateCoordinates(sgNz,sgCz,sgCzmin,sgCzmax);
  


  for(i=0;i<sgFMAX;i++)
    sgFMaterialTable[i]=0;

  for(i=0;i<sgCMAX;i++)
    sgCMaterialTable[i]=i,
    sgFMaterialTable[i]=i;

}

void sgCreateGridAndDump(Cogeometry &cog, ibgCriteria &crit)
{
  FILE *SimplexFile;
  char cmdname[64];
  int dim;
  
  printf("I-Data: cgrid size %d x %d x %d\n",
	 sgNx, sgNy, sgNz);
  printf("I-Data: cgrid volume [ %g , %g ] x [ %g x %g ] x [ %g x %g]",
	 sgCx[0],sgCx[sgNx-1],
	 sgCy[0],sgCy[sgNy-1],
	 sgCz[0],sgCz[sgNz-1]);
  
  

  if (sgNx<1)  { printf("E-Wrong, wrong x coordinate number\n", sgNx); exit(1);}
  if (sgNy<1)  { printf("E-Wrong, wrong y coordinate number\n", sgNy); exit(1);}
  if (sgNz<1)  { printf("E-Wrong, wrong z coordinate number\n", sgNz); exit(1);}

  if (sgCx[0]>sgCx[sgNx-1]){ printf("E-Wrong, wrong x coordinate values\n"); exit(1);}
  if (sgCy[0]>sgCy[sgNy-1]){ printf("E-Wrong, wrong y coordinate values\n"); exit(1);}
  if (sgCz[0]>sgCz[sgNz-1]){ printf("E-Wrong, wrong z coordinate values\n"); exit(1);}
  
  if (sgNx>1) dim=1;
  if (sgNy>1) dim=2;
  if (sgNz>1) dim=3;
  
  ibgRegularGrid coarse(dim);
  if (sgNx>1) coarse.setList(0,sgNx,sgCx);
  if (sgNy>1) coarse.setList(1,sgNy,sgCy);
  if (sgNz>1) coarse.setList(2,sgNz,sgCz);
  

  ibGrid *grid = ibgOldGridGenerate(
				    coarse, cog,crit);


 printf("\n\nI-Start: creation of simplex file %s started\n", sgFileName);

 sprintf(cmdname,"gzip > %s", sgFileName);
 SimplexFile = popen(cmdname,"w");
 sgWriteSmp(grid,
	    SimplexFile,
	    sgCMAX,sgCMaterialTable,sgCMatFunction,
	    sgFMAX,sgFMaterialTable,sgFMatFunction
	    );
 
 fflush(SimplexFile);
 pclose(SimplexFile);
 printf("I-Success: Creation of simplex file %s successful\n", sgFileName);
 
}





⌨️ 快捷键说明

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