From 5c226864a8b1d05b286cb27f5a0f7c3c648ee257 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 10 Jan 2019 09:56:12 +0100 Subject: [PATCH] ENH: add clip() method to GeometricField --- .../multiphaseSystem/multiphaseSystem.C | 2 +- .../twoPhaseSystem/twoPhaseSystem.C | 2 +- .../GeometricField/GeometricField.C | 42 ++++++++++++++----- .../GeometricField/GeometricField.H | 20 +++++++-- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C index 95b301284c7..be6d03ea886 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C +++ b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C @@ -692,7 +692,7 @@ void Foam::multiphaseSystem::solve() phase.alphaRhoPhi() = fvc::interpolate(phase.rho())*phase.alphaPhi(); // Ensure the phase-fractions are bounded - phase.maxMin(0, 1); + phase.clip(0, 1); } calcAlphas(); diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C index 07c640f8958..60b7adf9e2f 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C +++ b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C @@ -403,7 +403,7 @@ void Foam::twoPhaseSystem::solve() << endl; // Ensure the phase-fractions are bounded - alpha1.maxMin(0, 1); + alpha1.clip(0, 1); // Update the phase-fraction of the other phase alpha2 = scalar(1) - alpha1; diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 82a5482d60f..28049136c7d 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -1095,6 +1095,17 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::replace } +template<class Type, template<class> class PatchField, class GeoMesh> +void Foam::GeometricField<Type, PatchField, GeoMesh>::min +( + const dimensioned<Type>& dt +) +{ + Foam::min(primitiveFieldRef(), primitiveField(), dt.value()); + Foam::min(boundaryFieldRef(), boundaryField(), dt.value()); +} + + template<class Type, template<class> class PatchField, class GeoMesh> void Foam::GeometricField<Type, PatchField, GeoMesh>::max ( @@ -1107,27 +1118,38 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::max template<class Type, template<class> class PatchField, class GeoMesh> -void Foam::GeometricField<Type, PatchField, GeoMesh>::min +void Foam::GeometricField<Type, PatchField, GeoMesh>::clip ( - const dimensioned<Type>& dt + const dimensioned<MinMax<Type>>& range ) { - Foam::min(primitiveFieldRef(), primitiveField(), dt.value()); - Foam::min(boundaryFieldRef(), boundaryField(), dt.value()); + Foam::clip(primitiveFieldRef(), primitiveField(), range.value()); + Foam::clip(boundaryFieldRef(), boundaryField(), range.value()); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +void Foam::GeometricField<Type, PatchField, GeoMesh>::clip +( + const dimensioned<Type>& minVal, + const dimensioned<Type>& maxVal +) +{ + MinMax<Type> range(minVal.value(), maxVal.value()); + + Foam::clip(primitiveFieldRef(), primitiveField(), range); + Foam::clip(boundaryFieldRef(), boundaryField(), range); } template<class Type, template<class> class PatchField, class GeoMesh> void Foam::GeometricField<Type, PatchField, GeoMesh>::maxMin ( - const dimensioned<Type>& minDt, - const dimensioned<Type>& maxDt + const dimensioned<Type>& minVal, + const dimensioned<Type>& maxVal ) { - Foam::max(primitiveFieldRef(), primitiveField(), minDt.value()); - Foam::max(boundaryFieldRef(), boundaryField(), minDt.value()); - Foam::min(primitiveFieldRef(), primitiveField(), maxDt.value()); - Foam::min(boundaryFieldRef(), boundaryField(), maxDt.value()); + this->clip(minVal, maxVal); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 5226c1c4f95..039b7e41a42 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -598,12 +598,24 @@ public: // This sets the \em floor on the field values void max(const dimensioned<Type>& dt); - void maxMin + //- Clip the field to be bounded within the specified range + void clip(const dimensioned<MinMax<Type>>& range); + + //- Clip the field to be bounded within the specified range + void clip ( - const dimensioned<Type>& minDt, - const dimensioned<Type>& maxDt + const dimensioned<Type>& minVal, + const dimensioned<Type>& maxVal ); + //- Deprecated(2019-01) identical to clip() + // \deprecated(2019-01) identical to clip() + void maxMin + ( + const dimensioned<Type>& minVal, + const dimensioned<Type>& maxVal + ) FOAM_DEPRECATED_FOR(2019-01, "clip() method"); + // Member Operators -- GitLab