From 541813ace5f0e41c3813a76a3f3174f625731979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 15 Feb 2012 22:42:07 +0100 Subject: [PATCH] Made reordersequence a C++ source file, in order to use std::sort(). This is for the experimental change of the graph topology, putting the connections in the graph sorted by flux magnitude. Currently the changes are in the file, but commented out until further experiments have been done. --- Makefile.am | 2 +- ...{reordersequence.c => reordersequence.cpp} | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) rename opm/core/transport/reorder/{reordersequence.c => reordersequence.cpp} (82%) diff --git a/Makefile.am b/Makefile.am index 15305532..ab1a341c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,7 @@ opm/core/transport/spu_implicit.c \ opm/core/transport/transport_source.c \ opm/core/transport/reorder/TransportModelInterface.cpp \ opm/core/transport/reorder/TransportModelTwophase.cpp \ -opm/core/transport/reorder/reordersequence.c \ +opm/core/transport/reorder/reordersequence.cpp \ opm/core/transport/reorder/nlsolvers.c \ opm/core/transport/reorder/tarjan.c diff --git a/opm/core/transport/reorder/reordersequence.c b/opm/core/transport/reorder/reordersequence.cpp similarity index 82% rename from opm/core/transport/reorder/reordersequence.c rename to opm/core/transport/reorder/reordersequence.cpp index f2698e4a..6c662bd9 100644 --- a/opm/core/transport/reorder/reordersequence.c +++ b/opm/core/transport/reorder/reordersequence.cpp @@ -12,6 +12,20 @@ #include #endif +#include +#include + +struct SortByAbsFlux +{ + SortByAbsFlux(const double* flux) + : flux_(flux) + {} + bool operator() (int f1, int f2) + { + return std::fabs(flux_[f1]) < std::fabs(flux_[f2]); + } + const double* flux_; +}; /* Construct adjacency matrix of upwind graph wrt flux. Column indices are not sorted. */ @@ -64,11 +78,15 @@ make_upwind_graph(int nc, int *cellfaces, int *faceptr, int *face2cell, if ( theflux < 0) { - ja[p++] = work[f]; + // ja[p++] = f; + ja[p++] = work[f]; } } - ia[i+1] = p; + // std::sort(ja + ia[i], ja + ia[i+1], SortByAbsFlux(flux)); + // for (j = ia[i]; j < ia[i+1]; ++j) { + // ja[j] = work[ja[j]]; + // } } } @@ -84,9 +102,9 @@ compute_reorder_sequence(int nc, int nf, int *cellfaces, int *faceptr, int *face sz = 3*nc; } - work = malloc( sz * sizeof *work); - ia = malloc((nc+1) * sizeof *ia); - ja = malloc( nf * sizeof *ja); /* A bit too much... */ + work = (int*) malloc( sz * sizeof *work); + ia = (int*) malloc((nc+1) * sizeof *ia); + ja = (int*) malloc( nf * sizeof *ja); /* A bit too much... */ make_upwind_graph(nc, cellfaces, faceptr, face2cell,