diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.C b/src/OpenFOAM/dimensionSet/dimensionSet.C
index 584889e3c1..4dddfb7a69 100644
--- a/src/OpenFOAM/dimensionSet/dimensionSet.C
+++ b/src/OpenFOAM/dimensionSet/dimensionSet.C
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
- Copyright (C) 2017-2021 OpenCFD Ltd.
+ Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -518,6 +518,21 @@ Foam::dimensionSet Foam::hypot(const dimensionSet& ds1, const dimensionSet& ds2)
}
+Foam::dimensionSet Foam::stabilise
+(
+ const dimensionSet& ds1,
+ const dimensionSet& ds2
+)
+{
+ if (dimensionSet::checking())
+ {
+ checkDims("stabilise(a, b)", ds1, ds2);
+ }
+
+ return ds1;
+}
+
+
Foam::dimensionSet Foam::transform(const dimensionSet& ds)
{
return ds;
diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.H b/src/OpenFOAM/dimensionSet/dimensionSet.H
index 10d91eef57..d64d343668 100644
--- a/src/OpenFOAM/dimensionSet/dimensionSet.H
+++ b/src/OpenFOAM/dimensionSet/dimensionSet.H
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
- Copyright (C) 2017-2021 OpenCFD Ltd.
+ Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -397,6 +397,9 @@ dimensionSet atan2(const dimensionSet& ds1, const dimensionSet& ds2);
//- Arguments need the same dimensions. Does not change the dimension.
dimensionSet hypot(const dimensionSet& ds1, const dimensionSet& ds2);
+//- Arguments need the same dimensions. Does not change the dimension.
+dimensionSet stabilise(const dimensionSet& ds1, const dimensionSet& ds2);
+
//- Return the argument; transformations do not change the dimensions
dimensionSet transform(const dimensionSet& ds);
diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C
index b592d6aea1..2dbe387c51 100644
--- a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C
+++ b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.C
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
- Copyright (C) 2019 OpenCFD Ltd.
+ Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -338,6 +338,21 @@ dimensionedScalar hypot
}
+dimensionedScalar stabilise
+(
+ const dimensionedScalar& x,
+ const dimensionedScalar& y
+)
+{
+ return dimensionedScalar
+ (
+ "stabilise(" + x.name() + ',' + y.name() + ')',
+ stabilise(x.dimensions(), y.dimensions()),
+ stabilise(x.value(), y.value())
+ );
+}
+
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H
index 94b7648796..820374df8e 100644
--- a/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H
+++ b/src/OpenFOAM/dimensionedTypes/dimensionedScalar/dimensionedScalar.H
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
- Copyright (C) 2019 OpenCFD Ltd.
+ Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -102,6 +102,7 @@ dimensionedScalar jn(const int, const dimensionedScalar&);
dimensionedScalar y0(const dimensionedScalar&);
dimensionedScalar y1(const dimensionedScalar&);
dimensionedScalar yn(const int, const dimensionedScalar&);
+dimensionedScalar stabilise(const dimensionedScalar&, const dimensionedScalar&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files
index c285367b66..59fabd85cd 100644
--- a/src/functionObjects/field/Make/files
+++ b/src/functionObjects/field/Make/files
@@ -84,6 +84,7 @@ Curle/Curle.C
reference/reference.C
log/log.C
pow/pow.C
+norm/norm.C
fieldsExpression/fieldsExpression.C
add/add.C
diff --git a/src/functionObjects/field/norm/norm.C b/src/functionObjects/field/norm/norm.C
new file mode 100644
index 0000000000..af0b208ce0
--- /dev/null
+++ b/src/functionObjects/field/norm/norm.C
@@ -0,0 +1,142 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | www.openfoam.com
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+ Copyright (C) 2022 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 "norm.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace functionObjects
+{
+ defineTypeNameAndDebug(norm, 0);
+ addToRunTimeSelectionTable(functionObject, norm, dictionary);
+}
+}
+
+
+const Foam::Enum
+<
+ Foam::functionObjects::norm::normType
+>
+Foam::functionObjects::norm::normTypeNames
+({
+ { normType::L1 , "L1" },
+ { normType::L2 , "L2" },
+ { normType::LP , "Lp" },
+ { normType::MAX , "max" },
+ { normType::COMPOSITE , "composite" },
+ { normType::FIELD , "divisorField" }
+});
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// Implementation
+#include "normImpl.C"
+
+
+// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
+
+bool Foam::functionObjects::norm::calc()
+{
+ return
+ (
+ calcNorm()
+ || calcNorm()
+ || calcNorm()
+ || calcNorm()
+ || calcNorm()
+ );
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+Foam::functionObjects::norm::norm
+(
+ const word& name,
+ const Time& runTime,
+ const dictionary& dict
+)
+:
+ fieldExpression(name, runTime, dict),
+ norm_(normType::L1),
+ divisorPtr_(nullptr),
+ divisorFieldName_(word::null),
+ p_(-1)
+{
+ read(dict);
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+bool Foam::functionObjects::norm::read(const dictionary& dict)
+{
+ if (!fieldExpression::read(dict))
+ {
+ return false;
+ }
+
+ norm_ = normTypeNames.get("norm", dict);
+
+ if (norm_ == normType::LP)
+ {
+ p_ = dict.getCheck("p", scalarMinMax::ge(1));
+ }
+
+ if (norm_ == normType::COMPOSITE)
+ {
+ divisorPtr_ = Function1::New("divisor", dict, &mesh_);
+
+ if (!divisorPtr_)
+ {
+ FatalIOErrorInFunction(dict)
+ << "The norm 'composite' needs the input entry 'divisor'."
+ << abort(FatalIOError);
+ }
+ }
+
+ if (norm_ == normType::FIELD)
+ {
+ divisorFieldName_ = dict.get("divisorField");
+
+ if (divisorFieldName_ == word::null)
+ {
+ FatalIOErrorInFunction(dict)
+ << "The norm 'field' needs the input entry 'divisorField'."
+ << abort(FatalIOError);
+ }
+ }
+
+ return true;
+}
+
+
+// ************************************************************************* //
diff --git a/src/functionObjects/field/norm/norm.H b/src/functionObjects/field/norm/norm.H
new file mode 100644
index 0000000000..540a24d332
--- /dev/null
+++ b/src/functionObjects/field/norm/norm.H
@@ -0,0 +1,285 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | www.openfoam.com
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+ Copyright (C) 2022 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 .
+
+Class
+ Foam::functionObjects::norm
+
+Group
+ grpFieldFunctionObjects
+
+Description
+ Normalises an input field with a chosen norm,
+ and outputs a new normalised field.
+
+ Operands:
+ \table
+ Operand | Type | Location
+ input | {vol,surface,polySurface}\Field | \/\