Add convenience: Interpret ACTNUM==NULL as "all cells active".
Signed-off-by: Bård Skaflestad <Bard.Skaflestad@sintef.no>
This commit is contained in:
parent
ea6c01dd95
commit
e5ecded0a8
57
mxgrdecl.c
57
mxgrdecl.c
@ -32,37 +32,33 @@
|
||||
along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mex.h>
|
||||
|
||||
|
||||
#include "grdecl.h"
|
||||
|
||||
|
||||
void mx_init_grdecl(struct grdecl *g, const mxArray *s);
|
||||
#include "mxgrdecl.h"
|
||||
|
||||
/* Get COORD, ZCORN, ACTNUM and DIMS from mxArray. */
|
||||
/*-------------------------------------------------------*/
|
||||
void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
||||
{
|
||||
int i,n;
|
||||
mxArray *field;
|
||||
int numel;
|
||||
double *tmp;
|
||||
size_t numel;
|
||||
mxArray *cartdims=NULL, *actnum=NULL, *coord=NULL, *zcorn=NULL;
|
||||
|
||||
if (!mxIsStruct(s)
|
||||
|| !(cartdims = mxGetField(s, 0, "cartDims"))
|
||||
|| !(actnum = mxGetField(s, 0, "ACTNUM"))
|
||||
|| !(coord = mxGetField(s, 0, "COORD"))
|
||||
|| !(zcorn = mxGetField(s, 0, "ZCORN"))
|
||||
)
|
||||
{
|
||||
char str[]="Input must be a single Matlab struct with fields\n"
|
||||
"cartDims, ACTNUM, COORD and ZCORN\n";
|
||||
char str[]="Input must be a single MATLAB struct with fields\n"
|
||||
"'cartDims', 'COORD' and 'ZCORN'. ACTNUM may be included.\n";
|
||||
mexErrMsgTxt(str);
|
||||
}
|
||||
|
||||
@ -72,35 +68,44 @@ void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
||||
mexErrMsgTxt("cartDims field must be 3 numbers");
|
||||
}
|
||||
|
||||
tmp = mxGetPr(cartdims);
|
||||
n = 1;
|
||||
for (i=0; i<3; ++i){
|
||||
g->dims[i] = tmp[i];
|
||||
n *= tmp[i];
|
||||
if (mxIsDouble(cartdims)) {
|
||||
double *tmp = mxGetPr(cartdims);
|
||||
for (i = 0; i < 3; ++i) {
|
||||
g->dims[i] = (int) tmp[i];
|
||||
}
|
||||
}
|
||||
else if (mxIsInt32(cartdims)) {
|
||||
int *tmp = mxGetData(cartdims);
|
||||
memcpy(g->dims, tmp, 3 * sizeof *g->dims);
|
||||
}
|
||||
|
||||
n = g->dims[0];
|
||||
for (i = 1; i < 3; i++) { n *= g->dims[ i ]; }
|
||||
|
||||
|
||||
if ((actnum = mxGetField(s, 0, "ACTNUM")) != NULL) {
|
||||
numel = mxGetNumberOfElements(actnum);
|
||||
if (mxGetClassID(actnum) != mxINT32_CLASS ||
|
||||
numel != g->dims[0]*g->dims[1]*g->dims[2] ){
|
||||
if ((! mxIsInt32(actnum)) || (numel != (size_t)(n))) {
|
||||
mexErrMsgTxt("ACTNUM field must be nx*ny*nz numbers int32");
|
||||
}
|
||||
g->actnum = mxGetData(actnum);
|
||||
}
|
||||
else {
|
||||
g->actnum = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
field = mxGetField(s, 0, "COORD");
|
||||
numel = mxGetNumberOfElements(coord);
|
||||
if (mxGetClassID(coord) != mxDOUBLE_CLASS ||
|
||||
numel != 6*(g->dims[0]+1)*(g->dims[1]+1)){
|
||||
if ((! mxIsDouble(coord)) ||
|
||||
numel != (size_t)(6*(g->dims[0]+1)*(g->dims[1]+1))) {
|
||||
mexErrMsgTxt("COORD field must have 6*(nx+1)*(ny+1) doubles.");
|
||||
}
|
||||
g->coord = mxGetPr(coord);
|
||||
|
||||
|
||||
numel = mxGetNumberOfElements(zcorn);
|
||||
if (mxGetClassID(zcorn) != mxDOUBLE_CLASS ||
|
||||
numel != 8*g->dims[0]*g->dims[1]*g->dims[2]){
|
||||
if ((! mxIsDouble(zcorn)) ||
|
||||
numel != (size_t)(8*g->dims[0]*g->dims[1]*g->dims[2])) {
|
||||
mexErrMsgTxt("ZCORN field must have 8*nx*ny*nz doubles.");
|
||||
}
|
||||
g->zcorn = mxGetPr(zcorn);
|
||||
|
31
preprocess.c
31
preprocess.c
@ -451,20 +451,30 @@ copy_and_permute_actnum(int nx, int ny, int nz, const int *in, int *out)
|
||||
{
|
||||
int i,j,k;
|
||||
int *ptr = out;
|
||||
|
||||
/* Permute actnum such that values of each vertical stack of cells
|
||||
* are adjacent in memory, i.e.,
|
||||
|
||||
out = [in(0,0,:), in(1,0,:),..., in(nx-1, ny-1,:)]
|
||||
|
||||
in Matlab pseudo-code.
|
||||
*
|
||||
* out = [in(0,0,:), in(1,0,:),..., in(nx-1, ny-1,:)]
|
||||
*
|
||||
* in MATLAB pseudo-code.
|
||||
*/
|
||||
for (j=0; j<ny; ++j){
|
||||
for (i=0; i<nx; ++i){
|
||||
for (k=0; k<nz; ++k){
|
||||
*ptr++ = in[i+nx*(j+ny*k)];
|
||||
if (in != NULL) {
|
||||
for (j = 0; j < ny; ++j) {
|
||||
for (i = 0; i < nx; ++i) {
|
||||
for (k = 0; k < nz; ++k) {
|
||||
*ptr++ = in[i + nx*(j + ny*k)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* No explicit ACTNUM. Assume all cells active. */
|
||||
for (i = 0; i < nx * ny * nz; i++) {
|
||||
out[ i ] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -527,7 +537,10 @@ get_zcorn_sign(int nx, int ny, int nz, const int *actnum,
|
||||
c1 = i/2 + nx*(j/2 + ny*k/2);
|
||||
c2 = i/2 + nx*(j/2 + ny*(k+1)/2);
|
||||
|
||||
if (actnum[c1] && actnum[c2] && (z2 < z1)){
|
||||
if (((actnum == NULL) ||
|
||||
(actnum[c1] && actnum[c2]))
|
||||
&& (z2 < z1)) {
|
||||
|
||||
fprintf(stderr, "\nZCORN should be strictly "
|
||||
"nondecreasing along pillars!\n");
|
||||
*error = 1;
|
||||
|
@ -391,7 +391,9 @@ args_ok(int nlhs, int nrhs, const mxArray *prhs[])
|
||||
ok = ok && (mxGetFieldNumber(prhs[0], "cartDims") >= 0);
|
||||
ok = ok && (mxGetFieldNumber(prhs[0], "COORD" ) >= 0);
|
||||
ok = ok && (mxGetFieldNumber(prhs[0], "ZCORN" ) >= 0);
|
||||
#if 0
|
||||
ok = ok && (mxGetFieldNumber(prhs[0], "ACTNUM" ) >= 0);
|
||||
#endif
|
||||
|
||||
if (ok && (nrhs == 2)) {
|
||||
ok = mxIsDouble(prhs[1]) && (mxGetNumberOfElements(prhs[1]) == 1);
|
||||
@ -454,7 +456,7 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||
"G = %s(grdecl)\t%%or\n\t"
|
||||
"G = %s(grdecl, tolerance)\n"
|
||||
"The 'grdecl' must be a valid structure with fields\n"
|
||||
"\t'cartDims', 'COORD', 'ZCORN', and 'ACTNUM'",
|
||||
"\t'cartDims', 'COORD', 'ZCORN'",
|
||||
mexFunctionName(), mexFunctionName());
|
||||
mexErrMsgTxt(errmsg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user