From f4de5d17e498f32dd4ebdc00cb5d27b8510b6839 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Wed, 25 Nov 2015 17:05:13 +0000 Subject: [PATCH] ENH: fvcCellReduce - allow setting of initial value, and loop over surface field boundaries --- .../finiteVolume/fvc/fvcCellReduce.C | 40 +++++++++++++------ .../finiteVolume/fvc/fvcCellReduce.H | 8 ++-- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.C b/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.C index 63c718375b..7d8294b1e6 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,7 +45,8 @@ template tmp > cellReduce ( const GeometricField& ssf, - const CombineOp& cop + const CombineOp& cop, + const Type& nullValue ) { typedef GeometricField volFieldType; @@ -65,7 +66,7 @@ tmp > cellReduce IOobject::NO_WRITE ), mesh, - dimensioned("0", ssf.dimensions(), pTraits::zero), + dimensioned("initialValue", ssf.dimensions(), nullValue), zeroGradientFvPatchField::typeName ) ); @@ -75,15 +76,29 @@ tmp > cellReduce const labelUList& own = mesh.owner(); const labelUList& nbr = mesh.neighbour(); - forAll(own, i) + // Internal field + const Field& iField = ssf.internalField(); + forAll(iField, faceI) { - label cellI = own[i]; - cop(result[cellI], ssf[i]); + label cellOwn = own[faceI]; + cop(result[cellOwn], iField[faceI]); + + label cellNbr = nbr[faceI]; + cop(result[cellNbr], iField[faceI]); } - forAll(nbr, i) + + // Boundary field + forAll(ssf.boundaryField(), patchI) { - label cellI = nbr[i]; - cop(result[cellI], ssf[i]); + const fvsPatchField& pf = ssf.boundaryField()[patchI]; + const label start = pf.patch().start(); + + forAll(pf, i) + { + label faceI = start + i; + label cellI = own[faceI]; + cop(result[cellI], pf[i]); + } } result.correctBoundaryConditions(); @@ -96,13 +111,14 @@ template tmp > cellReduce ( const tmp&> tssf, - const CombineOp& cop + const CombineOp& cop, + const Type& nullValue ) { tmp > - tvf(cellReduce(cop, tssf)); + tvf(cellReduce(cop, tssf, nullValue)); - tssf.clear(); + tssf.clear(); return tvf; } diff --git a/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.H b/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.H index 19bd24135a..d355fd4a51 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.H +++ b/src/finiteVolume/finiteVolume/fvc/fvcCellReduce.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,14 +53,16 @@ namespace fvc tmp > cellReduce ( const GeometricField&, - const CombineOp& cop + const CombineOp& cop, + const Type& nullValue = pTraits::zero ); template tmp > cellReduce ( const tmp >&, - const CombineOp& cop + const CombineOp& cop, + const Type& nullValue = pTraits::zero ); }