From de66f358b0735b69110fab89989645fa35b7d12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 21 Jan 2013 11:09:07 +0100 Subject: [PATCH] Added functionAverage() method to DGBasis classes. --- opm/core/transport/reorder/DGBasis.cpp | 17 +++++++++++++++-- opm/core/transport/reorder/DGBasis.hpp | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/opm/core/transport/reorder/DGBasis.cpp b/opm/core/transport/reorder/DGBasis.cpp index 8527a1ca..93ca347b 100644 --- a/opm/core/transport/reorder/DGBasis.cpp +++ b/opm/core/transport/reorder/DGBasis.cpp @@ -154,6 +154,12 @@ namespace Opm } } + /// Compute the average of the function f = sum_i c_i b_i. + /// \param[in] coefficients Coefficients {c_i} for a single cell. + double DGBasisBoundedTotalDegree::functionAverage(const double* coefficients) const + { + return coefficients[0]; + } @@ -300,11 +306,18 @@ namespace Opm double* coefficients) const { const int nb = numBasisFunc(); - const double average = std::accumulate(coefficients, coefficients + nb, 0.0)/double(nb); + const double aver = functionAverage(coefficients); for (int ix = 0; ix < nb; ++ix) { - coefficients[ix] = factor*(coefficients[ix] - average) + average; + coefficients[ix] = factor*(coefficients[ix] - aver) + aver; } } + /// Compute the average of the function f = sum_i c_i b_i. + /// \param[in] coefficients Coefficients {c_i} for a single cell. + double DGBasisMultilin::functionAverage(const double* coefficients) const + { + const int nb = numBasisFunc(); + return std::accumulate(coefficients, coefficients + nb, 0.0)/double(nb); + } } // namespace Opm diff --git a/opm/core/transport/reorder/DGBasis.hpp b/opm/core/transport/reorder/DGBasis.hpp index a7410814..596fefbd 100644 --- a/opm/core/transport/reorder/DGBasis.hpp +++ b/opm/core/transport/reorder/DGBasis.hpp @@ -75,6 +75,10 @@ namespace Opm /// \param[out] coefficients Coefficients {c_i} for a single cell. virtual void multiplyGradient(const double factor, double* coefficients) const = 0; + + /// Compute the average of the function f = sum_i c_i b_i. + /// \param[in] coefficients Coefficients {c_i} for a single cell. + virtual double functionAverage(const double* coefficients) const = 0; }; @@ -144,6 +148,10 @@ namespace Opm virtual void multiplyGradient(const double factor, double* coefficients) const; + /// Compute the average of the function f = sum_i c_i b_i. + /// \param[in] coefficients Coefficients {c_i} for a single cell. + virtual double functionAverage(const double* coefficients) const; + private: const UnstructuredGrid& grid_; const int degree_; @@ -217,6 +225,10 @@ namespace Opm virtual void multiplyGradient(const double factor, double* coefficients) const; + /// Compute the average of the function f = sum_i c_i b_i. + /// \param[in] coefficients Coefficients {c_i} for a single cell. + virtual double functionAverage(const double* coefficients) const; + private: const UnstructuredGrid& grid_; const int degree_;