Loop3D/LoopStructural

Could LoopStructural build corner-point grid model?

Closed this issue · 5 comments

The corner-point gridding (CPG) format is the ECLIPSE reservoir modeling input deck file, so could LoopStructural write out CPG file in the future? Or where can the user write their own Python code to write out CPG format file besides vtk format and so on?
Thanks!
Li Jian
China University of Geosciences

Hi

There are some examples of writing out voxel formats in:

https://github.com/Loop3D/map2loop2-notebooks/blob/master/Utility%202%20-%20Exporters.ipynb

create_geoh5_block_model_data(),
create_omf_block_model_data() and
write_vol_gocad()

that can be modified to write out to CPG format.

If you write such a convertor please send us the code!

best wishes

Mark

lj-cug commented

I initially write a corner-point grid exporter imitating the code of Exporter.py from LoopStructural. But I get confused among the three kinds of style exported for omf, GOCAD and Geoh5 format. Could you please help me the check the following code?

from pathlib import Path
import numpy as np

voxel_size=500
sizex=int((maxx-minx)/voxel_size)
sizey=int((maxy-miny)/voxel_size)
sizez=int((model_top-model_base)/voxel_size)
nsteps=[sizex,sizey,sizez]

write out corner-point grid file after voxelization

def write_cpg(model,voxel_size,minx,miny,maxx,maxy,model_base,model_top,output_dir,nsteps):

voxels=model.evaluate_model(model.regular_grid(nsteps=(nsteps[0],nsteps[1],nsteps[2]),shuffle=False),scale=False)
voxels=voxels.astype(float)

# number of nodes at xyz directions
nodal_x = int((maxx-minx+1)/voxel_size)
nodal_y = int((maxy-miny+1)/voxel_size)
nodal_z = int((model_top-model_base+1)/voxel_size)
print(nodal_x,nodal_y,nodal_z)
print(minx,maxx,miny,maxy,model_base,model_top,voxel_size)

# Write out corner-point grid file
cpg_filepath = output_dir + "/loop_block_model.grdecl"

# Are they the pillar coordinates to COORD ?
coord=voxels.reshape((nodal_z,nodal_x,nodal_y)).transpose((0,1,2)).flatten()
export_coord = np.array(coord, dtype='float')

# Are they the corner-point Z coordinates from voxels to ZCORN ?
zcorn=voxels.reshape((nodal_z-1,nodal_x-1,nodal_y-1)).transpose((0,1,2)).flatten()
export_zcorn = np.array(zcorn, dtype='float')

corner-point grid

try:
    with open(cpg_filepath, "w+") as fp:
        fp.write('-- The following grdecl file was written from LoopStructural \n\n')
		fp.write('SPECGRID \n')
		fp.write(str(nodal_x-1)+ ' ',str(nodal_y-1)+ ' ',str(nodal_z-1)+ ' ',str(1)+ ' ','F')
		fp.write('\n')
		fp.write('/')
		fp.write('\n')
		
		fp.write('COORD \n')
		# How can I write out xyz coordinates of pillars ?
		export_coord.tofile(fp)
		
		fp.write('/')
		fp.write('\n')	
		
		fp.write('ZCORN \n')
		# How can I write out Z coordinate of 8 corners ?
		export_zcorn.tofile(fp)
		
		fp.write('/')
		fp.write('\n')
		
		# optionally write out ACTNUM
		fp.write('ACTNUM \n')
		for x in range(1, nodal_x*nodal_y*nodal_z):
			fp.write(str(1) + ' ')
		fp.write('/')
		fp.close()
		
except IOError as exc:
    print("Cannot export volume to Corner-point grid file")
    return False
return True	

output_dir= '' # output directory to savecorner-point grid
write_cpg(model,voxel_size,minx,miny,maxx,maxy,model_base,model_top,output_dir,nsteps)

Hi, what are the requirements of the file you are writing out? If you can explain this I can help to debug what you have tried to do. This issue seems more like a problem with writing a CPG file than using LoopStructural.

lj-cug commented

Yes, I have installed map2loop and LoopStructural tools on my computer. Because the reservoir simulation such as Slurmgerg's ECLIPSE and OPM all use industrial standard corner-point grid (CPG), not unstructured mesh, the geological model output from LoopStructural should be converted into CPG format. The facies modeling and property modeling results can be interpolated into the CPG to be as the pre-processing for the later reservoir simulation. The automaic workflow will speedup the modeling efficiency in many area including reservoir simulation, seismic wave modeling etc.
Now I get confused about the array content including the nodal coordinates and voxel cell coordinates in "Exporter" script supplied in "Loop3D-map2loop2-notebooks" case. So coupld please help to accomplish the converter code for CPG? It will save much time for me, that's great help.
Best Regards,
Li Jian