eclipse油藏数值模拟器的文件读写c/c++算法库libecl的使用学习1

https://github.com/equinor/libecl.git

按照这个库的地址,编译之后可以得到lib、bin、include文件夹,在visual 下配置即可使用,配置方法其它库方法类似。

libecl is a package for reading and writing the result files from the Eclipse reservoir simulator. The file types covered are the restart, init, rft, summary and grid files. Both unified and non-unified and formatted and unformatted files are supported.

libecl is mainly developed on Linux and macOS, in addition there is a portability layer which ensures that most of the functionality is available on Windows. The main functionality is written in C/C++, and should typically be linked in in other compiled programs. libecl was initially developed as part of the Ensemble Reservoir Tool, other applications using libecl are the reservoir simulator flow and Resinsight from the OPM project.

这里介绍关于网格、网格属性数据的相关对象和函数。

1、关于eclipse网格部分

Libecl可以读取的网格是eclipse的grid和egrid格式,都是二进制的。对文本格式的grdecl不完全支持。这个库大部分都是c语言函数,很难通过对象及属性的方法获取需要的数据,一般都是通过函数的方法,下面是读取grid文件并输出网格信息的一个例子。

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/util/util.h>

int main()
{
    std::cout << "Hello World!\n";
	ecl_grid_type* ecl_grid;
	const char* grid_fileName = "E:\\case3D_1\\case3D_1.GRID";
	ecl_grid = ecl_grid_alloc(grid_fileName);
	std::cout << "read grid done" << std::endl;
	ecl_grid_summarize(ecl_grid);  //输出网格摘要信息
	double x0, y0, z0, * x0Ptr, * y0Ptr, * z0Ptr;
	x0 = 0; y0 = 0; z0 = 0;
	x0Ptr = &x0;
	y0Ptr = &y0;
	z0Ptr = &z0;
	//获取第一个网格8个顶点的坐标信息
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 0, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 1, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 2, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 3, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 4, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 5, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 6, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	ecl_grid_get_cell_corner_xyz3(ecl_grid, 0, 0, 0, 7, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	//获取节点坐标信息
	ecl_grid_get_corner_xyz(ecl_grid, 0, 0, 0, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;
	//获取网格深度信息
	std::cout << "cell depth=" << ecl_grid_get_cdepth3(ecl_grid, 0, 0, 0) << std::endl;
	//获取节点坐标信息
	ecl_grid_get_corner_xyz(ecl_grid, 0, 0, 5, x0Ptr, y0Ptr, z0Ptr);
	std::cout << "x0=" << *x0Ptr << " y0=" << *y0Ptr << " z0=" << *z0Ptr << std::endl;

	//把对象写出到文本格式的grid文件
	const char* output_file = "E:\\case3D_1\\case3D_1_ascii.GRID";
	FILE* stream = util_mkdir_fopen(output_file, "w");
	//stream=stdout
	ecl_grid_dump_ascii(ecl_grid, false, stream);

	//释放对象的内存
	ecl_grid_free(ecl_grid);

    
    return 0;
}

 

其中ecl_grid_alloc是把grid文件读入到内存,成为ecl_grid_type对象。

函数ecl_grid_summarize() 是获取grid网格的统计信息,

函数ecl_grid_dump_ascii()是把对象写出为文本格式

函数ecl_grid_free()是释放内存。

计算结果如下:

 

从ecl_grid.hpp头文件可以看出,libecl提供了 多达192个类似ecl_grid_summarize的函数,可以获取网格相关的值,这些函数的作用从函数上基本就可以看出,具体函数可以查看头文件。

这里举几个例子:

//作用是获取指定I,j,k 网格单元8个顶点中某个顶点的三维坐标,其中corner_nr指定顶点编号,取值为0~7。 
 void  ecl_grid_get_cell_corner_xyz3(const ecl_grid_type * grid , int i , int j , int k, int corner_nr , double * xpos , double * ypos , double * zpos ); 
//作用是直接获取顶点的三维坐标
  void  ecl_grid_get_corner_xyz(const ecl_grid_type * grid , int i , int j , int k, double * xpos , double * ypos , double * zpos ); 

下面是每个函数的声明语句,可以找到自己需要的功能

bool                         ecl_grid_have_coarse_cells( const ecl_grid_type * main_grid );

  bool                         ecl_grid_cell_in_coarse_group1( const ecl_grid_type * main_grid , int global_index );

  bool                         ecl_grid_cell_in_coarse_group3( const ecl_grid_type * main_grid , int i , int j , int k);

  int                          ecl_grid_get_num_coarse_groups( const ecl_grid_type * main_grid );

  ecl_coarse_cell_type       * ecl_grid_iget_coarse_group( const ecl_grid_type * ecl_grid , int coarse_nr );

  ecl_coarse_cell_type       * ecl_grid_get_cell_coarse_group1( const ecl_grid_type * ecl_grid , int global_index);

  ecl_coarse_cell_type       * ecl_grid_get_cell_coarse_group3( const ecl_grid_type * ecl_grid , int i , int j , int k);



  int ecl_grid_get_cell_twist1( const ecl_grid_type * ecl_grid, int global_index );

  int ecl_grid_get_cell_twist3( const ecl_grid_type * ecl_grid, int i , int j , int k);



  void            ecl_grid_get_column_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j, double_vector_type * column);

  int             ecl_grid_get_global_index_from_xy_top( const ecl_grid_type * ecl_grid , double x , double y);

  int             ecl_grid_get_global_index_from_xy_bottom( const ecl_grid_type * ecl_grid , double x , double y);

  ecl_grid_type * ecl_grid_alloc_dx_dy_dz_tops( int nx, int ny , int nz , const double * dx , const double * dy , const double * dz , const double * tops , const int * actnum);



  void            ecl_grid_get_cell_corner_xyz3(const ecl_grid_type * grid , int i , int j , int k, int corner_nr , double * xpos , double * ypos , double * zpos );

  void            ecl_grid_get_cell_corner_xyz1(const ecl_grid_type * grid , int global_index , int corner_nr , double * xpos , double * ypos , double * zpos );

  void            ecl_grid_get_corner_xyz(const ecl_grid_type * grid , int i , int j , int k, double * xpos , double * ypos , double * zpos );



  double          ecl_grid_get_cell_dx1A( const ecl_grid_type * grid , int active_index);

  double          ecl_grid_get_cell_dy1A( const ecl_grid_type * grid , int active_index);

  double          ecl_grid_get_cell_dz1A( const ecl_grid_type * grid , int active_index );

  double          ecl_grid_get_cell_thickness1A( const ecl_grid_type * grid , int active_index );



  double          ecl_grid_get_cell_dx1( const ecl_grid_type * grid , int global_index );

  double          ecl_grid_get_cell_dy1( const ecl_grid_type * grid , int global_index );

  double          ecl_grid_get_cell_dz1( const ecl_grid_type * grid , int global_index );

  double          ecl_grid_get_cell_thickness1( const ecl_grid_type * grid , int global_index );



  double          ecl_grid_get_cell_dx3( const ecl_grid_type * grid , int i , int j , int k);

  double          ecl_grid_get_cell_dy3( const ecl_grid_type * grid , int i , int j , int k);

  double          ecl_grid_get_cell_dz3( const ecl_grid_type * grid , int i , int j , int k);

  double          ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j , int k);



  void            ecl_grid_get_distance(const ecl_grid_type * grid , int global_index1, int global_index2 , double *dx , double *dy , double *dz);

  double          ecl_grid_get_cdepth1A(const ecl_grid_type * grid , int active_index);

  double          ecl_grid_get_cdepth1(const ecl_grid_type * grid , int global_index);

  double          ecl_grid_get_cdepth3(const ecl_grid_type * grid , int i, int j , int k);

  int             ecl_grid_get_global_index_from_xy( const ecl_grid_type * ecl_grid , int k , bool lower_layer , double x , double y);

  bool            ecl_grid_cell_contains_xyz1( const ecl_grid_type * ecl_grid , int global_index , double x , double y , double z);

  bool            ecl_grid_cell_contains_xyz3( const ecl_grid_type * ecl_grid , int i , int j , int k, double x , double y , double z );

  double          ecl_grid_get_cell_volume1( const ecl_grid_type * ecl_grid, int global_index );

  double          ecl_grid_get_cell_volume3( const ecl_grid_type * ecl_grid, int i , int j , int k);

  double          ecl_grid_get_cell_volume1A( const ecl_grid_type * ecl_grid, int active_index );

  bool            ecl_grid_cell_contains1(const ecl_grid_type * grid , int global_index , double x , double y , double z);

  bool            ecl_grid_cell_contains3(const ecl_grid_type * grid , int i , int j ,int k , double x , double y , double z);

  int             ecl_grid_get_global_index_from_xyz(ecl_grid_type * grid , double x , double y , double z , int start_index);

  bool            ecl_grid_get_ijk_from_xyz(ecl_grid_type * grid , double x , double y , double z , int start_index, int *i, int *j, int *k );

  bool            ecl_grid_get_ij_from_xy( const ecl_grid_type * grid , double x , double y , int k , int* i, int* j);

  const  char   * ecl_grid_get_name( const ecl_grid_type * );

  int             ecl_grid_get_active_index3(const ecl_grid_type * ecl_grid , int i , int j , int k);

  int             ecl_grid_get_active_index1(const ecl_grid_type * ecl_grid , int global_index);

  int             ecl_grid_get_active_fracture_index3(const ecl_grid_type * ecl_grid , int i , int j , int k);

  int             ecl_grid_get_active_fracture_index1(const ecl_grid_type * ecl_grid , int global_index);

  bool            ecl_grid_cell_active3(const ecl_grid_type * , int  , int  , int );

  bool            ecl_grid_cell_active1(const ecl_grid_type * , int);

  bool            ecl_grid_ijk_valid(const ecl_grid_type * , int  , int , int );

  int             ecl_grid_get_global_index3(const ecl_grid_type * , int  , int , int );

  int             ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index);

  int             ecl_grid_get_global_index1F(const ecl_grid_type * ecl_grid , int active_fracture_index);



  const nnc_info_type * ecl_grid_get_cell_nnc_info3( const ecl_grid_type * grid , int i , int j , int k);

  const nnc_info_type * ecl_grid_get_cell_nnc_info1( const ecl_grid_type * grid , int global_index);

  void                  ecl_grid_add_self_nnc( ecl_grid_type * grid1, int g1, int g2, int nnc_index);

  void                  ecl_grid_add_self_nnc_list( ecl_grid_type * grid, const int * g1_list , const int * g2_list , int num_nnc );



  ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw );

  ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float *  , const float *  , const int * , bool apply_mapaxes , const float * mapaxes);

  ecl_grid_type * ecl_grid_alloc_GRID_data(int num_coords , int nx, int ny , int nz , int coords_size , int ** coords , float ** corners , bool apply_mapaxes, const float * mapaxes);

  ecl_grid_type * ecl_grid_alloc(const char * );

  ecl_grid_type * ecl_grid_alloc_ext_actnum(const char * , const int * ext_actnum);

  ecl_grid_type * ecl_grid_load_case( const char * case_input );

  ecl_grid_type * ecl_grid_load_case__( const char * case_input , bool apply_mapaxes);

  ecl_grid_type * ecl_grid_alloc_rectangular( int nx , int ny , int nz , double dx , double dy , double dz , const int * actnum);

  ecl_grid_type * ecl_grid_alloc_regular( int nx, int ny , int nz , const double * ivec, const double * jvec , const double * kvec , const int * actnum);

  ecl_grid_type * ecl_grid_alloc_dxv_dyv_dzv( int nx, int ny , int nz , const double * dxv , const double * dyv , const double * dzv , const int * actnum);

  ecl_grid_type * ecl_grid_alloc_dxv_dyv_dzv_depthz( int nx, int ny , int nz , const double * dxv , const double * dyv , const double * dzv , const double * depthz , const int * actnum);

  ecl_kw_type   * ecl_grid_alloc_volume_kw( const ecl_grid_type * grid , bool active_size);

  ecl_kw_type   * ecl_grid_alloc_mapaxes_kw( const ecl_grid_type * grid );

  ecl_kw_type   * ecl_grid_alloc_coord_kw( const ecl_grid_type * grid);



  bool            ecl_grid_exists( const char * case_input );

  char          * ecl_grid_alloc_case_filename( const char * case_input );



  void            ecl_grid_free(ecl_grid_type * );

  void            ecl_grid_free__( void * arg );

  grid_dims_type  ecl_grid_iget_dims( const ecl_grid_type * grid , int grid_nr);

  void            ecl_grid_get_dims(const ecl_grid_type * , int *, int * , int * , int *);

  int             ecl_grid_get_nz( const ecl_grid_type * grid );

  int             ecl_grid_get_nx( const ecl_grid_type * grid );

  int             ecl_grid_get_ny( const ecl_grid_type * grid );

  int             ecl_grid_get_nactive( const ecl_grid_type * grid );

  int             ecl_grid_get_nactive_fracture( const ecl_grid_type * grid );

  int             ecl_grid_get_active_index(const ecl_grid_type *  , int  , int  , int );

  void            ecl_grid_summarize(const ecl_grid_type * );

  void            ecl_grid_get_ijk1(const ecl_grid_type * , int global_index , int *, int * , int *);

  void            ecl_grid_get_ijk1A(const ecl_grid_type * , int active_index, int *, int * , int *);

  void            ecl_grid_get_ijk_from_active_index(const ecl_grid_type *, int , int *, int * , int * );



  void            ecl_grid_get_xyz3(const ecl_grid_type * , int , int , int , double * , double * , double *);

  void            ecl_grid_get_xyz1(const ecl_grid_type * grid , int global_index , double *xpos , double *ypos , double *zpos);

  void            ecl_grid_get_xyz1A(const ecl_grid_type * grid , int active_index , double *xpos , double *ypos , double *zpos);



  bool            ecl_grid_get_xyz_inside1(const ecl_grid_type * grid , int global_index , double *xpos , double *ypos , double *zpos);

  bool            ecl_grid_get_xyz_inside3(const ecl_grid_type * grid , int i , int j , int k , double *xpos , double *ypos , double *zpos);



  int             ecl_grid_get_global_size( const ecl_grid_type * ecl_grid );

  bool            ecl_grid_compare(const ecl_grid_type * g1 , const ecl_grid_type * g2 , bool include_lgr, bool include_nnc , bool verbose);

  int             ecl_grid_get_active_size( const ecl_grid_type * ecl_grid );



  double          ecl_grid_get_bottom1(const ecl_grid_type * grid , int global_index);

  double          ecl_grid_get_bottom3(const ecl_grid_type * grid , int i, int j , int k);

  double          ecl_grid_get_bottom1A(const ecl_grid_type * grid , int active_index);

  double          ecl_grid_get_top1(const ecl_grid_type * grid , int global_index);

  double          ecl_grid_get_top3(const ecl_grid_type * grid , int i, int j , int k);

  double          ecl_grid_get_top1A(const ecl_grid_type * grid , int active_index);

  double          ecl_grid_get_top2(const ecl_grid_type * grid , int i, int j);

  double          ecl_grid_get_bottom2(const ecl_grid_type * grid , int i, int j);

  int             ecl_grid_locate_depth( const ecl_grid_type * grid , double depth , int i , int j );



  void            ecl_grid_alloc_blocking_variables(ecl_grid_type * , int );

  void            ecl_grid_init_blocking(ecl_grid_type * );

  double          ecl_grid_block_eval3d(ecl_grid_type * grid , int i, int j , int k ,block_function_ftype * blockf );

  int             ecl_grid_get_block_count3d(const ecl_grid_type * ecl_grid , int i , int j, int k);

  bool            ecl_grid_block_value_3d(ecl_grid_type * , double  , double  ,double , double);



  bool            ecl_grid_cell_invalid1(const ecl_grid_type * ecl_grid , int global_index);

  bool            ecl_grid_cell_invalid3(const ecl_grid_type * ecl_grid , int i , int j , int k);

  double          ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index);



  bool            ecl_grid_cell_valid1(const ecl_grid_type * ecl_grid , int global_index);

  bool            ecl_grid_cell_valid3(const ecl_grid_type * ecl_grid , int i , int j , int k);

  double          ecl_grid_cell_valid1A(const ecl_grid_type * grid , int active_index);



  void            ecl_grid_dump(const ecl_grid_type * grid , FILE * stream);

  void            ecl_grid_dump_ascii(ecl_grid_type * grid , bool active_only , FILE * stream);

  void ecl_grid_dump_ascii_cell1(ecl_grid_type * grid , int global_index , FILE * stream, const double * offset);

  void ecl_grid_dump_ascii_cell3(ecl_grid_type * grid , int i , int j , int k , FILE * stream , const double * offset);



  /* lgr related functions */

  const ecl_grid_type   * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k);

  const ecl_grid_type   * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index);

  const ecl_grid_type   * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index );

  int                     ecl_grid_get_num_lgr(const ecl_grid_type * main_grid );

  int                     ecl_grid_get_lgr_nr( const ecl_grid_type * ecl_grid );

  int                     ecl_grid_get_lgr_nr_from_name( const ecl_grid_type * grid , const char * name);

  ecl_grid_type         * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_index);

  ecl_grid_type         * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr);

  ecl_grid_type         * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name);

  bool                    ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name);

  bool                    ecl_grid_has_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr);

  const char            * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_index);

  const char            * ecl_grid_get_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr);

  stringlist_type       * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid);

  int                     ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index);

  int                     ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k);

  const ecl_grid_type   * ecl_grid_get_global_grid( const ecl_grid_type * grid );

  bool                    ecl_grid_is_lgr( const ecl_grid_type * ecl_grid );



  double                ecl_grid_get_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k);

  float                 ecl_grid_get_float_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k);

  double                ecl_grid_get_double_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k);

  int                   ecl_grid_get_int_property(const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , int i , int j , int k);



  void                    ecl_grid_grdecl_fprintf_kw( const ecl_grid_type * ecl_grid , const ecl_kw_type * ecl_kw , const char * special_header , FILE * stream , double double_default);

  bool                    ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid );



  void                    ecl_grid_fwrite_dims( const ecl_grid_type * grid , fortio_type * init_file,  ert_ecl_unit_enum output_unit);

  void                    ecl_grid_fwrite_depth( const ecl_grid_type * grid , fortio_type * init_file , ert_ecl_unit_enum ouput_unit);



  void                    ecl_grid_fwrite_EGRID(  ecl_grid_type * grid , const char * filename, bool metric_output);

  void                    ecl_grid_fwrite_EGRID2( ecl_grid_type * grid , const char * filename, ert_ecl_unit_enum output_unit);



  void                    ecl_grid_fwrite_GRID( const ecl_grid_type * grid , const char * filename);

  void                    ecl_grid_fwrite_GRID2( const ecl_grid_type * grid , const char * filename, ert_ecl_unit_enum output_unit);



  void                    ecl_grid_fprintf_grdecl(  ecl_grid_type * grid , FILE * stream );

  void                    ecl_grid_fprintf_grdecl2(  ecl_grid_type * grid , FILE * stream , ert_ecl_unit_enum output_unit);



  int              ecl_grid_zcorn_index__(int nx, int ny , int i, int j , int k , int c);

  int              ecl_grid_zcorn_index(const ecl_grid_type * grid , int i, int j , int k , int c);

  ecl_grid_type * ecl_grid_alloc_EGRID(const char * grid_file, bool apply_mapaxes );

  ecl_grid_type * ecl_grid_alloc_GRID(const char * grid_file, bool apply_mapaxes );



  float          * ecl_grid_alloc_zcorn_data( const ecl_grid_type * grid );

  ecl_kw_type    * ecl_grid_alloc_zcorn_kw( const ecl_grid_type * grid );

  int            * ecl_grid_alloc_actnum_data( const ecl_grid_type * grid );

  ecl_kw_type    * ecl_grid_alloc_actnum_kw( const ecl_grid_type * grid );

  ecl_kw_type    * ecl_grid_alloc_hostnum_kw( const ecl_grid_type * grid );

  ecl_kw_type    * ecl_grid_alloc_gridhead_kw( int nx, int ny , int nz , int grid_nr);

  ecl_grid_type  * ecl_grid_alloc_copy( const ecl_grid_type * src_grid );

  ecl_grid_type  * ecl_grid_alloc_processed_copy( const ecl_grid_type * src_grid , const double * zcorn , const int * actnum);



  void             ecl_grid_ri_export( const ecl_grid_type * ecl_grid , double * ri_points);

  void             ecl_grid_cell_ri_export( const ecl_grid_type * ecl_grid , int global_index , double * ri_points);



  bool             ecl_grid_dual_grid( const ecl_grid_type * ecl_grid );

  int              ecl_grid_get_num_nnc( const ecl_grid_type * grid );



  bool ecl_grid_cell_regular3( const ecl_grid_type * ecl_grid, int i,int j,int k);

  bool ecl_grid_cell_regular1( const ecl_grid_type * ecl_grid, int global_index);



  void ecl_grid_init_zcorn_data( const ecl_grid_type * grid , float * zcorn );

  void ecl_grid_init_zcorn_data_double( const ecl_grid_type * grid , double * zcorn );

  int ecl_grid_get_zcorn_size( const ecl_grid_type * grid );



  void ecl_grid_init_coord_data( const ecl_grid_type * grid , float * coord );

  void ecl_grid_init_coord_data_double( const ecl_grid_type * grid , double * coord );

  int  ecl_grid_get_coord_size( const ecl_grid_type * ecl_grid);



  void ecl_grid_init_actnum_data( const ecl_grid_type * grid , int * actnum );

  bool ecl_grid_use_mapaxes( const ecl_grid_type * grid );

  void ecl_grid_init_mapaxes_data_double( const ecl_grid_type * grid , double * mapaxes);

  void ecl_grid_reset_actnum( ecl_grid_type * grid , const int * actnum );

  void ecl_grid_compressed_kw_copy( const ecl_grid_type * grid , ecl_kw_type * target_kw , const ecl_kw_type * src_kw);

  void ecl_grid_global_kw_copy( const ecl_grid_type * grid , ecl_kw_type * target_kw , const ecl_kw_type * src_kw);

  void ecl_grid_export_cell_corners1(const ecl_grid_type * grid, int global_index, double *x, double *y, double *z);



  ert_ecl_unit_enum ecl_grid_get_unit_system(const ecl_grid_type * grid);

  void ecl_grid_export_index(const ecl_grid_type * grid, int * global_index, int * index_data , bool active_only);

  void ecl_grid_export_data_as_int( int index_size, const int * global_index, const ecl_kw_type * kw, int * output);

  void ecl_grid_export_data_as_double( int index_size, const int * data_index, const ecl_kw_type * kw, double * output);

  void ecl_grid_export_volume( const ecl_grid_type * grid, int index_size, const int * global_index, double * output );

  void ecl_grid_export_position( const ecl_grid_type * grid, int index_size, const int * global_index, double * output);

  void export_corners( const ecl_grid_type * grid, int index_size, const int * global_index, double * output);

下面一个例子是通过读取文本格式的GRDECL 文件构建ecl_grid_type 对象。

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

#include <ert/util/util.h>
#include <ert/ecl/ecl_kw.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_kw_magic.h>


int main(int argc, char** argv) {
	const char* fileName = "E:\\Case3D_0.GRDECL";
	FILE* stream = util_fopen(fileName, "r");
	ecl_kw_type* gridhead_kw = ecl_kw_fscanf_alloc_grdecl_dynamic__(stream, SPECGRID_KW, false, ECL_INT);
	std::cout << "read dimension done " << std::endl;
	fclose(stream);

	const char* fileName1 = "E:\\Case3d_0_ZCORN.GRDECL";
	FILE* stream1 = util_fopen(fileName1, "r");
	ecl_kw_type* zcorn_kw = ecl_kw_fscanf_alloc_grdecl_dynamic(stream1, ZCORN_KW, ECL_FLOAT);
	std::cout << "read zcorn done" << std::endl;
	fclose(stream1);

	const char* fileName2 = "E:\\Case3D_0_COORD.GRDECL";
	FILE* stream2 = util_fopen(fileName2, "r");
	ecl_kw_type* coord_kw = ecl_kw_fscanf_alloc_grdecl_dynamic(stream2, COORD_KW, ECL_FLOAT);
	std::cout << "read coord done" << std::endl;
	fclose(stream2);

	const char* fileName3 = "E:\\Case3D_0_ACTNUM.GRDECL";
	FILE* stream3 = util_fopen(fileName3, "r");
	ecl_kw_type* actnum_kw = ecl_kw_fscanf_alloc_grdecl_dynamic(stream3, ACTNUM_KW, ECL_INT);
	std::cout << "read actnum done" << std::endl;
	fclose(stream3);

	{
		int nx = ecl_kw_iget_int(gridhead_kw, SPECGRID_NX_INDEX);
		int ny = ecl_kw_iget_int(gridhead_kw, SPECGRID_NY_INDEX);
		int nz = ecl_kw_iget_int(gridhead_kw, SPECGRID_NZ_INDEX);
		ecl_grid_type* ecl_grid = ecl_grid_alloc_GRDECL_kw(nx, ny, nz, zcorn_kw, coord_kw, actnum_kw, NULL);
		/* .... */
		ecl_grid_summarize(ecl_grid);

		ecl_grid_free(ecl_grid);
	}
	ecl_kw_free(gridhead_kw);
	ecl_kw_free(zcorn_kw);
	ecl_kw_free(actnum_kw);
	ecl_kw_free(coord_kw);
	
	return 0;
}

运行结果如下

posted @ 2022-08-21 10:13  Oliver2022  阅读(286)  评论(0编辑  收藏  举报