示例#1
0
//---------------------------------------------------------------------------
//Reading the parameters of simulation
int Input::Read_simulation_parameters(struct Simu_para &simu_para, ifstream &infile)
{
    if(simu_para.mark)
    {
        cout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl;
        return 0;
    }
    else simu_para.mark = true;

    istringstream istr0(Get_Line(infile));
    istr0 >> simu_para.simu_name;			//Read the name of simulation

    istringstream istr1(Get_Line(infile));
    istr1 >> simu_para.sample_num;			//Read the number of samples
    if(simu_para.sample_num<1)	 {
        hout << "Error: the number of samples less than 1." << endl;
        return 0;
    }

    istringstream istr2(Get_Line(infile));
    istr2 >> simu_para.create_read_network;		//Read a signal to show if create a new network or read a previouse network from a file
    if(simu_para.create_read_network!="Create_Network"&&simu_para.create_read_network!="Read_Network")
    {
        hout << "Error: the 'create_read_network' is neither 'Create_Network' nor 'Read_Network'." << endl;
        return 0;
    }

    return 1;
}
示例#2
0
//---------------------------------------------------------------------------
//Reading the geometric parameters of nanotubes
int Input::Read_nanotube_geo_parameters(struct Nanotube_Geo &nanotube_geo, ifstream &infile)
{
    if(nanotube_geo.mark)
    {
        cout << "Attention: \"" << nanotube_geo.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << nanotube_geo.keywords << "\" has been input!" << endl;
        return 0;
    }
    else nanotube_geo.mark = true;

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the initial growth direction type (random or specific) in a RVE
    istringstream istr_initial_direction(Get_Line(infile));
    istr_initial_direction >> nanotube_geo.dir_distrib_type;
    if(nanotube_geo.dir_distrib_type!="random"&&nanotube_geo.dir_distrib_type!="specific") {
        hout << "Error: the direction distribution type must be either random or specific." << endl;
        return 0;
    }
    if(nanotube_geo.dir_distrib_type=="specific")
    {
        istr_initial_direction  >> nanotube_geo.ini_sita >> nanotube_geo.ini_pha;
        if(nanotube_geo.ini_sita<0||nanotube_geo.ini_sita>PI||nanotube_geo.ini_pha<0||nanotube_geo.ini_pha>=2*PI)
        {
            hout << "Error: the specified angle is not in the acceptable range of (0, 2PI)." << endl;
            return 0;
        }
    }
示例#3
0
//---------------------------------------------------------------------------
//生成三维高斯节点
int Gauss::Generate_gauss(ifstream &infile)
{
	//---------------------------------------------------------------------------
	//读取高斯点精度
	istringstream istr_precision(Get_Line(infile));
	istr_precision >> precision; 
	if(precision<=0||precision>=1000)
	{ 
		hout <<"注意!取得一维高斯点的个数是" << precision << ",输入有误请检查!" << endl; 
		return 0; 
	}
	//---------------------------------------------------------------------------
	//生成高斯节点
	vector<double> temp_gauss;
	vector<double> temp_wight;
	if(Generate_gauss_array(temp_gauss, temp_wight)==0) return 0;

	for(int i=0; i<(int)temp_gauss.size(); i++)
	    for(int j=0; j<(int)temp_gauss.size(); j++)
			for(int k=0; k<(int)temp_gauss.size(); k++)
			{
				weight.push_back(temp_wight[i]*temp_wight[j]*temp_wight[k]);
				gauss.push_back(Node(temp_gauss[i], temp_gauss[j], temp_gauss[k]));
			}

	return 1;
}
示例#4
0
void CheatFile::Get_Cheat_Codes( int num, CODES_LIST &codes_list )
{
	int list_ptr;
	int notes_lines;

	/*
	"cheat name
	; comment
	@id
	; comment
	80 xxxxxx xxxx
	; comment
	$option - line 1
	$option - line 2
	$option - line 3
	; comment
	.notes - line 1
	.notes - line 2
	; comment
	"next cheat
	*/

	// init
	list_ptr = _cheat_index[ num ];
	notes_lines = 0;
	
	codes_list.num_codes = 0;


	while( list_ptr < _cheat_index[ num+1 ] )
	{
		if( Valid_Code( _file + list_ptr ) )
		{
			if( sscanf_s( _file+list_ptr, "%X %X %X",
						&codes_list.code[ codes_list.num_codes ],
						&codes_list.address[ codes_list.num_codes ],
						&codes_list.value[ codes_list.num_codes ] ) < 3 )
			{
				// ???? - quantity modifier
				codes_list.value[ codes_list.num_codes ] = _cheat_quantity[ num ];
			}

			codes_list.num_codes++;
		}


		list_ptr = Get_Line( list_ptr );
	}
}
示例#5
0
//---------------------------------------------------------------------------
//Reading the name of application case
int Input::Read_application_name(struct App_name &app_name, ifstream &infile)
{
    if(app_name.mark)
    {
        cout << "Attention: \"" << app_name.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << app_name.keywords << "\" has been input!" << endl;
        return 0;
    }
    else app_name.mark = true;

    istringstream istr(Get_Line(infile));
    istr >> app_name.str;

    return 1;
}
示例#6
0
文件: myweb.c 项目: yuichib/gnutella
int
Get_Content_Length(char *buf,int bufsize)
{
	char *p = buf;
	int size = bufsize;

	int i;
	char *line;
	int len;
	int ret;
	char *head;
	char *tmp;

	for(i=1; (line = Get_Line(p,i,size))!=NULL; i++){
		len = strlen(line);

		if(strncmp(line,"Content-Length:",strlen("Content-Length:")) == 0 ||
				strncmp(line,"Content-length:",strlen("Content-Length:")) == 0){//Found
			head = line;
			head += strlen("Content-Length:");
			len  -= strlen("Content-Length:");
			if(len <= 0)
				return -1;
			while(*head == ' ' || *head == '\t'){//slip space
				head++;
				len--;
				if(len <= 0)
					return -1;
			}
			if((tmp = Search_Char(head,'\r',len)) == NULL)
				return -1;
			*tmp = '\0';
			ret = atoi(head);
			free(line);
			return ret;
		}

		free(line);
	}

	return -1;//Not Found


}
示例#7
0
void CheatFile::Build_Game_List()
{
	int list_ptr;
	bool pec_hack;

	_game_count = 0;

	//_game_list.ClearSelection();

	list_ptr = 0;
	while( list_ptr < _file_size )
	{
		pec_hack = false;

		// new game entry
		if( _file[ list_ptr ] == '#' )
		{
			// add name ptr to master list
			_game_index[ _game_count ] = list_ptr;
			_game_count++;

			pec_hack = true;
		}

	
		list_ptr = Get_Line( list_ptr );


		// PEC hack - <name>#SLUS-00000
		if( pec_hack &&
				_file[ list_ptr-13 ] == '#' && 
				_file[ list_ptr-12 ] == 'S' &&
				_file[ list_ptr-11 ] == 'L' &&
				_file[ list_ptr-9 ]  == 'S' &&
				_file[ list_ptr-8 ]  == '-' )
		{
			_file[ list_ptr-13 ] = 0;
		}
	}


	// EOF
	_game_index[ _game_count ] = list_ptr;
}
void ChessRecognition::Find_ChessPoint(IplImage *Source, vector<ChessPoint> *Point) {
	if (_EnableThread != false) {
		// init함수를 통하여 설정한 mode에 맞추어 chessboard recognition & 좌표 보정 & src에 좌표 그리기 진행.
		// src : 좌표를 그릴 이미지, point : 연산을 통하여 cross point를 저장할 vector.
		Point->clear();

		if (_MODE == 1) {
			if (_HoughLineBased != NULL) {
				vector<std::pair<float, float> > _TCH_LineX, _TCH_LineY;

				Get_Line(&_TCH_LineX, &_TCH_LineY);
#if !defined(USING_QT)
				_HoughLineBased->DrawLines(_TCH_LineX, Source);
				_HoughLineBased->DrawLines(_TCH_LineY, Source);
#endif
				_HoughLineBased->FindIntersections(_TCH_LineX, _TCH_LineY, Point);
				Refine_CrossPoint(Point);
#if !defined(USING_QT)
				DrawPoints(Source, *Point);
#endif
			}
			else {
				// Not Initialize.
			}
		}
		else if (_MODE == 2) {
			if (_LineSearchBased != NULL) {
				_Vec_ProtectionMutex.lock();
				copy(_CP.begin(), _CP.end(), back_inserter(*Point));
				_Vec_ProtectionMutex.unlock();
				// 보정으로 인한 문제가 발생하여 잠시 보류.
				//Refine_CrossPoint(point);
#if !defined(USING_QT)
				DrawPoints(Source, *Point);
#endif
			}
			else {
				// Not Initialize.
			}
		}
	}
}
示例#9
0
//---------------------------------------------------------------------------
//赋予网格单元材料属性
int Mesher::Element_material_property(ifstream &infile)
{
	istringstream istr(Get_Line(infile));		//跳过注释行
	int define_case;
	double fiber_radius;
	istr >> define_case;

	if(define_case!=0&&define_case!=1) { hout <<"注意:定义的材料单元属性情况错误!请检查....Element_material_property 1" << endl;	return 0; }
	if(define_case==1) istr >> fiber_radius;
	if(fiber_radius<0.0) { hout <<"注意:纤维材料的半径输入错误!请检查....Element_material_property 2" << endl;	return 0; }

	if(define_case==0)	//纯材料
	{
		for(int i=0; i<(int)elements.size(); i++)
		{
			elements[i].type = 381;		//对应单元的形状类型(三个数字xyz: x 维度;y单元的节点个数;z单元的形函数幂次);
														//例如,121: 一维两节点(线段)线性形函数;231: 二维三节点(三角形)线性形函数;241: 二维四节点(四边形)线性形函数;
														//341: 三维四节点(四面体)线性形函数;361: 三维六节点(三棱柱)线性形函数;381:三维八节点(六面体)线性形函数
			elements[i].mat = 0;			//对应材料属性编号
		}
	}
	else if(define_case==1) //Z轴单向纤维
	{
		for(int i=0; i<(int)elements.size(); i++)
		{
			elements[i].type = 381;	
			Point_3D centp(0,0,0);
			for(int j=0; j<(int)elements[i].nodes_id.size(); j++)
			{
				centp.x += nodes[elements[i].nodes_id[j]].x;
				centp.y += nodes[elements[i].nodes_id[j]].y;
				centp.z += nodes[elements[i].nodes_id[j]].z;
			}
			centp = centp/elements[i].nodes_id.size();
			if((centp.x-0.5)*(centp.x-0.5)+(centp.y-0.5)*(centp.y-0.5)<fiber_radius*fiber_radius) elements[i].mat = 1;
			else elements[i].mat = 0;
		}
	}

	return 1;
}
示例#10
0
void CheatFile::Build_Cheat_List( int game_num )
{
	int list_ptr;
	int stop_ptr;

	_cheat_count = 0;


	// invalid index
	if( game_num >= _game_count ) return;

	list_ptr = _game_index[ game_num ];
	stop_ptr = _game_index[ game_num+1 ];


	while( list_ptr < stop_ptr )
	{
		// new cheat entry
		if( _file[ list_ptr ] == '"' )
		{
			Set_Cheat_Quantity( _cheat_count, 0 );

			
			// add name ptr to master list
			_cheat_index[ _cheat_count ] = list_ptr;
			_cheat_count++;
		}
		
		
		list_ptr = Get_Line( list_ptr );
	}


	// EOF
	_cheat_index[ _cheat_count ] = list_ptr;
}
示例#11
0
文件: pattern.c 项目: doug16rogers/dr
// --------------------------------------------------------------------------
// Pattern_Load:
//
static TEXT_PATTERN Pattern_Load (FILE*            file,
                                  const char*      filename,
                                  int*             line_number,
                                  TEXT_PATTERN pattern)
{
  const char NUL = '\0';
  const char* comment_characters = "#;!$/";
  const char* valid_letters = "-Ee+XxBbWw123456789";
  
  char* s = NULL;
  int i = 0;
  int row = 0;
  int column = 0;
  
  //
  // First find start of pattern. If no start, return NULL without error
  // message.
  //
  while (!feof (file))
  {
    if ((s = Get_Line (file, line_number)) == NULL)
    {
      return NULL;
    }
    
    for (; *s != NUL; s++)
    {
      if (!isspace (*s)) break;
    }
  
    //
    // Check for non-comment line.
    //
    if ((*s != '\0') && (strchr (comment_characters, *s) == NULL))
    {
      break;
    }
  }   // while looking for start of pattern

  if (sscanf (s, "%d %d", &pattern->rows, &pattern->columns) != 2)
  {
    fprintf (stderr, "%s:%d: bad pattern start \"%s\"; should be two decimal numbers\n",
                     filename, *line_number, s);
    return NULL;
  }
  
  if ((pattern->rows    < 1) || (pattern->rows    > MAX_PATTERN_SIZE) ||
      (pattern->columns < 1) || (pattern->columns > MAX_PATTERN_SIZE))
  {
    fprintf (stderr, "%s:%d: pattern size %dx%d bad; should be 1x1 to %dx%d\n",
                     filename, *line_number, pattern->rows, pattern->columns, MAX_PATTERN_SIZE, MAX_PATTERN_SIZE);
    return NULL;
  }
  
  pattern->positions = 0;
  
  for (i = 0; i < MAX_PATTERN_POSITIONS; i++)
  {
    pattern->row[i] = -1;
    pattern->col[i] = -1;
  }
  
  for (row = 0; row < pattern->rows; row++)
  {
    if ((s = Get_Line (file, line_number)) == NULL)
    {
      fprintf (stderr, "%s:%d: expected %d rows of pattern data, found only %d\n",
                       filename, *line_number, pattern->rows, row);
      return NULL;
    }
    
    for (column = 0; column < pattern->columns; column++)
    {
      while ((*s != NUL) && isspace (*s))
      {
        s++;
      }
      
      if (*s == NUL)
      {
        fprintf (stderr, "%s:%d: expected %d columns of pattern data for row %d, found only %d\n",
                         filename, *line_number, pattern->columns, row, column);
        return NULL;
      }
      
      if (strchr (valid_letters, *s) == NULL)
      {
        fprintf (stderr, "%s:%d: invalid pattern entry '%c' for row %d, column %d\n",
                         filename, *line_number, *s, row, column);
        return NULL;
      }
      
      pattern->letter[row][column] = *s;
      
      if ((*s >= '1') && (*s <= ('0' + MAX_PATTERN_POSITIONS)))
      {
        int position = *s - '0';
        
        pattern->row[position - 1] = row;
        pattern->col[position - 1] = column;
        
        if (position > pattern->positions)
        {
          pattern->positions = position;
        }
      }   // if loading a position letter
      
      s++;
    }   // for each column
  }   // for each row
  
  
  if ((s = Get_Line (file, line_number)) == NULL)
  {
    fprintf (stderr, "%s:%d: file ended trying to read position weights\n", filename, *line_number);
    return NULL;
  }
  
  for (i = 0; i < pattern->positions; i++)
  {
    if ((pattern->row[i] < 0) || (pattern->row[i] >= pattern->rows) ||
        (pattern->row[i] < 0) || (pattern->col[i] >= pattern->columns))
    {
      fprintf (stderr, "%s:%d: expected %d position indicators, but '%c' was missing\n",
                       filename, *line_number, pattern->positions, '1' + i);
      return NULL;
    }
    
    while ((*s != NUL) && isspace (*s))
    {
      s++;
    }
    
    if (*s == NUL)
    {
      fprintf (stderr, "%s:%d: expected %d position values; found only %d\n",
                       filename, *line_number, pattern->positions, i);
      return NULL;
    }
    
    if (sscanf (s, "%lg", &pattern->value[i]) != 1)
    {
      fprintf (stderr, "%s:%d: invalid floating point position value \"%s\"\n",
                       filename, *line_number, s);
      return NULL;
    }
    
    while ((*s != NUL) && !isspace (*s))
    {
      s++;
    }
  }   // for each position value
  
  return pattern;
}   // Pattern_Load
示例#12
0
//---------------------------------------------------------------------------
//背景六面体网格生成
int Mesher::Brick_background_mesh(ifstream &infile, struct RVE_Geo &cell_geo)
{
	//-----------------------------------------------------------------------------------------------------------------------------------------
	//读入单胞的长、宽和高的分割细度
	istringstream istr2(Get_Line(infile));	
	istr2 >> dx >> dy >> dz;
	if(dx<0||dy<0||dz<0)
	{
		hout << "RVE长宽高的分割细度输入错误! 请检查! ......... Brick_background_mesh" << endl;
		return 0;
	}

	//-----------------------------------------------------------------------------------------------------------------------------------------
	//背景网格(节点和单元)

	//生成各个方向的点数
	int x_sec_num = int(cell_geo.len_x/dx) +1;
	int y_sec_num = int(cell_geo.wid_y/dy)+1;
	int z_sec_num = int(cell_geo.hei_z/dz) +1;

	//微调整剖分步长,保证单胞的尺寸不变
	dx = cell_geo.len_x/(x_sec_num-1);
	dy = cell_geo.wid_y/(y_sec_num-1);
	dz = cell_geo.hei_z/(z_sec_num-1);

	//-----------------------------------------------------------------------------------------------------------------------------------------
	//记录分割细度到单胞信息中
	cell_geo.delt_x = dx;
	cell_geo.delt_y = dy;
	cell_geo.delt_z = dz;

	//-----------------------------------------------------------------------------------------------------------------------------------------
	//生成节点
	for( int i=0; i<z_sec_num; i++ )
	{
		double z = cell_geo.poi_min.z + i * dz ;
		for( int j=0; j<y_sec_num; j++ )
		{
			double y = cell_geo.poi_min.y + j * dy ;
			for( int k=0; k<x_sec_num; k++ )
			{
				double x = cell_geo.poi_min.x + k * dx ;

				Node nd(x,y,z);
				nd.type = Deter_node_type(i, j, k, z_sec_num-1, y_sec_num-1, x_sec_num-1);	//标注节点的位置(角点、边界线点、边界面点、内点)
				nodes.push_back(nd);
			}
		}
	}

	//-----------------------------------------------------------------------------------------------------------------------------------------
	//生成六面体单元

	//定义六面体向量
	for( int i=0; i<z_sec_num-1; i++ )
	{
		for( int j=0; j<y_sec_num-1; j++ )
		{
			for( int k=0; k<x_sec_num-1; k++ )
			{
				//六面体的八个顶点
				Element ele_temp;
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + j * x_sec_num + k);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + j * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + j * x_sec_num + k );
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + j * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k);

				elements.push_back(ele_temp);
			}
		}
	}

	return 1;
}
示例#13
0
//---------------------------------------------------------------------------
//Reading geometric information of the RVE
int Input::Read_rve_geometry(struct Geom_RVE &geom_rve, ifstream &infile)
{
    if(geom_rve.mark)
    {
        cout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl;
        hout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl;
        return 0;
    }
    else geom_rve.mark = true;

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the domain of RVE: the lower-left corner point of RVE and the length, width and height of RVE
    istringstream istr0(Get_Line(infile));
    istr0 >> geom_rve.origin.x >> geom_rve.origin.y >> geom_rve.origin.z;
    istr0 >> geom_rve.len_x >> geom_rve.wid_y >> geom_rve.hei_z;
    if(geom_rve.len_x<=0||geom_rve.wid_y<=0||geom_rve.hei_z<=0)
    {
        cout << "Error: the sizes of RVE should be positive!" << endl;
        hout << "Error: the sizes of RVE should be positive!" << endl;
        return 0;
    }
    geom_rve.volume = geom_rve.len_x*geom_rve.wid_y*geom_rve.hei_z;

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the size range of the observation window and descrement by every step in x, y and z directions
    istringstream istr1(Get_Line(infile));
    istr1 >> geom_rve.win_max_x >> geom_rve.win_max_y >> geom_rve.win_max_z;
    istringstream istr2(Get_Line(infile));
    istr2 >> geom_rve.win_delt_x >> geom_rve.win_delt_y >> geom_rve.win_delt_z;
    istringstream istr3(Get_Line(infile));
    istr3 >> geom_rve.win_min_x >> geom_rve.win_min_y >> geom_rve.win_min_z;

    if(geom_rve.win_max_x<=0.0||geom_rve.win_max_y<=0.0||geom_rve.win_max_z<=0.0||
            geom_rve.win_max_x>geom_rve.len_x||geom_rve.win_max_y>geom_rve.wid_y||geom_rve.win_max_z>geom_rve.hei_z)
    {
        cout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl;
        hout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl;
        return 0;
    }
    if(geom_rve.win_min_x<=0.0||geom_rve.win_min_y<=0.0||geom_rve.win_min_z<=0.0||
            geom_rve.win_min_x>geom_rve.win_max_x||geom_rve.win_min_y>geom_rve.win_max_y||geom_rve.win_min_z>geom_rve.win_max_z)
    {
        cout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl;
        hout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl;
        return 0;
    }
    if(geom_rve.win_delt_x<=0.0||geom_rve.win_delt_y<=0.0||geom_rve.win_delt_z<=0.0)
    {
        cout << "Error: the win_delt in each direction of RVE should be positive." << endl;
        hout << "Error: the win_delt in each direction of RVE should be positive." << endl;
        return 0;
    }

    //Details: +Zero for reducing the error of division
    int num[3] = {	(int)((geom_rve.win_max_x-geom_rve.win_min_x + Zero)/geom_rve.win_delt_x),
                    (int)((geom_rve.win_max_y-geom_rve.win_min_y + Zero)/geom_rve.win_delt_y),
                    (int)((geom_rve.win_max_z-geom_rve.win_min_z + Zero)/geom_rve.win_delt_z)
                 };

    if(num[0]!=num[1]||num[0]!=num[2])
    {
        cout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl;
        hout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl;
        return 0;
    }
    else geom_rve.cut_num = num[0];

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //Define the minimum size for background grids (looking for contact points)
    istringstream istr4(Get_Line(infile));
    istr4 >> geom_rve.gs_minx >> geom_rve.gs_miny >> geom_rve.gs_minz;
    if(geom_rve.gs_minx<=0||geom_rve.gs_miny<=0||geom_rve.gs_minz<=0)
    {
        cout << "Error: the number of segments in each direction of RVE should be positive!" << endl;
        hout << "Error: the number of segments in each direction of RVE should be positive" << endl;
        return 0;
    }
    else if((int)(geom_rve.win_max_x/geom_rve.gs_minx)>500||
            (int)(geom_rve.win_max_y/geom_rve.gs_miny)>500||
            (int)(geom_rve.win_max_z/geom_rve.gs_minz)>500)
    {
        cout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl;
        hout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl;
        return 0;
    }

    return 1;
}
示例#14
0
//---------------------------------------------------------------------------
//生成格子用于预估局部模型等效模量
int Mesher::Generate_grids_for_effective_stiffness(ifstream &infile, const double &decayR, double &grid_vol)
{
	//-----------------------------------------------------------------------------------------------------------------------------------------
	//读入格子尺寸(长、宽和高)
	istringstream istr(Get_Line(infile));	
	istr >> dx >> dy >> dz;
	if(dx<0||dy<0||dz<0)
	{
		hout << "预估刚度矩阵时,生成格子长宽高的分割细度输入错误! 请检查! ...Generate_grids_for_effective_stiffness" << endl;
		return 0;
	}

	//格子的体积
	grid_vol = dx*dy*dz;

	//生成各个方向的点数
	int x_sec_num = 2*(int(decayR/dx-Zero)+2);  //加一个小值为了避免取整的错误
	int y_sec_num = 2*(int(decayR/dy-Zero)+2);  //+2:一个+1是点的个数的一半比段数多1;一个+1是保证decayR<=n*dx(y,z)时,网格数要多1
	int z_sec_num = 2*(int(decayR/dz-Zero)+2);

	Point_3D origin(0,0,0);
	//-----------------------------------------------------------------------------------------------------------------------------------------
	//生成节点
	for( int i=0; i<z_sec_num; i++ )
	{
		double z = origin.z + i * dz ;
		for( int j=0; j<y_sec_num; j++ )
		{
			double y = origin.y + j * dy ;
			for( int k=0; k<x_sec_num; k++ )
			{
				double x = origin.x + k * dx ;

				Node nd(x,y,z);
				nodes.push_back(nd);
			}
		}
	}

	//-----------------------------------------------------------------------------------------------------------------------------------------
	//生成六面体单元

	//定义六面体向量
	for( int i=0; i<z_sec_num-1; i++ )
		for( int j=0; j<y_sec_num-1; j++ )
			for( int k=0; k<x_sec_num-1; k++ )
			{
				//六面体的八个顶点
				Element ele_temp;
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + j * x_sec_num + k);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + j * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(i * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + j * x_sec_num + k );
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + j * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k + 1);
				ele_temp.nodes_id.push_back(( i + 1 ) * x_sec_num * y_sec_num + ( j + 1 ) * x_sec_num + k);

				elements.push_back(ele_temp);
			}

	return 1;
}
示例#15
0
//---------------------------------------------------------------------------
//Read data
int Input::Read_Infile(ifstream &infile)
{

    cout << "Reading input file..." << endl;
    hout << "Reading input file..." << endl;

    while(!infile.eof())
    {
        istringstream istr(Get_Line(infile));
        if(infile.eof()) break;
        string str_temp;
        istr >> str_temp;

        if(str_temp.empty()) continue;  //skip over the space or Enter key after every input item
        else if(str_temp=="Application_Name") {
            if(Read_application_name(app_name, infile)==0) return 0;
        }
        else if(str_temp=="Simulation_Parameters")	{
            if(Read_simulation_parameters(simu_para, infile)==0) return 0;
        }
        else if(str_temp=="RVE_Geometry")	{
            if(Read_rve_geometry(geom_rve, infile)==0) return 0;
        }
        else if(str_temp=="Nanotube_Geometry")	{
            if(Read_nanotube_geo_parameters(nanotube_geo, infile)==0) return 0;
        }
        else if(str_temp=="Cluster_Geometry")	{
            if(Read_cluster_geo_parameters(cluster_geo, infile)==0) return 0;
        }
        else if(str_temp=="Cutoff_Distances")	{
            if(Read_cutoff_distances(cutoff_dist, infile)==0) return 0;
        }
        else if(str_temp=="Electrical_Parameters")	{
            if(Read_electrical_paramters(electric_para, infile)==0) return 0;
        }
        else
        {
            cout << "Error: the keywords \"" << str_temp << "\" is not defined!" << endl;
            hout << "Error: the keywords \"" << str_temp << "\" is not defined!" << endl;
            return 0;
        }

        //the real volume of cnts in the RVE
        if(geom_rve.mark&&nanotube_geo.mark)
        {
            //Calculate the real volume of nanotubes
            nanotube_geo.real_volume = nanotube_geo.volume_fraction * geom_rve.volume;
            //Define the extented RVE with one length of nanotube
            geom_rve.ex_origin.x = geom_rve.origin.x - nanotube_geo.len_max;
            geom_rve.ex_origin.y = geom_rve.origin.y - nanotube_geo.len_max;
            geom_rve.ex_origin.z = geom_rve.origin.z - nanotube_geo.len_max;
            geom_rve.ex_len = geom_rve.len_x + 2*nanotube_geo.len_max;
            geom_rve.ey_wid = geom_rve.wid_y+ 2*nanotube_geo.len_max;
            geom_rve.ez_hei = geom_rve.hei_z + 2*nanotube_geo.len_max;
        }
    }

    cout << "Reading the keywords is finished!" << endl;
    hout << "Reading the keywords is finished!" << endl;

    if(!app_name.mark) {
        cout << "Attention: \"Application_Name\" will use default parameters!" << endl;
        hout << "Attention: \"Application_Name\" will use default parameters!" << endl;
    }
    if(!simu_para.mark) {
        cout << "Attention: \"Simulation_Parameters\" will use default parameters!" << endl;
        hout << "Attention: \"Simulation_Parameters\" will use default parameters!" << endl;
    }
    if(!geom_rve.mark) {
        cout << "Attention: \"RVE_Geometry\" will use default parameters!" << endl;
        hout << "Attention: \"RVE_Geometry\" will use default parameters!" << endl;
    }
    if(!nanotube_geo.mark) {
        cout << "Attention: \"Nanotube_Geometry\" will use default parameters!" << endl;
        hout << "Attention: \"Nanotube_Geometry\" will use default parameters!" << endl;
    }
    if(!cluster_geo.mark) {
        cout << "Attention: \"Cluster_Geometry\" will use default parameters!" << endl;
        hout << "Attention: \"Cluster_Geometry\" will use default parameters!" << endl;
    }
    if(!cutoff_dist.mark) {
        cout << "Attention: \"Cutoff_Distances\" will use default parameters!" << endl;
        hout << "Attention: \"Cutoff_Distances\" will use default parameters!" << endl;
    }
    if(!electric_para.mark) {
        cout << "Attention: \"Electrical_Parameters\" will use default parameters!" << endl;
        hout << "Attention: \"Electrical_Parameters\" will use default parameters!" << endl;
    }

    return 1;
}
示例#16
0
void CheatFile::Get_Cheat_Info( int num, CHEAT_INFO &info )
{
	int list_ptr;
	int notes_lines;

	/*
	"cheat name
	; comment
	@id
	; comment
	80 xxxxxx xxxx
	; comment
	$option - line 1
	$option - line 2
	$option - line 3
	; comment
	.notes - line 1
	.notes - line 2
	; comment
	"next cheat
	*/

	// init
	list_ptr = _cheat_index[ num ];
	notes_lines = 0;
	
	memset( &info, 0, sizeof(CHEAT_INFO) );


	while( list_ptr < _cheat_index[ num+1 ] )
	{
		switch( _file[ list_ptr ] )
		{
			// name
			case '"':
				info.name = _file + list_ptr + 1;


				// check for sub-directory
				if( info.name[0] == '\\' && info.name[1] == '\\' )
				{
					info.subdir = 1;

					info.name += 2;
				}
				break;


			// ID
			case '@':
				sscanf_s( _file + list_ptr + 1, "%d", &info.id );
				break;


			// options
			case '$':
				{
					// option value
					sscanf_s( _file + list_ptr, "$%X", &info.option_value[ info.num_options ] );


					// option name
					int lcv2;

					lcv2 = 0;
					while( _file[ list_ptr + lcv2 ] != ' ' )
						lcv2++;
					while( _file[ list_ptr + lcv2 ] == ' ' )
						lcv2++;

					info.options_name[ info.num_options ] = _file + list_ptr + lcv2;


					info.num_options++;
				}
				break;


			// notes
			case '.':
				notes_lines++;

				// start of cheat comments
				if( notes_lines == 1 )
				{
					strcpy_s( _cheat_notes, _file + list_ptr + 1 );

					info.notes = _cheat_notes;
				}

				// notes 1 += '\r\n' + notes 2
				else
				{
					strcat_s( _cheat_notes, "\r\n" );
					strcat_s( _cheat_notes, _file + list_ptr + 1 );
				}
				break;


			// misc - comment, code, other
			default:
				break;
		}


		list_ptr = Get_Line( list_ptr );
	}
}
示例#17
0
//---------------------------------------------------------------------------
void EllipseMade::ellip_generation(ifstream &infile,string output_file,string data_file,double mod)
{
    struct  point_type
    {
        double	x;
        double	y;
        double	z;
    };

    double	x,y,z;
    double	x1,y1,z1;
    double	A,B,C;
    double	a_max,a_min,b_min,c_min;		// the ellipse the max a and the min a and the min b,a is half of the long axis,b is the half of the short axis.
    double  sita,phi;
    double  alpha1,beta1,alpha2;
    double	sign;
    double  d,f;								// the distance between two ellipses center
    double  vol_ratio;
    int		times;
    int		k1,K,l1,L;

    istringstream istr0(Get_Line(infile));		//长方体区域的六条边
    istr0	>> space.x0 >> space.x >> space.y0 >> space.y >> space.z0 >> space.z;

    istringstream istr2(Get_Line(infile));		//椭球长中短轴信息
    istr2 >> a_min >> a_max >> b_min >> c_min;
    if (a_min>a_max)
    {
        hout << "输入的椭球长轴最小值大于最大值!" << endl;
        exit(0);
    }

    istringstream istr6(Get_Line(infile));		//体积百分比
    istr6 >> vol_ratio;
//@
    //	int in;
    //	ifstream o("num.dat");
    //	o>>in;
    //	o.close();
    //if(in>10) in=in-10;
    //else if(in>5) in=in-5;
    //vol_ratio=vol_ratio*in;

    //-------------------------------------------------------------
    //椭球生成计数器
    double delt_h = 2*sqrt(pow(c_min,2)*(pow(a_max,2)-pow(a_max-(a_min+c_min)*epsilon,2))/pow(a_max,2))/pi;
    double cell_volume = (space.x-space.x0)*(space.y-space.y0)*(space.z-space.z0);
    double ellip_volume = 0.0;
    ellip_ratio = 0.0;
    times=0;

    //用于随机生成的起始时间
    srand((unsigned int)time(0));

    do
    {
        //-------------------------------------------------------------
        //产生椭球
        struct elliparam ell_temp;

        ell_temp.x=((double)(rand())/RAND_MAX)*(space.x-space.x0)+space.x0;
        ell_temp.y=((double)(rand())/RAND_MAX)*(space.y-space.y0)+space.y0;
        ell_temp.z=((double)(rand())/RAND_MAX)*(space.z-space.z0)+space.z0;

        ell_temp.a=((double)(rand())/RAND_MAX)*(a_max-a_min)+a_min;
        if(!(b_min==0&&c_min==0))
        {
            ell_temp.b=((double)(rand())/RAND_MAX)*(ell_temp.a-b_min)+b_min;
            ell_temp.c=((double)(rand())/RAND_MAX)*(ell_temp.a-c_min)+c_min;
        }
        else
        {
            ell_temp.b=ell_temp.a;
            ell_temp.c=ell_temp.a;
        }

        alpha1 =((double)(rand())/RAND_MAX)*pi;
        if(alpha1>pi/2.0)
        {
            beta1  =((double)(rand())/RAND_MAX)*(2*(pi-alpha1))+(alpha1-pi/2.0);
        }
        else
        {
            beta1  =((double)(rand())/RAND_MAX)*(2*alpha1)+(pi/2.0-alpha1);
        }
        ell_temp.alpha1 =cos(alpha1);																// r1 from 0 to pi
        ell_temp.beta1  =cos(beta1);																	// r2 from (pi/2-r1) to (pi/2+r1)
        ell_temp.gamma1 =(int)pow(-1.0,(int)fmod(rand(),2.0)+1)*sqrt(1-pow(ell_temp.alpha1,2)-pow(ell_temp.beta1,2));	// choose one in both, minus value or positive value

        if(alpha1>pi/2.0)
        {
            alpha2  =((double)(rand())/RAND_MAX)*(2*(pi-alpha1))+(alpha1-pi/2.0);
        }
        else
        {
            alpha2  =((double)(rand())/RAND_MAX)*(2*alpha1)+(pi/2.0-alpha1);
        }
        ell_temp.alpha2=cos(alpha2);

        A=1+pow(ell_temp.beta1/ell_temp.gamma1,2);
        B=2*(ell_temp.alpha1*ell_temp.alpha2*ell_temp.beta1)/pow(ell_temp.gamma1,2);
        C=pow(ell_temp.alpha1*ell_temp.alpha2/ell_temp.gamma1,2)+pow(ell_temp.alpha2,2)-1.0;

        ell_temp.beta2	 =(-B+(int)pow(-1.0,(int)fmod(rand(),2.0)+1)*sqrt(pow(B,2)-4*A*C))/(2.0*A);
        ell_temp.gamma2 =-(ell_temp.beta1/ell_temp.gamma1)*ell_temp.beta2-(ell_temp.alpha1*ell_temp.alpha2/ell_temp.gamma1);

        sign=(ell_temp.alpha1*ell_temp.beta2)/fabs(ell_temp.alpha1*ell_temp.beta2);
        ell_temp.alpha3 =sign*sqrt(1-pow(ell_temp.alpha1,2)-pow(ell_temp.alpha2,2));
        ell_temp.beta3	 =-(ell_temp.alpha1*ell_temp.beta1+ell_temp.alpha2*ell_temp.beta2)/ell_temp.alpha3;
        ell_temp.gamma3 =-(ell_temp.alpha1*ell_temp.gamma1+ell_temp.alpha2*ell_temp.gamma2)/ell_temp.alpha3;

        ell_temp.a=(1+epsilon)*ell_temp.a;
        ell_temp.b=(1+epsilon)*ell_temp.b;
        ell_temp.c=(1+epsilon)*ell_temp.c;
        //---------------------------------------------------------------------------
        //check this ellipse
        //---------------------------------------------------------------------------
        //whether this ellipse intersect with other ellipses
        k1=(int)(sqrt(pow(ell_temp.a,2)+pow(ell_temp.b,2))/delt_h);
        K=4*(k1+1);
        sita=pi/(K/2.0);

        //(添加一段程序080414)考虑不与边界相交的情况
        //for(int j=1;j<=K/2;j++)
        //{
        //	l1=(int)(sqrt(pow(ell_temp.a*sin(j*sita),2)+pow(ell_temp.b*sin(j*sita),2))/delt_h);
        //	L=4*(l1+1);
        //	phi=2*pi/L;

        //	for(int m=1;m<=L;m++)
        //	{
        //		x=ell_temp.a*sin(j*sita)*cos(m*phi);
        //		y=ell_temp.b*sin(j*sita)*sin(m*phi);
        //		z=ell_temp.c*cos(j*sita);

        //		x1=ell_temp.x+x*ell_temp.alpha1+y*ell_temp.alpha2+z*ell_temp.alpha3;
        //		y1=ell_temp.y+x*ell_temp.beta1+y*ell_temp.beta2+z*ell_temp.beta3;
        //		z1=ell_temp.z+x*ell_temp.gamma1+y*ell_temp.gamma2+z*ell_temp.gamma3;

        //		x=x1;
        //		y=y1;
        //		z=z1;

        //		if(x1<=space.x0+0.04||x1>=space.x-0.04||y1<=space.y0+0.04||y1>=space.y-0.04||z1<=space.z0+0.04||z1>=space.z-0.04)
        //		{
        //			times=times+1;
        //			goto gen_again;
        //		}
        //	}
        //}

        for(int i=0; i<int(ellip.size()); i++)
        {
            //probably estimate
            d=sqrt(pow(ell_temp.x-ellip[i].x,2)+pow(ell_temp.y-ellip[i].y,2)+pow(ell_temp.z-ellip[i].z,2));

            if(d>=ell_temp.a+ellip[i].a+2*epsi)
            {
                goto gene;
            }
            else if((d<ell_temp.b+ellip[i].b+2*epsi*(ellip[i].b/ellip[i].a))&&(d<ell_temp.c+ellip[i].c+2*epsi*(ellip[i].c/ellip[i].a)))
            {
                times=times+1;
                goto gen_again;
            }
            else
            {
                //exactly compute
                for(int j=1; j<=K/2; j++)
                {
                    l1=(int)(sqrt(pow(ell_temp.a*sin(j*sita),2)+pow(ell_temp.b*sin(j*sita),2))/delt_h);
                    L=4*(l1+1);
                    phi=2*pi/L;

                    for(int m=1; m<=L; m++)
                    {
                        x=ell_temp.a*sin(j*sita)*cos(m*phi);
                        y=ell_temp.b*sin(j*sita)*sin(m*phi);
                        z=ell_temp.c*cos(j*sita);

                        x1=ell_temp.x+x*ell_temp.alpha1+y*ell_temp.alpha2+z*ell_temp.alpha3;
                        y1=ell_temp.y+x*ell_temp.beta1+y*ell_temp.beta2+z*ell_temp.beta3;
                        z1=ell_temp.z+x*ell_temp.gamma1+y*ell_temp.gamma2+z*ell_temp.gamma3;

                        x=x1;
                        y=y1;
                        z=z1;

                        x=x-ellip[i].x;
                        y=y-ellip[i].y;
                        z=z-ellip[i].z;

                        x1=x*ellip[i].alpha1+y*ellip[i].beta1+z*ellip[i].gamma1;
                        y1=x*ellip[i].alpha2+y*ellip[i].beta2+z*ellip[i].gamma2;
                        z1=x*ellip[i].alpha3+y*ellip[i].beta3+z*ellip[i].gamma3;

                        f=pow(x1,2)/pow(ellip[i].a,2)+pow(y1,2)/pow(ellip[i].b,2)+pow(z1,2)/pow(ellip[i].c,2)-1.0;

                        if(f<0.0)
                        {
                            times=times+1;
                            goto gen_again;
                        }
                    }
                }
            }
gene:
            ;
        }
        //---------------------------------------------------------------------
        //次数清零并插入椭球向量
        times=0;
        ellip.push_back(ell_temp);
        //---------------------------------------------------------------------
        //计算体积比
        ellip_volume = ellip_volume + ellipse_volume(ell_temp,epsilon);
        ellip_ratio = ellip_volume/cell_volume;
gen_again:
        ;
    } while(times<=N_times&&ellip_ratio<vol_ratio);

    //---------------------------------------------------------------------
    //椭球收缩
    for(int i=0; i<int(ellip.size()); i++)
    {
        ellip[i].a=ellip[i].a/(1+epsilon);
        ellip[i].b=ellip[i].b/(1+epsilon);
        ellip[i].c=ellip[i].c/(1+epsilon);
    }

    //---------------------------------------------------------------------
    //画图
//	if(mod!=0) draw_tecplot("generate_ellipse.dat",delt_h);

    //---------------------------------------------------------------------
    //输出数据
    if(mod!=0) output_EllipseData(output_file);

    //---------------------------------------------------------------------
    //输入到样本数据文件
    output_Datafile(data_file);

}