CS - MRST
Vim
How-to snippets for building the EGG model and detecting cell boundaries in MRST.
Build the EGG model with deckformat
How to build the EGG model with GAWPS by using deckformat:
mrstModule add deckformat
f = fullfile('..', 'GAWPS', 'Models', 'EGG', 'Egg_Model_ECL.DATA');
% Reading the input deck
deck = readEclipseDeck(f);
deck = convertDeckUnits(deck); % Convert to MRST units (SI)
% Reading grid structure
G = initEclipseGrid(deck);
G = computeGeometry(G);
% Reading rock properties
rock = initEclipseRock(deck);
rock = compressRock(rock, G.cells.indexMap);Detect cell boundaries in arbitrary grids
How to detect cell boundaries in arbitrary grids:
bndyfac = any(G.faces.neighbors == 0, 2);
bndycells = find(accumarray(sum(G.faces.neighbors(bndyfac,:), 2), 1) > 0);
% check that you have selected all the boundary faces
figure, plotFaces(G,bndyfac);Verification
Verification steps:
% check if all the boundary cells were selected
figure
plotGrid(G,'Facecolor','none');
bndyfac = any(G.faces.neighbors == 0, 2);
bndycells = accumarray(sum(G.faces.neighbors(bndyfac,:), 2), 1) > 0;
plotGrid(G,~bndycells,'FaceColor','b');Understanding accumarray
How to understand accumarray above:
G.faces.neighbors(bndyfac,:)extracts ann x 2array containing the indices of cells on opposite sides of the faces given bybndyfac. Each row in this array will have two entries, but ifbndyfaconly contains boundary faces, one of the entries will always be zero. We can then extract the nonzero entry in each row by summing in the second dimension.- The
sum(G.faces....)operation has given us an array with indices of cells that lie next to the boundary. This array may contain repeated entries, since boundary cells may have more than one boundary face. Theaccumarray()counts the number of occurrences for each cell index (from 1 to the maximum returned bysum()). We can then usefind(accumarray(..) > 0)to extract the cell indices that appear at least once in the list.