From a50ee8e2d23df5b7689e31e48abc10f6c6ccaf0d Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Wed, 12 Jul 2023 16:48:21 +0100 Subject: [PATCH 1/5] BUG: electricPotential: correct return value of read function --- .../solvers/electricPotential/electricPotential.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functionObjects/solvers/electricPotential/electricPotential.C b/src/functionObjects/solvers/electricPotential/electricPotential.C index 676658d2c5..ba92586345 100644 --- a/src/functionObjects/solvers/electricPotential/electricPotential.C +++ b/src/functionObjects/solvers/electricPotential/electricPotential.C @@ -341,7 +341,7 @@ bool Foam::functionObjects::electricPotential::read(const dictionary& dict) } } - return false; + return true; } From f3d939fa10bb67a591180ca42600f0851c76b9a9 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Wed, 12 Jul 2023 16:47:54 +0100 Subject: [PATCH 2/5] ENH: electricPotential: add finite-volume constraint hook --- .../solvers/electricPotential/electricPotential.C | 8 ++++++++ .../solvers/electricPotential/electricPotential.H | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/functionObjects/solvers/electricPotential/electricPotential.C b/src/functionObjects/solvers/electricPotential/electricPotential.C index ba92586345..6a83baee67 100644 --- a/src/functionObjects/solvers/electricPotential/electricPotential.C +++ b/src/functionObjects/solvers/electricPotential/electricPotential.C @@ -217,6 +217,7 @@ Foam::functionObjects::electricPotential::electricPotential IOobject::scopedName(typeName, "E") ) ), + fvOptions_(mesh_), nCorr_(1), writeDerivedFields_(false), electricField_(false) @@ -341,6 +342,11 @@ bool Foam::functionObjects::electricPotential::read(const dictionary& dict) } } + if (const dictionary* dictptr = dict.findDict("fvOptions")) + { + fvOptions_.reset(*dictptr); + } + return true; } @@ -363,6 +369,8 @@ bool Foam::functionObjects::electricPotential::execute() eVEqn.relax(); + fvOptions_.constrain(eVEqn); + eVEqn.solve(); } diff --git a/src/functionObjects/solvers/electricPotential/electricPotential.H b/src/functionObjects/solvers/electricPotential/electricPotential.H index 027867fddc..af1b0e47fe 100644 --- a/src/functionObjects/solvers/electricPotential/electricPotential.H +++ b/src/functionObjects/solvers/electricPotential/electricPotential.H @@ -123,6 +123,7 @@ Usage V ; electricField ; E ; + fvOptions ; // Inherited entries ... @@ -141,10 +142,12 @@ Usage V | Name of electric potential field | word | no | electricPotential:V electricField | Flag to calculate electric field | bool | no | false E | Name of electric field | word | no | electricPotential:E + fvOptions | List of finite-volume options | dict | no | - \endtable The inherited entries are elaborated in: - \link functionObject.H \endlink + - \link fvOption.H \endlink Fields written out when the \c writeDerivedFields entry is \c true: \table @@ -153,6 +156,9 @@ Usage Charge density | volScalarField | \/electricPotential:rho \endtable +Note + - Only constraint-type finite-volume options can be used. + SourceFiles electricPotential.C @@ -163,6 +169,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "volFields.H" +#include "fvOptionList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -208,6 +215,9 @@ class electricPotential //- Name of electric field word Ename_; + //- Run-time selectable finite volume options + fv::optionList fvOptions_; + //- Number of corrector iterations int nCorr_; From f54400d5cc38a31a2b40c727fef68649b1e97fed Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Tue, 18 Jul 2023 09:21:02 +0100 Subject: [PATCH 3/5] ENH: cellSetOption: add new selectionMode for moving points --- src/fvOptions/cellSetOption/cellSetOption.C | 86 ++++++++++++++++++++- src/fvOptions/cellSetOption/cellSetOption.H | 21 ++++- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/src/fvOptions/cellSetOption/cellSetOption.C b/src/fvOptions/cellSetOption/cellSetOption.C index 3f0310dd4c..297f13e8b7 100644 --- a/src/fvOptions/cellSetOption/cellSetOption.C +++ b/src/fvOptions/cellSetOption/cellSetOption.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,6 +52,7 @@ Foam::fv::cellSetOption::selectionModeTypeNames_ { selectionModeType::smAll, "all" }, { selectionModeType::smGeometric, "geometric" }, { selectionModeType::smPoints, "points" }, + { selectionModeType::smMovingPoints, "movingPoints" }, { selectionModeType::smCellSet, "cellSet" }, { selectionModeType::smCellZone, "cellZone" }, { selectionModeType::smCellType, "cellType" } @@ -80,6 +81,31 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict) dict.readEntry("points", points_); break; } + case smMovingPoints: + { + const dictionary& mpsDict = dict.subDict("movingPoints"); + + movingPoints_.resize_null(mpsDict.size()); + + label pointi = 0; + for (const entry& dEntry : mpsDict) + { + const word& key = dEntry.keyword(); + + movingPoints_.set + ( + pointi, + Function1::New + ( + key, + mpsDict, + &mesh_ + ) + ); + ++pointi; + } + break; + } case smCellSet: { selectionNames_.resize(1); @@ -196,6 +222,50 @@ void Foam::fv::cellSetOption::setCellSelection() cells_ = selectedCells.sortedToc(); break; } + case smMovingPoints: + { + Info<< indent << "- selecting cells using moving points" << endl; + + const scalar t = mesh_.time().timeOutputValue(); + + labelHashSet selectedCells; + + forAll(movingPoints_, i) + { + if (!movingPoints_.set(i)) + { + continue; + } + + const point p(movingPoints_[i].value(t)); + + const label celli = mesh_.findCell(p); + + const bool found = (celli >= 0); + + // Ensure that only one processor inserts this cell + label proci = -1; + if (found) + { + proci = Pstream::myProcNo(); + } + reduce(proci, maxOp