2012-01-27 12:27:02 +00:00
|
|
|
/*=========================================================================
|
2009-06-19 07:54:00 +00:00
|
|
|
//
|
|
|
|
|
// File: mxgrdecl.c
|
|
|
|
|
//
|
|
|
|
|
// Created: Fri Jun 19 08:48:21 2009
|
|
|
|
|
//
|
|
|
|
|
// Author: Jostein R. Natvig <Jostein.R.Natvig@sintef.no>
|
|
|
|
|
//
|
|
|
|
|
// $Date$
|
|
|
|
|
//
|
|
|
|
|
// $Revision$
|
|
|
|
|
//
|
2012-01-27 12:27:02 +00:00
|
|
|
//=======================================================================*/
|
2009-06-19 07:54:00 +00:00
|
|
|
|
|
|
|
|
/*
|
2012-01-31 08:48:40 +00:00
|
|
|
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
Copyright 2009, 2010 Statoil ASA.
|
2009-06-19 07:54:00 +00:00
|
|
|
|
2012-01-31 08:48:40 +00:00
|
|
|
This file is part of The Open Reservoir Simulator Project (OpenRS).
|
2009-06-19 07:54:00 +00:00
|
|
|
|
2012-01-31 08:48:40 +00:00
|
|
|
OpenRS is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
2009-06-19 07:54:00 +00:00
|
|
|
|
2012-01-31 08:48:40 +00:00
|
|
|
OpenRS is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2009-06-19 07:54:00 +00:00
|
|
|
|
2012-01-31 08:48:40 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OpenRS. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-19 07:54:00 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-05-15 20:24:02 +00:00
|
|
|
#include <assert.h>
|
2009-06-11 07:33:50 +00:00
|
|
|
#include <math.h>
|
2012-05-15 20:24:02 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdlib.h>
|
2009-06-11 07:33:50 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-05-15 20:24:02 +00:00
|
|
|
#include <mex.h>
|
2009-06-11 07:33:50 +00:00
|
|
|
|
|
|
|
|
#include "grdecl.h"
|
2012-05-15 20:24:02 +00:00
|
|
|
#include "mxgrdecl.h"
|
2009-06-11 07:33:50 +00:00
|
|
|
|
|
|
|
|
/* Get COORD, ZCORN, ACTNUM and DIMS from mxArray. */
|
|
|
|
|
/*-------------------------------------------------------*/
|
2009-06-18 16:10:37 +00:00
|
|
|
void mx_init_grdecl(struct grdecl *g, const mxArray *s)
|
2009-06-11 07:33:50 +00:00
|
|
|
{
|
2012-01-31 08:48:40 +00:00
|
|
|
int i,n;
|
2012-05-15 20:24:02 +00:00
|
|
|
size_t numel;
|
2012-01-31 08:48:40 +00:00
|
|
|
mxArray *cartdims=NULL, *actnum=NULL, *coord=NULL, *zcorn=NULL;
|
|
|
|
|
|
|
|
|
|
if (!mxIsStruct(s)
|
|
|
|
|
|| !(cartdims = mxGetField(s, 0, "cartDims"))
|
|
|
|
|
|| !(coord = mxGetField(s, 0, "COORD"))
|
2012-05-15 20:24:02 +00:00
|
|
|
|| !(zcorn = mxGetField(s, 0, "ZCORN"))
|
2012-01-31 08:48:40 +00:00
|
|
|
)
|
|
|
|
|
{
|
2012-05-15 20:24:02 +00:00
|
|
|
char str[]="Input must be a single MATLAB struct with fields\n"
|
|
|
|
|
"'cartDims', 'COORD' and 'ZCORN'. ACTNUM may be included.\n";
|
2012-01-31 08:48:40 +00:00
|
|
|
mexErrMsgTxt(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
numel = mxGetNumberOfElements(cartdims);
|
|
|
|
|
if (!mxIsNumeric(cartdims) || numel != 3){
|
|
|
|
|
mexErrMsgTxt("cartDims field must be 3 numbers");
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-15 20:24:02 +00:00
|
|
|
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);
|
2012-01-31 08:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-15 20:24:02 +00:00
|
|
|
n = g->dims[0];
|
|
|
|
|
for (i = 1; i < 3; i++) { n *= g->dims[ i ]; }
|
2012-01-31 08:48:40 +00:00
|
|
|
|
|
|
|
|
|
2012-05-15 20:24:02 +00:00
|
|
|
if ((actnum = mxGetField(s, 0, "ACTNUM")) != NULL) {
|
|
|
|
|
numel = mxGetNumberOfElements(actnum);
|
|
|
|
|
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;
|
|
|
|
|
}
|
2012-01-31 08:48:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
numel = mxGetNumberOfElements(coord);
|
2012-05-15 20:24:02 +00:00
|
|
|
if ((! mxIsDouble(coord)) ||
|
|
|
|
|
numel != (size_t)(6*(g->dims[0]+1)*(g->dims[1]+1))) {
|
2012-01-31 08:48:40 +00:00
|
|
|
mexErrMsgTxt("COORD field must have 6*(nx+1)*(ny+1) doubles.");
|
|
|
|
|
}
|
|
|
|
|
g->coord = mxGetPr(coord);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
numel = mxGetNumberOfElements(zcorn);
|
2012-05-15 20:24:02 +00:00
|
|
|
if ((! mxIsDouble(zcorn)) ||
|
|
|
|
|
numel != (size_t)(8*g->dims[0]*g->dims[1]*g->dims[2])) {
|
2012-01-31 08:48:40 +00:00
|
|
|
mexErrMsgTxt("ZCORN field must have 8*nx*ny*nz doubles.");
|
|
|
|
|
}
|
|
|
|
|
g->zcorn = mxGetPr(zcorn);
|
2009-06-11 07:33:50 +00:00
|
|
|
}
|
2012-01-31 08:48:40 +00:00
|
|
|
|
|
|
|
|
/* Local Variables: */
|
|
|
|
|
/* c-basic-offset:4 */
|
|
|
|
|
/* End: */
|