From 7321a5eeb395e0cdd9f1557c7b523f4ae75c752c Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Tue, 24 Nov 2015 16:35:45 +0000
Subject: [PATCH] fvPatchFields/derived/fixedProfile: New BC which applies the
 specified 1D profile

This is useful when applying an experimentally obtained profile as an
inlet condition:

    Example of the boundary condition specification:
    \verbatim
    myPatch
    {
        type            fixedProfile;
        profile    csvFile;

        profileCoeffs
        {
            nHeaderLine         0;          // Number of header lines
            refColumn           0;          // Reference column index
            componentColumns    (1 2 3);    // Component column indices
            separator           ",";        // Optional (defaults to ",")
            mergeSeparators     no;         // Merge multiple separators
            fileName            "Uprofile.csv";  // name of csv data file
            outOfBounds         clamp;      // Optional out-of-bounds handling
            interpolationScheme linear;     // Optional interpolation scheme
        }
        direction        (0 1 0);
        origin           0;
    }
    \endverbatim

or a simple polynomial profile:

    Example setting a parabolic inlet profile for the PitzDaily case:
    \verbatim
    inlet
    {
        type            fixedProfile;

        profile         polynomial
        (
            ((1 0 0)        (0 0 0))
            ((-6200 0 0)    (2 0 0))
        );
        direction       (0 1 0);
        origin          0.0127;
    }
    \endverbatim

Based on code provided by Hassan Kassem:
http://www.openfoam.org/mantisbt/view.php?id=1922
---
 src/finiteVolume/Make/files                   |   1 +
 .../fixedProfile/fixedProfileFvPatchField.C   | 167 +++++++++++++
 .../fixedProfile/fixedProfileFvPatchField.H   | 230 ++++++++++++++++++
 .../fixedProfile/fixedProfileFvPatchFields.C  |  43 ++++
 .../fixedProfile/fixedProfileFvPatchFields.H  |  49 ++++
 .../fixedProfileFvPatchFieldsFwd.H            |  50 ++++
 6 files changed, 540 insertions(+)
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.C
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.H
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.C
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.H
 create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFieldsFwd.H

diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files
index 1b9c242765d..a8eaa086398 100644
--- a/src/finiteVolume/Make/files
+++ b/src/finiteVolume/Make/files
@@ -200,6 +200,7 @@ $(derivedFvPatchFields)/waveSurfacePressure/waveSurfacePressureFvPatchScalarFiel
 $(derivedFvPatchFields)/interstitialInletVelocity/interstitialInletVelocityFvPatchVectorField.C
 $(derivedFvPatchFields)/prghPressure/prghPressureFvPatchScalarField.C
 $(derivedFvPatchFields)/prghTotalPressure/prghTotalPressureFvPatchScalarField.C
+$(derivedFvPatchFields)/fixedProfile/fixedProfileFvPatchFields.C
 
 fvsPatchFields = fields/fvsPatchFields
 $(fvsPatchFields)/fvsPatchField/fvsPatchFields.C
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.C
new file mode 100644
index 00000000000..a9db1a70360
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.C
@@ -0,0 +1,167 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
+     \\/     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 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "fixedProfileFvPatchField.H"
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fvPatch& p,
+    const DimensionedField<Type, volMesh>& iF
+)
+:
+    fixedValueFvPatchField<Type>(p, iF),
+    profile_(),
+    dir_(pTraits<vector>::zero),
+    origin_(0)
+{}
+
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fvPatch& p,
+    const DimensionedField<Type, volMesh>& iF,
+    const Field<Type>& fld
+)
+:
+    fixedValueFvPatchField<Type>(p, iF, fld),
+    profile_(),
+    dir_(pTraits<vector>::zero),
+    origin_(0)
+{}
+
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fvPatch& p,
+    const DimensionedField<Type, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    fixedValueFvPatchField<Type>(p, iF),
+    profile_(DataEntry<Type>::New("profile", dict)),
+    dir_(dict.lookup("direction")),
+    origin_(readScalar(dict.lookup("origin")))
+{
+    if (mag(dir_) < SMALL)
+    {
+        FatalErrorInFunction
+            << "magnitude Direction must be greater than zero"
+            << abort(FatalError);
+    }
+
+    // Ensure direction vector is normalized
+    dir_ /= mag(dir_);
+
+    // Evaluate profile
+    this->evaluate();
+}
+
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fixedProfileFvPatchField<Type>& ptf,
+    const fvPatch& p,
+    const DimensionedField<Type, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    fixedValueFvPatchField<Type>(p, iF),  // Don't map
+    profile_(ptf.profile_, false),
+    dir_(ptf.dir_),
+    origin_(ptf.origin_)
+{
+    // Evaluate profile since value not mapped
+    this->evaluate();
+}
+
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fixedProfileFvPatchField<Type>& ptf
+)
+:
+    fixedValueFvPatchField<Type>(ptf),
+    profile_(ptf.profile_, false),
+    dir_(ptf.dir_),
+    origin_(ptf.origin_)
+{}
+
+
+template<class Type>
+Foam::fixedProfileFvPatchField<Type>::fixedProfileFvPatchField
+(
+    const fixedProfileFvPatchField<Type>& ptf,
+    const DimensionedField<Type, volMesh>& iF
+)
+:
+    fixedValueFvPatchField<Type>(ptf, iF),
+    profile_(ptf.profile_, false),
+    dir_(ptf.dir_),
+    origin_(ptf.origin_)
+{
+    // Evaluate the profile if defined
+    if (ptf.profile_.valid())
+    {
+        this->evaluate();
+    }
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+template<class Type>
+void Foam::fixedProfileFvPatchField<Type>::updateCoeffs()
+{
+    if (this->updated())
+    {
+        return;
+    }
+
+    const scalarField dirCmpt((dir_ & this->patch().Cf()) - origin_);
+    fvPatchField<Type>::operator==(profile_->value(dirCmpt));
+
+    fixedValueFvPatchField<Type>::updateCoeffs();
+}
+
+
+template<class Type>
+void Foam::fixedProfileFvPatchField<Type>::write(Ostream& os) const
+{
+    fvPatchField<Type>::write(os);
+    profile_->writeData(os);
+    os.writeKeyword("direction") << dir_ << token::END_STATEMENT << nl;
+    os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
+    this->writeEntry("value", os);
+}
+
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.H
new file mode 100644
index 00000000000..d644a8e73c6
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchField.H
@@ -0,0 +1,230 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
+     \\/     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 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 <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::fixedProfileFvPatchField
+
+Group
+    grpGenericBoundaryConditions
+
+Description
+    This boundary condition provides a fixed value profile condition.
+
+    \heading Patch usage
+
+    \table
+        Property     | Description              | Required | Default value
+        profile      | Profile DataEntry        | yes |
+        direction    | Profile direction        | yes |
+        origin       | Profile origin           | yes |
+    \endtable
+
+    Example of the boundary condition specification:
+    \verbatim
+    myPatch
+    {
+        type            fixedProfile;
+        profile    csvFile;
+
+        profileCoeffs
+        {
+            nHeaderLine         0;          // Number of header lines
+            refColumn           0;          // Reference column index
+            componentColumns    (1 2 3);    // Component column indices
+            separator           ",";        // Optional (defaults to ",")
+            mergeSeparators     no;         // Merge multiple separators
+            fileName            "Uprofile.csv";  // name of csv data file
+            outOfBounds         clamp;      // Optional out-of-bounds handling
+            interpolationScheme linear;     // Optional interpolation scheme
+        }
+        direction        (0 1 0);
+        origin           0;
+    }
+    \endverbatim
+
+    Example setting a parabolic inlet profile for the PitzDaily case:
+    \verbatim
+    inlet
+    {
+        type            fixedProfile;
+
+        profile         polynomial
+        (
+            ((1 0 0)        (0 0 0))
+            ((-6200 0 0)    (2 0 0))
+        );
+        direction       (0 1 0);
+        origin          0.0127;
+    }
+    \endverbatim
+
+Note
+    The profile entry is a DataEntry type.  The example above gives the
+    usage for supplying csv file.
+
+SeeAlso
+    Foam::fixedValueFvPatchField
+    Foam::DataEntry
+    Foam::timeVaryingMappedFixedValueFvPatchField
+
+SourceFiles
+    fixedProfileFvPatchField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef fixedProfileFvPatchField_H
+#define fixedProfileFvPatchField_H
+
+#include "fixedValueFvPatchFields.H"
+#include "DataEntry.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                Class fixedProfileFvPatchField Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class Type>
+class fixedProfileFvPatchField
+:
+    public fixedValueFvPatchField<Type>
+{
+    // Private data
+
+        //- Profile data
+        autoPtr<DataEntry<Type> > profile_;
+
+        //- Profile direction
+        vector dir_;
+
+        //- Profile origin
+        scalar origin_;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("fixedProfile");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        fixedProfileFvPatchField
+        (
+            const fvPatch&,
+            const DimensionedField<Type, volMesh>&
+        );
+
+        //- Construct from patch and internal field and patch field
+        fixedProfileFvPatchField
+        (
+            const fvPatch&,
+            const DimensionedField<Type, volMesh>&,
+            const Field<Type>& fld
+        );
+
+        //- Construct from patch, internal field and dictionary
+        fixedProfileFvPatchField
+        (
+            const fvPatch&,
+            const DimensionedField<Type, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given fixedProfileFvPatchField
+        //  onto a new patch
+        fixedProfileFvPatchField
+        (
+            const fixedProfileFvPatchField<Type>&,
+            const fvPatch&,
+            const DimensionedField<Type, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct as copy
+        fixedProfileFvPatchField
+        (
+            const fixedProfileFvPatchField<Type>&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchField<Type> > clone() const
+        {
+            return tmp<fvPatchField<Type> >
+            (
+                new fixedProfileFvPatchField<Type>(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        fixedProfileFvPatchField
+        (
+            const fixedProfileFvPatchField<Type>&,
+            const DimensionedField<Type, volMesh>&
+        );
+
+        //- Construct and return a clone setting internal field reference
+        virtual tmp<fvPatchField<Type> > clone
+        (
+            const DimensionedField<Type, volMesh>& iF
+        ) const
+        {
+            return tmp<fvPatchField<Type> >
+            (
+                new fixedProfileFvPatchField<Type>(*this, iF)
+            );
+        }
+
+
+    // Member functions
+
+        // Evaluation functions
+
+            //- Update the coefficients associated with the patch field
+            virtual void updateCoeffs();
+
+
+        //- Write
+        virtual void write(Ostream&) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+#   include "fixedProfileFvPatchField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.C
new file mode 100644
index 00000000000..155f369672b
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.C
@@ -0,0 +1,43 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
+     \\/     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 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "fixedProfileFvPatchFields.H"
+#include "addToRunTimeSelectionTable.H"
+#include "volFields.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+makePatchFields(fixedProfile);
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.H
new file mode 100644
index 00000000000..0896b8c760f
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFields.H
@@ -0,0 +1,49 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
+     \\/     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 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef fixedProfileFvPatchFields_H
+#define fixedProfileFvPatchFields_H
+
+#include "fixedProfileFvPatchField.H"
+#include "fieldTypes.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+makePatchTypeFieldTypedefs(fixedProfile);
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFieldsFwd.H
new file mode 100644
index 00000000000..e324c24dc90
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedProfile/fixedProfileFvPatchFieldsFwd.H
@@ -0,0 +1,50 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2015 OpenFOAM Foundation
+     \\/     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 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef fixedProfileFvPatchFieldsFwd_H
+#define fixedProfileFvPatchFieldsFwd_H
+
+#include "fieldTypes.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+template<class Type> class fixedProfileFvPatchField;
+
+makePatchTypeFieldTypedefs(fixedValue);
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab