From bfdd9917a8c3ffbd31ffcebbe82e05957dfa3451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 28 Aug 2012 16:03:26 +0200 Subject: [PATCH 01/13] Add a utility for creating a grid from textual representation. There is little to no error checking, and the importer assumes that the grid is serialised more or less directly from the grid structure. Intended use: Testing on non-uniform grids created in MRST. --- opm/core/grid.c | 397 ++++++++++++++++++++++++++++++++++++++++++++++++ opm/core/grid.h | 11 ++ 2 files changed, 408 insertions(+) diff --git a/opm/core/grid.c b/opm/core/grid.c index 9fa4cd67..bb7de1bc 100644 --- a/opm/core/grid.c +++ b/opm/core/grid.c @@ -18,7 +18,12 @@ */ #include + +#include +#include +#include #include +#include void @@ -135,3 +140,395 @@ allocate_grid(size_t ndims , return G; } + + +#define GRID_NDIMS 0 +#define GRID_NCELLS 1 +#define GRID_NFACES 2 +#define GRID_NNODES 3 +#define GRID_NFACENODES 4 +#define GRID_NCELLFACES 5 + + +static void +input_error(FILE *fp, const char * const err) +{ + int save_errno = errno; + + if (ferror(fp)) { + fprintf(stderr, "%s: %s\n", err, strerror(save_errno)); + clearerr(fp); + } + else if (feof(fp)) { + fprintf(stderr, "%s: End-of-file\n", err); + } + + errno = save_errno; +} + + +static struct UnstructuredGrid * +allocate_grid_from_file(FILE *fp, int *has_tag, int *has_indexmap) +{ + struct UnstructuredGrid *G; + + int save_errno; + unsigned long tmp; + size_t dimens[6], i; + + save_errno = errno; + + i = 0; + while ((i < 6) && (fscanf(fp, " %lu", &tmp) == 1)) { + dimens[i] = tmp; + + i += 1; + } + + if (i == 6) { + if (fscanf(fp, "%d %d", has_tag, has_indexmap) == 2) { + G = allocate_grid(dimens[GRID_NDIMS] , + dimens[GRID_NCELLS] , + dimens[GRID_NFACES] , + dimens[GRID_NFACENODES], + dimens[GRID_NCELLFACES], + dimens[GRID_NNODES] ); + + if (G != NULL) { + if (! *has_tag) { + free(G->cell_facetag); + G->cell_facetag = NULL; + } + + if (*has_indexmap) { + G->global_cell = + malloc(dimens[GRID_NCELLS] * sizeof *G->global_cell); + + /* Allocation failure checked elsewhere. */ + } + + G->number_of_cells = (int) dimens[GRID_NCELLS]; + G->number_of_faces = (int) dimens[GRID_NFACES]; + G->number_of_nodes = (int) dimens[GRID_NNODES]; + G->dimensions = (int) dimens[GRID_NDIMS]; + + i = 0; + while ((i < dimens[GRID_NDIMS]) && + (fscanf(fp, "%d", & G->cartdims[ i ]) == 1)) { + i += 1; + } + + if (i < dimens[GRID_NDIMS]) { + input_error(fp, "Unable to read Cartesian dimensions"); + + destroy_grid(G); + G = NULL; + } + else { + /* Account for dimens[GRID_DIMS] < 3 */ + size_t n = (sizeof G->cartdims) / (sizeof G->cartdims[0]); + for (; i < n; i++) { G->cartdims[ i ] = 1; } + } + } + } + else { + input_error(fp, "Unable to read grid predicates"); + + G = NULL; + } + } + else { + input_error(fp, "Unable to read grid dimensions"); + + G = NULL; + } + + errno = save_errno; + + return G; +} + + +static int +read_grid_nodes(FILE *fp, struct UnstructuredGrid *G) +{ + int save_errno; + size_t i, n; + + save_errno = errno; + + n = G->dimensions; + n *= G->number_of_nodes; + + i = 0; + while ((i < n) && + (fscanf(fp, " %lf", & G->node_coordinates[ i ]) == 1)) { + i += 1; + } + + if (i < n) { + input_error(fp, "Unable to read node coordinates"); + } + + errno = save_errno; + + return i == n; +} + + +static int +read_grid_faces(FILE *fp, struct UnstructuredGrid *G) +{ + int save_errno, ok; + size_t nf, nfn, i; + + save_errno = errno; + + nf = G->number_of_faces; + + /* G->face_nodepos */ + i = 0; + while ((i < nf + 1) && + (fscanf(fp, " %d", & G->face_nodepos[ i ]) == 1)) { + i += 1; + } + ok = i == nf + 1; + + if (! ok) { + input_error(fp, "Unable to read node indirection array"); + } + else { + /* G->face_nodes */ + nfn = G->face_nodepos[ nf ]; + + i = 0; + while ((i < nfn) && (fscanf(fp, " %d", & G->face_nodes[ i ]) == 1)) { + i += 1; + } + + ok = i == nfn; + if (! ok) { + input_error(fp, "Unable to read face-nodes"); + } + } + + if (ok) { + /* G->face_cells */ + i = 0; + while ((i < 2 * nf) && (fscanf(fp, " %d", & G->face_cells[ i ]) == 1)) { + i += 1; + } + + ok = i == 2 * nf; + if (! ok) { + input_error(fp, "Unable to read neighbourship"); + } + } + + if (ok) { + /* G->face_areas */ + i = 0; + while ((i < nf) && (fscanf(fp, " %lf", & G->face_areas[ i ]) == 1)) { + i += 1; + } + + ok = i == nf; + if (! ok) { + input_error(fp, "Unable to read face areas"); + } + } + + if (ok) { + /* G->face_centroids */ + size_t n; + + n = G->dimensions; + n *= nf; + + i = 0; + while ((i < n) && (fscanf(fp, " %lf", & G->face_centroids[ i ]) == 1)) { + i += 1; + } + + ok = i == n; + if (! ok) { + input_error(fp, "Unable to read face centroids"); + } + } + + if (ok) { + /* G->face_normals */ + size_t n; + + n = G->dimensions; + n *= nf; + + i = 0; + while ((i < n) && (fscanf(fp, " %lf", & G->face_normals[ i ]) == 1)) { + i += 1; + } + + ok = i == n; + if (! ok) { + input_error(fp, "Unable to read face normals"); + } + } + + errno = save_errno; + + return ok; +} + + +static int +read_grid_cells(FILE *fp, int has_tag, int has_indexmap, + struct UnstructuredGrid *G) +{ + int save_errno, ok; + size_t nc, ncf, i; + + save_errno = errno; + + nc = G->number_of_cells; + + /* G->cell_facepos */ + i = 0; + while ((i < nc + 1) && (fscanf(fp, " %d", & G->cell_facepos[ i ]) == 1)) { + i += 1; + } + ok = i == nc + 1; + + if (! ok) { + input_error(fp, "Unable to read face indirection array"); + } + else { + /* G->cell_faces (and G->cell_facetag if applicable) */ + ncf = G->cell_facepos[ nc ]; + i = 0; + + if (has_tag) { + assert (G->cell_facetag != NULL); + + while ((i < ncf) && + (fscanf(fp, " %d %d", + & G->cell_faces [ i ], + & G->cell_facetag[ i ]) == 2)) { + i += 1; + } + } + else { + while ((i < ncf) && + (fscanf(fp, " %d", & G->cell_faces[ i ]) == 1)) { + i += 1; + } + } + + ok = i == ncf; + if (! ok) { + input_error(fp, "Unable to read cell-faces"); + } + } + + if (ok) { + /* G->global_cell if applicable */ + if (has_indexmap) { + i = 0; + + if (G->global_cell != NULL) { + while ((i < nc) && + (fscanf(fp, " %d", & G->global_cell[ i ]) == 1)) { + i += 1; + } + } + else { + int discard; + + while ((i < nc) && (fscanf(fp, " %d", & discard) == 1)) { + i += 1; + } + } + } + else { + assert (G->global_cell == NULL); + i = nc; + } + + ok = i == nc; + if (! ok) { + input_error(fp, "Unable to read global cellmap"); + } + } + + if (ok) { + /* G->cell_volumes */ + i = 0; + while ((i < nc) && (fscanf(fp, " %lf", & G->cell_volumes[ i ]) == 1)) { + i += 1; + } + + ok = i == nc; + if (! ok) { + input_error(fp, "Unable to read cell volumes"); + } + } + + if (ok) { + /* G->cell_centroids */ + size_t n; + + n = G->dimensions; + n *= nc; + + i = 0; + while ((i < n) && (fscanf(fp, " %lf", & G->cell_centroids[ i ]) == 1)) { + i += 1; + } + + ok = i == n; + if (! ok) { + input_error(fp, "Unable to read cell centroids"); + } + } + + errno = save_errno; + + return ok; +} + + +struct UnstructuredGrid * +read_grid(const char *fname) +{ + struct UnstructuredGrid *G; + FILE *fp; + + int save_errno; + int has_tag, has_indexmap, ok; + + save_errno = errno; + + fp = fopen(fname, "rt"); + if (fp != NULL) { + G = allocate_grid_from_file(fp, & has_tag, & has_indexmap); + + ok = G != NULL; + + if (ok) { ok = read_grid_nodes(fp, G); } + if (ok) { ok = read_grid_faces(fp, G); } + if (ok) { ok = read_grid_cells(fp, has_tag, has_indexmap, G); } + + if (! ok) { + destroy_grid(G); + G = NULL; + } + + fclose(fp); + } + else { + G = NULL; + } + + errno = save_errno; + + return G; +} diff --git a/opm/core/grid.h b/opm/core/grid.h index 841ea8e2..37b074d4 100644 --- a/opm/core/grid.h +++ b/opm/core/grid.h @@ -273,6 +273,17 @@ allocate_grid(size_t ndims , size_t ncellfaces, size_t nnodes ); + +/** + * Import a grid from a character representation stored in file. + * + * @param[in] fname File name. + * @return Fully formed UnstructuredGrid with all fields allocated and filled. + * Returns @c NULL in case of allocation failure. + */ +struct UnstructuredGrid * +read_grid(const char *fname); + #ifdef __cplusplus } #endif From 66ee40c80999486858468b11102b762f1c0834bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Tue, 28 Aug 2012 16:05:44 +0200 Subject: [PATCH 02/13] Add a simple test to demonstrate grid input. Should be extended to test that the input is sane, too. --- tests/Makefile.am | 1 + tests/test_read_grid.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_read_grid.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 43812479..b1e70503 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,6 +19,7 @@ sparsevector_test \ test_cartgrid \ test_column_extract \ test_lapack \ +test_read_grid \ test_read_vag \ test_readpolymer \ test_sf2p \ diff --git a/tests/test_read_grid.c b/tests/test_read_grid.c new file mode 100644 index 00000000..c739771a --- /dev/null +++ b/tests/test_read_grid.c @@ -0,0 +1,25 @@ +/* + * test_read_grid.c + * + * Created on: Aug 28, 2012 + * Author: bska + */ + +#include + +#include +#include + +int +main(void) +{ + struct UnstructuredGrid *G1, *G2; + + G1 = read_grid("cart_grid_2d.txt"); + G2 = create_grid_cart2d(2, 2); + + destroy_grid(G2); + destroy_grid(G1); + + return 0; +} From c1970ac90d8f695283e5a0e30b537c0a787d99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 3 Sep 2012 15:24:22 +0200 Subject: [PATCH 03/13] allocate_grid_from_file(): Name magic constant (6) The constant 6 is the number of array dimensions needed to successfully allocate a grid. While unlikely, this number may change in the future and it is better to have a manifest constant (in this case, GRID_NMETA) than a hard-coded number. --- opm/core/grid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/opm/core/grid.c b/opm/core/grid.c index bb7de1bc..12a851b1 100644 --- a/opm/core/grid.c +++ b/opm/core/grid.c @@ -142,6 +142,7 @@ allocate_grid(size_t ndims , } +#define GRID_NMETA 6 #define GRID_NDIMS 0 #define GRID_NCELLS 1 #define GRID_NFACES 2 @@ -174,18 +175,18 @@ allocate_grid_from_file(FILE *fp, int *has_tag, int *has_indexmap) int save_errno; unsigned long tmp; - size_t dimens[6], i; + size_t dimens[GRID_NMETA], i; save_errno = errno; i = 0; - while ((i < 6) && (fscanf(fp, " %lu", &tmp) == 1)) { + while ((i < GRID_NMETA) && (fscanf(fp, " %lu", &tmp) == 1)) { dimens[i] = tmp; i += 1; } - if (i == 6) { + if (i == GRID_NMETA) { if (fscanf(fp, "%d %d", has_tag, has_indexmap) == 2) { G = allocate_grid(dimens[GRID_NDIMS] , dimens[GRID_NCELLS] , From 233e3601a8fc0f98fca49fa08961be0764fc1eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 19:44:13 +0200 Subject: [PATCH 04/13] Simplify the logic to support --with-unit*=speciallib syntax This change implements the approach of (e.g.,) ax_boost_system.m4, but may lose some of the initial refinements. In that case, we will have to refine this code. --- m4/ax_boost_unit_test_framework.m4 | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/m4/ax_boost_unit_test_framework.m4 b/m4/ax_boost_unit_test_framework.m4 index 0cee8baa..424b3162 100644 --- a/m4/ax_boost_unit_test_framework.m4 +++ b/m4/ax_boost_unit_test_framework.m4 @@ -102,27 +102,32 @@ AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK], fi else link_unit_test_framework="no" - saved_ldflags="${LDFLAGS}" + saved_ldflags="${LDFLAGS}" for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do - if test "x$link_unit_test_framework" = "xyes"; then - break; - fi - for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.so* $BOOSTLIBDIR/lib${ax_lib}.a* 2>/dev/null` ; do - if test -r $unittest_library ; then - libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` - ax_lib=${libextension} - link_unit_test_framework="yes" - else - link_unit_test_framework="no" - fi + #if test "x$link_unit_test_framework" = "xyes"; then + # break; + #fi + #for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.so* $BOOSTLIBDIR/lib${ax_lib}.a* 2>/dev/null` ; do + #if test -r $unittest_library ; then + # libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` + # ax_lib=${libextension} + # link_unit_test_framework="yes" + # else + # link_unit_test_framework="no" + # fi +# + # if test "x$link_unit_test_framework" = "xyes"; then + # BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" + # AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) + # break + # fi - if test "x$link_unit_test_framework" = "xyes"; then - BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" - AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) - break - fi - done - done + # done + + AC_CHECK_LIB($ax_lib, [exit], + [BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST([BOOST_UNIT_TEST_FRAMEWORK_LIB]) link_unit_test_framework="yes"; break], + [link_unit_test_framework="no"]) + done fi if test "x$ax_lib" = "x"; then AC_MSG_ERROR(Could not find a version of the library!) From b7c0ba8b1a73126d39ecb3c5e7a81d88bbc5a5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 19:53:15 +0200 Subject: [PATCH 05/13] Expose the Boost library directory to the build system. This enables explicitly encoding the directory, e.g., in the OPM-Core run-path. This, in turn, reduces the burden on library clients that would otherwise have to satisfy library link requirements in addition to any other link requirements they might have. --- m4/opm_boost_base.m4 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/m4/opm_boost_base.m4 b/m4/opm_boost_base.m4 index 430f9abb..4f4ea066 100644 --- a/m4/opm_boost_base.m4 +++ b/m4/opm_boost_base.m4 @@ -103,6 +103,7 @@ if test "x$want_boost" = "xyes"; then for ac_boost_path_tmp in $libsubdirs; do if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then OPM_BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp" + OPM_BOOST_LIBDIR="${ac_boost_path}/${ac_boost_path_tmp}" break fi done @@ -114,6 +115,7 @@ if test "x$want_boost" = "xyes"; then done OPM_BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir" OPM_BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" + OPM_BOOST_LIBDIR="${ac_boost_path_tmp}/${libsubdir}" break; fi done @@ -123,6 +125,7 @@ if test "x$want_boost" = "xyes"; then dnl --with-boost-libdir parameter if test "$ac_boost_lib_path" != ""; then OPM_BOOST_LDFLAGS="-L$ac_boost_lib_path" + OPM_BOOST_LIBDIR="${ac_boost_lib_path}" fi CPPFLAGS_SAVED="$CPPFLAGS" @@ -191,6 +194,7 @@ if test "x$want_boost" = "xyes"; then if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi done OPM_BOOST_LDFLAGS="-L$best_path/$libsubdir" + OPM_BOOST_LIBDIR="$best_path/$libsubdir" fi fi @@ -207,6 +211,7 @@ if test "x$want_boost" = "xyes"; then AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) OPM_BOOST_CPPFLAGS="-I$BOOST_ROOT" OPM_BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir" + OPM_BOOST_LIBDIR="$BOOST_ROOT/stage/$libsubdir" fi fi fi @@ -248,6 +253,7 @@ if test "x$want_boost" = "xyes"; then else AC_SUBST([OPM_BOOST_CPPFLAGS]) AC_SUBST([OPM_BOOST_LDFLAGS]) + AC_SUBST([OPM_BOOST_LIBDIR]) AC_DEFINE([OPM_HAVE_BOOST], [1], [define if the Boost library is available]) # execute ACTION-IF-FOUND (if present): ifelse([$2], , :, [$2]) From 37e14f468e1354ef54083513548f2bb54d4c768b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 20:15:57 +0200 Subject: [PATCH 06/13] Encode Boost library location in OPM-Core's run-path. Specifically, use the OPM_BOOST_LIBDIR variable created in commit 5c97e512 and Libtool's "-R" link-time switch to encode the library location within OPM-Core's run-path. This simplifies using the library, because the onus of satisfying the library's link-time requirements is removed from the client. A second refinement puts the additional link-requirements (i.e., "-l" and "-L" options) within the *_LIBADD primary. This moves the libraries from the middle to the end of the link statement. middle. --- Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 845c5fa9..048dfaa0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,10 @@ $(OPM_BOOST_CPPFLAGS) # (transitively) convey inter-library dependency information. lib_libopmcore_la_LDFLAGS = \ -$(OPM_BOOST_LDFLAGS) \ +-R $(OPM_BOOST_LIBDIR) \ +$(OPM_BOOST_LDFLAGS) + +lib_libopmcore_la_LIBADD = \ $(BOOST_FILESYSTEM_LIB) \ $(BOOST_SYSTEM_LIB) \ $(BOOST_DATE_TIME_LIB) \ From b1ec06293e6293003b13cf17b9734c15708726f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 20:22:07 +0200 Subject: [PATCH 07/13] Obtain Boost libraries from libopmcore.la . Specifically, commit ff4f709e made the support for transitively conveying interlibrary dependencies onto clients of OPM-Core more robust. As a consequence, we no longer need to explicitly link in the Boost.System or Boost.Filesystem libraries to use the software contained therein. --- examples/Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index b01f7674..38d41e22 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -5,9 +5,7 @@ $(OPM_BOOST_CPPFLAGS) # All targets link to the library LDADD = \ -$(top_builddir)/lib/libopmcore.la \ -$(BOOST_FILESYSTEM_LIB) \ -$(BOOST_SYSTEM_LIB) +$(top_builddir)/lib/libopmcore.la # ---------------------------------------------------------------------- # Declare products (i.e., the example programs). From a6dc97a7069a5d459a1102ddf0c8d978ef77d852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 16:31:15 +0200 Subject: [PATCH 08/13] Honour exact interface of LAPACK routine DGTSV. The "MAT_SIZE_T" is not necessarily equivalent to 'int'. --- opm/core/transport/GravityColumnSolver_impl.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opm/core/transport/GravityColumnSolver_impl.hpp b/opm/core/transport/GravityColumnSolver_impl.hpp index 5d5c6445..7e31778c 100644 --- a/opm/core/transport/GravityColumnSolver_impl.hpp +++ b/opm/core/transport/GravityColumnSolver_impl.hpp @@ -175,10 +175,10 @@ namespace Opm } // model_.sourceTerms(); // Not needed // Solve. - const int num_rhs = 1; - int info = 0; + const MAT_SIZE_T num_rhs = 1, colSize = col_size; + MAT_SIZE_T info = 0; // Solution will be written to rhs. - dgtsv_(&col_size, &num_rhs, DL, D, DU, &rhs[0], &col_size, &info); + dgtsv_(&colSize, &num_rhs, DL, D, DU, &rhs[0], &colSize, &info); if (info != 0) { THROW("Lapack reported error in dgtsv: " << info); } From 8a3593c372821826caba0a05a7b8fe29e7b5b771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 16:35:34 +0200 Subject: [PATCH 09/13] Unequivocally exclude MATLAB timing printing. It is not actually needed and prevents building when symbol MATLAB_MEX_FILE is defined. --- opm/core/transport/reorder/TransportModelInterface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opm/core/transport/reorder/TransportModelInterface.cpp b/opm/core/transport/reorder/TransportModelInterface.cpp index c52b528d..f8e138a3 100644 --- a/opm/core/transport/reorder/TransportModelInterface.cpp +++ b/opm/core/transport/reorder/TransportModelInterface.cpp @@ -35,6 +35,7 @@ void Opm::TransportModelInterface::reorderAndTransport(const UnstructuredGrid& g // Invoke appropriate solve method for each interdependent component. for (int comp = 0; comp < ncomponents; ++comp) { +#if 0 #ifdef MATLAB_MEX_FILE // \TODO replace this with general signal handling code, check if it costs performance. if (interrupt_signal) { @@ -42,6 +43,7 @@ void Opm::TransportModelInterface::reorderAndTransport(const UnstructuredGrid& g "cells finished.\n", i, grid.number_of_cells); break; } +#endif #endif const int comp_size = components[comp + 1] - components[comp]; if (comp_size == 1) { From 203728109fd9ac3dcbe3d6ad38aec3de2b5b6e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 16:49:50 +0200 Subject: [PATCH 10/13] Honour exact interfaces of LAPACK routines. The size type, MAT_SIZE_T, is not necessarily equivalent to 'int'. --- tests/test_lapack.cpp | 54 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/tests/test_lapack.cpp b/tests/test_lapack.cpp index 3f5aff91..56b0bbb9 100644 --- a/tests/test_lapack.cpp +++ b/tests/test_lapack.cpp @@ -24,34 +24,36 @@ namespace { struct BandMatrixCoeff { - BandMatrixCoeff(int N, int ku, int kl) : ku_(ku), kl_(kl), nrow_(2*kl + ku + 1), N_(N) { + BandMatrixCoeff(MAT_SIZE_T N, MAT_SIZE_T ku, MAT_SIZE_T kl) + : ku_(ku), kl_(kl), nrow_(2 * kl + ku + 1), N_(N) + { } // compute the position where to store the coefficient of a matrix A_{i,j} (i,j=0,...,N-1) // in a array which is sent to the band matrix solver of LAPACK. - int operator ()(int i, int j) { + int operator ()(MAT_SIZE_T i, MAT_SIZE_T j) { return kl_ + ku_ + i - j + j*nrow_; } - const int ku_; - const int kl_; - const int nrow_; - const int N_; + const MAT_SIZE_T ku_; + const MAT_SIZE_T kl_; + const MAT_SIZE_T nrow_; + const MAT_SIZE_T N_; }; } //end anonymous namespace int main() { - const int N = 5; - const int nrhs = 1; + const MAT_SIZE_T N = 5; + const MAT_SIZE_T nrhs = 1; double DU[N-1] = { 2.1, -1.0, 1.9, 8.0 }; double D[N] = { 3.0, 2.3, -5.0, -0.9, 7.1 }; double DL[N-1] = { 3.4, 3.6, 7.0, -6.0 }; double B[N] = { 2.7, -0.5, 2.6, 0.6, 2.7 }; // double B[N] = { 2.7, -0.5, 2.6, 0.6, 2.7 }; - int info = 0; + MAT_SIZE_T info = 0; dgtsv_(&N, &nrhs, DL, D, DU, B, &N, &info); if (info == 0) { for (int i = 0; i < N; ++i) { @@ -64,12 +66,12 @@ int main() std::cout << std::endl; //test of dgbsv_ - int ldb = N; - int lda = N; - std::vector ipiv(N, 0); + MAT_SIZE_T ldb = N; + MAT_SIZE_T lda = N; + std::vector ipiv(N, 0); std::vector AA(N*N, 0.); std::vector BB(N, 0.); - for (int i = 0; i < N; ++i) { + for (MAT_SIZE_T i = 0; i < N; ++i) { AA[i + i*N] = 10.; if (i > 0) { AA[i + (i - 1)*N] = i; @@ -78,31 +80,31 @@ int main() BB[i] = i; } - for (int i = 0; i < N; ++i) { - for (int j = 0; j < N; ++j) { + for (MAT_SIZE_T i = 0; i < N; ++i) { + for (MAT_SIZE_T j = 0; j < N; ++j) { std::cout << " " << AA[i + j*N]; } std::cout << " " << std::endl; } std::cout << std::endl; - int kl = 1; - int ku = 1; - int nrowAB = 2*kl + ku + 1; - int ldab = nrowAB; + MAT_SIZE_T kl = 1; + MAT_SIZE_T ku = 1; + MAT_SIZE_T nrowAB = 2*kl + ku + 1; + MAT_SIZE_T ldab = nrowAB; std::vector AB(nrowAB*N, 0.); BandMatrixCoeff bmc(N, ku, kl); // Rewrite AA matrix in band format AB - for (int i = 0; i < N; ++i) { - for (int j = -1; j < 2; ++j) { + for (MAT_SIZE_T i = 0; i < N; ++i) { + for (MAT_SIZE_T j = -1; j < 2; ++j) { if (i + j > -1 && i + j < N) AB[bmc(i, i + j)] = AA[i + N*(i + j)]; } } - for (int i = 0; i < nrowAB; ++i) { - for (int j = 0; j < N; ++j) { + for (MAT_SIZE_T i = 0; i < nrowAB; ++i) { + for (MAT_SIZE_T j = 0; j < N; ++j) { std::cout << " " << AB[i + j*nrowAB]; } std::cout << " " << std::endl; @@ -113,7 +115,7 @@ int main() dgesv_(&N ,&nrhs, &AA[0], &lda, &ipiv[0], &BB[0], &ldb, &info); if (info == 0) { - for (int i = 0; i < N; ++i) { + for (MAT_SIZE_T i = 0; i < N; ++i) { std::cout << BB[i] << ' '; } std::cout << std::endl; @@ -121,14 +123,14 @@ int main() std::cerr << "Something went wrong in debsv_()\n"; } - for (int i = 0; i < N; ++i) { + for (MAT_SIZE_T i = 0; i < N; ++i) { BB[i] = i; } dgbsv_(&N, &kl, &ku, &nrhs, &AB[0], &ldab, &ipiv[0], &BB[0], &ldb, &info); if (info == 0) { - for (int i = 0; i < N; ++i) { + for (MAT_SIZE_T i = 0; i < N; ++i) { std::cout << BB[i] << ' '; } std::cout << std::endl; From 6fd5c36cc93adb998d053041aa5d5c5cb7ce68d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 18:26:26 +0200 Subject: [PATCH 11/13] Remove a derelict statement inherited from original implementation. Disabled by default, this statement attempted to pass a std::istream to function std::fclose() which is meaningless and should not be enabled at any time--even for a MATLAB-related build. --- opm/core/utility/parameters/ParameterGroup.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/opm/core/utility/parameters/ParameterGroup.cpp b/opm/core/utility/parameters/ParameterGroup.cpp index 30e7b8e4..3fcbf8d2 100644 --- a/opm/core/utility/parameters/ParameterGroup.cpp +++ b/opm/core/utility/parameters/ParameterGroup.cpp @@ -4,7 +4,7 @@ // // Created: Tue Jun 2 19:13:17 2009 // -// Author(s): Bård Skaflestad +// Author(s): BÃ¥rd Skaflestad // Atgeirr F Rasmussen // // $Date$ @@ -139,9 +139,6 @@ namespace Opm { } } } - #ifdef MATLAB_MEX_FILE - fclose(is); - #endif } void ParameterGroup::writeParam(const std::string& param_filename) const { From 5c9c9b9c59f9495fb993e90ebaf5f862a980b00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 19:16:31 +0200 Subject: [PATCH 12/13] Reference from canonical location. The header was removed from this directory upon import from the preexisting "opmtransport" repository. --- opm/core/transport/reorder/reordersequence.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/transport/reorder/reordersequence.cpp b/opm/core/transport/reorder/reordersequence.cpp index 29f3a0aa..0e7b9f94 100644 --- a/opm/core/transport/reorder/reordersequence.cpp +++ b/opm/core/transport/reorder/reordersequence.cpp @@ -1,11 +1,11 @@ /* Copyright 2011 (c) Jostein R. Natvig */ +#include + #ifdef MATLAB_MEX_FILE -#include "grid.h" #include "reordersequence.h" #include "tarjan.h" #else -#include #include #include #endif From 811bfa771247703d4177025f8730015d648763b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 24 Aug 2012 19:28:08 +0200 Subject: [PATCH 13/13] Remove MEX support. This has not been used in a long time, and actually prevents using the module in MEX. --- opm/core/transport/reorder/nlsolvers.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/opm/core/transport/reorder/nlsolvers.c b/opm/core/transport/reorder/nlsolvers.c index df95d2b3..ae372eb2 100644 --- a/opm/core/transport/reorder/nlsolvers.c +++ b/opm/core/transport/reorder/nlsolvers.c @@ -26,24 +26,8 @@ SOFTWARE. #include #include -#ifdef MATLAB_MEX_FILE -#include "nlsolvers.h" - -#include -extern int interrupt_signal; -#define print mexPrintf -#define malloc mxMalloc -#define calloc mxCalloc -#define realloc mxRealloc -#define free mxFree - -#else /* MATLAB_MEX_FILE */ - -#define print printf #include -#endif /* MATLAB_MEX_FILE */ - static const char no_root_str[]= " In %s:\n" " With G(%5f) =% 5f, G(%5f) =% 5f, G(x) is not bracketed!\n"; @@ -100,7 +84,7 @@ ridders (double (*G)(double, void*), void *data, struct NonlinearSolverCtrl *ctr if (G0*G1 > 0) { - print(no_root_str, "ridder", s0, G0, s1, G1); + printf(no_root_str, "ridder", s0, G0, s1, G1); return -1.0; } @@ -157,7 +141,7 @@ ridders (double (*G)(double, void*), void *data, struct NonlinearSolverCtrl *ctr } else { - print("In ridder:\nG0=%10.10f, G1=%10.10f, " + printf("In ridder:\nG0=%10.10f, G1=%10.10f, " "G3=%10.10f\n", G0, G1, G3); } s2 = 0.5*(s0+s1); @@ -199,7 +183,7 @@ regulafalsi (double (*G)(double, void*), void *data, struct NonlinearSolverCtrl if (G0*G1 > 0) { - print(no_root_str, "regulafalsi", s0, G0, s1, G1); + printf(no_root_str, "regulafalsi", s0, G0, s1, G1); return -1.0; } @@ -282,7 +266,7 @@ bisection (double (*G)(double, void*), void *data, struct NonlinearSolverCtrl *c if (G0*G1 > 0.0) { - print(no_root_str, "bisection", s0, G0, s1, G1); + printf(no_root_str, "bisection", s0, G0, s1, G1); return -1.0; } @@ -312,7 +296,7 @@ bisection (double (*G)(double, void*), void *data, struct NonlinearSolverCtrl *c } if (ctrl->iterations >= ctrl->maxiterations) { - print("Warning: convergence criterion not met\n"); + printf("Warning: convergence criterion not met\n"); } ctrl->residual = Gn; return sn;