diff --git a/applications/utilities/postProcessing/field/components/Make/files b/applications/utilities/postProcessing/field/components/Make/files
deleted file mode 100644
index 1f61233dd1a57142df0560e3216fcc8a0c7ad2c4..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/components/Make/files
+++ /dev/null
@@ -1,3 +0,0 @@
-components.C
-
-EXE = $(FOAM_APPBIN)/components
diff --git a/applications/utilities/postProcessing/field/components/Make/options b/applications/utilities/postProcessing/field/components/Make/options
deleted file mode 100644
index be7f7d631d3092c6fdffcb40349c53ba1fff4db8..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/components/Make/options
+++ /dev/null
@@ -1,6 +0,0 @@
-EXE_INC = \
-    -I$(LIB_SRC)/finiteVolume/lnInclude
-
-EXE_LIBS = \
-    -lfiniteVolume \
-   
diff --git a/applications/utilities/postProcessing/field/components/components.C b/applications/utilities/postProcessing/field/components/components.C
deleted file mode 100644
index 895704474ab53477629f75c77b6aa93f59de80d8..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/components/components.C
+++ /dev/null
@@ -1,113 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-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 2 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, write to the Free Software Foundation,
-    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-Application
-    components
-
-Description
-    Writes scalar fields corresponding to each component of the supplied
-    field (name) for each time.
-
-\*---------------------------------------------------------------------------*/
-
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-#include "writeComponentFields.C"
-
-int main(int argc, char *argv[])
-{
-    timeSelector::addOptions();
-    argList::validArgs.append("fieldName1 .. fieldNameN"); // abuse for usage
-
-    // setRootCase, but skip args check
-    argList args(argc, argv, false);
-    if (!args.checkRootCase())
-    {
-        Foam::FatalError.exit();
-    }
-
-    const stringList& params = args.additionalArgs();
-    if (!params.size())
-    {
-        Info<< nl << "must specify one or more fields" << nl;
-        args.printUsage();
-        FatalError.exit();
-    }
-
-#   include "createTime.H"
-    instantList timeDirs = timeSelector::select0(runTime, args);
-#   include "createMesh.H"
-
-    forAll(timeDirs, timeI)
-    {
-        runTime.setTime(timeDirs[timeI], timeI);
-        Info<< "Time = " << runTime.timeName() << endl;
-        mesh.readUpdate();
-
-        forAll(params, paramI)
-        {
-            const word fieldName(params[paramI]);
-
-            IOobject fieldHeader
-            (
-                fieldName,
-                runTime.timeName(),
-                mesh,
-                IOobject::MUST_READ
-            );
-
-            // Check field exists
-            if (fieldHeader.headerOk())
-            {
-                bool processed = false;
-
-                writeComponentFields<vector>(fieldHeader, mesh, processed);
-                writeComponentFields<sphericalTensor>
-                (
-                    fieldHeader,
-                    mesh,
-                    processed
-                );
-
-                if (!processed)
-                {
-                    FatalError
-                        << "Unable to process " << fieldName << nl
-                        << "No call to components for fields of type "
-                        << fieldHeader.headerClassName() << nl << nl
-                        << exit(FatalError);
-                }
-            }
-            else
-            {
-                Info<< "    No " << fieldName << endl;
-            }
-        }
-    }
-
-    return 0;
-}
-
-// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/mag/Make/files b/applications/utilities/postProcessing/field/mag/Make/files
deleted file mode 100644
index a661e8243e9413d72108a930853370f5cd2f3fad..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/mag/Make/files
+++ /dev/null
@@ -1,3 +0,0 @@
-mag.C
-
-EXE = $(FOAM_APPBIN)/mag
diff --git a/applications/utilities/postProcessing/field/mag/Make/options b/applications/utilities/postProcessing/field/mag/Make/options
deleted file mode 100644
index be7f7d631d3092c6fdffcb40349c53ba1fff4db8..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/mag/Make/options
+++ /dev/null
@@ -1,6 +0,0 @@
-EXE_INC = \
-    -I$(LIB_SRC)/finiteVolume/lnInclude
-
-EXE_LIBS = \
-    -lfiniteVolume \
-   
diff --git a/applications/utilities/postProcessing/field/mag/mag.C b/applications/utilities/postProcessing/field/mag/mag.C
deleted file mode 100644
index 4c72866e76a7706fae3dade0f2fe6082e0f48c5a..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/mag/mag.C
+++ /dev/null
@@ -1,110 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-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 2 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, write to the Free Software Foundation,
-    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-Application
-    mag
-
-Description
-    Calculates and writes the magnitude of a field for each time
-
-\*---------------------------------------------------------------------------*/
-
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-#include "writeMagField.C"
-
-int main(int argc, char *argv[])
-{
-    timeSelector::addOptions();
-    argList::validArgs.append("fieldName1 .. fieldNameN"); // abuse for usage
-
-    // setRootCase, but skip args check
-    argList args(argc, argv, false);
-    if (!args.checkRootCase())
-    {
-        Foam::FatalError.exit();
-    }
-
-    const stringList& params = args.additionalArgs();
-    if (!params.size())
-    {
-        Info<< nl << "must specify one or more fields" << nl;
-        args.printUsage();
-        FatalError.exit();
-    }
-
-#   include "createTime.H"
-    instantList timeDirs = timeSelector::select0(runTime, args);
-#   include "createMesh.H"
-
-    forAll(timeDirs, timeI)
-    {
-        runTime.setTime(timeDirs[timeI], timeI);
-        Info<< "Time = " << runTime.timeName() << endl;
-        mesh.readUpdate();
-
-        forAll(params, paramI)
-        {
-            const word fieldName(params[paramI]);
-
-            IOobject fieldHeader
-            (
-                fieldName,
-                runTime.timeName(),
-                mesh,
-                IOobject::MUST_READ
-            );
-
-            // Check field exists
-            if (fieldHeader.headerOk())
-            {
-                bool processed = false;
-
-                writeMagField<scalar>(fieldHeader, mesh, processed);
-                writeMagField<vector>(fieldHeader, mesh, processed);
-                writeMagField<sphericalTensor>(fieldHeader, mesh, processed);
-                writeMagField<symmTensor>(fieldHeader, mesh, processed);
-                writeMagField<tensor>(fieldHeader, mesh, processed);
-
-                if (!processed)
-                {
-                    FatalError
-                        << "Unable to process " << fieldName << nl
-                        << "No call to mag for fields of type "
-                        << fieldHeader.headerClassName() << nl << nl
-                        << exit(FatalError);
-                }
-            }
-            else
-            {
-                Info<< "    No " << fieldName << endl;
-            }
-        }
-    }
-
-    return 0;
-}
-
-// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/magGrad/FoamX/magGradU.cfg b/applications/utilities/postProcessing/field/magGrad/FoamX/magGradU.cfg
deleted file mode 100644
index bc1556cde32c3446296eb0f69bb827b5bf0a5d7e..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magGrad/FoamX/magGradU.cfg
+++ /dev/null
@@ -1,27 +0,0 @@
-/*---------------------------------------------------------------------------*\
-| =========                 |                                                 |
-| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  1.0                                   |
-|   \\  /    A nd           | Web:      http://www.openfoam.org               |
-|    \\/     M anipulation  |                                                 |
-\*---------------------------------------------------------------------------*/
-// magGradU tool definition
-
-description     "Magnitude of grad(U) calculation";
-
-magGradUDict
-{
-    type            dictionary;
-    description     "magGradU control dictionary";
-    dictionaryPath  "system";
-
-    entries
-    {
-        arguments
-        {
-            type        rootCaseTimeArguments;
-        }
-    }
-}
-
-// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/magGrad/Make/files b/applications/utilities/postProcessing/field/magGrad/Make/files
deleted file mode 100644
index 7e6229f15058457109fc673445005406ae3340ba..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magGrad/Make/files
+++ /dev/null
@@ -1,3 +0,0 @@
-magGrad.C
-
-EXE = $(FOAM_APPBIN)/magGrad
diff --git a/applications/utilities/postProcessing/field/magGrad/Make/options b/applications/utilities/postProcessing/field/magGrad/Make/options
deleted file mode 100644
index be7f7d631d3092c6fdffcb40349c53ba1fff4db8..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magGrad/Make/options
+++ /dev/null
@@ -1,6 +0,0 @@
-EXE_INC = \
-    -I$(LIB_SRC)/finiteVolume/lnInclude
-
-EXE_LIBS = \
-    -lfiniteVolume \
-   
diff --git a/applications/utilities/postProcessing/field/magGrad/magGrad.C b/applications/utilities/postProcessing/field/magGrad/magGrad.C
deleted file mode 100644
index 6297203e64205ce27f8ffe4729f3cc3f7159ccde..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magGrad/magGrad.C
+++ /dev/null
@@ -1,108 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-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 2 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, write to the Free Software Foundation,
-    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-Application
-    magGrad
-
-Description
-    Calculates and writes the magnitude of the gradient of a field for each
-    time
-
-\*---------------------------------------------------------------------------*/
-
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-#include "writeMagGradField.C"
-
-int main(int argc, char *argv[])
-{
-    timeSelector::addOptions();
-    argList::validArgs.append("fieldName1 .. fieldNameN"); // abuse for usage
-
-    // setRootCase, but skip args check
-    argList args(argc, argv, false);
-    if (!args.checkRootCase())
-    {
-        Foam::FatalError.exit();
-    }
-
-    const stringList& params = args.additionalArgs();
-    if (!params.size())
-    {
-        Info<< nl << "must specify one or more fields" << nl;
-        args.printUsage();
-        FatalError.exit();
-    }
-
-#   include "createTime.H"
-    instantList timeDirs = timeSelector::select0(runTime, args);
-#   include "createMesh.H"
-
-    forAll(timeDirs, timeI)
-    {
-        runTime.setTime(timeDirs[timeI], timeI);
-        Info<< "Time = " << runTime.timeName() << endl;
-        mesh.readUpdate();
-
-        forAll(params, paramI)
-        {
-            const word fieldName(params[paramI]);
-
-            IOobject fieldHeader
-            (
-                fieldName,
-                runTime.timeName(),
-                mesh,
-                IOobject::MUST_READ
-            );
-
-            // Check field exists
-            if (fieldHeader.headerOk())
-            {
-                bool processed = false;
-
-                writeMagGradField<scalar>(fieldHeader, mesh, processed);
-                writeMagGradField<vector>(fieldHeader, mesh, processed);
-
-                if (!processed)
-                {
-                    FatalError
-                        << "Unable to process " << fieldName << nl
-                        << "No call to magGrad for fields of type "
-                        << fieldHeader.headerClassName() << nl << nl
-                        << exit(FatalError);
-                }
-            }
-            else
-            {
-                Info<< "    No " << fieldName << endl;
-            }
-        }
-    }
-
-    return 0;
-}
-
-// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/magSqr/Make/files b/applications/utilities/postProcessing/field/magSqr/Make/files
deleted file mode 100644
index 7f7b96ef99983c1f5b2b5fcf6cc529d2c21f5aac..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magSqr/Make/files
+++ /dev/null
@@ -1,3 +0,0 @@
-magSqr.C
-
-EXE = $(FOAM_APPBIN)/magSqr
diff --git a/applications/utilities/postProcessing/field/magSqr/magSqr.C b/applications/utilities/postProcessing/field/magSqr/magSqr.C
deleted file mode 100644
index f352f425da41b2a5152408b0799ae7260e6da4bf..0000000000000000000000000000000000000000
--- a/applications/utilities/postProcessing/field/magSqr/magSqr.C
+++ /dev/null
@@ -1,110 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-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 2 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, write to the Free Software Foundation,
-    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-Application
-    magSqr
-
-Description
-    Calculates and writes the magnitude-squared of a field for each time
-
-\*---------------------------------------------------------------------------*/
-
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-#include "writeMagSqrField.C"
-
-int main(int argc, char *argv[])
-{
-    timeSelector::addOptions();
-    argList::validArgs.append("fieldName1 .. fieldNameN"); // abuse for usage
-
-    // setRootCase, but skip args check
-    argList args(argc, argv, false);
-    if (!args.checkRootCase())
-    {
-        Foam::FatalError.exit();
-    }
-
-    const stringList& params = args.additionalArgs();
-    if (!params.size())
-    {
-        Info<< nl << "must specify one or more fields" << nl;
-        args.printUsage();
-        FatalError.exit();
-    }
-
-#   include "createTime.H"
-    instantList timeDirs = timeSelector::select0(runTime, args);
-#   include "createMesh.H"
-
-    forAll(timeDirs, timeI)
-    {
-        runTime.setTime(timeDirs[timeI], timeI);
-        Info<< "Time = " << runTime.timeName() << endl;
-        mesh.readUpdate();
-
-        forAll(params, paramI)
-        {
-            const word fieldName(params[paramI]);
-
-            IOobject fieldHeader
-            (
-                fieldName,
-                runTime.timeName(),
-                mesh,
-                IOobject::MUST_READ
-            );
-
-            // Check field exists
-            if (fieldHeader.headerOk())
-            {
-                bool processed = false;
-
-                writeMagSqrField<scalar>(fieldHeader, mesh, processed);
-                writeMagSqrField<vector>(fieldHeader, mesh, processed);
-                writeMagSqrField<sphericalTensor>(fieldHeader, mesh, processed);
-                writeMagSqrField<symmTensor>(fieldHeader, mesh, processed);
-                writeMagSqrField<tensor>(fieldHeader, mesh, processed);
-
-                if (!processed)
-                {
-                    FatalError
-                        << "Unable to process " << fieldName << nl
-                        << "No call to mag for fields of type "
-                        << fieldHeader.headerClassName() << nl << nl
-                        << exit(FatalError);
-                }
-            }
-            else
-            {
-                Info<< "    No " << fieldName << endl;
-            }
-        }
-    }
-
-    return 0;
-}
-
-// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/foamCalc/Make/files b/applications/utilities/postProcessing/foamCalc/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..a2d961e851352bb17af0ad0c09b577aad152e7e3
--- /dev/null
+++ b/applications/utilities/postProcessing/foamCalc/Make/files
@@ -0,0 +1,3 @@
+foamCalc.C
+
+EXE = $(FOAM_APPBIN)/foamCalc
diff --git a/applications/utilities/postProcessing/foamCalc/Make/options b/applications/utilities/postProcessing/foamCalc/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..dbe9ddc0488d2f4b3fa0a296368149fcf54c0a95
--- /dev/null
+++ b/applications/utilities/postProcessing/foamCalc/Make/options
@@ -0,0 +1,7 @@
+EXE_INC = \
+    -I$(LIB_SRC)/finiteVolume/lnInclude \
+    -I$(LIB_SRC)/postProcessing/foamCalcFunctions/lnInclude
+
+EXE_LIBS = \
+    -lfiniteVolume \
+    -lfoamCalcFunctions
diff --git a/applications/utilities/postProcessing/foamCalc/foamCalc.C b/applications/utilities/postProcessing/foamCalc/foamCalc.C
new file mode 100644
index 0000000000000000000000000000000000000000..452487df55f8ccbd8067fb6c495cc3c5641d0b9b
--- /dev/null
+++ b/applications/utilities/postProcessing/foamCalc/foamCalc.C
@@ -0,0 +1,91 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Application
+    foamCalc
+
+Description
+    Generic wrapper for calculating a quantity at each time. Split into four
+    phases:
+        1. Intialise
+        2. Pre-time calculation loop
+        3. Calculation loop
+        4. Post-calculation loop
+
+\*---------------------------------------------------------------------------*/
+
+#include "timeSelector.H"
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+int main(int argc, char *argv[])
+{
+    Foam::timeSelector::addOptions();
+    Foam::argList::validOptions.insert("noWrite", "");
+    Foam::argList::validOptions.insert("dict", "dictionary name");
+
+    if (argc < 2)
+    {
+        FatalError
+            << "No utility has been supplied" << nl
+            << exit(FatalError);
+    }
+
+    word utilityName = argv[1];
+
+    Foam::autoPtr<Foam::calcType> utility
+    (
+        calcType::New(utilityName)
+    );
+
+    utility().tryInit();
+
+#   include "setRootCase.H"
+#   include "createTime.H"
+    Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
+#   include "createMesh.H"
+
+    utility().tryPreCalc(args, runTime, mesh);
+
+    forAll(timeDirs, timeI)
+    {
+        runTime.setTime(timeDirs[timeI], timeI);
+
+        Foam::Info<< "Time = " << runTime.timeName() << Foam::endl;
+
+        mesh.readUpdate();
+
+        utility().tryCalc(args, runTime, mesh);
+
+        Foam::Info<< Foam::endl;
+    }
+
+    utility().tryPostCalc(args, runTime, mesh);
+
+    return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/src/postProcessing/Allwmake b/src/postProcessing/Allwmake
index ed91892bdee973efa58fe6aa02c10cf9d2738301..a7b00e35a34268a25a3bd82259aaa0eb3bd25ff3 100755
--- a/src/postProcessing/Allwmake
+++ b/src/postProcessing/Allwmake
@@ -4,4 +4,6 @@ set -x
 wmake libo postCalc
 wmake libso forces
 wmake libso fieldAverage
+wmake libso foamCalcFunctions
+
 
diff --git a/src/postProcessing/foamCalcFunctions/Make/files b/src/postProcessing/foamCalcFunctions/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..839e7681476983b657eb01a4236941da8b8cef06
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/Make/files
@@ -0,0 +1,9 @@
+calcType/calcType.C
+calcType/newCalcType.C
+
+field/components/components.C
+field/mag/mag.C
+field/magSqr/magSqr.C
+field/magGrad/magGrad.C
+
+LIB = $(FOAM_LIBBIN)/libfoamCalcFunctions
diff --git a/applications/utilities/postProcessing/field/magSqr/Make/options b/src/postProcessing/foamCalcFunctions/Make/options
similarity index 72%
rename from applications/utilities/postProcessing/field/magSqr/Make/options
rename to src/postProcessing/foamCalcFunctions/Make/options
index be7f7d631d3092c6fdffcb40349c53ba1fff4db8..fa15f124528ebfcaf279a88a73a0d7954f2e9dc1 100644
--- a/applications/utilities/postProcessing/field/magSqr/Make/options
+++ b/src/postProcessing/foamCalcFunctions/Make/options
@@ -2,5 +2,4 @@ EXE_INC = \
     -I$(LIB_SRC)/finiteVolume/lnInclude
 
 EXE_LIBS = \
-    -lfiniteVolume \
-   
+    -lfiniteVolume
diff --git a/src/postProcessing/foamCalcFunctions/calcType/calcType.C b/src/postProcessing/foamCalcFunctions/calcType/calcType.C
new file mode 100644
index 0000000000000000000000000000000000000000..f26c0914fd8c09649b914e8a9c36eae77a890d5f
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/calcType/calcType.C
@@ -0,0 +1,166 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+defineTypeNameAndDebug(calcType, 0);
+
+defineRunTimeSelectionTable(calcType, dictionary);
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::calcType::calcType()
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::calcType::~calcType()
+{}
+
+
+// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
+
+void Foam::calcType::init()
+{
+    // Do nothing
+}
+
+
+void Foam::calcType::preCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    // Do nothing
+}
+
+
+void Foam::calcType::calc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    // Do nothing
+}
+
+
+void Foam::calcType::postCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    // Do nothing
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::calcType::tryInit()
+{
+    FatalIOError.throwExceptions();
+
+    try
+    {
+        init();
+    }
+    catch(IOerror& err)
+    {
+        Warning<< err << endl;
+    }
+}
+
+
+void Foam::calcType::tryPreCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    FatalIOError.throwExceptions();
+
+    try
+    {
+        preCalc(args, runTime, mesh);
+    }
+    catch(IOerror& err)
+    {
+        Warning<< err << endl;
+    }
+}
+
+
+void Foam::calcType::tryCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    FatalIOError.throwExceptions();
+
+    try
+    {
+        calc(args, runTime, mesh);
+    }
+    catch(IOerror& err)
+    {
+        Warning<< err << endl;
+    }
+}
+
+
+void Foam::calcType::tryPostCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    FatalIOError.throwExceptions();
+
+    try
+    {
+        postCalc(args, runTime, mesh);
+    }
+    catch(IOerror& err)
+    {
+        Warning<< err << endl;
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/postProcessing/foamCalcFunctions/calcType/calcType.H b/src/postProcessing/foamCalcFunctions/calcType/calcType.H
new file mode 100644
index 0000000000000000000000000000000000000000..5e7d1079d2583a179e6ec85e0a51baf6f61ad64e
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/calcType/calcType.H
@@ -0,0 +1,175 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::calcType
+
+Description
+    Base class for post-processing calculation functions
+
+SourceFiles
+    calcType.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef calcType_H
+#define calcType_H
+
+#include "autoPtr.H"
+#include "runTimeSelectionTables.H"
+
+#include "fvCFD.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                          Class calcType Declaration
+\*---------------------------------------------------------------------------*/
+
+class calcType
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        calcType(const calcType&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const calcType&);
+
+
+protected:
+
+    // Protected member functions
+
+        // Calculation routines
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            virtual void init();
+
+            //- Pre-time loop calculations
+            virtual void preCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            virtual void calc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Post-time loop calculations
+            virtual void postCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+
+public:
+
+    //- Runtime type information
+    TypeName("calcType");
+
+
+    // Declare runtime constructor selection table
+
+        declareRunTimeSelectionTable
+        (
+            autoPtr,
+            calcType,
+            dictionary,
+            (),
+            ()
+        );
+
+
+    // Constructors
+
+        //- Construct null
+        calcType();
+
+
+    // Selectors
+
+        static autoPtr<calcType> New(const word& calcTypeName);
+
+
+    // Destructor
+
+        virtual ~calcType();
+
+
+    // Member Functions
+
+        // Calculation routines - wrapped by exception handling loop
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            void tryInit();
+
+            //- Pre-time loop calculations
+            void tryPreCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            void tryCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Post-time loop calculations
+            void tryPostCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/postProcessing/foamCalcFunctions/calcType/newCalcType.C b/src/postProcessing/foamCalcFunctions/calcType/newCalcType.C
new file mode 100644
index 0000000000000000000000000000000000000000..4ce6740fea468c407749de1ed8ce61ec471738b3
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/calcType/newCalcType.C
@@ -0,0 +1,55 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+Foam::autoPtr<Foam::calcType> Foam::calcType::New
+(
+    const word& calcTypeName
+)
+{
+    Info<< "Selecting calcType " << calcTypeName << endl;
+
+    dictionaryConstructorTable::iterator cstrIter =
+        dictionaryConstructorTablePtr_->find(calcTypeName);
+
+    if (cstrIter == dictionaryConstructorTablePtr_->end())
+    {
+        FatalErrorIn("calcType::New()")
+            << "    unknown calcType type " << calcTypeName
+            << ", constructor not in hash table" << nl << nl
+            << "    Valid calcType selections are: " << nl
+            << dictionaryConstructorTablePtr_->toc() << nl
+            << abort(FatalError);
+    }
+
+    return autoPtr<calcType>(cstrIter()());
+}
+
+
+// ************************************************************************* //
diff --git a/src/postProcessing/foamCalcFunctions/field/components/components.C b/src/postProcessing/foamCalcFunctions/field/components/components.C
new file mode 100644
index 0000000000000000000000000000000000000000..644771023b65a1e76a8b25b9416f75bbd91f33f1
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/components/components.C
@@ -0,0 +1,132 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "components.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    namespace calcTypes
+    {
+        defineTypeNameAndDebug(components, 0);
+        addToRunTimeSelectionTable(calcType, components, dictionary);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::calcTypes::components::components()
+:
+    calcType()
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::calcTypes::components::~components()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::calcTypes::components::init()
+{
+    Foam::argList::validArgs.append("components");
+    argList::validArgs.append("fieldName1 .. fieldNameN");
+}
+
+
+void Foam::calcTypes::components::preCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    if (args.additionalArgs().size() < 2)
+    {
+        Info<< nl << "must specify one or more fields" << nl;
+        args.printUsage();
+        FatalError.exit();
+    }
+}
+
+
+void Foam::calcTypes::components::calc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    const stringList& params = args.additionalArgs();
+
+    for (label fieldi=1; fieldi<params.size(); fieldi++)
+    {
+        const word fieldName(params[fieldi]);
+
+        IOobject fieldHeader
+        (
+            fieldName,
+            runTime.timeName(),
+            mesh,
+            IOobject::MUST_READ
+        );
+
+        // Check field exists
+        if (fieldHeader.headerOk())
+        {
+            bool processed = false;
+
+            writeComponentFields<vector>(fieldHeader, mesh, processed);
+            writeComponentFields<sphericalTensor>
+            (
+                fieldHeader,
+                mesh,
+                processed
+            );
+
+            if (!processed)
+            {
+                FatalError
+                    << "Unable to process " << fieldName << nl
+                    << "No call to components for fields of type "
+                    << fieldHeader.headerClassName() << nl << nl
+                    << exit(FatalError);
+            }
+        }
+        else
+        {
+            Info<< "    No " << fieldName << endl;
+        }
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/postProcessing/foamCalcFunctions/field/components/components.H b/src/postProcessing/foamCalcFunctions/field/components/components.H
new file mode 100644
index 0000000000000000000000000000000000000000..8c66325a6246674db9cca1800add6eae721bdf05
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/components/components.H
@@ -0,0 +1,139 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::components
+
+Description
+    Writes scalar fields corresponding to each component of the supplied
+    field (name) for each time.
+
+SourceFiles
+    components.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef components_H
+#define components_H
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+namespace calcTypes
+{
+
+/*---------------------------------------------------------------------------*\
+                         Class components Declaration
+\*---------------------------------------------------------------------------*/
+
+class components
+:
+    public calcType
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        components(const components&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const components&);
+
+
+protected:
+
+    // Member Functions
+
+        // Calculation routines
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            virtual void init();
+
+            //- Pre-time loop calculations
+            virtual void preCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            virtual void calc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+
+        // I-O
+
+            //- Write component fields
+            template<class Type>
+            void writeComponentFields
+            (
+                const IOobject& header,
+                const fvMesh& mesh,
+                bool& processed
+            );
+
+
+public:
+
+    //- Runtime type information
+    TypeName("components");
+
+
+    // Constructors
+
+        //- Construct null
+        components();
+
+
+    // Destructor
+
+        virtual ~components();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace calcTypes
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "writeComponentFields.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/components/writeComponentFields.C b/src/postProcessing/foamCalcFunctions/field/components/writeComponentFields.C
similarity index 89%
rename from applications/utilities/postProcessing/field/components/writeComponentFields.C
rename to src/postProcessing/foamCalcFunctions/field/components/writeComponentFields.C
index df91bc2131e21db335aba0966b63c68de9119837..fb8919dde4ae862d5c6ee92c4b3755ffc21361ef 100644
--- a/applications/utilities/postProcessing/field/components/writeComponentFields.C
+++ b/src/postProcessing/foamCalcFunctions/field/components/writeComponentFields.C
@@ -22,21 +22,10 @@ License
     along with OpenFOAM; if not, write to the Free Software Foundation,
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-Application
-    components
-
-Description
-    Writes scalar fields corresponding to each component of the supplied
-    field (name) for each time.
-
 \*---------------------------------------------------------------------------*/
 
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 template <class Type>
-void writeComponentFields
+void Foam::calcTypes::components::writeComponentFields
 (
     const IOobject& header,
     const fvMesh& mesh,
diff --git a/src/postProcessing/foamCalcFunctions/field/mag/mag.C b/src/postProcessing/foamCalcFunctions/field/mag/mag.C
new file mode 100644
index 0000000000000000000000000000000000000000..fd5793e5d1aec1f7e3f19d32ba00d68976367f50
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/mag/mag.C
@@ -0,0 +1,131 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "mag.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    namespace calcTypes
+    {
+        defineTypeNameAndDebug(mag, 0);
+        addToRunTimeSelectionTable(calcType, mag, dictionary);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::calcTypes::mag::mag()
+:
+    calcType()
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::calcTypes::mag::~mag()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::calcTypes::mag::init()
+{
+    Foam::argList::validArgs.append("mag");
+    argList::validArgs.append("fieldName1 .. fieldNameN");
+}
+
+
+void Foam::calcTypes::mag::preCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    if (args.additionalArgs().size() < 2)
+    {
+        Info<< nl << "must specify one or more fields" << nl;
+        args.printUsage();
+        FatalError.exit();
+    }
+}
+
+
+void Foam::calcTypes::mag::calc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    const stringList& params = args.additionalArgs();
+
+    for (label fieldi=1; fieldi<params.size(); fieldi++)
+    {
+        const word fieldName(params[fieldi]);
+
+        IOobject fieldHeader
+        (
+            fieldName,
+            runTime.timeName(),
+            mesh,
+            IOobject::MUST_READ
+        );
+
+        // Check field exists
+        if (fieldHeader.headerOk())
+        {
+            bool processed = false;
+
+            writeMagField<scalar>(fieldHeader, mesh, processed);
+            writeMagField<vector>(fieldHeader, mesh, processed);
+            writeMagField<sphericalTensor>(fieldHeader, mesh, processed);
+            writeMagField<symmTensor>(fieldHeader, mesh, processed);
+            writeMagField<tensor>(fieldHeader, mesh, processed);
+
+            if (!processed)
+            {
+                 FatalError
+                     << "Unable to process " << fieldName << nl
+                     << "No call to mag for fields of type "
+                     << fieldHeader.headerClassName() << nl << nl
+                     << exit(FatalError);
+            }
+        }
+        else
+        {
+            Info<< "    No " << fieldName << endl;
+        }
+    }
+}
+
+
+// ************************************************************************* //
+
diff --git a/src/postProcessing/foamCalcFunctions/field/mag/mag.H b/src/postProcessing/foamCalcFunctions/field/mag/mag.H
new file mode 100644
index 0000000000000000000000000000000000000000..179d5b235d4a6ee446e4ca96b9a2687838870fec
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/mag/mag.H
@@ -0,0 +1,138 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::mag
+
+Description
+    Calculates and writes the magnitude of a field for each time
+
+SourceFiles
+    mag.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef mag_H
+#define mag_H
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+namespace calcTypes
+{
+
+/*---------------------------------------------------------------------------*\
+                           Class mag Declaration
+\*---------------------------------------------------------------------------*/
+
+class mag
+:
+    public calcType
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        mag(const mag&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const mag&);
+
+
+protected:
+
+    // Member Functions
+
+        // Calculation routines
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            virtual void init();
+
+            //- Pre-time loop calculations
+            virtual void preCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            virtual void calc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+
+        // I-O
+
+            //- Write component fields
+            template<class Type>
+            void writeMagField
+            (
+                const IOobject& header,
+                const fvMesh& mesh,
+                bool& processed
+            );
+
+
+public:
+
+    //- Runtime type information
+    TypeName("mag");
+
+
+    // Constructors
+
+        //- Construct null
+        mag();
+
+
+    // Destructor
+
+        virtual ~mag();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace calcTypes
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "writeMagField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/mag/writeMagField.C b/src/postProcessing/foamCalcFunctions/field/mag/writeMagField.C
similarity index 89%
rename from applications/utilities/postProcessing/field/mag/writeMagField.C
rename to src/postProcessing/foamCalcFunctions/field/mag/writeMagField.C
index 760c785392935b1a157db7e1017c3125a7a98854..8804fa2585519bdd0ca2cf33cb6dc04aaf03b7f9 100644
--- a/applications/utilities/postProcessing/field/mag/writeMagField.C
+++ b/src/postProcessing/foamCalcFunctions/field/mag/writeMagField.C
@@ -22,20 +22,10 @@ License
     along with OpenFOAM; if not, write to the Free Software Foundation,
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-Application
-    mag
-
-Description
-    Calculates and writes the magnitude of a field for each time
-
 \*---------------------------------------------------------------------------*/
 
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 template<class Type>
-void writeMagField
+void Foam::calcTypes::mag::writeMagField
 (
     const IOobject& header,
     const fvMesh& mesh,
@@ -59,7 +49,7 @@ void writeMagField
                 mesh,
                 IOobject::NO_READ
             ),
-            mag(field)
+            Foam::mag(field)
         );
         magField.write();
 
diff --git a/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.C b/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.C
new file mode 100644
index 0000000000000000000000000000000000000000..9e26d27496876057efc91e2e77ce3ff58e008357
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.C
@@ -0,0 +1,128 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "magGrad.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    namespace calcTypes
+    {
+        defineTypeNameAndDebug(magGrad, 0);
+        addToRunTimeSelectionTable(calcType, magGrad, dictionary);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::calcTypes::magGrad::magGrad()
+:
+    calcType()
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::calcTypes::magGrad::~magGrad()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::calcTypes::magGrad::init()
+{
+    Foam::argList::validArgs.append("magGrad");
+    argList::validArgs.append("fieldName1 .. fieldNameN");
+}
+
+
+void Foam::calcTypes::magGrad::preCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    if (args.additionalArgs().size() < 2)
+    {
+        Info<< nl << "must specify one or more fields" << nl;
+        args.printUsage();
+        FatalError.exit();
+    }
+}
+
+
+void Foam::calcTypes::magGrad::calc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    const stringList& params = args.additionalArgs();
+
+    for (label fieldi=1; fieldi<params.size(); fieldi++)
+    {
+        const word fieldName(params[fieldi]);
+
+        IOobject fieldHeader
+        (
+            fieldName,
+            runTime.timeName(),
+            mesh,
+            IOobject::MUST_READ
+        );
+
+        // Check field exists
+        if (fieldHeader.headerOk())
+        {
+            bool processed = false;
+
+            writeMagGradField<scalar>(fieldHeader, mesh, processed);
+            writeMagGradField<vector>(fieldHeader, mesh, processed);
+
+            if (!processed)
+            {
+                 FatalError
+                     << "Unable to process " << fieldName << nl
+                     << "No call to magGrad for fields of type "
+                     << fieldHeader.headerClassName() << nl << nl
+                     << exit(FatalError);
+            }
+        }
+        else
+        {
+            Info<< "    No " << fieldName << endl;
+        }
+    }
+}
+
+
+// ************************************************************************* //
+
diff --git a/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.H b/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.H
new file mode 100644
index 0000000000000000000000000000000000000000..9ab358bdfb527e41ff857dc832de4cc4648263a9
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.H
@@ -0,0 +1,139 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::magGrad
+
+Description
+    Writes scalar fields corresponding to the magnitude ot the gradient
+    of the supplied field (name) for each time.
+
+SourceFiles
+    magGrad.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef magGrad_H
+#define magGrad_H
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+namespace calcTypes
+{
+
+/*---------------------------------------------------------------------------*\
+                          Class magGrad Declaration
+\*---------------------------------------------------------------------------*/
+
+class magGrad
+:
+    public calcType
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        magGrad(const magGrad&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const magGrad&);
+
+
+protected:
+
+    // Member Functions
+
+        // Calculation routines
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            virtual void init();
+
+            //- Pre-time loop calculations
+            virtual void preCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            virtual void calc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+
+        // I-O
+
+            //- Write magGrad fields
+            template<class Type>
+            void writeMagGradField
+            (
+                const IOobject& header,
+                const fvMesh& mesh,
+                bool& processed
+            );
+
+
+public:
+
+    //- Runtime type information
+    TypeName("magGrad");
+
+
+    // Constructors
+
+        //- Construct null
+        magGrad();
+
+
+    // Destructor
+
+        virtual ~magGrad();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace calcTypes
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "writeMagGradField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/magGrad/writeMagGradField.C b/src/postProcessing/foamCalcFunctions/field/magGrad/writeMagGradField.C
similarity index 87%
rename from applications/utilities/postProcessing/field/magGrad/writeMagGradField.C
rename to src/postProcessing/foamCalcFunctions/field/magGrad/writeMagGradField.C
index 644ea449dd54589da99945dd4987e81357a43d9c..6f7c64c68d2a321627becc0aa882c095ac81edb0 100644
--- a/applications/utilities/postProcessing/field/magGrad/writeMagGradField.C
+++ b/src/postProcessing/foamCalcFunctions/field/magGrad/writeMagGradField.C
@@ -22,21 +22,10 @@ License
     along with OpenFOAM; if not, write to the Free Software Foundation,
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-Application
-    magGrad
-
-Description
-    Calculates and writes the magnitude of the gradient of a field for each
-    time
-
 \*---------------------------------------------------------------------------*/
 
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 template<class Type>
-void writeMagGradField
+void Foam::calcTypes::magGrad::writeMagGradField
 (
     const IOobject& header,
     const fvMesh& mesh,
@@ -60,7 +49,7 @@ void writeMagGradField
                 mesh,
                 IOobject::NO_READ
             ),
-            mag(fvc::grad(field))
+            Foam::mag(fvc::grad(field))
         );
         magGradField.write();
 
diff --git a/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.C b/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.C
new file mode 100644
index 0000000000000000000000000000000000000000..40cdafce3dcc3f823a775b4f0a92c3fe8fdf876b
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.C
@@ -0,0 +1,131 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "magSqr.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    namespace calcTypes
+    {
+        defineTypeNameAndDebug(magSqr, 0);
+        addToRunTimeSelectionTable(calcType, magSqr, dictionary);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::calcTypes::magSqr::magSqr()
+:
+    calcType()
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::calcTypes::magSqr::~magSqr()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::calcTypes::magSqr::init()
+{
+    Foam::argList::validArgs.append("magSqr");
+    argList::validArgs.append("fieldName1 .. fieldNameN");
+}
+
+
+void Foam::calcTypes::magSqr::preCalc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    if (args.additionalArgs().size() < 2)
+    {
+        Info<< nl << "must specify one or more fields" << nl;
+        args.printUsage();
+        FatalError.exit();
+    }
+}
+
+
+void Foam::calcTypes::magSqr::calc
+(
+    const argList& args,
+    const Time& runTime,
+    const fvMesh& mesh
+)
+{
+    const stringList& params = args.additionalArgs();
+
+    for (label fieldi=1; fieldi<params.size(); fieldi++)
+    {
+        const word fieldName(params[fieldi]);
+
+        IOobject fieldHeader
+        (
+            fieldName,
+            runTime.timeName(),
+            mesh,
+            IOobject::MUST_READ
+        );
+
+        // Check field exists
+        if (fieldHeader.headerOk())
+        {
+            bool processed = false;
+
+            writeMagSqrField<scalar>(fieldHeader, mesh, processed);
+            writeMagSqrField<vector>(fieldHeader, mesh, processed);
+            writeMagSqrField<sphericalTensor>(fieldHeader, mesh, processed);
+            writeMagSqrField<symmTensor>(fieldHeader, mesh, processed);
+            writeMagSqrField<tensor>(fieldHeader, mesh, processed);
+
+            if (!processed)
+            {
+                 FatalError
+                     << "Unable to process " << fieldName << nl
+                     << "No call to magSqr for fields of type "
+                     << fieldHeader.headerClassName() << nl << nl
+                     << exit(FatalError);
+            }
+        }
+        else
+        {
+            Info<< "    No " << fieldName << endl;
+        }
+    }
+}
+
+
+// ************************************************************************* //
+
diff --git a/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.H b/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.H
new file mode 100644
index 0000000000000000000000000000000000000000..7609763e9e1a212c1542b5e4a793685ab1d6cec2
--- /dev/null
+++ b/src/postProcessing/foamCalcFunctions/field/magSqr/magSqr.H
@@ -0,0 +1,138 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::magSqr
+
+Description
+    Calculates and writes the magnitude-sqaured of a field for each time
+
+SourceFiles
+    magSqr.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef magSqr_H
+#define magSqr_H
+
+#include "calcType.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+namespace calcTypes
+{
+
+/*---------------------------------------------------------------------------*\
+                          Class magSqr Declaration
+\*---------------------------------------------------------------------------*/
+
+class magSqr
+:
+    public calcType
+{
+    // Private Member Functions
+
+        //- Disallow default bitwise copy construct
+        magSqr(const magSqr&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const magSqr&);
+
+
+protected:
+
+    // Member Functions
+
+        // Calculation routines
+
+            //- Initialise - typically setting static variables,
+            //  e.g. command line arguments
+            virtual void init();
+
+            //- Pre-time loop calculations
+            virtual void preCalc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+            //- Time loop calculations
+            virtual void calc
+            (
+                const argList& args,
+                const Time& runTime,
+                const fvMesh& mesh
+            );
+
+
+        // I-O
+
+            //- Write component fields
+            template<class Type>
+            void writeMagSqrField
+            (
+                const IOobject& header,
+                const fvMesh& mesh,
+                bool& processed
+            );
+
+
+public:
+
+    //- Runtime type information
+    TypeName("magSqr");
+
+
+    // Constructors
+
+        //- Construct null
+        magSqr();
+
+
+    // Destructor
+
+        virtual ~magSqr();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace calcTypes
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "writeMagSqrField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/field/magSqr/writeMagSqrField.C b/src/postProcessing/foamCalcFunctions/field/magSqr/writeMagSqrField.C
similarity index 88%
rename from applications/utilities/postProcessing/field/magSqr/writeMagSqrField.C
rename to src/postProcessing/foamCalcFunctions/field/magSqr/writeMagSqrField.C
index 7198e88df7d4df83fadfdb6b63f060d9045869cf..5a49dadf1a061638536941ea49322e71fc68931d 100644
--- a/applications/utilities/postProcessing/field/magSqr/writeMagSqrField.C
+++ b/src/postProcessing/foamCalcFunctions/field/magSqr/writeMagSqrField.C
@@ -22,20 +22,10 @@ License
     along with OpenFOAM; if not, write to the Free Software Foundation,
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
-Application
-    mag
-
-Description
-    Calculates and writes the magnitude-squared of a field for each time
-
 \*---------------------------------------------------------------------------*/
 
-#include "fvCFD.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 template<class Type>
-void writeMagSqrField
+void Foam::calcTypes::magSqr::writeMagSqrField
 (
     const IOobject& header,
     const fvMesh& mesh,
@@ -59,7 +49,7 @@ void writeMagSqrField
                 mesh,
                 IOobject::NO_READ
             ),
-            magSqr(field)
+            Foam::magSqr(field)
         );
         magSqrField.write();
 
@@ -69,4 +59,3 @@ void writeMagSqrField
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-