mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-27 01:31:00 -06:00
Enable further compression of boundary conditions.
Specifically, refine the representation to allow a boundary condition to apply to a set of interfaces rather than just a single face. This support is realised by the introduction of new interface flow_conditions_append_multi(). Update all consumers of struct FlowBoundaryConditions to accommodate the one-to-many boundary condition interface mapping in the process.
This commit is contained in:
parent
8ca51c0ca4
commit
7bc5ef229a
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <opm/core/pressure/flow_bc.h>
|
#include <opm/core/pressure/flow_bc.h>
|
||||||
|
|
||||||
@ -50,48 +51,63 @@ static void
|
|||||||
initialise_structure(struct FlowBoundaryConditions *fbc)
|
initialise_structure(struct FlowBoundaryConditions *fbc)
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
fbc->nbc = 0;
|
fbc->nbc = 0;
|
||||||
fbc->cpty = 0;
|
fbc->cond_cpty = 0;
|
||||||
|
fbc->face_cpty = 0;
|
||||||
|
|
||||||
fbc->type = NULL;
|
fbc->cond_pos = NULL;
|
||||||
fbc->value = NULL;
|
fbc->type = NULL;
|
||||||
fbc->face = NULL;
|
fbc->value = NULL;
|
||||||
|
fbc->face = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
static int
|
static int
|
||||||
expand_tables(size_t nbc,
|
expand_tables(size_t nbc,
|
||||||
|
size_t nf ,
|
||||||
struct FlowBoundaryConditions *fbc)
|
struct FlowBoundaryConditions *fbc)
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
int ok;
|
int ok_cond, ok_face;
|
||||||
size_t alloc_sz;
|
size_t alloc_sz;
|
||||||
void *p1, *p2, *p3;
|
void *p1, *p2, *p3, *p4;
|
||||||
|
|
||||||
ok = nbc <= fbc->cpty;
|
ok_cond = nbc <= fbc->cond_cpty;
|
||||||
|
ok_face = nf <= fbc->face_cpty;
|
||||||
|
|
||||||
if (! ok) {
|
if (! ok_cond) {
|
||||||
alloc_sz = alloc_size(nbc, fbc->cpty);
|
alloc_sz = alloc_size(nbc, fbc->cond_cpty);
|
||||||
|
|
||||||
p1 = realloc(fbc->type , alloc_sz * sizeof *fbc->type );
|
p1 = realloc(fbc->type , (alloc_sz + 0) * sizeof *fbc->type );
|
||||||
p2 = realloc(fbc->value, alloc_sz * sizeof *fbc->value);
|
p2 = realloc(fbc->value , (alloc_sz + 0) * sizeof *fbc->value );
|
||||||
p3 = realloc(fbc->face , alloc_sz * sizeof *fbc->face );
|
p3 = realloc(fbc->cond_pos, (alloc_sz + 1) * sizeof *fbc->cond_pos);
|
||||||
|
|
||||||
ok = (p1 != NULL) && (p2 != NULL) && (p3 != NULL);
|
ok_cond = (p1 != NULL) && (p2 != NULL) && (p3 != NULL);
|
||||||
|
|
||||||
if (ok) {
|
if (p1 != NULL) { fbc->type = p1; }
|
||||||
fbc->type = p1;
|
if (p2 != NULL) { fbc->value = p2; }
|
||||||
fbc->value = p2;
|
if (p3 != NULL) { fbc->cond_pos = p3; }
|
||||||
fbc->face = p3;
|
|
||||||
|
|
||||||
fbc->cpty = alloc_sz;
|
if (ok_cond) {
|
||||||
} else {
|
fbc->cond_cpty = alloc_sz;
|
||||||
free(p3); free(p2); free(p1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
if (! ok_face) {
|
||||||
|
alloc_sz = alloc_size(nf, fbc->face_cpty);
|
||||||
|
|
||||||
|
p4 = realloc(fbc->face, alloc_sz * sizeof *fbc->face);
|
||||||
|
|
||||||
|
ok_face = p4 != NULL;
|
||||||
|
|
||||||
|
if (ok_face) {
|
||||||
|
fbc->face = p4;
|
||||||
|
fbc->face_cpty = alloc_sz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok_cond && ok_face;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,12 +132,14 @@ flow_conditions_construct(size_t nbc)
|
|||||||
if (fbc != NULL) {
|
if (fbc != NULL) {
|
||||||
initialise_structure(fbc);
|
initialise_structure(fbc);
|
||||||
|
|
||||||
ok = expand_tables(nbc, fbc);
|
ok = expand_tables(nbc, nbc, fbc);
|
||||||
|
|
||||||
if (! ok) {
|
if (! ok) {
|
||||||
flow_conditions_destroy(fbc);
|
flow_conditions_destroy(fbc);
|
||||||
|
|
||||||
fbc = NULL;
|
fbc = NULL;
|
||||||
|
} else {
|
||||||
|
fbc->cond_pos[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +156,10 @@ flow_conditions_destroy(struct FlowBoundaryConditions *fbc)
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
if (fbc != NULL) {
|
if (fbc != NULL) {
|
||||||
free(fbc->face );
|
free(fbc->face );
|
||||||
free(fbc->value);
|
free(fbc->cond_pos);
|
||||||
free(fbc->type );
|
free(fbc->value );
|
||||||
|
free(fbc->type );
|
||||||
}
|
}
|
||||||
|
|
||||||
free(fbc);
|
free(fbc);
|
||||||
@ -159,14 +178,38 @@ flow_conditions_append(enum FlowBCType type ,
|
|||||||
struct FlowBoundaryConditions *fbc )
|
struct FlowBoundaryConditions *fbc )
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
int ok;
|
return flow_conditions_append_multi(type, 1, &face, value, fbc);
|
||||||
|
}
|
||||||
|
|
||||||
ok = expand_tables(fbc->nbc + 1, fbc);
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
/* Append a new boundary condition that affects multiple interfaces.
|
||||||
|
*
|
||||||
|
* Return one (1) if successful, and zero (0) otherwise. */
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
int
|
||||||
|
flow_conditions_append_multi(enum FlowBCType type ,
|
||||||
|
size_t nfaces,
|
||||||
|
const int *faces ,
|
||||||
|
double value ,
|
||||||
|
struct FlowBoundaryConditions *fbc )
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
int ok;
|
||||||
|
size_t nbc;
|
||||||
|
|
||||||
|
nbc = fbc->nbc;
|
||||||
|
|
||||||
|
ok = expand_tables(nbc + 1, fbc->cond_pos[ nbc ] + nfaces, fbc);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
fbc->type [ fbc->nbc ] = type ;
|
memcpy(fbc->face + fbc->cond_pos[ nbc ],
|
||||||
fbc->value[ fbc->nbc ] = value;
|
faces, nfaces * sizeof *faces);
|
||||||
fbc->face [ fbc->nbc ] = face ;
|
|
||||||
|
fbc->type [ nbc ] = type;
|
||||||
|
fbc->value[ nbc ] = value;
|
||||||
|
|
||||||
|
fbc->cond_pos[ nbc + 1 ] = fbc->cond_pos[ nbc ] + nfaces;
|
||||||
|
|
||||||
fbc->nbc += 1;
|
fbc->nbc += 1;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,11 @@ enum FlowBCType { BC_NOFLOW ,
|
|||||||
* The field 'cpty' is for internal use by the implementation. */
|
* The field 'cpty' is for internal use by the implementation. */
|
||||||
struct FlowBoundaryConditions {
|
struct FlowBoundaryConditions {
|
||||||
size_t nbc; /* Current number of bdry. conditions */
|
size_t nbc; /* Current number of bdry. conditions */
|
||||||
size_t cpty; /* Internal management. Do not touch */
|
|
||||||
|
size_t face_cpty; /* Internal management. Do not touch */
|
||||||
|
size_t cond_cpty; /* Internal management. Do not touch */
|
||||||
|
|
||||||
|
size_t *cond_pos; /* Indirection pointer into '.face' */
|
||||||
|
|
||||||
enum FlowBCType *type; /* Condition type */
|
enum FlowBCType *type; /* Condition type */
|
||||||
double *value; /* Condition value (target) */
|
double *value; /* Condition value (target) */
|
||||||
@ -67,6 +71,16 @@ flow_conditions_append(enum FlowBCType type ,
|
|||||||
double value,
|
double value,
|
||||||
struct FlowBoundaryConditions *fbc );
|
struct FlowBoundaryConditions *fbc );
|
||||||
|
|
||||||
|
/* Append a new boundary condition that affects multiple interfaces.
|
||||||
|
*
|
||||||
|
* Return one (1) if successful, and zero (0) otherwise. */
|
||||||
|
int
|
||||||
|
flow_conditions_append_multi(enum FlowBCType type ,
|
||||||
|
size_t nfaces,
|
||||||
|
const int *faces ,
|
||||||
|
double value ,
|
||||||
|
struct FlowBoundaryConditions *fbc );
|
||||||
|
|
||||||
|
|
||||||
/* Clear existing set of boundary conditions */
|
/* Clear existing set of boundary conditions */
|
||||||
void
|
void
|
||||||
|
@ -161,7 +161,7 @@ assemble_bc_contrib(struct UnstructuredGrid *G ,
|
|||||||
int is_neumann;
|
int is_neumann;
|
||||||
int i, f, c1, c2;
|
int i, f, c1, c2;
|
||||||
|
|
||||||
size_t j;
|
size_t j, ix;
|
||||||
|
|
||||||
is_neumann = 1;
|
is_neumann = 1;
|
||||||
|
|
||||||
@ -169,17 +169,19 @@ assemble_bc_contrib(struct UnstructuredGrid *G ,
|
|||||||
if (bc->type[ i ] == BC_PRESSURE) {
|
if (bc->type[ i ] == BC_PRESSURE) {
|
||||||
is_neumann = 0;
|
is_neumann = 0;
|
||||||
|
|
||||||
f = bc->face[ i ];
|
for (j = bc->cond_pos[ i ]; j < bc->cond_pos[i + 1]; j++) {
|
||||||
c1 = G->face_cells[2*f + 0];
|
f = bc->face[ j ];
|
||||||
c2 = G->face_cells[2*f + 1];
|
c1 = G->face_cells[2*f + 0];
|
||||||
|
c2 = G->face_cells[2*f + 1];
|
||||||
|
|
||||||
assert ((c1 < 0) ^ (c2 < 0)); /* BCs on ext. faces only */
|
assert ((c1 < 0) ^ (c2 < 0)); /* BCs on ext. faces only */
|
||||||
|
|
||||||
c1 = (c1 >= 0) ? c1 : c2;
|
c1 = (c1 >= 0) ? c1 : c2;
|
||||||
j = csrmatrix_elm_index(c1, c1, h->A);
|
ix = csrmatrix_elm_index(c1, c1, h->A);
|
||||||
|
|
||||||
h->A->sa[ j ] += trans[ f ];
|
h->A->sa[ ix ] += trans[ f ];
|
||||||
h->b [ c1] += trans[ f ] * bc->value[ i ];
|
h->b [ c1 ] += trans[ f ] * bc->value[ i ];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Other types currently not handled */
|
/* Other types currently not handled */
|
||||||
|
Loading…
Reference in New Issue
Block a user