We construct the Cartesian grid, set the permeability to 100 mD, and use the default single-phase fluid with density 1000 kg/m^3 and viscosity 1 cP.
nx = 20; ny = 20; nz = 8;
Nx = 5; Ny = 5; Nz = 2;
verbose = false;
G = cartGrid([nx ny nz]);
G = computeGeometry(G);
rock.perm = repmat(100*milli*darcy, [G.cells.num, 1]);
fluid = initSingleFluid('mu' , 1*centi*poise , ...'rho', 1000*kilogram/meter^3);
Set two wells, one vertical and one horizontal. Note that a vertical well can be constructed by both addWell and verticalWell, so the appropriate choice depends on whether you know the well cells or the I, J, K position of the well.
W = verticalWell([], G, rock, nx, ny, 1:nz, ...'Type', 'rate', 'Val', 1*meter^3/day, ...'Radius', .1, 'Name', 'I', 'Comp_i', [1, 0]);
W = addWell(W, G, rock, 1:nx, 'Type','bhp', ...'Val', 1*barsa, 'Radius', .1, 'Dir', 'x', ...'Name', 'P', 'Comp_i', [0, 1]);
Set up solution structures
Here we need four solution structures, two for each simulator to hold the solutions on the grid and in the wells, respectively.
xRef = initState(G, W, 0, [0, 1]);
xMs = xRef;
Partition the grid
We partition the fine grid into a regular Nx-by-Ny-by-Nz coarse grid in index space so that each coarse block holds (nx/Nx)-by-(ny/Ny)-by-(nz/Nz) fine cells. The resulting vector p has one entry per fine-grid cell giving the index of the corresponding coarse block. After the grid is partitioned in index space, we postprocess it to make sure that all blocks consist of a connected set of fine cells. This step is superfluous for Cartesian grids, but is required for grids that are only logically Cartesian (e.g., corner-point and other mapped grids that may contain inactive or degenerate cells).
p = partitionUI(G, [Nx, Ny, Nz]);
p = processPartition(G, p, 'Verbose', verbose);
% Generate the coarse-grid structure
CG = generateCoarseGrid(G, p, 'Verbose', verbose);