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

📄 plt_loader_read.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 2 页
字号:
      std::cout << "Variable Types: ";            for (unsigned int v=0; v<this->n_vars(); v++)	std::cout << this->var_type (v) << " ";        std::cout << std::endl;      std::cout << "Zone Names: ";      for (unsigned int z=0; z<this->n_zones(); z++)	std::cout << "\"" << this->zone_name (z) << "\"" << " ";      std::cout << std::endl;      std::cout << "Zone Types: ";      for (unsigned int z=0; z<this->n_zones(); z++)	{	  std::cout << this->zone_type (z) << " ";	  if (this->zone_type (z) != ORDERED)	    std::cout << "(" << this->n_nodes(z) << "," << this->n_elem(z) << ") ";	}      std::cout << std::endl;      std::cout << "Zone Dimensions: " << std::endl;      for (unsigned int z=0; z<this->n_zones(); z++)	std::cout << "  ("		  << this->imax(z) << "," 		  << this->jmax(z) << "," 		  << this->kmax(z) << ")"		  << std::endl;      }}void PltLoader::read_data (std::istream& in){  libmesh_assert (in.good());  // A byte-reverser in case the data is foreign  Utility::ReverseBytes rb(this->is_foreign());    //----------------------------------------------------  // Read the TECPLOT data for each zone  if (this->verbose())    {      std::cout << "Reading Zones";      std::cout.flush();    }          for (unsigned int zone=0; zone<this->n_zones(); zone++)    {      if (this->verbose())	{	  std::cout << ".";	  std::cout.flush();	}      //----------------------------------------------------      // Read plt files written by older versions of Tecplot      if (this->version().rfind("V7") < this->version().size())	{	  float f = 0.;	  	  // Find the next Zone marker.	  do	    {	      f = 0.;	      in.read (buf, SIZEOF_FLOAT);	      std::memcpy  (&f, buf, SIZEOF_FLOAT);	      rb(f);	    }	  while ((f != 299.) && in.good());		  // Did we overrun the file?	  if (!in.good())	    {	      std::cerr << "ERROR: Unexpected end-of-file!"			<< std::endl;	      libmesh_error();	    }	  // Get the number of repeated vars.	  unsigned int n_rep_vars=0;	  std::vector<int> rep_vars;		  {		    in.read (buf, SIZEOF_INT);	    std::memcpy  (&n_rep_vars, buf, SIZEOF_INT);	    rb(n_rep_vars);	    rep_vars.resize (n_rep_vars);		    // Get the repeated variables number.	    for (unsigned int v=0; v<n_rep_vars; v++)	      {		std::cerr << "ERROR:  I don't understand repeated variables yet!"			  << std::endl;		libmesh_error();	    		in.read (buf, SIZEOF_INT);		std::memcpy  (&rep_vars[v], buf, SIZEOF_INT);		rb(rep_vars[v]);	      }		  }	  // Get the variable data type	  //std::cout << "var_types=";	  for (unsigned int v=0; v<this->n_vars(); v++)	    {	      in.read (buf, SIZEOF_INT);	      std::memcpy  (&this->var_type(v), buf, SIZEOF_INT);	      rb(this->var_type(v));	      //std::cout << this->var_type(v) << " ";	    }	  //std::cout << std::endl;      	  // Read the data.	  switch (this->zone_type(zone) )	    {	      // Block-based data.  Structured meshes.	    case BLOCK:	      {		this->read_block_data (in, zone);		break;	      }	  	      // Point-based data.  Structured meshes.	    case POINT:	      {		this->read_point_data (in, zone);		break;	      }	  	      // FE block data.  Unstructured meshes.	    case FEBLOCK:	      {		this->read_feblock_data (in, zone);	    		if (this->verbose())	      		  std::cout << "Zone " << zone << ":" << std::endl			    << "  nnodes   =" << this->imax(zone) << std::endl			    << "  nelem    =" << this->jmax(zone) << std::endl			    << "  elem_type=" << this->kmax(zone) << std::endl			    << std::endl;		break;	      }	      // FE point data.  Unstructured meshes.	    case FEPOINT:	      {		this->read_fepoint_data (in, zone);		break;	      }	  	    default:	      {		std::cerr << "ERROR: Unsupported Zone type: "			  << this->zone_type(zone)			  << std::endl;		libmesh_error();	      }	    } // end switch on zone type	}        //----------------------------------------------------      // Read plt files written by newer versions of Tecplot      else if (this->version().rfind("V1") < this->version().size())	{	  float f = 0.;	  	  // Find the next Zone marker.	  do	    {	      f = 0.;	      in.read (buf, SIZEOF_FLOAT);	      std::memcpy  (&f, buf, SIZEOF_FLOAT);	      rb(f);	    }	  while ((f != 299.) && in.good());		  // Did we overrun the file?	  if (!in.good())	    {	      std::cerr << "ERROR: Unexpected end-of-file!"			<< std::endl;	      libmesh_error();	    }	  // Get the variable data type	  for (unsigned int v=0; v<this->n_vars(); v++)	    {	      in.read (buf, SIZEOF_INT);	      std::memcpy  (&this->var_type(v), buf, SIZEOF_INT);	      rb(this->var_type(v));	      //std::cout << this->var_type(v) << " ";	    }	  // Get the variable sharing flag	  {	    int vs=0;	    int sv=0;	    in.read (buf, SIZEOF_INT);	    std::memcpy  (&vs, buf, SIZEOF_INT);	    rb(vs);	    if (vs)	      {		for (unsigned int v=0; v<this->n_vars(); v++)		  {		    in.read (buf, SIZEOF_INT);		    std::memcpy  (&sv, buf, SIZEOF_INT);		    rb(sv);		    		    if (sv != -1)		      {			std::cerr << "ERROR:  I don't understand variable sharing!"				  << std::endl;			libmesh_error();		      }		  }	      }	  }	  // Get zone to share connectivity with	  {	    int sc=0;	    in.read (buf, SIZEOF_INT);	    std::memcpy  (&sc, buf, SIZEOF_INT);	    rb(sc);	    	    libmesh_assert (sc == -1);	  }      	  // Read the data.	  if (this->zone_type(zone) == ORDERED)	    {		// Block-based data.  Structured meshes.	      if (this->zone_pack(zone) == 0)		this->read_block_data (in, zone);	  	      // Point-based data.  Structured meshes.	      else if (this->zone_pack(zone) == 1)		this->read_point_data (in, zone);	      else		libmesh_error();	    }	  else	    {	      // Block-based data.  Unstructured meshes.	      if (this->zone_pack(zone) == 0)		this->read_feblock_data (in, zone);	      // Point-based data.  Unstructured meshes.	      else if (this->zone_pack(zone) == 1)		this->read_fepoint_data (in, zone);	      else		libmesh_error();	    }	}        //----------------------------------------------------      // Unrecognized Tecplot Version!      else	{	  std::cerr << "ERROR:  This plot file was written by an unrecognized version of Tecplot!:"		    << std::endl		    << this->version()		    << std::endl;	  libmesh_error();	}          } // end loop on zones}void PltLoader::read_block_data (std::istream& in, const unsigned int zone){  libmesh_assert (in.good());    // A byte-reverser in case the data is foreign  Utility::ReverseBytes rb(this->is_foreign());    for (unsigned int var=0; var<this->n_vars(); var++)     {            switch (this->var_type(var))	{	  	  // Read a single-precision variable	case FLOAT:	  {	    std::vector<float> & data = _data[zone][var];	    	    data.clear();	    data.resize (this->imax(zone)*			 this->jmax(zone)*			 this->kmax(zone));	    	    in.read ((char*) &data[0], SIZEOF_FLOAT*data.size());	    for (unsigned int i=0; i<data.size(); i++)	      rb(data[i]);	    	    break;	  }	  	  // Read a double-precision variable	case DOUBLE:	  {	    std::vector<double> ddata;	    std::vector<float> & data = _data[zone][var];	    	    data.clear();	    data.resize (this->imax(zone)*			 this->jmax(zone)*			 this->kmax(zone));	    	    ddata.resize (this->imax(zone)*			  this->jmax(zone)*			  this->kmax(zone));	    	    in.read ((char*) &ddata[0], SIZEOF_DOUBLE*ddata.size());	    for (unsigned int i=0; i<data.size(); i++)	      data[i] = rb(ddata[i]);	    	    break;	  }		      	default:	  {	    std::cerr << "ERROR: Unsupported data type: "		      << this->var_type(var)		      << std::endl;	    libmesh_error();	  }	}    }}void PltLoader::read_point_data (std::istream& in, const unsigned int zone){  libmesh_assert (in.good());  // A byte-reverser in case the data is foreign  Utility::ReverseBytes rb(this->is_foreign());  // First allocate space  for (unsigned int var=0; var<this->n_vars(); var++)    {      std::vector<float> & data = _data[zone][var];            data.clear();      data.reserve (this->imax(zone)*		    this->jmax(zone)*		    this->kmax(zone));    }    for (unsigned int k=0; k<this->kmax(zone); k++)    for (unsigned int j=0; j<this->jmax(zone); j++)      for (unsigned int i=0; i<this->imax(zone); i++)	for (unsigned int var=0; var<this->n_vars(); var++)	  if (this->var_type(var) == FLOAT)	    {	      float f = 0.;	      	      libmesh_assert (in.good());	      	      in.read (buf, SIZEOF_FLOAT);	      std::memcpy  (&f, buf, SIZEOF_FLOAT);	      rb(f);		    	      _data[zone][var].push_back(f);				    }	  else if (this->var_type(var) == DOUBLE)	    {	      double d = 0.;	      	      libmesh_assert (in.good());	      	      in.read (buf, SIZEOF_DOUBLE);	      std::memcpy  (&d, buf, SIZEOF_DOUBLE);	      rb(d);	      	      _data[zone][var].push_back(d);				    }	  else	    {	      std::cerr << "ERROR: unsupported data type: "			<< this->var_type(var)			<< std::endl;	      libmesh_error();	    }}void PltLoader::read_feblock_data (std::istream& in, const unsigned int zone){  libmesh_assert (in.good());  // A byte-reverser in case the data is foreign  Utility::ReverseBytes rb(this->is_foreign());  // Read the variable values at each node.  for (unsigned int var=0; var<this->n_vars(); var++)     {            switch (this->var_type(var))	{	  	  // Read a single-precision variable	case FLOAT:	  {	    std::vector<float> & data = _data[zone][var];	    	    data.clear();	    data.resize (this->imax(zone));	    	    in.read ((char*) &data[0], SIZEOF_FLOAT*data.size());	    for (unsigned int i=0; i<data.size(); i++)	      rb(data[i]);	    	    break;	  }	  	  // Read a double-precision variable	case DOUBLE:	  {	    std::vector<double> ddata;	    std::vector<float> & data = _data[zone][var];	    	    data.clear();	    data.resize (this->imax(zone));	    ddata.resize (this->imax(zone));	    	    in.read ((char*) &ddata[0], SIZEOF_DOUBLE*ddata.size());	    for (unsigned int i=0; i<data.size(); i++)	      data[i] = rb(ddata[i]);	    	    break;	  }		      	default:	  {	    std::cerr << "ERROR: Unsupported data type: "		      << this->var_type(var)		      << std::endl;	    libmesh_error();	  }	}    }  // Read the connectivity  {    // Get the connectivity repetition flag    int rep=0;    in.read ((char*) &rep, SIZEOF_INT);    rb(rep);    if (rep == 1 && this->n_zones() > 1)      {	std::cerr << "ERROR:  Repeated connectivity not supported!"		  << std::endl;	libmesh_error();      }    // Read the connectivity    else      {	libmesh_assert (zone < _conn.size());	libmesh_assert (this->kmax(zone) < 4);		_conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);		in.read ((char*) &_conn[zone][0], SIZEOF_INT*_conn[zone].size());	for (unsigned int i=0; i<_conn[zone].size(); i++)	  rb(_conn[zone][i]);      }  }  }void PltLoader::read_fepoint_data (std::istream& in, const unsigned int zone){  libmesh_assert (in.good());  // A byte-reverser in case the data is foreign  Utility::ReverseBytes rb(this->is_foreign());  // First allocate space  for (unsigned int var=0; var<this->n_vars(); var++)    {      std::vector<float> & data = _data[zone][var];            data.clear();      data.reserve (this->imax(zone));    }    for (unsigned int i=0; i<this->imax(zone); i++)    for (unsigned int var=0; var<this->n_vars(); var++)      if (this->var_type(var) == FLOAT)	{	  float f = 0.;	  	  libmesh_assert (in.good());	  	  in.read (buf, SIZEOF_FLOAT);	  std::memcpy  (&f, buf, SIZEOF_FLOAT);	  rb(f);	  	  _data[zone][var].push_back(f);				}      else if (this->var_type(var) == DOUBLE)	{	  double d = 0.;	  	  libmesh_assert (in.good());	  	  in.read (buf, SIZEOF_DOUBLE);	  std::memcpy  (&d, buf, SIZEOF_DOUBLE);	  rb(d);	  	  _data[zone][var].push_back(d);				}      else	{	  std::cerr << "ERROR: unsupported data type: "		    << this->var_type(var)		    << std::endl;	  libmesh_error();	}  // Read the connectivity  {    // Get the connectivity repetition flag    int rep=0;    in.read ((char*) &rep, SIZEOF_INT);    rb(rep);    if (rep == 1)      {	std::cerr << "ERROR:  Repeated connectivity not supported!"		  << std::endl;	libmesh_error();      }    // Read the connectivity    else      {	libmesh_assert (zone < _conn.size());	libmesh_assert (this->kmax(zone) < 4);		_conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);		in.read ((char*) &_conn[zone][0], SIZEOF_INT*_conn[zone].size());	for (unsigned int i=0; i<_conn[zone].size(); i++)	  rb(_conn[zone][i]);      }  }}

⌨️ 快捷键说明

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