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/>.
|
along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <mex.h>
|
#include <mex.h>
|
||||||
|
|
||||||
|
|
||||||
#include "grdecl.h"
|
#include "grdecl.h"
|
||||||
|
#include "mxgrdecl.h"
|
||||||
|
|
||||||
void mx_init_grdecl(struct grdecl *g, const mxArray *s);
|
|
||||||
|
|
||||||
/* Get COORD, ZCORN, ACTNUM and DIMS from mxArray. */
|
/* Get COORD, ZCORN, ACTNUM and DIMS from mxArray. */
|
||||||
/*-------------------------------------------------------*/
|
/*-------------------------------------------------------*/
|
||||||
void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
||||||
{
|
{
|
||||||
int i,n;
|
int i,n;
|
||||||
mxArray *field;
|
size_t numel;
|
||||||
int numel;
|
|
||||||
double *tmp;
|
|
||||||
mxArray *cartdims=NULL, *actnum=NULL, *coord=NULL, *zcorn=NULL;
|
mxArray *cartdims=NULL, *actnum=NULL, *coord=NULL, *zcorn=NULL;
|
||||||
|
|
||||||
if (!mxIsStruct(s)
|
if (!mxIsStruct(s)
|
||||||
|| !(cartdims = mxGetField(s, 0, "cartDims"))
|
|| !(cartdims = mxGetField(s, 0, "cartDims"))
|
||||||
|| !(actnum = mxGetField(s, 0, "ACTNUM"))
|
|
||||||
|| !(coord = mxGetField(s, 0, "COORD"))
|
|| !(coord = mxGetField(s, 0, "COORD"))
|
||||||
|| !(zcorn = mxGetField(s, 0, "ZCORN"))
|
|| !(zcorn = mxGetField(s, 0, "ZCORN"))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char str[]="Input must be a single Matlab struct with fields\n"
|
char str[]="Input must be a single MATLAB struct with fields\n"
|
||||||
"cartDims, ACTNUM, COORD and ZCORN\n";
|
"'cartDims', 'COORD' and 'ZCORN'. ACTNUM may be included.\n";
|
||||||
mexErrMsgTxt(str);
|
mexErrMsgTxt(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,35 +68,44 @@ void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
|||||||
mexErrMsgTxt("cartDims field must be 3 numbers");
|
mexErrMsgTxt("cartDims field must be 3 numbers");
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = mxGetPr(cartdims);
|
if (mxIsDouble(cartdims)) {
|
||||||
n = 1;
|
double *tmp = mxGetPr(cartdims);
|
||||||
for (i=0; i<3; ++i){
|
for (i = 0; i < 3; ++i) {
|
||||||
g->dims[i] = tmp[i];
|
g->dims[i] = (int) tmp[i];
|
||||||
n *= 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);
|
numel = mxGetNumberOfElements(actnum);
|
||||||
if (mxGetClassID(actnum) != mxINT32_CLASS ||
|
if ((! mxIsInt32(actnum)) || (numel != (size_t)(n))) {
|
||||||
numel != g->dims[0]*g->dims[1]*g->dims[2] ){
|
|
||||||
mexErrMsgTxt("ACTNUM field must be nx*ny*nz numbers int32");
|
mexErrMsgTxt("ACTNUM field must be nx*ny*nz numbers int32");
|
||||||
}
|
}
|
||||||
g->actnum = mxGetData(actnum);
|
g->actnum = mxGetData(actnum);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g->actnum = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
field = mxGetField(s, 0, "COORD");
|
|
||||||
numel = mxGetNumberOfElements(coord);
|
numel = mxGetNumberOfElements(coord);
|
||||||
if (mxGetClassID(coord) != mxDOUBLE_CLASS ||
|
if ((! mxIsDouble(coord)) ||
|
||||||
numel != 6*(g->dims[0]+1)*(g->dims[1]+1)){
|
numel != (size_t)(6*(g->dims[0]+1)*(g->dims[1]+1))) {
|
||||||
mexErrMsgTxt("COORD field must have 6*(nx+1)*(ny+1) doubles.");
|
mexErrMsgTxt("COORD field must have 6*(nx+1)*(ny+1) doubles.");
|
||||||
}
|
}
|
||||||
g->coord = mxGetPr(coord);
|
g->coord = mxGetPr(coord);
|
||||||
|
|
||||||
|
|
||||||
numel = mxGetNumberOfElements(zcorn);
|
numel = mxGetNumberOfElements(zcorn);
|
||||||
if (mxGetClassID(zcorn) != mxDOUBLE_CLASS ||
|
if ((! mxIsDouble(zcorn)) ||
|
||||||
numel != 8*g->dims[0]*g->dims[1]*g->dims[2]){
|
numel != (size_t)(8*g->dims[0]*g->dims[1]*g->dims[2])) {
|
||||||
mexErrMsgTxt("ZCORN field must have 8*nx*ny*nz doubles.");
|
mexErrMsgTxt("ZCORN field must have 8*nx*ny*nz doubles.");
|
||||||
}
|
}
|
||||||
g->zcorn = mxGetPr(zcorn);
|
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 i,j,k;
|
||||||
int *ptr = out;
|
int *ptr = out;
|
||||||
|
|
||||||
/* Permute actnum such that values of each vertical stack of cells
|
/* Permute actnum such that values of each vertical stack of cells
|
||||||
* are adjacent in memory, i.e.,
|
* are adjacent in memory, i.e.,
|
||||||
|
*
|
||||||
out = [in(0,0,:), in(1,0,:),..., in(nx-1, ny-1,:)]
|
* out = [in(0,0,:), in(1,0,:),..., in(nx-1, ny-1,:)]
|
||||||
|
*
|
||||||
in Matlab pseudo-code.
|
* in MATLAB pseudo-code.
|
||||||
*/
|
*/
|
||||||
for (j=0; j<ny; ++j){
|
if (in != NULL) {
|
||||||
for (i=0; i<nx; ++i){
|
for (j = 0; j < ny; ++j) {
|
||||||
for (k=0; k<nz; ++k){
|
for (i = 0; i < nx; ++i) {
|
||||||
*ptr++ = in[i+nx*(j+ny*k)];
|
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;
|
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);
|
c1 = i/2 + nx*(j/2 + ny*k/2);
|
||||||
c2 = i/2 + nx*(j/2 + ny*(k+1)/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 "
|
fprintf(stderr, "\nZCORN should be strictly "
|
||||||
"nondecreasing along pillars!\n");
|
"nondecreasing along pillars!\n");
|
||||||
*error = 1;
|
*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], "cartDims") >= 0);
|
||||||
ok = ok && (mxGetFieldNumber(prhs[0], "COORD" ) >= 0);
|
ok = ok && (mxGetFieldNumber(prhs[0], "COORD" ) >= 0);
|
||||||
ok = ok && (mxGetFieldNumber(prhs[0], "ZCORN" ) >= 0);
|
ok = ok && (mxGetFieldNumber(prhs[0], "ZCORN" ) >= 0);
|
||||||
|
#if 0
|
||||||
ok = ok && (mxGetFieldNumber(prhs[0], "ACTNUM" ) >= 0);
|
ok = ok && (mxGetFieldNumber(prhs[0], "ACTNUM" ) >= 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ok && (nrhs == 2)) {
|
if (ok && (nrhs == 2)) {
|
||||||
ok = mxIsDouble(prhs[1]) && (mxGetNumberOfElements(prhs[1]) == 1);
|
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)\t%%or\n\t"
|
||||||
"G = %s(grdecl, tolerance)\n"
|
"G = %s(grdecl, tolerance)\n"
|
||||||
"The 'grdecl' must be a valid structure with fields\n"
|
"The 'grdecl' must be a valid structure with fields\n"
|
||||||
"\t'cartDims', 'COORD', 'ZCORN', and 'ACTNUM'",
|
"\t'cartDims', 'COORD', 'ZCORN'",
|
||||||
mexFunctionName(), mexFunctionName());
|
mexFunctionName(), mexFunctionName());
|
||||||
mexErrMsgTxt(errmsg);
|
mexErrMsgTxt(errmsg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user