From 881eeb0214657219d5274a3e2f807b01bfb43334 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Thu, 15 Apr 2021 11:24:23 +0100 Subject: [PATCH 1/4] TUT: atmFlatTerrain: fix atmAmbientTurbSource value (#2031) --- .../atmFlatTerrain/precursor/constant/fvOptions.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/verificationAndValidation/atmosphericModels/atmFlatTerrain/precursor/constant/fvOptions.template b/tutorials/verificationAndValidation/atmosphericModels/atmFlatTerrain/precursor/constant/fvOptions.template index 70aeaf68dd..b3042a2817 100644 --- a/tutorials/verificationAndValidation/atmosphericModels/atmFlatTerrain/precursor/constant/fvOptions.template +++ b/tutorials/verificationAndValidation/atmosphericModels/atmFlatTerrain/precursor/constant/fvOptions.template @@ -43,7 +43,7 @@ atmAmbientTurbSource1 atmAmbientTurbSourceCoeffs { selectionMode all; - kAmb 0.001; + kAmb 1.0e-04; epsilonAmb 7.208e-08; } } From 8bfab7aa80b818b0188b6e4d7d039db0921578a9 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Mon, 12 Apr 2021 11:59:45 +0100 Subject: [PATCH 2/4] ENH: QRMatrix: improve stability in pinv --- src/OpenFOAM/matrices/QRMatrix/QRMatrix.C | 53 +++++++++++++++++------ src/OpenFOAM/matrices/QRMatrix/QRMatrix.H | 2 +- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C index fa9f6833af..0b63f2017b 100644 --- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C +++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -492,9 +492,10 @@ template MatrixType Foam::pinv ( const MatrixType& A, - const scalar tol + const scalar tolerance ) { + scalar tol = tolerance; typedef typename MatrixType::cmptType cmptType; if (A.empty()) @@ -506,7 +507,12 @@ MatrixType Foam::pinv if (A.size() == 1) { - return MatrixType({1, 1}, cmptType(1.0)/(A(0,0) + cmptType(VSMALL))); + if (A(0,0) == cmptType(0)) + { + return MatrixType({1, 1}, cmptType(0)); + } + + return MatrixType({1, 1}, cmptType(1)/(A(0,0) + cmptType(VSMALL))); } QRMatrix QRM @@ -521,27 +527,47 @@ MatrixType Foam::pinv // R1 (KP:p. 648) // Find the first diagonal element index with (almost) zero value in R label firstZeroElemi = 0; + label i = 0; + while (i < 2) { const List diag(R.diag()); - auto lessT = [&](const cmptType& x) { return mag(x) < tol; }; + auto lessThan = [=](const cmptType& x) { return tol > mag(x); }; firstZeroElemi = std::distance ( diag.cbegin(), - std::find_if(diag.cbegin(), diag.cend(), lessT) + std::find_if(diag.cbegin(), diag.cend(), lessThan) ); - } - if (firstZeroElemi == 0) - { - WarningInFunction - << "The largest (magnitude) diagonal element is (almost) zero." - << nl << "Returning a zero matrix." - << endl; + if (firstZeroElemi == 0) + { + if (i == 0) + { + WarningInFunction + << "The largest diagonal element magnitude is nearly zero. " + << "Tightening the tolerance." + << endl; - return MatrixType(A.sizes(), Zero); + tol = 1e-13; + ++i; + } + else + { + WarningInFunction + << "The largest diagonal element magnitude is nearly zero. " + << "Returning a zero matrix." + << endl; + ++i; + + return MatrixType({A.n(), A.m()}, Zero); + } + } + else + { + i += 2; + } } // Exclude the first (almost) zero diagonal row and the rows below @@ -599,4 +625,5 @@ MatrixType Foam::pinv } } + // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H index 415fbba853..ee9bd62edf 100644 --- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H +++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. From 2a8e1c08653b5698de28404996a3e958fc409d2e Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Mon, 12 Apr 2021 12:00:47 +0100 Subject: [PATCH 3/4] ENH: DMD: refactor dynamic mode decomposition FO ENH: DMD: enable operations on patch fields ENH: DMD: enable postProcess utility --- src/functionObjects/field/DMD/DMD.C | 234 +++ src/functionObjects/field/DMD/DMD.H | 278 ++++ .../field/DMD/DMDModels/DMDModel/DMDModel.C | 78 + .../field/DMD/DMDModels/DMDModel/DMDModel.H | 203 +++ .../DMD/DMDModels/DMDModel/DMDModelNew.C | 58 + .../DMDModels/DMDModel/DMDModelTemplates.C | 54 + .../field/DMD/DMDModels/derived/STDMD/STDMD.C | 988 +++++++++++++ .../field/DMD/DMDModels/derived/STDMD/STDMD.H | 530 +++++++ .../DMDModels/derived/STDMD/STDMDTemplates.C | 236 +++ .../STDMDTemplates.C => DMD/DMDTemplates.C} | 161 +-- src/functionObjects/field/Make/files | 5 +- src/functionObjects/field/Make/options | 2 + src/functionObjects/field/STDMD/STDMD.C | 1280 ----------------- src/functionObjects/field/STDMD/STDMD.H | 645 --------- 14 files changed, 2731 insertions(+), 2021 deletions(-) create mode 100644 src/functionObjects/field/DMD/DMD.C create mode 100644 src/functionObjects/field/DMD/DMD.H create mode 100644 src/functionObjects/field/DMD/DMDModels/DMDModel/DMDModel.C create mode 100644 src/functionObjects/field/DMD/DMDModels/DMDModel/DMDModel.H create mode 100644 src/functionObjects/field/DMD/DMDModels/DMDModel/DMDModelNew.C create mode 100644 src/functionObjects/field/DMD/DMDModels/DMDModel/DMDModelTemplates.C create mode 100644 src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.C create mode 100644 src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.H create mode 100644 src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMDTemplates.C rename src/functionObjects/field/{STDMD/STDMDTemplates.C => DMD/DMDTemplates.C} (51%) delete mode 100644 src/functionObjects/field/STDMD/STDMD.C delete mode 100644 src/functionObjects/field/STDMD/STDMD.H diff --git a/src/functionObjects/field/DMD/DMD.C b/src/functionObjects/field/DMD/DMD.C new file mode 100644 index 0000000000..e225d31cb4 --- /dev/null +++ b/src/functionObjects/field/DMD/DMD.C @@ -0,0 +1,234 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020-2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "DMD.H" +#include "DMDModel.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(DMD, 0); + addToRunTimeSelectionTable(functionObject, DMD, dictionary); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::DMD::snapshot() +{ + bool processed = false; + processed = processed || getSnapshot(); + processed = processed || getSnapshot(); + processed = processed || getSnapshot(); + processed = processed || getSnapshot(); + processed = processed || getSnapshot(); + + if (!processed) + { + FatalErrorInFunction + << " functionObjects::" << type() << " " << name() << ":" + << " cannot find required input field during snapshot loading: " + << fieldName_ << nl + << " Do you execute required functionObjects" + << " before executing DMD, e.g. mapFields?" + << exit(FatalError); + } +} + + +void Foam::functionObjects::DMD::initialise() +{ + const label nComps = DMDModelPtr_->nComponents(fieldName_); + + if (patch_.empty()) + { + nSnap_ = nComps*mesh_.nCells(); + } + else + { + const label patchi = mesh_.boundaryMesh().findPatchID(patch_); + + if (patchi < 0) + { + FatalErrorInFunction + << "Cannot find patch " << patch_ + << exit(FatalError); + } + + nSnap_ = nComps*(mesh_.C().boundaryField()[patchi]).size(); + } + + const label nSnapTotal = returnReduce(nSnap_, sumOp