From 5a2d26360b3609e1ac7abd89926056ffe885e4e2 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. --- ...{reordersequence.c => reordersequence.cpp} | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) rename opm/core/transport/reorder/{reordersequence.c => reordersequence.cpp} (82%) 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 f2698e4a0..6c662bd91 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,