diff --git a/Makefile.am b/Makefile.am index b21a6ed5..b40f7bed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,7 +85,7 @@ opm/core/transport/reorder/reordersequence.c \ opm/core/transport/reorder/twophase.c \ opm/core/transport/reorder/nlsolvers.c \ opm/core/transport/reorder/tarjan.c \ -opm/core/transport/reorder/twophasetransport.c +opm/core/transport/reorder/twophasetransport.cpp nobase_include_HEADERS = \ @@ -201,7 +201,7 @@ opm/core/transport/reorder/nlsolvers.h \ opm/core/transport/reorder/reordersequence.h \ opm/core/transport/reorder/twophase.h \ opm/core/transport/reorder/tarjan.h \ -opm/core/transport/reorder/twophasetransport.h +opm/core/transport/reorder/twophasetransport.hpp if UMFPACK libopmcore_la_SOURCES += opm/core/linalg/call_umfpack.c diff --git a/examples/Makefile.am b/examples/Makefile.am index e2815600..02f2e48a 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -11,5 +11,7 @@ scaneclipsedeck if UMFPACK noinst_PROGRAMS += spu_2p reorder-qfs + spu_2p_SOURCES = spu_2p.cpp +reorder_qfs_SOURCES = reorder-qfs.cpp endif diff --git a/examples/reorder-qfs.c b/examples/reorder-qfs.cpp similarity index 82% rename from examples/reorder-qfs.c rename to examples/reorder-qfs.cpp index adf2f90c..709b694f 100644 --- a/examples/reorder-qfs.c +++ b/examples/reorder-qfs.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include struct Rock { @@ -39,12 +39,12 @@ static struct Rock* init_rock(int nc, int d) { int i,j; - struct Rock *rock = malloc(sizeof *rock); + struct Rock *rock = (struct Rock*) malloc(sizeof *rock); if (rock!=NULL) { - rock->perm = malloc(nc*d*d*sizeof *rock->perm); - rock->poro = malloc(nc * sizeof *rock->poro); + rock->perm = (double*) malloc(nc*d*d*sizeof *rock->perm); + rock->poro = (double*) malloc(nc * sizeof *rock->poro); if ((rock->perm==NULL) || (rock->poro==NULL)) { @@ -84,7 +84,7 @@ qfs(grid_t *g, struct Rock *rock, double *src, alloc_sz += g->number_of_faces; /* trans */ alloc_sz += totconn; /* gpress */ - htrans = malloc(alloc_sz * sizeof *htrans); + htrans = (double*) malloc(alloc_sz * sizeof *htrans); trans = htrans + totconn; gpress = trans + g->number_of_faces; @@ -129,11 +129,11 @@ int main(void) { struct UnstructuredGrid *g = create_cart_grid_2d(10,10); struct Rock *rock = init_rock(g->number_of_cells, g->dimensions); - double *sat = malloc(g->number_of_cells *sizeof *sat); - double *press = malloc(g->number_of_cells *sizeof *press); - double *flux = malloc(g->number_of_faces *sizeof *flux); - double *pv = malloc(g->number_of_cells *sizeof *pv); - double *src = malloc(g->number_of_cells *sizeof *src); + double *sat = (double*) malloc(g->number_of_cells *sizeof *sat); + double *press = (double*) malloc(g->number_of_cells *sizeof *press); + double *flux = (double*) malloc(g->number_of_faces *sizeof *flux); + double *pv = (double*) malloc(g->number_of_cells *sizeof *pv); + double *src = (double*) malloc(g->number_of_cells *sizeof *src); vector_zero(g->number_of_cells, sat); vector_zero(g->number_of_cells, src); diff --git a/examples/spu_2p.cpp b/examples/spu_2p.cpp index 40720cc2..b3d03a82 100644 --- a/examples/spu_2p.cpp +++ b/examples/spu_2p.cpp @@ -68,7 +68,7 @@ #include #include -#include +#include diff --git a/opm/core/transport/reorder/fluid.h b/opm/core/transport/reorder/fluid.h index edef301a..178468bf 100644 --- a/opm/core/transport/reorder/fluid.h +++ b/opm/core/transport/reorder/fluid.h @@ -16,6 +16,10 @@ #ifndef FLUID_H #define FLUID_H +#ifdef __cplusplus +extern "C" { +#endif + #ifdef MATLAB_MEX_FILE void init_fluid(const mxArray *); #else @@ -26,4 +30,8 @@ double fluxfun (double sw, const int); double dfluxfun (double sw, const int); int getNumSatRegions(void); +#ifdef __cplusplus +} +#endif + #endif /* FLUID_H */ diff --git a/opm/core/transport/reorder/nlsolvers.h b/opm/core/transport/reorder/nlsolvers.h index aeadd2a2..40de92d1 100644 --- a/opm/core/transport/reorder/nlsolvers.h +++ b/opm/core/transport/reorder/nlsolvers.h @@ -3,6 +3,10 @@ #ifndef NLSOLVERS_H #define NLSOLVERS_H +#ifdef __cplusplus +extern "C" { +#endif + struct NonlinearSolverCtrl { enum Method {RIDDERS, REGULAFALSI, BISECTION} method; @@ -18,6 +22,10 @@ double bisection (double (*)(double, void*), void*, struct NonlinearSolverCtrl double ridders (double (*)(double, void*), void*, struct NonlinearSolverCtrl *ctrl); double regulafalsi (double (*)(double, void*), void*, struct NonlinearSolverCtrl *ctrl); +#ifdef __cplusplus +} +#endif + #endif /* NLSOLVERS_H */ /* Local Variables: */ diff --git a/opm/core/transport/reorder/reordersequence.h b/opm/core/transport/reorder/reordersequence.h index 253864b5..3cda7446 100644 --- a/opm/core/transport/reorder/reordersequence.h +++ b/opm/core/transport/reorder/reordersequence.h @@ -2,12 +2,22 @@ #ifndef REORDERSEQUENCE_H_INCLUDED #define REORDERSEQUENCE_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + struct UnstructuredGrid; void compute_sequence(struct UnstructuredGrid *grid, const double *flux, int *sequence, int *components, int *ncomponents); + + +#ifdef __cplusplus +} #endif +#endif /* REORDERSEQUENCE_H_INCLUDED */ + /* Local Variables: */ /* c-basic-offset:4 */ /* End: */ diff --git a/opm/core/transport/reorder/twophase.h b/opm/core/transport/reorder/twophase.h index e04d3e9e..7217c365 100644 --- a/opm/core/transport/reorder/twophase.h +++ b/opm/core/transport/reorder/twophase.h @@ -3,6 +3,9 @@ #ifndef TWOPHASE_H_INCLUDED #define TWOPHASE_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif struct UnstructuredGrid; @@ -31,6 +34,10 @@ init_solverdata(struct UnstructuredGrid *grid, const double *darcyflux, const double *porevolume, const double *source, const int *satnum, double dt, double *saturation); +#ifdef __cplusplus +} +#endif + #endif /* TWOPHASE_H_INCLUDED */ /* Local Variables: */ diff --git a/opm/core/transport/reorder/twophasetransport.c b/opm/core/transport/reorder/twophasetransport.cpp similarity index 87% rename from opm/core/transport/reorder/twophasetransport.c rename to opm/core/transport/reorder/twophasetransport.cpp index 8c5a85bd..5a5a6566 100644 --- a/opm/core/transport/reorder/twophasetransport.c +++ b/opm/core/transport/reorder/twophasetransport.cpp @@ -10,7 +10,7 @@ #include "tarjan.h" #include "nlsolvers.h" #include "twophase.h" -#include "twophasetransport.h" +#include "twophasetransport.hpp" #include extern int interrupt_signal; @@ -26,7 +26,7 @@ extern int interrupt_signal; #include #include #include -#include +#include #define print printf @@ -58,8 +58,8 @@ void twophasetransport( /* Compute sequence of single-cell problems */ - sequence = malloc( grid->number_of_cells * sizeof *sequence); - components = malloc(( grid->number_of_cells+1) * sizeof *components); + sequence = (int*) malloc( grid->number_of_cells * sizeof *sequence); + components = (int*) malloc(( grid->number_of_cells+1) * sizeof *components); compute_sequence(grid, darcyflux, sequence, components, &ncomponents); assert(ncomponents == grid->number_of_cells); @@ -68,7 +68,7 @@ void twophasetransport( ctrl.maxiterations = 20; ctrl.nltolerance = 1e-9; - ctrl.method = REGULAFALSI; + ctrl.method = NonlinearSolverCtrl::REGULAFALSI; ctrl.initialguess = 0.5; /* Assume all strong components are single-cell domains. */ diff --git a/opm/core/transport/reorder/twophasetransport.h b/opm/core/transport/reorder/twophasetransport.hpp similarity index 63% rename from opm/core/transport/reorder/twophasetransport.h rename to opm/core/transport/reorder/twophasetransport.hpp index 6852bfcb..d76d8578 100644 --- a/opm/core/transport/reorder/twophasetransport.h +++ b/opm/core/transport/reorder/twophasetransport.hpp @@ -1,11 +1,8 @@ /* Copyright 2011 (c) Jostein R. Natvig */ -#ifndef TWOPHASETRANSPORT_H_INCLUDED -#define TWOPHASETRANSPORT_H_INCLUDED +#ifndef TWOPHASETRANSPORT_HPP_INCLUDED +#define TWOPHASETRANSPORT_HPP_INCLUDED -#ifdef __cplusplus -extern "C" { -#endif struct UnstructuredGrid; void twophasetransport( @@ -17,8 +14,5 @@ void twophasetransport( const int *satnum, double *saturation); -#ifdef __cplusplus -} -#endif -#endif /* TWOPHASETRANSPORT_H_INCLUDED */ +#endif /* TWOPHASETRANSPORT_HPP_INCLUDED */