Implementation (not finished) of wells_equal, well_controls_equal, and tests. To build a WellsManager test for old and new parser
Conflicts: CMakeLists_files.cmake
This commit is contained in:
parent
b280af372b
commit
fd942e347d
@ -166,6 +166,8 @@ list (APPEND TEST_SOURCE_FILES
|
|||||||
tests/test_shadow.cpp
|
tests/test_shadow.cpp
|
||||||
tests/test_units.cpp
|
tests/test_units.cpp
|
||||||
tests/test_blackoilstate.cpp
|
tests/test_blackoilstate.cpp
|
||||||
|
tests/test_parser.cpp
|
||||||
|
tests/test_wellsmanager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# originally generated with the command:
|
# originally generated with the command:
|
||||||
@ -176,6 +178,7 @@ list (APPEND TEST_DATA_FILES
|
|||||||
tests/testFluid.DATA
|
tests/testFluid.DATA
|
||||||
tests/testBlackoilState1.DATA
|
tests/testBlackoilState1.DATA
|
||||||
tests/testBlackoilState2.DATA
|
tests/testBlackoilState2.DATA
|
||||||
|
tests/wells_manager_data.data
|
||||||
)
|
)
|
||||||
|
|
||||||
# originally generated with the command:
|
# originally generated with the command:
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef OPM_WELLS_H_INCLUDED
|
#ifndef OPM_WELLS_H_INCLUDED
|
||||||
#define OPM_WELLS_H_INCLUDED
|
#define OPM_WELLS_H_INCLUDED
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
@ -82,6 +83,8 @@ struct WellControls
|
|||||||
*/
|
*/
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
|
int number_of_phases;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of control types.
|
* Array of control types.
|
||||||
*/
|
*/
|
||||||
@ -94,7 +97,7 @@ struct WellControls
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of rate control distributions,
|
* Array of rate control distributions,
|
||||||
* <CODE>Wells::number_of_phases</CODE> numbers for each control
|
* <CODE>number_of_phases</CODE> numbers for each control
|
||||||
*/
|
*/
|
||||||
double *distr;
|
double *distr;
|
||||||
|
|
||||||
@ -327,6 +330,12 @@ destroy_wells(struct Wells *W);
|
|||||||
struct Wells *
|
struct Wells *
|
||||||
clone_wells(const struct Wells *W);
|
clone_wells(const struct Wells *W);
|
||||||
|
|
||||||
|
bool
|
||||||
|
wells_equal(const struct Wells *W1, const struct Wells *W2);
|
||||||
|
|
||||||
|
bool
|
||||||
|
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct WellControlMgmt {
|
struct WellControlMgmt {
|
||||||
int cpty;
|
int cpty;
|
||||||
};
|
};
|
||||||
@ -124,6 +126,7 @@ well_controls_create(void)
|
|||||||
if (ctrl != NULL) {
|
if (ctrl != NULL) {
|
||||||
/* Initialise empty control set */
|
/* Initialise empty control set */
|
||||||
ctrl->num = 0;
|
ctrl->num = 0;
|
||||||
|
ctrl->number_of_phases = 0;
|
||||||
ctrl->type = NULL;
|
ctrl->type = NULL;
|
||||||
ctrl->target = NULL;
|
ctrl->target = NULL;
|
||||||
ctrl->distr = NULL;
|
ctrl->distr = NULL;
|
||||||
@ -160,6 +163,8 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl)
|
|||||||
if (target != NULL) { ctrl->target = target; ok++; }
|
if (target != NULL) { ctrl->target = target; ok++; }
|
||||||
if (distr != NULL) { ctrl->distr = distr ; ok++; }
|
if (distr != NULL) { ctrl->distr = distr ; ok++; }
|
||||||
|
|
||||||
|
ctrl->number_of_phases = nphases;
|
||||||
|
|
||||||
if (ok == 3) {
|
if (ok == 3) {
|
||||||
m = ctrl->data;
|
m = ctrl->data;
|
||||||
for (c = m->cpty; c < nctrl; c++) {
|
for (c = m->cpty; c < nctrl; c++) {
|
||||||
@ -167,7 +172,7 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl)
|
|||||||
ctrl->target[c] = -1.0;
|
ctrl->target[c] = -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (p = m->cpty * nphases; p < nctrl * nphases; ++p) {
|
for (p = m->cpty * ctrl->number_of_phases; p < nctrl * ctrl->number_of_phases; ++p) {
|
||||||
ctrl->distr[ p ] = 0.0;
|
ctrl->distr[ p ] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,6 +596,7 @@ clear_well_controls(int well_index, struct Wells *W)
|
|||||||
|
|
||||||
if (W->ctrls[well_index] != NULL) {
|
if (W->ctrls[well_index] != NULL) {
|
||||||
W->ctrls[well_index]->num = 0;
|
W->ctrls[well_index]->num = 0;
|
||||||
|
W->ctrls[well_index]->number_of_phases = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,3 +674,67 @@ clone_wells(const struct Wells *W)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
bool
|
||||||
|
wells_equal(const struct Wells *W1, const struct Wells *W2)
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
bool are_equal = true;
|
||||||
|
are_equal = (W1->number_of_wells == W2->number_of_wells);
|
||||||
|
are_equal &= (W1->number_of_phases == W2->number_of_phases);
|
||||||
|
if (!are_equal) {
|
||||||
|
return are_equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<W1->number_of_wells; i++) {
|
||||||
|
are_equal &= (strcmp(W1->name[i], W2->name[i]) == 0);
|
||||||
|
are_equal &= (W1->type[i] == W2->type[i]);
|
||||||
|
are_equal &= (W1->depth_ref[i] == W2->depth_ref[i]);
|
||||||
|
are_equal &= (well_controls_equal(W1->ctrls[i], W2->ctrls[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct WellMgmt* mgmt1 = (struct WellMgmt*)(W1->data);
|
||||||
|
struct WellMgmt* mgmt2 = (struct WellMgmt*)(W2->data);
|
||||||
|
are_equal &= (mgmt1->perf_cpty == mgmt2->perf_cpty);
|
||||||
|
are_equal &= (mgmt1->well_cpty == mgmt2->well_cpty);
|
||||||
|
|
||||||
|
are_equal &= (memcmp(W1->comp_frac, W2->comp_frac, W1->number_of_wells * W1->number_of_phases * sizeof *W1->comp_frac ) == 0);
|
||||||
|
are_equal &= (memcmp(W1->well_connpos, W2->well_connpos, (1 + W1->number_of_wells) * sizeof *W1->well_connpos ) == 0);
|
||||||
|
if (!are_equal) {
|
||||||
|
return are_equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int number_of_perforations = W1->well_connpos[W1->number_of_wells];
|
||||||
|
|
||||||
|
are_equal &= (memcmp(W1->well_cells, W2->well_cells, number_of_perforations * sizeof *W1->well_cells ) == 0);
|
||||||
|
are_equal &= (memcmp(W1->WI, W2->WI, number_of_perforations * sizeof *W1->WI ) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return are_equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
bool
|
||||||
|
well_controls_equal(const struct WellControls *ctrls1, const struct WellControls *ctrls2)
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
bool are_equal = true;
|
||||||
|
are_equal = (ctrls1->num == ctrls2->num);
|
||||||
|
are_equal &= (ctrls1->number_of_phases == ctrls2->number_of_phases);
|
||||||
|
if (!are_equal) {
|
||||||
|
return are_equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
are_equal &= (memcmp(ctrls1->type, ctrls2->type, ctrls1->num * sizeof *ctrls1->type ) == 0);
|
||||||
|
are_equal &= (memcmp(ctrls1->target, ctrls2->target, ctrls1->num * sizeof *ctrls1->target ) == 0);
|
||||||
|
are_equal &= (memcmp(ctrls1->distr, ctrls2->distr, ctrls1->num * ctrls1->number_of_phases * sizeof *ctrls1->distr ) == 0);
|
||||||
|
|
||||||
|
struct WellControlMgmt* mgmt1 = (struct WellControlMgmt*)(ctrls1->data);
|
||||||
|
struct WellControlMgmt* mgmt2 = (struct WellControlMgmt*)(ctrls2->data);
|
||||||
|
are_equal &= (mgmt1->cpty == mgmt2->cpty);
|
||||||
|
|
||||||
|
return are_equal;
|
||||||
|
}
|
||||||
|
@ -203,3 +203,29 @@ BOOST_AUTO_TEST_CASE(Copy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(Equals_WellsEqual_ReturnsTrue) {
|
||||||
|
const int nphases = 2;
|
||||||
|
const int nwells = 2;
|
||||||
|
const int nperfs = 2;
|
||||||
|
|
||||||
|
std::shared_ptr<Wells> W1(create_wells(nphases, nwells, nperfs),
|
||||||
|
destroy_wells);
|
||||||
|
std::shared_ptr<Wells> W2(create_wells(nphases, nwells, nperfs),
|
||||||
|
destroy_wells);
|
||||||
|
|
||||||
|
BOOST_CHECK(wells_equal(W1.get(), W2.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(Equals_WellsDiffer_ReturnsFalse) {
|
||||||
|
const int nphases = 2;
|
||||||
|
const int nperfs = 2;
|
||||||
|
|
||||||
|
std::shared_ptr<Wells> W1(create_wells(nphases, 2, nperfs),
|
||||||
|
destroy_wells);
|
||||||
|
std::shared_ptr<Wells> W2(create_wells(nphases, 3, nperfs),
|
||||||
|
destroy_wells);
|
||||||
|
|
||||||
|
BOOST_CHECK(!wells_equal(W1.get(), W2.get()));
|
||||||
|
}
|
||||||
|
40
tests/test_wellsmanager.cpp
Normal file
40
tests/test_wellsmanager.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 Statoil ASA.
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM 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.
|
||||||
|
|
||||||
|
OPM 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.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#if HAVE_DYNAMIC_BOOST_TEST
|
||||||
|
#define BOOST_TEST_DYN_LINK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NVERBOSE // Suppress own messages when throw()ing
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE WellsManagerTests
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <opm/core/wells/WellsManager.hpp>
|
||||||
|
#include <opm/core/io/eclipse/EclipseGridParser.hpp>
|
||||||
|
#include <opm/core/grid/GridManager.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(Constructor_Old_Works) {
|
||||||
|
Opm::EclipseGridParser oldParser("wells_manager_data.data");
|
||||||
|
Opm::GridManager gridManager(oldParser);
|
||||||
|
Opm::WellsManager wellsManager(oldParser, *gridManager.c_grid(), NULL);
|
||||||
|
const Wells* oldWells = wellsManager.c_wells();
|
||||||
|
BOOST_CHECK_EQUAL(oldWells->number_of_wells, 2);
|
||||||
|
}
|
45
tests/wells_manager_data.data
Executable file
45
tests/wells_manager_data.data
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
OIL
|
||||||
|
GAS
|
||||||
|
WATER
|
||||||
|
|
||||||
|
DIMENS
|
||||||
|
15 5 5 /
|
||||||
|
|
||||||
|
GRID
|
||||||
|
|
||||||
|
DXV
|
||||||
|
15*1000.0 /
|
||||||
|
|
||||||
|
DYV
|
||||||
|
5*1000.0 /
|
||||||
|
|
||||||
|
DZV
|
||||||
|
10.0 20.0 30.0 10.0 5.0 /
|
||||||
|
|
||||||
|
SCHEDULE
|
||||||
|
|
||||||
|
WELSPECS
|
||||||
|
'INJ1' 'G' 1 1 8335 'GAS' /
|
||||||
|
'PROD1' 'G' 10 10 8400 'OIL' /
|
||||||
|
/
|
||||||
|
|
||||||
|
COMPDAT
|
||||||
|
'INJ1' 1 1 1 1 'OPEN' 1 10.6092 0.5 /
|
||||||
|
'PROD1' 10 3 3 3 'OPEN' 0 10.6092 0.5 /
|
||||||
|
|
||||||
|
/
|
||||||
|
|
||||||
|
WCONPROD
|
||||||
|
'PROD1' 'OPEN' 'ORAT' 20000 4* 1000 /
|
||||||
|
/
|
||||||
|
|
||||||
|
WCONINJE
|
||||||
|
'INJ1' 'GAS' 'OPEN' 'RATE' 100000 100000 50000/
|
||||||
|
/
|
||||||
|
|
||||||
|
|
||||||
|
TSTEP
|
||||||
|
14.0
|
||||||
|
/
|
||||||
|
|
||||||
|
END
|
Loading…
Reference in New Issue
Block a user